blob: 6edee479ebc5f5a5a874979f101711803afc92f9 [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"
Tobin Ehlis63bb9482015-03-17 16:24:32 -060025#include <vector>
26
27using namespace std;
28
Tobin Ehlise79df942014-11-18 16:38:08 -070029// Draw State ERROR codes
30typedef enum _DRAW_STATE_ERROR
31{
Tobin Ehlis84c521c2015-01-19 08:42:29 -070032 DRAWSTATE_NONE, // Used for INFO & other non-error messages
Tobin Ehlis41415bb2015-01-22 10:45:21 -070033 DRAWSTATE_INTERNAL_ERROR, // Error with DrawState internal data structures
Tobin Ehlis84c521c2015-01-19 08:42:29 -070034 DRAWSTATE_NO_PIPELINE_BOUND, // Unable to identify a bound pipeline
Tobin Ehlis41415bb2015-01-22 10:45:21 -070035 DRAWSTATE_INVALID_REGION, // Invalid DS region
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070036 DRAWSTATE_INVALID_SET, // Invalid DS
Tobin Ehlis41415bb2015-01-22 10:45:21 -070037 DRAWSTATE_INVALID_LAYOUT, // Invalid DS layout
Tobin Ehlis84c521c2015-01-19 08:42:29 -070038 DRAWSTATE_DS_END_WITHOUT_BEGIN, // EndDSUpdate called w/o corresponding BeginDSUpdate
39 DRAWSTATE_UPDATE_WITHOUT_BEGIN, // Attempt to update descriptors w/o calling BeginDescriptorRegionUpdate
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070040 DRAWSTATE_INVALID_PIPELINE, // Invalid Pipeline referenced
Tobin Ehlis8cced212015-02-13 10:26:14 -070041 DRAWSTATE_INVALID_CMD_BUFFER, // Invalid CmdBuffer referenced
Tobin Ehlis84c521c2015-01-19 08:42:29 -070042 DRAWSTATE_VTX_INDEX_OUT_OF_BOUNDS, // binding in xglCmdBindVertexData() too large for PSO's pVertexBindingDescriptions array
43 DRAWSTATE_INVALID_DYNAMIC_STATE_OBJECT, // Invalid dyn state object
44 DRAWSTATE_MISSING_DOT_PROGRAM, // No "dot" program in order to generate png image
45 DRAWSTATE_BINDING_DS_NO_END_UPDATE, // DS bound to CmdBuffer w/o call to xglEndDescriptorSetUpdate())
46 DRAWSTATE_NO_DS_REGION, // No DS Region is available
Tobin Ehlis41415bb2015-01-22 10:45:21 -070047 DRAWSTATE_OUT_OF_MEMORY, // malloc failed
48 DRAWSTATE_DESCRIPTOR_TYPE_MISMATCH, // Type in layout vs. update are not the same
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070049 DRAWSTATE_DESCRIPTOR_UPDATE_OUT_OF_BOUNDS, // Descriptors set for update out of bounds for corresponding layout section
Tobin Ehlis8733adc2015-02-23 16:09:58 -070050 DRAWSTATE_INVALID_UPDATE_INDEX, // Index of requested update is invalid for specified descriptors set
51 DRAWSTATE_INVALID_UPDATE_STRUCT // Struct in DS Update tree is of invalid type
Tobin Ehlise79df942014-11-18 16:38:08 -070052} DRAW_STATE_ERROR;
Tobin Ehlis26092022014-11-20 09:49:17 -070053
54typedef enum _DRAW_TYPE
55{
56 DRAW = 0,
57 DRAW_INDEXED = 1,
58 DRAW_INDIRECT = 2,
59 DRAW_INDEXED_INDIRECT = 3,
60 DRAW_BEGIN_RANGE = DRAW,
61 DRAW_END_RANGE = DRAW_INDEXED_INDIRECT,
62 NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1),
63} DRAW_TYPE;
Tobin Ehlisa701ef02014-11-27 15:43:39 -070064
Tobin Ehlis84c521c2015-01-19 08:42:29 -070065typedef struct _SHADER_DS_MAPPING {
66 uint32_t slotCount;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070067 XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pShaderMappingSlot;
68} SHADER_DS_MAPPING;
69
Tobin Ehlis41415bb2015-01-22 10:45:21 -070070typedef struct _GENERIC_HEADER {
Tobin Ehlis84c521c2015-01-19 08:42:29 -070071 XGL_STRUCTURE_TYPE sType;
72 const void* pNext;
Tobin Ehlis41415bb2015-01-22 10:45:21 -070073} GENERIC_HEADER;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070074
75typedef struct _PIPELINE_NODE {
76 XGL_PIPELINE pipeline;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070077 XGL_GRAPHICS_PIPELINE_CREATE_INFO *pCreateTree; // Ptr to shadow of data in create tree
Tobin Ehlis84c521c2015-01-19 08:42:29 -070078 // Vtx input info (if any)
79 uint32_t vtxBindingCount; // number of bindings
80 XGL_VERTEX_INPUT_BINDING_DESCRIPTION* pVertexBindingDescriptions;
81 uint32_t vtxAttributeCount; // number of attributes
82 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* pVertexAttributeDescriptions;
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070083 uint32_t attachmentCount; // number of CB attachments
84 XGL_PIPELINE_CB_ATTACHMENT_STATE* pAttachments;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070085} PIPELINE_NODE;
86
87typedef struct _SAMPLER_NODE {
88 XGL_SAMPLER sampler;
89 XGL_SAMPLER_CREATE_INFO createInfo;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070090} SAMPLER_NODE;
91
Tobin Ehlis41415bb2015-01-22 10:45:21 -070092typedef struct _IMAGE_NODE {
93 XGL_IMAGE_VIEW image;
94 XGL_IMAGE_VIEW_CREATE_INFO createInfo;
95 XGL_IMAGE_VIEW_ATTACH_INFO attachInfo;
Tobin Ehlis41415bb2015-01-22 10:45:21 -070096} 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;
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700102} BUFFER_NODE;
103
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700104typedef struct _DYNAMIC_STATE_NODE {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600105 XGL_DYNAMIC_STATE_OBJECT stateObj;
106 GENERIC_HEADER* pCreateInfo;
107 union {
108 XGL_DYNAMIC_VP_STATE_CREATE_INFO vpci;
109 XGL_DYNAMIC_RS_STATE_CREATE_INFO rsci;
110 XGL_DYNAMIC_CB_STATE_CREATE_INFO cbci;
111 XGL_DYNAMIC_DS_STATE_CREATE_INFO dsci;
112 } create_info;
113 //struct _DYNAMIC_STATE_NODE* pNext;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700114} DYNAMIC_STATE_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700115// Descriptor Data structures
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700116// Layout Node has the core layout data
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700117typedef struct _LAYOUT_NODE {
118 XGL_DESCRIPTOR_SET_LAYOUT layout;
119 XGL_FLAGS stageFlags;
Tobin Ehlisd215d4b2015-02-16 14:29:30 -0700120 uint32_t shaderStageBindPoints[XGL_NUM_SHADER_STAGE];
Tobin Ehlisefa84162015-02-17 09:54:13 -0700121 XGL_DESCRIPTOR_TYPE* pTypes; // Dynamic array that will be created to verify descriptor types
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600122 XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pCreateInfoList;
Tobin Ehlis83ebbef2015-02-10 15:35:23 -0700123 uint32_t startIndex; // 1st index of this layout
124 uint32_t endIndex; // last index of this layout
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700125 struct _LAYOUT_NODE* pPriorSetLayout; // Points to node w/ priorSetLayout
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700126} LAYOUT_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700127typedef struct _SET_NODE {
128 XGL_DESCRIPTOR_SET set;
129 XGL_DESCRIPTOR_REGION region;
130 XGL_DESCRIPTOR_SET_USAGE setUsage;
Tobin Ehlis82871a82015-02-19 09:55:18 -0700131 // Head of LL of all Update structs for this set
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700132 GENERIC_HEADER* pUpdateStructs;
133 // Total num of descriptors in this set (count of its layout plus all prior layouts)
134 uint32_t descriptorCount;
Tobin Ehlis82871a82015-02-19 09:55:18 -0700135 GENERIC_HEADER** ppDescriptors; // Array where each index points to update node for its slot
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700136 LAYOUT_NODE* pLayouts;
137 struct _SET_NODE* pNext;
138} SET_NODE;
139
140typedef struct _REGION_NODE {
141 XGL_DESCRIPTOR_REGION region;
142 XGL_DESCRIPTOR_REGION_USAGE regionUsage;
143 uint32_t maxSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600144 XGL_DESCRIPTOR_REGION_CREATE_INFO createInfo;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700145 bool32_t updateActive; // Track if Region is in an update block
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700146 SET_NODE* pSets; // Head of LL of sets for this Region
147} REGION_NODE;
148
Tobin Ehlis8cced212015-02-13 10:26:14 -0700149// Cmd Buffer Tracking
150typedef enum _CMD_TYPE
151{
152 CMD_BINDPIPELINE,
153 CMD_BINDPIPELINEDELTA,
154 CMD_BINDDYNAMICSTATEOBJECT,
155 CMD_BINDDESCRIPTORSET,
156 CMD_BINDINDEXBUFFER,
157 CMD_BINDVERTEXBUFFER,
158 CMD_DRAW,
159 CMD_DRAWINDEXED,
160 CMD_DRAWINDIRECT,
161 CMD_DRAWINDEXEDINDIRECT,
162 CMD_DISPATCH,
163 CMD_DISPATCHINDIRECT,
164 CMD_COPYBUFFER,
165 CMD_COPYIMAGE,
166 CMD_COPYBUFFERTOIMAGE,
167 CMD_COPYIMAGETOBUFFER,
168 CMD_CLONEIMAGEDATA,
169 CMD_UPDATEBUFFER,
170 CMD_FILLBUFFER,
171 CMD_CLEARCOLORIMAGE,
172 CMD_CLEARCOLORIMAGERAW,
173 CMD_CLEARDEPTHSTENCIL,
174 CMD_RESOLVEIMAGE,
175 CMD_SETEVENT,
176 CMD_RESETEVENT,
177 CMD_WAITEVENTS,
178 CMD_PIPELINEBARRIER,
179 CMD_BEGINQUERY,
180 CMD_ENDQUERY,
181 CMD_RESETQUERYPOOL,
182 CMD_WRITETIMESTAMP,
183 CMD_INITATOMICCOUNTERS,
184 CMD_LOADATOMICCOUNTERS,
185 CMD_SAVEATOMICCOUNTERS,
186 CMD_BEGINRENDERPASS,
Tobin Ehlis1dae99a2015-03-02 10:16:40 -0700187 CMD_ENDRENDERPASS,
188 CMD_DBGMARKERBEGIN,
189 CMD_DBGMARKEREND,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700190} CMD_TYPE;
191// Data structure for holding sequence of cmds in cmd buffer
192typedef struct _CMD_NODE {
Tobin Ehlis8cced212015-02-13 10:26:14 -0700193 CMD_TYPE type;
194 uint64_t cmdNumber;
195} CMD_NODE;
196
197typedef enum _CB_STATE
198{
199 CB_NEW, // Newly created CB w/o any cmds
200 CB_UPDATE_ACTIVE, // BeginCB has been called on this CB
201 CB_UPDATE_COMPLETE // EndCB has been called on this CB
202} CB_STATE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600203// Cmd Buffer Wrapper Struct
Tobin Ehlis8cced212015-02-13 10:26:14 -0700204typedef struct _GLOBAL_CB_NODE {
Tobin Ehlis8cced212015-02-13 10:26:14 -0700205 XGL_CMD_BUFFER cmdBuffer;
206 XGL_QUEUE_TYPE queueType;
207 XGL_FLAGS flags;
208 XGL_FENCE fence; // fence tracking this cmd buffer
209 uint64_t numCmds; // number of cmds in this CB
210 uint64_t drawCount[NUM_DRAW_TYPES]; // Count of each type of draw in this CB
211 CB_STATE state; // Track if cmd buffer update status
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600212 vector<CMD_NODE*> pCmds;
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*);