blob: c13d95f4483ea08b7ef3800c3dc1cd694591b3cf [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
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060025#include "vkLayer.h"
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050026
27#ifdef __cplusplus
28extern "C" {
29#endif
30
Tobin Ehlis62086412014-11-19 16:19:28 -070031// Mem Tracker ERROR codes
32typedef enum _MEM_TRACK_ERROR
33{
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -050034 MEMTRACK_NONE = 0, // Used for INFO & other non-error messages
35 MEMTRACK_INVALID_CB = 1, // Cmd Buffer invalid
36 MEMTRACK_INVALID_MEM_REF = 2, // Requested mem ref is missing or invalid
37 MEMTRACK_INVALID_MEM_OBJ = 3, // Invalid Memory Object
38 MEMTRACK_INTERNAL_ERROR = 4, // Bug in Mem Track Layer internal data structures
39 MEMTRACK_CB_MISSING_FENCE = 5, // Cmd Buffer does not have fence
40 MEMTRACK_FREED_MEM_REF = 6, // MEM Obj freed while it still has obj and/or CB refs
41 MEMTRACK_MEM_OBJ_CLEAR_EMPTY_BINDINGS = 7, // Clearing bindings on mem obj that doesn't have any bindings
42 MEMTRACK_MISSING_MEM_BINDINGS = 8, // Trying to retrieve mem bindings, but none found (may be internal error)
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060043 MEMTRACK_INVALID_OBJECT = 9, // Attempting to reference generic VK Object that is invalid
44 MEMTRACK_FREE_MEM_ERROR = 10, // Error while calling vkFreeMemory
Tobin Ehlis62086412014-11-19 16:19:28 -070045 MEMTRACK_DESTROY_OBJECT_ERROR = 11, // Destroying an object that has a memory reference
46 MEMTRACK_MEMORY_BINDING_ERROR = 12, // Error during one of many calls that bind memory to object or CB
47 MEMTRACK_OUT_OF_MEMORY_ERROR = 13, // malloc failed
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060048 MEMTRACK_MEMORY_LEAK = 14, // Failure to call vkFreeMemory on Mem Obj prior to DestroyDevice
Tobin Ehlis366fbd32015-01-14 12:47:30 -070049 MEMTRACK_INVALID_STATE = 15, // Memory not in the correct state
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060050 MEMTRACK_RESET_CB_WHILE_IN_FLIGHT = 16, // vkResetCommandBuffer() called on a CB that hasn't completed
Mark Lobodzinskibe783fe2015-04-07 13:38:21 -050051 MEMTRACK_INVALID_QUEUE = 17, // Invalid queue requested or selected
Mark Lobodzinskiebe814d2015-04-07 16:07:57 -050052 MEMTRACK_INVALID_FENCE_STATE = 18, // Invalid Fence State signaled or used
Tobin Ehlis62086412014-11-19 16:19:28 -070053} MEM_TRACK_ERROR;
54
Tobin Ehlis6aa77422015-01-07 17:49:29 -070055/*
56 * Data Structure overview
Courtney Goeltzenleuchterdfd1b2a2015-04-15 00:14:36 -060057 * There are 4 global STL(' maps
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050058 * cbMap -- map of command Buffer (CB) objects to MT_CB_INFO structures
59 * Each MT_CB_INFO struct has an stl list container with
Tobin Ehlis6aa77422015-01-07 17:49:29 -070060 * memory objects that are referenced by this CB
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050061 * memObjMap -- map of Memory Objects to MT_MEM_OBJ_INFO structures
62 * Each MT_MEM_OBJ_INFO has two stl list containers with:
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050063 * -- all CBs referencing this mem obj
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -060064 * -- all VK Objects that are bound to this memory
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050065 * objectMap -- map of objects to MT_OBJ_INFO structures
Tobin Ehlis6aa77422015-01-07 17:49:29 -070066 *
67 * Algorithm overview
68 * These are the primary events that should happen related to different objects
69 * 1. Command buffers
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050070 * CREATION - Add object,structure to map
71 * CMD BIND - If mem associated, add mem reference to list container
72 * DESTROY - Remove from map, decrement (and report) mem references
Tobin Ehlis6aa77422015-01-07 17:49:29 -070073 * 2. Mem Objects
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050074 * CREATION - Add object,structure to map
75 * OBJ BIND - Add obj structure to list container for that mem node
76 * CMB BIND - If mem-related add CB structure to list container for that mem node
77 * DESTROY - Flag as errors any remaining refs and remove from map
Tobin Ehlis6aa77422015-01-07 17:49:29 -070078 * 3. Generic Objects
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050079 * 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 -050080 * DESTROY - If mem bound, remove reference list container for that memInfo, remove object ref from map
Tobin Ehlis6aa77422015-01-07 17:49:29 -070081 */
82// TODO : Is there a way to track when Cmd Buffer finishes & remove mem references at that point?
83// TODO : Could potentially store a list of freed mem allocs to flag when they're incorrectly used
84
Tobin Ehlis6aa77422015-01-07 17:49:29 -070085// Data struct for tracking memory object
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050086struct MT_MEM_OBJ_INFO {
Mark Lobodzinski15427102015-02-18 16:38:17 -060087 uint32_t refCount; // Count of references (obj bindings or CB use)
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060088 VkGpuMemory mem;
Courtney Goeltzenleuchterddcb6192015-04-14 18:48:46 -060089 VkMemoryAllocInfo allocInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060090 list<VkObject> pObjBindings; // list container of objects bound to this memory
91 list<VkCmdBuffer> pCmdBufferBindings; // list container of cmd buffers that reference this mem object
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050092};
Tobin Ehlis6aa77422015-01-07 17:49:29 -070093
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050094struct MT_OBJ_INFO {
95 MT_MEM_OBJ_INFO* pMemObjInfo;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -060096 VkObject object;
97 VkStructureType sType;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050098 uint32_t ref_count;
Tobin Ehlis6aa77422015-01-07 17:49:29 -070099 // Capture all object types that may have memory bound. From prog guide:
100 // The only objects that are guaranteed to have no external memory
101 // requirements are devices, queues, command buffers, shaders and memory objects.
102 union {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600103 VkColorAttachmentViewCreateInfo color_attachment_view_create_info;
104 VkDepthStencilViewCreateInfo ds_view_create_info;
105 VkImageViewCreateInfo image_view_create_info;
106 VkImageCreateInfo image_create_info;
107 VkGraphicsPipelineCreateInfo graphics_pipeline_create_info;
108 VkComputePipelineCreateInfo compute_pipeline_create_info;
109 VkSamplerCreateInfo sampler_create_info;
110 VkFenceCreateInfo fence_create_info;
Mark Lobodzinski15427102015-02-18 16:38:17 -0600111#ifndef _WIN32
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600112 VK_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO wsi_x11_presentable_image_create_info;
Mark Lobodzinski15427102015-02-18 16:38:17 -0600113#endif // _WIN32
Tobin Ehlis6aa77422015-01-07 17:49:29 -0700114 } create_info;
Mark Lobodzinski78a2b4b2015-02-20 16:38:40 -0600115 char object_name[64];
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500116};
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700117
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500118// Track all command buffers
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500119struct MT_CB_INFO {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600120 VkCmdBufferCreateInfo createInfo;
Courtney Goeltzenleuchter9cc421e2015-04-08 15:36:08 -0600121 MT_OBJ_INFO* pDynamicState[VK_NUM_STATE_BIND_POINT];
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600122 VkPipeline pipelines[VK_NUM_PIPELINE_BIND_POINT];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600123 uint32_t colorAttachmentCount;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600124 VkDepthStencilBindInfo dsBindInfo;
125 VkCmdBuffer cmdBuffer;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500126 uint64_t fenceId;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500127 // Order dependent, stl containers must be at end of struct
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600128 list<VkGpuMemory> pMemObjList; // List container of Mem objs referenced by this CB
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500129};
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500130
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500131// Associate fenceId with a fence object
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500132struct MT_FENCE_INFO {
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600133 VkFence fence; // Handle to fence object
134 VkQueue queue; // Queue that this fence is submitted against
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500135 bool32_t localFence; // Is fence created by layer?
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500136};
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500137
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500138// Track Queue information
139struct MT_QUEUE_INFO {
140 uint64_t lastRetiredId;
Mark Lobodzinski8ee96342015-04-02 20:49:09 -0500141 uint64_t lastSubmittedId;
Courtney Goeltzenleuchter382489d2015-04-10 08:34:15 -0600142 list<VkCmdBuffer> pQueueCmdBuffers;
143 list<VkGpuMemory> pMemRefList;
Mark Lobodzinski85a83982015-04-02 08:52:53 -0500144};
145
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500146#ifdef __cplusplus
147}
148#endif