blob: 1159c850d709b13935e809d9e1e32720da70422e [file] [log] [blame]
Tobin Ehlis62086412014-11-19 16:19:28 -07001/*
2 * XGL
3 *
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
Tobin Ehlis62086412014-11-19 16:19:28 -070025#include "xglLayer.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{
34 MEMTRACK_NONE = 0, // Used for INFO & other non-error messages
35 MEMTRACK_INVALID_CB = 1, // Cmd Buffer invalid
36 MEMTRACK_CB_MISSING_MEM_REF = 2, // pMemRefs for CB is missing a mem ref
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)
43 MEMTRACK_INVALID_OBJECT = 9, // Attempting to reference generic XGL Object that is invalid
44 MEMTRACK_FREE_MEM_ERROR = 10, // Error while calling xglFreeMemory
45 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
Tobin Ehlis22d03232014-11-25 18:01:12 -070048 MEMTRACK_MEMORY_LEAK = 14, // Failure to call xglFreeMemory on Mem Obj prior to DestroyDevice
Tobin Ehlis366fbd32015-01-14 12:47:30 -070049 MEMTRACK_INVALID_STATE = 15, // Memory not in the correct state
Tobin Ehlis77b3abb2015-03-04 08:38:22 -070050 MEMTRACK_RESET_CB_WHILE_IN_FLIGHT = 16, // xglResetCommandBuffer() called on a CB that hasn't completed
Tobin Ehlis62086412014-11-19 16:19:28 -070051} MEM_TRACK_ERROR;
52
Tobin Ehlis6aa77422015-01-07 17:49:29 -070053/*
54 * Data Structure overview
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050055 * There are 4 global STL maps
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050056 * cbMap -- map of command Buffer (CB) objects to MT_CB_INFO structures
57 * Each MT_CB_INFO struct has an stl list container with
Tobin Ehlis6aa77422015-01-07 17:49:29 -070058 * memory objects that are referenced by this CB
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050059 * memObjMap -- map of Memory Objects to MT_MEM_OBJ_INFO structures
60 * Each MT_MEM_OBJ_INFO has two stl list containers with:
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050061 * -- all CBs referencing this mem obj
62 * -- all XGL Objects that are bound to this memory
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050063 * objectMap -- map of objects to MT_OBJ_INFO structures
Tobin Ehlis6aa77422015-01-07 17:49:29 -070064 *
65 * Algorithm overview
66 * These are the primary events that should happen related to different objects
67 * 1. Command buffers
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050068 * CREATION - Add object,structure to map
69 * CMD BIND - If mem associated, add mem reference to list container
70 * DESTROY - Remove from map, decrement (and report) mem references
Tobin Ehlis6aa77422015-01-07 17:49:29 -070071 * 2. Mem Objects
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050072 * CREATION - Add object,structure to map
73 * OBJ BIND - Add obj structure to list container for that mem node
74 * CMB BIND - If mem-related add CB structure to list container for that mem node
75 * DESTROY - Flag as errors any remaining refs and remove from map
Tobin Ehlis6aa77422015-01-07 17:49:29 -070076 * 3. Generic Objects
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050077 * 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 -050078 * DESTROY - If mem bound, remove reference list container for that memInfo, remove object ref from map
Tobin Ehlis6aa77422015-01-07 17:49:29 -070079 */
80// TODO : Is there a way to track when Cmd Buffer finishes & remove mem references at that point?
81// TODO : Could potentially store a list of freed mem allocs to flag when they're incorrectly used
82
Tobin Ehlis6aa77422015-01-07 17:49:29 -070083// Data struct for tracking memory object
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050084struct MT_MEM_OBJ_INFO {
Mark Lobodzinski15427102015-02-18 16:38:17 -060085 uint32_t refCount; // Count of references (obj bindings or CB use)
86 XGL_GPU_MEMORY mem;
87 XGL_MEMORY_ALLOC_INFO allocInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050088 list<XGL_OBJECT> pObjBindings; // list container of objects bound to this memory
89 list<XGL_CMD_BUFFER> pCmdBufferBindings; // list container of cmd buffers that reference this mem object
90};
Tobin Ehlis6aa77422015-01-07 17:49:29 -070091
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -050092struct MT_OBJ_INFO {
93 MT_MEM_OBJ_INFO* pMemObjInfo;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -050094 XGL_OBJECT object;
95 XGL_STRUCTURE_TYPE sType;
96 uint32_t ref_count;
Tobin Ehlis6aa77422015-01-07 17:49:29 -070097 // Capture all object types that may have memory bound. From prog guide:
98 // The only objects that are guaranteed to have no external memory
99 // requirements are devices, queues, command buffers, shaders and memory objects.
100 union {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500101 XGL_COLOR_ATTACHMENT_VIEW_CREATE_INFO color_attachment_view_create_info;
102 XGL_DEPTH_STENCIL_VIEW_CREATE_INFO ds_view_create_info;
103 XGL_IMAGE_VIEW_CREATE_INFO image_view_create_info;
104 XGL_IMAGE_CREATE_INFO image_create_info;
105 XGL_GRAPHICS_PIPELINE_CREATE_INFO graphics_pipeline_create_info;
106 XGL_COMPUTE_PIPELINE_CREATE_INFO compute_pipeline_create_info;
107 XGL_SAMPLER_CREATE_INFO sampler_create_info;
108 XGL_FENCE_CREATE_INFO fence_create_info;
Mark Lobodzinski15427102015-02-18 16:38:17 -0600109#ifndef _WIN32
Tobin Ehlis6aa77422015-01-07 17:49:29 -0700110 XGL_WSI_X11_PRESENTABLE_IMAGE_CREATE_INFO wsi_x11_presentable_image_create_info;
Mark Lobodzinski15427102015-02-18 16:38:17 -0600111#endif // _WIN32
Tobin Ehlis6aa77422015-01-07 17:49:29 -0700112 } create_info;
Mark Lobodzinski78a2b4b2015-02-20 16:38:40 -0600113 char object_name[64];
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500114};
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700115
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500116// Track all command buffers
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500117struct MT_CB_INFO {
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700118 XGL_CMD_BUFFER_CREATE_INFO createInfo;
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500119 MT_OBJ_INFO* pDynamicState[XGL_NUM_STATE_BIND_POINT];
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700120 XGL_PIPELINE pipelines[XGL_NUM_PIPELINE_BIND_POINT];
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600121 uint32_t colorAttachmentCount;
Tobin Ehlis2836a7d2015-01-08 15:22:32 -0700122 XGL_DEPTH_STENCIL_BIND_INFO dsBindInfo;
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500123 XGL_CMD_BUFFER cmdBuffer;
124 uint64_t fenceId;
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500125 // Order dependent, stl containers must be at end of struct
126 list<XGL_GPU_MEMORY> pMemObjList; // List container of Mem objs referenced by this CB
127};
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500128
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500129// Associate fenceId with a fence object
Mark Lobodzinski7a428ce2015-03-31 16:05:35 -0500130struct MT_FENCE_INFO {
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500131 XGL_FENCE fence;
132 bool32_t localFence;
133};
Mark Lobodzinski4aad3642015-03-17 10:53:12 -0500134
Mark Lobodzinski283a4c22015-03-24 16:29:24 -0500135#ifdef __cplusplus
136}
137#endif