blob: 0176bd4dd3a2c94daf0db60c02e0811be208ae02 [file] [log] [blame]
Tobin Ehlise79df942014-11-18 16:38:08 -07001/*
2 * XGL
3 *
4 * Copyright (C) 2014 LunarG, Inc.
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 */
24#include "xglLayer.h"
25// Draw State ERROR codes
26typedef enum _DRAW_STATE_ERROR
27{
Tobin Ehlis84c521c2015-01-19 08:42:29 -070028 DRAWSTATE_NONE, // Used for INFO & other non-error messages
Tobin Ehlis41415bb2015-01-22 10:45:21 -070029 DRAWSTATE_INTERNAL_ERROR, // Error with DrawState internal data structures
Tobin Ehlis84c521c2015-01-19 08:42:29 -070030 DRAWSTATE_NO_PIPELINE_BOUND, // Unable to identify a bound pipeline
Tobin Ehlis41415bb2015-01-22 10:45:21 -070031 DRAWSTATE_INVALID_REGION, // Invalid DS region
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070032 DRAWSTATE_INVALID_SET, // Invalid DS
Tobin Ehlis41415bb2015-01-22 10:45:21 -070033 DRAWSTATE_INVALID_LAYOUT, // Invalid DS layout
Tobin Ehlis84c521c2015-01-19 08:42:29 -070034 DRAWSTATE_DS_END_WITHOUT_BEGIN, // EndDSUpdate called w/o corresponding BeginDSUpdate
35 DRAWSTATE_UPDATE_WITHOUT_BEGIN, // Attempt to update descriptors w/o calling BeginDescriptorRegionUpdate
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070036 DRAWSTATE_INVALID_PIPELINE, // Invalid Pipeline referenced
Tobin Ehlis8cced212015-02-13 10:26:14 -070037 DRAWSTATE_INVALID_CMD_BUFFER, // Invalid CmdBuffer referenced
Tobin Ehlis84c521c2015-01-19 08:42:29 -070038 DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, // binding in xglCmdBindVertexData() too large for PSO's pVertexBindingDescriptions array
39 DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, // Invalid dyn state object
40 DRAWSTATE_MISSING_DOT_PROGRAM, // No "dot" program in order to generate png image
41 DRAWSTATE_BINDING_DS_NO_END_UPDATE, // DS bound to CmdBuffer w/o call to xglEndDescriptorSetUpdate())
42 DRAWSTATE_NO_DS_REGION, // No DS Region is available
Tobin Ehlis41415bb2015-01-22 10:45:21 -070043 DRAWSTATE_OUT_OF_MEMORY, // malloc failed
44 DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, // Type in layout vs. update are not the same
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070045 DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, // Descriptors set for update out of bounds for corresponding layout section
Tobin Ehlis8733adc2015-02-23 16:09:58 -070046 DRAWSTATE_INVALID_UPDATE_INDEX, // Index of requested update is invalid for specified descriptors set
47 DRAWSTATE_INVALID_UPDATE_STRUCT // Struct in DS Update tree is of invalid type
Tobin Ehlise79df942014-11-18 16:38:08 -070048} DRAW_STATE_ERROR;
Tobin Ehlis26092022014-11-20 09:49:17 -070049
50typedef enum _DRAW_TYPE
51{
52 DRAW = 0,
53 DRAW_INDEXED = 1,
54 DRAW_INDIRECT = 2,
55 DRAW_INDEXED_INDIRECT = 3,
56 DRAW_BEGIN_RANGE = DRAW,
57 DRAW_END_RANGE = DRAW_INDEXED_INDIRECT,
58 NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1),
59} DRAW_TYPE;
Tobin Ehlisa701ef02014-11-27 15:43:39 -070060
Tobin Ehlis84c521c2015-01-19 08:42:29 -070061typedef struct _SHADER_DS_MAPPING {
62 uint32_t slotCount;
63 // TODO : Need to understand this with new binding model, changed to LAYOUT_CI for now
64 XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pShaderMappingSlot;
65} SHADER_DS_MAPPING;
66
Tobin Ehlis41415bb2015-01-22 10:45:21 -070067typedef struct _GENERIC_HEADER {
Tobin Ehlis84c521c2015-01-19 08:42:29 -070068 XGL_STRUCTURE_TYPE sType;
69 const void* pNext;
Tobin Ehlis41415bb2015-01-22 10:45:21 -070070} GENERIC_HEADER;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070071
72typedef struct _PIPELINE_NODE {
73 XGL_PIPELINE pipeline;
74 struct _PIPELINE_NODE *pNext;
75 XGL_GRAPHICS_PIPELINE_CREATE_INFO *pCreateTree; // Ptr to shadow of data in create tree
Tobin Ehlis84c521c2015-01-19 08:42:29 -070076 // Vtx input info (if any)
77 uint32_t vtxBindingCount; // number of bindings
78 XGL_VERTEX_INPUT_BINDING_DESCRIPTION* pVertexBindingDescriptions;
79 uint32_t vtxAttributeCount; // number of attributes
80 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* pVertexAttributeDescriptions;
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070081 uint32_t attachmentCount; // number of CB attachments
82 XGL_PIPELINE_CB_ATTACHMENT_STATE* pAttachments;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070083} PIPELINE_NODE;
84
85typedef struct _SAMPLER_NODE {
86 XGL_SAMPLER sampler;
87 XGL_SAMPLER_CREATE_INFO createInfo;
Tobin Ehlis41415bb2015-01-22 10:45:21 -070088 struct _SAMPLER_NODE* pNext;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070089} SAMPLER_NODE;
90
Tobin Ehlis41415bb2015-01-22 10:45:21 -070091typedef struct _IMAGE_NODE {
92 XGL_IMAGE_VIEW image;
93 XGL_IMAGE_VIEW_CREATE_INFO createInfo;
94 XGL_IMAGE_VIEW_ATTACH_INFO attachInfo;
95 struct _IMAGE_NODE* pNext;
96} IMAGE_NODE;
97
98typedef struct _BUFFER_NODE {
99 XGL_BUFFER_VIEW buffer;
100 XGL_BUFFER_VIEW_CREATE_INFO createInfo;
101 XGL_BUFFER_VIEW_ATTACH_INFO attachInfo;
102 struct _BUFFER_NODE* pNext;
103} BUFFER_NODE;
104
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700105typedef struct _DYNAMIC_STATE_NODE {
106 XGL_DYNAMIC_STATE_OBJECT stateObj;
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700107 GENERIC_HEADER *pCreateInfo;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700108 struct _DYNAMIC_STATE_NODE *pNext;
109} DYNAMIC_STATE_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700110// Descriptor Data structures
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700111// Layout Node has the core layout data
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700112typedef struct _LAYOUT_NODE {
113 XGL_DESCRIPTOR_SET_LAYOUT layout;
114 XGL_FLAGS stageFlags;
Tobin Ehlisd215d4b2015-02-16 14:29:30 -0700115 uint32_t shaderStageBindPoints[XGL_NUM_SHADER_STAGE];
Tobin Ehlisefa84162015-02-17 09:54:13 -0700116 XGL_DESCRIPTOR_TYPE* pTypes; // Dynamic array that will be created to verify descriptor types
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700117 const XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pCreateInfoList;
Tobin Ehlis83ebbef2015-02-10 15:35:23 -0700118 uint32_t startIndex; // 1st index of this layout
119 uint32_t endIndex; // last index of this layout
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700120 struct _LAYOUT_NODE* pPriorSetLayout; // Points to node w/ priorSetLayout
121 struct _LAYOUT_NODE* pNext; // Point to next layout in global LL chain of layouts
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700122} LAYOUT_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700123typedef struct _SET_NODE {
124 XGL_DESCRIPTOR_SET set;
125 XGL_DESCRIPTOR_REGION region;
126 XGL_DESCRIPTOR_SET_USAGE setUsage;
Tobin Ehlis82871a82015-02-19 09:55:18 -0700127 // Head of LL of all Update structs for this set
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700128 GENERIC_HEADER* pUpdateStructs;
129 // Total num of descriptors in this set (count of its layout plus all prior layouts)
130 uint32_t descriptorCount;
Tobin Ehlis82871a82015-02-19 09:55:18 -0700131 GENERIC_HEADER** ppDescriptors; // Array where each index points to update node for its slot
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700132 LAYOUT_NODE* pLayouts;
133 struct _SET_NODE* pNext;
134} SET_NODE;
135
136typedef struct _REGION_NODE {
137 XGL_DESCRIPTOR_REGION region;
138 XGL_DESCRIPTOR_REGION_USAGE regionUsage;
139 uint32_t maxSets;
140 const XGL_DESCRIPTOR_REGION_CREATE_INFO createInfo;
141 bool32_t updateActive; // Track if Region is in an update block
142 struct _REGION_NODE* pNext;
143 SET_NODE* pSets; // Head of LL of sets for this Region
144} REGION_NODE;
145
Tobin Ehlis8cced212015-02-13 10:26:14 -0700146// Cmd Buffer Tracking
147typedef enum _CMD_TYPE
148{
149 CMD_BINDPIPELINE,
150 CMD_BINDPIPELINEDELTA,
151 CMD_BINDDYNAMICSTATEOBJECT,
152 CMD_BINDDESCRIPTORSET,
153 CMD_BINDINDEXBUFFER,
154 CMD_BINDVERTEXBUFFER,
155 CMD_DRAW,
156 CMD_DRAWINDEXED,
157 CMD_DRAWINDIRECT,
158 CMD_DRAWINDEXEDINDIRECT,
159 CMD_DISPATCH,
160 CMD_DISPATCHINDIRECT,
161 CMD_COPYBUFFER,
162 CMD_COPYIMAGE,
163 CMD_COPYBUFFERTOIMAGE,
164 CMD_COPYIMAGETOBUFFER,
165 CMD_CLONEIMAGEDATA,
166 CMD_UPDATEBUFFER,
167 CMD_FILLBUFFER,
168 CMD_CLEARCOLORIMAGE,
169 CMD_CLEARCOLORIMAGERAW,
170 CMD_CLEARDEPTHSTENCIL,
171 CMD_RESOLVEIMAGE,
172 CMD_SETEVENT,
173 CMD_RESETEVENT,
174 CMD_WAITEVENTS,
175 CMD_PIPELINEBARRIER,
176 CMD_BEGINQUERY,
177 CMD_ENDQUERY,
178 CMD_RESETQUERYPOOL,
179 CMD_WRITETIMESTAMP,
180 CMD_INITATOMICCOUNTERS,
181 CMD_LOADATOMICCOUNTERS,
182 CMD_SAVEATOMICCOUNTERS,
183 CMD_BEGINRENDERPASS,
Tobin Ehlis1dae99a2015-03-02 10:16:40 -0700184 CMD_ENDRENDERPASS,
185 CMD_DBGMARKERBEGIN,
186 CMD_DBGMARKEREND,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700187} CMD_TYPE;
188// Data structure for holding sequence of cmds in cmd buffer
189typedef struct _CMD_NODE {
190 struct _CMD_NODE* pNext;
191 CMD_TYPE type;
192 uint64_t cmdNumber;
193} CMD_NODE;
194
195typedef enum _CB_STATE
196{
197 CB_NEW, // Newly created CB w/o any cmds
198 CB_UPDATE_ACTIVE, // BeginCB has been called on this CB
199 CB_UPDATE_COMPLETE // EndCB has been called on this CB
200} CB_STATE;
201// Store a single LL of command buffers
202typedef struct _GLOBAL_CB_NODE {
203 struct _GLOBAL_CB_NODE* pNextGlobalCBNode;
204 XGL_CMD_BUFFER cmdBuffer;
205 XGL_QUEUE_TYPE queueType;
206 XGL_FLAGS flags;
207 XGL_FENCE fence; // fence tracking this cmd buffer
208 uint64_t numCmds; // number of cmds in this CB
209 uint64_t drawCount[NUM_DRAW_TYPES]; // Count of each type of draw in this CB
210 CB_STATE state; // Track if cmd buffer update status
Tobin Ehlisd092d232015-02-13 13:30:07 -0700211 CMD_NODE* pCmds;
212 CMD_NODE* lastCmd;
Tobin Ehlis8cced212015-02-13 10:26:14 -0700213 // Currently storing "lastBound" objects on per-CB basis
214 // long-term may want to create caches of "lastBound" states and could have
215 // each individual CMD_NODE referencing its own "lastBound" state
216 XGL_PIPELINE lastBoundPipeline;
217 uint32_t lastVtxBinding;
218 DYNAMIC_STATE_NODE* lastBoundDynamicState[XGL_NUM_STATE_BIND_POINT];
219 XGL_DESCRIPTOR_SET lastBoundDescriptorSet;
220} GLOBAL_CB_NODE;
221
Tobin Ehlisa701ef02014-11-27 15:43:39 -0700222//prototypes for extension functions
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600223void drawStateDumpDotFile(char* outFileName);
224void drawStateDumpPngFile(char* outFileName);
Jeremy Hayes7ec63022015-02-26 15:59:19 -0700225void drawStateDumpCommandBufferDotFile(char* outFileName);
Tobin Ehlis266473d2014-12-16 17:34:50 -0700226// Func ptr typedefs
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600227typedef void (*DRAW_STATE_DUMP_DOT_FILE)(char*);
228typedef void (*DRAW_STATE_DUMP_PNG_FILE)(char*);
Jeremy Hayes7ec63022015-02-26 15:59:19 -0700229typedef void (*DRAW_STATE_DUMP_COMMAND_BUFFER_DOT_FILE)(char*);