Tobin Ehlis | 6208641 | 2014-11-19 16:19:28 -0700 | [diff] [blame] | 1 | /* |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 2 | * Vulkan |
Tobin Ehlis | 6208641 | 2014-11-19 16:19:28 -0700 | [diff] [blame] | 3 | * |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 4 | * Copyright (C) 2015 LunarG, Inc. |
Tobin Ehlis | 6208641 | 2014-11-19 16:19:28 -0700 | [diff] [blame] | 5 | * |
| 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 |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * 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 | */ |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 24 | #pragma once |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 25 | #include <vector> |
Tobin Ehlis | 2d1d970 | 2015-07-03 09:42:57 -0600 | [diff] [blame] | 26 | #include "vk_layer.h" |
Courtney Goeltzenleuchter | d4d26dd | 2015-09-23 12:30:48 -0600 | [diff] [blame] | 27 | #include "vk_debug_report_lunarg.h" |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 28 | |
| 29 | #ifdef __cplusplus |
| 30 | extern "C" { |
| 31 | #endif |
| 32 | |
Tobin Ehlis | 6208641 | 2014-11-19 16:19:28 -0700 | [diff] [blame] | 33 | // Mem Tracker ERROR codes |
| 34 | typedef enum _MEM_TRACK_ERROR |
| 35 | { |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 36 | MEMTRACK_NONE, // Used for INFO & other non-error messages |
| 37 | MEMTRACK_INVALID_CB, // Cmd Buffer invalid |
| 38 | MEMTRACK_INVALID_MEM_OBJ, // Invalid Memory Object |
| 39 | MEMTRACK_INTERNAL_ERROR, // Bug in Mem Track Layer internal data structures |
| 40 | MEMTRACK_FREED_MEM_REF, // MEM Obj freed while it still has obj and/or CB refs |
| 41 | MEMTRACK_MEM_OBJ_CLEAR_EMPTY_BINDINGS, // Clearing bindings on mem obj that doesn't have any bindings |
| 42 | MEMTRACK_MISSING_MEM_BINDINGS, // Trying to retrieve mem bindings, but none found (may be internal error) |
| 43 | MEMTRACK_INVALID_OBJECT, // Attempting to reference generic VK Object that is invalid |
Mark Lobodzinski | c66c671 | 2015-06-05 13:59:04 -0500 | [diff] [blame] | 44 | MEMTRACK_MEMORY_BINDING_ERROR, // Error during one of many calls that bind memory to object or CB |
| 45 | MEMTRACK_MEMORY_LEAK, // Failure to call vkFreeMemory on Mem Obj prior to DestroyDevice |
| 46 | MEMTRACK_INVALID_STATE, // Memory not in the correct state |
| 47 | MEMTRACK_RESET_CB_WHILE_IN_FLIGHT, // vkResetCommandBuffer() called on a CB that hasn't completed |
| 48 | MEMTRACK_INVALID_FENCE_STATE, // Invalid Fence State signaled or used |
| 49 | MEMTRACK_REBIND_OBJECT, // Non-sparse object bindings are immutable |
Tobin Ehlis | d94ba72 | 2015-07-03 08:45:14 -0600 | [diff] [blame] | 50 | MEMTRACK_INVALID_USAGE_FLAG, // Usage flags specified at image/buffer create conflict w/ use of object |
Tobin Ehlis | 6208641 | 2014-11-19 16:19:28 -0700 | [diff] [blame] | 51 | } MEM_TRACK_ERROR; |
| 52 | |
Mark Lobodzinski | 2a25307 | 2015-10-08 10:44:07 -0600 | [diff] [blame] | 53 | // MemTracker Semaphore states |
| 54 | typedef enum _MtSemaphoreState |
| 55 | { |
| 56 | MEMTRACK_SEMAPHORE_STATE_UNSET, // Semaphore is in an undefined state |
| 57 | MEMTRACK_SEMAPHORE_STATE_SIGNALLED, // Semaphore has is in signalled state |
| 58 | MEMTRACK_SEMAPHORE_STATE_WAIT, // Semaphore is in wait state |
| 59 | } MtSemaphoreState; |
| 60 | |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 61 | /* |
| 62 | * Data Structure overview |
Courtney Goeltzenleuchter | dfd1b2a | 2015-04-15 00:14:36 -0600 | [diff] [blame] | 63 | * There are 4 global STL(' maps |
Mark Lobodzinski | 7a428ce | 2015-03-31 16:05:35 -0500 | [diff] [blame] | 64 | * cbMap -- map of command Buffer (CB) objects to MT_CB_INFO structures |
| 65 | * Each MT_CB_INFO struct has an stl list container with |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 66 | * memory objects that are referenced by this CB |
Mark Lobodzinski | 7a428ce | 2015-03-31 16:05:35 -0500 | [diff] [blame] | 67 | * memObjMap -- map of Memory Objects to MT_MEM_OBJ_INFO structures |
| 68 | * Each MT_MEM_OBJ_INFO has two stl list containers with: |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 69 | * -- all CBs referencing this mem obj |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 70 | * -- all VK Objects that are bound to this memory |
Mark Lobodzinski | 7a428ce | 2015-03-31 16:05:35 -0500 | [diff] [blame] | 71 | * objectMap -- map of objects to MT_OBJ_INFO structures |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 72 | * |
| 73 | * Algorithm overview |
| 74 | * These are the primary events that should happen related to different objects |
| 75 | * 1. Command buffers |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 76 | * CREATION - Add object,structure to map |
| 77 | * CMD BIND - If mem associated, add mem reference to list container |
| 78 | * DESTROY - Remove from map, decrement (and report) mem references |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 79 | * 2. Mem Objects |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 80 | * CREATION - Add object,structure to map |
| 81 | * OBJ BIND - Add obj structure to list container for that mem node |
| 82 | * CMB BIND - If mem-related add CB structure to list container for that mem node |
| 83 | * DESTROY - Flag as errors any remaining refs and remove from map |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 84 | * 3. Generic Objects |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 85 | * MEM BIND - DESTROY any previous binding, Add obj node w/ ref to map, add obj ref to list container for that mem node |
Mark Lobodzinski | 7a428ce | 2015-03-31 16:05:35 -0500 | [diff] [blame] | 86 | * DESTROY - If mem bound, remove reference list container for that memInfo, remove object ref from map |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 87 | */ |
| 88 | // TODO : Is there a way to track when Cmd Buffer finishes & remove mem references at that point? |
| 89 | // TODO : Could potentially store a list of freed mem allocs to flag when they're incorrectly used |
| 90 | |
Tobin Ehlis | 92f12cd | 2015-07-08 17:08:02 -0600 | [diff] [blame] | 91 | // Simple struct to hold handle and type of object so they can be uniquely identified and looked up in appropriate map |
| 92 | struct MT_OBJ_HANDLE_TYPE { |
| 93 | uint64_t handle; |
| 94 | VkDbgObjectType type; |
| 95 | }; |
| 96 | |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 97 | // Data struct for tracking memory object |
Mark Lobodzinski | 7a428ce | 2015-03-31 16:05:35 -0500 | [diff] [blame] | 98 | struct MT_MEM_OBJ_INFO { |
Mark Lobodzinski | d027366 | 2015-08-10 14:37:52 -0600 | [diff] [blame] | 99 | void* object; // Dispatchable object used to create this memory (device of swapchain) |
Mark Lobodzinski | a908b16 | 2015-04-21 15:33:04 -0600 | [diff] [blame] | 100 | uint32_t refCount; // Count of references (obj bindings or CB use) |
| 101 | VkDeviceMemory mem; |
| 102 | VkMemoryAllocInfo allocInfo; |
Tobin Ehlis | 92f12cd | 2015-07-08 17:08:02 -0600 | [diff] [blame] | 103 | list<MT_OBJ_HANDLE_TYPE> pObjBindings; // list container of objects bound to this memory |
Mark Lobodzinski | a908b16 | 2015-04-21 15:33:04 -0600 | [diff] [blame] | 104 | list<VkCmdBuffer> pCmdBufferBindings; // list container of cmd buffers that reference this mem object |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 105 | }; |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 106 | |
Tobin Ehlis | 92f12cd | 2015-07-08 17:08:02 -0600 | [diff] [blame] | 107 | // This only applies to Buffers and Images, which can have memory bound to them |
| 108 | struct MT_OBJ_BINDING_INFO { |
| 109 | VkDeviceMemory mem; |
Chris Forbes | a0a71b6 | 2015-07-11 16:06:23 +1200 | [diff] [blame] | 110 | union create_info { |
Tobin Ehlis | 92f12cd | 2015-07-08 17:08:02 -0600 | [diff] [blame] | 111 | VkImageCreateInfo image; |
| 112 | VkBufferCreateInfo buffer; |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 113 | } create_info; |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 114 | }; |
Tobin Ehlis | 2836a7d | 2015-01-08 15:22:32 -0700 | [diff] [blame] | 115 | |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 116 | // Track all command buffers |
Mark Lobodzinski | 7a428ce | 2015-03-31 16:05:35 -0500 | [diff] [blame] | 117 | struct MT_CB_INFO { |
Courtney Goeltzenleuchter | 831c183 | 2015-10-23 14:21:05 -0600 | [diff] [blame^] | 118 | VkCmdBufferAllocInfo createInfo; |
Courtney Goeltzenleuchter | a7281c2 | 2015-07-12 15:42:02 -0600 | [diff] [blame] | 119 | VkPipeline pipelines[VK_PIPELINE_BIND_POINT_NUM]; |
Chia-I Wu | c278df8 | 2015-07-07 11:50:03 +0800 | [diff] [blame] | 120 | uint32_t attachmentCount; |
Mark Lobodzinski | a908b16 | 2015-04-21 15:33:04 -0600 | [diff] [blame] | 121 | VkCmdBuffer cmdBuffer; |
| 122 | uint64_t fenceId; |
Mike Stroyan | 5343033 | 2015-05-19 15:16:08 -0600 | [diff] [blame] | 123 | VkFence lastSubmittedFence; |
| 124 | VkQueue lastSubmittedQueue; |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 125 | // Order dependent, stl containers must be at end of struct |
Mark Lobodzinski | a908b16 | 2015-04-21 15:33:04 -0600 | [diff] [blame] | 126 | list<VkDeviceMemory> pMemObjList; // List container of Mem objs referenced by this CB |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 127 | }; |
Mark Lobodzinski | 4aad364 | 2015-03-17 10:53:12 -0500 | [diff] [blame] | 128 | |
Mark Lobodzinski | 85a8398 | 2015-04-02 08:52:53 -0500 | [diff] [blame] | 129 | // Associate fenceId with a fence object |
Mark Lobodzinski | 7a428ce | 2015-03-31 16:05:35 -0500 | [diff] [blame] | 130 | struct MT_FENCE_INFO { |
Mike Stroyan | 5343033 | 2015-05-19 15:16:08 -0600 | [diff] [blame] | 131 | uint64_t fenceId; // Sequence number for fence at last submit |
| 132 | VkQueue queue; // Queue that this fence is submitted against or NULL |
Tobin Ehlis | 92f12cd | 2015-07-08 17:08:02 -0600 | [diff] [blame] | 133 | VkFenceCreateInfo createInfo; |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 134 | }; |
Mark Lobodzinski | 4aad364 | 2015-03-17 10:53:12 -0500 | [diff] [blame] | 135 | |
Mark Lobodzinski | 85a8398 | 2015-04-02 08:52:53 -0500 | [diff] [blame] | 136 | // Track Queue information |
| 137 | struct MT_QUEUE_INFO { |
Mark Lobodzinski | a908b16 | 2015-04-21 15:33:04 -0600 | [diff] [blame] | 138 | uint64_t lastRetiredId; |
| 139 | uint64_t lastSubmittedId; |
| 140 | list<VkCmdBuffer> pQueueCmdBuffers; |
| 141 | list<VkDeviceMemory> pMemRefList; |
Mark Lobodzinski | 85a8398 | 2015-04-02 08:52:53 -0500 | [diff] [blame] | 142 | }; |
| 143 | |
Mark Lobodzinski | 2a25307 | 2015-10-08 10:44:07 -0600 | [diff] [blame] | 144 | // Track Swapchain Information |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 145 | struct MT_SWAP_CHAIN_INFO { |
Mark Lobodzinski | 2a25307 | 2015-10-08 10:44:07 -0600 | [diff] [blame] | 146 | VkSwapchainCreateInfoKHR createInfo; |
| 147 | std::vector<VkImage> images; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 148 | }; |
| 149 | |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 150 | #ifdef __cplusplus |
| 151 | } |
| 152 | #endif |