blob: 1ea4f69c4388604d0aca13685b2c8f573309d684 [file] [log] [blame]
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001/*
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05002 * Vulkan
Tobin Ehlis791a49c2014-11-10 12:29:12 -07003 *
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05004 * Copyright (C) 2015 LunarG, Inc.
Tobin Ehlis791a49c2014-11-10 12:29:12 -07005 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050017* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Tobin Ehlis791a49c2014-11-10 12:29:12 -070018 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
Mark Lobodzinski4aad3642015-03-17 10:53:12 -050025#include <inttypes.h>
Tobin Ehlis791a49c2014-11-10 12:29:12 -070026#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <assert.h>
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050030#include <list>
31#include <map>
32using namespace std;
33
Ian Elliott81ac44c2015-01-13 17:52:38 -070034#include "loader_platform.h"
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060035#include "vk_dispatch_table_helper.h"
36#include "vk_struct_string_helper_cpp.h"
Tobin Ehlis62086412014-11-19 16:19:28 -070037#include "mem_tracker.h"
Jon Ashburnf57ea372014-12-22 13:24:15 -070038#include "layers_config.h"
Ian Elliott20f06872015-02-12 17:08:34 -070039// The following is #included again to catch certain OS-specific functions
40// being used:
41#include "loader_platform.h"
Jon Ashburn5a7be202015-02-16 08:46:53 -070042#include "layers_msg.h"
Tobin Ehlis791a49c2014-11-10 12:29:12 -070043
Jon Ashburn301c5f02015-04-06 10:58:22 -060044static VkLayerDispatchTable nextTable;
45static VkBaseLayerObject *pCurObj;
Ian Elliott81ac44c2015-01-13 17:52:38 -070046static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -060047// TODO : This can be much smarter, using separate locks for separate global data
48static int globalLockInitialized = 0;
49static loader_platform_thread_mutex globalLock;
Jon Ashburnf57ea372014-12-22 13:24:15 -070050
Tobin Ehlis2836a7d2015-01-08 15:22:32 -070051#define MAX_BINDING 0xFFFFFFFF
Tobin Ehlis2836a7d2015-01-08 15:22:32 -070052
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060053map<VkCmdBuffer, MT_CB_INFO*> cbMap;
54map<VkGpuMemory, MT_MEM_OBJ_INFO*> memObjMap;
55map<VkObject, MT_OBJ_INFO*> objectMap;
Mark Lobodzinski85a83982015-04-02 08:52:53 -050056map<uint64_t, MT_FENCE_INFO*> fenceMap; // Map fenceId to fence info
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060057map<VkQueue, MT_QUEUE_INFO*> queueMap;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050058
Mark Lobodzinski8ee96342015-04-02 20:49:09 -050059// TODO : Add per-device fence completion
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050060static uint64_t g_currentFenceId = 1;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060061static VkDevice globalDevice = NULL;
Mark Lobodzinski15427102015-02-18 16:38:17 -060062
Mark Lobodzinski85a83982015-04-02 08:52:53 -050063// Add new queue for this device to map container
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060064static void addQueueInfo(const VkQueue queue)
Mark Lobodzinski85a83982015-04-02 08:52:53 -050065{
Mark Lobodzinski8ee96342015-04-02 20:49:09 -050066 MT_QUEUE_INFO* pInfo = new MT_QUEUE_INFO;
67 pInfo->lastRetiredId = 0;
68 pInfo->lastSubmittedId = 0;
69 queueMap[queue] = pInfo;
Mark Lobodzinski85a83982015-04-02 08:52:53 -050070}
71
72static void deleteQueueInfoList(void)
73{
74 // Process queue list, cleaning up each entry before deleting
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060075 for (map<VkQueue, MT_QUEUE_INFO*>::iterator ii=queueMap.begin(); ii!=queueMap.end(); ++ii) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -050076 (*ii).second->pQueueCmdBuffers.clear();
77 }
78 queueMap.clear();
79}
80
81// Add new CBInfo for this cb to map container
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060082static void addCBInfo(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -070083{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050084 MT_CB_INFO* pInfo = new MT_CB_INFO;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060085 memset(pInfo, 0, (sizeof(MT_CB_INFO) - sizeof(list<VkGpuMemory>)));
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050086 pInfo->cmdBuffer = cb;
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -060087 cbMap[cb] = pInfo;
Tobin Ehlis791a49c2014-11-10 12:29:12 -070088}
89
Mark Lobodzinski85a83982015-04-02 08:52:53 -050090// Return ptr to Info in CB map, or NULL if not found
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060091static MT_CB_INFO* getCBInfo(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -070092{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050093 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050094 if (cbMap.find(cb) != cbMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050095 pCBInfo = cbMap[cb];
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -060096 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050097 return pCBInfo;
Tobin Ehlis791a49c2014-11-10 12:29:12 -070098}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -060099
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500100// Return object info for 'object' or return NULL if no info exists
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600101static MT_OBJ_INFO* getObjectInfo(const VkObject object)
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500102{
103 MT_OBJ_INFO* pObjInfo = NULL;
104
105 if (objectMap.find(object) != objectMap.end()) {
106 pObjInfo = objectMap[object];
107 }
108 return pObjInfo;
109}
110
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600111static MT_OBJ_INFO* addObjectInfo(VkObject object, VkStructureType sType, const void *pCreateInfo, const int struct_size, const char *name_prefix)
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500112{
113 MT_OBJ_INFO* pInfo = new MT_OBJ_INFO;
114 memset(pInfo, 0, sizeof(MT_OBJ_INFO));
115 memcpy(&pInfo->create_info, pCreateInfo, struct_size);
116 sprintf(pInfo->object_name, "%s_%p", name_prefix, object);
117
118 pInfo->object = object;
119 pInfo->ref_count = 1;
120 pInfo->sType = sType;
121 objectMap[object] = pInfo;
122
123 return pInfo;
124}
125
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500126// Add a fence, creating one if necessary to our list of fences/fenceIds
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600127static uint64_t addFenceInfo(VkFence fence, VkQueue queue)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500128{
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500129 // Create fence object
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500130 MT_FENCE_INFO* pFenceInfo = new MT_FENCE_INFO;
Mark Lobodzinski8ee96342015-04-02 20:49:09 -0500131 MT_QUEUE_INFO* pQueueInfo = queueMap[queue];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500132 uint64_t fenceId = g_currentFenceId++;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500133 memset(pFenceInfo, 0, sizeof(MT_FENCE_INFO));
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500134 // If no fence, create an internal fence to track the submissions
135 if (fence == NULL) {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600136 VkFenceCreateInfo fci;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600137 fci.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500138 fci.pNext = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600139 fci.flags = static_cast<VkFenceCreateFlags>(0);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500140 nextTable.CreateFence(globalDevice, &fci, &pFenceInfo->fence);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600141 addObjectInfo(pFenceInfo->fence, fci.sType, &fci, sizeof(VkFenceCreateInfo), "internalFence");
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600142 pFenceInfo->localFence = VK_TRUE;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500143 } else {
Mark Lobodzinski56945182015-04-09 13:46:09 -0500144 // Validate that fence is in UNSIGNALED state
145 MT_OBJ_INFO* pObjectInfo = getObjectInfo(fence);
146 if (pObjectInfo != NULL) {
Tobin Ehlisf29da382015-04-15 07:46:12 -0600147 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinski56945182015-04-09 13:46:09 -0500148 char str[1024];
149 sprintf(str, "Fence %p submitted in SIGNALED state. Fences must be reset before being submitted", fence);
Tobin Ehlisf29da382015-04-15 07:46:12 -0600150 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, fence, 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Mark Lobodzinski56945182015-04-09 13:46:09 -0500151 }
152 }
Tobin Ehlisf29da382015-04-15 07:46:12 -0600153 pFenceInfo->localFence = VK_FALSE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500154 pFenceInfo->fence = fence;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700155 }
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500156 pFenceInfo->queue = queue;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500157 fenceMap[fenceId] = pFenceInfo;
Mark Lobodzinski8ee96342015-04-02 20:49:09 -0500158 // Update most recently submitted fenceId for Queue
159 pQueueInfo->lastSubmittedId = fenceId;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500160 return fenceId;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500161}
162
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500163// Remove a fenceInfo from our list of fences/fenceIds
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500164static void deleteFenceInfo(uint64_t fenceId)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500165{
166 if (fenceId != 0) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500167 if (fenceMap.find(fenceId) != fenceMap.end()) {
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600168 map<uint64_t, MT_FENCE_INFO*>::iterator item;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500169 MT_FENCE_INFO* pDelInfo = fenceMap[fenceId];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500170 if (pDelInfo != NULL) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600171 if (pDelInfo->localFence == VK_TRUE) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500172 nextTable.DestroyObject(pDelInfo->fence);
173 }
174 delete pDelInfo;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500175 }
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600176 item = fenceMap.find(fenceId);
177 fenceMap.erase(item);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500178 }
179 }
180}
181
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500182// Search through list for this fence, deleting all items before it (with lower IDs) and updating lastRetiredId
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600183static void updateFenceTracking(VkFence fence)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500184{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500185 MT_FENCE_INFO *pCurFenceInfo = NULL;
186 uint64_t fenceId = 0;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600187 VkQueue queue = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500188
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500189 for (map<uint64_t, MT_FENCE_INFO*>::iterator ii=fenceMap.begin(); ii!=fenceMap.end(); ++ii) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500190 if ((*ii).second != NULL) {
191 if (fence == ((*ii).second)->fence) {
192 queue = ((*ii).second)->queue;
193 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
194 pQueueInfo->lastRetiredId = (*ii).first;
195 } else {
196 deleteFenceInfo((*ii).first);
197 }
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500198 // Update fence state in fenceCreateInfo structure
199 MT_OBJ_INFO* pObjectInfo = getObjectInfo(fence);
200 if (pObjectInfo != NULL) {
Mark Lobodzinski56945182015-04-09 13:46:09 -0500201 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisf29da382015-04-15 07:46:12 -0600202 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags | VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500203 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500204 }
205 }
206}
207
208// Utility function that determines if a fenceId has been retired yet
209static bool32_t fenceRetired(uint64_t fenceId)
210{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600211 bool32_t result = VK_FALSE;
Mark Lobodzinski91a1ec52015-04-02 08:52:53 -0500212 MT_FENCE_INFO* pFenceInfo = fenceMap[fenceId];
213 if (pFenceInfo != 0)
214 {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500215 MT_QUEUE_INFO* pQueueInfo = queueMap[pFenceInfo->queue];
Mark Lobodzinski91a1ec52015-04-02 08:52:53 -0500216 if (fenceId <= pQueueInfo->lastRetiredId)
217 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600218 result = VK_TRUE;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500219 }
Mark Lobodzinski8ee96342015-04-02 20:49:09 -0500220 } else { // If not in list, fence has been retired and deleted
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600221 result = VK_TRUE;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500222 }
223 return result;
224}
225
226// Return the fence associated with a fenceId
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600227static VkFence getFenceFromId(uint64_t fenceId)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500228{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600229 VkFence fence = NULL;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500230 if (fenceId != 0) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500231 // Search for an item with this fenceId
232 if (fenceMap.find(fenceId) != fenceMap.end()) {
233 MT_FENCE_INFO* pFenceInfo = fenceMap[fenceId];
234 if (pFenceInfo != NULL) {
235 MT_QUEUE_INFO* pQueueInfo = queueMap[pFenceInfo->queue];
236 if (fenceId > pQueueInfo->lastRetiredId) {
237 fence = pFenceInfo->fence;
238 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500239 }
240 }
241 }
242 return fence;
243}
244
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500245// Helper routine that updates the fence list for a specific queue to all-retired
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600246static void retireQueueFences(VkQueue queue)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500247{
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600248 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
249 pQueueInfo->lastRetiredId = pQueueInfo->lastSubmittedId;
250 // Set Queue's lastRetired to lastSubmitted, free items in queue's fence list
251 map<uint64_t, MT_FENCE_INFO*>::iterator it = fenceMap.begin();
252 map<uint64_t, MT_FENCE_INFO*>::iterator temp;
253 while (it != fenceMap.end()) {
254 if (((*it).second)->queue == queue) {
255 temp = it;
256 ++temp;
257 deleteFenceInfo((*it).first);
258 it = temp;
259 } else {
260 ++it;
261 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500262 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700263}
264
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500265// Helper routine that updates fence list for all queues to all-retired
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600266static void retireDeviceFences(VkDevice device)
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500267{
268 // Process each queue for device
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600269 // TODO: Add multiple device support
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600270 for (map<VkQueue, MT_QUEUE_INFO*>::iterator ii=queueMap.begin(); ii!=queueMap.end(); ++ii) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500271 retireQueueFences((*ii).first);
272 }
273}
274
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500275// Returns True if a memory reference is present in a Queue's memory reference list
276// Queue is validated by caller
277static bool32_t checkMemRef(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600278 VkQueue queue,
279 VkGpuMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500280{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600281 bool32_t result = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600282 list<VkGpuMemory>::iterator it;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500283 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
284 for (it = pQueueInfo->pMemRefList.begin(); it != pQueueInfo->pMemRefList.end(); ++it) {
285 if ((*it) == mem) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600286 result = VK_TRUE;
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500287 break;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500288 }
289 }
290 return result;
291}
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500292
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500293static bool32_t validateQueueMemRefs(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600294 VkQueue queue,
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500295 uint32_t cmdBufferCount,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600296 const VkCmdBuffer *pCmdBuffers)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500297{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600298 bool32_t result = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500299
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500300 // Verify Queue
301 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
302 if (pQueueInfo == NULL) {
303 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600304 sprintf(str, "Unknown Queue %p specified in vkQueueSubmit", queue);
305 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500306 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500307 else {
308 // Iterate through all CBs in pCmdBuffers
309 for (uint32_t i = 0; i < cmdBufferCount; i++) {
310 MT_CB_INFO* pCBInfo = getCBInfo(pCmdBuffers[i]);
311 if (!pCBInfo) {
312 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600313 sprintf(str, "Unable to find info for CB %p in order to check memory references in vkQueueSubmit for queue %p", (void*)pCmdBuffers[i], queue);
314 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_INVALID_CB, "MEM", str);
315 result = VK_FALSE;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500316 } else {
317 // Validate that all actual references are accounted for in pMemRefs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600318 for (list<VkGpuMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500319 // Search for each memref in queues memreflist.
320 if (checkMemRef(queue, *it)) {
321 char str[1024];
322 sprintf(str, "Found Mem Obj %p binding to CB %p for queue %p", (*it), pCmdBuffers[i], queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600323 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500324 }
325 else {
326 char str[1024];
327 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 -0600328 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pCmdBuffers[i], 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
329 result = VK_FALSE;
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500330 }
331 }
332 }
333 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600334 if (result == VK_TRUE) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500335 char str[1024];
336 sprintf(str, "Verified all memory dependencies for Queue %p are included in pMemRefs list", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600337 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500338 // TODO : Could report mem refs in pMemRefs that AREN'T in mem list, that would be primarily informational
339 // Currently just noting that there is a difference
340 }
341 }
342
343 return result;
344}
Courtney Goeltzenleuchter8d49dbd2015-04-07 17:13:38 -0600345
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500346// Return ptr to info in map container containing mem, or NULL if not found
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700347// Calls to this function should be wrapped in mutex
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600348static MT_MEM_OBJ_INFO* getMemObjInfo(const VkGpuMemory mem)
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700349{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500350 MT_MEM_OBJ_INFO* pMemObjInfo = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500351
352 if (memObjMap.find(mem) != memObjMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500353 pMemObjInfo = memObjMap[mem];
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600354 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500355 return pMemObjInfo;
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700356}
357
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600358static void addMemObjInfo(const VkGpuMemory mem, const VkMemoryAllocInfo* pAllocInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700359{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500360 MT_MEM_OBJ_INFO* pInfo = new MT_MEM_OBJ_INFO;
361 pInfo->refCount = 0;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600362 memset(&pInfo->allocInfo, 0, sizeof(VkMemoryAllocInfo));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500363
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600364 if (pAllocInfo) { // MEM alloc created by vkWsiX11CreatePresentableImage() doesn't have alloc info struct
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600365 memcpy(&pInfo->allocInfo, pAllocInfo, sizeof(VkMemoryAllocInfo));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500366 // TODO: Update for real hardware, actually process allocation info structures
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500367 pInfo->allocInfo.pNext = NULL;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700368 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500369 pInfo->mem = mem;
370 memObjMap[mem] = pInfo;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700371}
372
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500373// Find CB Info and add mem binding to list container
374// Find Mem Obj Info and add CB binding to list container
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600375static bool32_t updateCBBinding(const VkCmdBuffer cb, const VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700376{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600377 bool32_t result = VK_TRUE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700378 // First update CB binding in MemObj mini CB list
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500379 MT_MEM_OBJ_INFO* pMemInfo = getMemObjInfo(mem);
380 if (!pMemInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700381 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500382 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 -0600383 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
384 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600385 } else {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500386 // Search for cmd buffer object in memory object's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600387 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600388 for (list<VkCmdBuffer>::iterator it = pMemInfo->pCmdBufferBindings.begin(); it != pMemInfo->pCmdBufferBindings.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500389 if ((*it) == cb) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600390 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500391 break;
392 }
393 }
394 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600395 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500396 pMemInfo->pCmdBufferBindings.push_front(cb);
397 pMemInfo->refCount++;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500398 }
399
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500400 // Now update CBInfo's Mem binding list
401 MT_CB_INFO* pCBInfo = getCBInfo(cb);
402 if (!pCBInfo) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500403 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500404 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 -0600405 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
406 result = VK_FALSE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500407 } else {
408 // Search for memory object in cmd buffer's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600409 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600410 for (list<VkGpuMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500411 if ((*it) == mem) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600412 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500413 break;
414 }
415 }
416 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600417 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500418 pCBInfo->pMemObjList.push_front(mem);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600419 }
420 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700421 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600422 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700423}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600424
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700425// Clear the CB Binding for mem
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700426// Calls to this function should be wrapped in mutex
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600427static void clearCBBinding(const VkCmdBuffer cb, const VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700428{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500429 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500430 // TODO : Having this check is not ideal, really if memInfo was deleted,
Tobin Ehlis77b3abb2015-03-04 08:38:22 -0700431 // its CB bindings should be cleared and then freeCBBindings wouldn't call
432 // us here with stale mem objs
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500433 if (pInfo) {
434 pInfo->pCmdBufferBindings.remove(cb);
435 pInfo->refCount--;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700436 }
437}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600438
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700439// Free bindings related to CB
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600440static bool32_t freeCBBindings(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700441{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600442 bool32_t result = VK_TRUE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500443 MT_CB_INFO* pCBInfo = getCBInfo(cb);
444 if (!pCBInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700445 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500446 sprintf(str, "Unable to find global CB info %p for deletion", cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600447 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
448 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600449 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500450 if (!fenceRetired(pCBInfo->fenceId)) {
451 deleteFenceInfo(pCBInfo->fenceId);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600452 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500453
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600454 for (list<VkGpuMemory>::iterator it=pCBInfo->pMemObjList.begin(); it!=pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500455 clearCBBinding(cb, (*it));
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600456 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500457 pCBInfo->pMemObjList.clear();
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700458 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600459 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700460}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600461
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500462// Delete CBInfo from list along with all of it's mini MemObjInfo
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500463// and also clear mem references to CB
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700464// TODO : When should this be called? There's no Destroy of CBs that I see
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600465static bool32_t deleteCBInfo(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700466{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600467 bool32_t result = VK_TRUE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600468 result = freeCBBindings(cb);
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500469 // Delete the CBInfo info
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600470 if (result == VK_TRUE) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500471 if (cbMap.find(cb) != cbMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500472 MT_CB_INFO* pDelInfo = cbMap[cb];
473 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500474 cbMap.erase(cb);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600475 }
Ian Elliott81ac44c2015-01-13 17:52:38 -0700476 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600477 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700478}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600479
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700480// Delete the entire CB list
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500481static bool32_t deleteCBInfoList()
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700482{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600483 bool32_t result = VK_TRUE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600484 for (map<VkCmdBuffer, MT_CB_INFO*>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500485 freeCBBindings((*ii).first);
486 delete (*ii).second;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700487 }
488 return result;
489}
490
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500491// For given MemObjInfo, report Obj & CB bindings
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500492static void reportMemReferences(const MT_MEM_OBJ_INFO* pMemObjInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700493{
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600494 uint32_t refCount = 0; // Count found references
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500495
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600496 for (list<VkCmdBuffer>::const_iterator it = pMemObjInfo->pCmdBufferBindings.begin(); it != pMemObjInfo->pCmdBufferBindings.end(); ++it) {
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700497 refCount++;
Tobin Ehlis62086412014-11-19 16:19:28 -0700498 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500499 sprintf(str, "Command Buffer %p has reference to mem obj %p", (*it), pMemObjInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600500 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (*it), 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700501 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600502 for (list<VkObject>::const_iterator it = pMemObjInfo->pObjBindings.begin(); it != pMemObjInfo->pObjBindings.end(); ++it) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700503 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600504 sprintf(str, "VK Object %p has reference to mem obj %p", (*it), pMemObjInfo->mem);
505 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, (*it), 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700506 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500507 if (refCount != pMemObjInfo->refCount) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700508 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500509 sprintf(str, "Refcount of %u for Mem Obj %p does't match reported refs of %u", pMemObjInfo->refCount, pMemObjInfo->mem, refCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600510 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pMemObjInfo->mem, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700511 }
512}
513
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600514static void deleteMemObjInfo(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700515{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500516 MT_MEM_OBJ_INFO* pDelInfo = memObjMap[mem];
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500517 if (memObjMap.find(mem) != memObjMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500518 MT_MEM_OBJ_INFO* pDelInfo = memObjMap[mem];
519 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500520 memObjMap.erase(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700521 }
522}
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500523
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700524// Check if fence for given CB is completed
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600525static bool32_t checkCBCompleted(const VkCmdBuffer cb)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700526{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600527 bool32_t result = VK_TRUE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500528 MT_CB_INFO* pCBInfo = getCBInfo(cb);
529 if (!pCBInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700530 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500531 sprintf(str, "Unable to find global CB info %p to check for completion", cb);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600532 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
533 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600534 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500535 if (!fenceRetired(pCBInfo->fenceId)) {
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600536 char str[1024];
537 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 -0600538 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, cb, 0, MEMTRACK_NONE, "MEM", str);
539 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600540 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700541 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600542 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700543}
544
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600545static bool32_t freeMemObjInfo(VkGpuMemory mem, bool internal)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700546{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600547 bool32_t result = VK_TRUE;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500548 // Parse global list to find info w/ mem
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500549 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
550 if (!pInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700551 char str[1024];
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500552 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 -0600553 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
554 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600555 } else {
Courtney Goeltzenleuchterc4804862015-03-26 16:15:39 -0600556 if (pInfo->allocInfo.allocationSize == 0 && !internal) {
Mark Lobodzinskidaa1d432015-02-18 18:06:24 -0600557 char str[1024];
558 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 -0600559 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
560 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600561 } else {
562 // Clear any CB bindings for completed CBs
563 // TODO : Is there a better place to do this?
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500564
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600565 list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin();
566 list<VkCmdBuffer>::iterator temp;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500567 while (it != pInfo->pCmdBufferBindings.end()) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600568 if (VK_TRUE == checkCBCompleted(*it)) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500569 temp = it;
570 ++temp;
571 freeCBBindings(*it);
572 it = temp;
573 } else {
574 ++it;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600575 }
576 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500577
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600578 // Now verify that no references to this mem obj remain
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500579 if (0 != pInfo->refCount) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500580 // If references remain, report the error and can search CB list to find references
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600581 char str[1024];
582 sprintf(str, "Freeing mem obj %p while it still has references", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600583 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_FREED_MEM_REF, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500584 reportMemReferences(pInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600585 result = VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600586 }
Courtney Goeltzenleuchterc6b048f2015-04-14 00:01:21 -0600587 // Delete mem obj info
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500588 deleteMemObjInfo(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700589 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700590 }
591 return result;
592}
593
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700594// Remove object binding performs 3 tasks:
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500595// 1. Remove ObjectInfo from MemObjInfo list container of obj bindings & free it
596// 2. Decrement refCount for MemObjInfo
597// 3. Clear MemObjInfo ptr from ObjectInfo
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600598static bool32_t clearObjectBinding(VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700599{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600600 bool32_t result = VK_FALSE;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500601 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
602 if (!pObjInfo) {
Tobin Ehlis62086412014-11-19 16:19:28 -0700603 char str[1024];
Mark Lobodzinski15427102015-02-18 16:38:17 -0600604 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 -0600605 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600606 } else {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500607 if (!pObjInfo->pMemObjInfo) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600608 char str[1024];
609 sprintf(str, "Attempting to clear mem binding on obj %p but it has no binding.", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600610 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 -0600611 } else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600612 for (list<VkObject>::iterator it = pObjInfo->pMemObjInfo->pObjBindings.begin(); it != pObjInfo->pMemObjInfo->pObjBindings.end(); ++it) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500613 pObjInfo->pMemObjInfo->refCount--;
614 pObjInfo->pMemObjInfo = NULL;
615 it = pObjInfo->pMemObjInfo->pObjBindings.erase(it);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600616 result = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500617 break;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600618 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600619 if (result == VK_FALSE) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600620 char str[1024];
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500621 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 -0500622 object, pObjInfo->pMemObjInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600623 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600624 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700625 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700626 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600627 return result;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700628}
629
630// For NULL mem case, clear any previous binding Else...
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500631// Make sure given object is in global object map
Tobin Ehlis62086412014-11-19 16:19:28 -0700632// IF a previous binding existed, clear it
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500633// Add reference from objectInfo to memoryInfo
634// Add reference off of objInfo
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600635// Return VK_TRUE if addition is successful, VK_FALSE otherwise
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600636static bool32_t updateObjectBinding(VkObject object, VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700637{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600638 bool32_t result = VK_FALSE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700639 // Handle NULL case separately, just clear previous binding & decrement reference
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600640 if (mem == VK_NULL_HANDLE) {
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700641 clearObjectBinding(object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600642 result = VK_TRUE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600643 } else {
644 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500645 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
646 if (!pObjInfo) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600647 sprintf(str, "Attempting to update Binding of Obj(%p) that's not in global list()", (void*)object);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600648 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
649 return VK_FALSE;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600650 }
651 // non-null case so should have real mem obj
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500652 MT_MEM_OBJ_INFO* pInfo = getMemObjInfo(mem);
653 if (!pInfo) {
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500654 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 -0600655 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600656 } else {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500657 // Search for object in memory object's binding list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600658 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600659 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500660 if ((*it) == object) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600661 found = VK_TRUE;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500662 break;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600663 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600664 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500665 // If not present, add to list
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600666 if (found == VK_FALSE) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500667 pInfo->pObjBindings.push_front(object);
668 pInfo->refCount++;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500669 }
670
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500671 if (pObjInfo->pMemObjInfo) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500672 clearObjectBinding(object); // Need to clear the previous object binding before setting new binding
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500673 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 -0600674 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500675 }
676 // For image objects, make sure default memory state is correctly set
677 // TODO : What's the best/correct way to handle this?
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600678 if (VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO == pObjInfo->sType) {
679 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 -0500680 // TODO:: More memory state transition stuff.
681 }
682 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500683 pObjInfo->pMemObjInfo = pInfo;
Tobin Ehlis6aa77422015-01-07 17:49:29 -0700684 }
685 }
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600686 return VK_TRUE;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700687}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600688
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700689// Print details of global Obj tracking list
690static void printObjList()
691{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500692 MT_OBJ_INFO* pInfo = NULL;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500693 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500694 sprintf(str, "Details of Object list of size %lu elements", objectMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600695 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600696 for (map<VkObject, MT_OBJ_INFO*>::iterator ii=objectMap.begin(); ii!=objectMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500697 pInfo = (*ii).second;
698 sprintf(str, " ObjInfo %p has object %p, pMemObjInfo %p", pInfo, pInfo->object, pInfo->pMemObjInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600699 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, pInfo->object, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700700 }
701}
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600702
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700703// For given Object, get 'mem' obj that it's bound to or NULL if no binding
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600704static VkGpuMemory getMemBindingFromObject(const VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700705{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600706 VkGpuMemory mem = NULL;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500707 MT_OBJ_INFO* pObjInfo = getObjectInfo(object);
708 if (pObjInfo) {
709 if (pObjInfo->pMemObjInfo) {
710 mem = pObjInfo->pMemObjInfo->mem;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700711 }
712 else {
Tobin Ehlis62086412014-11-19 16:19:28 -0700713 char str[1024];
714 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 -0600715 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MISSING_MEM_BINDINGS, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700716 printObjList();
717 }
718 }
719 else {
Tobin Ehlis62086412014-11-19 16:19:28 -0700720 char str[1024];
721 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 -0600722 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700723 printObjList();
724 }
725 return mem;
726}
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500727
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500728// Print details of MemObjInfo list
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700729static void printMemList()
730{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500731 MT_MEM_OBJ_INFO* pInfo = NULL;
Tobin Ehlis62086412014-11-19 16:19:28 -0700732 // Just printing each msg individually for now, may want to package these into single large print
733 char str[1024];
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500734 sprintf(str, "MEM INFO : Details of Memory Object list of size %lu elements", memObjMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600735 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500736
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600737 for (map<VkGpuMemory, MT_MEM_OBJ_INFO*>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500738 pInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500739
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500740 sprintf(str, " ===MemObjInfo at %p===", (void*)pInfo);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600741 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500742 sprintf(str, " Mem object: %p", (void*)pInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600743 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500744 sprintf(str, " Ref Count: %u", pInfo->refCount);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600745 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500746 if (0 != pInfo->allocInfo.allocationSize) {
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -0600747 string pAllocInfoMsg = vk_print_vkmemoryallocinfo(&pInfo->allocInfo, "{MEM}INFO : ");
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500748 sprintf(str, " Mem Alloc info:\n%s", pAllocInfoMsg.c_str());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600749 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500750 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600751 sprintf(str, " Mem Alloc info is NULL (alloc done by vkWsiX11CreatePresentableImage())");
752 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500753 }
754
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600755 sprintf(str, " VK OBJECT Binding list of size %lu elements:", pInfo->pObjBindings.size());
756 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600757 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600758 sprintf(str, " VK OBJECT %p", (*it));
759 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500760 }
761
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600762 sprintf(str, " VK Command Buffer (CB) binding list of size %lu elements", pInfo->pCmdBufferBindings.size());
763 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600764 for (list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin(); it != pInfo->pCmdBufferBindings.end(); ++it) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600765 sprintf(str, " VK CB %p", (*it));
766 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700767 }
768 }
769}
770
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500771static void printCBList()
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700772{
Tobin Ehlis62086412014-11-19 16:19:28 -0700773 char str[1024] = {0};
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500774 MT_CB_INFO* pCBInfo = NULL;
775 sprintf(str, "Details of CB list of size %lu elements", cbMap.size());
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600776 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500777
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600778 for (map<VkCmdBuffer, MT_CB_INFO*>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500779 pCBInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500780
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500781 sprintf(str, " CB Info (%p) has CB %p, fenceId %" PRIx64", and fence %p",
782 (void*)pCBInfo, (void*)pCBInfo->cmdBuffer, pCBInfo->fenceId,
783 (void*)getFenceFromId(pCBInfo->fenceId));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600784 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500785
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600786 for (list<VkGpuMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500787 sprintf(str, " Mem obj %p", (*it));
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600788 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700789 }
790 }
791}
792
Mark Lobodzinski15427102015-02-18 16:38:17 -0600793static void initMemTracker(void)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700794{
Jon Ashburnf57ea372014-12-22 13:24:15 -0700795 const char *strOpt;
796 // initialize MemTracker options
Ian Elliott7d0b5d22015-03-06 13:50:05 -0700797 getLayerOptionEnum("MemTrackerReportLevel", (uint32_t *) &g_reportingLevel);
798 g_actionIsDefault = getLayerOptionEnum("MemTrackerDebugAction", (uint32_t *) &g_debugAction);
Tobin Ehlis5b7acaa2015-01-08 14:26:53 -0700799
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600800 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Jon Ashburnf57ea372014-12-22 13:24:15 -0700801 {
802 strOpt = getLayerOption("MemTrackerLogFilename");
803 if (strOpt)
804 {
805 g_logFile = fopen(strOpt, "w");
Jon Ashburnf57ea372014-12-22 13:24:15 -0700806 }
807 if (g_logFile == NULL)
808 g_logFile = stdout;
809 }
810
811 // initialize Layer dispatch table
812 // TODO handle multiple GPUs
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600813 PFN_vkGetProcAddr fpNextGPA;
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700814 fpNextGPA = pCurObj->pGPA;
815 assert(fpNextGPA);
816
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600817 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkPhysicalGpu) pCurObj->nextObject);
Chia-I Wu0f65b1e2015-01-04 23:11:43 +0800818
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600819 PFN_vkGetProcAddr fpGetProcAddr = (PFN_vkGetProcAddr)fpNextGPA((VkPhysicalGpu) pCurObj->nextObject, (char *) "vkGetProcAddr");
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700820 nextTable.GetProcAddr = fpGetProcAddr;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600821
822 if (!globalLockInitialized)
823 {
824 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600825 // suggestion is to call this during vkCreateInstance(), and then we
826 // can clean it up during vkDestroyInstance(). However, that requires
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600827 // that the layer have per-instance locks. We need to come back and
828 // address this soon.
829 loader_platform_thread_create_mutex(&globalLock);
830 globalLockInitialized = 1;
831 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700832}
833
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600834VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(VkPhysicalGpu gpu, const VkDeviceCreateInfo* pCreateInfo, VkDevice* pDevice)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700835{
Jon Ashburn630e44f2015-04-08 21:33:34 -0600836 pCurObj = (VkBaseLayerObject *) gpu;
Ian Elliott81ac44c2015-01-13 17:52:38 -0700837 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburn630e44f2015-04-08 21:33:34 -0600838 VkResult result = nextTable.CreateDevice(gpu, pCreateInfo, pDevice);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700839 // Save off device in case we need it to create Fences
840 globalDevice = *pDevice;
841 return result;
842}
843
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600844VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(VkDevice device)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700845{
Tobin Ehlis62086412014-11-19 16:19:28 -0700846 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600847 sprintf(str, "Printing List details prior to vkDestroyDevice()");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600848 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600849 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, device, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700850 printMemList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500851 printCBList();
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700852 printObjList();
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600853 if (VK_FALSE == deleteCBInfoList()) {
854 sprintf(str, "Issue deleting global CB list in vkDestroyDevice()");
855 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, device, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -0700856 }
Tobin Ehlis22d03232014-11-25 18:01:12 -0700857 // Report any memory leaks
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500858 MT_MEM_OBJ_INFO* pInfo = NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600859 for (map<VkGpuMemory, MT_MEM_OBJ_INFO*>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500860 pInfo = (*ii).second;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500861
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500862 if (pInfo->allocInfo.allocationSize != 0) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600863 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 -0500864 pInfo->mem, pInfo->mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600865 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, pInfo->mem, 0, MEMTRACK_MEMORY_LEAK, "MEM", str);
Mark Lobodzinskidaa1d432015-02-18 18:06:24 -0600866 }
Tobin Ehlis22d03232014-11-25 18:01:12 -0700867 }
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500868
869 // Queues persist until device is destroyed
870 deleteQueueInfoList();
871
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -0600872 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600873 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700874 return result;
875}
876
Jon Ashburneb2728b2015-04-10 14:33:07 -0600877struct extProps {
878 uint32_t version;
879 const char * const name;
880};
Jon Ashburnbdcd7562015-04-14 14:12:59 -0600881#define MEM_TRACKER_LAYER_EXT_ARRAY_SIZE 2
Jon Ashburneb2728b2015-04-10 14:33:07 -0600882static const struct extProps mtExts[MEM_TRACKER_LAYER_EXT_ARRAY_SIZE] = {
883 // TODO what is the version?
Jon Ashburnbdcd7562015-04-14 14:12:59 -0600884 0x10, "MemTracker",
885 0x10, "Validation"
Jon Ashburneb2728b2015-04-10 14:33:07 -0600886};
887
888VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
889 VkExtensionInfoType infoType,
890 uint32_t extensionIndex,
891 size_t* pDataSize,
892 void* pData)
893{
894 VkResult result;
895
896 /* This entrypoint is NOT going to init it's own dispatch table since loader calls here early */
897 VkExtensionProperties *ext_props;
898 uint32_t *count;
899
900 if (pDataSize == NULL)
901 return VK_ERROR_INVALID_POINTER;
902
903 switch (infoType) {
904 case VK_EXTENSION_INFO_TYPE_COUNT:
905 *pDataSize = sizeof(uint32_t);
906 if (pData == NULL)
907 return VK_SUCCESS;
908 count = (uint32_t *) pData;
909 *count = MEM_TRACKER_LAYER_EXT_ARRAY_SIZE;
910 break;
911 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
912 *pDataSize = sizeof(VkExtensionProperties);
913 if (pData == NULL)
914 return VK_SUCCESS;
915 if (extensionIndex >= MEM_TRACKER_LAYER_EXT_ARRAY_SIZE)
916 return VK_ERROR_INVALID_VALUE;
917 ext_props = (VkExtensionProperties *) pData;
918 ext_props->version = mtExts[extensionIndex].version;
919 strncpy(ext_props->extName, mtExts[extensionIndex].name,
920 VK_MAX_EXTENSION_NAME);
921 ext_props->extName[VK_MAX_EXTENSION_NAME - 1] = '\0';
922 break;
923 default:
924 return VK_ERROR_INVALID_VALUE;
925 };
926
927 return VK_SUCCESS;
928}
929
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600930VK_LAYER_EXPORT VkResult VKAPI vkGetExtensionSupport(VkPhysicalGpu gpu, const char* pExtName)
Jon Ashburn25566352015-04-02 12:06:28 -0600931{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600932 VkResult result;
Jon Ashburn25566352015-04-02 12:06:28 -0600933 /* This entrypoint is NOT going to init its own dispatch table since loader calls here early */
934 if (!strcmp(pExtName, "MemTracker"))
935 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600936 result = VK_SUCCESS;
Jon Ashburn25566352015-04-02 12:06:28 -0600937 } else if (nextTable.GetExtensionSupport != NULL)
938 {
Jon Ashburn630e44f2015-04-08 21:33:34 -0600939 result = nextTable.GetExtensionSupport(gpu, pExtName);
Jon Ashburn25566352015-04-02 12:06:28 -0600940 } else
941 {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600942 result = VK_ERROR_INVALID_EXTENSION;
Jon Ashburn25566352015-04-02 12:06:28 -0600943 }
944 return result;
945}
946
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600947VK_LAYER_EXPORT VkResult VKAPI vkEnumerateLayers(VkPhysicalGpu gpu, size_t maxLayerCount,
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500948 size_t maxStringSize, size_t* pOutLayerCount, char* const* pOutLayers, void* pReserved)
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700949{
Jon Ashburn451c16f2014-11-25 11:08:42 -0700950 if (gpu != NULL)
951 {
Jon Ashburn630e44f2015-04-08 21:33:34 -0600952 pCurObj = (VkBaseLayerObject *) gpu;
Ian Elliott81ac44c2015-01-13 17:52:38 -0700953 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburn630e44f2015-04-08 21:33:34 -0600954 VkResult result = nextTable.EnumerateLayers(gpu, maxLayerCount,
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500955 maxStringSize, pOutLayerCount, pOutLayers, pReserved);
Jon Ashburn451c16f2014-11-25 11:08:42 -0700956 return result;
957 } else
958 {
959 if (pOutLayerCount == NULL || pOutLayers == NULL || pOutLayers[0] == NULL)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600960 return VK_ERROR_INVALID_POINTER;
Jon Ashburn451c16f2014-11-25 11:08:42 -0700961 // This layer compatible with all GPUs
962 *pOutLayerCount = 1;
Chia-I Wua837c522014-12-16 10:47:33 +0800963 strncpy((char *) pOutLayers[0], "MemTracker", maxStringSize);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600964 return VK_SUCCESS;
Jon Ashburn451c16f2014-11-25 11:08:42 -0700965 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -0700966}
967
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600968VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(VkDevice device, uint32_t queueNodeIndex, uint32_t queueIndex, VkQueue* pQueue)
Mark Lobodzinski55e53d92015-03-31 16:05:35 -0500969{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600970 VkResult result = nextTable.GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600971 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500972 loader_platform_thread_lock_mutex(&globalLock);
973 addQueueInfo(*pQueue);
974 loader_platform_thread_unlock_mutex(&globalLock);
975 }
Mark Lobodzinski55e53d92015-03-31 16:05:35 -0500976 return result;
977}
978
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600979VK_LAYER_EXPORT VkResult VKAPI vkQueueAddMemReference(VkQueue queue, VkGpuMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500980{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600981 VkResult result = nextTable.QueueAddMemReference(queue, mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600982 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500983 loader_platform_thread_lock_mutex(&globalLock);
984
985 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
986 if (pQueueInfo == NULL) {
987 char str[1024];
988 sprintf(str, "Unknown Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600989 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500990 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500991 else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600992 if (checkMemRef(queue, mem) == VK_TRUE) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -0500993 // Alread in list, just warn
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500994 char str[1024];
995 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 -0600996 layerCbMsg(VK_DBG_MSG_WARNING, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -0500997 }
998 else {
999 // Add to queue's memory reference list
1000 pQueueInfo->pMemRefList.push_front(mem);
1001 }
1002 }
1003 loader_platform_thread_unlock_mutex(&globalLock);
1004 }
1005 return result;
1006}
1007
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001008VK_LAYER_EXPORT VkResult VKAPI vkQueueRemoveMemReference(VkQueue queue, VkGpuMemory mem)
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001009{
1010 // TODO : Decrement ref count for this memory reference on this queue. Remove if ref count is zero.
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001011 VkResult result = nextTable.QueueRemoveMemReference(queue, mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001012 if (result == VK_SUCCESS) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001013 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001014
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001015 MT_QUEUE_INFO *pQueueInfo = queueMap[queue];
1016 if (pQueueInfo == NULL) {
1017 char str[1024];
1018 sprintf(str, "Unknown Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001019 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_QUEUE, "MEM", str);
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001020 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001021 else {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001022 for (list<VkGpuMemory>::iterator it = pQueueInfo->pMemRefList.begin(); it != pQueueInfo->pMemRefList.end(); ++it) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001023 if ((*it) == mem) {
1024 it = pQueueInfo->pMemRefList.erase(it);
1025 }
1026 }
1027 }
1028 loader_platform_thread_unlock_mutex(&globalLock);
1029 }
1030 return result;
1031}
1032
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001033VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(
1034 VkQueue queue,
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001035 uint32_t cmdBufferCount,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001036 const VkCmdBuffer *pCmdBuffers,
1037 VkFence fence)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001038{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001039 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001040 // TODO : Need to track fence and clear mem references when fence clears
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001041 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001042 uint64_t fenceId = addFenceInfo(fence, queue);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001043
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001044 printMemList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001045 printCBList();
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001046 for (uint32_t i = 0; i < cmdBufferCount; i++) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001047 pCBInfo = getCBInfo(pCmdBuffers[i]);
1048 pCBInfo->fenceId = fenceId;
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001049 }
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001050
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001051 if (VK_FALSE == validateQueueMemRefs(queue, cmdBufferCount, pCmdBuffers)) {
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001052 char str[1024];
1053 sprintf(str, "Unable to verify memory references for Queue %p", queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001054 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_INVALID_MEM_REF, "MEM", str);
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -05001055 }
1056
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001057 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001058 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, getFenceFromId(fenceId));
Courtney Goeltzenleuchtercfedf362015-04-02 13:39:07 -06001059 return result;
1060}
1061
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001062VK_LAYER_EXPORT VkResult VKAPI vkAllocMemory(VkDevice device, const VkMemoryAllocInfo* pAllocInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001063{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001064 VkResult result = nextTable.AllocMemory(device, pAllocInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001065 // TODO : Track allocations and overall size here
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001066 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001067 addMemObjInfo(*pMem, pAllocInfo);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001068 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001069 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001070 return result;
1071}
1072
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001073VK_LAYER_EXPORT VkResult VKAPI vkFreeMemory(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001074{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001075 /* From spec : A memory object is freed by calling vkFreeMemory() when it is no longer needed. Before
Tobin Ehlisa747e682014-11-25 14:47:20 -07001076 * freeing a memory object, an application must ensure the memory object is unbound from
1077 * all API objects referencing it and that it is not referenced by any queued command buffers
1078 */
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001079 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001080 if (VK_FALSE == freeMemObjInfo(mem, false)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001081 char str[1024];
1082 sprintf(str, "Issue while freeing mem obj %p", (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001083 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_FREE_MEM_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001084 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001085 printMemList();
1086 printObjList();
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001087 printCBList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001088 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001089 VkResult result = nextTable.FreeMemory(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001090 return result;
1091}
1092
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001093VK_LAYER_EXPORT VkResult VKAPI vkSetMemoryPriority(VkGpuMemory mem, VkMemoryPriority priority)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001094{
1095 // TODO : Update tracking for this alloc
1096 // Make sure memory is not pinned, which can't have priority set
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001097 VkResult result = nextTable.SetMemoryPriority(mem, priority);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001098 return result;
1099}
1100
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001101VK_LAYER_EXPORT VkResult VKAPI vkMapMemory(VkGpuMemory mem, VkFlags flags, void** ppData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001102{
1103 // TODO : Track when memory is mapped
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001104 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001105 MT_MEM_OBJ_INFO *pMemObj = getMemObjInfo(mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001106 if ((pMemObj->allocInfo.memProps & VK_MEMORY_PROPERTY_CPU_VISIBLE_BIT) == 0) {
Mark Lobodzinski06f60b82015-02-25 12:16:04 -06001107 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001108 sprintf(str, "Mapping Memory (%p) without VK_MEMORY_PROPERTY_CPU_VISIBLE_BIT set", (void*)mem);
1109 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, mem, 0, MEMTRACK_INVALID_STATE, "MEM", str);
Mark Lobodzinski06f60b82015-02-25 12:16:04 -06001110 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001111 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001112 VkResult result = nextTable.MapMemory(mem, flags, ppData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001113 return result;
1114}
1115
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001116VK_LAYER_EXPORT VkResult VKAPI vkUnmapMemory(VkGpuMemory mem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001117{
1118 // TODO : Track as memory gets unmapped, do we want to check what changed following map?
1119 // Make sure that memory was ever mapped to begin with
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001120 VkResult result = nextTable.UnmapMemory(mem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001121 return result;
1122}
1123
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001124VK_LAYER_EXPORT VkResult VKAPI vkPinSystemMemory(VkDevice device, const void* pSysMem, size_t memSize, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001125{
1126 // TODO : Track this
1127 // Verify that memory is actually pinnable
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001128 VkResult result = nextTable.PinSystemMemory(device, pSysMem, memSize, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001129 return result;
1130}
1131
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001132VK_LAYER_EXPORT VkResult VKAPI vkOpenSharedMemory(VkDevice device, const VkMemoryOpenInfo* pOpenInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001133{
1134 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001135 VkResult result = nextTable.OpenSharedMemory(device, pOpenInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001136 return result;
1137}
1138
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001139VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerMemory(VkDevice device, const VkPeerMemoryOpenInfo* pOpenInfo, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001140{
1141 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001142 VkResult result = nextTable.OpenPeerMemory(device, pOpenInfo, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001143 return result;
1144}
1145
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001146VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerImage(VkDevice device, const VkPeerImageOpenInfo* pOpenInfo, VkImage* pImage, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001147{
1148 // TODO : Track this
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001149 VkResult result = nextTable.OpenPeerImage(device, pOpenInfo, pImage, pMem);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001150 return result;
1151}
1152
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001153VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(VkObject object)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001154{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001155 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001156
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001157 // First check if this is a CmdBuffer
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001158 if (NULL != getCBInfo((VkCmdBuffer)object)) {
1159 deleteCBInfo((VkCmdBuffer)object);
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001160 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001161
1162 if (objectMap.find(object) != objectMap.end()) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001163 MT_OBJ_INFO* pDelInfo = objectMap[object];
1164 if (pDelInfo->pMemObjInfo) {
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001165 // Wsi allocated Memory is tied to image object so clear the binding and free that memory automatically
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001166 if (0 == pDelInfo->pMemObjInfo->allocInfo.allocationSize) { // Wsi allocated memory has NULL allocInfo w/ 0 size
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001167 VkGpuMemory memToFree = pDelInfo->pMemObjInfo->mem;
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001168 clearObjectBinding(object);
Courtney Goeltzenleuchterc4804862015-03-26 16:15:39 -06001169 freeMemObjInfo(memToFree, true);
1170 }
1171 else {
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001172 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001173 sprintf(str, "Destroying obj %p that is still bound to memory object %p\nYou should first clear binding by calling vkBindObjectMemory(%p, 0, VK_NULL_HANDLE, 0)", object, (void*)pDelInfo->pMemObjInfo->mem, object);
1174 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_DESTROY_OBJECT_ERROR, "MEM", str);
Tobin Ehlise6884ef2014-11-27 07:52:04 -07001175 // From the spec : If an object has previous memory binding, it is required to unbind memory from an API object before it is destroyed.
1176 clearObjectBinding(object);
1177 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001178 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001179 delete pDelInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001180 objectMap.erase(object);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001181 }
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001182
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001183 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001184 VkResult result = nextTable.DestroyObject(object);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001185 return result;
1186}
1187
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001188VK_LAYER_EXPORT VkResult VKAPI vkGetObjectInfo(VkBaseObject object, VkObjectInfoType infoType, size_t* pDataSize, void* pData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001189{
1190 // TODO : What to track here?
1191 // Could potentially save returned mem requirements and validate values passed into BindObjectMemory for this object
Tobin Ehlis62086412014-11-19 16:19:28 -07001192 // 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 -06001193 VkResult result = nextTable.GetObjectInfo(object, infoType, pDataSize, pData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001194 return result;
1195}
1196
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001197VK_LAYER_EXPORT VkResult VKAPI vkBindObjectMemory(VkObject object, uint32_t allocationIdx, VkGpuMemory mem, VkGpuSize offset)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001198{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001199 VkResult result = nextTable.BindObjectMemory(object, allocationIdx, mem, offset);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001200 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001201 // Track objects tied to memory
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001202 if (VK_FALSE == updateObjectBinding(object, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001203 char str[1024];
1204 sprintf(str, "Unable to set object %p binding to mem obj %p", (void*)object, (void*)mem);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001205 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, object, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001206 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001207 printObjList();
1208 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001209 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001210 return result;
1211}
1212
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001213VK_LAYER_EXPORT VkResult VKAPI vkCreateFence(VkDevice device, const VkFenceCreateInfo* pCreateInfo, VkFence* pFence)
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001214{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001215 VkResult result = nextTable.CreateFence(device, pCreateInfo, pFence);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001216 if (VK_SUCCESS == result) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001217 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001218 addObjectInfo(*pFence, pCreateInfo->sType, pCreateInfo, sizeof(VkFenceCreateInfo), "fence");
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001219 loader_platform_thread_unlock_mutex(&globalLock);
1220 }
1221 return result;
1222}
1223
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001224VK_LAYER_EXPORT VkResult VKAPI vkResetFences(VkDevice device, uint32_t fenceCount, VkFence* pFences)
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001225{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001226 VkResult result = nextTable.ResetFences(device, fenceCount, pFences);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001227 if (VK_SUCCESS == result) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001228 loader_platform_thread_lock_mutex(&globalLock);
1229 // Reset fence state in fenceCreateInfo structure
1230 for (uint32_t i = 0; i < fenceCount; i++) {
1231 MT_OBJ_INFO* pObjectInfo = getObjectInfo(pFences[i]);
1232 if (pObjectInfo != NULL) {
Mark Lobodzinski56945182015-04-09 13:46:09 -05001233 // Validate fences in SIGNALED state
Tobin Ehlisf29da382015-04-15 07:46:12 -06001234 if (!(pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT)) {
Mark Lobodzinski56945182015-04-09 13:46:09 -05001235 char str[1024];
Mark Lobodzinski610be622015-04-14 14:09:32 -05001236 sprintf(str, "Fence %p submitted to VkResetFences in UNSIGNALED STATE", pFences[i]);
Tobin Ehlisf29da382015-04-15 07:46:12 -06001237 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
1238 result = VK_ERROR_INVALID_VALUE;
Mark Lobodzinski56945182015-04-09 13:46:09 -05001239 }
1240 else {
1241 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisf29da382015-04-15 07:46:12 -06001242 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags & ~VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinski56945182015-04-09 13:46:09 -05001243 }
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001244 }
1245 }
1246 loader_platform_thread_unlock_mutex(&globalLock);
1247 }
1248 return result;
1249}
1250
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001251VK_LAYER_EXPORT VkResult VKAPI vkGetFenceStatus(VkFence fence)
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001252{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001253 VkResult result = nextTable.GetFenceStatus(fence);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001254 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001255 loader_platform_thread_lock_mutex(&globalLock);
1256 updateFenceTracking(fence);
1257 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001258 }
1259 return result;
1260}
1261
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001262VK_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 -07001263{
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001264 // Verify fence status of submitted fences
1265 for(uint32_t i = 0; i < fenceCount; i++) {
1266 MT_OBJ_INFO* pObjectInfo = getObjectInfo(pFences[i]);
1267 if (pObjectInfo != NULL) {
Tobin Ehlisf29da382015-04-15 07:46:12 -06001268 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -05001269 char str[1024];
Mark Lobodzinski610be622015-04-14 14:09:32 -05001270 sprintf(str, "VkWaitForFences specified fence %p already in SIGNALED state.", pFences[i]);
Tobin Ehlisf29da382015-04-15 07:46:12 -06001271 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 -05001272 }
1273 }
1274 }
1275
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001276 VkResult result = nextTable.WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001277 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001278
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001279 if (VK_SUCCESS == result) {
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001280 if (waitAll || fenceCount == 1) { // Clear all the fences
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001281 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001282 updateFenceTracking(pFences[i]);
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001283 }
1284 }
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001285 }
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001286 loader_platform_thread_unlock_mutex(&globalLock);
1287 return result;
1288}
1289
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001290VK_LAYER_EXPORT VkResult VKAPI vkQueueWaitIdle(VkQueue queue)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001291{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001292 VkResult result = nextTable.QueueWaitIdle(queue);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001293 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001294 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001295 retireQueueFences(queue);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001296 loader_platform_thread_unlock_mutex(&globalLock);
1297 }
1298 return result;
1299}
1300
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001301VK_LAYER_EXPORT VkResult VKAPI vkDeviceWaitIdle(VkDevice device)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001302{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001303 VkResult result = nextTable.DeviceWaitIdle(device);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001304 if (VK_SUCCESS == result) {
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001305 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski8ee96342015-04-02 20:49:09 -05001306 retireDeviceFences(device);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001307 loader_platform_thread_unlock_mutex(&globalLock);
1308 }
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001309 return result;
1310}
1311
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001312VK_LAYER_EXPORT VkResult VKAPI vkCreateEvent(VkDevice device, const VkEventCreateInfo* pCreateInfo, VkEvent* pEvent)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001313{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001314 VkResult result = nextTable.CreateEvent(device, pCreateInfo, pEvent);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001315 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001316 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001317 addObjectInfo(*pEvent, pCreateInfo->sType, pCreateInfo, sizeof(VkEventCreateInfo), "event");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001318 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001319 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001320 return result;
1321}
1322
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001323VK_LAYER_EXPORT VkResult VKAPI vkCreateQueryPool(VkDevice device, const VkQueryPoolCreateInfo* pCreateInfo, VkQueryPool* pQueryPool)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001324{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001325 VkResult result = nextTable.CreateQueryPool(device, pCreateInfo, pQueryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001326 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001327 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001328 addObjectInfo(*pQueryPool, pCreateInfo->sType, pCreateInfo, sizeof(VkQueryPoolCreateInfo), "query_pool");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001329 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001330 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001331 return result;
1332}
1333
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001334VK_LAYER_EXPORT VkResult VKAPI vkCreateBuffer(VkDevice device, const VkBufferCreateInfo* pCreateInfo, VkBuffer* pBuffer)
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001335{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001336 VkResult result = nextTable.CreateBuffer(device, pCreateInfo, pBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001337 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001338 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001339 addObjectInfo(*pBuffer, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferCreateInfo), "buffer");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001340 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001341 }
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001342 return result;
1343}
1344
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001345VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(VkDevice device, const VkBufferViewCreateInfo* pCreateInfo, VkBufferView* pView)
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001346{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001347 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001348 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001349 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -06001350 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferViewCreateInfo), "buffer_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001351 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001352 }
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001353 return result;
1354}
1355
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001356VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(VkDevice device, const VkImageCreateInfo* pCreateInfo, VkImage* pImage)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001357{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001358 VkResult result = nextTable.CreateImage(device, pCreateInfo, pImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001359 if (VK_SUCCESS == result) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001360 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001361 addObjectInfo(*pImage, pCreateInfo->sType, pCreateInfo, sizeof(VkImageCreateInfo), "image");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001362 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001363 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001364 return result;
1365}
1366
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001367VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(VkDevice device, const VkImageViewCreateInfo* pCreateInfo, VkImageView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001368{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001369 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001370 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001371 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001372 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkImageViewCreateInfo), "image_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001373 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001374 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001375 return result;
1376}
1377
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001378VK_LAYER_EXPORT VkResult VKAPI vkCreateColorAttachmentView(VkDevice device, const VkColorAttachmentViewCreateInfo* pCreateInfo,
1379 VkColorAttachmentView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001380{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001381 VkResult result = nextTable.CreateColorAttachmentView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001382 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001383 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001384 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkColorAttachmentViewCreateInfo), "color_attachment_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001385 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001386 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001387 return result;
1388}
1389
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001390VK_LAYER_EXPORT VkResult VKAPI vkCreateDepthStencilView(VkDevice device, const VkDepthStencilViewCreateInfo* pCreateInfo, VkDepthStencilView* pView)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001391{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001392 VkResult result = nextTable.CreateDepthStencilView(device, pCreateInfo, pView);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001393 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001394 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001395 addObjectInfo(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkDepthStencilViewCreateInfo), "ds_view");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001396 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001397 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001398 return result;
1399}
1400
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001401VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(VkDevice device, const VkShaderCreateInfo* pCreateInfo, VkShader* pShader)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001402{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001403 VkResult result = nextTable.CreateShader(device, pCreateInfo, pShader);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001404 return result;
1405}
1406
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001407VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(VkDevice device, const VkGraphicsPipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001408{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001409 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001410 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001411 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001412 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001413 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001414 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001415 return result;
1416}
1417
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001418VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
1419 VkDevice device,
1420 const VkGraphicsPipelineCreateInfo* pCreateInfo,
1421 VkPipeline basePipeline,
1422 VkPipeline* pPipeline)
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001423{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001424 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001425 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001426 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001427 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Courtney Goeltzenleuchter32876a12015-03-25 15:37:49 -06001428 loader_platform_thread_unlock_mutex(&globalLock);
1429 }
1430 return result;
1431}
1432
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001433VK_LAYER_EXPORT VkResult VKAPI vkCreateComputePipeline(VkDevice device, const VkComputePipelineCreateInfo* pCreateInfo, VkPipeline* pPipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001434{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001435 VkResult result = nextTable.CreateComputePipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001436 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001437 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001438 addObjectInfo(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkComputePipelineCreateInfo), "compute_pipeline");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001439 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001440 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001441 return result;
1442}
1443
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001444VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(VkDevice device, const VkSamplerCreateInfo* pCreateInfo, VkSampler* pSampler)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001445{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001446 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001447 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001448 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001449 addObjectInfo(*pSampler, pCreateInfo->sType, pCreateInfo, sizeof(VkSamplerCreateInfo), "sampler");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001450 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001451 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001452 return result;
1453}
1454
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001455VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(VkDevice device, const VkDynamicVpStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001456 VkDynamicVpState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001457{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001458 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001459 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001460 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001461 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo), "viewport_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001462 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001463 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001464 return result;
1465}
1466
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001467VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(VkDevice device, const VkDynamicRsStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001468 VkDynamicRsState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001469{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001470 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001471 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001472 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001473 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo), "raster_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001474 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001475 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001476 return result;
1477}
1478
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001479VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(VkDevice device, const VkDynamicCbStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001480 VkDynamicCbState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001481{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001482 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001483 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001484 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001485 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo), "cb_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001486 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001487 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001488 return result;
1489}
1490
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001491VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(VkDevice device, const VkDynamicDsStateCreateInfo* pCreateInfo,
Courtney Goeltzenleuchterfcf855f2015-04-10 16:24:50 -06001492 VkDynamicDsState* pState)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001493{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001494 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001495 if (result == VK_SUCCESS) {
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001496 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001497 addObjectInfo(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo), "ds_state");
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001498 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001499 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001500 return result;
1501}
1502
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001503VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(VkDevice device, const VkCmdBufferCreateInfo* pCreateInfo, VkCmdBuffer* pCmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001504{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001505 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001506 // At time of cmd buffer creation, create global cmd buffer info for the returned cmd buffer
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001507 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001508 if (*pCmdBuffer)
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001509 addCBInfo(*pCmdBuffer);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001510 printCBList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001511 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001512 return result;
1513}
1514
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001515VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(VkCmdBuffer cmdBuffer, const VkCmdBufferBeginInfo* pBeginInfo)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001516{
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001517 // 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 -05001518 MT_CB_INFO* pCBInfo = getCBInfo(cmdBuffer);
1519 if (pCBInfo && (!fenceRetired(pCBInfo->fenceId))) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001520 bool32_t cbDone = checkCBCompleted(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001521 if (VK_FALSE == cbDone) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001522 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001523 sprintf(str, "Calling vkBeginCommandBuffer() on active CB %p before it has completed. You must check CB flag before this call.", cmdBuffer);
1524 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 -07001525 }
1526 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001527 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001528 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001529 freeCBBindings(cmdBuffer);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001530 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001531 return result;
1532}
1533
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001534VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001535{
1536 // TODO : Anything to do here?
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001537 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001538 return result;
1539}
1540
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001541VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(VkCmdBuffer cmdBuffer)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001542{
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001543 // Verify that CB is complete (not in-flight)
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001544 MT_CB_INFO* pCBInfo = getCBInfo(cmdBuffer);
1545 if (pCBInfo && (!fenceRetired(pCBInfo->fenceId))) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001546 bool32_t cbDone = checkCBCompleted(cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001547 if (VK_FALSE == cbDone) {
Tobin Ehlis77b3abb2015-03-04 08:38:22 -07001548 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001549 sprintf(str, "Resetting CB %p before it has completed. You must check CB flag before calling vkResetCommandBuffer().", cmdBuffer);
1550 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 -07001551 }
1552 }
1553 // Clear memory references as this point.
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001554 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001555 freeCBBindings(cmdBuffer);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001556 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001557 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001558 return result;
1559}
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001560// TODO : For any vkCmdBind* calls that include an object which has mem bound to it,
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001561// need to account for that mem now having binding to given cmdBuffer
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001562VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(VkCmdBuffer cmdBuffer, VkPipelineBindPoint pipelineBindPoint, VkPipeline pipeline)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001563{
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001564#if 0
1565 // TODO : If memory bound to pipeline, then need to tie that mem to cmdBuffer
1566 if (getPipeline(pipeline)) {
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001567 MT_CB_INFO *pCBInfo = getCBInfo(cmdBuffer);
1568 if (pCBInfo) {
1569 pCBInfo->pipelines[pipelineBindPoint] = pipeline;
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001570 } else {
1571 char str[1024];
1572 sprintf(str, "Attempt to bind Pipeline %p to non-existant command buffer %p!", (void*)pipeline, cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001573 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 -07001574 }
1575 }
1576 else {
1577 char str[1024];
1578 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001579 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 -07001580 }
1581#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001582 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1583}
1584
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001585VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(VkCmdBuffer cmdBuffer, VkStateBindPoint stateBindPoint, VkDynamicStateObject state)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001586{
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001587 MT_OBJ_INFO *pObjInfo;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001588 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001589 MT_CB_INFO *pCmdBuf = getCBInfo(cmdBuffer);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001590 if (!pCmdBuf) {
1591 char str[1024];
1592 sprintf(str, "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001593 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_INVALID_CB, "DD", str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001594 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001595 pObjInfo = getObjectInfo(state);
1596 if (!pObjInfo) {
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001597 char str[1024];
1598 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001599 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, state, 0, MEMTRACK_INVALID_OBJECT, "DD", str);
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001600 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001601 pCmdBuf->pDynamicState[stateBindPoint] = pObjInfo;
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001602 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001603 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001604}
1605
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001606VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001607 VkCmdBuffer cmdBuffer,
1608 VkPipelineBindPoint pipelineBindPoint,
1609 VkDescriptorSetLayoutChain layoutChain,
Mark Lobodzinski411f0612015-04-07 09:34:09 -05001610 uint32_t layoutChainSlot,
1611 uint32_t count,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001612 const VkDescriptorSet* pDescriptorSets,
Mark Lobodzinski411f0612015-04-07 09:34:09 -05001613 const uint32_t* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001614{
Tobin Ehlis2836a7d2015-01-08 15:22:32 -07001615 // 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 -06001616 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, layoutChain, layoutChainSlot, count, pDescriptorSets, pUserData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001617}
1618
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001619VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t binding)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001620{
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001621 nextTable.CmdBindVertexBuffer(cmdBuffer, buffer, offset, binding);
Chia-I Wufb5062e2015-01-05 13:42:56 +08001622}
1623
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001624VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, VkIndexType indexType)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001625{
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001626 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001627}
1628
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001629VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001630{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001631 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001632 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001633 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001634 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001635 sprintf(str, "In vkCmdDrawIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1636 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001637 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001638 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001639 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001640}
1641
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001642VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset, uint32_t count, uint32_t stride)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001643{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001644 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001645 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001646 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001647 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001648 sprintf(str, "In vkCmdDrawIndexedIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1649 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001650 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001651 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001652 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001653}
1654
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001655VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(VkCmdBuffer cmdBuffer, VkBuffer buffer, VkGpuSize offset)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001656{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001657 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001658 VkGpuMemory mem = getMemBindingFromObject(buffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001659 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001660 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001661 sprintf(str, "In vkCmdDispatchIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
1662 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001663 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001664 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001665 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001666}
1667
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001668VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(VkCmdBuffer cmdBuffer, VkBuffer srcBuffer, VkBuffer destBuffer,
1669 uint32_t regionCount, const VkBufferCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001670{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001671 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001672 VkGpuMemory mem = getMemBindingFromObject(srcBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001673 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001674 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001675 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
1676 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001677 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001678 mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001679 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001680 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001681 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1682 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001683 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001684 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinski15427102015-02-18 16:38:17 -06001685 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001686}
1687
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001688VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(VkCmdBuffer cmdBuffer,
1689 VkImage srcImage, VkImageLayout srcImageLayout,
1690 VkImage destImage, VkImageLayout destImageLayout,
1691 uint32_t regionCount, const VkImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001692{
1693 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001694 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001695}
1696
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001697VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(VkCmdBuffer cmdBuffer,
1698 VkImage srcImage, VkImageLayout srcImageLayout,
1699 VkImage destImage, VkImageLayout destImageLayout,
1700 uint32_t regionCount, const VkImageBlit* pRegions)
Courtney Goeltzenleuchterb787a1e2015-03-08 17:02:18 -06001701{
1702 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001703 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Courtney Goeltzenleuchterb787a1e2015-03-08 17:02:18 -06001704}
1705
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001706VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(VkCmdBuffer cmdBuffer,
1707 VkBuffer srcBuffer,
1708 VkImage destImage, VkImageLayout destImageLayout,
1709 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001710{
1711 // TODO : Track this
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001712 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001713 VkGpuMemory mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001714 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001715 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001716 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1717 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001718 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001719
1720 mem = getMemBindingFromObject(srcBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001721 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001722 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001723 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
1724 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001725 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001726 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001727 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001728}
1729
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001730VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(VkCmdBuffer cmdBuffer,
1731 VkImage srcImage, VkImageLayout srcImageLayout,
1732 VkBuffer destBuffer,
1733 uint32_t regionCount, const VkBufferImageCopy* pRegions)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001734{
1735 // TODO : Track this
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001736 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001737 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001738 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001739 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001740 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1741 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001742 }
Mark Lobodzinski15427102015-02-18 16:38:17 -06001743 mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001744 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001745 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001746 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1747 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001748 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001749 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001750 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001751}
1752
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001753VK_LAYER_EXPORT void VKAPI vkCmdCloneImageData(VkCmdBuffer cmdBuffer, VkImage srcImage, VkImageLayout srcImageLayout,
1754 VkImage destImage, VkImageLayout destImageLayout)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001755{
1756 // TODO : Each image will have mem mapping so track them
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001757 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001758 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001759 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001760 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001761 sprintf(str, "In vkCmdCloneImageData() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1762 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001763 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001764 mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001765 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001766 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001767 sprintf(str, "In vkCmdCloneImageData() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1768 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001769 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001770 loader_platform_thread_unlock_mutex(&globalLock);
Mike Stroyan55658c22014-12-04 11:08:39 +00001771 nextTable.CmdCloneImageData(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001772}
1773
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001774VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkGpuSize destOffset, VkGpuSize dataSize, const uint32_t* pData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001775{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001776 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001777 VkGpuMemory mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001778 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001779 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001780 sprintf(str, "In vkCmdUpdateMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1781 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001782 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001783 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001784 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001785}
1786
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001787VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(VkCmdBuffer cmdBuffer, VkBuffer destBuffer, VkGpuSize destOffset, VkGpuSize fillSize, uint32_t data)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001788{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001789 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001790 VkGpuMemory mem = getMemBindingFromObject(destBuffer);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001791 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001792 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001793 sprintf(str, "In vkCmdFillMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
1794 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001795 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001796 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis84c521c2015-01-19 08:42:29 -07001797 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001798}
1799
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001800VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(VkCmdBuffer cmdBuffer,
1801 VkImage image, VkImageLayout imageLayout,
1802 VkClearColor color,
1803 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001804{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001805 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001806 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001807 VkGpuMemory mem = getMemBindingFromObject(image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001808 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001809 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001810 sprintf(str, "In vkCmdClearColorImage() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
1811 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001812 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001813 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001814 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, color, rangeCount, pRanges);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001815}
1816
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001817VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(VkCmdBuffer cmdBuffer,
1818 VkImage image, VkImageLayout imageLayout,
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001819 float depth, uint32_t stencil,
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001820 uint32_t rangeCount, const VkImageSubresourceRange* pRanges)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001821{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001822 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001823 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001824 VkGpuMemory mem = getMemBindingFromObject(image);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001825 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001826 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001827 sprintf(str, "In vkCmdClearDepthStencil() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
1828 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001829 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001830 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001831 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001832}
1833
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001834VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(VkCmdBuffer cmdBuffer,
1835 VkImage srcImage, VkImageLayout srcImageLayout,
1836 VkImage destImage, VkImageLayout destImageLayout,
1837 uint32_t rectCount, const VkImageResolve* pRects)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001838{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001839 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001840 VkGpuMemory mem = getMemBindingFromObject(srcImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001841 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001842 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001843 sprintf(str, "In vkCmdResolveImage() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
1844 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001845 }
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001846 mem = getMemBindingFromObject(destImage);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001847 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001848 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001849 sprintf(str, "In vkCmdResolveImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
1850 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001851 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001852 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter51cbf302015-03-25 11:25:10 -06001853 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, rectCount, pRects);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001854}
1855
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001856VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot, VkFlags flags)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001857{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001858 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001859 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001860 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001861 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001862 sprintf(str, "In vkCmdBeginQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1863 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001864 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001865 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001866 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
1867}
1868
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001869VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t slot)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001870{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001871 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001872 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001873 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001874 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001875 sprintf(str, "In vkCmdEndQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1876 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001877 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001878 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001879 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
1880}
1881
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001882VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(VkCmdBuffer cmdBuffer, VkQueryPool queryPool, uint32_t startQuery, uint32_t queryCount)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001883{
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001884 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001885 VkGpuMemory mem = getMemBindingFromObject(queryPool);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001886 if (VK_FALSE == updateCBBinding(cmdBuffer, mem)) {
Tobin Ehlis62086412014-11-19 16:19:28 -07001887 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001888 sprintf(str, "In vkCmdResetQueryPool() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
1889 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis62086412014-11-19 16:19:28 -07001890 }
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001891 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001892 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
1893}
1894
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001895VK_LAYER_EXPORT VkResult VKAPI vkDbgRegisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback, void* pUserData)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001896{
Tobin Ehlis62086412014-11-19 16:19:28 -07001897 // This layer intercepts callbacks
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001898 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 -07001899 if (!pNewDbgFuncNode)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001900 return VK_ERROR_OUT_OF_MEMORY;
Tobin Ehlis62086412014-11-19 16:19:28 -07001901 pNewDbgFuncNode->pfnMsgCallback = pfnMsgCallback;
1902 pNewDbgFuncNode->pUserData = pUserData;
Jon Ashburnf57ea372014-12-22 13:24:15 -07001903 pNewDbgFuncNode->pNext = g_pDbgFunctionHead;
1904 g_pDbgFunctionHead = pNewDbgFuncNode;
Jon Ashburne4722392015-03-03 15:07:15 -07001905 // force callbacks if DebugAction hasn't been set already other than initial value
Courtney Goeltzenleuchter9e3aafa2015-03-04 15:47:34 -07001906 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001907 g_debugAction = VK_DBG_LAYER_ACTION_CALLBACK;
Courtney Goeltzenleuchter9e3aafa2015-03-04 15:47:34 -07001908 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001909 VkResult result = nextTable.DbgRegisterMsgCallback(instance, pfnMsgCallback, pUserData);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001910 return result;
1911}
1912
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001913VK_LAYER_EXPORT VkResult VKAPI vkDbgUnregisterMsgCallback(VkInstance instance, VK_DBG_MSG_CALLBACK_FUNCTION pfnMsgCallback)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001914{
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001915 VK_LAYER_DBG_FUNCTION_NODE *pInfo = g_pDbgFunctionHead;
1916 VK_LAYER_DBG_FUNCTION_NODE *pPrev = pInfo;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001917 while (pInfo) {
1918 if (pInfo->pfnMsgCallback == pfnMsgCallback) {
1919 pPrev->pNext = pInfo->pNext;
1920 if (g_pDbgFunctionHead == pInfo)
1921 g_pDbgFunctionHead = pInfo->pNext;
1922 free(pInfo);
Tobin Ehlis62086412014-11-19 16:19:28 -07001923 break;
1924 }
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -05001925 pPrev = pInfo;
1926 pInfo = pInfo->pNext;
Tobin Ehlis62086412014-11-19 16:19:28 -07001927 }
Jon Ashburne4722392015-03-03 15:07:15 -07001928 if (g_pDbgFunctionHead == NULL)
1929 {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001930 if (g_actionIsDefault) {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001931 g_debugAction = VK_DBG_LAYER_ACTION_LOG_MSG;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001932 } else {
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001933 g_debugAction = (VK_LAYER_DBG_ACTION)(g_debugAction & ~((uint32_t)VK_DBG_LAYER_ACTION_CALLBACK));
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05001934 }
Jon Ashburne4722392015-03-03 15:07:15 -07001935 }
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001936 VkResult result = nextTable.DbgUnregisterMsgCallback(instance, pfnMsgCallback);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001937 return result;
1938}
1939
Jon Ashburndc899962015-03-02 16:51:38 -07001940#if !defined(WIN32)
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001941VK_LAYER_EXPORT VkResult VKAPI vkWsiX11CreatePresentableImage(VkDevice device, const VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO* pCreateInfo,
1942 VkImage* pImage, VkGpuMemory* pMem)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001943{
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001944 VkResult result = nextTable.WsiX11CreatePresentableImage(device, pCreateInfo, pImage, pMem);
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001945 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001946 if (VK_SUCCESS == result) {
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001947 // Add image object, then insert the new Mem Object and then bind it to created image
Courtney Goeltzenleuchter070f6da2015-04-10 17:59:44 -06001948 addObjectInfo(*pImage, VkStructureType_MAX_ENUM, pCreateInfo, sizeof(VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO), "wsi_x11_image");
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001949 addMemObjInfo(*pMem, NULL);
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001950 if (VK_FALSE == updateObjectBinding(*pImage, *pMem)) {
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001951 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001952 sprintf(str, "In vkWsiX11CreatePresentableImage(), unable to set image %p binding to mem obj %p", (void*)*pImage, (void*)*pMem);
1953 layerCbMsg(VK_DBG_MSG_ERROR, VK_VALIDATION_LEVEL_0, *pImage, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehlis6aa77422015-01-07 17:49:29 -07001954 }
Tobin Ehlis62086412014-11-19 16:19:28 -07001955 }
1956 printObjList();
1957 printMemList();
Mark Lobodzinski0c0d6a02015-03-02 20:23:52 -06001958 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001959 return result;
1960}
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001961
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001962VK_LAYER_EXPORT VkResult VKAPI vkWsiX11QueuePresent(VkQueue queue, const VK_WSI_X11_PRESENT_INFO* pPresentInfo, VkFence fence)
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001963{
1964 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski85a83982015-04-02 08:52:53 -05001965 addFenceInfo(fence, queue);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001966 char str[1024];
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001967 sprintf(str, "In vkWsiX11QueuePresent(), checking queue %p for fence %p", queue, fence);
1968 layerCbMsg(VK_DBG_MSG_UNKNOWN, VK_VALIDATION_LEVEL_0, queue, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001969 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001970 VkResult result = nextTable.WsiX11QueuePresent(queue, pPresentInfo, fence);
Mark Lobodzinski4aad3642015-03-17 10:53:12 -05001971 return result;
1972}
Ian Elliott81ac44c2015-01-13 17:52:38 -07001973#endif // WIN32
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001974
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06001975VK_LAYER_EXPORT void* VKAPI vkGetProcAddr(VkPhysicalGpu gpu, const char* funcName)
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001976{
Jon Ashburn301c5f02015-04-06 10:58:22 -06001977 VkBaseLayerObject* gpuw = (VkBaseLayerObject *) gpu;
Chia-I Wu706533e2015-01-05 13:18:57 +08001978
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001979 if (gpu == NULL)
1980 return NULL;
1981 pCurObj = gpuw;
Ian Elliott81ac44c2015-01-13 17:52:38 -07001982 loader_platform_thread_once(&g_initOnce, initMemTracker);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07001983
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06001984 if (!strcmp(funcName, "vkGetProcAddr"))
1985 return (void *) vkGetProcAddr;
1986 if (!strcmp(funcName, "vkCreateDevice"))
1987 return (void*) vkCreateDevice;
1988 if (!strcmp(funcName, "vkDestroyDevice"))
1989 return (void*) vkDestroyDevice;
1990 if (!strcmp(funcName, "vkGetExtensionSupport"))
1991 return (void*) vkGetExtensionSupport;
1992 if (!strcmp(funcName, "vkEnumerateLayers"))
1993 return (void*) vkEnumerateLayers;
1994 if (!strcmp(funcName, "vkQueueSubmit"))
1995 return (void*) vkQueueSubmit;
1996 if (!strcmp(funcName, "vkAllocMemory"))
1997 return (void*) vkAllocMemory;
1998 if (!strcmp(funcName, "vkFreeMemory"))
1999 return (void*) vkFreeMemory;
2000 if (!strcmp(funcName, "vkSetMemoryPriority"))
2001 return (void*) vkSetMemoryPriority;
2002 if (!strcmp(funcName, "vkMapMemory"))
2003 return (void*) vkMapMemory;
2004 if (!strcmp(funcName, "vkUnmapMemory"))
2005 return (void*) vkUnmapMemory;
2006 if (!strcmp(funcName, "vkPinSystemMemory"))
2007 return (void*) vkPinSystemMemory;
2008 if (!strcmp(funcName, "vkOpenSharedMemory"))
2009 return (void*) vkOpenSharedMemory;
2010 if (!strcmp(funcName, "vkOpenPeerMemory"))
2011 return (void*) vkOpenPeerMemory;
2012 if (!strcmp(funcName, "vkOpenPeerImage"))
2013 return (void*) vkOpenPeerImage;
2014 if (!strcmp(funcName, "vkDestroyObject"))
2015 return (void*) vkDestroyObject;
2016 if (!strcmp(funcName, "vkGetObjectInfo"))
2017 return (void*) vkGetObjectInfo;
2018 if (!strcmp(funcName, "vkBindObjectMemory"))
2019 return (void*) vkBindObjectMemory;
2020 if (!strcmp(funcName, "vkCreateFence"))
2021 return (void*) vkCreateFence;
2022 if (!strcmp(funcName, "vkGetFenceStatus"))
2023 return (void*) vkGetFenceStatus;
2024 if (!strcmp(funcName, "vkResetFences"))
2025 return (void*) vkResetFences;
2026 if (!strcmp(funcName, "vkWaitForFences"))
2027 return (void*) vkWaitForFences;
2028 if (!strcmp(funcName, "vkQueueWaitIdle"))
2029 return (void*) vkQueueWaitIdle;
2030 if (!strcmp(funcName, "vkDeviceWaitIdle"))
2031 return (void*) vkDeviceWaitIdle;
2032 if (!strcmp(funcName, "vkCreateEvent"))
2033 return (void*) vkCreateEvent;
2034 if (!strcmp(funcName, "vkCreateQueryPool"))
2035 return (void*) vkCreateQueryPool;
2036 if (!strcmp(funcName, "vkCreateBuffer"))
2037 return (void*) vkCreateBuffer;
2038 if (!strcmp(funcName, "vkCreateBufferView"))
2039 return (void*) vkCreateBufferView;
2040 if (!strcmp(funcName, "vkCreateImage"))
2041 return (void*) vkCreateImage;
2042 if (!strcmp(funcName, "vkCreateImageView"))
2043 return (void*) vkCreateImageView;
2044 if (!strcmp(funcName, "vkCreateColorAttachmentView"))
2045 return (void*) vkCreateColorAttachmentView;
2046 if (!strcmp(funcName, "vkCreateDepthStencilView"))
2047 return (void*) vkCreateDepthStencilView;
2048 if (!strcmp(funcName, "vkCreateShader"))
2049 return (void*) vkCreateShader;
2050 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2051 return (void*) vkCreateGraphicsPipeline;
2052 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2053 return (void*) vkCreateGraphicsPipelineDerivative;
2054 if (!strcmp(funcName, "vkCreateComputePipeline"))
2055 return (void*) vkCreateComputePipeline;
2056 if (!strcmp(funcName, "vkCreateSampler"))
2057 return (void*) vkCreateSampler;
2058 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2059 return (void*) vkCreateDynamicViewportState;
2060 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2061 return (void*) vkCreateDynamicRasterState;
2062 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2063 return (void*) vkCreateDynamicColorBlendState;
2064 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2065 return (void*) vkCreateDynamicDepthStencilState;
2066 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2067 return (void*) vkCreateCommandBuffer;
2068 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2069 return (void*) vkBeginCommandBuffer;
2070 if (!strcmp(funcName, "vkEndCommandBuffer"))
2071 return (void*) vkEndCommandBuffer;
2072 if (!strcmp(funcName, "vkResetCommandBuffer"))
2073 return (void*) vkResetCommandBuffer;
2074 if (!strcmp(funcName, "vkCmdBindPipeline"))
2075 return (void*) vkCmdBindPipeline;
2076 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2077 return (void*) vkCmdBindDynamicStateObject;
2078 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2079 return (void*) vkCmdBindDescriptorSets;
2080 if (!strcmp(funcName, "vkCmdBindVertexBuffer"))
2081 return (void*) vkCmdBindVertexBuffer;
2082 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2083 return (void*) vkCmdBindIndexBuffer;
2084 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2085 return (void*) vkCmdDrawIndirect;
2086 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2087 return (void*) vkCmdDrawIndexedIndirect;
2088 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2089 return (void*) vkCmdDispatchIndirect;
2090 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2091 return (void*) vkCmdCopyBuffer;
2092 if (!strcmp(funcName, "vkCmdCopyImage"))
2093 return (void*) vkCmdCopyImage;
2094 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2095 return (void*) vkCmdCopyBufferToImage;
2096 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2097 return (void*) vkCmdCopyImageToBuffer;
2098 if (!strcmp(funcName, "vkCmdCloneImageData"))
2099 return (void*) vkCmdCloneImageData;
2100 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2101 return (void*) vkCmdUpdateBuffer;
2102 if (!strcmp(funcName, "vkCmdFillBuffer"))
2103 return (void*) vkCmdFillBuffer;
2104 if (!strcmp(funcName, "vkCmdClearColorImage"))
2105 return (void*) vkCmdClearColorImage;
2106 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2107 return (void*) vkCmdClearDepthStencil;
2108 if (!strcmp(funcName, "vkCmdResolveImage"))
2109 return (void*) vkCmdResolveImage;
2110 if (!strcmp(funcName, "vkCmdBeginQuery"))
2111 return (void*) vkCmdBeginQuery;
2112 if (!strcmp(funcName, "vkCmdEndQuery"))
2113 return (void*) vkCmdEndQuery;
2114 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2115 return (void*) vkCmdResetQueryPool;
2116 if (!strcmp(funcName, "vkDbgRegisterMsgCallback"))
2117 return (void*) vkDbgRegisterMsgCallback;
2118 if (!strcmp(funcName, "vkDbgUnregisterMsgCallback"))
2119 return (void*) vkDbgUnregisterMsgCallback;
2120 if (!strcmp(funcName, "vkGetDeviceQueue"))
2121 return (void*) vkGetDeviceQueue;
2122 if (!strcmp(funcName, "vkQueueAddMemReference"))
2123 return (void*) vkQueueAddMemReference;
2124 if (!strcmp(funcName, "vkQueueRemoveMemReference"))
2125 return (void*) vkQueueRemoveMemReference;
Jon Ashburndc899962015-03-02 16:51:38 -07002126#if !defined(WIN32)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002127 if (!strcmp(funcName, "vkWsiX11CreatePresentableImage"))
2128 return (void*) vkWsiX11CreatePresentableImage;
2129 if (!strcmp(funcName, "vkWsiX11QueuePresent"))
2130 return (void*) vkWsiX11QueuePresent;
Jon Ashburndc899962015-03-02 16:51:38 -07002131#endif
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002132 else {
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002133 if (gpuw->pGPA == NULL)
2134 return NULL;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -06002135 return gpuw->pGPA((VkPhysicalGpu)gpuw->nextObject, funcName);
Tobin Ehlis791a49c2014-11-10 12:29:12 -07002136 }
2137}