blob: 684cb2253f9bbd7961b5753ac94f8583c0b4b5ec [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 Lobodzinskicf26e072015-04-16 11:44:05 -0500493static void reportMemReferencesAndCleanUp(MT_MEM_OBJ_INFO* pMemObjInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700494{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500495 uint32_t cmdBufRefCount = pMemObjInfo->pCmdBufferBindings.size();
496 uint32_t objRefCount = pMemObjInfo->pObjBindings.size();
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500497
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500498 if ((pMemObjInfo->pCmdBufferBindings.size() + pMemObjInfo->pObjBindings.size()) != 0) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700499 char str[1024];
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500500 sprintf(str, "Attempting to free memory object %p which still contains %d references", pMemObjInfo->mem, (cmdBufRefCount + objRefCount));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600501 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pMemObjInfo->mem, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700502 }
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500503
504 if (cmdBufRefCount > 0) {
505 for (list<VkCmdBuffer>::const_iterator it = pMemObjInfo->pCmdBufferBindings.begin(); it != pMemObjInfo->pCmdBufferBindings.end(); ++it) {
506 char str[1024];
507 sprintf(str, "Command Buffer %p still has a reference to mem obj %p", (*it), pMemObjInfo->mem);
508 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (*it), 0, MEMTRACK_NONE, "MEM", str);
509 }
510 // Clear the list of hanging references
511 pMemObjInfo->pCmdBufferBindings.clear();
512 }
513
514 if (objRefCount > 0) {
515 for (list<VkObject>::const_iterator it = pMemObjInfo->pObjBindings.begin(); it != pMemObjInfo->pObjBindings.end(); ++it) {
516 char str[1024];
517 sprintf(str, "VK Object %p still has a reference to mem obj %p", (*it), pMemObjInfo->mem);
518 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (*it), 0, MEMTRACK_NONE, "MEM", str);
519 }
520 // Clear the list of hanging references
521 pMemObjInfo->pObjBindings.clear();
522 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700523}
524
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600525static void deleteMemObjInfo(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700526{
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500527 if (memObjMap.find(mem) != memObjMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500528 MT_MEM_OBJ_INFO* pDelInfo = memObjMap[mem];
529 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500530 memObjMap.erase(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700531 }
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500532 else {
533 char str[1024];
534 sprintf(str, "Request to delete memory object %p not present in memory Object Map", mem);
535 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
536 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700537}
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500538
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700539// Check if fence for given CB is completed
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600540static bool32_t checkCBCompleted(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700541{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600542 bool32_t result = VK_TRUE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500543 MT_CB_INFO* pCBInfo = getCBInfo(cb);
544 if (!pCBInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700545 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500546 sprintf(str, "Unable to find global CB info %p to check for completion", cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600547 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
548 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600549 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500550 if (!fenceRetired(pCBInfo->fenceId)) {
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600551 char str[1024];
552 sprintf(str, "FenceId %" PRIx64", fence %p for CB %p has not been checked for completion", pCBInfo->fenceId, getFenceFromId(pCBInfo->fenceId), cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600553 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_NONE, "MEM", str);
554 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600555 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700556 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600557 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700558}
559
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600560static bool32_t freeMemObjInfo(VkGpuMemory mem, bool internal)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700561{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600562 bool32_t result = VK_TRUE;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500563 // Parse global list to find info w/ mem
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500564 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
565 if (!pInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700566 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500567 sprintf(str, "Couldn't find mem info object for %p\n Was %p never allocated or previously freed?", (void*)mem, (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600568 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
569 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600570 } else {
Courtney Goeltzenleuchterc4804862015-03-26 16:15:39 -0600571 if (pInfo->allocInfo.allocationSize == 0 && !internal) {
Mark Lobodzinskidaa1d432015-02-18 18:06:24 -0600572 char str[1024];
573 sprintf(str, "Attempting to free memory associated with a Presentable Image, %p, this should not be explicitly freed\n", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600574 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
575 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600576 } else {
577 // Clear any CB bindings for completed CBs
578 // TODO : Is there a better place to do this?
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500579
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600580 list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin();
581 list<VkCmdBuffer>::iterator temp;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500582 while (it != pInfo->pCmdBufferBindings.end()) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600583 if (VK_TRUE == checkCBCompleted(*it)) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500584 temp = it;
585 ++temp;
586 freeCBBindings(*it);
587 it = temp;
588 } else {
589 ++it;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600590 }
591 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500592
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600593 // Now verify that no references to this mem obj remain
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500594 if (0 != pInfo->refCount) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500595 // If references remain, report the error and can search CB list to find references
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600596 char str[1024];
597 sprintf(str, "Freeing mem obj %p while it still has references", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600598 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_FREED_MEM_REF, "MEM", str);
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500599 reportMemReferencesAndCleanUp(pInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600600 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600601 }
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600602 // Delete mem obj info
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500603 deleteMemObjInfo(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700604 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700605 }
606 return result;
607}
608
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700609// Remove object binding performs 3 tasks:
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500610// 1. Remove ObjectInfo from MemObjInfo list container of obj bindings & free it
611// 2. Decrement refCount for MemObjInfo
612// 3. Clear MemObjInfo ptr from ObjectInfo
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600613static bool32_t clearObjectBinding(VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700614{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600615 bool32_t result = VK_FALSE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500616 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
617 if (!pObjInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700618 char str[1024];
Mark Lobodzinski15427102015-02-18 16:38:17 -0600619 sprintf(str, "Attempting to clear mem binding for object %p: devices, queues, command buffers, shaders and memory objects do not have external memory requirements and it is unneccessary to call bind/unbindObjectMemory on them.", object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600620 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600621 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500622 if (!pObjInfo->pMemObjInfo) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600623 char str[1024];
624 sprintf(str, "Attempting to clear mem binding on obj %p but it has no binding.", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600625 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MEM_OBJ_CLEAR_EMPTY_BINDINGS, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600626 } else {
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500627 // This obj is bound to a memory object. Remove the reference to this object in that memory object's list, decrement the memObj's refcount
628 // and set the objects memory binding pointer to NULL.
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600629 for (list<VkObject>::iterator it = pObjInfo->pMemObjInfo->pObjBindings.begin(); it != pObjInfo->pMemObjInfo->pObjBindings.end(); ++it) {
Mark Lobodzinskicf26e072015-04-16 11:44:05 -0500630 if ((*it) == object) {
631 pObjInfo->pMemObjInfo->refCount--;
632 pObjInfo->pMemObjInfo->pObjBindings.erase(it);
633 pObjInfo->pMemObjInfo = NULL;
634 result = VK_TRUE;
635 break;
636 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600637 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600638 if (result == VK_FALSE) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600639 char str[1024];
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500640 sprintf(str, "While trying to clear mem binding for object %p, unable to find that object referenced by mem obj %p",
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500641 object, pObjInfo->pMemObjInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600642 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600643 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700644 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700645 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600646 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700647}
648
649// For NULL mem case, clear any previous binding Else...
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500650// Make sure given object is in global object map
Tobin Ehlis62086412014-11-19 16:19:28 -0700651// IF a previous binding existed, clear it
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500652// Add reference from objectInfo to memoryInfo
653// Add reference off of objInfo
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600654// Return VK_TRUE if addition is successful, VK_FALSE otherwise
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600655static bool32_t updateObjectBinding(VkObject object, VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700656{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600657 bool32_t result = VK_FALSE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700658 // Handle NULL case separately, just clear previous binding & decrement reference
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600659 if (mem == VK_NULL_HANDLE) {
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700660 clearObjectBinding(object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600661 result = VK_TRUE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600662 } else {
663 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500664 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
665 if (!pObjInfo) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600666 sprintf(str, "Attempting to update Binding of Obj(%p) that's not in global list()", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600667 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
668 return VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600669 }
670 // non-null case so should have real mem obj
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500671 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
672 if (!pInfo) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500673 sprintf(str, "While trying to bind mem for obj %p, couldn't find info for mem obj %p", (void*)object, (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600674 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600675 } else {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500676 // Search for object in memory object's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600677 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600678 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500679 if ((*it) == object) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600680 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500681 break;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600682 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600683 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500684 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600685 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500686 pInfo->pObjBindings.push_front(object);
687 pInfo->refCount++;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500688 }
689
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500690 if (pObjInfo->pMemObjInfo) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500691 clearObjectBinding(object); // Need to clear the previous object binding before setting new binding
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500692 sprintf(str, "Updating memory binding for object %p from mem obj %p to %p", object, pObjInfo->pMemObjInfo->mem, mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600693 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500694 }
695 // For image objects, make sure default memory state is correctly set
696 // TODO : What's the best/correct way to handle this?
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600697 if (VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO == pObjInfo->sType) {
698 if (pObjInfo->create_info.image_create_info.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_BIT)) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500699 // TODO:: More memory state transition stuff.
700 }
701 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500702 pObjInfo->pMemObjInfo = pInfo;
Tobin Ehlis6aa77422015-01-07 17:49:29 -0700703 }
704 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600705 return VK_TRUE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700706}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600707
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700708// Print details of global Obj tracking list
709static void printObjList()
710{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500711 MT_OBJ_INFO* pInfo = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500712 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500713 sprintf(str, "Details of Object list of size %lu elements", objectMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600714 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600715 for (map<VkObject, MT_OBJ_INFO*>::iterator ii=objectMap.begin(); ii!=objectMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500716 pInfo = (*ii).second;
717 sprintf(str, " ObjInfo %p has object %p, pMemObjInfo %p", pInfo, pInfo->object, pInfo->pMemObjInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600718 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pInfo->object, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700719 }
720}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600721
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700722// For given Object, get 'mem' obj that it's bound to or NULL if no binding
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600723static VkGpuMemory getMemBindingFromObject(const VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700724{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600725 VkGpuMemory mem = NULL;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500726 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
727 if (pObjInfo) {
728 if (pObjInfo->pMemObjInfo) {
729 mem = pObjInfo->pMemObjInfo->mem;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700730 }
731 else {
Tobin Ehlis62086412014-11-19 16:19:28 -0700732 char str[1024];
733 sprintf(str, "Trying to get mem binding for object %p but object has no mem binding", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600734 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MISSING_MEM_BINDINGS, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700735 printObjList();
736 }
737 }
738 else {
Tobin Ehlis62086412014-11-19 16:19:28 -0700739 char str[1024];
740 sprintf(str, "Trying to get mem binding for object %p but no such object in global list", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600741 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700742 printObjList();
743 }
744 return mem;
745}
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500746
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500747// Print details of MemObjInfo list
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700748static void printMemList()
749{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500750 MT_MEM_OBJ_INFO* pInfo = NULL;
Tobin Ehlis62086412014-11-19 16:19:28 -0700751 // Just printing each msg individually for now, may want to package these into single large print
752 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500753 sprintf(str, "MEM INFO : Details of Memory Object list of size %lu elements", memObjMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600754 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500755
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600756 for (map<VkGpuMemory, MT_MEM_OBJ_INFO*>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500757 pInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500758
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500759 sprintf(str, " ===MemObjInfo at %p===", (void*)pInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600760 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500761 sprintf(str, " Mem object: %p", (void*)pInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600762 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500763 sprintf(str, " Ref Count: %u", pInfo->refCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600764 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500765 if (0 != pInfo->allocInfo.allocationSize) {
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600766 string pAllocInfoMsg = vk_print_vkmemoryallocinfo(&pInfo->allocInfo, "{MEM}INFO : ");
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500767 sprintf(str, " Mem Alloc info:\n%s", pAllocInfoMsg.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600768 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500769 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600770 sprintf(str, " Mem Alloc info is NULL (alloc done by vkWsiX11CreatePresentableImage())");
771 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500772 }
773
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600774 sprintf(str, " VK OBJECT Binding list of size %lu elements:", pInfo->pObjBindings.size());
775 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600776 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600777 sprintf(str, " VK OBJECT %p", (*it));
778 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500779 }
780
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600781 sprintf(str, " VK Command Buffer (CB) binding list of size %lu elements", pInfo->pCmdBufferBindings.size());
782 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600783 for (list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin(); it != pInfo->pCmdBufferBindings.end(); ++it) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600784 sprintf(str, " VK CB %p", (*it));
785 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700786 }
787 }
788}
789
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500790static void printCBList()
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700791{
Tobin Ehlis62086412014-11-19 16:19:28 -0700792 char str[1024] = {0};
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500793 MT_CB_INFO* pCBInfo = NULL;
794 sprintf(str, "Details of CB list of size %lu elements", cbMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600795 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500796
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600797 for (map<VkCmdBuffer, MT_CB_INFO*>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500798 pCBInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500799
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500800 sprintf(str, " CB Info (%p) has CB %p, fenceId %" PRIx64", and fence %p",
801 (void*)pCBInfo, (void*)pCBInfo->cmdBuffer, pCBInfo->fenceId,
802 (void*)getFenceFromId(pCBInfo->fenceId));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600803 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500804
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600805 for (list<VkGpuMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500806 sprintf(str, " Mem obj %p", (*it));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600807 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700808 }
809 }
810}
811
Mark Lobodzinski15427102015-02-18 16:38:17 -0600812static void initMemTracker(void)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700813{
Jon Ashburnf57ea372014-12-22 13:24:15 -0700814 const char *strOpt;
815 // initialize MemTracker options
Ian Elliott7d0b5d22015-03-06 13:50:05 -0700816 getLayerOptionEnum("MemTrackerReportLevel", (uint32_t *) &g_reportingLevel);
817 g_actionIsDefault = getLayerOptionEnum("MemTrackerDebugAction", (uint32_t *) &g_debugAction);
Tobin Ehlis5b7acaa2015-01-08 14:26:53 -0700818
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600819 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Jon Ashburnf57ea372014-12-22 13:24:15 -0700820 {
821 strOpt = getLayerOption("MemTrackerLogFilename");
822 if (strOpt)
823 {
824 g_logFile = fopen(strOpt, "w");
Jon Ashburnf57ea372014-12-22 13:24:15 -0700825 }
826 if (g_logFile == NULL)
827 g_logFile = stdout;
828 }
829
830 // initialize Layer dispatch table
831 // TODO handle multiple GPUs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600832 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700833 fpNextGPA = pCurObj->pGPA;
834 assert(fpNextGPA);
835
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600836 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalGpu) pCurObj->nextObject);
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800837
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600838 if (!globalLockInitialized)
839 {
840 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600841 // suggestion is to call this during vkCreateInstance(), and then we
842 // can clean it up during vkDestroyInstance(). However, that requires
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600843 // that the layer have per-instance locks. We need to come back and
844 // address this soon.
845 loader_platform_thread_create_mutex(&globalLock);
846 globalLockInitialized = 1;
847 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700848}
849
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600850VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700851{
Jon Ashburn630e44f2015-04-08 21:33:34 -0600852 pCurObj = (VkBaseLayerObject *) gpu;
Ian Elliott81ac44c2015-01-13 17:52:38 -0700853 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburn630e44f2015-04-08 21:33:34 -0600854 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700855 // Save off device in case we need it to create Fences
856 globalDevice = *pDevice;
857 return result;
858}
859
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600860VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700861{
Tobin Ehlis62086412014-11-19 16:19:28 -0700862 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600863 sprintf(str, "Printing List details prior to vkDestroyDevice()");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600864 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600865 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, device, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700866 printMemList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500867 printCBList();
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700868 printObjList();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600869 if (VK_FALSE == deleteCBInfoList()) {
870 sprintf(str, "Issue deleting global CB list in vkDestroyDevice()");
871 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, device, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -0700872 }
Tobin Ehlis22d03232014-11-25 18:01:12 -0700873 // Report any memory leaks
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500874 MT_MEM_OBJ_INFO* pInfo = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600875 for (map<VkGpuMemory, MT_MEM_OBJ_INFO*>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500876 pInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500877
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500878 if (pInfo->allocInfo.allocationSize != 0) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600879 sprintf(str, "Mem Object %p has not been freed. You should clean up this memory by calling vkFreeMemory(%p) prior to vkDestroyDevice().",
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500880 pInfo->mem, pInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600881 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, pInfo->mem, 0, MEMTRACK_MEMORY_LEAK, "MEM", str);
Mark Lobodzinskidaa1d432015-02-18 18:06:24 -0600882 }
Tobin Ehlis22d03232014-11-25 18:01:12 -0700883 }
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500884
885 // Queues persist until device is destroyed
886 deleteQueueInfoList();
887
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600888 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600889 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700890 return result;
891}
892
Jon Ashburneb2728b2015-04-10 14:33:07 -0600893struct extProps {
894 uint32_t version;
895 const char * const name;
896};
Jon Ashburnbdcd7562015-04-14 14:12:59 -0600897#define MEM_TRACKER_LAYER_EXT_ARRAY_SIZE 2
Jon Ashburneb2728b2015-04-10 14:33:07 -0600898static const struct extProps mtExts[MEM_TRACKER_LAYER_EXT_ARRAY_SIZE] = {
899 // TODO what is the version?
Jon Ashburnbdcd7562015-04-14 14:12:59 -0600900 0x10, "MemTracker",
901 0x10, "Validation"
Jon Ashburneb2728b2015-04-10 14:33:07 -0600902};
903
904VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
905 VkExtensionInfoType infoType,
906 uint32_t extensionIndex,
907 size_t* pDataSize,
908 void* pData)
909{
910 VkResult result;
911
912 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
913 VkExtensionProperties *ext_props;
914 uint32_t *count;
915
916 if (pDataSize == NULL)
917 return VK_ERROR_INVALID_POINTER;
918
919 switch (infoType) {
920 case VK_EXTENSION_INFO_TYPE_COUNT:
921 *pDataSize = sizeof(uint32_t);
922 if (pData == NULL)
923 return VK_SUCCESS;
924 count = (uint32_t *) pData;
925 *count = MEM_TRACKER_LAYER_EXT_ARRAY_SIZE;
926 break;
927 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
928 *pDataSize = sizeof(VkExtensionProperties);
929 if (pData == NULL)
930 return VK_SUCCESS;
931 if (extensionIndex >= MEM_TRACKER_LAYER_EXT_ARRAY_SIZE)
932 return VK_ERROR_INVALID_VALUE;
933 ext_props = (VkExtensionProperties *) pData;
934 ext_props->version = mtExts[extensionIndex].version;
935 strncpy(ext_props->extName, mtExts[extensionIndex].name,
936 VK_MAX_EXTENSION_NAME);
937 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
938 break;
939 default:
940 return VK_ERROR_INVALID_VALUE;
941 };
942
943 return VK_SUCCESS;
944}
945
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600946VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalGpu gpu, size_t maxLayerCount,
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500947 size_t maxStringSize, size_t* pOutLayerCount, char* const* pOutLayers, void* pReserved)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700948{
Jon Ashburn451c16f2014-11-25 11:08:42 -0700949 if (gpu != NULL)
950 {
Jon Ashburn630e44f2015-04-08 21:33:34 -0600951 pCurObj = (VkBaseLayerObject *) gpu;
Ian Elliott81ac44c2015-01-13 17:52:38 -0700952 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburn630e44f2015-04-08 21:33:34 -0600953 VkResult result = nextTable.EnumerateLayers(gpu, maxLayerCount,
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500954 maxStringSize, pOutLayerCount, pOutLayers, pReserved);
Jon Ashburn451c16f2014-11-25 11:08:42 -0700955 return result;
956 } else
957 {
958 if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600959 return VK_ERROR_INVALID_POINTER;
Jon Ashburn451c16f2014-11-25 11:08:42 -0700960 // This layer compatible with all GPUs
961 *pOutLayerCount = 1;
Chia-I Wua837c522014-12-16 10:47:33 +0800962 strncpy((char *) pOutLayers[0], "MemTracker", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600963 return VK_SUCCESS;
Jon Ashburn451c16f2014-11-25 11:08:42 -0700964 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700965}
966
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600967VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueNodeIndex, uint32_t queueIndex, VkQueue* pQueue)
Mark Lobodzinski55e53d92015-03-31 16:05:35 -0500968{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600969 VkResult result = nextTable.GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600970 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500971 loader_platform_thread_lock_mutex(&globalLock);
972 addQueueInfo(*pQueue);
973 loader_platform_thread_unlock_mutex(&globalLock);
974 }
Mark Lobodzinski55e53d92015-03-31 16:05:35 -0500975 return result;
976}
977
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600978VK_LAYER_EXPORT VkResult VKAPI vkQueueAddMemReference(VkQueue queue, VkGpuMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500979{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600980 VkResult result = nextTable.QueueAddMemReference(queue, mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600981 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500982 loader_platform_thread_lock_mutex(&globalLock);
983
984 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
985 if (pQueueInfo == NULL) {
986 char str[1024];
987 sprintf(str, "Unknown Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600988 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500989 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500990 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600991 if (checkMemRef(queue, mem) == VK_TRUE) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500992 // Alread in list, just warn
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500993 char str[1024];
994 sprintf(str, "Request to add a memory reference (%p) to Queue %p -- ref is already present in the queue's reference list", mem, queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600995 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500996 }
997 else {
998 // Add to queue's memory reference list
999 pQueueInfo->pMemRefList.push_front(mem);
1000 }
1001 }
1002 loader_platform_thread_unlock_mutex(&globalLock);
1003 }
1004 return result;
1005}
1006
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001007VK_LAYER_EXPORT VkResult VKAPI vkQueueRemoveMemReference(VkQueue queue, VkGpuMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001008{
1009 // TODO : Decrement ref count for this memory reference on this queue. Remove if ref count is zero.
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001010 VkResult result = nextTable.QueueRemoveMemReference(queue, mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001011 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001012 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001013
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001014 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
1015 if (pQueueInfo == NULL) {
1016 char str[1024];
1017 sprintf(str, "Unknown Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001018 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001019 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001020 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001021 for (list<VkGpuMemory>::iterator it = pQueueInfo->pMemRefList.begin(); it != pQueueInfo->pMemRefList.end(); ++it) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001022 if ((*it) == mem) {
1023 it = pQueueInfo->pMemRefList.erase(it);
1024 }
1025 }
1026 }
1027 loader_platform_thread_unlock_mutex(&globalLock);
1028 }
1029 return result;
1030}
1031
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001032VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(
1033 VkQueue queue,
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001034 uint32_t cmdBufferCount,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001035 const VkCmdBuffer *pCmdBuffers,
1036 VkFence fence)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001037{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001038 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001039 // TODO : Need to track fence and clear mem references when fence clears
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001040 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001041 uint64_t fenceId = addFenceInfo(fence, queue);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001042
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001043 printMemList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001044 printCBList();
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001045 for (uint32_t i = 0; i < cmdBufferCount; i++) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001046 pCBInfo = getCBInfo(pCmdBuffers[i]);
1047 pCBInfo->fenceId = fenceId;
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001048 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001049
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001050 if (VK_FALSE == validateQueueMemRefs(queue, cmdBufferCount, pCmdBuffers)) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001051 char str[1024];
1052 sprintf(str, "Unable to verify memory references for Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001053 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001054 }
1055
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001056 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001057 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, getFenceFromId(fenceId));
Courtney Goeltzenleuchtercfedf362015-04-02 13:39:07 -06001058 return result;
1059}
1060
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001061VK_LAYER_EXPORT VkResult VKAPI vkAllocMemory(VkDevice device, const VkMemoryAllocInfo* pAllocInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001062{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001063 VkResult result = nextTable.AllocMemory(device, pAllocInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001064 // TODO : Track allocations and overall size here
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001065 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001066 addMemObjInfo(*pMem, pAllocInfo);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001067 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001068 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001069 return result;
1070}
1071
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001072VK_LAYER_EXPORT VkResult VKAPI vkFreeMemory(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001073{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001074 /* From spec : A memory object is freed by calling vkFreeMemory() when it is no longer needed. Before
Tobin Ehlisa747e682014-11-25 14:47:20 -07001075 * freeing a memory object, an application must ensure the memory object is unbound from
1076 * all API objects referencing it and that it is not referenced by any queued command buffers
1077 */
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001078 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001079 if (VK_FALSE == freeMemObjInfo(mem, false)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001080 char str[1024];
1081 sprintf(str, "Issue while freeing mem obj %p", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001082 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_FREE_MEM_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001083 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001084 printMemList();
1085 printObjList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001086 printCBList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001087 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001088 VkResult result = nextTable.FreeMemory(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001089 return result;
1090}
1091
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001092VK_LAYER_EXPORT VkResult VKAPI vkSetMemoryPriority(VkGpuMemory mem, VkMemoryPriority priority)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001093{
1094 // TODO : Update tracking for this alloc
1095 // Make sure memory is not pinned, which can't have priority set
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001096 VkResult result = nextTable.SetMemoryPriority(mem, priority);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001097 return result;
1098}
1099
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001100VK_LAYER_EXPORT VkResult VKAPI vkMapMemory(VkGpuMemory mem, VkFlags flags, void** ppData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001101{
1102 // TODO : Track when memory is mapped
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001103 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001104 MT_MEM_OBJ_INFO *pMemObj = getMemObjInfo(mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001105 if ((pMemObj->allocInfo.memProps & VK_MEMORY_PROPERTY_CPU_VISIBLE_BIT) == 0) {
Mark Lobodzinski06f60b82015-02-25 12:16:04 -06001106 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001107 sprintf(str, "Mapping Memory (%p) without VK_MEMORY_PROPERTY_CPU_VISIBLE_BIT set", (void*)mem);
1108 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_STATE, "MEM", str);
Mark Lobodzinski06f60b82015-02-25 12:16:04 -06001109 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001110 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001111 VkResult result = nextTable.MapMemory(mem, flags, ppData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001112 return result;
1113}
1114
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001115VK_LAYER_EXPORT VkResult VKAPI vkUnmapMemory(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001116{
1117 // TODO : Track as memory gets unmapped, do we want to check what changed following map?
1118 // Make sure that memory was ever mapped to begin with
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001119 VkResult result = nextTable.UnmapMemory(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001120 return result;
1121}
1122
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001123VK_LAYER_EXPORT VkResult VKAPI vkPinSystemMemory(VkDevice device, const void* pSysMem, size_t memSize, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001124{
1125 // TODO : Track this
1126 // Verify that memory is actually pinnable
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001127 VkResult result = nextTable.PinSystemMemory(device, pSysMem, memSize, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001128 return result;
1129}
1130
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001131VK_LAYER_EXPORT VkResult VKAPI vkOpenSharedMemory(VkDevice device, const VkMemoryOpenInfo* pOpenInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001132{
1133 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001134 VkResult result = nextTable.OpenSharedMemory(device, pOpenInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001135 return result;
1136}
1137
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001138VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerMemory(VkDevice device, const VkPeerMemoryOpenInfo* pOpenInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001139{
1140 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001141 VkResult result = nextTable.OpenPeerMemory(device, pOpenInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001142 return result;
1143}
1144
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001145VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerImage(VkDevice device, const VkPeerImageOpenInfo* pOpenInfo, VkImage* pImage, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001146{
1147 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001148 VkResult result = nextTable.OpenPeerImage(device, pOpenInfo, pImage, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001149 return result;
1150}
1151
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001152VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001153{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001154 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001155
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001156 // First check if this is a CmdBuffer
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001157 if (NULL != getCBInfo((VkCmdBuffer)object)) {
1158 deleteCBInfo((VkCmdBuffer)object);
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001159 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001160
1161 if (objectMap.find(object) != objectMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001162 MT_OBJ_INFO* pDelInfo = objectMap[object];
1163 if (pDelInfo->pMemObjInfo) {
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001164 // Wsi allocated Memory is tied to image object so clear the binding and free that memory automatically
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001165 if (0 == pDelInfo->pMemObjInfo->allocInfo.allocationSize) { // Wsi allocated memory has NULL allocInfo w/ 0 size
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001166 VkGpuMemory memToFree = pDelInfo->pMemObjInfo->mem;
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001167 clearObjectBinding(object);
Courtney Goeltzenleuchterc4804862015-03-26 16:15:39 -06001168 freeMemObjInfo(memToFree, true);
1169 }
1170 else {
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001171 char str[1024];
Mark Lobodzinskicf26e072015-04-16 11:44:05 -05001172 sprintf(str, "Destroying obj %p that is still bound to memory object %p\nYou should first clear binding by calling vkQueueBindObjectMemory(queue, %p, 0, VK_NULL_HANDLE, 0)", object, (void*)pDelInfo->pMemObjInfo->mem, object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001173 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_DESTROY_OBJECT_ERROR, "MEM", str);
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001174 // From the spec : If an object has previous memory binding, it is required to unbind memory from an API object before it is destroyed.
1175 clearObjectBinding(object);
1176 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001177 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001178 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001179 objectMap.erase(object);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001180 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001181
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001182 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001183 VkResult result = nextTable.DestroyObject(object);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001184 return result;
1185}
1186
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001187VK_LAYER_EXPORT VkResult VKAPI vkGetObjectInfo(VkBaseObject object, VkObjectInfoType infoType, size_t* pDataSize, void* pData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001188{
1189 // TODO : What to track here?
Mark Lobodzinskicf26e072015-04-16 11:44:05 -05001190 // Could potentially save returned mem requirements and validate values passed into QueueBindObjectMemory for this object
Tobin Ehlis62086412014-11-19 16:19:28 -07001191 // From spec : The only objects that are guaranteed to have no external memory requirements are devices, queues, command buffers, shaders and memory objects.
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001192 VkResult result = nextTable.GetObjectInfo(object, infoType, pDataSize, pData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001193 return result;
1194}
1195
Mark Lobodzinskicf26e072015-04-16 11:44:05 -05001196VK_LAYER_EXPORT VkResult VKAPI vkQueueBindObjectMemory(VkQueue queue, VkObject object, uint32_t allocationIdx, VkGpuMemory mem, VkGpuSize offset)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001197{
Mark Lobodzinskicf26e072015-04-16 11:44:05 -05001198 VkResult result = nextTable.QueueBindObjectMemory(queue, object, allocationIdx, mem, offset);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001199 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001200 // Track objects tied to memory
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001201 if (VK_FALSE == updateObjectBinding(object, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001202 char str[1024];
1203 sprintf(str, "Unable to set object %p binding to mem obj %p", (void*)object, (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001204 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001205 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001206 printObjList();
1207 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001208 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001209 return result;
1210}
1211
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001212VK_LAYER_EXPORT VkResult VKAPI vkCreateFence(VkDevice device, const VkFenceCreateInfo* pCreateInfo, VkFence* pFence)
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001213{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001214 VkResult result = nextTable.CreateFence(device, pCreateInfo, pFence);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001215 if (VK_SUCCESS == result) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001216 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001217 addObjectInfo(*pFence, pCreateInfo->sType, pCreateInfo, sizeof(VkFenceCreateInfo), "fence");
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001218 loader_platform_thread_unlock_mutex(&globalLock);
1219 }
1220 return result;
1221}
1222
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001223VK_LAYER_EXPORT VkResult VKAPI vkResetFences(VkDevice device, uint32_t fenceCount, VkFence* pFences)
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001224{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001225 VkResult result = nextTable.ResetFences(device, fenceCount, pFences);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001226 if (VK_SUCCESS == result) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001227 loader_platform_thread_lock_mutex(&globalLock);
1228 // Reset fence state in fenceCreateInfo structure
1229 for (uint32_t i = 0; i < fenceCount; i++) {
1230 MT_OBJ_INFO* pObjectInfo = getObjectInfo(pFences[i]);
1231 if (pObjectInfo != NULL) {
Mark Lobodzinski56945182015-04-09 13:46:09 -05001232 // Validate fences in SIGNALED state
Tobin Ehlisf29da382015-04-15 07:46:12 -06001233 if (!(pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT)) {
Mark Lobodzinski56945182015-04-09 13:46:09 -05001234 char str[1024];
Mark Lobodzinski610be622015-04-14 14:09:32 -05001235 sprintf(str, "Fence %p submitted to VkResetFences in UNSIGNALED STATE", pFences[i]);
Tobin Ehlisf29da382015-04-15 07:46:12 -06001236 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
1237 result = VK_ERROR_INVALID_VALUE;
Mark Lobodzinski56945182015-04-09 13:46:09 -05001238 }
1239 else {
1240 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisf29da382015-04-15 07:46:12 -06001241 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags & ~VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinski56945182015-04-09 13:46:09 -05001242 }
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001243 }
1244 }
1245 loader_platform_thread_unlock_mutex(&globalLock);
1246 }
1247 return result;
1248}
1249
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001250VK_LAYER_EXPORT VkResult VKAPI vkGetFenceStatus(VkFence fence)
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001251{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001252 VkResult result = nextTable.GetFenceStatus(fence);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001253 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001254 loader_platform_thread_lock_mutex(&globalLock);
1255 updateFenceTracking(fence);
1256 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001257 }
1258 return result;
1259}
1260
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001261VK_LAYER_EXPORT VkResult VKAPI vkWaitForFences(VkDevice device, uint32_t fenceCount, const VkFence* pFences, bool32_t waitAll, uint64_t timeout)
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001262{
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001263 // Verify fence status of submitted fences
1264 for(uint32_t i = 0; i < fenceCount; i++) {
1265 MT_OBJ_INFO* pObjectInfo = getObjectInfo(pFences[i]);
1266 if (pObjectInfo != NULL) {
Tobin Ehlisf29da382015-04-15 07:46:12 -06001267 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001268 char str[1024];
Mark Lobodzinski610be622015-04-14 14:09:32 -05001269 sprintf(str, "VkWaitForFences specified fence %p already in SIGNALED state.", pFences[i]);
Tobin Ehlisf29da382015-04-15 07:46:12 -06001270 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001271 }
1272 }
1273 }
1274
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001275 VkResult result = nextTable.WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001276 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001277
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001278 if (VK_SUCCESS == result) {
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001279 if (waitAll || fenceCount == 1) { // Clear all the fences
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001280 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001281 updateFenceTracking(pFences[i]);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001282 }
1283 }
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001284 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001285 loader_platform_thread_unlock_mutex(&globalLock);
1286 return result;
1287}
1288
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001289VK_LAYER_EXPORT VkResult VKAPI vkQueueWaitIdle(VkQueue queue)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001290{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001291 VkResult result = nextTable.QueueWaitIdle(queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001292 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001293 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001294 retireQueueFences(queue);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001295 loader_platform_thread_unlock_mutex(&globalLock);
1296 }
1297 return result;
1298}
1299
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001300VK_LAYER_EXPORT VkResult VKAPI vkDeviceWaitIdle(VkDevice device)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001301{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001302 VkResult result = nextTable.DeviceWaitIdle(device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001303 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001304 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001305 retireDeviceFences(device);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001306 loader_platform_thread_unlock_mutex(&globalLock);
1307 }
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001308 return result;
1309}
1310
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001311VK_LAYER_EXPORT VkResult VKAPI vkCreateEvent(VkDevice device, const VkEventCreateInfo* pCreateInfo, VkEvent* pEvent)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001312{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001313 VkResult result = nextTable.CreateEvent(device, pCreateInfo, pEvent);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001314 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001315 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001316 addObjectInfo(*pEvent, pCreateInfo->sType, pCreateInfo, sizeof(VkEventCreateInfo), "event");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001317 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001318 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001319 return result;
1320}
1321
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001322VK_LAYER_EXPORT VkResult VKAPI vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, VkQueryPool* pQueryPool)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001323{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001324 VkResult result = nextTable.CreateQueryPool(device, pCreateInfo, pQueryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001325 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001326 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001327 addObjectInfo(*pQueryPool, pCreateInfo->sType, pCreateInfo, sizeof(VkQueryPoolCreateInfo), "query_pool");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001328 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001329 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001330 return result;
1331}
1332
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001333VK_LAYER_EXPORT VkResult VKAPI vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, VkBuffer* pBuffer)
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001334{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001335 VkResult result = nextTable.CreateBuffer(device, pCreateInfo, pBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001336 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001337 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001338 addObjectInfo(*pBuffer, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferCreateInfo), "buffer");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001339 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001340 }
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001341 return result;
1342}
1343
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001344VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001345{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001346 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001347 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001348 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001349 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferViewCreateInfo), "buffer_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001350 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001351 }
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001352 return result;
1353}
1354
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001355VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, VkImage* pImage)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001356{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001357 VkResult result = nextTable.CreateImage(device, pCreateInfo, pImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001358 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001359 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001360 addObjectInfo(*pImage, pCreateInfo->sType, pCreateInfo, sizeof(VkImageCreateInfo), "image");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001361 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001362 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001363 return result;
1364}
1365
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001366VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001367{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001368 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001369 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001370 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001371 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkImageViewCreateInfo), "image_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001372 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001373 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001374 return result;
1375}
1376
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001377VK_LAYER_EXPORT VkResult VKAPI vkCreateColorAttachmentView(VkDevice device, const VkColorAttachmentViewCreateInfo* pCreateInfo,
1378 VkColorAttachmentView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001379{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001380 VkResult result = nextTable.CreateColorAttachmentView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001381 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001382 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001383 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkColorAttachmentViewCreateInfo), "color_attachment_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001384 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001385 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001386 return result;
1387}
1388
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001389VK_LAYER_EXPORT VkResult VKAPI vkCreateDepthStencilView(VkDevice device, const VkDepthStencilViewCreateInfo* pCreateInfo, VkDepthStencilView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001390{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001391 VkResult result = nextTable.CreateDepthStencilView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001392 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001393 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001394 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkDepthStencilViewCreateInfo), "ds_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001395 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001396 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001397 return result;
1398}
1399
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001400VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(VkDevice device, const VkShaderCreateInfo* pCreateInfo, VkShader* pShader)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001401{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001402 VkResult result = nextTable.CreateShader(device, pCreateInfo, pShader);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001403 return result;
1404}
1405
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001406VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001407{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001408 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001409 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001410 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001411 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001412 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001413 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001414 return result;
1415}
1416
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001417VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1418 VkDevice device,
1419 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1420 VkPipeline basePipeline,
1421 VkPipeline* pPipeline)
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001422{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001423 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001424 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001425 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001426 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001427 loader_platform_thread_unlock_mutex(&globalLock);
1428 }
1429 return result;
1430}
1431
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001432VK_LAYER_EXPORT VkResult VKAPI vkCreateComputePipeline(VkDevice device, const VkComputePipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001433{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001434 VkResult result = nextTable.CreateComputePipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001435 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001436 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001437 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkComputePipelineCreateInfo), "compute_pipeline");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001438 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001439 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001440 return result;
1441}
1442
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001443VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001444{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001445 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001446 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001447 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001448 addObjectInfo(*pSampler, pCreateInfo->sType, pCreateInfo, sizeof(VkSamplerCreateInfo), "sampler");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001449 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001450 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001451 return result;
1452}
1453
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001454VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001455 VkDynamicVpState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001456{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001457 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001458 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001459 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001460 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo), "viewport_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001461 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001462 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001463 return result;
1464}
1465
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001466VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001467 VkDynamicRsState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001468{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001469 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001470 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001471 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001472 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo), "raster_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001473 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001474 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001475 return result;
1476}
1477
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001478VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001479 VkDynamicCbState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001480{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001481 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001482 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001483 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001484 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo), "cb_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001485 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001486 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001487 return result;
1488}
1489
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001490VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001491 VkDynamicDsState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001492{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001493 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001494 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001495 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001496 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo), "ds_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001497 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001498 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001499 return result;
1500}
1501
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001502VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001503{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001504 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001505 // At time of cmd buffer creation, create global cmd buffer info for the returned cmd buffer
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001506 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001507 if (*pCmdBuffer)
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001508 addCBInfo(*pCmdBuffer);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001509 printCBList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001510 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001511 return result;
1512}
1513
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001514VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001515{
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001516 // This implicitly resets the Cmd Buffer so make sure any fence is done and then clear memory references
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001517 MT_CB_INFO* pCBInfo = getCBInfo(cmdBuffer);
1518 if (pCBInfo && (!fenceRetired(pCBInfo->fenceId))) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001519 bool32_t cbDone = checkCBCompleted(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001520 if (VK_FALSE == cbDone) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001521 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001522 sprintf(str, "Calling vkBeginCommandBuffer() on active CB %p before it has completed. You must check CB flag before this call.", cmdBuffer);
1523 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, "MEM", str);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001524 }
1525 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001526 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001527 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001528 freeCBBindings(cmdBuffer);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001529 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001530 return result;
1531}
1532
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001533VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001534{
1535 // TODO : Anything to do here?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001536 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001537 return result;
1538}
1539
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001540VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001541{
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001542 // Verify that CB is complete (not in-flight)
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001543 MT_CB_INFO* pCBInfo = getCBInfo(cmdBuffer);
1544 if (pCBInfo && (!fenceRetired(pCBInfo->fenceId))) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001545 bool32_t cbDone = checkCBCompleted(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001546 if (VK_FALSE == cbDone) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001547 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001548 sprintf(str, "Resetting CB %p before it has completed. You must check CB flag before calling vkResetCommandBuffer().", cmdBuffer);
1549 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, "MEM", str);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001550 }
1551 }
1552 // Clear memory references as this point.
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001553 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001554 freeCBBindings(cmdBuffer);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001555 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001556 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001557 return result;
1558}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001559// TODO : For any vkCmdBind* calls that include an object which has mem bound to it,
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001560// need to account for that mem now having binding to given cmdBuffer
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001561VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001562{
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001563#if 0
1564 // TODO : If memory bound to pipeline, then need to tie that mem to cmdBuffer
1565 if (getPipeline(pipeline)) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001566 MT_CB_INFO *pCBInfo = getCBInfo(cmdBuffer);
1567 if (pCBInfo) {
1568 pCBInfo->pipelines[pipelineBindPoint] = pipeline;
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001569 } else {
1570 char str[1024];
1571 sprintf(str, "Attempt to bind Pipeline %p to non-existant command buffer %p!", (void*)pipeline, cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001572 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_INVALID_CB, (char *) "DS", (char *) str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001573 }
1574 }
1575 else {
1576 char str[1024];
1577 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001578 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pipeline, 0, MEMTRACK_INVALID_OBJECT, (char *) "DS", (char *) str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001579 }
1580#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001581 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1582}
1583
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001584VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001585{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001586 MT_OBJ_INFO *pObjInfo;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001587 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001588 MT_CB_INFO *pCmdBuf = getCBInfo(cmdBuffer);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001589 if (!pCmdBuf) {
1590 char str[1024];
1591 sprintf(str, "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001592 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_INVALID_CB, "DD", str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001593 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001594 pObjInfo = getObjectInfo(state);
1595 if (!pObjInfo) {
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001596 char str[1024];
1597 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001598 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, state, 0, MEMTRACK_INVALID_OBJECT, "DD", str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001599 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001600 pCmdBuf->pDynamicState[stateBindPoint] = pObjInfo;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001601 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001602 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001603}
1604
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001605VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001606 VkCmdBuffer cmdBuffer,
1607 VkPipelineBindPoint pipelineBindPoint,
1608 VkDescriptorSetLayoutChain layoutChain,
Mark Lobodzinski411f0612015-04-07 09:34:09 -05001609 uint32_t layoutChainSlot,
1610 uint32_t count,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001611 const VkDescriptorSet* pDescriptorSets,
Mark Lobodzinski411f0612015-04-07 09:34:09 -05001612 const uint32_t* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001613{
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001614 // TODO : Somewhere need to verify that all textures referenced by shaders in DS are in some type of *SHADER_READ* state
Courtney Goeltzenleuchter24591b62015-04-02 22:54:15 -06001615 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, layoutChain, layoutChainSlot, count, pDescriptorSets, pUserData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001616}
1617
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001618VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t binding)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001619{
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001620 nextTable.CmdBindVertexBuffer(cmdBuffer, buffer, offset, binding);
Chia-I Wufb5062e2015-01-05 13:42:56 +08001621}
1622
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001623VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, VkIndexType indexType)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001624{
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001625 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001626}
1627
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001628VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001629{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001630 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001631 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001632 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001633 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001634 sprintf(str, "In vkCmdDrawIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1635 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001636 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001637 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001638 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001639}
1640
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001641VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001642{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001643 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001644 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001645 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001646 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001647 sprintf(str, "In vkCmdDrawIndexedIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1648 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001649 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001650 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001651 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001652}
1653
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001654VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001655{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001656 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001657 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001658 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001659 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001660 sprintf(str, "In vkCmdDispatchIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1661 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001662 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001663 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001664 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001665}
1666
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001667VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer,
1668 uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001669{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001670 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001671 VkGpuMemory mem = getMemBindingFromObject(srcBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001672 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001673 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001674 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
1675 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001676 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001677 mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001678 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001679 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001680 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1681 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001682 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001683 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001684 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001685}
1686
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001687VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
1688 VkImage srcImage, VkImageLayout srcImageLayout,
1689 VkImage destImage, VkImageLayout destImageLayout,
1690 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001691{
1692 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001693 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001694}
1695
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001696VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
1697 VkImage srcImage, VkImageLayout srcImageLayout,
1698 VkImage destImage, VkImageLayout destImageLayout,
1699 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchterb787a1e2015-03-08 17:02:18 -06001700{
1701 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001702 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Courtney Goeltzenleuchterb787a1e2015-03-08 17:02:18 -06001703}
1704
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001705VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
1706 VkBuffer srcBuffer,
1707 VkImage destImage, VkImageLayout destImageLayout,
1708 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001709{
1710 // TODO : Track this
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001711 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001712 VkGpuMemory mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001713 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001714 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001715 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1716 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001717 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001718
1719 mem = getMemBindingFromObject(srcBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001720 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001721 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001722 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
1723 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001724 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001725 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001726 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001727}
1728
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001729VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
1730 VkImage srcImage, VkImageLayout srcImageLayout,
1731 VkBuffer destBuffer,
1732 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001733{
1734 // TODO : Track this
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001735 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001736 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001737 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001738 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001739 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1740 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001741 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001742 mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001743 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001744 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001745 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1746 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001747 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001748 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001749 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001750}
1751
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001752VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout,
1753 VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001754{
1755 // TODO : Each image will have mem mapping so track them
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001756 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001757 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001758 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001759 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001760 sprintf(str, "In vkCmdCloneImageData() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1761 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001762 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001763 mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001764 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001765 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001766 sprintf(str, "In vkCmdCloneImageData() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1767 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001768 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001769 loader_platform_thread_unlock_mutex(&globalLock);
Mike Stroyan55658c22014-12-04 11:08:39 +00001770 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001771}
1772
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001773VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkGpuSize destOffset, VkGpuSize dataSize, const uint32_t* pData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001774{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001775 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001776 VkGpuMemory mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001777 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001778 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001779 sprintf(str, "In vkCmdUpdateMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1780 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001781 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001782 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001783 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001784}
1785
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001786VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkGpuSize destOffset, VkGpuSize fillSize, uint32_t data)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001787{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001788 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001789 VkGpuMemory mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001790 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001791 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001792 sprintf(str, "In vkCmdFillMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1793 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001794 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001795 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001796 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001797}
1798
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001799VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(VkCmdBuffer cmdBuffer,
1800 VkImage image, VkImageLayout imageLayout,
1801 VkClearColor color,
1802 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001803{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001804 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001805 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001806 VkGpuMemory mem = getMemBindingFromObject(image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001807 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001808 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001809 sprintf(str, "In vkCmdClearColorImage() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
1810 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001811 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001812 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001813 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001814}
1815
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001816VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
1817 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001818 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001819 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001820{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001821 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001822 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001823 VkGpuMemory mem = getMemBindingFromObject(image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001824 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001825 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001826 sprintf(str, "In vkCmdClearDepthStencil() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
1827 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001828 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001829 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001830 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001831}
1832
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001833VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
1834 VkImage srcImage, VkImageLayout srcImageLayout,
1835 VkImage destImage, VkImageLayout destImageLayout,
Tony Barbour11f74372015-04-13 15:02:52 -06001836 uint32_t regionCount, const VkImageResolve* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001837{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001838 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001839 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001840 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001841 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001842 sprintf(str, "In vkCmdResolveImage() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1843 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001844 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001845 mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001846 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001847 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001848 sprintf(str, "In vkCmdResolveImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1849 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001850 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001851 loader_platform_thread_unlock_mutex(&globalLock);
Tony Barbour11f74372015-04-13 15:02:52 -06001852 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001853}
1854
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001855VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001856{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001857 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001858 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001859 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001860 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001861 sprintf(str, "In vkCmdBeginQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1862 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001863 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001864 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001865 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
1866}
1867
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001868VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001869{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001870 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001871 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001872 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001873 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001874 sprintf(str, "In vkCmdEndQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1875 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001876 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001877 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001878 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
1879}
1880
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001881VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001882{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001883 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001884 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001885 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001886 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001887 sprintf(str, "In vkCmdResetQueryPool() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1888 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001889 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001890 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001891 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
1892}
1893
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001894VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001895{
Tobin Ehlis62086412014-11-19 16:19:28 -07001896 // This layer intercepts callbacks
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001897 VK_LAYER_DBG_FUNCTION_NODE *pNewDbgFuncNode = (VK_LAYER_DBG_FUNCTION_NODE*)malloc(sizeof(VK_LAYER_DBG_FUNCTION_NODE));
Tobin Ehlis62086412014-11-19 16:19:28 -07001898 if (!pNewDbgFuncNode)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001899 return VK_ERROR_OUT_OF_MEMORY;
Tobin Ehlis62086412014-11-19 16:19:28 -07001900 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
1901 pNewDbgFuncNode->pUserData = pUserData;
Jon Ashburnf57ea372014-12-22 13:24:15 -07001902 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
1903 g_pDbgFunctionHead = pNewDbgFuncNode;
Jon Ashburne4722392015-03-03 15:07:15 -07001904 // force callbacks if DebugAction hasn't been set already other than initial value
Courtney Goeltzenleuchter9e3aafa2015-03-04 15:47:34 -07001905 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001906 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Courtney Goeltzenleuchter9e3aafa2015-03-04 15:47:34 -07001907 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001908 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001909 return result;
1910}
1911
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001912VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001913{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001914 VK_LAYER_DBG_FUNCTION_NODE *pInfo = g_pDbgFunctionHead;
1915 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pInfo;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001916 while (pInfo) {
1917 if (pInfo->pfnMsgCallback == pfnMsgCallback) {
1918 pPrev->pNext = pInfo->pNext;
1919 if (g_pDbgFunctionHead == pInfo)
1920 g_pDbgFunctionHead = pInfo->pNext;
1921 free(pInfo);
Tobin Ehlis62086412014-11-19 16:19:28 -07001922 break;
1923 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001924 pPrev = pInfo;
1925 pInfo = pInfo->pNext;
Tobin Ehlis62086412014-11-19 16:19:28 -07001926 }
Jon Ashburne4722392015-03-03 15:07:15 -07001927 if (g_pDbgFunctionHead == NULL)
1928 {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001929 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001930 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001931 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001932 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001933 }
Jon Ashburne4722392015-03-03 15:07:15 -07001934 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001935 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001936 return result;
1937}
1938
Jon Ashburndc899962015-03-02 16:51:38 -07001939#if !defined(WIN32)
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001940VK_LAYER_EXPORT VkResult VKAPI vkWsiX11CreatePresentableImage(VkDevice device, const VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO* pCreateInfo,
1941 VkImage* pImage, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001942{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001943 VkResult result = nextTable.WsiX11CreatePresentableImage(device, pCreateInfo, pImage, pMem);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001944 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001945 if (VK_SUCCESS == result) {
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001946 // Add image object, then insert the new Mem Object and then bind it to created image
Courtney Goeltzenleuchter070f6da2015-04-10 17:59:44 -06001947 addObjectInfo(*pImage, VkStructureType_MAX_ENUM, pCreateInfo, sizeof(VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO), "wsi_x11_image");
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001948 addMemObjInfo(*pMem, NULL);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001949 if (VK_FALSE == updateObjectBinding(*pImage, *pMem)) {
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001950 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001951 sprintf(str, "In vkWsiX11CreatePresentableImage(), unable to set image %p binding to mem obj %p", (void*)*pImage, (void*)*pMem);
1952 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pImage, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001953 }
Tobin Ehlis62086412014-11-19 16:19:28 -07001954 }
1955 printObjList();
1956 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001957 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001958 return result;
1959}
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001960
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001961VK_LAYER_EXPORT VkResult VKAPI vkWsiX11QueuePresent(VkQueue queue, const VK_WSI_X11_PRESENT_INFO* pPresentInfo, VkFence fence)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001962{
1963 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001964 addFenceInfo(fence, queue);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001965 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001966 sprintf(str, "In vkWsiX11QueuePresent(), checking queue %p for fence %p", queue, fence);
1967 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001968 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001969 VkResult result = nextTable.WsiX11QueuePresent(queue, pPresentInfo, fence);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001970 return result;
1971}
Ian Elliott81ac44c2015-01-13 17:52:38 -07001972#endif // WIN32
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001973
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001974VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalGpu gpu, const char* funcName)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001975{
Jon Ashburn301c5f02015-04-06 10:58:22 -06001976 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Chia-I Wu706533e2015-01-05 13:18:57 +08001977
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001978 if (gpu == NULL)
1979 return NULL;
1980 pCurObj = gpuw;
Ian Elliott81ac44c2015-01-13 17:52:38 -07001981 loader_platform_thread_once(&g_initOnce, initMemTracker);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001982
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001983 if (!strcmp(funcName, "vkGetProcAddr"))
1984 return (void *) vkGetProcAddr;
1985 if (!strcmp(funcName, "vkCreateDevice"))
1986 return (void*) vkCreateDevice;
1987 if (!strcmp(funcName, "vkDestroyDevice"))
1988 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001989 if (!strcmp(funcName, "vkEnumerateLayers"))
1990 return (void*) vkEnumerateLayers;
1991 if (!strcmp(funcName, "vkQueueSubmit"))
1992 return (void*) vkQueueSubmit;
1993 if (!strcmp(funcName, "vkAllocMemory"))
1994 return (void*) vkAllocMemory;
1995 if (!strcmp(funcName, "vkFreeMemory"))
1996 return (void*) vkFreeMemory;
1997 if (!strcmp(funcName, "vkSetMemoryPriority"))
1998 return (void*) vkSetMemoryPriority;
1999 if (!strcmp(funcName, "vkMapMemory"))
2000 return (void*) vkMapMemory;
2001 if (!strcmp(funcName, "vkUnmapMemory"))
2002 return (void*) vkUnmapMemory;
2003 if (!strcmp(funcName, "vkPinSystemMemory"))
2004 return (void*) vkPinSystemMemory;
2005 if (!strcmp(funcName, "vkOpenSharedMemory"))
2006 return (void*) vkOpenSharedMemory;
2007 if (!strcmp(funcName, "vkOpenPeerMemory"))
2008 return (void*) vkOpenPeerMemory;
2009 if (!strcmp(funcName, "vkOpenPeerImage"))
2010 return (void*) vkOpenPeerImage;
2011 if (!strcmp(funcName, "vkDestroyObject"))
2012 return (void*) vkDestroyObject;
2013 if (!strcmp(funcName, "vkGetObjectInfo"))
2014 return (void*) vkGetObjectInfo;
Mark Lobodzinskicf26e072015-04-16 11:44:05 -05002015 if (!strcmp(funcName, "vkQueueBindObjectMemory"))
2016 return (void*) vkQueueBindObjectMemory;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002017 if (!strcmp(funcName, "vkCreateFence"))
2018 return (void*) vkCreateFence;
2019 if (!strcmp(funcName, "vkGetFenceStatus"))
2020 return (void*) vkGetFenceStatus;
2021 if (!strcmp(funcName, "vkResetFences"))
2022 return (void*) vkResetFences;
2023 if (!strcmp(funcName, "vkWaitForFences"))
2024 return (void*) vkWaitForFences;
2025 if (!strcmp(funcName, "vkQueueWaitIdle"))
2026 return (void*) vkQueueWaitIdle;
2027 if (!strcmp(funcName, "vkDeviceWaitIdle"))
2028 return (void*) vkDeviceWaitIdle;
2029 if (!strcmp(funcName, "vkCreateEvent"))
2030 return (void*) vkCreateEvent;
2031 if (!strcmp(funcName, "vkCreateQueryPool"))
2032 return (void*) vkCreateQueryPool;
2033 if (!strcmp(funcName, "vkCreateBuffer"))
2034 return (void*) vkCreateBuffer;
2035 if (!strcmp(funcName, "vkCreateBufferView"))
2036 return (void*) vkCreateBufferView;
2037 if (!strcmp(funcName, "vkCreateImage"))
2038 return (void*) vkCreateImage;
2039 if (!strcmp(funcName, "vkCreateImageView"))
2040 return (void*) vkCreateImageView;
2041 if (!strcmp(funcName, "vkCreateColorAttachmentView"))
2042 return (void*) vkCreateColorAttachmentView;
2043 if (!strcmp(funcName, "vkCreateDepthStencilView"))
2044 return (void*) vkCreateDepthStencilView;
2045 if (!strcmp(funcName, "vkCreateShader"))
2046 return (void*) vkCreateShader;
2047 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2048 return (void*) vkCreateGraphicsPipeline;
2049 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2050 return (void*) vkCreateGraphicsPipelineDerivative;
2051 if (!strcmp(funcName, "vkCreateComputePipeline"))
2052 return (void*) vkCreateComputePipeline;
2053 if (!strcmp(funcName, "vkCreateSampler"))
2054 return (void*) vkCreateSampler;
2055 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2056 return (void*) vkCreateDynamicViewportState;
2057 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2058 return (void*) vkCreateDynamicRasterState;
2059 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2060 return (void*) vkCreateDynamicColorBlendState;
2061 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2062 return (void*) vkCreateDynamicDepthStencilState;
2063 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2064 return (void*) vkCreateCommandBuffer;
2065 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2066 return (void*) vkBeginCommandBuffer;
2067 if (!strcmp(funcName, "vkEndCommandBuffer"))
2068 return (void*) vkEndCommandBuffer;
2069 if (!strcmp(funcName, "vkResetCommandBuffer"))
2070 return (void*) vkResetCommandBuffer;
2071 if (!strcmp(funcName, "vkCmdBindPipeline"))
2072 return (void*) vkCmdBindPipeline;
2073 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2074 return (void*) vkCmdBindDynamicStateObject;
2075 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2076 return (void*) vkCmdBindDescriptorSets;
2077 if (!strcmp(funcName, "vkCmdBindVertexBuffer"))
2078 return (void*) vkCmdBindVertexBuffer;
2079 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2080 return (void*) vkCmdBindIndexBuffer;
2081 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2082 return (void*) vkCmdDrawIndirect;
2083 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2084 return (void*) vkCmdDrawIndexedIndirect;
2085 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2086 return (void*) vkCmdDispatchIndirect;
2087 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2088 return (void*) vkCmdCopyBuffer;
2089 if (!strcmp(funcName, "vkCmdCopyImage"))
2090 return (void*) vkCmdCopyImage;
2091 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2092 return (void*) vkCmdCopyBufferToImage;
2093 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2094 return (void*) vkCmdCopyImageToBuffer;
2095 if (!strcmp(funcName, "vkCmdCloneImageData"))
2096 return (void*) vkCmdCloneImageData;
2097 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2098 return (void*) vkCmdUpdateBuffer;
2099 if (!strcmp(funcName, "vkCmdFillBuffer"))
2100 return (void*) vkCmdFillBuffer;
2101 if (!strcmp(funcName, "vkCmdClearColorImage"))
2102 return (void*) vkCmdClearColorImage;
2103 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2104 return (void*) vkCmdClearDepthStencil;
2105 if (!strcmp(funcName, "vkCmdResolveImage"))
2106 return (void*) vkCmdResolveImage;
2107 if (!strcmp(funcName, "vkCmdBeginQuery"))
2108 return (void*) vkCmdBeginQuery;
2109 if (!strcmp(funcName, "vkCmdEndQuery"))
2110 return (void*) vkCmdEndQuery;
2111 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2112 return (void*) vkCmdResetQueryPool;
2113 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2114 return (void*) vkDbgRegisterMsgCallback;
2115 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2116 return (void*) vkDbgUnregisterMsgCallback;
2117 if (!strcmp(funcName, "vkGetDeviceQueue"))
2118 return (void*) vkGetDeviceQueue;
2119 if (!strcmp(funcName, "vkQueueAddMemReference"))
2120 return (void*) vkQueueAddMemReference;
2121 if (!strcmp(funcName, "vkQueueRemoveMemReference"))
2122 return (void*) vkQueueRemoveMemReference;
Jon Ashburndc899962015-03-02 16:51:38 -07002123#if !defined(WIN32)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002124 if (!strcmp(funcName, "vkWsiX11CreatePresentableImage"))
2125 return (void*) vkWsiX11CreatePresentableImage;
2126 if (!strcmp(funcName, "vkWsiX11QueuePresent"))
2127 return (void*) vkWsiX11QueuePresent;
Jon Ashburndc899962015-03-02 16:51:38 -07002128#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002129 else {
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002130 if (gpuw->pGPA == NULL)
2131 return NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002132 return gpuw->pGPA((VkPhysicalGpu)gpuw->nextObject, funcName);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002133 }
2134}