blob: a9ef5f42f266c6ca4511adc1b39913188d91194f [file] [log] [blame]
Tobin Ehlis6663f492014-11-10 12:29:12 -07001/*
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05002 * Vulkan
Tobin Ehlis6663f492014-11-10 12:29:12 -07003 *
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05004 * Copyright (C) 2015 LunarG, Inc.
Tobin Ehlis6663f492014-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 Lobodzinskib6ddb462015-03-24 16:29:24 -050017* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Tobin Ehlis6663f492014-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 Lobodzinskie61ebe72015-03-17 10:53:12 -050025#include <inttypes.h>
Tobin Ehlis6663f492014-11-10 12:29:12 -070026#include <stdio.h>
27#include <stdlib.h>
28#include <string.h>
29#include <assert.h>
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -050030#include <list>
Mike Stroyan950496e2015-05-19 15:16:08 -060031#include <unordered_map>
Chia-I Wuf8693382015-04-16 22:02:10 +080032#include <vector>
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -050033using namespace std;
34
Ian Elliott2d4ab1e2015-01-13 17:52:38 -070035#include "loader_platform.h"
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -060036#include "vk_dispatch_table_helper.h"
37#include "vk_struct_string_helper_cpp.h"
Tobin Ehliscd9223b2014-11-19 16:19:28 -070038#include "mem_tracker.h"
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -070039#include "layers_config.h"
Ian Elliott655cad72015-02-12 17:08:34 -070040// The following is #included again to catch certain OS-specific functions
41// being used:
42#include "loader_platform.h"
Jon Ashburn2e672892015-02-16 08:46:53 -070043#include "layers_msg.h"
Tobin Ehlis6663f492014-11-10 12:29:12 -070044
Jon Ashburnbacb0f52015-04-06 10:58:22 -060045static VkLayerDispatchTable nextTable;
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -060046static VkLayerInstanceDispatchTable nextInstanceTable;
Jon Ashburnbacb0f52015-04-06 10:58:22 -060047static VkBaseLayerObject *pCurObj;
Ian Elliott2d4ab1e2015-01-13 17:52:38 -070048static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_initOnce);
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -060049static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_tabDeviceOnce);
50static LOADER_PLATFORM_THREAD_ONCE_DECLARATION(g_tabInstanceOnce);
51
Mark Lobodzinski93f494b2015-03-02 20:23:52 -060052// TODO : This can be much smarter, using separate locks for separate global data
53static int globalLockInitialized = 0;
54static loader_platform_thread_mutex globalLock;
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -070055
Tobin Ehlisc145be82015-01-08 15:22:32 -070056#define MAX_BINDING 0xFFFFFFFF
Tobin Ehlisc145be82015-01-08 15:22:32 -070057
Mike Stroyandd7aed72015-05-19 17:03:40 -060058unordered_map<VkCmdBuffer, MT_CB_INFO> cbMap;
59unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO> memObjMap;
60unordered_map<VkObject, MT_OBJ_INFO> objectMap;
61unordered_map<VkFence, MT_FENCE_INFO> fenceMap; // Map fence to fence info
62unordered_map<VkQueue, MT_QUEUE_INFO> queueMap;
Mike Stroyan950496e2015-05-19 15:16:08 -060063unordered_map<VkSwapChainWSI, MT_SWAP_CHAIN_INFO*> swapChainMap;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -050064
Mark Lobodzinski50932972015-04-02 20:49:09 -050065// TODO : Add per-device fence completion
Mark Lobodzinskib1567a02015-04-21 15:33:04 -060066static uint64_t g_currentFenceId = 1;
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -060067static VkDevice globalDevice = NULL;
Mark Lobodzinskic52b7752015-02-18 16:38:17 -060068
Mark Lobodzinski223ca202015-04-02 08:52:53 -050069// Add new queue for this device to map container
Mark Lobodzinski944aab12015-06-05 13:59:04 -050070static void add_queue_info(const VkQueue queue)
Mark Lobodzinski223ca202015-04-02 08:52:53 -050071{
Mike Stroyandd7aed72015-05-19 17:03:40 -060072 MT_QUEUE_INFO* pInfo = &queueMap[queue];
Mark Lobodzinski50932972015-04-02 20:49:09 -050073 pInfo->lastRetiredId = 0;
74 pInfo->lastSubmittedId = 0;
Mark Lobodzinski223ca202015-04-02 08:52:53 -050075}
76
Mark Lobodzinski944aab12015-06-05 13:59:04 -050077static void delete_queue_info_list(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -060078 void)
Mark Lobodzinski223ca202015-04-02 08:52:53 -050079{
80 // Process queue list, cleaning up each entry before deleting
Mark Lobodzinski223ca202015-04-02 08:52:53 -050081 queueMap.clear();
82}
83
Mark Lobodzinski944aab12015-06-05 13:59:04 -050084static void add_swap_chain_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -060085 const VkSwapChainWSI swapChain)
Chia-I Wuf8693382015-04-16 22:02:10 +080086{
87 MT_SWAP_CHAIN_INFO* pInfo = new MT_SWAP_CHAIN_INFO;
88 swapChainMap[swapChain] = pInfo;
89}
90
Mark Lobodzinski223ca202015-04-02 08:52:53 -050091// Add new CBInfo for this cb to map container
Mark Lobodzinski944aab12015-06-05 13:59:04 -050092static void add_cmd_buf_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -060093 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -070094{
Mike Stroyandd7aed72015-05-19 17:03:40 -060095 cbMap[cb].cmdBuffer = cb;
Tobin Ehlis6663f492014-11-10 12:29:12 -070096}
97
Mark Lobodzinski223ca202015-04-02 08:52:53 -050098// Return ptr to Info in CB map, or NULL if not found
Mark Lobodzinski944aab12015-06-05 13:59:04 -050099static MT_CB_INFO* get_cmd_buf_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600100 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700101{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600102 unordered_map<VkCmdBuffer, MT_CB_INFO>::iterator item = cbMap.find(cb);
Mike Stroyan950496e2015-05-19 15:16:08 -0600103 if (item != cbMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600104 return &(*item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600105 } else {
106 return NULL;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600107 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700108}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600109
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500110// Return object info for 'object' or return NULL if no info exists
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500111static MT_OBJ_INFO* get_object_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600112 const VkObject object)
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500113{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600114 unordered_map<VkObject, MT_OBJ_INFO>::iterator item = objectMap.find(object);
Mike Stroyan950496e2015-05-19 15:16:08 -0600115 if (item != objectMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600116 return &(*item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600117 } else {
118 return NULL;
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500119 }
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500120}
121
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500122static MT_OBJ_INFO* add_object_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600123 VkObject object,
124 VkStructureType sType,
125 const void *pCreateInfo,
126 const int struct_size,
127 const char *name_prefix)
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500128{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600129 MT_OBJ_INFO* pInfo = &objectMap[object];
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500130 memset(pInfo, 0, sizeof(MT_OBJ_INFO));
131 memcpy(&pInfo->create_info, pCreateInfo, struct_size);
132 sprintf(pInfo->object_name, "%s_%p", name_prefix, object);
133
134 pInfo->object = object;
135 pInfo->ref_count = 1;
136 pInfo->sType = sType;
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500137
138 return pInfo;
139}
140
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500141// Add a fence, creating one if necessary to our list of fences/fenceIds
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500142static uint64_t add_fence_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600143 VkFence fence,
144 VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500145{
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500146 // Create fence object
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500147 uint64_t fenceId = g_currentFenceId++;
Mike Stroyan950496e2015-05-19 15:16:08 -0600148 if (fence != NULL) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600149 fenceMap[fence].fenceId = fenceId;
150 fenceMap[fence].queue = queue;
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500151 // Validate that fence is in UNSIGNALED state
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500152 MT_OBJ_INFO* pObjectInfo = get_object_info(fence);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500153 if (pObjectInfo != NULL) {
Tobin Ehlisb870cbb2015-04-15 07:46:12 -0600154 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500155 char str[1024];
156 sprintf(str, "Fence %p submitted in SIGNALED state. Fences must be reset before being submitted", fence);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600157 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_FENCE, fence, 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -0500158 }
159 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700160 }
Mike Stroyan950496e2015-05-19 15:16:08 -0600161 // Update most recently submitted fence and fenceId for Queue
Mike Stroyandd7aed72015-05-19 17:03:40 -0600162 queueMap[queue].lastSubmittedId = fenceId;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500163 return fenceId;
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500164}
165
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500166// Remove a fenceInfo from our list of fences/fenceIds
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500167static void delete_fence_info(
Mike Stroyan950496e2015-05-19 15:16:08 -0600168 VkFence fence)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500169{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600170 fenceMap.erase(fence);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500171}
172
Mike Stroyan950496e2015-05-19 15:16:08 -0600173// Record information when a fence is known to be signalled
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500174static void update_fence_tracking(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600175 VkFence fence)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500176{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600177 unordered_map<VkFence, MT_FENCE_INFO>::iterator fence_item = fenceMap.find(fence);
Mike Stroyan950496e2015-05-19 15:16:08 -0600178 if (fence_item != fenceMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600179 MT_FENCE_INFO *pCurFenceInfo = &(*fence_item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600180 VkQueue queue = pCurFenceInfo->queue;
Mike Stroyandd7aed72015-05-19 17:03:40 -0600181 unordered_map<VkQueue, MT_QUEUE_INFO>::iterator queue_item = queueMap.find(queue);
Mike Stroyan950496e2015-05-19 15:16:08 -0600182 if (queue_item != queueMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600183 MT_QUEUE_INFO *pQueueInfo = &(*queue_item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600184 if (pQueueInfo->lastRetiredId < pCurFenceInfo->fenceId) {
185 pQueueInfo->lastRetiredId = pCurFenceInfo->fenceId;
Mark Lobodzinski148e1582015-04-07 16:07:57 -0500186 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500187 }
188 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500189
Mike Stroyan950496e2015-05-19 15:16:08 -0600190 // Update fence state in fenceCreateInfo structure
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500191 MT_OBJ_INFO* pObjectInfo = get_object_info(fence);
Mike Stroyan950496e2015-05-19 15:16:08 -0600192 if (pObjectInfo != NULL) {
193 pObjectInfo->create_info.fence_create_info.flags =
194 static_cast<VkFenceCreateFlags>(
195 pObjectInfo->create_info.fence_create_info.flags | VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500196 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500197}
198
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500199// Helper routine that updates the fence list for a specific queue to all-retired
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500200static void retire_queue_fences(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600201 VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500202{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600203 MT_QUEUE_INFO *pQueueInfo = &queueMap[queue];
204 // Set queue's lastRetired to lastSubmitted indicating all fences completed
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600205 pQueueInfo->lastRetiredId = pQueueInfo->lastSubmittedId;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700206}
207
Mike Stroyandd7aed72015-05-19 17:03:40 -0600208// Helper routine that updates all queues to all-retired
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500209static void retire_device_fences(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600210 VkDevice device)
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500211{
212 // Process each queue for device
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600213 // TODO: Add multiple device support
Mike Stroyandd7aed72015-05-19 17:03:40 -0600214 for (unordered_map<VkQueue, MT_QUEUE_INFO>::iterator ii=queueMap.begin(); ii!=queueMap.end(); ++ii) {
215 // Set queue's lastRetired to lastSubmitted indicating all fences completed
216 MT_QUEUE_INFO *pQueueInfo = &(*ii).second;
217 pQueueInfo->lastRetiredId = pQueueInfo->lastSubmittedId;
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500218 }
219}
220
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500221// Return ptr to info in map container containing mem, or NULL if not found
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -0700222// Calls to this function should be wrapped in mutex
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500223static MT_MEM_OBJ_INFO* get_mem_obj_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600224 const VkDeviceMemory mem)
Tobin Ehlisc145be82015-01-08 15:22:32 -0700225{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600226 unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO>::iterator item = memObjMap.find(mem);
Mike Stroyan950496e2015-05-19 15:16:08 -0600227 if (item != memObjMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600228 return &(*item).second;
Mike Stroyan950496e2015-05-19 15:16:08 -0600229 } else {
230 return NULL;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600231 }
Tobin Ehlisc145be82015-01-08 15:22:32 -0700232}
233
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500234static void add_mem_obj_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600235 const VkDeviceMemory mem,
236 const VkMemoryAllocInfo *pAllocInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700237{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600238 memObjMap[mem].refCount = 0;
Chia-I Wuf8693382015-04-16 22:02:10 +0800239 if (pAllocInfo) { // MEM alloc created by vkCreateSwapChainWSI() doesn't have alloc info struct
Mike Stroyandd7aed72015-05-19 17:03:40 -0600240 memcpy(&memObjMap[mem].allocInfo, pAllocInfo, sizeof(VkMemoryAllocInfo));
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500241 // TODO: Update for real hardware, actually process allocation info structures
Mike Stroyandd7aed72015-05-19 17:03:40 -0600242 memObjMap[mem].allocInfo.pNext = NULL;
243 } else {
244 memset(&memObjMap[mem].allocInfo, 0, sizeof(VkMemoryAllocInfo));
Tobin Ehlis6663f492014-11-10 12:29:12 -0700245 }
Mike Stroyandd7aed72015-05-19 17:03:40 -0600246 memObjMap[mem].mem = mem;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700247}
248
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500249// Find CB Info and add mem reference to list container
250// Find Mem Obj Info and add CB reference to list container
251static bool32_t update_cmd_buf_and_mem_references(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600252 const VkCmdBuffer cb,
253 const VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700254{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600255 bool32_t result = VK_TRUE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700256 // First update CB binding in MemObj mini CB list
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500257 MT_MEM_OBJ_INFO* pMemInfo = get_mem_obj_info(mem);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500258 if (!pMemInfo) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700259 char str[1024];
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600260 sprintf(str, "Trying to bind mem obj %p to CB %p but no info for that mem obj.\n "
261 "Was it correctly allocated? Did it already get freed?", mem, cb);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600262 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600263 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600264 } else {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500265 // Search for cmd buffer object in memory object's binding list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600266 bool32_t found = VK_FALSE;
David Pinedod8f83d82015-04-27 16:36:17 -0600267 if (pMemInfo->pCmdBufferBindings.size() > 0) {
268 for (list<VkCmdBuffer>::iterator it = pMemInfo->pCmdBufferBindings.begin(); it != pMemInfo->pCmdBufferBindings.end(); ++it) {
269 if ((*it) == cb) {
270 found = VK_TRUE;
271 break;
272 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500273 }
274 }
275 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600276 if (found == VK_FALSE) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500277 pMemInfo->pCmdBufferBindings.push_front(cb);
278 pMemInfo->refCount++;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500279 }
280
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500281 // Now update CBInfo's Mem reference list
282 MT_CB_INFO* pCBInfo = get_cmd_buf_info(cb);
283 // TODO: keep track of all destroyed CBs so we know if this is a stale or simply invalid object
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500284 if (!pCBInfo) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500285 char str[1024];
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500286 sprintf(str, "Trying to bind mem obj %p to CB %p but no info for that CB. Was CB incorrectly destroyed?", mem, cb);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600287 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600288 result = VK_FALSE;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500289 } else {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500290 // Search for memory object in cmd buffer's reference list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600291 bool32_t found = VK_FALSE;
David Pinedod8f83d82015-04-27 16:36:17 -0600292 if (pCBInfo->pMemObjList.size() > 0) {
293 for (list<VkDeviceMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
294 if ((*it) == mem) {
295 found = VK_TRUE;
296 break;
297 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500298 }
299 }
300 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600301 if (found == VK_FALSE) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500302 pCBInfo->pMemObjList.push_front(mem);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600303 }
304 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700305 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600306 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700307}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600308
Tobin Ehlis6663f492014-11-10 12:29:12 -0700309// Clear the CB Binding for mem
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500310// Calls to this function should be wrapped in mutex
311static void remove_cmd_buf_and_mem_reference(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600312 const VkCmdBuffer cb,
313 const VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700314{
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500315 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem);
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500316 // TODO : Having this check is not ideal, really if memInfo was deleted,
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500317 // its CB bindings should be cleared and then clear_cmd_buf_and_mem_references wouldn't call
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -0700318 // us here with stale mem objs
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500319 if (pInfo) {
320 pInfo->pCmdBufferBindings.remove(cb);
321 pInfo->refCount--;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700322 }
323}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600324
Tobin Ehlis6663f492014-11-10 12:29:12 -0700325// Free bindings related to CB
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500326static bool32_t clear_cmd_buf_and_mem_references(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600327 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700328{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600329 bool32_t result = VK_TRUE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500330 MT_CB_INFO* pCBInfo = get_cmd_buf_info(cb);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500331 if (!pCBInfo) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700332 char str[1024];
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500333 sprintf(str, "Unable to find global CB info %p for deletion", cb);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600334 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600335 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600336 } else {
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600337 if (pCBInfo->pMemObjList.size() > 0) {
338 list<VkDeviceMemory> mem_obj_list = pCBInfo->pMemObjList;
339 for (list<VkDeviceMemory>::iterator it=mem_obj_list.begin(); it!=mem_obj_list.end(); ++it) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500340 remove_cmd_buf_and_mem_reference(cb, (*it));
David Pinedod8f83d82015-04-27 16:36:17 -0600341 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600342 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500343 pCBInfo->pMemObjList.clear();
Tobin Ehlis6663f492014-11-10 12:29:12 -0700344 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600345 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700346}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600347
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500348// Delete CBInfo from list along with all of it's mini MemObjInfo
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500349// and also clear mem references to CB
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500350static bool32_t delete_cmd_buf_info(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600351 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700352{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600353 bool32_t result = VK_TRUE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500354 result = clear_cmd_buf_and_mem_references(cb);
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500355 // Delete the CBInfo info
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600356 if (result == VK_TRUE) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600357 cbMap.erase(cb);
Ian Elliott2d4ab1e2015-01-13 17:52:38 -0700358 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600359 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700360}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600361
Tobin Ehlis6663f492014-11-10 12:29:12 -0700362// Delete the entire CB list
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500363static bool32_t delete_cmd_buf_info_list(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600364 void)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700365{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600366 for (unordered_map<VkCmdBuffer, MT_CB_INFO>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500367 clear_cmd_buf_and_mem_references((*ii).first);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700368 }
Mike Stroyandd7aed72015-05-19 17:03:40 -0600369 cbMap.clear();
370 return VK_TRUE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700371}
372
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500373// For given MemObjInfo, report Obj & CB bindings
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600374static void reportMemReferencesAndCleanUp(
375 MT_MEM_OBJ_INFO* pMemObjInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700376{
Tony Barbour18f71552015-04-22 11:36:22 -0600377 size_t cmdBufRefCount = pMemObjInfo->pCmdBufferBindings.size();
378 size_t objRefCount = pMemObjInfo->pObjBindings.size();
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500379
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500380 if ((pMemObjInfo->pCmdBufferBindings.size() + pMemObjInfo->pObjBindings.size()) != 0) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700381 char str[1024];
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600382 sprintf(str, "Attempting to free memory object %p which still contains %lu references",
383 pMemObjInfo->mem, (cmdBufRefCount + objRefCount));
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600384 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, pMemObjInfo->mem, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700385 }
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500386
David Pinedod8f83d82015-04-27 16:36:17 -0600387 if (cmdBufRefCount > 0 && pMemObjInfo->pCmdBufferBindings.size() > 0) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500388 for (list<VkCmdBuffer>::const_iterator it = pMemObjInfo->pCmdBufferBindings.begin(); it != pMemObjInfo->pCmdBufferBindings.end(); ++it) {
389 char str[1024];
390 sprintf(str, "Command Buffer %p still has a reference to mem obj %p", (*it), pMemObjInfo->mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600391 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, (*it), 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500392 }
393 // Clear the list of hanging references
394 pMemObjInfo->pCmdBufferBindings.clear();
395 }
396
David Pinedod8f83d82015-04-27 16:36:17 -0600397 if (objRefCount > 0 && pMemObjInfo->pObjBindings.size() > 0) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500398 for (list<VkObject>::const_iterator it = pMemObjInfo->pObjBindings.begin(); it != pMemObjInfo->pObjBindings.end(); ++it) {
399 char str[1024];
400 sprintf(str, "VK Object %p still has a reference to mem obj %p", (*it), pMemObjInfo->mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600401 /* TODO: Would be nice to return the actual object type */
402 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, (*it), 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500403 }
404 // Clear the list of hanging references
405 pMemObjInfo->pObjBindings.clear();
406 }
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500407
Tobin Ehlis6663f492014-11-10 12:29:12 -0700408}
409
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600410static void deleteMemObjInfo(
411 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700412{
Mike Stroyandd7aed72015-05-19 17:03:40 -0600413 unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO>::iterator item = memObjMap.find(mem);
Mike Stroyan950496e2015-05-19 15:16:08 -0600414 if (item != memObjMap.end()) {
Mike Stroyan950496e2015-05-19 15:16:08 -0600415 memObjMap.erase(item);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700416 }
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500417 else {
418 char str[1024];
419 sprintf(str, "Request to delete memory object %p not present in memory Object Map", mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600420 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500421 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700422}
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -0500423
Tobin Ehlis6663f492014-11-10 12:29:12 -0700424// Check if fence for given CB is completed
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600425static bool32_t checkCBCompleted(
426 const VkCmdBuffer cb)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700427{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600428 bool32_t result = VK_TRUE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500429 MT_CB_INFO* pCBInfo = get_cmd_buf_info(cb);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500430 if (!pCBInfo) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700431 char str[1024];
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500432 sprintf(str, "Unable to find global CB info %p to check for completion", cb);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600433 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_INVALID_CB, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600434 result = VK_FALSE;
Mike Stroyan950496e2015-05-19 15:16:08 -0600435 } else if (pCBInfo->lastSubmittedQueue != NULL) {
436 VkQueue queue = pCBInfo->lastSubmittedQueue;
Mike Stroyandd7aed72015-05-19 17:03:40 -0600437 MT_QUEUE_INFO *pQueueInfo = &queueMap[queue];
Mike Stroyan950496e2015-05-19 15:16:08 -0600438 if (pCBInfo->fenceId > pQueueInfo->lastRetiredId) {
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600439 char str[1024];
Mike Stroyan950496e2015-05-19 15:16:08 -0600440 sprintf(str, "fence %p for CB %p has not been checked for completion",
441 (void*)pCBInfo->lastSubmittedFence, cb);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600442 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cb, 0, MEMTRACK_NONE, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600443 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600444 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700445 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600446 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700447}
448
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600449static bool32_t freeMemObjInfo(
450 VkDeviceMemory mem,
451 bool internal)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700452{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600453 bool32_t result = VK_TRUE;
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500454 // Parse global list to find info w/ mem
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500455 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500456 if (!pInfo) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700457 char str[1024];
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600458 sprintf(str, "Couldn't find mem info object for %p\n Was %p never allocated or previously freed?",
459 (void*)mem, (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600460 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600461 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600462 } else {
Courtney Goeltzenleuchter1c943a72015-03-26 16:15:39 -0600463 if (pInfo->allocInfo.allocationSize == 0 && !internal) {
Mark Lobodzinski2f3b19b2015-02-18 18:06:24 -0600464 char str[1024];
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600465 sprintf(str, "Attempting to free memory associated with a Persistent Image, %p, "
466 "this should not be explicitly freed\n", (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600467 layerCbMsg(VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600468 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600469 } else {
470 // Clear any CB bindings for completed CBs
471 // TODO : Is there a better place to do this?
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500472
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600473 list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin();
474 list<VkCmdBuffer>::iterator temp;
David Pinedod8f83d82015-04-27 16:36:17 -0600475 while (pInfo->pCmdBufferBindings.size() > 0 && it != pInfo->pCmdBufferBindings.end()) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600476 if (VK_TRUE == checkCBCompleted(*it)) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500477 temp = it;
478 ++temp;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500479 clear_cmd_buf_and_mem_references(*it);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500480 it = temp;
481 } else {
482 ++it;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600483 }
484 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500485
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600486 // Now verify that no references to this mem obj remain
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500487 if (0 != pInfo->refCount) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500488 reportMemReferencesAndCleanUp(pInfo);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600489 result = VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600490 }
Courtney Goeltzenleuchter2f3f8a22015-04-14 00:01:21 -0600491 // Delete mem obj info
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500492 deleteMemObjInfo(mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700493 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700494 }
495 return result;
496}
497
Tobin Ehlis6663f492014-11-10 12:29:12 -0700498// Remove object binding performs 3 tasks:
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500499// 1. Remove ObjectInfo from MemObjInfo list container of obj bindings & free it
500// 2. Decrement refCount for MemObjInfo
501// 3. Clear MemObjInfo ptr from ObjectInfo
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500502static bool32_t clear_object_binding(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600503 VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700504{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600505 bool32_t result = VK_FALSE;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500506 MT_OBJ_INFO* pObjInfo = get_object_info(object);
507 if (pObjInfo) {
David Pinedod8f83d82015-04-27 16:36:17 -0600508 if (!pObjInfo->pMemObjInfo || pObjInfo->pMemObjInfo->pObjBindings.size() <= 0) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600509 char str[1024];
510 sprintf(str, "Attempting to clear mem binding on obj %p but it has no binding.", (void*)object);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600511 layerCbMsg(VK_DBG_REPORT_WARN_BIT, (VkObjectType) 0, object, 0, MEMTRACK_MEM_OBJ_CLEAR_EMPTY_BINDINGS, "MEM", str);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600512 } else {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500513 // This obj is bound to a memory object. Remove the reference to this object in that memory object's list, decrement the memObj's refcount
514 // and set the objects memory binding pointer to NULL.
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600515 for (list<VkObject>::iterator it = pObjInfo->pMemObjInfo->pObjBindings.begin(); it != pObjInfo->pMemObjInfo->pObjBindings.end(); ++it) {
Mark Lobodzinski40f7f402015-04-16 11:44:05 -0500516 if ((*it) == object) {
517 pObjInfo->pMemObjInfo->refCount--;
518 pObjInfo->pMemObjInfo->pObjBindings.erase(it);
519 pObjInfo->pMemObjInfo = NULL;
520 result = VK_TRUE;
521 break;
522 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600523 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600524 if (result == VK_FALSE) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600525 char str[1024];
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500526 sprintf(str, "While trying to clear mem binding for object %p, unable to find that object referenced by mem obj %p",
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500527 object, pObjInfo->pMemObjInfo->mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600528 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600529 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700530 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700531 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600532 return result;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700533}
534
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500535// For NULL mem case, output warning
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500536// Make sure given object is in global object map
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500537// IF a previous binding existed, output validation error
538// Otherwise, add reference from objectInfo to memoryInfo
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500539// Add reference off of objInfo
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600540// Return VK_TRUE if addition is successful, VK_FALSE otherwise
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500541static bool32_t set_object_binding(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600542 VkObject object,
543 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700544{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600545 bool32_t result = VK_FALSE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700546 // Handle NULL case separately, just clear previous binding & decrement reference
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600547 if (mem == VK_NULL_HANDLE) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500548 char str[1024];
549 sprintf(str, "Attempting to Bind Obj(%p) to NULL", (void*)object);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600550 layerCbMsg(VK_DBG_REPORT_WARN_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500551 return VK_TRUE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600552 } else {
553 char str[1024];
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500554 MT_OBJ_INFO* pObjInfo = get_object_info(object);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500555 if (!pObjInfo) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600556 sprintf(str, "Attempting to update Binding of Obj(%p) that's not in global list()", (void*)object);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600557 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600558 return VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600559 }
560 // non-null case so should have real mem obj
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500561 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem);
562 if (!pInfo) {
563 sprintf(str, "While trying to bind mem for obj %p, couldn't find info for mem obj %p", (void*)object, (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600564 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500565 return VK_FALSE;
566 } else {
567 if (pObjInfo->pMemObjInfo != NULL) {
568 sprintf(str, "Attempting to bind memory (%p) to object (%p) which has already been bound to mem object %p",
569 (void*)mem, (void*)object, (void*)pObjInfo->pMemObjInfo->mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600570 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_REBIND_OBJECT, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500571 return VK_FALSE;
572 }
573 else {
574 pInfo->pObjBindings.push_front(object);
575 pInfo->refCount++;
576
577 // For image objects, make sure default memory state is correctly set
578 // TODO : What's the best/correct way to handle this?
579 if (VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO == pObjInfo->sType) {
580 if (pObjInfo->create_info.image_create_info.usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
581 VK_IMAGE_USAGE_DEPTH_STENCIL_BIT)) {
582 // TODO:: More memory state transition stuff.
583 }
584 }
585 pObjInfo->pMemObjInfo = pInfo;
586 }
587 }
588 }
589 return VK_TRUE;
590}
591
592// For NULL mem case, clear any previous binding Else...
593// Make sure given object is in global object map
594// IF a previous binding existed, update binding
595// Add reference from objectInfo to memoryInfo
596// Add reference off of objInfo
597// Return VK_TRUE if addition is successful, VK_FALSE otherwise
598static bool32_t set_sparse_buffer_binding(
599 VkObject object,
600 VkDeviceMemory mem)
601{
602 bool32_t result = VK_FALSE;
603 // Handle NULL case separately, just clear previous binding & decrement reference
604 if (mem == VK_NULL_HANDLE) {
605 clear_object_binding(object);
606 return VK_TRUE;
607 } else {
608 char str[1024];
609 MT_OBJ_INFO* pObjInfo = get_object_info(object);
610 if (!pObjInfo) {
611 sprintf(str, "Attempting to update Binding of Obj(%p) that's not in global list()", (void*)object);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600612 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500613 return VK_FALSE;
614 }
615 // non-null case so should have real mem obj
616 MT_MEM_OBJ_INFO* pInfo = get_mem_obj_info(mem);
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600617 if (!pInfo) {
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500618 sprintf(str, "While trying to bind mem for obj %p, couldn't find info for mem obj %p", (void*)object, (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600619 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_MEM_OBJ, "MEM", str);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500620 return VK_FALSE;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600621 } else {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500622 // Search for object in memory object's binding list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600623 bool32_t found = VK_FALSE;
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600624 if (pInfo->pObjBindings.size() > 0) {
625 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
626 if ((*it) == object) {
627 found = VK_TRUE;
628 break;
629 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600630 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600631 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500632 // If not present, add to list
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600633 if (found == VK_FALSE) {
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500634 pInfo->pObjBindings.push_front(object);
635 pInfo->refCount++;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500636 }
637
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500638 if (pObjInfo->pMemObjInfo) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500639 clear_object_binding(object); // Need to clear the previous object binding before setting new binding
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500640 sprintf(str, "Updating memory binding for object %p from mem obj %p to %p", object, pObjInfo->pMemObjInfo->mem, mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600641 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, object, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500642 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500643 pObjInfo->pMemObjInfo = pInfo;
Tobin Ehlis8be20fd2015-01-07 17:49:29 -0700644 }
645 }
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600646 return VK_TRUE;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700647}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600648
Tobin Ehlis6663f492014-11-10 12:29:12 -0700649// Print details of global Obj tracking list
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500650static void print_object_list(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600651 void)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700652{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500653 MT_OBJ_INFO* pInfo = NULL;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500654 char str[1024];
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500655 sprintf(str, "Details of Object list of size %lu elements", objectMap.size());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600656 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
David Pinedod8f83d82015-04-27 16:36:17 -0600657 if (objectMap.size() <= 0)
658 return;
Mike Stroyandd7aed72015-05-19 17:03:40 -0600659 for (unordered_map<VkObject, MT_OBJ_INFO>::iterator ii=objectMap.begin(); ii!=objectMap.end(); ++ii) {
660 pInfo = &(*ii).second;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500661 sprintf(str, " ObjInfo %p has object %p, pMemObjInfo %p", pInfo, pInfo->object, pInfo->pMemObjInfo);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600662 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, pInfo->object, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700663 }
664}
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600665
Tobin Ehlis6663f492014-11-10 12:29:12 -0700666// For given Object, get 'mem' obj that it's bound to or NULL if no binding
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500667static VkDeviceMemory get_mem_binding_from_object(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600668 const VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700669{
Tony Barbourd1c35722015-04-16 15:59:00 -0600670 VkDeviceMemory mem = NULL;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500671 MT_OBJ_INFO* pObjInfo = get_object_info(object);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500672 if (pObjInfo) {
673 if (pObjInfo->pMemObjInfo) {
674 mem = pObjInfo->pMemObjInfo->mem;
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600675 } else {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700676 char str[1024];
677 sprintf(str, "Trying to get mem binding for object %p but object has no mem binding", (void*)object);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600678 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_MISSING_MEM_BINDINGS, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500679 print_object_list();
Tobin Ehlis6663f492014-11-10 12:29:12 -0700680 }
Courtney Goeltzenleuchtere4171f02015-04-29 10:51:48 -0600681 } else {
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700682 char str[1024];
683 sprintf(str, "Trying to get mem binding for object %p but no such object in global list", (void*)object);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600684 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, object, 0, MEMTRACK_INVALID_OBJECT, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500685 print_object_list();
Tobin Ehlis6663f492014-11-10 12:29:12 -0700686 }
687 return mem;
688}
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500689
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500690// Print details of MemObjInfo list
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500691static void print_mem_list(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600692 void)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700693{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500694 MT_MEM_OBJ_INFO* pInfo = NULL;
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700695 // Just printing each msg individually for now, may want to package these into single large print
696 char str[1024];
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500697 sprintf(str, "MEM INFO : Details of Memory Object list of size %lu elements", memObjMap.size());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600698 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500699
David Pinedod8f83d82015-04-27 16:36:17 -0600700 if (memObjMap.size() <= 0)
701 return;
702
Mike Stroyandd7aed72015-05-19 17:03:40 -0600703 for (unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
704 pInfo = &(*ii).second;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500705
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500706 sprintf(str, " ===MemObjInfo at %p===", (void*)pInfo);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600707 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500708 sprintf(str, " Mem object: %p", (void*)pInfo->mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600709 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500710 sprintf(str, " Ref Count: %u", pInfo->refCount);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600711 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500712 if (0 != pInfo->allocInfo.allocationSize) {
Courtney Goeltzenleuchter95487bc2015-04-14 18:48:46 -0600713 string pAllocInfoMsg = vk_print_vkmemoryallocinfo(&pInfo->allocInfo, "{MEM}INFO : ");
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500714 sprintf(str, " Mem Alloc info:\n%s", pAllocInfoMsg.c_str());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600715 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500716 } else {
Chia-I Wuf8693382015-04-16 22:02:10 +0800717 sprintf(str, " Mem Alloc info is NULL (alloc done by vkCreateSwapChainWSI())");
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600718 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500719 }
720
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600721 sprintf(str, " VK OBJECT Binding list of size %lu elements:", pInfo->pObjBindings.size());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600722 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
David Pinedod8f83d82015-04-27 16:36:17 -0600723 if (pInfo->pObjBindings.size() > 0) {
724 for (list<VkObject>::iterator it = pInfo->pObjBindings.begin(); it != pInfo->pObjBindings.end(); ++it) {
725 sprintf(str, " VK OBJECT %p", (*it));
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600726 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
David Pinedod8f83d82015-04-27 16:36:17 -0600727 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500728 }
729
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600730 sprintf(str, " VK Command Buffer (CB) binding list of size %lu elements", pInfo->pCmdBufferBindings.size());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600731 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
David Pinedod8f83d82015-04-27 16:36:17 -0600732 if (pInfo->pCmdBufferBindings.size() > 0)
733 {
734 for (list<VkCmdBuffer>::iterator it = pInfo->pCmdBufferBindings.begin(); it != pInfo->pCmdBufferBindings.end(); ++it) {
735 sprintf(str, " VK CB %p", (*it));
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600736 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
David Pinedod8f83d82015-04-27 16:36:17 -0600737 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700738 }
739 }
740}
741
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600742static void printCBList(
743 void)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700744{
Mike Stroyan950496e2015-05-19 15:16:08 -0600745 char str[1024];
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500746 MT_CB_INFO* pCBInfo = NULL;
747 sprintf(str, "Details of CB list of size %lu elements", cbMap.size());
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600748 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500749
David Pinedod8f83d82015-04-27 16:36:17 -0600750 if (cbMap.size() <= 0)
751 return;
752
Mike Stroyandd7aed72015-05-19 17:03:40 -0600753 for (unordered_map<VkCmdBuffer, MT_CB_INFO>::iterator ii=cbMap.begin(); ii!=cbMap.end(); ++ii) {
754 pCBInfo = &(*ii).second;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500755
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500756 sprintf(str, " CB Info (%p) has CB %p, fenceId %" PRIx64", and fence %p",
757 (void*)pCBInfo, (void*)pCBInfo->cmdBuffer, pCBInfo->fenceId,
Mike Stroyan950496e2015-05-19 15:16:08 -0600758 (void*)pCBInfo->lastSubmittedFence);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600759 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500760
David Pinedod8f83d82015-04-27 16:36:17 -0600761 if (pCBInfo->pMemObjList.size() <= 0)
762 continue;
Tony Barbourd1c35722015-04-16 15:59:00 -0600763 for (list<VkDeviceMemory>::iterator it = pCBInfo->pMemObjList.begin(); it != pCBInfo->pMemObjList.end(); ++it) {
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500764 sprintf(str, " Mem obj %p", (*it));
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600765 layerCbMsg(VK_DBG_REPORT_INFO_BIT, (VkObjectType) 0, NULL, 0, MEMTRACK_NONE, "MEM", str);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700766 }
767 }
768}
769
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -0600770// TODO handle multiple GPUs/instances for both instance and device dispatch tables
771static void initDeviceTable(void)
772{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600773 PFN_vkGetDeviceProcAddr fpNextGPA;
774 fpNextGPA = (PFN_vkGetDeviceProcAddr) pCurObj->pGPA;
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -0600775 assert(fpNextGPA);
Jon Ashburn8d1b0b52015-05-18 13:20:15 -0600776 layer_initialize_dispatch_table(&nextTable, fpNextGPA, (VkDevice) pCurObj->nextObject);
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -0600777}
778
779static void initInstanceTable(void)
780{
781 PFN_vkGetInstanceProcAddr fpNextGPA;
782 fpNextGPA = (PFN_vkGetInstanceProcAddr) pCurObj->pGPA;
783 assert(fpNextGPA);
784 layer_init_instance_dispatch_table(&nextInstanceTable, fpNextGPA, (VkInstance) pCurObj->nextObject);
785}
786
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600787static void initMemTracker(
788 void)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700789{
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700790 const char *strOpt;
791 // initialize MemTracker options
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600792 getLayerOptionEnum("MemTrackerReportLevel", (uint32_t *) &g_reportFlags);
Ian Elliotte7826712015-03-06 13:50:05 -0700793 g_actionIsDefault = getLayerOptionEnum("MemTrackerDebugAction", (uint32_t *) &g_debugAction);
Tobin Ehlisee702232015-01-08 14:26:53 -0700794
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600795 if (g_debugAction & VK_DBG_LAYER_ACTION_LOG_MSG)
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700796 {
797 strOpt = getLayerOption("MemTrackerLogFilename");
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600798 if (strOpt) {
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700799 g_logFile = fopen(strOpt, "w");
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700800 }
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600801 if (g_logFile == NULL) {
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700802 g_logFile = stdout;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600803 }
Jon Ashburn7d7b3cf2014-12-22 13:24:15 -0700804 }
805
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600806 if (!globalLockInitialized)
807 {
808 // TODO/TBD: Need to delete this mutex sometime. How??? One
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600809 // suggestion is to call this during vkCreateInstance(), and then we
810 // can clean it up during vkDestroyInstance(). However, that requires
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600811 // that the layer have per-instance locks. We need to come back and
812 // address this soon.
813 loader_platform_thread_create_mutex(&globalLock);
814 globalLockInitialized = 1;
815 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700816}
817
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600818//VkResult VKAPI vkCreateInstance(
819// const VkInstanceCreateInfo* pCreateInfo,
820// VkInstance* pInstance)
821//{
822// loader_platform_thread_once(&g_initOnce, initMemTracker);
823// VkResult result = nextTable.CreateInstance(pCreateInfo, pInstance);
824// if (result == VK_SUCCESS) {
825// enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->ppEnabledExtensionNames);
826// }
827// return result;
828//}
829
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600830VK_LAYER_EXPORT VkResult VKAPI vkCreateDevice(
831 VkPhysicalDevice gpu,
832 const VkDeviceCreateInfo *pCreateInfo,
833 VkDevice *pDevice)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700834{
Jon Ashburn95a77ba2015-05-15 15:09:35 -0600835 VkResult result = nextInstanceTable.CreateDevice(gpu, pCreateInfo, pDevice);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600836 if (result == VK_SUCCESS) {
837 // Save off device in case we need it to create Fences
838 globalDevice = *pDevice;
839
840 enable_debug_report(pCreateInfo->extensionCount, pCreateInfo->pEnabledExtensions);
841 }
Tobin Ehlis6663f492014-11-10 12:29:12 -0700842 return result;
843}
844
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600845VK_LAYER_EXPORT VkResult VKAPI vkDestroyDevice(
846 VkDevice device)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700847{
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700848 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600849 sprintf(str, "Printing List details prior to vkDestroyDevice()");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600850 loader_platform_thread_lock_mutex(&globalLock);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600851 layerCbMsg(VK_DBG_REPORT_INFO_BIT, VK_OBJECT_TYPE_DEVICE, device, 0, MEMTRACK_NONE, "MEM", str);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500852 print_mem_list();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500853 printCBList();
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500854 print_object_list();
855 if (VK_FALSE == delete_cmd_buf_info_list()) {
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600856 sprintf(str, "Issue deleting global CB list in vkDestroyDevice()");
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600857 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE, device, 0, MEMTRACK_INTERNAL_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -0700858 }
Tobin Ehlisb54ef782014-11-25 18:01:12 -0700859 // Report any memory leaks
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500860 MT_MEM_OBJ_INFO* pInfo = NULL;
David Pinedod8f83d82015-04-27 16:36:17 -0600861 if (memObjMap.size() > 0) {
Mike Stroyandd7aed72015-05-19 17:03:40 -0600862 for (unordered_map<VkDeviceMemory, MT_MEM_OBJ_INFO>::iterator ii=memObjMap.begin(); ii!=memObjMap.end(); ++ii) {
863 pInfo = &(*ii).second;
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -0500864
David Pinedod8f83d82015-04-27 16:36:17 -0600865 if (pInfo->allocInfo.allocationSize != 0) {
866 sprintf(str, "Mem Object %p has not been freed. You should clean up this memory by calling "
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600867 "vkFreeMemory(%p) prior to vkDestroyDevice().", pInfo->mem, pInfo->mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600868 layerCbMsg(VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, pInfo->mem, 0, MEMTRACK_MEMORY_LEAK, "MEM", str);
David Pinedod8f83d82015-04-27 16:36:17 -0600869 }
Mark Lobodzinski2f3b19b2015-02-18 18:06:24 -0600870 }
Tobin Ehlisb54ef782014-11-25 18:01:12 -0700871 }
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500872
873 // Queues persist until device is destroyed
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500874 delete_queue_info_list();
Mark Lobodzinski223ca202015-04-02 08:52:53 -0500875
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600876 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600877 VkResult result = nextTable.DestroyDevice(device);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700878 return result;
879}
880
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600881struct extProps {
882 uint32_t version;
883 const char * const name;
884};
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600885#define MEM_TRACKER_LAYER_EXT_ARRAY_SIZE 1
886static const VkExtensionProperties mtExts[MEM_TRACKER_LAYER_EXT_ARRAY_SIZE] = {
887 {
888 VK_STRUCTURE_TYPE_EXTENSION_PROPERTIES,
889 "MemTracker",
890 0x10,
891 "Sample layer: MemTracker",
892 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600893};
894
895VK_LAYER_EXPORT VkResult VKAPI vkGetGlobalExtensionInfo(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600896 VkExtensionInfoType infoType,
897 uint32_t extensionIndex,
898 size_t *pDataSize,
899 void *pData)
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600900{
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500901 // This entrypoint is NOT going to init its own dispatch table since loader calls here early
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600902 uint32_t *count;
903
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600904 if (pDataSize == NULL) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600905 return VK_ERROR_INVALID_POINTER;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600906 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600907
908 switch (infoType) {
909 case VK_EXTENSION_INFO_TYPE_COUNT:
910 *pDataSize = sizeof(uint32_t);
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600911 if (pData == NULL) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600912 return VK_SUCCESS;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600913 }
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600914 count = (uint32_t *) pData;
915 *count = MEM_TRACKER_LAYER_EXT_ARRAY_SIZE;
916 break;
917 case VK_EXTENSION_INFO_TYPE_PROPERTIES:
918 *pDataSize = sizeof(VkExtensionProperties);
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600919 if (pData == NULL) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600920 return VK_SUCCESS;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600921 }
922 if (extensionIndex >= MEM_TRACKER_LAYER_EXT_ARRAY_SIZE) {
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600923 return VK_ERROR_INVALID_VALUE;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600924 }
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -0600925 memcpy((VkExtensionProperties *) pData, &mtExts[extensionIndex], sizeof(VkExtensionProperties));
Jon Ashburn9fd4cc42015-04-10 14:33:07 -0600926 break;
927 default:
928 return VK_ERROR_INVALID_VALUE;
929 };
930
931 return VK_SUCCESS;
932}
933
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600934VK_LAYER_EXPORT VkResult VKAPI vkGetDeviceQueue(
935 VkDevice device,
936 uint32_t queueNodeIndex,
937 uint32_t queueIndex,
938 VkQueue *pQueue)
Mark Lobodzinski748eddf2015-03-31 16:05:35 -0500939{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600940 VkResult result = nextTable.GetDeviceQueue(device, queueNodeIndex, queueIndex, pQueue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600941 if (result == VK_SUCCESS) {
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500942 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500943 add_queue_info(*pQueue);
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500944 loader_platform_thread_unlock_mutex(&globalLock);
945 }
Mark Lobodzinski748eddf2015-03-31 16:05:35 -0500946 return result;
947}
948
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600949VK_LAYER_EXPORT VkResult VKAPI vkQueueSubmit(
950 VkQueue queue,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600951 uint32_t cmdBufferCount,
952 const VkCmdBuffer *pCmdBuffers,
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600953 VkFence fence)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700954{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600955 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700956 // TODO : Need to track fence and clear mem references when fence clears
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500957 MT_CB_INFO* pCBInfo = NULL;
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500958 uint64_t fenceId = add_fence_info(fence, queue);
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500959
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500960 print_mem_list();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500961 printCBList();
Tobin Ehlis6663f492014-11-10 12:29:12 -0700962 for (uint32_t i = 0; i < cmdBufferCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500963 pCBInfo = get_cmd_buf_info(pCmdBuffers[i]);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -0500964 pCBInfo->fenceId = fenceId;
Mike Stroyan950496e2015-05-19 15:16:08 -0600965 pCBInfo->lastSubmittedFence = fence;
966 pCBInfo->lastSubmittedQueue = queue;
Tobin Ehlis6663f492014-11-10 12:29:12 -0700967 }
Mark Lobodzinskied450b02015-04-07 13:38:21 -0500968
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600969 loader_platform_thread_unlock_mutex(&globalLock);
Mike Stroyanf7a43bd2015-05-18 16:31:44 -0600970 VkResult result = nextTable.QueueSubmit(queue, cmdBufferCount, pCmdBuffers, fence);
Courtney Goeltzenleuchterd3fb9552015-04-02 13:39:07 -0600971 return result;
972}
973
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600974VK_LAYER_EXPORT VkResult VKAPI vkAllocMemory(
975 VkDevice device,
976 const VkMemoryAllocInfo *pAllocInfo,
977 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700978{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -0600979 VkResult result = nextTable.AllocMemory(device, pAllocInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700980 // TODO : Track allocations and overall size here
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600981 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500982 add_mem_obj_info(*pMem, pAllocInfo);
983 print_mem_list();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600984 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -0700985 return result;
986}
987
Mark Lobodzinskib1567a02015-04-21 15:33:04 -0600988VK_LAYER_EXPORT VkResult VKAPI vkFreeMemory(
989 VkDevice device,
990 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -0700991{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -0600992 /* From spec : A memory object is freed by calling vkFreeMemory() when it is no longer needed. Before
Tobin Ehlisc0418f92014-11-25 14:47:20 -0700993 * freeing a memory object, an application must ensure the memory object is unbound from
994 * all API objects referencing it and that it is not referenced by any queued command buffers
995 */
Mark Lobodzinski93f494b2015-03-02 20:23:52 -0600996 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski3780e142015-05-14 15:08:13 -0500997 bool32_t noerror = freeMemObjInfo(mem, false);
Mark Lobodzinski944aab12015-06-05 13:59:04 -0500998 print_mem_list();
999 print_object_list();
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001000 printCBList();
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001001 // Output an warning message for proper error/warning handling
1002 if (noerror == VK_FALSE) {
1003 char str[1024];
1004 sprintf(str, "Freeing memory object while it still has references: mem obj %p", (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001005 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_DESTROY_OBJECT_ERROR, "MEM", str);
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001006 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001007 loader_platform_thread_unlock_mutex(&globalLock);
Mike Stroyanb050c682015-04-17 12:36:38 -06001008 VkResult result = nextTable.FreeMemory(device, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001009 return result;
1010}
1011
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001012VK_LAYER_EXPORT VkResult VKAPI vkSetMemoryPriority(
1013 VkDevice device,
1014 VkDeviceMemory mem,
1015 VkMemoryPriority priority)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001016{
1017 // TODO : Update tracking for this alloc
1018 // Make sure memory is not pinned, which can't have priority set
Mike Stroyanb050c682015-04-17 12:36:38 -06001019 VkResult result = nextTable.SetMemoryPriority(device, mem, priority);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001020 return result;
1021}
1022
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001023VK_LAYER_EXPORT VkResult VKAPI vkMapMemory(
1024 VkDevice device,
1025 VkDeviceMemory mem,
1026 VkDeviceSize offset,
1027 VkDeviceSize size,
1028 VkFlags flags,
1029 void **ppData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001030{
1031 // TODO : Track when memory is mapped
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001032 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001033 MT_MEM_OBJ_INFO *pMemObj = get_mem_obj_info(mem);
Tony Barbourd1c35722015-04-16 15:59:00 -06001034 if ((pMemObj->allocInfo.memProps & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT) == 0) {
Mark Lobodzinski95152dc2015-02-25 12:16:04 -06001035 char str[1024];
Mark Lobodzinski3780e142015-05-14 15:08:13 -05001036 sprintf(str, "Mapping Memory without VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT set: mem obj %p", (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001037 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_DEVICE_MEMORY, mem, 0, MEMTRACK_INVALID_STATE, "MEM", str);
Mark Lobodzinski95152dc2015-02-25 12:16:04 -06001038 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001039 loader_platform_thread_unlock_mutex(&globalLock);
Mike Stroyanb050c682015-04-17 12:36:38 -06001040 VkResult result = nextTable.MapMemory(device, mem, offset, size, flags, ppData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001041 return result;
1042}
1043
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001044VK_LAYER_EXPORT VkResult VKAPI vkUnmapMemory(
1045 VkDevice device,
1046 VkDeviceMemory mem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001047{
1048 // TODO : Track as memory gets unmapped, do we want to check what changed following map?
1049 // Make sure that memory was ever mapped to begin with
Mike Stroyanb050c682015-04-17 12:36:38 -06001050 VkResult result = nextTable.UnmapMemory(device, mem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001051 return result;
1052}
1053
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001054VK_LAYER_EXPORT VkResult VKAPI vkPinSystemMemory(
1055 VkDevice device,
1056 const void *pSysMem,
1057 size_t memSize,
1058 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001059{
1060 // TODO : Track this
1061 // Verify that memory is actually pinnable
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001062 VkResult result = nextTable.PinSystemMemory(device, pSysMem, memSize, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001063 return result;
1064}
1065
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001066VK_LAYER_EXPORT VkResult VKAPI vkOpenSharedMemory(
1067 VkDevice device,
1068 const VkMemoryOpenInfo *pOpenInfo,
1069 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001070{
1071 // TODO : Track this
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001072 VkResult result = nextTable.OpenSharedMemory(device, pOpenInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001073 return result;
1074}
1075
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001076VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerMemory(
1077 VkDevice device,
1078 const VkPeerMemoryOpenInfo *pOpenInfo,
1079 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001080{
1081 // TODO : Track this
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001082 VkResult result = nextTable.OpenPeerMemory(device, pOpenInfo, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001083 return result;
1084}
1085
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001086VK_LAYER_EXPORT VkResult VKAPI vkOpenPeerImage(
1087 VkDevice device,
1088 const VkPeerImageOpenInfo *pOpenInfo,
1089 VkImage *pImage,
1090 VkDeviceMemory *pMem)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001091{
1092 // TODO : Track this
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001093 VkResult result = nextTable.OpenPeerImage(device, pOpenInfo, pImage, pMem);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001094 return result;
1095}
1096
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001097VK_LAYER_EXPORT VkResult VKAPI vkDestroyObject(
1098 VkDevice device,
1099 VkObjectType objType,
1100 VkObject object)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001101{
Mike Stroyandd7aed72015-05-19 17:03:40 -06001102 unordered_map<VkObject, MT_OBJ_INFO>::iterator item;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001103 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001104
Mike Stroyan950496e2015-05-19 15:16:08 -06001105 // First check if this is a CmdBuffer or fence
1106 switch (objType) {
1107 case VK_OBJECT_TYPE_COMMAND_BUFFER:
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001108 delete_cmd_buf_info((VkCmdBuffer)object);
Mike Stroyan950496e2015-05-19 15:16:08 -06001109 break;
1110 case VK_OBJECT_TYPE_FENCE:
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001111 delete_fence_info((VkFence)object);
Mike Stroyan950496e2015-05-19 15:16:08 -06001112 break;
1113 default:
1114 break;
Tobin Ehlisa98df732014-11-27 07:52:04 -07001115 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001116
Mike Stroyan950496e2015-05-19 15:16:08 -06001117 if ((item = objectMap.find(object)) != objectMap.end()) {
Mike Stroyandd7aed72015-05-19 17:03:40 -06001118 MT_OBJ_INFO* pDelInfo = &(*item).second;
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001119 if (pDelInfo->pMemObjInfo) {
Tobin Ehlisa98df732014-11-27 07:52:04 -07001120 // Wsi allocated Memory is tied to image object so clear the binding and free that memory automatically
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001121 if (0 == pDelInfo->pMemObjInfo->allocInfo.allocationSize) { // Wsi allocated memory has NULL allocInfo w/ 0 size
Tony Barbourd1c35722015-04-16 15:59:00 -06001122 VkDeviceMemory memToFree = pDelInfo->pMemObjInfo->mem;
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001123 clear_object_binding(object);
Courtney Goeltzenleuchter1c943a72015-03-26 16:15:39 -06001124 freeMemObjInfo(memToFree, true);
1125 }
1126 else {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001127 // Remove this object from memory object's reference list and decrement its ref counter
1128 clear_object_binding(object);
Tobin Ehlisa98df732014-11-27 07:52:04 -07001129 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001130 }
Mike Stroyan950496e2015-05-19 15:16:08 -06001131 objectMap.erase(item);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001132 }
Mark Lobodzinskib6ddb462015-03-24 16:29:24 -05001133
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001134 loader_platform_thread_unlock_mutex(&globalLock);
Mike Stroyanb050c682015-04-17 12:36:38 -06001135 VkResult result = nextTable.DestroyObject(device, objType, object);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001136 return result;
1137}
1138
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001139VK_LAYER_EXPORT VkResult VKAPI vkGetObjectInfo(
1140 VkDevice device,
1141 VkObjectType objType,
1142 VkObject object,
1143 VkObjectInfoType infoType,
1144 size_t *pDataSize,
1145 void *pData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001146{
1147 // TODO : What to track here?
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001148 // Could potentially save returned mem requirements and validate values passed into BindObjectMemory for this object
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001149 // From spec : The only objects that are guaranteed to have no external memory requirements are devices, queues,
1150 // command buffers, shaders and memory objects.
Mike Stroyanb050c682015-04-17 12:36:38 -06001151 VkResult result = nextTable.GetObjectInfo(device, objType, object, infoType, pDataSize, pData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001152 return result;
1153}
1154
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001155VK_LAYER_EXPORT VkResult VKAPI vkBindObjectMemory(
1156 VkDevice device,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001157 VkObjectType objType,
1158 VkObject object,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001159 VkDeviceMemory mem,
1160 VkDeviceSize offset)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001161{
Mark Lobodzinski23065352015-05-29 09:32:35 -05001162 VkResult result = nextTable.BindObjectMemory(device, objType, object, mem, offset);
Mike Stroyanb050c682015-04-17 12:36:38 -06001163 loader_platform_thread_lock_mutex(&globalLock);
1164 // Track objects tied to memory
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001165 set_object_binding(object, mem);
1166 print_object_list();
1167 print_mem_list();
Mike Stroyanb050c682015-04-17 12:36:38 -06001168 loader_platform_thread_unlock_mutex(&globalLock);
1169 return result;
1170}
1171
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001172VK_LAYER_EXPORT VkResult VKAPI vkQueueBindSparseBufferMemory(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001173 VkQueue queue,
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001174 VkBuffer buffer,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001175 VkDeviceSize rangeOffset,
1176 VkDeviceSize rangeSize,
1177 VkDeviceMemory mem,
1178 VkDeviceSize memOffset)
Mike Stroyanb050c682015-04-17 12:36:38 -06001179{
Mark Lobodzinski23065352015-05-29 09:32:35 -05001180 VkResult result = nextTable.QueueBindSparseBufferMemory(queue, buffer, rangeOffset, rangeSize, mem, memOffset);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001181 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001182 // Track objects tied to memory
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001183 if (VK_FALSE == set_sparse_buffer_binding(buffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001184 char str[1024];
Mark Lobodzinski942b1722015-05-11 17:21:15 -05001185 sprintf(str, "Unable to set object %p binding to mem obj %p", (void*)buffer, (void*)mem);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001186 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_BUFFER, buffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001187 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001188 print_object_list();
1189 print_mem_list();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001190 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001191 return result;
1192}
1193
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001194VK_LAYER_EXPORT VkResult VKAPI vkCreateFence(
1195 VkDevice device,
1196 const VkFenceCreateInfo *pCreateInfo,
1197 VkFence *pFence)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001198{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001199 VkResult result = nextTable.CreateFence(device, pCreateInfo, pFence);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001200 if (VK_SUCCESS == result) {
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001201 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001202 add_object_info(*pFence, pCreateInfo->sType, pCreateInfo, sizeof(VkFenceCreateInfo), "fence");
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001203 loader_platform_thread_unlock_mutex(&globalLock);
1204 }
1205 return result;
1206}
1207
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001208VK_LAYER_EXPORT VkResult VKAPI vkResetFences(
1209 VkDevice device,
1210 uint32_t fenceCount,
1211 VkFence *pFences)
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001212{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001213 VkResult result = nextTable.ResetFences(device, fenceCount, pFences);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001214 if (VK_SUCCESS == result) {
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001215 loader_platform_thread_lock_mutex(&globalLock);
1216 // Reset fence state in fenceCreateInfo structure
1217 for (uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001218 MT_OBJ_INFO* pObjectInfo = get_object_info(pFences[i]);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001219 if (pObjectInfo != NULL) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001220 // Validate fences in SIGNALED state
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001221 if (!(pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT)) {
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001222 char str[1024];
Mark Lobodzinskib2689212015-04-14 14:09:32 -05001223 sprintf(str, "Fence %p submitted to VkResetFences in UNSIGNALED STATE", pFences[i]);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001224 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_FENCE, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001225 result = VK_ERROR_INVALID_VALUE;
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001226 }
1227 else {
1228 pObjectInfo->create_info.fence_create_info.flags =
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001229 static_cast<VkFenceCreateFlags>(pObjectInfo->create_info.fence_create_info.flags & ~VK_FENCE_CREATE_SIGNALED_BIT);
Mark Lobodzinskiabc1bc42015-04-09 13:46:09 -05001230 }
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001231 }
1232 }
1233 loader_platform_thread_unlock_mutex(&globalLock);
1234 }
1235 return result;
1236}
1237
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001238VK_LAYER_EXPORT VkResult VKAPI vkGetFenceStatus(
1239 VkDevice device,
1240 VkFence fence)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001241{
Mike Stroyanb050c682015-04-17 12:36:38 -06001242 VkResult result = nextTable.GetFenceStatus(device, fence);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001243 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001244 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001245 update_fence_tracking(fence);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001246 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001247 }
1248 return result;
1249}
1250
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001251VK_LAYER_EXPORT VkResult VKAPI vkWaitForFences(
1252 VkDevice device,
1253 uint32_t fenceCount,
1254 const VkFence *pFences,
1255 bool32_t waitAll,
1256 uint64_t timeout)
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001257{
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001258 // Verify fence status of submitted fences
1259 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001260 MT_OBJ_INFO* pObjectInfo = get_object_info(pFences[i]);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001261 if (pObjectInfo != NULL) {
Tobin Ehlisb870cbb2015-04-15 07:46:12 -06001262 if (pObjectInfo->create_info.fence_create_info.flags & VK_FENCE_CREATE_SIGNALED_BIT) {
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001263 char str[1024];
Mark Lobodzinskib2689212015-04-14 14:09:32 -05001264 sprintf(str, "VkWaitForFences specified fence %p already in SIGNALED state.", pFences[i]);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001265 layerCbMsg(VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_FENCE, pFences[i], 0, MEMTRACK_INVALID_FENCE_STATE, "MEM", str);
Mark Lobodzinski148e1582015-04-07 16:07:57 -05001266 }
1267 }
1268 }
1269
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001270 VkResult result = nextTable.WaitForFences(device, fenceCount, pFences, waitAll, timeout);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001271 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski50932972015-04-02 20:49:09 -05001272
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001273 if (VK_SUCCESS == result) {
Mark Lobodzinski50932972015-04-02 20:49:09 -05001274 if (waitAll || fenceCount == 1) { // Clear all the fences
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001275 for(uint32_t i = 0; i < fenceCount; i++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001276 update_fence_tracking(pFences[i]);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001277 }
1278 }
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001279 }
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001280 loader_platform_thread_unlock_mutex(&globalLock);
1281 return result;
1282}
1283
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001284VK_LAYER_EXPORT VkResult VKAPI vkQueueWaitIdle(
1285 VkQueue queue)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001286{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001287 VkResult result = nextTable.QueueWaitIdle(queue);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001288 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001289 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001290 retire_queue_fences(queue);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001291 loader_platform_thread_unlock_mutex(&globalLock);
1292 }
1293 return result;
1294}
1295
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001296VK_LAYER_EXPORT VkResult VKAPI vkDeviceWaitIdle(
1297 VkDevice device)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001298{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001299 VkResult result = nextTable.DeviceWaitIdle(device);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001300 if (VK_SUCCESS == result) {
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001301 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001302 retire_device_fences(device);
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05001303 loader_platform_thread_unlock_mutex(&globalLock);
1304 }
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001305 return result;
1306}
1307
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001308VK_LAYER_EXPORT VkResult VKAPI vkCreateEvent(
1309 VkDevice device,
1310 const VkEventCreateInfo *pCreateInfo,
1311 VkEvent *pEvent)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001312{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001313 VkResult result = nextTable.CreateEvent(device, pCreateInfo, pEvent);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001314 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001315 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001316 add_object_info(*pEvent, pCreateInfo->sType, pCreateInfo, sizeof(VkEventCreateInfo), "event");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001317 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001318 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001319 return result;
1320}
1321
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001322VK_LAYER_EXPORT VkResult VKAPI vkCreateQueryPool(
1323 VkDevice device,
1324 const VkQueryPoolCreateInfo *pCreateInfo,
1325 VkQueryPool *pQueryPool)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001326{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001327 VkResult result = nextTable.CreateQueryPool(device, pCreateInfo, pQueryPool);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001328 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001329 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001330 add_object_info(*pQueryPool, pCreateInfo->sType, pCreateInfo, sizeof(VkQueryPoolCreateInfo), "query_pool");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001331 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001332 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001333 return result;
1334}
1335
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001336VK_LAYER_EXPORT VkResult VKAPI vkCreateBuffer(
1337 VkDevice device,
1338 const VkBufferCreateInfo *pCreateInfo,
1339 VkBuffer *pBuffer)
Tobin Ehlis7265e832015-01-19 08:42:29 -07001340{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001341 VkResult result = nextTable.CreateBuffer(device, pCreateInfo, pBuffer);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001342 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001343 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001344 add_object_info(*pBuffer, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferCreateInfo), "buffer");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001345 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001346 }
Tobin Ehlis7265e832015-01-19 08:42:29 -07001347 return result;
1348}
1349
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001350VK_LAYER_EXPORT VkResult VKAPI vkCreateBufferView(
1351 VkDevice device,
1352 const VkBufferViewCreateInfo *pCreateInfo,
1353 VkBufferView *pView)
Tobin Ehlis7265e832015-01-19 08:42:29 -07001354{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001355 VkResult result = nextTable.CreateBufferView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001356 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001357 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001358 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkBufferViewCreateInfo), "buffer_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001359 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001360 }
Tobin Ehlis7265e832015-01-19 08:42:29 -07001361 return result;
1362}
1363
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001364VK_LAYER_EXPORT VkResult VKAPI vkCreateImage(
1365 VkDevice device,
1366 const VkImageCreateInfo *pCreateInfo,
1367 VkImage *pImage)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001368{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001369 VkResult result = nextTable.CreateImage(device, pCreateInfo, pImage);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001370 if (VK_SUCCESS == result) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001371 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001372 add_object_info(*pImage, pCreateInfo->sType, pCreateInfo, sizeof(VkImageCreateInfo), "image");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001373 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001374 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001375 return result;
1376}
1377
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001378VK_LAYER_EXPORT VkResult VKAPI vkCreateImageView(
1379 VkDevice device,
1380 const VkImageViewCreateInfo *pCreateInfo,
1381 VkImageView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001382{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001383 VkResult result = nextTable.CreateImageView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001384 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001385 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001386 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkImageViewCreateInfo), "image_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001387 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001388 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001389 return result;
1390}
1391
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001392VK_LAYER_EXPORT VkResult VKAPI vkCreateColorAttachmentView(
1393 VkDevice device,
1394 const VkColorAttachmentViewCreateInfo *pCreateInfo,
1395 VkColorAttachmentView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001396{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001397 VkResult result = nextTable.CreateColorAttachmentView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001398 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001399 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001400 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkColorAttachmentViewCreateInfo), "color_attachment_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001401 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001402 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001403 return result;
1404}
1405
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001406VK_LAYER_EXPORT VkResult VKAPI vkCreateDepthStencilView(
1407 VkDevice device,
1408 const VkDepthStencilViewCreateInfo *pCreateInfo,
1409 VkDepthStencilView *pView)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001410{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001411 VkResult result = nextTable.CreateDepthStencilView(device, pCreateInfo, pView);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001412 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001413 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001414 add_object_info(*pView, pCreateInfo->sType, pCreateInfo, sizeof(VkDepthStencilViewCreateInfo), "ds_view");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001415 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001416 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001417 return result;
1418}
1419
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001420VK_LAYER_EXPORT VkResult VKAPI vkCreateShader(
1421 VkDevice device,
1422 const VkShaderCreateInfo *pCreateInfo,
1423 VkShader *pShader)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001424{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001425 VkResult result = nextTable.CreateShader(device, pCreateInfo, pShader);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001426 return result;
1427}
1428
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001429VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipeline(
1430 VkDevice device,
1431 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1432 VkPipeline *pPipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001433{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001434 VkResult result = nextTable.CreateGraphicsPipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001435 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001436 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001437 add_object_info(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001438 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001439 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001440 return result;
1441}
1442
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001443VK_LAYER_EXPORT VkResult VKAPI vkCreateGraphicsPipelineDerivative(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001444 VkDevice device,
1445 const VkGraphicsPipelineCreateInfo *pCreateInfo,
1446 VkPipeline basePipeline,
1447 VkPipeline *pPipeline)
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001448{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001449 VkResult result = nextTable.CreateGraphicsPipelineDerivative(device, pCreateInfo, basePipeline, pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001450 if (result == VK_SUCCESS) {
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001451 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001452 add_object_info(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkGraphicsPipelineCreateInfo), "graphics_pipeline");
Courtney Goeltzenleuchter0d40f152015-03-25 15:37:49 -06001453 loader_platform_thread_unlock_mutex(&globalLock);
1454 }
1455 return result;
1456}
1457
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001458VK_LAYER_EXPORT VkResult VKAPI vkCreateComputePipeline(
1459 VkDevice device,
1460 const VkComputePipelineCreateInfo *pCreateInfo,
1461 VkPipeline *pPipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001462{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001463 VkResult result = nextTable.CreateComputePipeline(device, pCreateInfo, pPipeline);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001464 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001465 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001466 add_object_info(*pPipeline, pCreateInfo->sType, pCreateInfo, sizeof(VkComputePipelineCreateInfo), "compute_pipeline");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001467 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001468 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001469 return result;
1470}
1471
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001472VK_LAYER_EXPORT VkResult VKAPI vkCreateSampler(
1473 VkDevice device,
1474 const VkSamplerCreateInfo *pCreateInfo,
1475 VkSampler *pSampler)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001476{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001477 VkResult result = nextTable.CreateSampler(device, pCreateInfo, pSampler);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001478 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001479 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001480 add_object_info(*pSampler, pCreateInfo->sType, pCreateInfo, sizeof(VkSamplerCreateInfo), "sampler");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001481 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001482 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001483 return result;
1484}
1485
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001486VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicViewportState(
1487 VkDevice device,
1488 const VkDynamicVpStateCreateInfo *pCreateInfo,
1489 VkDynamicVpState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001490{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001491 VkResult result = nextTable.CreateDynamicViewportState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001492 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001493 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001494 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicVpStateCreateInfo), "viewport_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001495 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001496 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001497 return result;
1498}
1499
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001500VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicRasterState(
1501 VkDevice device,
1502 const VkDynamicRsStateCreateInfo *pCreateInfo,
1503 VkDynamicRsState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001504{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001505 VkResult result = nextTable.CreateDynamicRasterState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001506 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001507 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001508 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicRsStateCreateInfo), "raster_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001509 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001510 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001511 return result;
1512}
1513
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001514VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicColorBlendState(
1515 VkDevice device,
1516 const VkDynamicCbStateCreateInfo *pCreateInfo,
1517 VkDynamicCbState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001518{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001519 VkResult result = nextTable.CreateDynamicColorBlendState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001520 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001521 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001522 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicCbStateCreateInfo), "cb_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001523 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001524 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001525 return result;
1526}
1527
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001528VK_LAYER_EXPORT VkResult VKAPI vkCreateDynamicDepthStencilState(
1529 VkDevice device,
1530 const VkDynamicDsStateCreateInfo *pCreateInfo,
1531 VkDynamicDsState *pState)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001532{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001533 VkResult result = nextTable.CreateDynamicDepthStencilState(device, pCreateInfo, pState);
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001534 if (result == VK_SUCCESS) {
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001535 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001536 add_object_info(*pState, pCreateInfo->sType, pCreateInfo, sizeof(VkDynamicDsStateCreateInfo), "ds_state");
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001537 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis8be20fd2015-01-07 17:49:29 -07001538 }
Tobin Ehlis6663f492014-11-10 12:29:12 -07001539 return result;
1540}
1541
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001542VK_LAYER_EXPORT VkResult VKAPI vkCreateCommandBuffer(
1543 VkDevice device,
1544 const VkCmdBufferCreateInfo *pCreateInfo,
1545 VkCmdBuffer *pCmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001546{
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001547 VkResult result = nextTable.CreateCommandBuffer(device, pCreateInfo, pCmdBuffer);
Mark Lobodzinski223ca202015-04-02 08:52:53 -05001548 // At time of cmd buffer creation, create global cmd buffer info for the returned cmd buffer
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001549 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001550 if (*pCmdBuffer)
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001551 add_cmd_buf_info(*pCmdBuffer);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001552 printCBList();
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001553 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001554 return result;
1555}
1556
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001557VK_LAYER_EXPORT VkResult VKAPI vkBeginCommandBuffer(
1558 VkCmdBuffer cmdBuffer,
1559 const VkCmdBufferBeginInfo *pBeginInfo)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001560{
Mike Stroyan950496e2015-05-19 15:16:08 -06001561 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001562 // This implicitly resets the Cmd Buffer so make sure any fence is done and then clear memory references
Mike Stroyan950496e2015-05-19 15:16:08 -06001563 if (!checkCBCompleted(cmdBuffer)) {
1564 char str[1024];
1565 sprintf(str, "Calling vkBeginCommandBuffer() on active CB %p before it has completed. "
1566 "You must check CB flag before this call.", cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001567 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, "MEM", str);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001568 }
Mike Stroyan950496e2015-05-19 15:16:08 -06001569 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001570 VkResult result = nextTable.BeginCommandBuffer(cmdBuffer, pBeginInfo);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001571 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001572 clear_cmd_buf_and_mem_references(cmdBuffer);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001573 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001574 return result;
1575}
1576
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001577VK_LAYER_EXPORT VkResult VKAPI vkEndCommandBuffer(
1578 VkCmdBuffer cmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001579{
1580 // TODO : Anything to do here?
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001581 VkResult result = nextTable.EndCommandBuffer(cmdBuffer);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001582 return result;
1583}
1584
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001585VK_LAYER_EXPORT VkResult VKAPI vkResetCommandBuffer(
1586 VkCmdBuffer cmdBuffer)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001587{
Mike Stroyan950496e2015-05-19 15:16:08 -06001588 loader_platform_thread_lock_mutex(&globalLock);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001589 // Verify that CB is complete (not in-flight)
Mike Stroyan950496e2015-05-19 15:16:08 -06001590 if (!checkCBCompleted(cmdBuffer)) {
1591 char str[1024];
1592 sprintf(str, "Resetting CB %p before it has completed. You must check CB flag before "
1593 "calling vkResetCommandBuffer().", cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001594 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, "MEM", str);
Tobin Ehlisc9dbcd52015-03-04 08:38:22 -07001595 }
1596 // Clear memory references as this point.
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001597 clear_cmd_buf_and_mem_references(cmdBuffer);
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001598 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterfb4efc62015-04-10 08:34:15 -06001599 VkResult result = nextTable.ResetCommandBuffer(cmdBuffer);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001600 return result;
1601}
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001602// TODO : For any vkCmdBind* calls that include an object which has mem bound to it,
Tobin Ehlis6663f492014-11-10 12:29:12 -07001603// need to account for that mem now having binding to given cmdBuffer
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001604VK_LAYER_EXPORT void VKAPI vkCmdBindPipeline(
1605 VkCmdBuffer cmdBuffer,
1606 VkPipelineBindPoint pipelineBindPoint,
1607 VkPipeline pipeline)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001608{
Tobin Ehlisc145be82015-01-08 15:22:32 -07001609#if 0
1610 // TODO : If memory bound to pipeline, then need to tie that mem to cmdBuffer
1611 if (getPipeline(pipeline)) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001612 MT_CB_INFO *pCBInfo = get_cmd_buf_info(cmdBuffer);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001613 if (pCBInfo) {
1614 pCBInfo->pipelines[pipelineBindPoint] = pipeline;
Tobin Ehlisc145be82015-01-08 15:22:32 -07001615 } else {
1616 char str[1024];
1617 sprintf(str, "Attempt to bind Pipeline %p to non-existant command buffer %p!", (void*)pipeline, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001618 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_INVALID_CB, (char *) "DS", (char *) str);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001619 }
1620 }
1621 else {
1622 char str[1024];
1623 sprintf(str, "Attempt to bind Pipeline %p that doesn't exist!", (void*)pipeline);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001624 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_PIPELINE, pipeline, 0, MEMTRACK_INVALID_OBJECT, (char *) "DS", (char *) str);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001625 }
1626#endif
Tobin Ehlis6663f492014-11-10 12:29:12 -07001627 nextTable.CmdBindPipeline(cmdBuffer, pipelineBindPoint, pipeline);
1628}
1629
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001630VK_LAYER_EXPORT void VKAPI vkCmdBindDynamicStateObject(
1631 VkCmdBuffer cmdBuffer,
1632 VkStateBindPoint stateBindPoint,
1633 VkDynamicStateObject state)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001634{
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001635 MT_OBJ_INFO *pObjInfo;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001636 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001637 MT_CB_INFO *pCmdBuf = get_cmd_buf_info(cmdBuffer);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001638 if (!pCmdBuf) {
1639 char str[1024];
1640 sprintf(str, "Unable to find command buffer object %p, was it ever created?", (void*)cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001641 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_INVALID_CB, "DD", str);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001642 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001643 pObjInfo = get_object_info(state);
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001644 if (!pObjInfo) {
Tobin Ehlisc145be82015-01-08 15:22:32 -07001645 char str[1024];
1646 sprintf(str, "Unable to find dynamic state object %p, was it ever created?", (void*)state);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001647 /* TODO: put in real object type */
1648 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, (VkObjectType) 0, state, 0, MEMTRACK_INVALID_OBJECT, "DD", str);
Tobin Ehlisc145be82015-01-08 15:22:32 -07001649 }
Mark Lobodzinski6434eff2015-03-31 16:05:35 -05001650 pCmdBuf->pDynamicState[stateBindPoint] = pObjInfo;
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001651 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001652 nextTable.CmdBindDynamicStateObject(cmdBuffer, stateBindPoint, state);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001653}
1654
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001655VK_LAYER_EXPORT void VKAPI vkCmdBindDescriptorSets(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001656 VkCmdBuffer cmdBuffer,
1657 VkPipelineBindPoint pipelineBindPoint,
1658 uint32_t firstSet,
1659 uint32_t setCount,
1660 const VkDescriptorSet *pDescriptorSets,
1661 uint32_t dynamicOffsetCount,
1662 const uint32_t *pDynamicOffsets)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001663{
Tobin Ehlisc145be82015-01-08 15:22:32 -07001664 // TODO : Somewhere need to verify that all textures referenced by shaders in DS are in some type of *SHADER_READ* state
Cody Northropd4c1a502015-04-16 13:41:56 -06001665 nextTable.CmdBindDescriptorSets(cmdBuffer, pipelineBindPoint, firstSet, setCount, pDescriptorSets, dynamicOffsetCount, pDynamicOffsets);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001666}
1667
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06001668VK_LAYER_EXPORT void VKAPI vkCmdBindVertexBuffers(
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001669 VkCmdBuffer cmdBuffer,
1670 uint32_t startBinding,
1671 uint32_t bindingCount,
1672 const VkBuffer *pBuffers,
1673 const VkDeviceSize *pOffsets)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001674{
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06001675 nextTable.CmdBindVertexBuffers(cmdBuffer, startBinding, bindingCount, pBuffers, pOffsets);
Chia-I Wu19156822015-01-05 13:42:56 +08001676}
1677
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001678VK_LAYER_EXPORT void VKAPI vkCmdBindIndexBuffer(
1679 VkCmdBuffer cmdBuffer,
1680 VkBuffer buffer,
1681 VkDeviceSize offset,
1682 VkIndexType indexType)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001683{
Tobin Ehlis7265e832015-01-19 08:42:29 -07001684 nextTable.CmdBindIndexBuffer(cmdBuffer, buffer, offset, indexType);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001685}
1686
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001687VK_LAYER_EXPORT void VKAPI vkCmdDrawIndirect(
1688 VkCmdBuffer cmdBuffer,
1689 VkBuffer buffer,
1690 VkDeviceSize offset,
1691 uint32_t count,
1692 uint32_t stride)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001693{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001694 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001695 VkDeviceMemory mem = get_mem_binding_from_object(buffer);
1696 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001697 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001698 sprintf(str, "In vkCmdDrawIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001699 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001700 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001701 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7265e832015-01-19 08:42:29 -07001702 nextTable.CmdDrawIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001703}
1704
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001705VK_LAYER_EXPORT void VKAPI vkCmdDrawIndexedIndirect(
1706 VkCmdBuffer cmdBuffer,
1707 VkBuffer buffer,
1708 VkDeviceSize offset,
1709 uint32_t count,
1710 uint32_t stride)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001711{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001712 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001713 VkDeviceMemory mem = get_mem_binding_from_object(buffer);
1714 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001715 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001716 sprintf(str, "In vkCmdDrawIndexedIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001717 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001718 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001719 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7265e832015-01-19 08:42:29 -07001720 nextTable.CmdDrawIndexedIndirect(cmdBuffer, buffer, offset, count, stride);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001721}
1722
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001723VK_LAYER_EXPORT void VKAPI vkCmdDispatchIndirect(
1724 VkCmdBuffer cmdBuffer,
1725 VkBuffer buffer,
1726 VkDeviceSize offset)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001727{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001728 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001729 VkDeviceMemory mem = get_mem_binding_from_object(buffer);
1730 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001731 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001732 sprintf(str, "In vkCmdDispatchIndirect() call unable to update binding of buffer %p to cmdBuffer %p", buffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001733 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001734 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001735 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001736 nextTable.CmdDispatchIndirect(cmdBuffer, buffer, offset);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001737}
1738
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001739VK_LAYER_EXPORT void VKAPI vkCmdCopyBuffer(
1740 VkCmdBuffer cmdBuffer,
1741 VkBuffer srcBuffer,
1742 VkBuffer destBuffer,
1743 uint32_t regionCount,
1744 const VkBufferCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001745{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001746 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001747 VkDeviceMemory mem = get_mem_binding_from_object(srcBuffer);
1748 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001749 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001750 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001751 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001752 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001753 mem = get_mem_binding_from_object(destBuffer);
1754 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001755 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001756 sprintf(str, "In vkCmdCopyBuffer() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001757 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001758 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001759 loader_platform_thread_unlock_mutex(&globalLock);
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001760 nextTable.CmdCopyBuffer(cmdBuffer, srcBuffer, destBuffer, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001761}
1762
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001763VK_LAYER_EXPORT void VKAPI vkCmdCopyImage(
1764 VkCmdBuffer cmdBuffer,
1765 VkImage srcImage,
1766 VkImageLayout srcImageLayout,
1767 VkImage destImage,
1768 VkImageLayout destImageLayout,
1769 uint32_t regionCount,
1770 const VkImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001771{
1772 // TODO : Each image will have mem mapping so track them
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001773 nextTable.CmdCopyImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001774}
1775
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001776VK_LAYER_EXPORT void VKAPI vkCmdBlitImage(
1777 VkCmdBuffer cmdBuffer,
1778 VkImage srcImage,
1779 VkImageLayout srcImageLayout,
1780 VkImage destImage,
1781 VkImageLayout destImageLayout,
1782 uint32_t regionCount,
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05001783 const VkImageBlit *pRegions,
1784 VkTexFilter filter)
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06001785{
1786 // TODO : Each image will have mem mapping so track them
Mark Lobodzinskiee5eef12015-05-22 14:43:25 -05001787 nextTable.CmdBlitImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions, filter);
Courtney Goeltzenleuchter89299fa2015-03-08 17:02:18 -06001788}
1789
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001790VK_LAYER_EXPORT void VKAPI vkCmdCopyBufferToImage(
1791 VkCmdBuffer cmdBuffer,
1792 VkBuffer srcBuffer,
1793 VkImage destImage,
1794 VkImageLayout destImageLayout,
1795 uint32_t regionCount,
1796 const VkBufferImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001797{
1798 // TODO : Track this
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001799 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001800 VkDeviceMemory mem = get_mem_binding_from_object(destImage);
1801 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001802 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001803 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001804 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001805 }
Mark Lobodzinskic52b7752015-02-18 16:38:17 -06001806
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001807 mem = get_mem_binding_from_object(srcBuffer);
1808 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001809 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001810 sprintf(str, "In vkCmdCopyMemoryToImage() call unable to update binding of srcBuffer %p to cmdBuffer %p", srcBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001811 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001812 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001813 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001814 nextTable.CmdCopyBufferToImage(cmdBuffer, srcBuffer, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001815}
1816
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001817VK_LAYER_EXPORT void VKAPI vkCmdCopyImageToBuffer(
1818 VkCmdBuffer cmdBuffer,
1819 VkImage srcImage,
1820 VkImageLayout srcImageLayout,
1821 VkBuffer destBuffer,
1822 uint32_t regionCount,
1823 const VkBufferImageCopy *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001824{
1825 // TODO : Track this
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001826 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001827 VkDeviceMemory mem = get_mem_binding_from_object(srcImage);
1828 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001829 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001830 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001831 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001832 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001833 mem = get_mem_binding_from_object(destBuffer);
1834 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001835 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001836 sprintf(str, "In vkCmdCopyImageToMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001837 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001838 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001839 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001840 nextTable.CmdCopyImageToBuffer(cmdBuffer, srcImage, srcImageLayout, destBuffer, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001841}
1842
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001843VK_LAYER_EXPORT void VKAPI vkCmdUpdateBuffer(
1844 VkCmdBuffer cmdBuffer,
1845 VkBuffer destBuffer,
1846 VkDeviceSize destOffset,
1847 VkDeviceSize dataSize,
1848 const uint32_t *pData)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001849{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001850 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001851 VkDeviceMemory mem = get_mem_binding_from_object(destBuffer);
1852 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001853 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001854 sprintf(str, "In vkCmdUpdateMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001855 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001856 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001857 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7265e832015-01-19 08:42:29 -07001858 nextTable.CmdUpdateBuffer(cmdBuffer, destBuffer, destOffset, dataSize, pData);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001859}
1860
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001861VK_LAYER_EXPORT void VKAPI vkCmdFillBuffer(
1862 VkCmdBuffer cmdBuffer,
1863 VkBuffer destBuffer,
1864 VkDeviceSize destOffset,
1865 VkDeviceSize fillSize,
1866 uint32_t data)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001867{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001868 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001869 VkDeviceMemory mem = get_mem_binding_from_object(destBuffer);
1870 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001871 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001872 sprintf(str, "In vkCmdFillMemory() call unable to update binding of destBuffer %p to cmdBuffer %p", destBuffer, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001873 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001874 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001875 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis7265e832015-01-19 08:42:29 -07001876 nextTable.CmdFillBuffer(cmdBuffer, destBuffer, destOffset, fillSize, data);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001877}
1878
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001879VK_LAYER_EXPORT void VKAPI vkCmdClearColorImage(
1880 VkCmdBuffer cmdBuffer,
1881 VkImage image,
1882 VkImageLayout imageLayout,
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06001883 const VkClearColor *pColor,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001884 uint32_t rangeCount,
1885 const VkImageSubresourceRange *pRanges)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001886{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001887 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001888 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001889 VkDeviceMemory mem = get_mem_binding_from_object(image);
1890 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001891 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001892 sprintf(str, "In vkCmdClearColorImage() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001893 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001894 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001895 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterd7a5cff2015-04-23 17:49:22 -06001896 nextTable.CmdClearColorImage(cmdBuffer, image, imageLayout, pColor, rangeCount, pRanges);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001897}
1898
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001899VK_LAYER_EXPORT void VKAPI vkCmdClearDepthStencil(
1900 VkCmdBuffer cmdBuffer,
1901 VkImage image,
1902 VkImageLayout imageLayout,
1903 float depth,
1904 uint32_t stencil,
1905 uint32_t rangeCount,
1906 const VkImageSubresourceRange *pRanges)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001907{
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001908 // TODO : Verify memory is in VK_IMAGE_STATE_CLEAR state
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001909 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001910 VkDeviceMemory mem = get_mem_binding_from_object(image);
1911 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001912 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001913 sprintf(str, "In vkCmdClearDepthStencil() call unable to update binding of image buffer %p to cmdBuffer %p", image, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001914 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001915 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001916 loader_platform_thread_unlock_mutex(&globalLock);
Courtney Goeltzenleuchterb3efe9b2015-03-25 11:25:10 -06001917 nextTable.CmdClearDepthStencil(cmdBuffer, image, imageLayout, depth, stencil, rangeCount, pRanges);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001918}
1919
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001920VK_LAYER_EXPORT void VKAPI vkCmdResolveImage(
1921 VkCmdBuffer cmdBuffer,
1922 VkImage srcImage,
1923 VkImageLayout srcImageLayout,
1924 VkImage destImage,
1925 VkImageLayout destImageLayout,
1926 uint32_t regionCount,
1927 const VkImageResolve *pRegions)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001928{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001929 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001930 VkDeviceMemory mem = get_mem_binding_from_object(srcImage);
1931 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001932 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001933 sprintf(str, "In vkCmdResolveImage() call unable to update binding of srcImage buffer %p to cmdBuffer %p", srcImage, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001934 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001935 }
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001936 mem = get_mem_binding_from_object(destImage);
1937 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001938 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001939 sprintf(str, "In vkCmdResolveImage() call unable to update binding of destImage buffer %p to cmdBuffer %p", destImage, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001940 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001941 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001942 loader_platform_thread_unlock_mutex(&globalLock);
Tony Barbour6865d4a2015-04-13 15:02:52 -06001943 nextTable.CmdResolveImage(cmdBuffer, srcImage, srcImageLayout, destImage, destImageLayout, regionCount, pRegions);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001944}
1945
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001946VK_LAYER_EXPORT void VKAPI vkCmdBeginQuery(
1947 VkCmdBuffer cmdBuffer,
1948 VkQueryPool queryPool,
1949 uint32_t slot,
1950 VkFlags flags)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001951{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001952 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001953 VkDeviceMemory mem = get_mem_binding_from_object(queryPool);
1954 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001955 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001956 sprintf(str, "In vkCmdBeginQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001957 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001958 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001959 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001960 nextTable.CmdBeginQuery(cmdBuffer, queryPool, slot, flags);
1961}
1962
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001963VK_LAYER_EXPORT void VKAPI vkCmdEndQuery(
1964 VkCmdBuffer cmdBuffer,
1965 VkQueryPool queryPool,
1966 uint32_t slot)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001967{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001968 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001969 VkDeviceMemory mem = get_mem_binding_from_object(queryPool);
1970 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001971 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001972 sprintf(str, "In vkCmdEndQuery() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001973 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001974 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001975 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001976 nextTable.CmdEndQuery(cmdBuffer, queryPool, slot);
1977}
1978
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06001979VK_LAYER_EXPORT void VKAPI vkCmdResetQueryPool(
1980 VkCmdBuffer cmdBuffer,
1981 VkQueryPool queryPool,
1982 uint32_t startQuery,
1983 uint32_t queryCount)
Tobin Ehlis6663f492014-11-10 12:29:12 -07001984{
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001985 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05001986 VkDeviceMemory mem = get_mem_binding_from_object(queryPool);
1987 if (VK_FALSE == update_cmd_buf_and_mem_references(cmdBuffer, mem)) {
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001988 char str[1024];
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06001989 sprintf(str, "In vkCmdResetQueryPool() call unable to update binding of queryPool buffer %p to cmdBuffer %p", queryPool, cmdBuffer);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001990 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_COMMAND_BUFFER, cmdBuffer, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07001991 }
Mark Lobodzinski93f494b2015-03-02 20:23:52 -06001992 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehlis6663f492014-11-10 12:29:12 -07001993 nextTable.CmdResetQueryPool(cmdBuffer, queryPool, startQuery, queryCount);
1994}
1995
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06001996VK_LAYER_EXPORT VkResult VKAPI vkDbgCreateMsgCallback(
1997 VkInstance instance,
1998 VkFlags msgFlags,
1999 const PFN_vkDbgMsgCallback pfnMsgCallback,
2000 void* pUserData,
2001 VkDbgMsgCallback* pMsgCallback)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002002{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002003 return layer_create_msg_callback(instance, &nextInstanceTable, msgFlags, pfnMsgCallback, pUserData, pMsgCallback);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002004}
2005
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002006VK_LAYER_EXPORT VkResult VKAPI vkDbgDestroyMsgCallback(
2007 VkInstance instance,
2008 VkDbgMsgCallback msgCallback)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002009{
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002010 return layer_destroy_msg_callback(instance, &nextInstanceTable, msgCallback);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002011}
2012
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002013VK_LAYER_EXPORT VkResult VKAPI vkCreateSwapChainWSI(
2014 VkDevice device,
2015 const VkSwapChainCreateInfoWSI *pCreateInfo,
2016 VkSwapChainWSI *pSwapChain)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002017{
Chia-I Wuf8693382015-04-16 22:02:10 +08002018 VkResult result = nextTable.CreateSwapChainWSI(device, pCreateInfo, pSwapChain);
2019
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002020 if (VK_SUCCESS == result) {
Chia-I Wuf8693382015-04-16 22:02:10 +08002021 loader_platform_thread_lock_mutex(&globalLock);
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002022 add_swap_chain_info(*pSwapChain);
Chia-I Wuf8693382015-04-16 22:02:10 +08002023 loader_platform_thread_unlock_mutex(&globalLock);
Tobin Ehliscd9223b2014-11-19 16:19:28 -07002024 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002025
Tobin Ehlis6663f492014-11-10 12:29:12 -07002026 return result;
2027}
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002028
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002029VK_LAYER_EXPORT VkResult VKAPI vkDestroySwapChainWSI(
2030 VkSwapChainWSI swapChain)
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002031{
2032 loader_platform_thread_lock_mutex(&globalLock);
Chia-I Wuf8693382015-04-16 22:02:10 +08002033
2034 if (swapChainMap.find(swapChain) != swapChainMap.end()) {
2035 MT_SWAP_CHAIN_INFO* pInfo = swapChainMap[swapChain];
2036
David Pinedod8f83d82015-04-27 16:36:17 -06002037 if (pInfo->images.size() > 0) {
2038 for (std::vector<VkSwapChainImageInfoWSI>::const_iterator it = pInfo->images.begin();
2039 it != pInfo->images.end(); it++) {
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002040 clear_object_binding(it->image);
David Pinedod8f83d82015-04-27 16:36:17 -06002041 freeMemObjInfo(it->memory, true);
Chia-I Wuf8693382015-04-16 22:02:10 +08002042
David Pinedod8f83d82015-04-27 16:36:17 -06002043 objectMap.erase(it->image);
2044 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002045 }
2046
2047 delete pInfo;
2048 swapChainMap.erase(swapChain);
2049 }
2050
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002051 loader_platform_thread_unlock_mutex(&globalLock);
Chia-I Wuf8693382015-04-16 22:02:10 +08002052
2053 return nextTable.DestroySwapChainWSI(swapChain);
2054}
2055
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002056VK_LAYER_EXPORT VkResult VKAPI vkGetSwapChainInfoWSI(
2057 VkSwapChainWSI swapChain,
2058 VkSwapChainInfoTypeWSI infoType,
2059 size_t *pDataSize,
2060 void *pData)
Chia-I Wuf8693382015-04-16 22:02:10 +08002061{
2062 VkResult result = nextTable.GetSwapChainInfoWSI(swapChain, infoType, pDataSize, pData);
2063
2064 if (infoType == VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI && result == VK_SUCCESS) {
2065 const size_t count = *pDataSize / sizeof(VkSwapChainImageInfoWSI);
2066 MT_SWAP_CHAIN_INFO *pInfo = swapChainMap[swapChain];
2067
2068 if (pInfo->images.empty()) {
2069 pInfo->images.resize(count);
2070 memcpy(&pInfo->images[0], pData, sizeof(pInfo->images[0]) * count);
2071
David Pinedod8f83d82015-04-27 16:36:17 -06002072 if (pInfo->images.size() > 0) {
2073 for (std::vector<VkSwapChainImageInfoWSI>::const_iterator it = pInfo->images.begin();
2074 it != pInfo->images.end(); it++) {
2075 // Add image object, then insert the new Mem Object and then bind it to created image
Mark Lobodzinski944aab12015-06-05 13:59:04 -05002076 add_object_info(it->image, VK_STRUCTURE_TYPE_MAX_ENUM, &pInfo->createInfo, sizeof(pInfo->createInfo), "persistent_image");
2077 add_mem_obj_info(it->memory, NULL);
2078 if (VK_FALSE == set_object_binding(it->image, it->memory)) {
David Pinedod8f83d82015-04-27 16:36:17 -06002079 char str[1024];
2080 sprintf(str, "In vkGetSwapChainInfoWSI(), unable to set image %p binding to mem obj %p", (void*)it->image, (void*)it->memory);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002081 layerCbMsg(VK_DBG_REPORT_ERROR_BIT, VK_OBJECT_TYPE_IMAGE, it->image, 0, MEMTRACK_MEMORY_BINDING_ERROR, "MEM", str);
David Pinedod8f83d82015-04-27 16:36:17 -06002082 }
Chia-I Wuf8693382015-04-16 22:02:10 +08002083 }
2084 }
2085 } else {
2086 const bool mismatch = (pInfo->images.size() != count ||
2087 memcmp(&pInfo->images[0], pData, sizeof(pInfo->images[0]) * count));
2088
2089 if (mismatch) {
2090 char str[1024];
2091 sprintf(str, "vkGetSwapChainInfoWSI(%p, VK_SWAP_CHAIN_INFO_TYPE_PERSISTENT_IMAGES_WSI) returned mismatching data", swapChain);
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002092 layerCbMsg(VK_DBG_REPORT_WARN_BIT, VK_OBJECT_TYPE_SWAP_CHAIN_WSI, (VkObject) swapChain, 0, MEMTRACK_NONE, "SWAP_CHAIN", str);
Chia-I Wuf8693382015-04-16 22:02:10 +08002093 }
2094 }
2095 }
2096
Mark Lobodzinskie61ebe72015-03-17 10:53:12 -05002097 return result;
2098}
Tobin Ehlis6663f492014-11-10 12:29:12 -07002099
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002100VK_LAYER_EXPORT void* VKAPI vkGetDeviceProcAddr(
2101 VkDevice dev,
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002102 const char *funcName)
Tobin Ehlis6663f492014-11-10 12:29:12 -07002103{
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002104 VkBaseLayerObject* devw = (VkBaseLayerObject *) dev;
Chia-I Wu4d11dcc2015-01-05 13:18:57 +08002105
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002106 if (dev == NULL) {
Tobin Ehlis6663f492014-11-10 12:29:12 -07002107 return NULL;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002108 }
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002109 pCurObj = devw;
Ian Elliott2d4ab1e2015-01-13 17:52:38 -07002110 loader_platform_thread_once(&g_initOnce, initMemTracker);
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -06002111 loader_platform_thread_once(&g_tabDeviceOnce, initDeviceTable);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002112
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002113 if (!strcmp(funcName, "vkGetDeviceProcAddr"))
2114 return (void *) vkGetDeviceProcAddr;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002115 if (!strcmp(funcName, "vkDestroyDevice"))
2116 return (void*) vkDestroyDevice;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002117 if (!strcmp(funcName, "vkQueueSubmit"))
2118 return (void*) vkQueueSubmit;
2119 if (!strcmp(funcName, "vkAllocMemory"))
2120 return (void*) vkAllocMemory;
2121 if (!strcmp(funcName, "vkFreeMemory"))
2122 return (void*) vkFreeMemory;
2123 if (!strcmp(funcName, "vkSetMemoryPriority"))
2124 return (void*) vkSetMemoryPriority;
2125 if (!strcmp(funcName, "vkMapMemory"))
2126 return (void*) vkMapMemory;
2127 if (!strcmp(funcName, "vkUnmapMemory"))
2128 return (void*) vkUnmapMemory;
2129 if (!strcmp(funcName, "vkPinSystemMemory"))
2130 return (void*) vkPinSystemMemory;
2131 if (!strcmp(funcName, "vkOpenSharedMemory"))
2132 return (void*) vkOpenSharedMemory;
2133 if (!strcmp(funcName, "vkOpenPeerMemory"))
2134 return (void*) vkOpenPeerMemory;
2135 if (!strcmp(funcName, "vkOpenPeerImage"))
2136 return (void*) vkOpenPeerImage;
2137 if (!strcmp(funcName, "vkDestroyObject"))
2138 return (void*) vkDestroyObject;
2139 if (!strcmp(funcName, "vkGetObjectInfo"))
2140 return (void*) vkGetObjectInfo;
Mark Lobodzinski942b1722015-05-11 17:21:15 -05002141 if (!strcmp(funcName, "vkBindObjectMemory"))
2142 return (void*) vkBindObjectMemory;
2143 if (!strcmp(funcName, "vkQueueBindSparseBufferMemory"))
2144 return (void*) vkQueueBindSparseBufferMemory;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002145 if (!strcmp(funcName, "vkCreateFence"))
2146 return (void*) vkCreateFence;
2147 if (!strcmp(funcName, "vkGetFenceStatus"))
2148 return (void*) vkGetFenceStatus;
2149 if (!strcmp(funcName, "vkResetFences"))
2150 return (void*) vkResetFences;
2151 if (!strcmp(funcName, "vkWaitForFences"))
2152 return (void*) vkWaitForFences;
2153 if (!strcmp(funcName, "vkQueueWaitIdle"))
2154 return (void*) vkQueueWaitIdle;
2155 if (!strcmp(funcName, "vkDeviceWaitIdle"))
2156 return (void*) vkDeviceWaitIdle;
2157 if (!strcmp(funcName, "vkCreateEvent"))
2158 return (void*) vkCreateEvent;
2159 if (!strcmp(funcName, "vkCreateQueryPool"))
2160 return (void*) vkCreateQueryPool;
2161 if (!strcmp(funcName, "vkCreateBuffer"))
2162 return (void*) vkCreateBuffer;
2163 if (!strcmp(funcName, "vkCreateBufferView"))
2164 return (void*) vkCreateBufferView;
2165 if (!strcmp(funcName, "vkCreateImage"))
2166 return (void*) vkCreateImage;
2167 if (!strcmp(funcName, "vkCreateImageView"))
2168 return (void*) vkCreateImageView;
2169 if (!strcmp(funcName, "vkCreateColorAttachmentView"))
2170 return (void*) vkCreateColorAttachmentView;
2171 if (!strcmp(funcName, "vkCreateDepthStencilView"))
2172 return (void*) vkCreateDepthStencilView;
2173 if (!strcmp(funcName, "vkCreateShader"))
2174 return (void*) vkCreateShader;
2175 if (!strcmp(funcName, "vkCreateGraphicsPipeline"))
2176 return (void*) vkCreateGraphicsPipeline;
2177 if (!strcmp(funcName, "vkCreateGraphicsPipelineDerivative"))
2178 return (void*) vkCreateGraphicsPipelineDerivative;
2179 if (!strcmp(funcName, "vkCreateComputePipeline"))
2180 return (void*) vkCreateComputePipeline;
2181 if (!strcmp(funcName, "vkCreateSampler"))
2182 return (void*) vkCreateSampler;
2183 if (!strcmp(funcName, "vkCreateDynamicViewportState"))
2184 return (void*) vkCreateDynamicViewportState;
2185 if (!strcmp(funcName, "vkCreateDynamicRasterState"))
2186 return (void*) vkCreateDynamicRasterState;
2187 if (!strcmp(funcName, "vkCreateDynamicColorBlendState"))
2188 return (void*) vkCreateDynamicColorBlendState;
2189 if (!strcmp(funcName, "vkCreateDynamicDepthStencilState"))
2190 return (void*) vkCreateDynamicDepthStencilState;
2191 if (!strcmp(funcName, "vkCreateCommandBuffer"))
2192 return (void*) vkCreateCommandBuffer;
2193 if (!strcmp(funcName, "vkBeginCommandBuffer"))
2194 return (void*) vkBeginCommandBuffer;
2195 if (!strcmp(funcName, "vkEndCommandBuffer"))
2196 return (void*) vkEndCommandBuffer;
2197 if (!strcmp(funcName, "vkResetCommandBuffer"))
2198 return (void*) vkResetCommandBuffer;
2199 if (!strcmp(funcName, "vkCmdBindPipeline"))
2200 return (void*) vkCmdBindPipeline;
2201 if (!strcmp(funcName, "vkCmdBindDynamicStateObject"))
2202 return (void*) vkCmdBindDynamicStateObject;
2203 if (!strcmp(funcName, "vkCmdBindDescriptorSets"))
2204 return (void*) vkCmdBindDescriptorSets;
Courtney Goeltzenleuchterf68ad722015-04-16 13:38:46 -06002205 if (!strcmp(funcName, "vkCmdBindVertexBuffers"))
2206 return (void*) vkCmdBindVertexBuffers;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002207 if (!strcmp(funcName, "vkCmdBindIndexBuffer"))
2208 return (void*) vkCmdBindIndexBuffer;
2209 if (!strcmp(funcName, "vkCmdDrawIndirect"))
2210 return (void*) vkCmdDrawIndirect;
2211 if (!strcmp(funcName, "vkCmdDrawIndexedIndirect"))
2212 return (void*) vkCmdDrawIndexedIndirect;
2213 if (!strcmp(funcName, "vkCmdDispatchIndirect"))
2214 return (void*) vkCmdDispatchIndirect;
2215 if (!strcmp(funcName, "vkCmdCopyBuffer"))
2216 return (void*) vkCmdCopyBuffer;
2217 if (!strcmp(funcName, "vkCmdCopyImage"))
2218 return (void*) vkCmdCopyImage;
2219 if (!strcmp(funcName, "vkCmdCopyBufferToImage"))
2220 return (void*) vkCmdCopyBufferToImage;
2221 if (!strcmp(funcName, "vkCmdCopyImageToBuffer"))
2222 return (void*) vkCmdCopyImageToBuffer;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002223 if (!strcmp(funcName, "vkCmdUpdateBuffer"))
2224 return (void*) vkCmdUpdateBuffer;
2225 if (!strcmp(funcName, "vkCmdFillBuffer"))
2226 return (void*) vkCmdFillBuffer;
2227 if (!strcmp(funcName, "vkCmdClearColorImage"))
2228 return (void*) vkCmdClearColorImage;
2229 if (!strcmp(funcName, "vkCmdClearDepthStencil"))
2230 return (void*) vkCmdClearDepthStencil;
2231 if (!strcmp(funcName, "vkCmdResolveImage"))
2232 return (void*) vkCmdResolveImage;
2233 if (!strcmp(funcName, "vkCmdBeginQuery"))
2234 return (void*) vkCmdBeginQuery;
2235 if (!strcmp(funcName, "vkCmdEndQuery"))
2236 return (void*) vkCmdEndQuery;
2237 if (!strcmp(funcName, "vkCmdResetQueryPool"))
2238 return (void*) vkCmdResetQueryPool;
Courtney Goeltzenleuchterf579fa62015-06-10 17:39:03 -06002239 if (g_DEBUG_REPORT && !strcmp(funcName, "vkDbgCreateMsgCallback"))
2240 return (void*) vkDbgCreateMsgCallback;
Courtney Goeltzenleuchterd8e229c2015-04-08 15:36:08 -06002241 if (!strcmp(funcName, "vkGetDeviceQueue"))
2242 return (void*) vkGetDeviceQueue;
Chia-I Wuf8693382015-04-16 22:02:10 +08002243 if (!strcmp(funcName, "vkCreateSwapChainWSI"))
2244 return (void*) vkCreateSwapChainWSI;
2245 if (!strcmp(funcName, "vkDestroySwapChainWSI"))
2246 return (void*) vkDestroySwapChainWSI;
2247 if (!strcmp(funcName, "vkGetSwapChainInfoWSI"))
2248 return (void*) vkGetSwapChainInfoWSI;
Tobin Ehlis6663f492014-11-10 12:29:12 -07002249 else {
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002250 if (devw->pGPA == NULL) {
Tobin Ehlis6663f492014-11-10 12:29:12 -07002251 return NULL;
Mark Lobodzinskib1567a02015-04-21 15:33:04 -06002252 }
Jon Ashburn8d1b0b52015-05-18 13:20:15 -06002253 return devw->pGPA((VkObject)devw->nextObject, funcName);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002254 }
2255}
2256
2257VK_LAYER_EXPORT void* VKAPI vkGetInstanceProcAddr(
2258 VkInstance instance,
2259 const char *funcName)
2260{
2261 VkBaseLayerObject* instw = (VkBaseLayerObject *) instance;
2262
2263 if (instance == NULL) {
2264 return NULL;
2265 }
Jon Ashburn8c5cbcf2015-05-07 10:27:37 -06002266
2267 pCurObj = instw;
2268 loader_platform_thread_once(&g_initOnce, initMemTracker);
2269 loader_platform_thread_once(&g_tabInstanceOnce, initInstanceTable);
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002270
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002271 if (!strcmp(funcName, "vkGetInstanceProcAddr"))
2272 return (void *) vkGetInstanceProcAddr;
2273 if (!strcmp(funcName, "vkCreateDevice"))
2274 return (void*) vkCreateDevice;
Jon Ashburnf6b33db2015-05-05 14:22:52 -06002275 else {
2276 if (instw->pGPA == NULL) {
2277 return NULL;
2278 }
2279 return instw->pGPA((VkObject)instw->nextObject, funcName);
Tobin Ehlis6663f492014-11-10 12:29:12 -07002280 }
2281}