blob: 4a85b8455b3815c08042938d05ced8696186983e [file] [log] [blame]
Tobin Ehlis62086412014-11-19 16:19:28 -07001/*
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -06002 * Vulkan
Tobin Ehlis62086412014-11-19 16:19:28 -07003 *
Mark Lobodzinski283a4c22015-03-24 16:29:24 -05004 * Copyright (C) 2015 LunarG, Inc.
Tobin Ehlis62086412014-11-19 16:19:28 -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
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 Lobodzinski283a4c22015-03-24 16:29:24 -050024#pragma once
Chia-I Wu5b66aa52015-04-16 22:02:10 +080025#include <vector>
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060026#include "vkLayer.h"
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050027
28#ifdef __cplusplus
29extern "C" {
30#endif
31
Tobin Ehlis62086412014-11-19 16:19:28 -070032// Mem Tracker ERROR codes
33typedef enum _MEM_TRACK_ERROR
34{
Mark Lobodzinskic66c6712015-06-05 13:59:04 -050035 MEMTRACK_NONE, // Used for INFO & other non-error messages
36 MEMTRACK_INVALID_CB, // Cmd Buffer invalid
37 MEMTRACK_INVALID_MEM_OBJ, // Invalid Memory Object
38 MEMTRACK_INTERNAL_ERROR, // Bug in Mem Track Layer internal data structures
39 MEMTRACK_FREED_MEM_REF, // MEM Obj freed while it still has obj and/or CB refs
40 MEMTRACK_MEM_OBJ_CLEAR_EMPTY_BINDINGS, // Clearing bindings on mem obj that doesn't have any bindings
41 MEMTRACK_MISSING_MEM_BINDINGS, // Trying to retrieve mem bindings, but none found (may be internal error)
42 MEMTRACK_INVALID_OBJECT, // Attempting to reference generic VK Object that is invalid
43 MEMTRACK_DESTROY_OBJECT_ERROR, // Destroying an object that has a memory reference
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 Ehlis62086412014-11-19 16:19:28 -070050} MEM_TRACK_ERROR;
51
Tobin Ehlis6aa77422015-01-07 17:49:29 -070052/*
53 * Data Structure overview
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -060054 * There are 4 global STL(' maps
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050055 * cbMap -- map of command Buffer (CB) objects to MT_CB_INFO structures
56 * Each MT_CB_INFO struct has an stl list container with
Tobin Ehlis6aa77422015-01-07 17:49:29 -070057 * memory objects that are referenced by this CB
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050058 * memObjMap -- map of Memory Objects to MT_MEM_OBJ_INFO structures
59 * Each MT_MEM_OBJ_INFO has two stl list containers with:
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050060 * -- all CBs referencing this mem obj
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060061 * -- all VK Objects that are bound to this memory
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050062 * objectMap -- map of objects to MT_OBJ_INFO structures
Tobin Ehlis6aa77422015-01-07 17:49:29 -070063 *
64 * Algorithm overview
65 * These are the primary events that should happen related to different objects
66 * 1. Command buffers
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050067 * CREATION - Add object,structure to map
68 * CMD BIND - If mem associated, add mem reference to list container
69 * DESTROY - Remove from map, decrement (and report) mem references
Tobin Ehlis6aa77422015-01-07 17:49:29 -070070 * 2. Mem Objects
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050071 * CREATION - Add object,structure to map
72 * OBJ BIND - Add obj structure to list container for that mem node
73 * CMB BIND - If mem-related add CB structure to list container for that mem node
74 * DESTROY - Flag as errors any remaining refs and remove from map
Tobin Ehlis6aa77422015-01-07 17:49:29 -070075 * 3. Generic Objects
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050076 * MEM BIND - DESTROY any previous binding, Add obj node w/ ref to map, add obj ref to list container for that mem node
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050077 * DESTROY - If mem bound, remove reference list container for that memInfo, remove object ref from map
Tobin Ehlis6aa77422015-01-07 17:49:29 -070078 */
79// TODO : Is there a way to track when Cmd Buffer finishes & remove mem references at that point?
80// TODO : Could potentially store a list of freed mem allocs to flag when they're incorrectly used
81
Tobin Ehlis6aa77422015-01-07 17:49:29 -070082// Data struct for tracking memory object
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050083struct MT_MEM_OBJ_INFO {
Mark Lobodzinskia908b162015-04-21 15:33:04 -060084 uint32_t refCount; // Count of references (obj bindings or CB use)
85 VkDeviceMemory mem;
86 VkMemoryAllocInfo allocInfo;
87 list<VkObject> pObjBindings; // list container of objects bound to this memory
88 list<VkCmdBuffer> pCmdBufferBindings; // list container of cmd buffers that reference this mem object
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050089};
Tobin Ehlis6aa77422015-01-07 17:49:29 -070090
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050091struct MT_OBJ_INFO {
Mark Lobodzinskia908b162015-04-21 15:33:04 -060092 MT_MEM_OBJ_INFO* pMemObjInfo;
93 VkObject object;
94 VkStructureType sType;
95 uint32_t ref_count;
Tobin Ehlis6aa77422015-01-07 17:49:29 -070096 // Capture all object types that may have memory bound. From prog guide:
97 // The only objects that are guaranteed to have no external memory
Mark Lobodzinskia908b162015-04-21 15:33:04 -060098 // requirements are devices, queues, command buffers, shaders and memory objects.
Tobin Ehlis6aa77422015-01-07 17:49:29 -070099 union {
Mark Lobodzinskia908b162015-04-21 15:33:04 -0600100 VkColorAttachmentViewCreateInfo color_attachment_view_create_info;
101 VkDepthStencilViewCreateInfo ds_view_create_info;
102 VkImageViewCreateInfo image_view_create_info;
103 VkImageCreateInfo image_create_info;
104 VkGraphicsPipelineCreateInfo graphics_pipeline_create_info;
105 VkComputePipelineCreateInfo compute_pipeline_create_info;
106 VkSamplerCreateInfo sampler_create_info;
107 VkFenceCreateInfo fence_create_info;
108 VkSwapChainCreateInfoWSI swap_chain_create_info;
Tobin Ehlis6aa77422015-01-07 17:49:29 -0700109 } create_info;
Mark Lobodzinski78a2b4b2015-02-20 16:38:40 -0600110 char object_name[64];
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500111};
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700112
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500113// Track all command buffers
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500114struct MT_CB_INFO {
Mark Lobodzinskia908b162015-04-21 15:33:04 -0600115 VkCmdBufferCreateInfo createInfo;
116 MT_OBJ_INFO* pDynamicState[VK_NUM_STATE_BIND_POINT];
117 VkPipeline pipelines[VK_NUM_PIPELINE_BIND_POINT];
118 uint32_t colorAttachmentCount;
119 VkDepthStencilBindInfo dsBindInfo;
120 VkCmdBuffer cmdBuffer;
121 uint64_t fenceId;
Mike Stroyan53430332015-05-19 15:16:08 -0600122 VkFence lastSubmittedFence;
123 VkQueue lastSubmittedQueue;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500124 // Order dependent, stl containers must be at end of struct
Mark Lobodzinskia908b162015-04-21 15:33:04 -0600125 list<VkDeviceMemory> pMemObjList; // List container of Mem objs referenced by this CB
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500126};
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500127
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500128// Associate fenceId with a fence object
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500129struct MT_FENCE_INFO {
Mike Stroyan53430332015-05-19 15:16:08 -0600130 uint64_t fenceId; // Sequence number for fence at last submit
131 VkQueue queue; // Queue that this fence is submitted against or NULL
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500132};
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500133
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500134// Track Queue information
135struct MT_QUEUE_INFO {
Mark Lobodzinskia908b162015-04-21 15:33:04 -0600136 uint64_t lastRetiredId;
137 uint64_t lastSubmittedId;
138 list<VkCmdBuffer> pQueueCmdBuffers;
139 list<VkDeviceMemory> pMemRefList;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500140};
141
Chia-I Wu5b66aa52015-04-16 22:02:10 +0800142struct MT_SWAP_CHAIN_INFO {
Mark Lobodzinskia908b162015-04-21 15:33:04 -0600143 VkSwapChainCreateInfoWSI createInfo;
Chia-I Wu5b66aa52015-04-16 22:02:10 +0800144 std::vector<VkSwapChainImageInfoWSI> images;
145};
146
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500147#ifdef __cplusplus
148}
149#endif