blob: 332fa0c761176266e9d824a7cf56807abd140161 [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
Tobin Ehlis2464b882015-04-01 08:40:34 -060051 DRAWSTATE_INVALID_UPDATE_STRUCT, // Struct in DS Update tree is of invalid type
52 DRAWSTATE_NUM_SAMPLES_MISMATCH // Number of samples in bound PSO does not match number in FB of current RenderPass
Tobin Ehlise79df942014-11-18 16:38:08 -070053} DRAW_STATE_ERROR;
Tobin Ehlis26092022014-11-20 09:49:17 -070054
55typedef enum _DRAW_TYPE
56{
57 DRAW = 0,
58 DRAW_INDEXED = 1,
59 DRAW_INDIRECT = 2,
60 DRAW_INDEXED_INDIRECT = 3,
61 DRAW_BEGIN_RANGE = DRAW,
62 DRAW_END_RANGE = DRAW_INDEXED_INDIRECT,
63 NUM_DRAW_TYPES = (DRAW_END_RANGE - DRAW_BEGIN_RANGE + 1),
64} DRAW_TYPE;
Tobin Ehlisa701ef02014-11-27 15:43:39 -070065
Tobin Ehlis84c521c2015-01-19 08:42:29 -070066typedef struct _SHADER_DS_MAPPING {
67 uint32_t slotCount;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070068 XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pShaderMappingSlot;
69} SHADER_DS_MAPPING;
70
Tobin Ehlis41415bb2015-01-22 10:45:21 -070071typedef struct _GENERIC_HEADER {
Tobin Ehlis84c521c2015-01-19 08:42:29 -070072 XGL_STRUCTURE_TYPE sType;
73 const void* pNext;
Tobin Ehlis41415bb2015-01-22 10:45:21 -070074} GENERIC_HEADER;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070075
76typedef struct _PIPELINE_NODE {
77 XGL_PIPELINE pipeline;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070078 XGL_GRAPHICS_PIPELINE_CREATE_INFO *pCreateTree; // Ptr to shadow of data in create tree
Tobin Ehlis84c521c2015-01-19 08:42:29 -070079 // Vtx input info (if any)
80 uint32_t vtxBindingCount; // number of bindings
81 XGL_VERTEX_INPUT_BINDING_DESCRIPTION* pVertexBindingDescriptions;
82 uint32_t vtxAttributeCount; // number of attributes
83 XGL_VERTEX_INPUT_ATTRIBUTE_DESCRIPTION* pVertexAttributeDescriptions;
Tobin Ehlis83ebbef2015-02-10 15:35:23 -070084 uint32_t attachmentCount; // number of CB attachments
85 XGL_PIPELINE_CB_ATTACHMENT_STATE* pAttachments;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070086} PIPELINE_NODE;
87
88typedef struct _SAMPLER_NODE {
89 XGL_SAMPLER sampler;
90 XGL_SAMPLER_CREATE_INFO createInfo;
Tobin Ehlis84c521c2015-01-19 08:42:29 -070091} SAMPLER_NODE;
92
Tobin Ehlis41415bb2015-01-22 10:45:21 -070093typedef struct _IMAGE_NODE {
94 XGL_IMAGE_VIEW image;
95 XGL_IMAGE_VIEW_CREATE_INFO createInfo;
96 XGL_IMAGE_VIEW_ATTACH_INFO attachInfo;
Tobin Ehlis41415bb2015-01-22 10:45:21 -070097} IMAGE_NODE;
98
99typedef struct _BUFFER_NODE {
100 XGL_BUFFER_VIEW buffer;
101 XGL_BUFFER_VIEW_CREATE_INFO createInfo;
102 XGL_BUFFER_VIEW_ATTACH_INFO attachInfo;
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700103} BUFFER_NODE;
104
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700105typedef struct _DYNAMIC_STATE_NODE {
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600106 XGL_DYNAMIC_STATE_OBJECT stateObj;
107 GENERIC_HEADER* pCreateInfo;
108 union {
109 XGL_DYNAMIC_VP_STATE_CREATE_INFO vpci;
110 XGL_DYNAMIC_RS_STATE_CREATE_INFO rsci;
111 XGL_DYNAMIC_CB_STATE_CREATE_INFO cbci;
112 XGL_DYNAMIC_DS_STATE_CREATE_INFO dsci;
113 } create_info;
114 //struct _DYNAMIC_STATE_NODE* pNext;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700115} DYNAMIC_STATE_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700116// Descriptor Data structures
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700117// Layout Node has the core layout data
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700118typedef struct _LAYOUT_NODE {
119 XGL_DESCRIPTOR_SET_LAYOUT layout;
120 XGL_FLAGS stageFlags;
Tobin Ehlisd215d4b2015-02-16 14:29:30 -0700121 uint32_t shaderStageBindPoints[XGL_NUM_SHADER_STAGE];
Tobin Ehlisefa84162015-02-17 09:54:13 -0700122 XGL_DESCRIPTOR_TYPE* pTypes; // Dynamic array that will be created to verify descriptor types
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600123 XGL_DESCRIPTOR_SET_LAYOUT_CREATE_INFO* pCreateInfoList;
Tobin Ehlis83ebbef2015-02-10 15:35:23 -0700124 uint32_t startIndex; // 1st index of this layout
125 uint32_t endIndex; // last index of this layout
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700126 struct _LAYOUT_NODE* pPriorSetLayout; // Points to node w/ priorSetLayout
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700127} LAYOUT_NODE;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700128typedef struct _SET_NODE {
129 XGL_DESCRIPTOR_SET set;
130 XGL_DESCRIPTOR_REGION region;
131 XGL_DESCRIPTOR_SET_USAGE setUsage;
Tobin Ehlis82871a82015-02-19 09:55:18 -0700132 // Head of LL of all Update structs for this set
Tobin Ehlis41415bb2015-01-22 10:45:21 -0700133 GENERIC_HEADER* pUpdateStructs;
134 // Total num of descriptors in this set (count of its layout plus all prior layouts)
135 uint32_t descriptorCount;
Tobin Ehlis82871a82015-02-19 09:55:18 -0700136 GENERIC_HEADER** ppDescriptors; // Array where each index points to update node for its slot
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700137 LAYOUT_NODE* pLayouts;
138 struct _SET_NODE* pNext;
139} SET_NODE;
140
141typedef struct _REGION_NODE {
142 XGL_DESCRIPTOR_REGION region;
143 XGL_DESCRIPTOR_REGION_USAGE regionUsage;
144 uint32_t maxSets;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600145 XGL_DESCRIPTOR_REGION_CREATE_INFO createInfo;
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700146 bool32_t updateActive; // Track if Region is in an update block
Tobin Ehlis84c521c2015-01-19 08:42:29 -0700147 SET_NODE* pSets; // Head of LL of sets for this Region
148} REGION_NODE;
149
Tobin Ehlis8cced212015-02-13 10:26:14 -0700150// Cmd Buffer Tracking
151typedef enum _CMD_TYPE
152{
153 CMD_BINDPIPELINE,
154 CMD_BINDPIPELINEDELTA,
155 CMD_BINDDYNAMICSTATEOBJECT,
156 CMD_BINDDESCRIPTORSET,
157 CMD_BINDINDEXBUFFER,
158 CMD_BINDVERTEXBUFFER,
159 CMD_DRAW,
160 CMD_DRAWINDEXED,
161 CMD_DRAWINDIRECT,
162 CMD_DRAWINDEXEDINDIRECT,
163 CMD_DISPATCH,
164 CMD_DISPATCHINDIRECT,
165 CMD_COPYBUFFER,
166 CMD_COPYIMAGE,
167 CMD_COPYBUFFERTOIMAGE,
168 CMD_COPYIMAGETOBUFFER,
169 CMD_CLONEIMAGEDATA,
170 CMD_UPDATEBUFFER,
171 CMD_FILLBUFFER,
172 CMD_CLEARCOLORIMAGE,
173 CMD_CLEARCOLORIMAGERAW,
174 CMD_CLEARDEPTHSTENCIL,
175 CMD_RESOLVEIMAGE,
176 CMD_SETEVENT,
177 CMD_RESETEVENT,
178 CMD_WAITEVENTS,
179 CMD_PIPELINEBARRIER,
180 CMD_BEGINQUERY,
181 CMD_ENDQUERY,
182 CMD_RESETQUERYPOOL,
183 CMD_WRITETIMESTAMP,
184 CMD_INITATOMICCOUNTERS,
185 CMD_LOADATOMICCOUNTERS,
186 CMD_SAVEATOMICCOUNTERS,
187 CMD_BEGINRENDERPASS,
Tobin Ehlis1dae99a2015-03-02 10:16:40 -0700188 CMD_ENDRENDERPASS,
189 CMD_DBGMARKERBEGIN,
190 CMD_DBGMARKEREND,
Tobin Ehlis8cced212015-02-13 10:26:14 -0700191} CMD_TYPE;
192// Data structure for holding sequence of cmds in cmd buffer
193typedef struct _CMD_NODE {
Tobin Ehlis8cced212015-02-13 10:26:14 -0700194 CMD_TYPE type;
195 uint64_t cmdNumber;
196} CMD_NODE;
197
198typedef enum _CB_STATE
199{
200 CB_NEW, // Newly created CB w/o any cmds
201 CB_UPDATE_ACTIVE, // BeginCB has been called on this CB
202 CB_UPDATE_COMPLETE // EndCB has been called on this CB
203} CB_STATE;
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600204// Cmd Buffer Wrapper Struct
Tobin Ehlis8cced212015-02-13 10:26:14 -0700205typedef struct _GLOBAL_CB_NODE {
Tobin Ehlis8cced212015-02-13 10:26:14 -0700206 XGL_CMD_BUFFER cmdBuffer;
207 XGL_QUEUE_TYPE queueType;
208 XGL_FLAGS flags;
209 XGL_FENCE fence; // fence tracking this cmd buffer
210 uint64_t numCmds; // number of cmds in this CB
211 uint64_t drawCount[NUM_DRAW_TYPES]; // Count of each type of draw in this CB
212 CB_STATE state; // Track if cmd buffer update status
Tobin Ehlis63bb9482015-03-17 16:24:32 -0600213 vector<CMD_NODE*> pCmds;
Tobin Ehlis8cced212015-02-13 10:26:14 -0700214 // Currently storing "lastBound" objects on per-CB basis
215 // long-term may want to create caches of "lastBound" states and could have
216 // each individual CMD_NODE referencing its own "lastBound" state
217 XGL_PIPELINE lastBoundPipeline;
218 uint32_t lastVtxBinding;
219 DYNAMIC_STATE_NODE* lastBoundDynamicState[XGL_NUM_STATE_BIND_POINT];
220 XGL_DESCRIPTOR_SET lastBoundDescriptorSet;
Tobin Ehlis2464b882015-04-01 08:40:34 -0600221 XGL_RENDER_PASS activeRenderPass;
Tobin Ehlis8cced212015-02-13 10:26:14 -0700222} GLOBAL_CB_NODE;
223
Tobin Ehlisa701ef02014-11-27 15:43:39 -0700224//prototypes for extension functions
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600225void drawStateDumpDotFile(char* outFileName);
226void drawStateDumpPngFile(char* outFileName);
Jeremy Hayes7ec63022015-02-26 15:59:19 -0700227void drawStateDumpCommandBufferDotFile(char* outFileName);
Tobin Ehlis266473d2014-12-16 17:34:50 -0700228// Func ptr typedefs
Mark Lobodzinskie2d07a52015-01-29 08:55:56 -0600229typedef void (*DRAW_STATE_DUMP_DOT_FILE)(char*);
230typedef void (*DRAW_STATE_DUMP_PNG_FILE)(char*);
Jeremy Hayes7ec63022015-02-26 15:59:19 -0700231typedef void (*DRAW_STATE_DUMP_COMMAND_BUFFER_DOT_FILE)(char*);