Ingen beskrivning
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.

IGPUResidentRenderPipeline.cs 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using System;
  2. namespace UnityEngine.Rendering
  3. {
  4. /// <summary>
  5. /// Modes for improved draw submission.
  6. /// </summary>
  7. public enum GPUResidentDrawerMode : byte
  8. {
  9. /// <summary>
  10. /// Default mode, GPU resident drawer will be disabled.
  11. /// </summary>
  12. Disabled,
  13. /// <summary>
  14. /// If used, the BatchRendererGroup will be used for draw submission whenever possible.
  15. /// </summary>
  16. InstancedDrawing
  17. }
  18. /// <summary>
  19. /// Utility struct to pass GPU resident drawer settings together
  20. /// </summary>
  21. public struct GPUResidentDrawerSettings
  22. {
  23. /// <summary>
  24. /// Serialized settings of GPUResidentDrawer
  25. /// </summary>
  26. public GPUResidentDrawerMode mode;
  27. /// <summary>
  28. /// Does the implementor support dithered crossfade
  29. /// </summary>
  30. public bool supportDitheringCrossFade;
  31. /// <summary>
  32. /// Enable GPU data for occlusion culling
  33. /// </summary>
  34. public bool enableOcclusionCulling;
  35. /// <summary>
  36. /// Allows the GPU Resident Drawer to run in edit mode
  37. /// </summary>
  38. public bool allowInEditMode;
  39. /// <summary>
  40. /// Default minimum screen percentage (0-20%) gpu-driven Renderers can cover before getting culled.
  41. /// </summary>
  42. public float smallMeshScreenPercentage;
  43. #if UNITY_EDITOR
  44. /// <summary>
  45. /// Shader used if no custom picking pass has been implemented
  46. /// </summary>
  47. public Shader pickingShader;
  48. #endif
  49. /// <summary>
  50. /// Shader used when an error is detected
  51. /// </summary>
  52. public Shader errorShader;
  53. /// <summary>
  54. /// Shader used while compiling shaders
  55. /// </summary>
  56. public Shader loadingShader;
  57. }
  58. /// <summary>
  59. /// Interface that can be added to a RenderPipelineAsset
  60. /// which indicates that it can support the GPUResidentDrawer.
  61. /// </summary>
  62. public interface IGPUResidentRenderPipeline
  63. {
  64. /// <summary>
  65. /// Gets the GPU resident drawer settings
  66. /// </summary>
  67. GPUResidentDrawerSettings gpuResidentDrawerSettings { get; }
  68. /// <summary>
  69. /// The mode the GPUResidentDrawer is configured for on this RenderPipeline
  70. /// </summary>
  71. GPUResidentDrawerMode gpuResidentDrawerMode
  72. {
  73. get;
  74. set;
  75. }
  76. /// <summary>
  77. /// Callback for use when the GPUResidentDrawer needs to be reinitialized.
  78. /// </summary>
  79. static void ReinitializeGPUResidentDrawer()
  80. {
  81. GPUResidentDrawer.Reinitialize();
  82. }
  83. /// <summary>
  84. /// Is the GPU resident drawer supported on this render pipeline.
  85. /// </summary>
  86. /// <param name="logReason">Should the reason for non support be logged?</param>
  87. /// <returns>true if supported</returns>
  88. bool IsGPUResidentDrawerSupportedBySRP(bool logReason = false)
  89. {
  90. bool supported = IsGPUResidentDrawerSupportedBySRP(out var message, out var severity);
  91. if (logReason && !supported)
  92. GPUResidentDrawer.LogMessage(message, severity);
  93. return supported;
  94. }
  95. /// <summary>
  96. /// Is the GPU resident drawer supported on this render pipeline.
  97. /// </summary>
  98. /// <param name="message">Why the system is not supported</param>
  99. /// <param name="severity">The severity of the message</param>
  100. /// <returns>true if supported</returns>
  101. bool IsGPUResidentDrawerSupportedBySRP(out string message, out LogType severity)
  102. {
  103. message = string.Empty;
  104. severity = LogType.Log;
  105. return true;
  106. }
  107. /// <summary>
  108. /// Is GPUResidentDrawer supported on this current configuration?
  109. /// </summary>
  110. /// <param name="logReason">Should the reason for non support be logged?</param>
  111. /// <returns>true if supported</returns>
  112. static bool IsGPUResidentDrawerSupportedByProjectConfiguration(bool logReason = false)
  113. {
  114. bool supported = GPUResidentDrawer.IsProjectSupported(out var message, out var severity);
  115. if (logReason && !string.IsNullOrEmpty(message))
  116. {
  117. Debug.LogWarning(message);
  118. }
  119. return supported;
  120. }
  121. /// <summary>
  122. /// Is GPUResidentDrawer currently enabled
  123. /// </summary>
  124. /// <returns>true if enabled</returns>
  125. static bool IsGPUResidentDrawerEnabled()
  126. {
  127. return GPUResidentDrawer.IsEnabled();
  128. }
  129. }
  130. }