blob: 8394bc8b9370a0c33e62fbe7862f09d384078e3e [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 {
Mark Lobodzinski56945182015-04-09 13:46:09 -0500144 // Validate that fence is in UNSIGNALED state
145 MT_OBJ_INFO* pObjectInfo = getObjectInfo(fence);
146 if (pObjectInfo != NULL) {
Tobin Ehlisf29da382015-04-15 07:46:12 -0600147 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinski56945182015-04-09 13:46:09 -0500148 char str[1024];
149 sprintf(str, "Fence %p submitted in SIGNALED state. Fences must be reset before being submitted", fence);
Tobin Ehlisf29da382015-04-15 07:46:12 -0600150 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, fence, 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Mark Lobodzinski56945182015-04-09 13:46:09 -0500151 }
152 }
Tobin Ehlisf29da382015-04-15 07:46:12 -0600153 pFenceInfo->localFence = VK_FALSE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500154 pFenceInfo->fence = fence;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700155 }
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500156 pFenceInfo->queue = queue;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500157 fenceMap[fenceId] = pFenceInfo;
Mark Lobodzinski8ee96342015-04-02 20:49:09 -0500158 // Update most recently submitted fenceId for Queue
159 pQueueInfo->lastSubmittedId = fenceId;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500160 return fenceId;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500161}
162
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500163// Remove a fenceInfo from our list of fences/fenceIds
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500164static void deleteFenceInfo(uint64_t fenceId)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500165{
166 if (fenceId != 0) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500167 if (fenceMap.find(fenceId) != fenceMap.end()) {
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600168 map<uint64_t, MT_FENCE_INFO*>::iterator item;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500169 MT_FENCE_INFO* pDelInfo = fenceMap[fenceId];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500170 if (pDelInfo != NULL) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600171 if (pDelInfo->localFence == VK_TRUE) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500172 nextTable.DestroyObject(pDelInfo->fence);
173 }
174 delete pDelInfo;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500175 }
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600176 item = fenceMap.find(fenceId);
177 fenceMap.erase(item);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500178 }
179 }
180}
181
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500182// Search through list for this fence, deleting all items before it (with lower IDs) and updating lastRetiredId
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600183static void updateFenceTracking(VkFence fence)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500184{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500185 MT_FENCE_INFO *pCurFenceInfo = NULL;
186 uint64_t fenceId = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600187 VkQueue queue = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500188
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500189 for (map<uint64_t, MT_FENCE_INFO*>::iterator ii=fenceMap.begin(); ii!=fenceMap.end(); ++ii) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500190 if ((*ii).second != NULL) {
191 if (fence == ((*ii).second)->fence) {
192 queue = ((*ii).second)->queue;
193 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
194 pQueueInfo->lastRetiredId = (*ii).first;
195 } else {
196 deleteFenceInfo((*ii).first);
197 }
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500198 // Update fence state in fenceCreateInfo structure
199 MT_OBJ_INFO* pObjectInfo = getObjectInfo(fence);
200 if (pObjectInfo != NULL) {
Mark Lobodzinski56945182015-04-09 13:46:09 -0500201 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisf29da382015-04-15 07:46:12 -0600202 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags | VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500203 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500204 }
205 }
206}
207
208// Utility function that determines if a fenceId has been retired yet
209static bool32_t fenceRetired(uint64_t fenceId)
210{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600211 bool32_t result = VK_FALSE;
Courtney Goeltzenleuchter60edc352015-04-15 14:10:51 -0600212 if (fenceMap.find(fenceId) != fenceMap.end()) {
213 MT_FENCE_INFO* pFenceInfo = fenceMap[fenceId];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500214 MT_QUEUE_INFO* pQueueInfo = queueMap[pFenceInfo->queue];
Mark Lobodzinski91a1ec52015-04-02 08:52:53 -0500215 if (fenceId <= pQueueInfo->lastRetiredId)
216 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600217 result = VK_TRUE;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500218 }
Mark Lobodzinski8ee96342015-04-02 20:49:09 -0500219 } else { // If not in list, fence has been retired and deleted
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600220 result = VK_TRUE;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500221 }
222 return result;
223}
224
225// Return the fence associated with a fenceId
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600226static VkFence getFenceFromId(uint64_t fenceId)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500227{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600228 VkFence fence = NULL;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500229 if (fenceId != 0) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500230 // Search for an item with this fenceId
231 if (fenceMap.find(fenceId) != fenceMap.end()) {
232 MT_FENCE_INFO* pFenceInfo = fenceMap[fenceId];
233 if (pFenceInfo != NULL) {
234 MT_QUEUE_INFO* pQueueInfo = queueMap[pFenceInfo->queue];
235 if (fenceId > pQueueInfo->lastRetiredId) {
236 fence = pFenceInfo->fence;
237 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500238 }
239 }
240 }
241 return fence;
242}
243
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500244// Helper routine that updates the fence list for a specific queue to all-retired
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600245static void retireQueueFences(VkQueue queue)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500246{
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600247 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
248 pQueueInfo->lastRetiredId = pQueueInfo->lastSubmittedId;
249 // Set Queue's lastRetired to lastSubmitted, free items in queue's fence list
250 map<uint64_t, MT_FENCE_INFO*>::iterator it = fenceMap.begin();
251 map<uint64_t, MT_FENCE_INFO*>::iterator temp;
252 while (it != fenceMap.end()) {
253 if (((*it).second)->queue == queue) {
254 temp = it;
255 ++temp;
256 deleteFenceInfo((*it).first);
257 it = temp;
258 } else {
259 ++it;
260 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500261 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700262}
263
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500264// Helper routine that updates fence list for all queues to all-retired
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600265static void retireDeviceFences(VkDevice device)
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500266{
267 // Process each queue for device
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600268 // TODO: Add multiple device support
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600269 for (map<VkQueue, MT_QUEUE_INFO*>::iterator ii=queueMap.begin(); ii!=queueMap.end(); ++ii) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500270 retireQueueFences((*ii).first);
271 }
272}
273
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500274// Returns True if a memory reference is present in a Queue's memory reference list
275// Queue is validated by caller
276static bool32_t checkMemRef(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600277 VkQueue queue,
278 VkGpuMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500279{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600280 bool32_t result = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600281 list<VkGpuMemory>::iterator it;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500282 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
283 for (it = pQueueInfo->pMemRefList.begin(); it != pQueueInfo->pMemRefList.end(); ++it) {
284 if ((*it) == mem) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600285 result = VK_TRUE;
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500286 break;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500287 }
288 }
289 return result;
290}
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500291
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500292static bool32_t validateQueueMemRefs(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600293 VkQueue queue,
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500294 uint32_t cmdBufferCount,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600295 const VkCmdBuffer *pCmdBuffers)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500296{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600297 bool32_t result = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500298
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500299 // Verify Queue
300 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
301 if (pQueueInfo == NULL) {
302 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600303 sprintf(str, "Unknown Queue %p specified in vkQueueSubmit", queue);
304 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500305 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500306 else {
307 // Iterate through all CBs in pCmdBuffers
308 for (uint32_t i = 0; i < cmdBufferCount; i++) {
309 MT_CB_INFO* pCBInfo = getCBInfo(pCmdBuffers[i]);
310 if (!pCBInfo) {
311 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600312 sprintf(str, "Unable to find info for CB %p in order to check memory references in vkQueueSubmit for queue %p", (void*)pCmdBuffers[i], queue);
313 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_INVALID_CB, "MEM", str);
314 result = VK_FALSE;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500315 } else {
316 // Validate that all actual references are accounted for in pMemRefs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600317 for (list<VkGpuMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500318 // Search for each memref in queues memreflist.
319 if (checkMemRef(queue, *it)) {
320 char str[1024];
321 sprintf(str, "Found Mem Obj %p binding to CB %p for queue %p", (*it), pCmdBuffers[i], queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600322 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500323 }
324 else {
325 char str[1024];
326 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 -0600327 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
328 result = VK_FALSE;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500329 }
330 }
331 }
332 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600333 if (result == VK_TRUE) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500334 char str[1024];
335 sprintf(str, "Verified all memory dependencies for Queue %p are included in pMemRefs list", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600336 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500337 // TODO : Could report mem refs in pMemRefs that AREN'T in mem list, that would be primarily informational
338 // Currently just noting that there is a difference
339 }
340 }
341
342 return result;
343}
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600344
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500345// Return ptr to info in map container containing mem, or NULL if not found
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700346// Calls to this function should be wrapped in mutex
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600347static MT_MEM_OBJ_INFO* getMemObjInfo(const VkGpuMemory mem)
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700348{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500349 MT_MEM_OBJ_INFO* pMemObjInfo = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500350
351 if (memObjMap.find(mem) != memObjMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500352 pMemObjInfo = memObjMap[mem];
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600353 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500354 return pMemObjInfo;
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700355}
356
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600357static void addMemObjInfo(const VkGpuMemory mem, const VkMemoryAllocInfo* pAllocInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700358{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500359 MT_MEM_OBJ_INFO* pInfo = new MT_MEM_OBJ_INFO;
360 pInfo->refCount = 0;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600361 memset(&pInfo->allocInfo, 0, sizeof(VkMemoryAllocInfo));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500362
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600363 if (pAllocInfo) { // MEM alloc created by vkWsiX11CreatePresentableImage() doesn't have alloc info struct
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600364 memcpy(&pInfo->allocInfo, pAllocInfo, sizeof(VkMemoryAllocInfo));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500365 // TODO: Update for real hardware, actually process allocation info structures
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500366 pInfo->allocInfo.pNext = NULL;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700367 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500368 pInfo->mem = mem;
369 memObjMap[mem] = pInfo;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700370}
371
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500372// Find CB Info and add mem binding to list container
373// Find Mem Obj Info and add CB binding to list container
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600374static bool32_t updateCBBinding(const VkCmdBuffer cb, const VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700375{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600376 bool32_t result = VK_TRUE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700377 // First update CB binding in MemObj mini CB list
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500378 MT_MEM_OBJ_INFO* pMemInfo = getMemObjInfo(mem);
379 if (!pMemInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700380 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500381 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 -0600382 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
383 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600384 } else {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500385 // Search for cmd buffer object in memory object's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600386 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600387 for (list<VkCmdBuffer>::iterator it = pMemInfo->pCmdBufferBindings.begin(); it != pMemInfo->pCmdBufferBindings.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500388 if ((*it) == cb) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600389 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500390 break;
391 }
392 }
393 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600394 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500395 pMemInfo->pCmdBufferBindings.push_front(cb);
396 pMemInfo->refCount++;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500397 }
398
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500399 // Now update CBInfo's Mem binding list
400 MT_CB_INFO* pCBInfo = getCBInfo(cb);
401 if (!pCBInfo) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500402 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500403 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 -0600404 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
405 result = VK_FALSE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500406 } else {
407 // Search for memory object in cmd buffer's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600408 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600409 for (list<VkGpuMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500410 if ((*it) == mem) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600411 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500412 break;
413 }
414 }
415 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600416 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500417 pCBInfo->pMemObjList.push_front(mem);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600418 }
419 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700420 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600421 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700422}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600423
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700424// Clear the CB Binding for mem
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700425// Calls to this function should be wrapped in mutex
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600426static void clearCBBinding(const VkCmdBuffer cb, const VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700427{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500428 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500429 // TODO : Having this check is not ideal, really if memInfo was deleted,
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700430 // its CB bindings should be cleared and then freeCBBindings wouldn't call
431 // us here with stale mem objs
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500432 if (pInfo) {
433 pInfo->pCmdBufferBindings.remove(cb);
434 pInfo->refCount--;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700435 }
436}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600437
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700438// Free bindings related to CB
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600439static bool32_t freeCBBindings(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700440{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600441 bool32_t result = VK_TRUE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500442 MT_CB_INFO* pCBInfo = getCBInfo(cb);
443 if (!pCBInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700444 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500445 sprintf(str, "Unable to find global CB info %p for deletion", cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600446 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
447 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600448 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500449 if (!fenceRetired(pCBInfo->fenceId)) {
450 deleteFenceInfo(pCBInfo->fenceId);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600451 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500452
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600453 for (list<VkGpuMemory>::iterator it=pCBInfo->pMemObjList.begin(); it!=pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500454 clearCBBinding(cb, (*it));
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600455 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500456 pCBInfo->pMemObjList.clear();
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700457 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600458 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700459}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600460
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500461// Delete CBInfo from list along with all of it's mini MemObjInfo
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500462// and also clear mem references to CB
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700463// TODO : When should this be called? There's no Destroy of CBs that I see
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600464static bool32_t deleteCBInfo(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700465{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600466 bool32_t result = VK_TRUE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600467 result = freeCBBindings(cb);
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500468 // Delete the CBInfo info
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600469 if (result == VK_TRUE) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500470 if (cbMap.find(cb) != cbMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500471 MT_CB_INFO* pDelInfo = cbMap[cb];
472 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500473 cbMap.erase(cb);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600474 }
Ian Elliott81ac44c2015-01-13 17:52:38 -0700475 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600476 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700477}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600478
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700479// Delete the entire CB list
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500480static bool32_t deleteCBInfoList()
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700481{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600482 bool32_t result = VK_TRUE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600483 for (map<VkCmdBuffer, MT_CB_INFO*>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500484 freeCBBindings((*ii).first);
485 delete (*ii).second;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700486 }
487 return result;
488}
489
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500490// For given MemObjInfo, report Obj & CB bindings
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500491static void reportMemReferences(const MT_MEM_OBJ_INFO* pMemObjInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700492{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600493 uint32_t refCount = 0; // Count found references
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500494
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600495 for (list<VkCmdBuffer>::const_iterator it = pMemObjInfo->pCmdBufferBindings.begin(); it != pMemObjInfo->pCmdBufferBindings.end(); ++it) {
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700496 refCount++;
Tobin Ehlis62086412014-11-19 16:19:28 -0700497 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500498 sprintf(str, "Command Buffer %p has reference to mem obj %p", (*it), pMemObjInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600499 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (*it), 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700500 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600501 for (list<VkObject>::const_iterator it = pMemObjInfo->pObjBindings.begin(); it != pMemObjInfo->pObjBindings.end(); ++it) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700502 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600503 sprintf(str, "VK Object %p has reference to mem obj %p", (*it), pMemObjInfo->mem);
504 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (*it), 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700505 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500506 if (refCount != pMemObjInfo->refCount) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700507 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500508 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 -0600509 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pMemObjInfo->mem, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700510 }
511}
512
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600513static void deleteMemObjInfo(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700514{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500515 MT_MEM_OBJ_INFO* pDelInfo = memObjMap[mem];
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500516 if (memObjMap.find(mem) != memObjMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500517 MT_MEM_OBJ_INFO* pDelInfo = memObjMap[mem];
518 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500519 memObjMap.erase(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700520 }
521}
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500522
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700523// Check if fence for given CB is completed
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600524static bool32_t checkCBCompleted(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700525{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600526 bool32_t result = VK_TRUE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500527 MT_CB_INFO* pCBInfo = getCBInfo(cb);
528 if (!pCBInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700529 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500530 sprintf(str, "Unable to find global CB info %p to check for completion", cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600531 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
532 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600533 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500534 if (!fenceRetired(pCBInfo->fenceId)) {
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600535 char str[1024];
536 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 -0600537 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_NONE, "MEM", str);
538 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600539 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700540 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600541 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700542}
543
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600544static bool32_t freeMemObjInfo(VkGpuMemory mem, bool internal)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700545{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600546 bool32_t result = VK_TRUE;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500547 // Parse global list to find info w/ mem
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500548 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
549 if (!pInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700550 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500551 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 -0600552 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
553 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600554 } else {
Courtney Goeltzenleuchterc4804862015-03-26 16:15:39 -0600555 if (pInfo->allocInfo.allocationSize == 0 && !internal) {
Mark Lobodzinskidaa1d432015-02-18 18:06:24 -0600556 char str[1024];
557 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 -0600558 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
559 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600560 } else {
561 // Clear any CB bindings for completed CBs
562 // TODO : Is there a better place to do this?
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500563
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600564 list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin();
565 list<VkCmdBuffer>::iterator temp;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500566 while (it != pInfo->pCmdBufferBindings.end()) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600567 if (VK_TRUE == checkCBCompleted(*it)) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500568 temp = it;
569 ++temp;
570 freeCBBindings(*it);
571 it = temp;
572 } else {
573 ++it;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600574 }
575 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500576
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600577 // Now verify that no references to this mem obj remain
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500578 if (0 != pInfo->refCount) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500579 // If references remain, report the error and can search CB list to find references
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600580 char str[1024];
581 sprintf(str, "Freeing mem obj %p while it still has references", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600582 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_FREED_MEM_REF, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500583 reportMemReferences(pInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600584 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600585 }
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600586 // Delete mem obj info
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500587 deleteMemObjInfo(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700588 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700589 }
590 return result;
591}
592
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700593// Remove object binding performs 3 tasks:
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500594// 1. Remove ObjectInfo from MemObjInfo list container of obj bindings & free it
595// 2. Decrement refCount for MemObjInfo
596// 3. Clear MemObjInfo ptr from ObjectInfo
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600597static bool32_t clearObjectBinding(VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700598{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600599 bool32_t result = VK_FALSE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500600 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
601 if (!pObjInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700602 char str[1024];
Mark Lobodzinski15427102015-02-18 16:38:17 -0600603 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 -0600604 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600605 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500606 if (!pObjInfo->pMemObjInfo) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600607 char str[1024];
608 sprintf(str, "Attempting to clear mem binding on obj %p but it has no binding.", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600609 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 -0600610 } else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600611 for (list<VkObject>::iterator it = pObjInfo->pMemObjInfo->pObjBindings.begin(); it != pObjInfo->pMemObjInfo->pObjBindings.end(); ++it) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500612 pObjInfo->pMemObjInfo->refCount--;
613 pObjInfo->pMemObjInfo = NULL;
614 it = pObjInfo->pMemObjInfo->pObjBindings.erase(it);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600615 result = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500616 break;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600617 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600618 if (result == VK_FALSE) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600619 char str[1024];
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500620 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 -0500621 object, pObjInfo->pMemObjInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600622 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600623 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700624 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700625 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600626 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700627}
628
629// For NULL mem case, clear any previous binding Else...
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500630// Make sure given object is in global object map
Tobin Ehlis62086412014-11-19 16:19:28 -0700631// IF a previous binding existed, clear it
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500632// Add reference from objectInfo to memoryInfo
633// Add reference off of objInfo
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600634// Return VK_TRUE if addition is successful, VK_FALSE otherwise
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600635static bool32_t updateObjectBinding(VkObject object, VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700636{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600637 bool32_t result = VK_FALSE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700638 // Handle NULL case separately, just clear previous binding & decrement reference
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600639 if (mem == VK_NULL_HANDLE) {
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700640 clearObjectBinding(object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600641 result = VK_TRUE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600642 } else {
643 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500644 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
645 if (!pObjInfo) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600646 sprintf(str, "Attempting to update Binding of Obj(%p) that's not in global list()", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600647 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
648 return VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600649 }
650 // non-null case so should have real mem obj
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500651 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
652 if (!pInfo) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500653 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 -0600654 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600655 } else {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500656 // Search for object in memory object's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600657 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600658 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500659 if ((*it) == object) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600660 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500661 break;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600662 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600663 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500664 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600665 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500666 pInfo->pObjBindings.push_front(object);
667 pInfo->refCount++;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500668 }
669
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500670 if (pObjInfo->pMemObjInfo) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500671 clearObjectBinding(object); // Need to clear the previous object binding before setting new binding
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500672 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 -0600673 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500674 }
675 // For image objects, make sure default memory state is correctly set
676 // TODO : What's the best/correct way to handle this?
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600677 if (VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO == pObjInfo->sType) {
678 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 -0500679 // TODO:: More memory state transition stuff.
680 }
681 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500682 pObjInfo->pMemObjInfo = pInfo;
Tobin Ehlis6aa77422015-01-07 17:49:29 -0700683 }
684 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600685 return VK_TRUE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700686}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600687
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700688// Print details of global Obj tracking list
689static void printObjList()
690{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500691 MT_OBJ_INFO* pInfo = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500692 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500693 sprintf(str, "Details of Object list of size %lu elements", objectMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600694 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600695 for (map<VkObject, MT_OBJ_INFO*>::iterator ii=objectMap.begin(); ii!=objectMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500696 pInfo = (*ii).second;
697 sprintf(str, " ObjInfo %p has object %p, pMemObjInfo %p", pInfo, pInfo->object, pInfo->pMemObjInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600698 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pInfo->object, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700699 }
700}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600701
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700702// For given Object, get 'mem' obj that it's bound to or NULL if no binding
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600703static VkGpuMemory getMemBindingFromObject(const VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700704{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600705 VkGpuMemory mem = NULL;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500706 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
707 if (pObjInfo) {
708 if (pObjInfo->pMemObjInfo) {
709 mem = pObjInfo->pMemObjInfo->mem;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700710 }
711 else {
Tobin Ehlis62086412014-11-19 16:19:28 -0700712 char str[1024];
713 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 -0600714 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MISSING_MEM_BINDINGS, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700715 printObjList();
716 }
717 }
718 else {
Tobin Ehlis62086412014-11-19 16:19:28 -0700719 char str[1024];
720 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 -0600721 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700722 printObjList();
723 }
724 return mem;
725}
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500726
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500727// Print details of MemObjInfo list
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700728static void printMemList()
729{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500730 MT_MEM_OBJ_INFO* pInfo = NULL;
Tobin Ehlis62086412014-11-19 16:19:28 -0700731 // Just printing each msg individually for now, may want to package these into single large print
732 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500733 sprintf(str, "MEM INFO : Details of Memory Object list of size %lu elements", memObjMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600734 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500735
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600736 for (map<VkGpuMemory, MT_MEM_OBJ_INFO*>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500737 pInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500738
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500739 sprintf(str, " ===MemObjInfo at %p===", (void*)pInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600740 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500741 sprintf(str, " Mem object: %p", (void*)pInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600742 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500743 sprintf(str, " Ref Count: %u", pInfo->refCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600744 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500745 if (0 != pInfo->allocInfo.allocationSize) {
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600746 string pAllocInfoMsg = vk_print_vkmemoryallocinfo(&pInfo->allocInfo, "{MEM}INFO : ");
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500747 sprintf(str, " Mem Alloc info:\n%s", pAllocInfoMsg.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600748 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500749 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600750 sprintf(str, " Mem Alloc info is NULL (alloc done by vkWsiX11CreatePresentableImage())");
751 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500752 }
753
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600754 sprintf(str, " VK OBJECT Binding list of size %lu elements:", pInfo->pObjBindings.size());
755 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600756 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600757 sprintf(str, " VK OBJECT %p", (*it));
758 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500759 }
760
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600761 sprintf(str, " VK Command Buffer (CB) binding list of size %lu elements", pInfo->pCmdBufferBindings.size());
762 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600763 for (list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin(); it != pInfo->pCmdBufferBindings.end(); ++it) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600764 sprintf(str, " VK CB %p", (*it));
765 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700766 }
767 }
768}
769
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500770static void printCBList()
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700771{
Tobin Ehlis62086412014-11-19 16:19:28 -0700772 char str[1024] = {0};
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500773 MT_CB_INFO* pCBInfo = NULL;
774 sprintf(str, "Details of CB list of size %lu elements", cbMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600775 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500776
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600777 for (map<VkCmdBuffer, MT_CB_INFO*>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500778 pCBInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500779
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500780 sprintf(str, " CB Info (%p) has CB %p, fenceId %" PRIx64", and fence %p",
781 (void*)pCBInfo, (void*)pCBInfo->cmdBuffer, pCBInfo->fenceId,
782 (void*)getFenceFromId(pCBInfo->fenceId));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600783 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500784
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600785 for (list<VkGpuMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500786 sprintf(str, " Mem obj %p", (*it));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600787 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700788 }
789 }
790}
791
Mark Lobodzinski15427102015-02-18 16:38:17 -0600792static void initMemTracker(void)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700793{
Jon Ashburnf57ea372014-12-22 13:24:15 -0700794 const char *strOpt;
795 // initialize MemTracker options
Ian Elliott7d0b5d22015-03-06 13:50:05 -0700796 getLayerOptionEnum("MemTrackerReportLevel", (uint32_t *) &g_reportingLevel);
797 g_actionIsDefault = getLayerOptionEnum("MemTrackerDebugAction", (uint32_t *) &g_debugAction);
Tobin Ehlis5b7acaa2015-01-08 14:26:53 -0700798
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600799 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Jon Ashburnf57ea372014-12-22 13:24:15 -0700800 {
801 strOpt = getLayerOption("MemTrackerLogFilename");
802 if (strOpt)
803 {
804 g_logFile = fopen(strOpt, "w");
Jon Ashburnf57ea372014-12-22 13:24:15 -0700805 }
806 if (g_logFile == NULL)
807 g_logFile = stdout;
808 }
809
810 // initialize Layer dispatch table
811 // TODO handle multiple GPUs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600812 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700813 fpNextGPA = pCurObj->pGPA;
814 assert(fpNextGPA);
815
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600816 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalGpu) pCurObj->nextObject);
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800817
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600818 PFN_vkGetProcAddr fpGetProcAddr = (PFN_vkGetProcAddr)fpNextGPA((VkPhysicalGpu) pCurObj->nextObject, (char *) "vkGetProcAddr");
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700819 nextTable.GetProcAddr = fpGetProcAddr;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600820
821 if (!globalLockInitialized)
822 {
823 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600824 // suggestion is to call this during vkCreateInstance(), and then we
825 // can clean it up during vkDestroyInstance(). However, that requires
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600826 // that the layer have per-instance locks. We need to come back and
827 // address this soon.
828 loader_platform_thread_create_mutex(&globalLock);
829 globalLockInitialized = 1;
830 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700831}
832
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600833VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700834{
Jon Ashburn630e44f2015-04-08 21:33:34 -0600835 pCurObj = (VkBaseLayerObject *) gpu;
Ian Elliott81ac44c2015-01-13 17:52:38 -0700836 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburn630e44f2015-04-08 21:33:34 -0600837 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700838 // Save off device in case we need it to create Fences
839 globalDevice = *pDevice;
840 return result;
841}
842
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600843VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700844{
Tobin Ehlis62086412014-11-19 16:19:28 -0700845 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600846 sprintf(str, "Printing List details prior to vkDestroyDevice()");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600847 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600848 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, device, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700849 printMemList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500850 printCBList();
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700851 printObjList();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600852 if (VK_FALSE == deleteCBInfoList()) {
853 sprintf(str, "Issue deleting global CB list in vkDestroyDevice()");
854 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, device, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -0700855 }
Tobin Ehlis22d03232014-11-25 18:01:12 -0700856 // Report any memory leaks
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500857 MT_MEM_OBJ_INFO* pInfo = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600858 for (map<VkGpuMemory, MT_MEM_OBJ_INFO*>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500859 pInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500860
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500861 if (pInfo->allocInfo.allocationSize != 0) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600862 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 -0500863 pInfo->mem, pInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600864 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, pInfo->mem, 0, MEMTRACK_MEMORY_LEAK, "MEM", str);
Mark Lobodzinskidaa1d432015-02-18 18:06:24 -0600865 }
Tobin Ehlis22d03232014-11-25 18:01:12 -0700866 }
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500867
868 // Queues persist until device is destroyed
869 deleteQueueInfoList();
870
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600871 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600872 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700873 return result;
874}
875
Jon Ashburneb2728b2015-04-10 14:33:07 -0600876struct extProps {
877 uint32_t version;
878 const char * const name;
879};
Jon Ashburnbdcd7562015-04-14 14:12:59 -0600880#define MEM_TRACKER_LAYER_EXT_ARRAY_SIZE 2
Jon Ashburneb2728b2015-04-10 14:33:07 -0600881static const struct extProps mtExts[MEM_TRACKER_LAYER_EXT_ARRAY_SIZE] = {
882 // TODO what is the version?
Jon Ashburnbdcd7562015-04-14 14:12:59 -0600883 0x10, "MemTracker",
884 0x10, "Validation"
Jon Ashburneb2728b2015-04-10 14:33:07 -0600885};
886
887VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
888 VkExtensionInfoType infoType,
889 uint32_t extensionIndex,
890 size_t* pDataSize,
891 void* pData)
892{
893 VkResult result;
894
895 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
896 VkExtensionProperties *ext_props;
897 uint32_t *count;
898
899 if (pDataSize == NULL)
900 return VK_ERROR_INVALID_POINTER;
901
902 switch (infoType) {
903 case VK_EXTENSION_INFO_TYPE_COUNT:
904 *pDataSize = sizeof(uint32_t);
905 if (pData == NULL)
906 return VK_SUCCESS;
907 count = (uint32_t *) pData;
908 *count = MEM_TRACKER_LAYER_EXT_ARRAY_SIZE;
909 break;
910 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
911 *pDataSize = sizeof(VkExtensionProperties);
912 if (pData == NULL)
913 return VK_SUCCESS;
914 if (extensionIndex >= MEM_TRACKER_LAYER_EXT_ARRAY_SIZE)
915 return VK_ERROR_INVALID_VALUE;
916 ext_props = (VkExtensionProperties *) pData;
917 ext_props->version = mtExts[extensionIndex].version;
918 strncpy(ext_props->extName, mtExts[extensionIndex].name,
919 VK_MAX_EXTENSION_NAME);
920 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
921 break;
922 default:
923 return VK_ERROR_INVALID_VALUE;
924 };
925
926 return VK_SUCCESS;
927}
928
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600929VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName)
Jon Ashburn25566352015-04-02 12:06:28 -0600930{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600931 VkResult result;
Jon Ashburn25566352015-04-02 12:06:28 -0600932 /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */
933 if (!strcmp(pExtName, "MemTracker"))
934 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600935 result = VK_SUCCESS;
Jon Ashburn25566352015-04-02 12:06:28 -0600936 } else if (nextTable.GetExtensionSupport != NULL)
937 {
Jon Ashburn630e44f2015-04-08 21:33:34 -0600938 result = nextTable.GetExtensionSupport(gpu, pExtName);
Jon Ashburn25566352015-04-02 12:06:28 -0600939 } else
940 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600941 result = VK_ERROR_INVALID_EXTENSION;
Jon Ashburn25566352015-04-02 12:06:28 -0600942 }
943 return result;
944}
945
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600946VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalGpu gpu, size_t maxLayerCount,
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500947 size_t maxStringSize, size_t* pOutLayerCount, char* const* pOutLayers, void* pReserved)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700948{
Jon Ashburn451c16f2014-11-25 11:08:42 -0700949 if (gpu != NULL)
950 {
Jon Ashburn630e44f2015-04-08 21:33:34 -0600951 pCurObj = (VkBaseLayerObject *) gpu;
Ian Elliott81ac44c2015-01-13 17:52:38 -0700952 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburn630e44f2015-04-08 21:33:34 -0600953 VkResult result = nextTable.EnumerateLayers(gpu, maxLayerCount,
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500954 maxStringSize, pOutLayerCount, pOutLayers, pReserved);
Jon Ashburn451c16f2014-11-25 11:08:42 -0700955 return result;
956 } else
957 {
958 if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600959 return VK_ERROR_INVALID_POINTER;
Jon Ashburn451c16f2014-11-25 11:08:42 -0700960 // This layer compatible with all GPUs
961 *pOutLayerCount = 1;
Chia-I Wua837c522014-12-16 10:47:33 +0800962 strncpy((char *) pOutLayers[0], "MemTracker", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600963 return VK_SUCCESS;
Jon Ashburn451c16f2014-11-25 11:08:42 -0700964 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700965}
966
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600967VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueNodeIndex, uint32_t queueIndex, VkQueue* pQueue)
Mark Lobodzinski55e53d92015-03-31 16:05:35 -0500968{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600969 VkResult result = nextTable.GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600970 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500971 loader_platform_thread_lock_mutex(&globalLock);
972 addQueueInfo(*pQueue);
973 loader_platform_thread_unlock_mutex(&globalLock);
974 }
Mark Lobodzinski55e53d92015-03-31 16:05:35 -0500975 return result;
976}
977
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600978VK_LAYER_EXPORT VkResult VKAPI vkQueueAddMemReference(VkQueue queue, VkGpuMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500979{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600980 VkResult result = nextTable.QueueAddMemReference(queue, mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600981 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500982 loader_platform_thread_lock_mutex(&globalLock);
983
984 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
985 if (pQueueInfo == NULL) {
986 char str[1024];
987 sprintf(str, "Unknown Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600988 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500989 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500990 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600991 if (checkMemRef(queue, mem) == VK_TRUE) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500992 // Alread in list, just warn
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500993 char str[1024];
994 sprintf(str, "Request to add a memory reference (%p) to Queue %p -- ref is already present in the queue's reference list", mem, queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600995 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500996 }
997 else {
998 // Add to queue's memory reference list
999 pQueueInfo->pMemRefList.push_front(mem);
1000 }
1001 }
1002 loader_platform_thread_unlock_mutex(&globalLock);
1003 }
1004 return result;
1005}
1006
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001007VK_LAYER_EXPORT VkResult VKAPI vkQueueRemoveMemReference(VkQueue queue, VkGpuMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001008{
1009 // TODO : Decrement ref count for this memory reference on this queue. Remove if ref count is zero.
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001010 VkResult result = nextTable.QueueRemoveMemReference(queue, mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001011 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001012 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001013
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001014 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
1015 if (pQueueInfo == NULL) {
1016 char str[1024];
1017 sprintf(str, "Unknown Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001018 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001019 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001020 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001021 for (list<VkGpuMemory>::iterator it = pQueueInfo->pMemRefList.begin(); it != pQueueInfo->pMemRefList.end(); ++it) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001022 if ((*it) == mem) {
1023 it = pQueueInfo->pMemRefList.erase(it);
1024 }
1025 }
1026 }
1027 loader_platform_thread_unlock_mutex(&globalLock);
1028 }
1029 return result;
1030}
1031
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001032VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(
1033 VkQueue queue,
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001034 uint32_t cmdBufferCount,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001035 const VkCmdBuffer *pCmdBuffers,
1036 VkFence fence)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001037{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001038 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001039 // TODO : Need to track fence and clear mem references when fence clears
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001040 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001041 uint64_t fenceId = addFenceInfo(fence, queue);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001042
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001043 printMemList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001044 printCBList();
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001045 for (uint32_t i = 0; i < cmdBufferCount; i++) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001046 pCBInfo = getCBInfo(pCmdBuffers[i]);
1047 pCBInfo->fenceId = fenceId;
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001048 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001049
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001050 if (VK_FALSE == validateQueueMemRefs(queue, cmdBufferCount, pCmdBuffers)) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001051 char str[1024];
1052 sprintf(str, "Unable to verify memory references for Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001053 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001054 }
1055
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001056 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001057 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, getFenceFromId(fenceId));
Courtney Goeltzenleuchtercfedf362015-04-02 13:39:07 -06001058 return result;
1059}
1060
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001061VK_LAYER_EXPORT VkResult VKAPI vkAllocMemory(VkDevice device, const VkMemoryAllocInfo* pAllocInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001062{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001063 VkResult result = nextTable.AllocMemory(device, pAllocInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001064 // TODO : Track allocations and overall size here
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001065 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001066 addMemObjInfo(*pMem, pAllocInfo);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001067 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001068 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001069 return result;
1070}
1071
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001072VK_LAYER_EXPORT VkResult VKAPI vkFreeMemory(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001073{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001074 /* From spec : A memory object is freed by calling vkFreeMemory() when it is no longer needed. Before
Tobin Ehlisa747e682014-11-25 14:47:20 -07001075 * freeing a memory object, an application must ensure the memory object is unbound from
1076 * all API objects referencing it and that it is not referenced by any queued command buffers
1077 */
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001078 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001079 if (VK_FALSE == freeMemObjInfo(mem, false)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001080 char str[1024];
1081 sprintf(str, "Issue while freeing mem obj %p", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001082 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_FREE_MEM_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001083 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001084 printMemList();
1085 printObjList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001086 printCBList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001087 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001088 VkResult result = nextTable.FreeMemory(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001089 return result;
1090}
1091
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001092VK_LAYER_EXPORT VkResult VKAPI vkSetMemoryPriority(VkGpuMemory mem, VkMemoryPriority priority)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001093{
1094 // TODO : Update tracking for this alloc
1095 // Make sure memory is not pinned, which can't have priority set
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001096 VkResult result = nextTable.SetMemoryPriority(mem, priority);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001097 return result;
1098}
1099
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001100VK_LAYER_EXPORT VkResult VKAPI vkMapMemory(VkGpuMemory mem, VkFlags flags, void** ppData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001101{
1102 // TODO : Track when memory is mapped
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001103 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001104 MT_MEM_OBJ_INFO *pMemObj = getMemObjInfo(mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001105 if ((pMemObj->allocInfo.memProps & VK_MEMORY_PROPERTY_CPU_VISIBLE_BIT) == 0) {
Mark Lobodzinski06f60b82015-02-25 12:16:04 -06001106 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001107 sprintf(str, "Mapping Memory (%p) without VK_MEMORY_PROPERTY_CPU_VISIBLE_BIT set", (void*)mem);
1108 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_STATE, "MEM", str);
Mark Lobodzinski06f60b82015-02-25 12:16:04 -06001109 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001110 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001111 VkResult result = nextTable.MapMemory(mem, flags, ppData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001112 return result;
1113}
1114
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001115VK_LAYER_EXPORT VkResult VKAPI vkUnmapMemory(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001116{
1117 // TODO : Track as memory gets unmapped, do we want to check what changed following map?
1118 // Make sure that memory was ever mapped to begin with
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001119 VkResult result = nextTable.UnmapMemory(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001120 return result;
1121}
1122
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001123VK_LAYER_EXPORT VkResult VKAPI vkPinSystemMemory(VkDevice device, const void* pSysMem, size_t memSize, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001124{
1125 // TODO : Track this
1126 // Verify that memory is actually pinnable
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001127 VkResult result = nextTable.PinSystemMemory(device, pSysMem, memSize, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001128 return result;
1129}
1130
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001131VK_LAYER_EXPORT VkResult VKAPI vkOpenSharedMemory(VkDevice device, const VkMemoryOpenInfo* pOpenInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001132{
1133 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001134 VkResult result = nextTable.OpenSharedMemory(device, pOpenInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001135 return result;
1136}
1137
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001138VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerMemory(VkDevice device, const VkPeerMemoryOpenInfo* pOpenInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001139{
1140 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001141 VkResult result = nextTable.OpenPeerMemory(device, pOpenInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001142 return result;
1143}
1144
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001145VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerImage(VkDevice device, const VkPeerImageOpenInfo* pOpenInfo, VkImage* pImage, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001146{
1147 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001148 VkResult result = nextTable.OpenPeerImage(device, pOpenInfo, pImage, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001149 return result;
1150}
1151
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001152VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001153{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001154 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001155
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001156 // First check if this is a CmdBuffer
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001157 if (NULL != getCBInfo((VkCmdBuffer)object)) {
1158 deleteCBInfo((VkCmdBuffer)object);
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001159 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001160
1161 if (objectMap.find(object) != objectMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001162 MT_OBJ_INFO* pDelInfo = objectMap[object];
1163 if (pDelInfo->pMemObjInfo) {
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001164 // Wsi allocated Memory is tied to image object so clear the binding and free that memory automatically
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001165 if (0 == pDelInfo->pMemObjInfo->allocInfo.allocationSize) { // Wsi allocated memory has NULL allocInfo w/ 0 size
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001166 VkGpuMemory memToFree = pDelInfo->pMemObjInfo->mem;
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001167 clearObjectBinding(object);
Courtney Goeltzenleuchterc4804862015-03-26 16:15:39 -06001168 freeMemObjInfo(memToFree, true);
1169 }
1170 else {
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001171 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001172 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);
1173 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_DESTROY_OBJECT_ERROR, "MEM", str);
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001174 // From the spec : If an object has previous memory binding, it is required to unbind memory from an API object before it is destroyed.
1175 clearObjectBinding(object);
1176 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001177 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001178 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001179 objectMap.erase(object);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001180 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001181
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001182 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001183 VkResult result = nextTable.DestroyObject(object);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001184 return result;
1185}
1186
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001187VK_LAYER_EXPORT VkResult VKAPI vkGetObjectInfo(VkBaseObject object, VkObjectInfoType infoType, size_t* pDataSize, void* pData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001188{
1189 // TODO : What to track here?
1190 // Could potentially save returned mem requirements and validate values passed into BindObjectMemory for this object
Tobin Ehlis62086412014-11-19 16:19:28 -07001191 // 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 -06001192 VkResult result = nextTable.GetObjectInfo(object, infoType, pDataSize, pData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001193 return result;
1194}
1195
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001196VK_LAYER_EXPORT VkResult VKAPI vkBindObjectMemory(VkObject object, uint32_t allocationIdx, VkGpuMemory mem, VkGpuSize offset)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001197{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001198 VkResult result = nextTable.BindObjectMemory(object, allocationIdx, mem, offset);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001199 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001200 // Track objects tied to memory
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001201 if (VK_FALSE == updateObjectBinding(object, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001202 char str[1024];
1203 sprintf(str, "Unable to set object %p binding to mem obj %p", (void*)object, (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001204 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001205 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001206 printObjList();
1207 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001208 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001209 return result;
1210}
1211
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001212VK_LAYER_EXPORT VkResult VKAPI vkCreateFence(VkDevice device, const VkFenceCreateInfo* pCreateInfo, VkFence* pFence)
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001213{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001214 VkResult result = nextTable.CreateFence(device, pCreateInfo, pFence);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001215 if (VK_SUCCESS == result) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001216 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001217 addObjectInfo(*pFence, pCreateInfo->sType, pCreateInfo, sizeof(VkFenceCreateInfo), "fence");
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001218 loader_platform_thread_unlock_mutex(&globalLock);
1219 }
1220 return result;
1221}
1222
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001223VK_LAYER_EXPORT VkResult VKAPI vkResetFences(VkDevice device, uint32_t fenceCount, VkFence* pFences)
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001224{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001225 VkResult result = nextTable.ResetFences(device, fenceCount, pFences);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001226 if (VK_SUCCESS == result) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001227 loader_platform_thread_lock_mutex(&globalLock);
1228 // Reset fence state in fenceCreateInfo structure
1229 for (uint32_t i = 0; i < fenceCount; i++) {
1230 MT_OBJ_INFO* pObjectInfo = getObjectInfo(pFences[i]);
1231 if (pObjectInfo != NULL) {
Mark Lobodzinski56945182015-04-09 13:46:09 -05001232 // Validate fences in SIGNALED state
Tobin Ehlisf29da382015-04-15 07:46:12 -06001233 if (!(pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT)) {
Mark Lobodzinski56945182015-04-09 13:46:09 -05001234 char str[1024];
Mark Lobodzinski610be622015-04-14 14:09:32 -05001235 sprintf(str, "Fence %p submitted to VkResetFences in UNSIGNALED STATE", pFences[i]);
Tobin Ehlisf29da382015-04-15 07:46:12 -06001236 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
1237 result = VK_ERROR_INVALID_VALUE;
Mark Lobodzinski56945182015-04-09 13:46:09 -05001238 }
1239 else {
1240 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisf29da382015-04-15 07:46:12 -06001241 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags & ~VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinski56945182015-04-09 13:46:09 -05001242 }
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001243 }
1244 }
1245 loader_platform_thread_unlock_mutex(&globalLock);
1246 }
1247 return result;
1248}
1249
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001250VK_LAYER_EXPORT VkResult VKAPI vkGetFenceStatus(VkFence fence)
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001251{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001252 VkResult result = nextTable.GetFenceStatus(fence);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001253 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001254 loader_platform_thread_lock_mutex(&globalLock);
1255 updateFenceTracking(fence);
1256 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001257 }
1258 return result;
1259}
1260
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001261VK_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 -07001262{
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001263 // Verify fence status of submitted fences
1264 for(uint32_t i = 0; i < fenceCount; i++) {
1265 MT_OBJ_INFO* pObjectInfo = getObjectInfo(pFences[i]);
1266 if (pObjectInfo != NULL) {
Tobin Ehlisf29da382015-04-15 07:46:12 -06001267 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001268 char str[1024];
Mark Lobodzinski610be622015-04-14 14:09:32 -05001269 sprintf(str, "VkWaitForFences specified fence %p already in SIGNALED state.", pFences[i]);
Tobin Ehlisf29da382015-04-15 07:46:12 -06001270 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001271 }
1272 }
1273 }
1274
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001275 VkResult result = nextTable.WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001276 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001277
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001278 if (VK_SUCCESS == result) {
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001279 if (waitAll || fenceCount == 1) { // Clear all the fences
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001280 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001281 updateFenceTracking(pFences[i]);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001282 }
1283 }
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001284 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001285 loader_platform_thread_unlock_mutex(&globalLock);
1286 return result;
1287}
1288
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001289VK_LAYER_EXPORT VkResult VKAPI vkQueueWaitIdle(VkQueue queue)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001290{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001291 VkResult result = nextTable.QueueWaitIdle(queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001292 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001293 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001294 retireQueueFences(queue);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001295 loader_platform_thread_unlock_mutex(&globalLock);
1296 }
1297 return result;
1298}
1299
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001300VK_LAYER_EXPORT VkResult VKAPI vkDeviceWaitIdle(VkDevice device)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001301{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001302 VkResult result = nextTable.DeviceWaitIdle(device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001303 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001304 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001305 retireDeviceFences(device);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001306 loader_platform_thread_unlock_mutex(&globalLock);
1307 }
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001308 return result;
1309}
1310
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001311VK_LAYER_EXPORT VkResult VKAPI vkCreateEvent(VkDevice device, const VkEventCreateInfo* pCreateInfo, VkEvent* pEvent)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001312{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001313 VkResult result = nextTable.CreateEvent(device, pCreateInfo, pEvent);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001314 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001315 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001316 addObjectInfo(*pEvent, pCreateInfo->sType, pCreateInfo, sizeof(VkEventCreateInfo), "event");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001317 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001318 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001319 return result;
1320}
1321
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001322VK_LAYER_EXPORT VkResult VKAPI vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, VkQueryPool* pQueryPool)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001323{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001324 VkResult result = nextTable.CreateQueryPool(device, pCreateInfo, pQueryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001325 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001326 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001327 addObjectInfo(*pQueryPool, pCreateInfo->sType, pCreateInfo, sizeof(VkQueryPoolCreateInfo), "query_pool");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001328 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001329 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001330 return result;
1331}
1332
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001333VK_LAYER_EXPORT VkResult VKAPI vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, VkBuffer* pBuffer)
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001334{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001335 VkResult result = nextTable.CreateBuffer(device, pCreateInfo, pBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001336 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001337 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001338 addObjectInfo(*pBuffer, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferCreateInfo), "buffer");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001339 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001340 }
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001341 return result;
1342}
1343
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001344VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001345{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001346 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001347 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001348 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001349 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferViewCreateInfo), "buffer_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001350 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001351 }
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001352 return result;
1353}
1354
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001355VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, VkImage* pImage)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001356{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001357 VkResult result = nextTable.CreateImage(device, pCreateInfo, pImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001358 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001359 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001360 addObjectInfo(*pImage, pCreateInfo->sType, pCreateInfo, sizeof(VkImageCreateInfo), "image");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001361 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001362 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001363 return result;
1364}
1365
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001366VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001367{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001368 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001369 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001370 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001371 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkImageViewCreateInfo), "image_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001372 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001373 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001374 return result;
1375}
1376
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001377VK_LAYER_EXPORT VkResult VKAPI vkCreateColorAttachmentView(VkDevice device, const VkColorAttachmentViewCreateInfo* pCreateInfo,
1378 VkColorAttachmentView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001379{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001380 VkResult result = nextTable.CreateColorAttachmentView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001381 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001382 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001383 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkColorAttachmentViewCreateInfo), "color_attachment_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001384 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001385 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001386 return result;
1387}
1388
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001389VK_LAYER_EXPORT VkResult VKAPI vkCreateDepthStencilView(VkDevice device, const VkDepthStencilViewCreateInfo* pCreateInfo, VkDepthStencilView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001390{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001391 VkResult result = nextTable.CreateDepthStencilView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001392 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001393 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001394 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkDepthStencilViewCreateInfo), "ds_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001395 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001396 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001397 return result;
1398}
1399
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001400VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(VkDevice device, const VkShaderCreateInfo* pCreateInfo, VkShader* pShader)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001401{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001402 VkResult result = nextTable.CreateShader(device, pCreateInfo, pShader);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001403 return result;
1404}
1405
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001406VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001407{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001408 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001409 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001410 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001411 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001412 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001413 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001414 return result;
1415}
1416
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001417VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1418 VkDevice device,
1419 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1420 VkPipeline basePipeline,
1421 VkPipeline* pPipeline)
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001422{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001423 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001424 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001425 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001426 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001427 loader_platform_thread_unlock_mutex(&globalLock);
1428 }
1429 return result;
1430}
1431
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001432VK_LAYER_EXPORT VkResult VKAPI vkCreateComputePipeline(VkDevice device, const VkComputePipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001433{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001434 VkResult result = nextTable.CreateComputePipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001435 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001436 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001437 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkComputePipelineCreateInfo), "compute_pipeline");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001438 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001439 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001440 return result;
1441}
1442
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001443VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001444{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001445 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001446 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001447 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001448 addObjectInfo(*pSampler, pCreateInfo->sType, pCreateInfo, sizeof(VkSamplerCreateInfo), "sampler");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001449 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001450 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001451 return result;
1452}
1453
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001454VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001455 VkDynamicVpState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001456{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001457 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001458 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001459 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001460 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo), "viewport_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001461 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001462 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001463 return result;
1464}
1465
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001466VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001467 VkDynamicRsState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001468{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001469 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001470 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001471 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001472 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo), "raster_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001473 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001474 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001475 return result;
1476}
1477
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001478VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001479 VkDynamicCbState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001480{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001481 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001482 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001483 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001484 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo), "cb_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001485 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001486 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001487 return result;
1488}
1489
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001490VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001491 VkDynamicDsState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001492{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001493 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001494 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001495 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001496 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo), "ds_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001497 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001498 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001499 return result;
1500}
1501
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001502VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001503{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001504 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001505 // At time of cmd buffer creation, create global cmd buffer info for the returned cmd buffer
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001506 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001507 if (*pCmdBuffer)
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001508 addCBInfo(*pCmdBuffer);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001509 printCBList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001510 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001511 return result;
1512}
1513
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001514VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001515{
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001516 // 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 -05001517 MT_CB_INFO* pCBInfo = getCBInfo(cmdBuffer);
1518 if (pCBInfo && (!fenceRetired(pCBInfo->fenceId))) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001519 bool32_t cbDone = checkCBCompleted(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001520 if (VK_FALSE == cbDone) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001521 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001522 sprintf(str, "Calling vkBeginCommandBuffer() on active CB %p before it has completed. You must check CB flag before this call.", cmdBuffer);
1523 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 -07001524 }
1525 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001526 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001527 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001528 freeCBBindings(cmdBuffer);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001529 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001530 return result;
1531}
1532
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001533VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001534{
1535 // TODO : Anything to do here?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001536 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001537 return result;
1538}
1539
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001540VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001541{
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001542 // Verify that CB is complete (not in-flight)
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001543 MT_CB_INFO* pCBInfo = getCBInfo(cmdBuffer);
1544 if (pCBInfo && (!fenceRetired(pCBInfo->fenceId))) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001545 bool32_t cbDone = checkCBCompleted(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001546 if (VK_FALSE == cbDone) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001547 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001548 sprintf(str, "Resetting CB %p before it has completed. You must check CB flag before calling vkResetCommandBuffer().", cmdBuffer);
1549 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 -07001550 }
1551 }
1552 // Clear memory references as this point.
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001553 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001554 freeCBBindings(cmdBuffer);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001555 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001556 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001557 return result;
1558}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001559// TODO : For any vkCmdBind* calls that include an object which has mem bound to it,
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001560// need to account for that mem now having binding to given cmdBuffer
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001561VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001562{
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001563#if 0
1564 // TODO : If memory bound to pipeline, then need to tie that mem to cmdBuffer
1565 if (getPipeline(pipeline)) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001566 MT_CB_INFO *pCBInfo = getCBInfo(cmdBuffer);
1567 if (pCBInfo) {
1568 pCBInfo->pipelines[pipelineBindPoint] = pipeline;
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001569 } else {
1570 char str[1024];
1571 sprintf(str, "Attempt to bind Pipeline %p to non-existant command buffer %p!", (void*)pipeline, cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001572 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 -07001573 }
1574 }
1575 else {
1576 char str[1024];
1577 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001578 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 -07001579 }
1580#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001581 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1582}
1583
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001584VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001585{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001586 MT_OBJ_INFO *pObjInfo;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001587 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001588 MT_CB_INFO *pCmdBuf = getCBInfo(cmdBuffer);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001589 if (!pCmdBuf) {
1590 char str[1024];
1591 sprintf(str, "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001592 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_INVALID_CB, "DD", str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001593 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001594 pObjInfo = getObjectInfo(state);
1595 if (!pObjInfo) {
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001596 char str[1024];
1597 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001598 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, state, 0, MEMTRACK_INVALID_OBJECT, "DD", str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001599 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001600 pCmdBuf->pDynamicState[stateBindPoint] = pObjInfo;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001601 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001602 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001603}
1604
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001605VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001606 VkCmdBuffer cmdBuffer,
1607 VkPipelineBindPoint pipelineBindPoint,
1608 VkDescriptorSetLayoutChain layoutChain,
Mark Lobodzinski411f0612015-04-07 09:34:09 -05001609 uint32_t layoutChainSlot,
1610 uint32_t count,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001611 const VkDescriptorSet* pDescriptorSets,
Mark Lobodzinski411f0612015-04-07 09:34:09 -05001612 const uint32_t* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001613{
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001614 // 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 -06001615 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, layoutChain, layoutChainSlot, count, pDescriptorSets, pUserData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001616}
1617
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001618VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t binding)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001619{
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001620 nextTable.CmdBindVertexBuffer(cmdBuffer, buffer, offset, binding);
Chia-I Wufb5062e2015-01-05 13:42:56 +08001621}
1622
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001623VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, VkIndexType indexType)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001624{
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001625 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001626}
1627
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001628VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001629{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001630 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001631 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001632 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001633 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001634 sprintf(str, "In vkCmdDrawIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1635 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001636 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001637 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001638 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001639}
1640
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001641VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001642{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001643 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001644 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001645 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001646 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001647 sprintf(str, "In vkCmdDrawIndexedIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1648 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001649 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001650 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001651 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001652}
1653
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001654VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001655{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001656 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001657 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001658 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001659 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001660 sprintf(str, "In vkCmdDispatchIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1661 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001662 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001663 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001664 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001665}
1666
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001667VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer,
1668 uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001669{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001670 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001671 VkGpuMemory mem = getMemBindingFromObject(srcBuffer);
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 vkCmdCopyBuffer() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, 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 Lobodzinski15427102015-02-18 16:38:17 -06001677 mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001678 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001679 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001680 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1681 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001682 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001683 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001684 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001685}
1686
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001687VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
1688 VkImage srcImage, VkImageLayout srcImageLayout,
1689 VkImage destImage, VkImageLayout destImageLayout,
1690 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001691{
1692 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001693 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001694}
1695
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001696VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
1697 VkImage srcImage, VkImageLayout srcImageLayout,
1698 VkImage destImage, VkImageLayout destImageLayout,
1699 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchterb787a1e2015-03-08 17:02:18 -06001700{
1701 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001702 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Courtney Goeltzenleuchterb787a1e2015-03-08 17:02:18 -06001703}
1704
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001705VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
1706 VkBuffer srcBuffer,
1707 VkImage destImage, VkImageLayout destImageLayout,
1708 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001709{
1710 // TODO : Track this
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001711 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001712 VkGpuMemory mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001713 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001714 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001715 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1716 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001717 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001718
1719 mem = getMemBindingFromObject(srcBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001720 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001721 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001722 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
1723 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001724 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001725 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001726 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001727}
1728
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001729VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
1730 VkImage srcImage, VkImageLayout srcImageLayout,
1731 VkBuffer destBuffer,
1732 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001733{
1734 // TODO : Track this
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001735 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001736 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001737 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001738 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001739 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1740 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001741 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001742 mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001743 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001744 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001745 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1746 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001747 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001748 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001749 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001750}
1751
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001752VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout,
1753 VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001754{
1755 // TODO : Each image will have mem mapping so track them
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001756 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001757 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001758 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001759 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001760 sprintf(str, "In vkCmdCloneImageData() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1761 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001762 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001763 mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001764 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001765 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001766 sprintf(str, "In vkCmdCloneImageData() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1767 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001768 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001769 loader_platform_thread_unlock_mutex(&globalLock);
Mike Stroyan55658c22014-12-04 11:08:39 +00001770 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001771}
1772
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001773VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkGpuSize destOffset, VkGpuSize dataSize, const uint32_t* pData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001774{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001775 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001776 VkGpuMemory mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001777 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001778 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001779 sprintf(str, "In vkCmdUpdateMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1780 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001781 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001782 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001783 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001784}
1785
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001786VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkGpuSize destOffset, VkGpuSize fillSize, uint32_t data)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001787{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001788 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001789 VkGpuMemory mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001790 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001791 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001792 sprintf(str, "In vkCmdFillMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1793 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001794 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001795 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001796 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001797}
1798
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001799VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(VkCmdBuffer cmdBuffer,
1800 VkImage image, VkImageLayout imageLayout,
1801 VkClearColor color,
1802 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001803{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001804 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001805 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001806 VkGpuMemory mem = getMemBindingFromObject(image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001807 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001808 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001809 sprintf(str, "In vkCmdClearColorImage() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
1810 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001811 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001812 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001813 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001814}
1815
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001816VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
1817 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001818 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001819 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001820{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001821 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001822 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001823 VkGpuMemory mem = getMemBindingFromObject(image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001824 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001825 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001826 sprintf(str, "In vkCmdClearDepthStencil() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
1827 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001828 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001829 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001830 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001831}
1832
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001833VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
1834 VkImage srcImage, VkImageLayout srcImageLayout,
1835 VkImage destImage, VkImageLayout destImageLayout,
1836 uint32_t rectCount, const VkImageResolve* pRects)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001837{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001838 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001839 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001840 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001841 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001842 sprintf(str, "In vkCmdResolveImage() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1843 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001844 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001845 mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001846 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001847 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001848 sprintf(str, "In vkCmdResolveImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1849 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001850 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001851 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001852 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, rectCount, pRects);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001853}
1854
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001855VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001856{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001857 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001858 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001859 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001860 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001861 sprintf(str, "In vkCmdBeginQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1862 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001863 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001864 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001865 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
1866}
1867
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001868VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001869{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001870 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001871 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001872 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001873 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001874 sprintf(str, "In vkCmdEndQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1875 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001876 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001877 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001878 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
1879}
1880
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001881VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001882{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001883 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001884 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001885 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001886 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001887 sprintf(str, "In vkCmdResetQueryPool() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1888 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001889 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001890 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001891 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
1892}
1893
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001894VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001895{
Tobin Ehlis62086412014-11-19 16:19:28 -07001896 // This layer intercepts callbacks
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001897 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 -07001898 if (!pNewDbgFuncNode)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001899 return VK_ERROR_OUT_OF_MEMORY;
Tobin Ehlis62086412014-11-19 16:19:28 -07001900 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
1901 pNewDbgFuncNode->pUserData = pUserData;
Jon Ashburnf57ea372014-12-22 13:24:15 -07001902 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
1903 g_pDbgFunctionHead = pNewDbgFuncNode;
Jon Ashburne4722392015-03-03 15:07:15 -07001904 // force callbacks if DebugAction hasn't been set already other than initial value
Courtney Goeltzenleuchter9e3aafa2015-03-04 15:47:34 -07001905 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001906 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Courtney Goeltzenleuchter9e3aafa2015-03-04 15:47:34 -07001907 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001908 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001909 return result;
1910}
1911
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001912VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001913{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001914 VK_LAYER_DBG_FUNCTION_NODE *pInfo = g_pDbgFunctionHead;
1915 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pInfo;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001916 while (pInfo) {
1917 if (pInfo->pfnMsgCallback == pfnMsgCallback) {
1918 pPrev->pNext = pInfo->pNext;
1919 if (g_pDbgFunctionHead == pInfo)
1920 g_pDbgFunctionHead = pInfo->pNext;
1921 free(pInfo);
Tobin Ehlis62086412014-11-19 16:19:28 -07001922 break;
1923 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001924 pPrev = pInfo;
1925 pInfo = pInfo->pNext;
Tobin Ehlis62086412014-11-19 16:19:28 -07001926 }
Jon Ashburne4722392015-03-03 15:07:15 -07001927 if (g_pDbgFunctionHead == NULL)
1928 {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001929 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001930 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001931 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001932 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001933 }
Jon Ashburne4722392015-03-03 15:07:15 -07001934 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001935 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001936 return result;
1937}
1938
Jon Ashburndc899962015-03-02 16:51:38 -07001939#if !defined(WIN32)
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001940VK_LAYER_EXPORT VkResult VKAPI vkWsiX11CreatePresentableImage(VkDevice device, const VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO* pCreateInfo,
1941 VkImage* pImage, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001942{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001943 VkResult result = nextTable.WsiX11CreatePresentableImage(device, pCreateInfo, pImage, pMem);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001944 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001945 if (VK_SUCCESS == result) {
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001946 // Add image object, then insert the new Mem Object and then bind it to created image
Courtney Goeltzenleuchter070f6da2015-04-10 17:59:44 -06001947 addObjectInfo(*pImage, VkStructureType_MAX_ENUM, pCreateInfo, sizeof(VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO), "wsi_x11_image");
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001948 addMemObjInfo(*pMem, NULL);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001949 if (VK_FALSE == updateObjectBinding(*pImage, *pMem)) {
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001950 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001951 sprintf(str, "In vkWsiX11CreatePresentableImage(), unable to set image %p binding to mem obj %p", (void*)*pImage, (void*)*pMem);
1952 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pImage, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001953 }
Tobin Ehlis62086412014-11-19 16:19:28 -07001954 }
1955 printObjList();
1956 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001957 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001958 return result;
1959}
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001960
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001961VK_LAYER_EXPORT VkResult VKAPI vkWsiX11QueuePresent(VkQueue queue, const VK_WSI_X11_PRESENT_INFO* pPresentInfo, VkFence fence)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001962{
1963 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001964 addFenceInfo(fence, queue);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001965 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001966 sprintf(str, "In vkWsiX11QueuePresent(), checking queue %p for fence %p", queue, fence);
1967 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001968 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001969 VkResult result = nextTable.WsiX11QueuePresent(queue, pPresentInfo, fence);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001970 return result;
1971}
Ian Elliott81ac44c2015-01-13 17:52:38 -07001972#endif // WIN32
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001973
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001974VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalGpu gpu, const char* funcName)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001975{
Jon Ashburn301c5f02015-04-06 10:58:22 -06001976 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Chia-I Wu706533e2015-01-05 13:18:57 +08001977
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001978 if (gpu == NULL)
1979 return NULL;
1980 pCurObj = gpuw;
Ian Elliott81ac44c2015-01-13 17:52:38 -07001981 loader_platform_thread_once(&g_initOnce, initMemTracker);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001982
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001983 if (!strcmp(funcName, "vkGetProcAddr"))
1984 return (void *) vkGetProcAddr;
1985 if (!strcmp(funcName, "vkCreateDevice"))
1986 return (void*) vkCreateDevice;
1987 if (!strcmp(funcName, "vkDestroyDevice"))
1988 return (void*) vkDestroyDevice;
1989 if (!strcmp(funcName, "vkGetExtensionSupport"))
1990 return (void*) vkGetExtensionSupport;
1991 if (!strcmp(funcName, "vkEnumerateLayers"))
1992 return (void*) vkEnumerateLayers;
1993 if (!strcmp(funcName, "vkQueueSubmit"))
1994 return (void*) vkQueueSubmit;
1995 if (!strcmp(funcName, "vkAllocMemory"))
1996 return (void*) vkAllocMemory;
1997 if (!strcmp(funcName, "vkFreeMemory"))
1998 return (void*) vkFreeMemory;
1999 if (!strcmp(funcName, "vkSetMemoryPriority"))
2000 return (void*) vkSetMemoryPriority;
2001 if (!strcmp(funcName, "vkMapMemory"))
2002 return (void*) vkMapMemory;
2003 if (!strcmp(funcName, "vkUnmapMemory"))
2004 return (void*) vkUnmapMemory;
2005 if (!strcmp(funcName, "vkPinSystemMemory"))
2006 return (void*) vkPinSystemMemory;
2007 if (!strcmp(funcName, "vkOpenSharedMemory"))
2008 return (void*) vkOpenSharedMemory;
2009 if (!strcmp(funcName, "vkOpenPeerMemory"))
2010 return (void*) vkOpenPeerMemory;
2011 if (!strcmp(funcName, "vkOpenPeerImage"))
2012 return (void*) vkOpenPeerImage;
2013 if (!strcmp(funcName, "vkDestroyObject"))
2014 return (void*) vkDestroyObject;
2015 if (!strcmp(funcName, "vkGetObjectInfo"))
2016 return (void*) vkGetObjectInfo;
2017 if (!strcmp(funcName, "vkBindObjectMemory"))
2018 return (void*) vkBindObjectMemory;
2019 if (!strcmp(funcName, "vkCreateFence"))
2020 return (void*) vkCreateFence;
2021 if (!strcmp(funcName, "vkGetFenceStatus"))
2022 return (void*) vkGetFenceStatus;
2023 if (!strcmp(funcName, "vkResetFences"))
2024 return (void*) vkResetFences;
2025 if (!strcmp(funcName, "vkWaitForFences"))
2026 return (void*) vkWaitForFences;
2027 if (!strcmp(funcName, "vkQueueWaitIdle"))
2028 return (void*) vkQueueWaitIdle;
2029 if (!strcmp(funcName, "vkDeviceWaitIdle"))
2030 return (void*) vkDeviceWaitIdle;
2031 if (!strcmp(funcName, "vkCreateEvent"))
2032 return (void*) vkCreateEvent;
2033 if (!strcmp(funcName, "vkCreateQueryPool"))
2034 return (void*) vkCreateQueryPool;
2035 if (!strcmp(funcName, "vkCreateBuffer"))
2036 return (void*) vkCreateBuffer;
2037 if (!strcmp(funcName, "vkCreateBufferView"))
2038 return (void*) vkCreateBufferView;
2039 if (!strcmp(funcName, "vkCreateImage"))
2040 return (void*) vkCreateImage;
2041 if (!strcmp(funcName, "vkCreateImageView"))
2042 return (void*) vkCreateImageView;
2043 if (!strcmp(funcName, "vkCreateColorAttachmentView"))
2044 return (void*) vkCreateColorAttachmentView;
2045 if (!strcmp(funcName, "vkCreateDepthStencilView"))
2046 return (void*) vkCreateDepthStencilView;
2047 if (!strcmp(funcName, "vkCreateShader"))
2048 return (void*) vkCreateShader;
2049 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2050 return (void*) vkCreateGraphicsPipeline;
2051 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2052 return (void*) vkCreateGraphicsPipelineDerivative;
2053 if (!strcmp(funcName, "vkCreateComputePipeline"))
2054 return (void*) vkCreateComputePipeline;
2055 if (!strcmp(funcName, "vkCreateSampler"))
2056 return (void*) vkCreateSampler;
2057 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2058 return (void*) vkCreateDynamicViewportState;
2059 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2060 return (void*) vkCreateDynamicRasterState;
2061 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2062 return (void*) vkCreateDynamicColorBlendState;
2063 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2064 return (void*) vkCreateDynamicDepthStencilState;
2065 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2066 return (void*) vkCreateCommandBuffer;
2067 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2068 return (void*) vkBeginCommandBuffer;
2069 if (!strcmp(funcName, "vkEndCommandBuffer"))
2070 return (void*) vkEndCommandBuffer;
2071 if (!strcmp(funcName, "vkResetCommandBuffer"))
2072 return (void*) vkResetCommandBuffer;
2073 if (!strcmp(funcName, "vkCmdBindPipeline"))
2074 return (void*) vkCmdBindPipeline;
2075 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2076 return (void*) vkCmdBindDynamicStateObject;
2077 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2078 return (void*) vkCmdBindDescriptorSets;
2079 if (!strcmp(funcName, "vkCmdBindVertexBuffer"))
2080 return (void*) vkCmdBindVertexBuffer;
2081 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2082 return (void*) vkCmdBindIndexBuffer;
2083 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2084 return (void*) vkCmdDrawIndirect;
2085 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2086 return (void*) vkCmdDrawIndexedIndirect;
2087 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2088 return (void*) vkCmdDispatchIndirect;
2089 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2090 return (void*) vkCmdCopyBuffer;
2091 if (!strcmp(funcName, "vkCmdCopyImage"))
2092 return (void*) vkCmdCopyImage;
2093 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2094 return (void*) vkCmdCopyBufferToImage;
2095 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2096 return (void*) vkCmdCopyImageToBuffer;
2097 if (!strcmp(funcName, "vkCmdCloneImageData"))
2098 return (void*) vkCmdCloneImageData;
2099 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2100 return (void*) vkCmdUpdateBuffer;
2101 if (!strcmp(funcName, "vkCmdFillBuffer"))
2102 return (void*) vkCmdFillBuffer;
2103 if (!strcmp(funcName, "vkCmdClearColorImage"))
2104 return (void*) vkCmdClearColorImage;
2105 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2106 return (void*) vkCmdClearDepthStencil;
2107 if (!strcmp(funcName, "vkCmdResolveImage"))
2108 return (void*) vkCmdResolveImage;
2109 if (!strcmp(funcName, "vkCmdBeginQuery"))
2110 return (void*) vkCmdBeginQuery;
2111 if (!strcmp(funcName, "vkCmdEndQuery"))
2112 return (void*) vkCmdEndQuery;
2113 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2114 return (void*) vkCmdResetQueryPool;
2115 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2116 return (void*) vkDbgRegisterMsgCallback;
2117 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2118 return (void*) vkDbgUnregisterMsgCallback;
2119 if (!strcmp(funcName, "vkGetDeviceQueue"))
2120 return (void*) vkGetDeviceQueue;
2121 if (!strcmp(funcName, "vkQueueAddMemReference"))
2122 return (void*) vkQueueAddMemReference;
2123 if (!strcmp(funcName, "vkQueueRemoveMemReference"))
2124 return (void*) vkQueueRemoveMemReference;
Jon Ashburndc899962015-03-02 16:51:38 -07002125#if !defined(WIN32)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002126 if (!strcmp(funcName, "vkWsiX11CreatePresentableImage"))
2127 return (void*) vkWsiX11CreatePresentableImage;
2128 if (!strcmp(funcName, "vkWsiX11QueuePresent"))
2129 return (void*) vkWsiX11QueuePresent;
Jon Ashburndc899962015-03-02 16:51:38 -07002130#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002131 else {
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002132 if (gpuw->pGPA == NULL)
2133 return NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002134 return gpuw->pGPA((VkPhysicalGpu)gpuw->nextObject, funcName);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002135 }
2136}