A game about forced loneliness, made by TACStudios
1using System.Collections.Generic;
2using System.Diagnostics;
3using UnityEngine.Experimental.Rendering;
4
5namespace UnityEngine.Rendering.RenderGraphModule
6{
7 public partial class RenderGraph
8 {
9 /// <summary>
10 /// Debug data interface shared by HDRP RG Compiler and NRP RG Compiler.
11 /// Some data is optional, depending on the value of isNRPCompiler.
12 /// </summary>
13 internal class DebugData
14 {
15 public DebugData()
16 {
17 for (int i = 0; i < (int) RenderGraphResourceType.Count; ++i)
18 resourceLists[i] = new List<ResourceData>();
19 }
20
21 // Debug data for passes.
22 public readonly List<PassData> passList = new List<PassData>();
23
24 // Debug data for resources.
25 public readonly List<ResourceData>[] resourceLists = new List<ResourceData>[(int) RenderGraphResourceType.Count];
26
27 // If true, the data was output by NRP compiler, in which case PassData.nrpInfo is available.
28 public bool isNRPCompiler;
29
30 [DebuggerDisplay("PassDebug: {name}")]
31 public struct PassData
32 {
33 // Render pass name.
34 public string name;
35
36 // Render graph pass type.
37 public RenderGraphPassType type;
38
39 // List of ResourceHandle.index's for each resource type read by this pass.
40 public List<int>[] resourceReadLists;
41
42 // List of ResourceHandle.index's for each resource type written by this pass.
43 public List<int>[] resourceWriteLists;
44
45 // Whether the pass was culled.
46 public bool culled;
47
48 // Whether the pass is an async compute pass.
49 public bool async;
50
51 // Native subpass index.
52 public int nativeSubPassIndex;
53
54 // Index of the pass that needs to be waited for.
55 public int syncToPassIndex;
56
57 // Smaller pass index that waits for this pass.
58 public int syncFromPassIndex;
59
60 // We have this member instead of removing the pass altogether because we need the full list of passes in
61 // order to be able to remap them correctly when we remove them from display in the viewer.
62 public bool generateDebugData;
63
64 public class NRPInfo
65 {
66 public class NativeRenderPassInfo
67 {
68 public class AttachmentInfo
69 {
70 public string resourceName;
71 public int attachmentIndex;
72 public string loadAction;
73 public string loadReason;
74 public string storeAction;
75 public string storeReason;
76 public string storeMsaaReason;
77 }
78
79 public struct PassCompatibilityInfo
80 {
81 public string message;
82 public bool isCompatible;
83 }
84
85 public string passBreakReasoning;
86 public List<AttachmentInfo> attachmentInfos;
87 public Dictionary<int, PassCompatibilityInfo> passCompatibility;
88 public List<int> mergedPassIds;
89 }
90
91 // If this pass is part of a Native Render Pass, this is available, null otherwise.
92 public NativeRenderPassInfo nativePassInfo;
93
94 // List of ResourceHandle.index's for each texture resource that is accessed using framebuffer fetch.
95 public List<int> textureFBFetchList = new();
96
97 // List of ResourceHandle.index's for each texture resource that this pass called PostSetGlobalTexture() for.
98 public List<int> setGlobals = new();
99
100 // Fragment info
101 public int width;
102 public int height;
103 public int volumeDepth;
104 public int samples;
105 public bool hasDepth;
106 }
107
108 // Only available when isNRPCompiler = true, null otherwise.
109 public NRPInfo nrpInfo;
110
111 // File path and line number where the render pass is defined.
112 public PassScriptInfo scriptInfo;
113 }
114
115 public class BufferResourceData
116 {
117 // Number of elements in buffer.
118 public int count;
119
120 // Size of one element in the buffer.
121 public int stride;
122
123 // Buffer usage type.
124 public GraphicsBuffer.Target target;
125
126 // Buffer usage flags.
127 public GraphicsBuffer.UsageFlags usage;
128 }
129
130 public class TextureResourceData
131 {
132 // Texture width & height.
133 public int width;
134 public int height;
135
136 // Texture depth (volume texture).
137 public int depth;
138
139 // Whether the texture is bound with multi sampling.
140 public bool bindMS;
141
142 // Number of texture MSAA samples.
143 public int samples;
144
145 // Render texture graphics format.
146 public GraphicsFormat format;
147
148 // Whether texture is cleared on first use.
149 public bool clearBuffer;
150 }
151
152 [DebuggerDisplay("ResourceDebug: {name} [{creationPassIndex}:{releasePassIndex}]")]
153 public struct ResourceData
154 {
155 // Resource name.
156 public string name;
157
158 // Whether the resource is imported outside of render graph.
159 public bool imported;
160
161 // Pass that creates the resource (for imported resources, the first pass that uses the resource).
162 public int creationPassIndex;
163
164 // Pass that releases the resource (for imported resources, the last pass that uses the resource).
165 public int releasePassIndex;
166
167 // List of passes that read the resource.
168 public List<int> consumerList;
169
170 // List of passes that write the resource.
171 public List<int> producerList;
172
173 // Whether the resource is memoryless (i.e resources that are created/destroyed within the same native render pass).
174 // Available if isNRPCompiler = true.
175 public bool memoryless;
176
177 // Texture-specific resource data.
178 public TextureResourceData textureData;
179
180 // Buffer-specific resource data.
181 public BufferResourceData bufferData;
182 }
183
184 public void Clear()
185 {
186 passList.Clear();
187 for (int i = 0; i < (int) RenderGraphResourceType.Count; ++i)
188 resourceLists[i].Clear();
189 }
190
191 // Script metadata for passes.
192 internal static readonly Dictionary<string, PassScriptInfo> s_PassScriptMetadata = new ();
193
194 // Pass script metadata.
195 public class PassScriptInfo
196 {
197 public string filePath;
198 public int line;
199 }
200 }
201
202 readonly string[] k_PassNameDebugIgnoreList = new string[] { k_BeginProfilingSamplerPassName, k_EndProfilingSamplerPassName };
203
204 [Conditional("UNITY_EDITOR")]
205 void AddPassDebugMetadata(string passName, string file, int line)
206 {
207 // Does nothing unless debug data capture is requested
208 if (m_CaptureDebugDataForExecution == null)
209 return;
210
211 for (int i = 0; i < k_PassNameDebugIgnoreList.Length; ++i)
212 if (passName == k_PassNameDebugIgnoreList[i])
213 return;
214
215 if (!DebugData.s_PassScriptMetadata.TryAdd(passName, new DebugData.PassScriptInfo { filePath = file, line = line }))
216 {
217 var existingFile = DebugData.s_PassScriptMetadata[passName].filePath;
218 var existingLine = DebugData.s_PassScriptMetadata[passName].line;
219 if (existingFile != file || existingLine != line)
220 Debug.LogWarning($"Two passes called {passName} in different locations: {existingFile}:{existingLine}" +
221 $" and {file}:{line}. Jumping to source from Render Graph Viewer will only work correctly for {existingFile}:{existingLine}.");
222 }
223 }
224
225 [Conditional("UNITY_EDITOR")]
226 void ClearPassDebugMetadata()
227 {
228 DebugData.s_PassScriptMetadata.Clear();
229 }
230 }
231}