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> |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 26 | #include "vkLayer.h" |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 27 | |
| 28 | #ifdef __cplusplus |
| 29 | extern "C" { |
| 30 | #endif |
| 31 | |
Tobin Ehlis | 6208641 | 2014-11-19 16:19:28 -0700 | [diff] [blame] | 32 | // Mem Tracker ERROR codes |
| 33 | typedef enum _MEM_TRACK_ERROR |
| 34 | { |
Mark Lobodzinski | be783fe | 2015-04-07 13:38:21 -0500 | [diff] [blame] | 35 | MEMTRACK_NONE = 0, // Used for INFO & other non-error messages |
| 36 | MEMTRACK_INVALID_CB = 1, // Cmd Buffer invalid |
| 37 | MEMTRACK_INVALID_MEM_REF = 2, // Requested mem ref is missing or invalid |
| 38 | MEMTRACK_INVALID_MEM_OBJ = 3, // Invalid Memory Object |
| 39 | MEMTRACK_INTERNAL_ERROR = 4, // Bug in Mem Track Layer internal data structures |
| 40 | MEMTRACK_CB_MISSING_FENCE = 5, // Cmd Buffer does not have fence |
| 41 | MEMTRACK_FREED_MEM_REF = 6, // MEM Obj freed while it still has obj and/or CB refs |
| 42 | MEMTRACK_MEM_OBJ_CLEAR_EMPTY_BINDINGS = 7, // Clearing bindings on mem obj that doesn't have any bindings |
| 43 | MEMTRACK_MISSING_MEM_BINDINGS = 8, // Trying to retrieve mem bindings, but none found (may be internal error) |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 44 | MEMTRACK_INVALID_OBJECT = 9, // Attempting to reference generic VK Object that is invalid |
| 45 | MEMTRACK_FREE_MEM_ERROR = 10, // Error while calling vkFreeMemory |
Tobin Ehlis | 6208641 | 2014-11-19 16:19:28 -0700 | [diff] [blame] | 46 | MEMTRACK_DESTROY_OBJECT_ERROR = 11, // Destroying an object that has a memory reference |
| 47 | MEMTRACK_MEMORY_BINDING_ERROR = 12, // Error during one of many calls that bind memory to object or CB |
| 48 | MEMTRACK_OUT_OF_MEMORY_ERROR = 13, // malloc failed |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 49 | MEMTRACK_MEMORY_LEAK = 14, // Failure to call vkFreeMemory on Mem Obj prior to DestroyDevice |
Tobin Ehlis | 366fbd3 | 2015-01-14 12:47:30 -0700 | [diff] [blame] | 50 | MEMTRACK_INVALID_STATE = 15, // Memory not in the correct state |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 51 | MEMTRACK_RESET_CB_WHILE_IN_FLIGHT = 16, // vkResetCommandBuffer() called on a CB that hasn't completed |
Mark Lobodzinski | be783fe | 2015-04-07 13:38:21 -0500 | [diff] [blame] | 52 | MEMTRACK_INVALID_QUEUE = 17, // Invalid queue requested or selected |
Mark Lobodzinski | ebe814d | 2015-04-07 16:07:57 -0500 | [diff] [blame] | 53 | MEMTRACK_INVALID_FENCE_STATE = 18, // Invalid Fence State signaled or used |
Tobin Ehlis | 6208641 | 2014-11-19 16:19:28 -0700 | [diff] [blame] | 54 | } MEM_TRACK_ERROR; |
| 55 | |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 56 | /* |
| 57 | * Data Structure overview |
Courtney Goeltzenleuchter | dfd1b2a | 2015-04-15 00:14:36 -0600 | [diff] [blame] | 58 | * There are 4 global STL(' maps |
Mark Lobodzinski | 7a428ce | 2015-03-31 16:05:35 -0500 | [diff] [blame] | 59 | * cbMap -- map of command Buffer (CB) objects to MT_CB_INFO structures |
| 60 | * Each MT_CB_INFO struct has an stl list container with |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 61 | * memory objects that are referenced by this CB |
Mark Lobodzinski | 7a428ce | 2015-03-31 16:05:35 -0500 | [diff] [blame] | 62 | * memObjMap -- map of Memory Objects to MT_MEM_OBJ_INFO structures |
| 63 | * Each MT_MEM_OBJ_INFO has two stl list containers with: |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 64 | * -- all CBs referencing this mem obj |
Courtney Goeltzenleuchter | 9cc421e | 2015-04-08 15:36:08 -0600 | [diff] [blame] | 65 | * -- all VK Objects that are bound to this memory |
Mark Lobodzinski | 7a428ce | 2015-03-31 16:05:35 -0500 | [diff] [blame] | 66 | * objectMap -- map of objects to MT_OBJ_INFO structures |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 67 | * |
| 68 | * Algorithm overview |
| 69 | * These are the primary events that should happen related to different objects |
| 70 | * 1. Command buffers |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 71 | * CREATION - Add object,structure to map |
| 72 | * CMD BIND - If mem associated, add mem reference to list container |
| 73 | * DESTROY - Remove from map, decrement (and report) mem references |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 74 | * 2. Mem Objects |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 75 | * CREATION - Add object,structure to map |
| 76 | * OBJ BIND - Add obj structure to list container for that mem node |
| 77 | * CMB BIND - If mem-related add CB structure to list container for that mem node |
| 78 | * DESTROY - Flag as errors any remaining refs and remove from map |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 79 | * 3. Generic Objects |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 80 | * 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] | 81 | * 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] | 82 | */ |
| 83 | // TODO : Is there a way to track when Cmd Buffer finishes & remove mem references at that point? |
| 84 | // TODO : Could potentially store a list of freed mem allocs to flag when they're incorrectly used |
| 85 | |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 86 | // Data struct for tracking memory object |
Mark Lobodzinski | 7a428ce | 2015-03-31 16:05:35 -0500 | [diff] [blame] | 87 | struct MT_MEM_OBJ_INFO { |
Mark Lobodzinski | a908b16 | 2015-04-21 15:33:04 -0600 | [diff] [blame] | 88 | uint32_t refCount; // Count of references (obj bindings or CB use) |
| 89 | VkDeviceMemory mem; |
| 90 | VkMemoryAllocInfo allocInfo; |
| 91 | list<VkObject> pObjBindings; // list container of objects bound to this memory |
| 92 | 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] | 93 | }; |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 94 | |
Mark Lobodzinski | 7a428ce | 2015-03-31 16:05:35 -0500 | [diff] [blame] | 95 | struct MT_OBJ_INFO { |
Mark Lobodzinski | a908b16 | 2015-04-21 15:33:04 -0600 | [diff] [blame] | 96 | MT_MEM_OBJ_INFO* pMemObjInfo; |
| 97 | VkObject object; |
| 98 | VkStructureType sType; |
| 99 | uint32_t ref_count; |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 100 | // Capture all object types that may have memory bound. From prog guide: |
| 101 | // The only objects that are guaranteed to have no external memory |
Mark Lobodzinski | a908b16 | 2015-04-21 15:33:04 -0600 | [diff] [blame] | 102 | // requirements are devices, queues, command buffers, shaders and memory objects. |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 103 | union { |
Mark Lobodzinski | a908b16 | 2015-04-21 15:33:04 -0600 | [diff] [blame] | 104 | VkColorAttachmentViewCreateInfo color_attachment_view_create_info; |
| 105 | VkDepthStencilViewCreateInfo ds_view_create_info; |
| 106 | VkImageViewCreateInfo image_view_create_info; |
| 107 | VkImageCreateInfo image_create_info; |
| 108 | VkGraphicsPipelineCreateInfo graphics_pipeline_create_info; |
| 109 | VkComputePipelineCreateInfo compute_pipeline_create_info; |
| 110 | VkSamplerCreateInfo sampler_create_info; |
| 111 | VkFenceCreateInfo fence_create_info; |
| 112 | VkSwapChainCreateInfoWSI swap_chain_create_info; |
Tobin Ehlis | 6aa7742 | 2015-01-07 17:49:29 -0700 | [diff] [blame] | 113 | } create_info; |
Mark Lobodzinski | 78a2b4b | 2015-02-20 16:38:40 -0600 | [diff] [blame] | 114 | char object_name[64]; |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 115 | }; |
Tobin Ehlis | 2836a7d | 2015-01-08 15:22:32 -0700 | [diff] [blame] | 116 | |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 117 | // Track all command buffers |
Mark Lobodzinski | 7a428ce | 2015-03-31 16:05:35 -0500 | [diff] [blame] | 118 | struct MT_CB_INFO { |
Mark Lobodzinski | a908b16 | 2015-04-21 15:33:04 -0600 | [diff] [blame] | 119 | VkCmdBufferCreateInfo createInfo; |
| 120 | MT_OBJ_INFO* pDynamicState[VK_NUM_STATE_BIND_POINT]; |
| 121 | VkPipeline pipelines[VK_NUM_PIPELINE_BIND_POINT]; |
| 122 | uint32_t colorAttachmentCount; |
| 123 | VkDepthStencilBindInfo dsBindInfo; |
| 124 | VkCmdBuffer cmdBuffer; |
| 125 | uint64_t fenceId; |
Mike Stroyan | 5343033 | 2015-05-19 15:16:08 -0600 | [diff] [blame] | 126 | VkFence lastSubmittedFence; |
| 127 | VkQueue lastSubmittedQueue; |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 128 | // Order dependent, stl containers must be at end of struct |
Mark Lobodzinski | a908b16 | 2015-04-21 15:33:04 -0600 | [diff] [blame] | 129 | list<VkDeviceMemory> pMemObjList; // List container of Mem objs referenced by this CB |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 130 | }; |
Mark Lobodzinski | 4aad364 | 2015-03-17 10:53:12 -0500 | [diff] [blame] | 131 | |
Mark Lobodzinski | 85a8398 | 2015-04-02 08:52:53 -0500 | [diff] [blame] | 132 | // Associate fenceId with a fence object |
Mark Lobodzinski | 7a428ce | 2015-03-31 16:05:35 -0500 | [diff] [blame] | 133 | struct MT_FENCE_INFO { |
Mike Stroyan | 5343033 | 2015-05-19 15:16:08 -0600 | [diff] [blame] | 134 | uint64_t fenceId; // Sequence number for fence at last submit |
| 135 | VkQueue queue; // Queue that this fence is submitted against or NULL |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 136 | }; |
Mark Lobodzinski | 4aad364 | 2015-03-17 10:53:12 -0500 | [diff] [blame] | 137 | |
Mark Lobodzinski | 85a8398 | 2015-04-02 08:52:53 -0500 | [diff] [blame] | 138 | // Track Queue information |
| 139 | struct MT_QUEUE_INFO { |
Mark Lobodzinski | a908b16 | 2015-04-21 15:33:04 -0600 | [diff] [blame] | 140 | uint64_t lastRetiredId; |
| 141 | uint64_t lastSubmittedId; |
| 142 | list<VkCmdBuffer> pQueueCmdBuffers; |
| 143 | list<VkDeviceMemory> pMemRefList; |
Mark Lobodzinski | 85a8398 | 2015-04-02 08:52:53 -0500 | [diff] [blame] | 144 | }; |
| 145 | |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 146 | struct MT_SWAP_CHAIN_INFO { |
Mark Lobodzinski | a908b16 | 2015-04-21 15:33:04 -0600 | [diff] [blame] | 147 | VkSwapChainCreateInfoWSI createInfo; |
Chia-I Wu | 5b66aa5 | 2015-04-16 22:02:10 +0800 | [diff] [blame] | 148 | std::vector<VkSwapChainImageInfoWSI> images; |
| 149 | }; |
| 150 | |
Mark Lobodzinski | 283a4c2 | 2015-03-24 16:29:24 -0500 | [diff] [blame] | 151 | #ifdef __cplusplus |
| 152 | } |
| 153 | #endif |