暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RenderGraph.DebugData.cs 8.8KB

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