blob: c5f83d234f244883d650eacba514d69e495c2766 [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;
Mike Stroyan62d0bbf2015-04-15 15:37:47 -0600188 bool found = false;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500189
Mike Stroyan62d0bbf2015-04-15 15:37:47 -0600190 for (map<uint64_t, MT_FENCE_INFO*>::iterator ii=fenceMap.begin(); !found && ii!=fenceMap.end(); ++ii) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500191 if ((*ii).second != NULL) {
192 if (fence == ((*ii).second)->fence) {
193 queue = ((*ii).second)->queue;
194 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
195 pQueueInfo->lastRetiredId = (*ii).first;
Mike Stroyan62d0bbf2015-04-15 15:37:47 -0600196 found = true;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500197 } else {
198 deleteFenceInfo((*ii).first);
199 }
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500200 // Update fence state in fenceCreateInfo structure
201 MT_OBJ_INFO* pObjectInfo = getObjectInfo(fence);
202 if (pObjectInfo != NULL) {
Mark Lobodzinski56945182015-04-09 13:46:09 -0500203 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisf29da382015-04-15 07:46:12 -0600204 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags | VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500205 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500206 }
207 }
208}
209
210// Utility function that determines if a fenceId has been retired yet
211static bool32_t fenceRetired(uint64_t fenceId)
212{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600213 bool32_t result = VK_FALSE;
Courtney Goeltzenleuchter60edc352015-04-15 14:10:51 -0600214 if (fenceMap.find(fenceId) != fenceMap.end()) {
215 MT_FENCE_INFO* pFenceInfo = fenceMap[fenceId];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500216 MT_QUEUE_INFO* pQueueInfo = queueMap[pFenceInfo->queue];
Mark Lobodzinski91a1ec52015-04-02 08:52:53 -0500217 if (fenceId <= pQueueInfo->lastRetiredId)
218 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600219 result = VK_TRUE;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500220 }
Mark Lobodzinski8ee96342015-04-02 20:49:09 -0500221 } else { // If not in list, fence has been retired and deleted
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600222 result = VK_TRUE;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500223 }
224 return result;
225}
226
227// Return the fence associated with a fenceId
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600228static VkFence getFenceFromId(uint64_t fenceId)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500229{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600230 VkFence fence = NULL;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500231 if (fenceId != 0) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500232 // Search for an item with this fenceId
233 if (fenceMap.find(fenceId) != fenceMap.end()) {
234 MT_FENCE_INFO* pFenceInfo = fenceMap[fenceId];
235 if (pFenceInfo != NULL) {
236 MT_QUEUE_INFO* pQueueInfo = queueMap[pFenceInfo->queue];
237 if (fenceId > pQueueInfo->lastRetiredId) {
238 fence = pFenceInfo->fence;
239 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500240 }
241 }
242 }
243 return fence;
244}
245
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500246// Helper routine that updates the fence list for a specific queue to all-retired
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600247static void retireQueueFences(VkQueue queue)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500248{
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600249 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
250 pQueueInfo->lastRetiredId = pQueueInfo->lastSubmittedId;
251 // Set Queue's lastRetired to lastSubmitted, free items in queue's fence list
252 map<uint64_t, MT_FENCE_INFO*>::iterator it = fenceMap.begin();
253 map<uint64_t, MT_FENCE_INFO*>::iterator temp;
254 while (it != fenceMap.end()) {
Tobin Ehlisbfc55032015-04-15 14:25:02 -0600255 if ((((*it).second) != NULL) && ((*it).second)->queue == queue) {
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600256 temp = it;
257 ++temp;
258 deleteFenceInfo((*it).first);
259 it = temp;
260 } else {
261 ++it;
262 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500263 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700264}
265
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500266// Helper routine that updates fence list for all queues to all-retired
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600267static void retireDeviceFences(VkDevice device)
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500268{
269 // Process each queue for device
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600270 // TODO: Add multiple device support
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600271 for (map<VkQueue, MT_QUEUE_INFO*>::iterator ii=queueMap.begin(); ii!=queueMap.end(); ++ii) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500272 retireQueueFences((*ii).first);
273 }
274}
275
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500276// Returns True if a memory reference is present in a Queue's memory reference list
277// Queue is validated by caller
278static bool32_t checkMemRef(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600279 VkQueue queue,
280 VkGpuMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500281{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600282 bool32_t result = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600283 list<VkGpuMemory>::iterator it;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500284 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
285 for (it = pQueueInfo->pMemRefList.begin(); it != pQueueInfo->pMemRefList.end(); ++it) {
286 if ((*it) == mem) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600287 result = VK_TRUE;
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500288 break;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500289 }
290 }
291 return result;
292}
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500293
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500294static bool32_t validateQueueMemRefs(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600295 VkQueue queue,
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500296 uint32_t cmdBufferCount,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600297 const VkCmdBuffer *pCmdBuffers)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500298{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600299 bool32_t result = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500300
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500301 // Verify Queue
302 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
303 if (pQueueInfo == NULL) {
304 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600305 sprintf(str, "Unknown Queue %p specified in vkQueueSubmit", queue);
306 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500307 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500308 else {
309 // Iterate through all CBs in pCmdBuffers
310 for (uint32_t i = 0; i < cmdBufferCount; i++) {
311 MT_CB_INFO* pCBInfo = getCBInfo(pCmdBuffers[i]);
312 if (!pCBInfo) {
313 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600314 sprintf(str, "Unable to find info for CB %p in order to check memory references in vkQueueSubmit for queue %p", (void*)pCmdBuffers[i], queue);
315 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_INVALID_CB, "MEM", str);
316 result = VK_FALSE;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500317 } else {
318 // Validate that all actual references are accounted for in pMemRefs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600319 for (list<VkGpuMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500320 // Search for each memref in queues memreflist.
321 if (checkMemRef(queue, *it)) {
322 char str[1024];
323 sprintf(str, "Found Mem Obj %p binding to CB %p for queue %p", (*it), pCmdBuffers[i], queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600324 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500325 }
326 else {
327 char str[1024];
328 sprintf(str, "Queue %p Memory reference list for Command Buffer %p is missing ref to mem obj %p", queue, pCmdBuffers[i], (*it));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600329 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
330 result = VK_FALSE;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500331 }
332 }
333 }
334 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600335 if (result == VK_TRUE) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500336 char str[1024];
337 sprintf(str, "Verified all memory dependencies for Queue %p are included in pMemRefs list", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600338 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500339 // TODO : Could report mem refs in pMemRefs that AREN'T in mem list, that would be primarily informational
340 // Currently just noting that there is a difference
341 }
342 }
343
344 return result;
345}
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600346
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500347// Return ptr to info in map container containing mem, or NULL if not found
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700348// Calls to this function should be wrapped in mutex
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600349static MT_MEM_OBJ_INFO* getMemObjInfo(const VkGpuMemory mem)
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700350{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500351 MT_MEM_OBJ_INFO* pMemObjInfo = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500352
353 if (memObjMap.find(mem) != memObjMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500354 pMemObjInfo = memObjMap[mem];
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600355 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500356 return pMemObjInfo;
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700357}
358
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600359static void addMemObjInfo(const VkGpuMemory mem, const VkMemoryAllocInfo* pAllocInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700360{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500361 MT_MEM_OBJ_INFO* pInfo = new MT_MEM_OBJ_INFO;
362 pInfo->refCount = 0;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600363 memset(&pInfo->allocInfo, 0, sizeof(VkMemoryAllocInfo));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500364
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600365 if (pAllocInfo) { // MEM alloc created by vkWsiX11CreatePresentableImage() doesn't have alloc info struct
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600366 memcpy(&pInfo->allocInfo, pAllocInfo, sizeof(VkMemoryAllocInfo));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500367 // TODO: Update for real hardware, actually process allocation info structures
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500368 pInfo->allocInfo.pNext = NULL;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700369 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500370 pInfo->mem = mem;
371 memObjMap[mem] = pInfo;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700372}
373
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500374// Find CB Info and add mem binding to list container
375// Find Mem Obj Info and add CB binding to list container
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600376static bool32_t updateCBBinding(const VkCmdBuffer cb, const VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700377{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600378 bool32_t result = VK_TRUE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700379 // First update CB binding in MemObj mini CB list
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500380 MT_MEM_OBJ_INFO* pMemInfo = getMemObjInfo(mem);
381 if (!pMemInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700382 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500383 sprintf(str, "Trying to bind mem obj %p to CB %p but no info for that mem obj.\n Was it correctly allocated? Did it already get freed?", mem, cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600384 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
385 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600386 } else {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500387 // Search for cmd buffer object in memory object's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600388 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600389 for (list<VkCmdBuffer>::iterator it = pMemInfo->pCmdBufferBindings.begin(); it != pMemInfo->pCmdBufferBindings.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500390 if ((*it) == cb) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600391 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500392 break;
393 }
394 }
395 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600396 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500397 pMemInfo->pCmdBufferBindings.push_front(cb);
398 pMemInfo->refCount++;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500399 }
400
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500401 // Now update CBInfo's Mem binding list
402 MT_CB_INFO* pCBInfo = getCBInfo(cb);
403 if (!pCBInfo) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500404 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500405 sprintf(str, "Trying to bind mem obj %p to CB %p but no info for that CB. Was it CB incorrectly destroyed?", mem, cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600406 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
407 result = VK_FALSE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500408 } else {
409 // Search for memory object in cmd buffer's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600410 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600411 for (list<VkGpuMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500412 if ((*it) == mem) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600413 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500414 break;
415 }
416 }
417 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600418 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500419 pCBInfo->pMemObjList.push_front(mem);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600420 }
421 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700422 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600423 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700424}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600425
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700426// Clear the CB Binding for mem
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700427// Calls to this function should be wrapped in mutex
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600428static void clearCBBinding(const VkCmdBuffer cb, const VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700429{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500430 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500431 // TODO : Having this check is not ideal, really if memInfo was deleted,
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700432 // its CB bindings should be cleared and then freeCBBindings wouldn't call
433 // us here with stale mem objs
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500434 if (pInfo) {
435 pInfo->pCmdBufferBindings.remove(cb);
436 pInfo->refCount--;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700437 }
438}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600439
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700440// Free bindings related to CB
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600441static bool32_t freeCBBindings(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700442{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600443 bool32_t result = VK_TRUE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500444 MT_CB_INFO* pCBInfo = getCBInfo(cb);
445 if (!pCBInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700446 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500447 sprintf(str, "Unable to find global CB info %p for deletion", cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600448 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
449 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600450 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500451 if (!fenceRetired(pCBInfo->fenceId)) {
452 deleteFenceInfo(pCBInfo->fenceId);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600453 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500454
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600455 for (list<VkGpuMemory>::iterator it=pCBInfo->pMemObjList.begin(); it!=pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500456 clearCBBinding(cb, (*it));
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600457 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500458 pCBInfo->pMemObjList.clear();
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700459 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600460 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700461}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600462
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500463// Delete CBInfo from list along with all of it's mini MemObjInfo
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500464// and also clear mem references to CB
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700465// TODO : When should this be called? There's no Destroy of CBs that I see
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600466static bool32_t deleteCBInfo(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700467{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600468 bool32_t result = VK_TRUE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600469 result = freeCBBindings(cb);
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500470 // Delete the CBInfo info
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600471 if (result == VK_TRUE) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500472 if (cbMap.find(cb) != cbMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500473 MT_CB_INFO* pDelInfo = cbMap[cb];
474 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500475 cbMap.erase(cb);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600476 }
Ian Elliott81ac44c2015-01-13 17:52:38 -0700477 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600478 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700479}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600480
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700481// Delete the entire CB list
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500482static bool32_t deleteCBInfoList()
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700483{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600484 bool32_t result = VK_TRUE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600485 for (map<VkCmdBuffer, MT_CB_INFO*>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500486 freeCBBindings((*ii).first);
487 delete (*ii).second;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700488 }
489 return result;
490}
491
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500492// For given MemObjInfo, report Obj & CB bindings
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500493static void reportMemReferences(const MT_MEM_OBJ_INFO* pMemObjInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700494{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600495 uint32_t refCount = 0; // Count found references
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500496
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600497 for (list<VkCmdBuffer>::const_iterator it = pMemObjInfo->pCmdBufferBindings.begin(); it != pMemObjInfo->pCmdBufferBindings.end(); ++it) {
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700498 refCount++;
Tobin Ehlis62086412014-11-19 16:19:28 -0700499 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500500 sprintf(str, "Command Buffer %p has reference to mem obj %p", (*it), pMemObjInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600501 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (*it), 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700502 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600503 for (list<VkObject>::const_iterator it = pMemObjInfo->pObjBindings.begin(); it != pMemObjInfo->pObjBindings.end(); ++it) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700504 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600505 sprintf(str, "VK Object %p has reference to mem obj %p", (*it), pMemObjInfo->mem);
506 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (*it), 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700507 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500508 if (refCount != pMemObjInfo->refCount) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700509 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500510 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 -0600511 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pMemObjInfo->mem, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700512 }
513}
514
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600515static void deleteMemObjInfo(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700516{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500517 MT_MEM_OBJ_INFO* pDelInfo = memObjMap[mem];
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500518 if (memObjMap.find(mem) != memObjMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500519 MT_MEM_OBJ_INFO* pDelInfo = memObjMap[mem];
520 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500521 memObjMap.erase(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700522 }
523}
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500524
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700525// Check if fence for given CB is completed
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600526static bool32_t checkCBCompleted(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700527{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600528 bool32_t result = VK_TRUE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500529 MT_CB_INFO* pCBInfo = getCBInfo(cb);
530 if (!pCBInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700531 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500532 sprintf(str, "Unable to find global CB info %p to check for completion", cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600533 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
534 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600535 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500536 if (!fenceRetired(pCBInfo->fenceId)) {
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600537 char str[1024];
538 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 -0600539 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_NONE, "MEM", str);
540 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600541 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700542 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600543 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700544}
545
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600546static bool32_t freeMemObjInfo(VkGpuMemory mem, bool internal)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700547{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600548 bool32_t result = VK_TRUE;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500549 // Parse global list to find info w/ mem
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500550 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
551 if (!pInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700552 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500553 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 -0600554 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
555 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600556 } else {
Courtney Goeltzenleuchterc4804862015-03-26 16:15:39 -0600557 if (pInfo->allocInfo.allocationSize == 0 && !internal) {
Mark Lobodzinskidaa1d432015-02-18 18:06:24 -0600558 char str[1024];
559 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 -0600560 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
561 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600562 } else {
563 // Clear any CB bindings for completed CBs
564 // TODO : Is there a better place to do this?
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500565
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600566 list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin();
567 list<VkCmdBuffer>::iterator temp;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500568 while (it != pInfo->pCmdBufferBindings.end()) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600569 if (VK_TRUE == checkCBCompleted(*it)) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500570 temp = it;
571 ++temp;
572 freeCBBindings(*it);
573 it = temp;
574 } else {
575 ++it;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600576 }
577 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500578
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600579 // Now verify that no references to this mem obj remain
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500580 if (0 != pInfo->refCount) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500581 // If references remain, report the error and can search CB list to find references
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600582 char str[1024];
583 sprintf(str, "Freeing mem obj %p while it still has references", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600584 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_FREED_MEM_REF, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500585 reportMemReferences(pInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600586 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600587 }
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600588 // Delete mem obj info
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500589 deleteMemObjInfo(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700590 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700591 }
592 return result;
593}
594
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700595// Remove object binding performs 3 tasks:
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500596// 1. Remove ObjectInfo from MemObjInfo list container of obj bindings & free it
597// 2. Decrement refCount for MemObjInfo
598// 3. Clear MemObjInfo ptr from ObjectInfo
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600599static bool32_t clearObjectBinding(VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700600{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600601 bool32_t result = VK_FALSE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500602 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
603 if (!pObjInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700604 char str[1024];
Mark Lobodzinski15427102015-02-18 16:38:17 -0600605 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 -0600606 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600607 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500608 if (!pObjInfo->pMemObjInfo) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600609 char str[1024];
610 sprintf(str, "Attempting to clear mem binding on obj %p but it has no binding.", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600611 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 -0600612 } else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600613 for (list<VkObject>::iterator it = pObjInfo->pMemObjInfo->pObjBindings.begin(); it != pObjInfo->pMemObjInfo->pObjBindings.end(); ++it) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500614 pObjInfo->pMemObjInfo->refCount--;
615 pObjInfo->pMemObjInfo = NULL;
616 it = pObjInfo->pMemObjInfo->pObjBindings.erase(it);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600617 result = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500618 break;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600619 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600620 if (result == VK_FALSE) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600621 char str[1024];
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500622 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 -0500623 object, pObjInfo->pMemObjInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600624 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600625 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700626 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700627 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600628 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700629}
630
631// For NULL mem case, clear any previous binding Else...
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500632// Make sure given object is in global object map
Tobin Ehlis62086412014-11-19 16:19:28 -0700633// IF a previous binding existed, clear it
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500634// Add reference from objectInfo to memoryInfo
635// Add reference off of objInfo
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600636// Return VK_TRUE if addition is successful, VK_FALSE otherwise
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600637static bool32_t updateObjectBinding(VkObject object, VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700638{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600639 bool32_t result = VK_FALSE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700640 // Handle NULL case separately, just clear previous binding & decrement reference
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600641 if (mem == VK_NULL_HANDLE) {
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700642 clearObjectBinding(object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600643 result = VK_TRUE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600644 } else {
645 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500646 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
647 if (!pObjInfo) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600648 sprintf(str, "Attempting to update Binding of Obj(%p) that's not in global list()", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600649 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
650 return VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600651 }
652 // non-null case so should have real mem obj
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500653 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
654 if (!pInfo) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500655 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 -0600656 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600657 } else {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500658 // Search for object in memory object's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600659 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600660 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500661 if ((*it) == object) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600662 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500663 break;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600664 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600665 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500666 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600667 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500668 pInfo->pObjBindings.push_front(object);
669 pInfo->refCount++;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500670 }
671
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500672 if (pObjInfo->pMemObjInfo) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500673 clearObjectBinding(object); // Need to clear the previous object binding before setting new binding
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500674 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 -0600675 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500676 }
677 // For image objects, make sure default memory state is correctly set
678 // TODO : What's the best/correct way to handle this?
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600679 if (VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO == pObjInfo->sType) {
680 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 -0500681 // TODO:: More memory state transition stuff.
682 }
683 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500684 pObjInfo->pMemObjInfo = pInfo;
Tobin Ehlis6aa77422015-01-07 17:49:29 -0700685 }
686 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600687 return VK_TRUE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700688}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600689
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700690// Print details of global Obj tracking list
691static void printObjList()
692{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500693 MT_OBJ_INFO* pInfo = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500694 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500695 sprintf(str, "Details of Object list of size %lu elements", objectMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600696 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600697 for (map<VkObject, MT_OBJ_INFO*>::iterator ii=objectMap.begin(); ii!=objectMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500698 pInfo = (*ii).second;
699 sprintf(str, " ObjInfo %p has object %p, pMemObjInfo %p", pInfo, pInfo->object, pInfo->pMemObjInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600700 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pInfo->object, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700701 }
702}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600703
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700704// For given Object, get 'mem' obj that it's bound to or NULL if no binding
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600705static VkGpuMemory getMemBindingFromObject(const VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700706{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600707 VkGpuMemory mem = NULL;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500708 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
709 if (pObjInfo) {
710 if (pObjInfo->pMemObjInfo) {
711 mem = pObjInfo->pMemObjInfo->mem;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700712 }
713 else {
Tobin Ehlis62086412014-11-19 16:19:28 -0700714 char str[1024];
715 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 -0600716 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MISSING_MEM_BINDINGS, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700717 printObjList();
718 }
719 }
720 else {
Tobin Ehlis62086412014-11-19 16:19:28 -0700721 char str[1024];
722 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 -0600723 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700724 printObjList();
725 }
726 return mem;
727}
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500728
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500729// Print details of MemObjInfo list
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700730static void printMemList()
731{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500732 MT_MEM_OBJ_INFO* pInfo = NULL;
Tobin Ehlis62086412014-11-19 16:19:28 -0700733 // Just printing each msg individually for now, may want to package these into single large print
734 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500735 sprintf(str, "MEM INFO : Details of Memory Object list of size %lu elements", memObjMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600736 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500737
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600738 for (map<VkGpuMemory, MT_MEM_OBJ_INFO*>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500739 pInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500740
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500741 sprintf(str, " ===MemObjInfo at %p===", (void*)pInfo);
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, " Mem object: %p", (void*)pInfo->mem);
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 sprintf(str, " Ref Count: %u", pInfo->refCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600746 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500747 if (0 != pInfo->allocInfo.allocationSize) {
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600748 string pAllocInfoMsg = vk_print_vkmemoryallocinfo(&pInfo->allocInfo, "{MEM}INFO : ");
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500749 sprintf(str, " Mem Alloc info:\n%s", pAllocInfoMsg.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600750 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500751 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600752 sprintf(str, " Mem Alloc info is NULL (alloc done by vkWsiX11CreatePresentableImage())");
753 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500754 }
755
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600756 sprintf(str, " VK OBJECT Binding list of size %lu elements:", pInfo->pObjBindings.size());
757 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600758 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600759 sprintf(str, " VK OBJECT %p", (*it));
760 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500761 }
762
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600763 sprintf(str, " VK Command Buffer (CB) binding list of size %lu elements", pInfo->pCmdBufferBindings.size());
764 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600765 for (list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin(); it != pInfo->pCmdBufferBindings.end(); ++it) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600766 sprintf(str, " VK CB %p", (*it));
767 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700768 }
769 }
770}
771
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500772static void printCBList()
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700773{
Tobin Ehlis62086412014-11-19 16:19:28 -0700774 char str[1024] = {0};
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500775 MT_CB_INFO* pCBInfo = NULL;
776 sprintf(str, "Details of CB list of size %lu elements", cbMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600777 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500778
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600779 for (map<VkCmdBuffer, MT_CB_INFO*>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500780 pCBInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500781
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500782 sprintf(str, " CB Info (%p) has CB %p, fenceId %" PRIx64", and fence %p",
783 (void*)pCBInfo, (void*)pCBInfo->cmdBuffer, pCBInfo->fenceId,
784 (void*)getFenceFromId(pCBInfo->fenceId));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600785 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500786
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600787 for (list<VkGpuMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500788 sprintf(str, " Mem obj %p", (*it));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600789 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700790 }
791 }
792}
793
Mark Lobodzinski15427102015-02-18 16:38:17 -0600794static void initMemTracker(void)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700795{
Jon Ashburnf57ea372014-12-22 13:24:15 -0700796 const char *strOpt;
797 // initialize MemTracker options
Ian Elliott7d0b5d22015-03-06 13:50:05 -0700798 getLayerOptionEnum("MemTrackerReportLevel", (uint32_t *) &g_reportingLevel);
799 g_actionIsDefault = getLayerOptionEnum("MemTrackerDebugAction", (uint32_t *) &g_debugAction);
Tobin Ehlis5b7acaa2015-01-08 14:26:53 -0700800
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600801 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Jon Ashburnf57ea372014-12-22 13:24:15 -0700802 {
803 strOpt = getLayerOption("MemTrackerLogFilename");
804 if (strOpt)
805 {
806 g_logFile = fopen(strOpt, "w");
Jon Ashburnf57ea372014-12-22 13:24:15 -0700807 }
808 if (g_logFile == NULL)
809 g_logFile = stdout;
810 }
811
812 // initialize Layer dispatch table
813 // TODO handle multiple GPUs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600814 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700815 fpNextGPA = pCurObj->pGPA;
816 assert(fpNextGPA);
817
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600818 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalGpu) pCurObj->nextObject);
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800819
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600820 if (!globalLockInitialized)
821 {
822 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600823 // suggestion is to call this during vkCreateInstance(), and then we
824 // can clean it up during vkDestroyInstance(). However, that requires
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600825 // that the layer have per-instance locks. We need to come back and
826 // address this soon.
827 loader_platform_thread_create_mutex(&globalLock);
828 globalLockInitialized = 1;
829 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700830}
831
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600832VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700833{
Jon Ashburn630e44f2015-04-08 21:33:34 -0600834 pCurObj = (VkBaseLayerObject *) gpu;
Ian Elliott81ac44c2015-01-13 17:52:38 -0700835 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburn630e44f2015-04-08 21:33:34 -0600836 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700837 // Save off device in case we need it to create Fences
838 globalDevice = *pDevice;
839 return result;
840}
841
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600842VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700843{
Tobin Ehlis62086412014-11-19 16:19:28 -0700844 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600845 sprintf(str, "Printing List details prior to vkDestroyDevice()");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600846 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600847 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, device, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700848 printMemList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500849 printCBList();
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700850 printObjList();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600851 if (VK_FALSE == deleteCBInfoList()) {
852 sprintf(str, "Issue deleting global CB list in vkDestroyDevice()");
853 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, device, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -0700854 }
Tobin Ehlis22d03232014-11-25 18:01:12 -0700855 // Report any memory leaks
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500856 MT_MEM_OBJ_INFO* pInfo = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600857 for (map<VkGpuMemory, MT_MEM_OBJ_INFO*>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500858 pInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500859
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500860 if (pInfo->allocInfo.allocationSize != 0) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600861 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 -0500862 pInfo->mem, pInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600863 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, pInfo->mem, 0, MEMTRACK_MEMORY_LEAK, "MEM", str);
Mark Lobodzinskidaa1d432015-02-18 18:06:24 -0600864 }
Tobin Ehlis22d03232014-11-25 18:01:12 -0700865 }
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500866
867 // Queues persist until device is destroyed
868 deleteQueueInfoList();
869
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600870 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600871 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700872 return result;
873}
874
Jon Ashburneb2728b2015-04-10 14:33:07 -0600875struct extProps {
876 uint32_t version;
877 const char * const name;
878};
Jon Ashburnbdcd7562015-04-14 14:12:59 -0600879#define MEM_TRACKER_LAYER_EXT_ARRAY_SIZE 2
Jon Ashburneb2728b2015-04-10 14:33:07 -0600880static const struct extProps mtExts[MEM_TRACKER_LAYER_EXT_ARRAY_SIZE] = {
881 // TODO what is the version?
Jon Ashburnbdcd7562015-04-14 14:12:59 -0600882 0x10, "MemTracker",
883 0x10, "Validation"
Jon Ashburneb2728b2015-04-10 14:33:07 -0600884};
885
886VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
887 VkExtensionInfoType infoType,
888 uint32_t extensionIndex,
889 size_t* pDataSize,
890 void* pData)
891{
892 VkResult result;
893
894 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
895 VkExtensionProperties *ext_props;
896 uint32_t *count;
897
898 if (pDataSize == NULL)
899 return VK_ERROR_INVALID_POINTER;
900
901 switch (infoType) {
902 case VK_EXTENSION_INFO_TYPE_COUNT:
903 *pDataSize = sizeof(uint32_t);
904 if (pData == NULL)
905 return VK_SUCCESS;
906 count = (uint32_t *) pData;
907 *count = MEM_TRACKER_LAYER_EXT_ARRAY_SIZE;
908 break;
909 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
910 *pDataSize = sizeof(VkExtensionProperties);
911 if (pData == NULL)
912 return VK_SUCCESS;
913 if (extensionIndex >= MEM_TRACKER_LAYER_EXT_ARRAY_SIZE)
914 return VK_ERROR_INVALID_VALUE;
915 ext_props = (VkExtensionProperties *) pData;
916 ext_props->version = mtExts[extensionIndex].version;
917 strncpy(ext_props->extName, mtExts[extensionIndex].name,
918 VK_MAX_EXTENSION_NAME);
919 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
920 break;
921 default:
922 return VK_ERROR_INVALID_VALUE;
923 };
924
925 return VK_SUCCESS;
926}
927
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600928VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName)
Jon Ashburn25566352015-04-02 12:06:28 -0600929{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600930 VkResult result;
Jon Ashburn25566352015-04-02 12:06:28 -0600931 /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */
932 if (!strcmp(pExtName, "MemTracker"))
933 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600934 result = VK_SUCCESS;
Jon Ashburn25566352015-04-02 12:06:28 -0600935 } else if (nextTable.GetExtensionSupport != NULL)
936 {
Jon Ashburn630e44f2015-04-08 21:33:34 -0600937 result = nextTable.GetExtensionSupport(gpu, pExtName);
Jon Ashburn25566352015-04-02 12:06:28 -0600938 } else
939 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600940 result = VK_ERROR_INVALID_EXTENSION;
Jon Ashburn25566352015-04-02 12:06:28 -0600941 }
942 return result;
943}
944
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600945VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalGpu gpu, size_t maxLayerCount,
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500946 size_t maxStringSize, size_t* pOutLayerCount, char* const* pOutLayers, void* pReserved)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700947{
Jon Ashburn451c16f2014-11-25 11:08:42 -0700948 if (gpu != NULL)
949 {
Jon Ashburn630e44f2015-04-08 21:33:34 -0600950 pCurObj = (VkBaseLayerObject *) gpu;
Ian Elliott81ac44c2015-01-13 17:52:38 -0700951 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburn630e44f2015-04-08 21:33:34 -0600952 VkResult result = nextTable.EnumerateLayers(gpu, maxLayerCount,
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500953 maxStringSize, pOutLayerCount, pOutLayers, pReserved);
Jon Ashburn451c16f2014-11-25 11:08:42 -0700954 return result;
955 } else
956 {
957 if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600958 return VK_ERROR_INVALID_POINTER;
Jon Ashburn451c16f2014-11-25 11:08:42 -0700959 // This layer compatible with all GPUs
960 *pOutLayerCount = 1;
Chia-I Wua837c522014-12-16 10:47:33 +0800961 strncpy((char *) pOutLayers[0], "MemTracker", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600962 return VK_SUCCESS;
Jon Ashburn451c16f2014-11-25 11:08:42 -0700963 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700964}
965
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600966VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueNodeIndex, uint32_t queueIndex, VkQueue* pQueue)
Mark Lobodzinski55e53d92015-03-31 16:05:35 -0500967{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600968 VkResult result = nextTable.GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600969 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500970 loader_platform_thread_lock_mutex(&globalLock);
971 addQueueInfo(*pQueue);
972 loader_platform_thread_unlock_mutex(&globalLock);
973 }
Mark Lobodzinski55e53d92015-03-31 16:05:35 -0500974 return result;
975}
976
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600977VK_LAYER_EXPORT VkResult VKAPI vkQueueAddMemReference(VkQueue queue, VkGpuMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500978{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600979 VkResult result = nextTable.QueueAddMemReference(queue, mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600980 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500981 loader_platform_thread_lock_mutex(&globalLock);
982
983 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
984 if (pQueueInfo == NULL) {
985 char str[1024];
986 sprintf(str, "Unknown Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600987 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500988 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500989 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600990 if (checkMemRef(queue, mem) == VK_TRUE) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500991 // Alread in list, just warn
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500992 char str[1024];
993 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 -0600994 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500995 }
996 else {
997 // Add to queue's memory reference list
998 pQueueInfo->pMemRefList.push_front(mem);
999 }
1000 }
1001 loader_platform_thread_unlock_mutex(&globalLock);
1002 }
1003 return result;
1004}
1005
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001006VK_LAYER_EXPORT VkResult VKAPI vkQueueRemoveMemReference(VkQueue queue, VkGpuMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001007{
1008 // TODO : Decrement ref count for this memory reference on this queue. Remove if ref count is zero.
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001009 VkResult result = nextTable.QueueRemoveMemReference(queue, mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001010 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001011 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001012
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001013 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
1014 if (pQueueInfo == NULL) {
1015 char str[1024];
1016 sprintf(str, "Unknown Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001017 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001018 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001019 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001020 for (list<VkGpuMemory>::iterator it = pQueueInfo->pMemRefList.begin(); it != pQueueInfo->pMemRefList.end(); ++it) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001021 if ((*it) == mem) {
1022 it = pQueueInfo->pMemRefList.erase(it);
1023 }
1024 }
1025 }
1026 loader_platform_thread_unlock_mutex(&globalLock);
1027 }
1028 return result;
1029}
1030
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001031VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(
1032 VkQueue queue,
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001033 uint32_t cmdBufferCount,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001034 const VkCmdBuffer *pCmdBuffers,
1035 VkFence fence)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001036{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001037 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001038 // TODO : Need to track fence and clear mem references when fence clears
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001039 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001040 uint64_t fenceId = addFenceInfo(fence, queue);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001041
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001042 printMemList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001043 printCBList();
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001044 for (uint32_t i = 0; i < cmdBufferCount; i++) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001045 pCBInfo = getCBInfo(pCmdBuffers[i]);
1046 pCBInfo->fenceId = fenceId;
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001047 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001048
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001049 if (VK_FALSE == validateQueueMemRefs(queue, cmdBufferCount, pCmdBuffers)) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001050 char str[1024];
1051 sprintf(str, "Unable to verify memory references for Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001052 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001053 }
1054
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001055 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001056 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, getFenceFromId(fenceId));
Courtney Goeltzenleuchtercfedf362015-04-02 13:39:07 -06001057 return result;
1058}
1059
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001060VK_LAYER_EXPORT VkResult VKAPI vkAllocMemory(VkDevice device, const VkMemoryAllocInfo* pAllocInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001061{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001062 VkResult result = nextTable.AllocMemory(device, pAllocInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001063 // TODO : Track allocations and overall size here
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001064 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001065 addMemObjInfo(*pMem, pAllocInfo);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001066 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001067 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001068 return result;
1069}
1070
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001071VK_LAYER_EXPORT VkResult VKAPI vkFreeMemory(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001072{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001073 /* From spec : A memory object is freed by calling vkFreeMemory() when it is no longer needed. Before
Tobin Ehlisa747e682014-11-25 14:47:20 -07001074 * freeing a memory object, an application must ensure the memory object is unbound from
1075 * all API objects referencing it and that it is not referenced by any queued command buffers
1076 */
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001077 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001078 if (VK_FALSE == freeMemObjInfo(mem, false)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001079 char str[1024];
1080 sprintf(str, "Issue while freeing mem obj %p", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001081 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_FREE_MEM_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001082 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001083 printMemList();
1084 printObjList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001085 printCBList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001086 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001087 VkResult result = nextTable.FreeMemory(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001088 return result;
1089}
1090
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001091VK_LAYER_EXPORT VkResult VKAPI vkSetMemoryPriority(VkGpuMemory mem, VkMemoryPriority priority)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001092{
1093 // TODO : Update tracking for this alloc
1094 // Make sure memory is not pinned, which can't have priority set
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001095 VkResult result = nextTable.SetMemoryPriority(mem, priority);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001096 return result;
1097}
1098
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001099VK_LAYER_EXPORT VkResult VKAPI vkMapMemory(VkGpuMemory mem, VkFlags flags, void** ppData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001100{
1101 // TODO : Track when memory is mapped
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001102 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001103 MT_MEM_OBJ_INFO *pMemObj = getMemObjInfo(mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001104 if ((pMemObj->allocInfo.memProps & VK_MEMORY_PROPERTY_CPU_VISIBLE_BIT) == 0) {
Mark Lobodzinski06f60b82015-02-25 12:16:04 -06001105 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001106 sprintf(str, "Mapping Memory (%p) without VK_MEMORY_PROPERTY_CPU_VISIBLE_BIT set", (void*)mem);
1107 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_STATE, "MEM", str);
Mark Lobodzinski06f60b82015-02-25 12:16:04 -06001108 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001109 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001110 VkResult result = nextTable.MapMemory(mem, flags, ppData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001111 return result;
1112}
1113
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001114VK_LAYER_EXPORT VkResult VKAPI vkUnmapMemory(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001115{
1116 // TODO : Track as memory gets unmapped, do we want to check what changed following map?
1117 // Make sure that memory was ever mapped to begin with
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001118 VkResult result = nextTable.UnmapMemory(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001119 return result;
1120}
1121
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001122VK_LAYER_EXPORT VkResult VKAPI vkPinSystemMemory(VkDevice device, const void* pSysMem, size_t memSize, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001123{
1124 // TODO : Track this
1125 // Verify that memory is actually pinnable
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001126 VkResult result = nextTable.PinSystemMemory(device, pSysMem, memSize, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001127 return result;
1128}
1129
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001130VK_LAYER_EXPORT VkResult VKAPI vkOpenSharedMemory(VkDevice device, const VkMemoryOpenInfo* pOpenInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001131{
1132 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001133 VkResult result = nextTable.OpenSharedMemory(device, pOpenInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001134 return result;
1135}
1136
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001137VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerMemory(VkDevice device, const VkPeerMemoryOpenInfo* pOpenInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001138{
1139 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001140 VkResult result = nextTable.OpenPeerMemory(device, pOpenInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001141 return result;
1142}
1143
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001144VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerImage(VkDevice device, const VkPeerImageOpenInfo* pOpenInfo, VkImage* pImage, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001145{
1146 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001147 VkResult result = nextTable.OpenPeerImage(device, pOpenInfo, pImage, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001148 return result;
1149}
1150
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001151VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001152{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001153 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001154
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001155 // First check if this is a CmdBuffer
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001156 if (NULL != getCBInfo((VkCmdBuffer)object)) {
1157 deleteCBInfo((VkCmdBuffer)object);
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001158 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001159
1160 if (objectMap.find(object) != objectMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001161 MT_OBJ_INFO* pDelInfo = objectMap[object];
1162 if (pDelInfo->pMemObjInfo) {
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001163 // Wsi allocated Memory is tied to image object so clear the binding and free that memory automatically
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001164 if (0 == pDelInfo->pMemObjInfo->allocInfo.allocationSize) { // Wsi allocated memory has NULL allocInfo w/ 0 size
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001165 VkGpuMemory memToFree = pDelInfo->pMemObjInfo->mem;
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001166 clearObjectBinding(object);
Courtney Goeltzenleuchterc4804862015-03-26 16:15:39 -06001167 freeMemObjInfo(memToFree, true);
1168 }
1169 else {
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001170 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001171 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);
1172 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_DESTROY_OBJECT_ERROR, "MEM", str);
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001173 // From the spec : If an object has previous memory binding, it is required to unbind memory from an API object before it is destroyed.
1174 clearObjectBinding(object);
1175 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001176 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001177 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001178 objectMap.erase(object);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001179 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001180
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001181 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001182 VkResult result = nextTable.DestroyObject(object);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001183 return result;
1184}
1185
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001186VK_LAYER_EXPORT VkResult VKAPI vkGetObjectInfo(VkBaseObject object, VkObjectInfoType infoType, size_t* pDataSize, void* pData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001187{
1188 // TODO : What to track here?
1189 // Could potentially save returned mem requirements and validate values passed into BindObjectMemory for this object
Tobin Ehlis62086412014-11-19 16:19:28 -07001190 // 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 -06001191 VkResult result = nextTable.GetObjectInfo(object, infoType, pDataSize, pData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001192 return result;
1193}
1194
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001195VK_LAYER_EXPORT VkResult VKAPI vkBindObjectMemory(VkObject object, uint32_t allocationIdx, VkGpuMemory mem, VkGpuSize offset)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001196{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001197 VkResult result = nextTable.BindObjectMemory(object, allocationIdx, mem, offset);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001198 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001199 // Track objects tied to memory
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001200 if (VK_FALSE == updateObjectBinding(object, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001201 char str[1024];
1202 sprintf(str, "Unable to set object %p binding to mem obj %p", (void*)object, (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001203 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001204 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001205 printObjList();
1206 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001207 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001208 return result;
1209}
1210
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001211VK_LAYER_EXPORT VkResult VKAPI vkCreateFence(VkDevice device, const VkFenceCreateInfo* pCreateInfo, VkFence* pFence)
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001212{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001213 VkResult result = nextTable.CreateFence(device, pCreateInfo, pFence);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001214 if (VK_SUCCESS == result) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001215 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001216 addObjectInfo(*pFence, pCreateInfo->sType, pCreateInfo, sizeof(VkFenceCreateInfo), "fence");
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001217 loader_platform_thread_unlock_mutex(&globalLock);
1218 }
1219 return result;
1220}
1221
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001222VK_LAYER_EXPORT VkResult VKAPI vkResetFences(VkDevice device, uint32_t fenceCount, VkFence* pFences)
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001223{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001224 VkResult result = nextTable.ResetFences(device, fenceCount, pFences);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001225 if (VK_SUCCESS == result) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001226 loader_platform_thread_lock_mutex(&globalLock);
1227 // Reset fence state in fenceCreateInfo structure
1228 for (uint32_t i = 0; i < fenceCount; i++) {
1229 MT_OBJ_INFO* pObjectInfo = getObjectInfo(pFences[i]);
1230 if (pObjectInfo != NULL) {
Mark Lobodzinski56945182015-04-09 13:46:09 -05001231 // Validate fences in SIGNALED state
Tobin Ehlisf29da382015-04-15 07:46:12 -06001232 if (!(pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT)) {
Mark Lobodzinski56945182015-04-09 13:46:09 -05001233 char str[1024];
Mark Lobodzinski610be622015-04-14 14:09:32 -05001234 sprintf(str, "Fence %p submitted to VkResetFences in UNSIGNALED STATE", pFences[i]);
Tobin Ehlisf29da382015-04-15 07:46:12 -06001235 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
1236 result = VK_ERROR_INVALID_VALUE;
Mark Lobodzinski56945182015-04-09 13:46:09 -05001237 }
1238 else {
1239 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisf29da382015-04-15 07:46:12 -06001240 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags & ~VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinski56945182015-04-09 13:46:09 -05001241 }
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001242 }
1243 }
1244 loader_platform_thread_unlock_mutex(&globalLock);
1245 }
1246 return result;
1247}
1248
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001249VK_LAYER_EXPORT VkResult VKAPI vkGetFenceStatus(VkFence fence)
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001250{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001251 VkResult result = nextTable.GetFenceStatus(fence);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001252 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001253 loader_platform_thread_lock_mutex(&globalLock);
1254 updateFenceTracking(fence);
1255 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001256 }
1257 return result;
1258}
1259
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001260VK_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 -07001261{
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001262 // Verify fence status of submitted fences
1263 for(uint32_t i = 0; i < fenceCount; i++) {
1264 MT_OBJ_INFO* pObjectInfo = getObjectInfo(pFences[i]);
1265 if (pObjectInfo != NULL) {
Tobin Ehlisf29da382015-04-15 07:46:12 -06001266 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001267 char str[1024];
Mark Lobodzinski610be622015-04-14 14:09:32 -05001268 sprintf(str, "VkWaitForFences specified fence %p already in SIGNALED state.", pFences[i]);
Tobin Ehlisf29da382015-04-15 07:46:12 -06001269 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 -05001270 }
1271 }
1272 }
1273
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001274 VkResult result = nextTable.WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001275 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001276
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001277 if (VK_SUCCESS == result) {
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001278 if (waitAll || fenceCount == 1) { // Clear all the fences
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001279 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001280 updateFenceTracking(pFences[i]);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001281 }
1282 }
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001283 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001284 loader_platform_thread_unlock_mutex(&globalLock);
1285 return result;
1286}
1287
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001288VK_LAYER_EXPORT VkResult VKAPI vkQueueWaitIdle(VkQueue queue)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001289{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001290 VkResult result = nextTable.QueueWaitIdle(queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001291 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001292 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001293 retireQueueFences(queue);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001294 loader_platform_thread_unlock_mutex(&globalLock);
1295 }
1296 return result;
1297}
1298
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001299VK_LAYER_EXPORT VkResult VKAPI vkDeviceWaitIdle(VkDevice device)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001300{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001301 VkResult result = nextTable.DeviceWaitIdle(device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001302 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001303 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001304 retireDeviceFences(device);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001305 loader_platform_thread_unlock_mutex(&globalLock);
1306 }
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001307 return result;
1308}
1309
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001310VK_LAYER_EXPORT VkResult VKAPI vkCreateEvent(VkDevice device, const VkEventCreateInfo* pCreateInfo, VkEvent* pEvent)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001311{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001312 VkResult result = nextTable.CreateEvent(device, pCreateInfo, pEvent);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001313 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001314 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001315 addObjectInfo(*pEvent, pCreateInfo->sType, pCreateInfo, sizeof(VkEventCreateInfo), "event");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001316 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001317 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001318 return result;
1319}
1320
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001321VK_LAYER_EXPORT VkResult VKAPI vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, VkQueryPool* pQueryPool)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001322{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001323 VkResult result = nextTable.CreateQueryPool(device, pCreateInfo, pQueryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001324 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001325 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001326 addObjectInfo(*pQueryPool, pCreateInfo->sType, pCreateInfo, sizeof(VkQueryPoolCreateInfo), "query_pool");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001327 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001328 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001329 return result;
1330}
1331
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001332VK_LAYER_EXPORT VkResult VKAPI vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, VkBuffer* pBuffer)
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001333{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001334 VkResult result = nextTable.CreateBuffer(device, pCreateInfo, pBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001335 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001336 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001337 addObjectInfo(*pBuffer, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferCreateInfo), "buffer");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001338 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001339 }
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001340 return result;
1341}
1342
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001343VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001344{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001345 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001346 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001347 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001348 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferViewCreateInfo), "buffer_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001349 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001350 }
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001351 return result;
1352}
1353
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001354VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, VkImage* pImage)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001355{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001356 VkResult result = nextTable.CreateImage(device, pCreateInfo, pImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001357 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001358 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001359 addObjectInfo(*pImage, pCreateInfo->sType, pCreateInfo, sizeof(VkImageCreateInfo), "image");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001360 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001361 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001362 return result;
1363}
1364
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001365VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001366{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001367 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001368 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001369 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001370 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkImageViewCreateInfo), "image_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001371 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001372 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001373 return result;
1374}
1375
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001376VK_LAYER_EXPORT VkResult VKAPI vkCreateColorAttachmentView(VkDevice device, const VkColorAttachmentViewCreateInfo* pCreateInfo,
1377 VkColorAttachmentView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001378{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001379 VkResult result = nextTable.CreateColorAttachmentView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001380 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001381 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001382 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkColorAttachmentViewCreateInfo), "color_attachment_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001383 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001384 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001385 return result;
1386}
1387
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001388VK_LAYER_EXPORT VkResult VKAPI vkCreateDepthStencilView(VkDevice device, const VkDepthStencilViewCreateInfo* pCreateInfo, VkDepthStencilView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001389{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001390 VkResult result = nextTable.CreateDepthStencilView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001391 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001392 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001393 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkDepthStencilViewCreateInfo), "ds_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001394 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001395 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001396 return result;
1397}
1398
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001399VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(VkDevice device, const VkShaderCreateInfo* pCreateInfo, VkShader* pShader)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001400{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001401 VkResult result = nextTable.CreateShader(device, pCreateInfo, pShader);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001402 return result;
1403}
1404
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001405VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001406{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001407 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001408 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001409 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001410 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001411 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001412 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001413 return result;
1414}
1415
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001416VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1417 VkDevice device,
1418 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1419 VkPipeline basePipeline,
1420 VkPipeline* pPipeline)
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001421{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001422 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001423 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001424 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001425 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001426 loader_platform_thread_unlock_mutex(&globalLock);
1427 }
1428 return result;
1429}
1430
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001431VK_LAYER_EXPORT VkResult VKAPI vkCreateComputePipeline(VkDevice device, const VkComputePipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001432{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001433 VkResult result = nextTable.CreateComputePipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001434 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001435 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001436 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkComputePipelineCreateInfo), "compute_pipeline");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001437 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001438 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001439 return result;
1440}
1441
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001442VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001443{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001444 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001445 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001446 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001447 addObjectInfo(*pSampler, pCreateInfo->sType, pCreateInfo, sizeof(VkSamplerCreateInfo), "sampler");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001448 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001449 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001450 return result;
1451}
1452
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001453VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001454 VkDynamicVpState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001455{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001456 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001457 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001458 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001459 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo), "viewport_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001460 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001461 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001462 return result;
1463}
1464
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001465VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001466 VkDynamicRsState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001467{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001468 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001469 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001470 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001471 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo), "raster_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001472 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001473 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001474 return result;
1475}
1476
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001477VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001478 VkDynamicCbState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001479{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001480 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001481 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001482 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001483 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo), "cb_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001484 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001485 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001486 return result;
1487}
1488
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001489VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001490 VkDynamicDsState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001491{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001492 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001493 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001494 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001495 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo), "ds_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001496 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001497 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001498 return result;
1499}
1500
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001501VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001502{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001503 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001504 // At time of cmd buffer creation, create global cmd buffer info for the returned cmd buffer
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001505 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001506 if (*pCmdBuffer)
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001507 addCBInfo(*pCmdBuffer);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001508 printCBList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001509 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001510 return result;
1511}
1512
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001513VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001514{
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001515 // 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 -05001516 MT_CB_INFO* pCBInfo = getCBInfo(cmdBuffer);
1517 if (pCBInfo && (!fenceRetired(pCBInfo->fenceId))) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001518 bool32_t cbDone = checkCBCompleted(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001519 if (VK_FALSE == cbDone) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001520 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001521 sprintf(str, "Calling vkBeginCommandBuffer() on active CB %p before it has completed. You must check CB flag before this call.", cmdBuffer);
1522 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 -07001523 }
1524 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001525 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001526 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001527 freeCBBindings(cmdBuffer);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001528 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001529 return result;
1530}
1531
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001532VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001533{
1534 // TODO : Anything to do here?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001535 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001536 return result;
1537}
1538
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001539VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001540{
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001541 // Verify that CB is complete (not in-flight)
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001542 MT_CB_INFO* pCBInfo = getCBInfo(cmdBuffer);
1543 if (pCBInfo && (!fenceRetired(pCBInfo->fenceId))) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001544 bool32_t cbDone = checkCBCompleted(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001545 if (VK_FALSE == cbDone) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001546 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001547 sprintf(str, "Resetting CB %p before it has completed. You must check CB flag before calling vkResetCommandBuffer().", cmdBuffer);
1548 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 -07001549 }
1550 }
1551 // Clear memory references as this point.
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001552 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001553 freeCBBindings(cmdBuffer);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001554 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001555 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001556 return result;
1557}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001558// TODO : For any vkCmdBind* calls that include an object which has mem bound to it,
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001559// need to account for that mem now having binding to given cmdBuffer
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001560VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001561{
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001562#if 0
1563 // TODO : If memory bound to pipeline, then need to tie that mem to cmdBuffer
1564 if (getPipeline(pipeline)) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001565 MT_CB_INFO *pCBInfo = getCBInfo(cmdBuffer);
1566 if (pCBInfo) {
1567 pCBInfo->pipelines[pipelineBindPoint] = pipeline;
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001568 } else {
1569 char str[1024];
1570 sprintf(str, "Attempt to bind Pipeline %p to non-existant command buffer %p!", (void*)pipeline, cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001571 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 -07001572 }
1573 }
1574 else {
1575 char str[1024];
1576 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001577 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 -07001578 }
1579#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001580 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1581}
1582
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001583VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001584{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001585 MT_OBJ_INFO *pObjInfo;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001586 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001587 MT_CB_INFO *pCmdBuf = getCBInfo(cmdBuffer);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001588 if (!pCmdBuf) {
1589 char str[1024];
1590 sprintf(str, "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001591 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_INVALID_CB, "DD", str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001592 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001593 pObjInfo = getObjectInfo(state);
1594 if (!pObjInfo) {
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001595 char str[1024];
1596 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001597 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, state, 0, MEMTRACK_INVALID_OBJECT, "DD", str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001598 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001599 pCmdBuf->pDynamicState[stateBindPoint] = pObjInfo;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001600 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001601 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001602}
1603
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001604VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001605 VkCmdBuffer cmdBuffer,
1606 VkPipelineBindPoint pipelineBindPoint,
1607 VkDescriptorSetLayoutChain layoutChain,
Mark Lobodzinski411f0612015-04-07 09:34:09 -05001608 uint32_t layoutChainSlot,
1609 uint32_t count,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001610 const VkDescriptorSet* pDescriptorSets,
Mark Lobodzinski411f0612015-04-07 09:34:09 -05001611 const uint32_t* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001612{
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001613 // 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 -06001614 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, layoutChain, layoutChainSlot, count, pDescriptorSets, pUserData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001615}
1616
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001617VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t binding)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001618{
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001619 nextTable.CmdBindVertexBuffer(cmdBuffer, buffer, offset, binding);
Chia-I Wufb5062e2015-01-05 13:42:56 +08001620}
1621
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001622VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, VkIndexType indexType)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001623{
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001624 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001625}
1626
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001627VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001628{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001629 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001630 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001631 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001632 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001633 sprintf(str, "In vkCmdDrawIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1634 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001635 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001636 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001637 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001638}
1639
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001640VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001641{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001642 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001643 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001644 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001645 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001646 sprintf(str, "In vkCmdDrawIndexedIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1647 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001648 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001649 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001650 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001651}
1652
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001653VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001654{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001655 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001656 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001657 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001658 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001659 sprintf(str, "In vkCmdDispatchIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1660 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001661 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001662 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001663 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001664}
1665
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001666VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer,
1667 uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001668{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001669 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001670 VkGpuMemory mem = getMemBindingFromObject(srcBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001671 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001672 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001673 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
1674 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001675 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001676 mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001677 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001678 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001679 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1680 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001681 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001682 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001683 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001684}
1685
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001686VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
1687 VkImage srcImage, VkImageLayout srcImageLayout,
1688 VkImage destImage, VkImageLayout destImageLayout,
1689 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001690{
1691 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001692 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001693}
1694
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001695VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
1696 VkImage srcImage, VkImageLayout srcImageLayout,
1697 VkImage destImage, VkImageLayout destImageLayout,
1698 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchterb787a1e2015-03-08 17:02:18 -06001699{
1700 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001701 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Courtney Goeltzenleuchterb787a1e2015-03-08 17:02:18 -06001702}
1703
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001704VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
1705 VkBuffer srcBuffer,
1706 VkImage destImage, VkImageLayout destImageLayout,
1707 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001708{
1709 // TODO : Track this
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001710 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001711 VkGpuMemory mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001712 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001713 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001714 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1715 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001716 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001717
1718 mem = getMemBindingFromObject(srcBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001719 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001720 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001721 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
1722 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001723 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001724 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001725 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001726}
1727
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001728VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
1729 VkImage srcImage, VkImageLayout srcImageLayout,
1730 VkBuffer destBuffer,
1731 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001732{
1733 // TODO : Track this
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001734 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001735 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001736 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001737 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001738 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1739 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001740 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001741 mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001742 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001743 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001744 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1745 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001746 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001747 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001748 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001749}
1750
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001751VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout,
1752 VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001753{
1754 // TODO : Each image will have mem mapping so track them
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001755 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001756 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001757 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001758 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001759 sprintf(str, "In vkCmdCloneImageData() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1760 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001761 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001762 mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001763 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001764 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001765 sprintf(str, "In vkCmdCloneImageData() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1766 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001767 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001768 loader_platform_thread_unlock_mutex(&globalLock);
Mike Stroyan55658c22014-12-04 11:08:39 +00001769 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001770}
1771
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001772VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkGpuSize destOffset, VkGpuSize dataSize, const uint32_t* pData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001773{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001774 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001775 VkGpuMemory mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001776 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001777 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001778 sprintf(str, "In vkCmdUpdateMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1779 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001780 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001781 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001782 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001783}
1784
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001785VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkGpuSize destOffset, VkGpuSize fillSize, uint32_t data)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001786{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001787 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001788 VkGpuMemory mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001789 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001790 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001791 sprintf(str, "In vkCmdFillMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1792 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001793 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001794 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001795 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001796}
1797
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001798VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(VkCmdBuffer cmdBuffer,
1799 VkImage image, VkImageLayout imageLayout,
1800 VkClearColor color,
1801 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001802{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001803 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001804 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001805 VkGpuMemory mem = getMemBindingFromObject(image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001806 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001807 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001808 sprintf(str, "In vkCmdClearColorImage() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
1809 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001810 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001811 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001812 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001813}
1814
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001815VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
1816 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001817 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001818 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001819{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001820 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001821 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001822 VkGpuMemory mem = getMemBindingFromObject(image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001823 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001824 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001825 sprintf(str, "In vkCmdClearDepthStencil() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
1826 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001827 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001828 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001829 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001830}
1831
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001832VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
1833 VkImage srcImage, VkImageLayout srcImageLayout,
1834 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06001835 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001836{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001837 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001838 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001839 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001840 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001841 sprintf(str, "In vkCmdResolveImage() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1842 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001843 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001844 mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001845 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001846 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001847 sprintf(str, "In vkCmdResolveImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1848 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001849 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001850 loader_platform_thread_unlock_mutex(&globalLock);
Tony Barbour11f74372015-04-13 15:02:52 -06001851 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001852}
1853
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001854VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001855{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001856 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001857 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001858 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001859 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001860 sprintf(str, "In vkCmdBeginQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1861 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001862 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001863 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001864 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
1865}
1866
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001867VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001868{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001869 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001870 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001871 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001872 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001873 sprintf(str, "In vkCmdEndQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1874 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001875 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001876 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001877 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
1878}
1879
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001880VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001881{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001882 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001883 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001884 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001885 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001886 sprintf(str, "In vkCmdResetQueryPool() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1887 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001888 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001889 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001890 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
1891}
1892
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001893VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001894{
Tobin Ehlis62086412014-11-19 16:19:28 -07001895 // This layer intercepts callbacks
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001896 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 -07001897 if (!pNewDbgFuncNode)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001898 return VK_ERROR_OUT_OF_MEMORY;
Tobin Ehlis62086412014-11-19 16:19:28 -07001899 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
1900 pNewDbgFuncNode->pUserData = pUserData;
Jon Ashburnf57ea372014-12-22 13:24:15 -07001901 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
1902 g_pDbgFunctionHead = pNewDbgFuncNode;
Jon Ashburne4722392015-03-03 15:07:15 -07001903 // force callbacks if DebugAction hasn't been set already other than initial value
Courtney Goeltzenleuchter9e3aafa2015-03-04 15:47:34 -07001904 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001905 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Courtney Goeltzenleuchter9e3aafa2015-03-04 15:47:34 -07001906 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001907 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001908 return result;
1909}
1910
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001911VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001912{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001913 VK_LAYER_DBG_FUNCTION_NODE *pInfo = g_pDbgFunctionHead;
1914 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pInfo;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001915 while (pInfo) {
1916 if (pInfo->pfnMsgCallback == pfnMsgCallback) {
1917 pPrev->pNext = pInfo->pNext;
1918 if (g_pDbgFunctionHead == pInfo)
1919 g_pDbgFunctionHead = pInfo->pNext;
1920 free(pInfo);
Tobin Ehlis62086412014-11-19 16:19:28 -07001921 break;
1922 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001923 pPrev = pInfo;
1924 pInfo = pInfo->pNext;
Tobin Ehlis62086412014-11-19 16:19:28 -07001925 }
Jon Ashburne4722392015-03-03 15:07:15 -07001926 if (g_pDbgFunctionHead == NULL)
1927 {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001928 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001929 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001930 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001931 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001932 }
Jon Ashburne4722392015-03-03 15:07:15 -07001933 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001934 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001935 return result;
1936}
1937
Jon Ashburndc899962015-03-02 16:51:38 -07001938#if !defined(WIN32)
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001939VK_LAYER_EXPORT VkResult VKAPI vkWsiX11CreatePresentableImage(VkDevice device, const VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO* pCreateInfo,
1940 VkImage* pImage, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001941{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001942 VkResult result = nextTable.WsiX11CreatePresentableImage(device, pCreateInfo, pImage, pMem);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001943 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001944 if (VK_SUCCESS == result) {
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001945 // Add image object, then insert the new Mem Object and then bind it to created image
Courtney Goeltzenleuchter070f6da2015-04-10 17:59:44 -06001946 addObjectInfo(*pImage, VkStructureType_MAX_ENUM, pCreateInfo, sizeof(VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO), "wsi_x11_image");
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001947 addMemObjInfo(*pMem, NULL);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001948 if (VK_FALSE == updateObjectBinding(*pImage, *pMem)) {
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001949 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001950 sprintf(str, "In vkWsiX11CreatePresentableImage(), unable to set image %p binding to mem obj %p", (void*)*pImage, (void*)*pMem);
1951 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pImage, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001952 }
Tobin Ehlis62086412014-11-19 16:19:28 -07001953 }
1954 printObjList();
1955 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001956 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001957 return result;
1958}
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001959
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001960VK_LAYER_EXPORT VkResult VKAPI vkWsiX11QueuePresent(VkQueue queue, const VK_WSI_X11_PRESENT_INFO* pPresentInfo, VkFence fence)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001961{
1962 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001963 addFenceInfo(fence, queue);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001964 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001965 sprintf(str, "In vkWsiX11QueuePresent(), checking queue %p for fence %p", queue, fence);
1966 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001967 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001968 VkResult result = nextTable.WsiX11QueuePresent(queue, pPresentInfo, fence);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001969 return result;
1970}
Ian Elliott81ac44c2015-01-13 17:52:38 -07001971#endif // WIN32
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001972
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001973VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalGpu gpu, const char* funcName)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001974{
Jon Ashburn301c5f02015-04-06 10:58:22 -06001975 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Chia-I Wu706533e2015-01-05 13:18:57 +08001976
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001977 if (gpu == NULL)
1978 return NULL;
1979 pCurObj = gpuw;
Ian Elliott81ac44c2015-01-13 17:52:38 -07001980 loader_platform_thread_once(&g_initOnce, initMemTracker);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001981
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001982 if (!strcmp(funcName, "vkGetProcAddr"))
1983 return (void *) vkGetProcAddr;
1984 if (!strcmp(funcName, "vkCreateDevice"))
1985 return (void*) vkCreateDevice;
1986 if (!strcmp(funcName, "vkDestroyDevice"))
1987 return (void*) vkDestroyDevice;
1988 if (!strcmp(funcName, "vkGetExtensionSupport"))
1989 return (void*) vkGetExtensionSupport;
1990 if (!strcmp(funcName, "vkEnumerateLayers"))
1991 return (void*) vkEnumerateLayers;
1992 if (!strcmp(funcName, "vkQueueSubmit"))
1993 return (void*) vkQueueSubmit;
1994 if (!strcmp(funcName, "vkAllocMemory"))
1995 return (void*) vkAllocMemory;
1996 if (!strcmp(funcName, "vkFreeMemory"))
1997 return (void*) vkFreeMemory;
1998 if (!strcmp(funcName, "vkSetMemoryPriority"))
1999 return (void*) vkSetMemoryPriority;
2000 if (!strcmp(funcName, "vkMapMemory"))
2001 return (void*) vkMapMemory;
2002 if (!strcmp(funcName, "vkUnmapMemory"))
2003 return (void*) vkUnmapMemory;
2004 if (!strcmp(funcName, "vkPinSystemMemory"))
2005 return (void*) vkPinSystemMemory;
2006 if (!strcmp(funcName, "vkOpenSharedMemory"))
2007 return (void*) vkOpenSharedMemory;
2008 if (!strcmp(funcName, "vkOpenPeerMemory"))
2009 return (void*) vkOpenPeerMemory;
2010 if (!strcmp(funcName, "vkOpenPeerImage"))
2011 return (void*) vkOpenPeerImage;
2012 if (!strcmp(funcName, "vkDestroyObject"))
2013 return (void*) vkDestroyObject;
2014 if (!strcmp(funcName, "vkGetObjectInfo"))
2015 return (void*) vkGetObjectInfo;
2016 if (!strcmp(funcName, "vkBindObjectMemory"))
2017 return (void*) vkBindObjectMemory;
2018 if (!strcmp(funcName, "vkCreateFence"))
2019 return (void*) vkCreateFence;
2020 if (!strcmp(funcName, "vkGetFenceStatus"))
2021 return (void*) vkGetFenceStatus;
2022 if (!strcmp(funcName, "vkResetFences"))
2023 return (void*) vkResetFences;
2024 if (!strcmp(funcName, "vkWaitForFences"))
2025 return (void*) vkWaitForFences;
2026 if (!strcmp(funcName, "vkQueueWaitIdle"))
2027 return (void*) vkQueueWaitIdle;
2028 if (!strcmp(funcName, "vkDeviceWaitIdle"))
2029 return (void*) vkDeviceWaitIdle;
2030 if (!strcmp(funcName, "vkCreateEvent"))
2031 return (void*) vkCreateEvent;
2032 if (!strcmp(funcName, "vkCreateQueryPool"))
2033 return (void*) vkCreateQueryPool;
2034 if (!strcmp(funcName, "vkCreateBuffer"))
2035 return (void*) vkCreateBuffer;
2036 if (!strcmp(funcName, "vkCreateBufferView"))
2037 return (void*) vkCreateBufferView;
2038 if (!strcmp(funcName, "vkCreateImage"))
2039 return (void*) vkCreateImage;
2040 if (!strcmp(funcName, "vkCreateImageView"))
2041 return (void*) vkCreateImageView;
2042 if (!strcmp(funcName, "vkCreateColorAttachmentView"))
2043 return (void*) vkCreateColorAttachmentView;
2044 if (!strcmp(funcName, "vkCreateDepthStencilView"))
2045 return (void*) vkCreateDepthStencilView;
2046 if (!strcmp(funcName, "vkCreateShader"))
2047 return (void*) vkCreateShader;
2048 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2049 return (void*) vkCreateGraphicsPipeline;
2050 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2051 return (void*) vkCreateGraphicsPipelineDerivative;
2052 if (!strcmp(funcName, "vkCreateComputePipeline"))
2053 return (void*) vkCreateComputePipeline;
2054 if (!strcmp(funcName, "vkCreateSampler"))
2055 return (void*) vkCreateSampler;
2056 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2057 return (void*) vkCreateDynamicViewportState;
2058 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2059 return (void*) vkCreateDynamicRasterState;
2060 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2061 return (void*) vkCreateDynamicColorBlendState;
2062 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2063 return (void*) vkCreateDynamicDepthStencilState;
2064 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2065 return (void*) vkCreateCommandBuffer;
2066 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2067 return (void*) vkBeginCommandBuffer;
2068 if (!strcmp(funcName, "vkEndCommandBuffer"))
2069 return (void*) vkEndCommandBuffer;
2070 if (!strcmp(funcName, "vkResetCommandBuffer"))
2071 return (void*) vkResetCommandBuffer;
2072 if (!strcmp(funcName, "vkCmdBindPipeline"))
2073 return (void*) vkCmdBindPipeline;
2074 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2075 return (void*) vkCmdBindDynamicStateObject;
2076 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2077 return (void*) vkCmdBindDescriptorSets;
2078 if (!strcmp(funcName, "vkCmdBindVertexBuffer"))
2079 return (void*) vkCmdBindVertexBuffer;
2080 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2081 return (void*) vkCmdBindIndexBuffer;
2082 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2083 return (void*) vkCmdDrawIndirect;
2084 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2085 return (void*) vkCmdDrawIndexedIndirect;
2086 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2087 return (void*) vkCmdDispatchIndirect;
2088 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2089 return (void*) vkCmdCopyBuffer;
2090 if (!strcmp(funcName, "vkCmdCopyImage"))
2091 return (void*) vkCmdCopyImage;
2092 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2093 return (void*) vkCmdCopyBufferToImage;
2094 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2095 return (void*) vkCmdCopyImageToBuffer;
2096 if (!strcmp(funcName, "vkCmdCloneImageData"))
2097 return (void*) vkCmdCloneImageData;
2098 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2099 return (void*) vkCmdUpdateBuffer;
2100 if (!strcmp(funcName, "vkCmdFillBuffer"))
2101 return (void*) vkCmdFillBuffer;
2102 if (!strcmp(funcName, "vkCmdClearColorImage"))
2103 return (void*) vkCmdClearColorImage;
2104 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2105 return (void*) vkCmdClearDepthStencil;
2106 if (!strcmp(funcName, "vkCmdResolveImage"))
2107 return (void*) vkCmdResolveImage;
2108 if (!strcmp(funcName, "vkCmdBeginQuery"))
2109 return (void*) vkCmdBeginQuery;
2110 if (!strcmp(funcName, "vkCmdEndQuery"))
2111 return (void*) vkCmdEndQuery;
2112 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2113 return (void*) vkCmdResetQueryPool;
2114 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2115 return (void*) vkDbgRegisterMsgCallback;
2116 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2117 return (void*) vkDbgUnregisterMsgCallback;
2118 if (!strcmp(funcName, "vkGetDeviceQueue"))
2119 return (void*) vkGetDeviceQueue;
2120 if (!strcmp(funcName, "vkQueueAddMemReference"))
2121 return (void*) vkQueueAddMemReference;
2122 if (!strcmp(funcName, "vkQueueRemoveMemReference"))
2123 return (void*) vkQueueRemoveMemReference;
Jon Ashburndc899962015-03-02 16:51:38 -07002124#if !defined(WIN32)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002125 if (!strcmp(funcName, "vkWsiX11CreatePresentableImage"))
2126 return (void*) vkWsiX11CreatePresentableImage;
2127 if (!strcmp(funcName, "vkWsiX11QueuePresent"))
2128 return (void*) vkWsiX11QueuePresent;
Jon Ashburndc899962015-03-02 16:51:38 -07002129#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002130 else {
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002131 if (gpuw->pGPA == NULL)
2132 return NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002133 return gpuw->pGPA((VkPhysicalGpu)gpuw->nextObject, funcName);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002134 }
2135}