using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine.Rendering.HighDefinition.Attributes;
namespace UnityEngine.Rendering.HighDefinition
{
[GenerateHLSL(needAccessors = false, generateCBuffer = true)]
unsafe struct ShaderVariablesDebugDisplay
{
[HLSLArray(32, typeof(Vector4))]
public fixed float _DebugRenderingLayersColors[32 * 4];
[HLSLArray(11, typeof(ShaderGenUInt4))]
public fixed uint _DebugViewMaterialArray[11 * 4]; // Contain the id (define in various materialXXX.cs.hlsl) of the property to display
public int _DebugLightingMode; // Match enum DebugLightingMode
public int _DebugLightLayersMask;
public int _DebugShadowMapMode;
public int _DebugMipMapMode; // Match enum DebugMipMapMode
public int _DebugFullScreenMode;
public float _DebugTransparencyOverdrawWeight;
public int _DebugMipMapModeTerrainTexture; // Match enum DebugMipMapModeTerrainTexture
public int _ColorPickerMode; // Match enum ColorPickerDebugMode
public Vector4 _DebugLightingAlbedo; // x == bool override, yzw = albedo for diffuse
public Vector4 _DebugLightingSmoothness; // x == bool override, y == override value
public Vector4 _DebugLightingNormal; // x == bool override
public Vector4 _DebugLightingAmbientOcclusion; // x == bool override, y == override value
public Vector4 _DebugLightingSpecularColor; // x == bool override, yzw = specular color
public Vector4 _DebugLightingEmissiveColor; // x == bool override, yzw = emissive color
public Vector4 _DebugLightingMaterialValidateHighColor; // user can specific the colors for the validator error conditions
public Vector4 _DebugLightingMaterialValidateLowColor;
public Vector4 _DebugLightingMaterialValidatePureMetalColor;
public Vector4 _MousePixelCoord; // xy unorm, zw norm
public Vector4 _MouseClickPixelCoord; // xy unorm, zw norm
public int _MatcapMixAlbedo;
public float _MatcapViewScale;
public int _DebugSingleShadowIndex;
public int _DebugProbeVolumeMode;
public int _DebugAOVOutput;
public int _DebugDisplayPad0;
public int _DebugDisplayPad1;
}
///
/// Full Screen Debug Mode.
///
[GenerateHLSL]
public enum FullScreenDebugMode
{
/// No Full Screen debug mode.
None,
// Lighting
/// Minimum Full Screen Lighting debug mode value (used internally).
MinLightingFullScreenDebug,
/// Display Screen Space Ambient Occlusion buffer.
ScreenSpaceAmbientOcclusion,
/// Display Screen Space Reflections buffer used for lighting.
ScreenSpaceReflections,
/// Display the Transparent Screen Space Reflections buffer.
TransparentScreenSpaceReflections,
/// Display Contact Shadows buffer.
ContactShadows,
/// Display Contact Shadows fade.
ContactShadowsFade,
/// Display Screen Space Shadows.
ScreenSpaceShadows,
/// Displays the color pyramid before the refraction pass.
PreRefractionColorPyramid,
/// Display the Depth Pyramid.
DepthPyramid,
/// Display the final color pyramid for the frame.
FinalColorPyramid,
// Raytracing Only
/// Display ray tracing light cluster.
LightCluster,
/// Display screen space global illumination.
ScreenSpaceGlobalIllumination,
/// Display recursive ray tracing.
RecursiveRayTracing,
/// Display ray-traced sub-surface scattering.
RayTracedSubSurface,
/// Maximum Full Screen Lighting debug mode value (used internally).
MaxLightingFullScreenDebug,
// Rendering
/// Minimum Full Screen Rendering debug mode value (used internally).
MinRenderingFullScreenDebug,
/// Display Motion Vectors.
MotionVectors,
/// Display NaNs.
NanTracker,
/// Display Log of the color buffer.
ColorLog,
/// Display Depth of Field circle of confusion.
DepthOfFieldCoc,
/// Display Transparency Overdraw.
TransparencyOverdraw,
/// Display Quad Overdraw.
QuadOverdraw,
/// Display Vertex Density.
VertexDensity,
/// Display Requested Virtual Texturing tiles, colored by the mip
RequestedVirtualTextureTiles,
/// Maximum Full Screen Rendering debug mode value (used internally).
MaxRenderingFullScreenDebug,
//Material
/// Minimum Full Screen Material debug mode value (used internally).
MinMaterialFullScreenDebug,
/// Display Diffuse Color validation mode.
ValidateDiffuseColor,
/// Display specular Color validation mode.
ValidateSpecularColor,
/// Maximum Full Screen Material debug mode value (used internally).
MaxMaterialFullScreenDebug,
// TODO: Move before count for 11.0
/// Display Screen Space Reflections buffer of the previous frame accumulated.
ScreenSpaceReflectionsPrev,
/// Display Screen Space Reflections buffer of the current frame hit.
ScreenSpaceReflectionsAccum
}
///
/// Class managing debug display in HDRP.
///
public class DebugDisplaySettings : IDebugData
{
static string k_PanelDisplayStats = "Display Stats";
static string k_PanelMaterials = "Material";
static string k_PanelLighting = "Lighting";
static string k_PanelVolume = "Volume";
static string k_PanelRendering = "Rendering";
static string k_PanelDecals = "Decals";
DebugUI.Widget[] m_DebugDisplayStatsItems;
DebugUI.Widget[] m_DebugMaterialItems;
DebugUI.Widget[] m_DebugLightingItems;
DebugUI.Widget[] m_DebugVolumeItems;
DebugUI.Widget[] m_DebugRenderingItems;
DebugUI.Widget[] m_DebugDecalsAffectingTransparentItems;
static GUIContent[] s_LightingFullScreenDebugStrings = null;
static int[] s_LightingFullScreenDebugValues = null;
static GUIContent[] s_RenderingFullScreenDebugStrings = null;
static int[] s_RenderingFullScreenDebugValues = null;
static GUIContent[] s_MaterialFullScreenDebugStrings = null;
static int[] s_MaterialFullScreenDebugValues = null;
static GUIContent[] s_MsaaSamplesDebugStrings = null;
static int[] s_MsaaSamplesDebugValues = null;
static GUIContent[] s_TileAndClusterDebugStrings = null;
static int[] s_TileAndClusterDebugValues = null;
static List s_CameraNames = new List();
static GUIContent[] s_CameraNamesStrings = null;
static int[] s_CameraNamesValues = null;
static bool needsRefreshingCameraFreezeList = true;
List m_RecordedSamplers = new List();
// Accumulate values to avg over one second.
class AccumulatedTiming
{
public float accumulatedValue = 0;
public float lastAverage = 0;
internal void UpdateLastAverage(int frameCount)
{
lastAverage = accumulatedValue / frameCount;
accumulatedValue = 0.0f;
}
}
Dictionary m_AccumulatedGPUTiming = new Dictionary();
Dictionary m_AccumulatedCPUTiming = new Dictionary();
Dictionary m_AccumulatedInlineCPUTiming = new Dictionary();
float m_TimeSinceLastAvgValue = 0.0f;
int m_AccumulatedFrames = 0;
const float k_AccumulationTimeInSeconds = 1.0f;
List m_RecordedSamplersRT = new List();
enum DebugProfilingType
{
CPU,
GPU,
InlineCPU
}
///
/// Debug data.
///
public class DebugData
{
/// Ratio of the screen size in which overlays are rendered.
public float debugOverlayRatio = 0.33f;
/// Current full screen debug mode.
public FullScreenDebugMode fullScreenDebugMode = FullScreenDebugMode.None;
/// Enable range remapping.
public bool enableDebugDepthRemap = false; // False per default to be compliant with AOV depth output (AOV depth must export unmodified linear depth)
/// Depth Range remapping values for some of the fullscreen mode. Only x and y are used.
public Vector4 fullScreenDebugDepthRemap = new Vector4(0.0f, 1.0f, 0.0f, 0.0f);
/// Current full screen debug mode mip level (when applicable).
public float fullscreenDebugMip = 0.0f;
/// Index of the light used for contact shadows display.
public int fullScreenContactShadowLightIndex = 0;
/// XR single pass test mode.
public bool xrSinglePassTestMode = false;
/// Whether to display the average timings every second.
public bool averageProfilerTimingsOverASecond = false;
/// Current material debug settings.
public MaterialDebugSettings materialDebugSettings = new MaterialDebugSettings();
/// Current lighting debug settings.
public LightingDebugSettings lightingDebugSettings = new LightingDebugSettings();
/// Current mip map debug settings.
public MipMapDebugSettings mipMapDebugSettings = new MipMapDebugSettings();
/// Current color picker debug settings.
public ColorPickerDebugSettings colorPickerDebugSettings = new ColorPickerDebugSettings();
/// Current false color debug settings.
public FalseColorDebugSettings falseColorDebugSettings = new FalseColorDebugSettings();
/// Current decals debug settings.
public DecalsDebugSettings decalsDebugSettings = new DecalsDebugSettings();
/// Current transparency debug settings.
public TransparencyDebugSettings transparencyDebugSettings = new TransparencyDebugSettings();
/// Current volume debug settings.
public VolumeDebugSettings volumeDebugSettings = new VolumeDebugSettings();
/// Current number of samples for MSAA textures.
public MSAASamples msaaSamples = MSAASamples.None;
/// Index of screen space shadow to display.
public uint screenSpaceShadowIndex = 0;
/// Max quad cost for quad overdraw display.
public uint maxQuadCost = 5;
/// Max vertex density for vertex density display.
public uint maxVertexDensity = 10;
/// Display ray tracing ray count per frame.
public bool countRays = false;
/// Index of the camera to freeze for visibility.
public int debugCameraToFreeze = 0;
// TODO: The only reason this exist is because of Material/Engine debug enums
// They have repeating values, which caused issues when iterating through the enum, thus the need for explicit indices
// Once we refactor material/engine debug to avoid repeating values, we should be able to remove that.
//saved enum fields for when repainting
internal int lightingDebugModeEnumIndex;
internal int lightingFulscreenDebugModeEnumIndex;
internal int materialValidatorDebugModeEnumIndex;
internal int tileClusterDebugEnumIndex;
internal int mipMapsEnumIndex;
internal int engineEnumIndex;
internal int attributesEnumIndex;
internal int propertiesEnumIndex;
internal int gBufferEnumIndex;
internal int shadowDebugModeEnumIndex;
internal int tileClusterDebugByCategoryEnumIndex;
internal int clusterDebugModeEnumIndex;
internal int lightVolumeDebugTypeEnumIndex;
internal int renderingFulscreenDebugModeEnumIndex;
internal int terrainTextureEnumIndex;
internal int colorPickerDebugModeEnumIndex;
internal int exposureDebugModeEnumIndex;
internal int msaaSampleDebugModeEnumIndex;
internal int debugCameraToFreezeEnumIndex;
internal int volumeComponentEnumIndex;
internal int volumeCameraEnumIndex;
internal int probeVolumeDebugModeEnumIndex;
internal int probeVolumeAtlasSliceModeEnumIndex;
// When settings mutually exclusives enum values, we need to reset the other ones.
internal void ResetExclusiveEnumIndices()
{
materialDebugSettings.materialEnumIndex = 0;
lightingDebugModeEnumIndex = 0;
mipMapsEnumIndex = 0;
engineEnumIndex = 0;
attributesEnumIndex = 0;
propertiesEnumIndex = 0;
gBufferEnumIndex = 0;
lightingFulscreenDebugModeEnumIndex = 0;
renderingFulscreenDebugModeEnumIndex = 0;
}
}
DebugData m_Data;
///
/// Debug data.
///
public DebugData data { get => m_Data; }
// Had to keep those public because HDRP tests using it (as a workaround to access proper enum values for this debug)
/// List of Full Screen Rendering Debug mode names.
public static GUIContent[] renderingFullScreenDebugStrings => s_RenderingFullScreenDebugStrings;
/// List of Full Screen Rendering Debug mode values.
public static int[] renderingFullScreenDebugValues => s_RenderingFullScreenDebugValues;
/// List of Full Screen Lighting Debug mode names.
public static GUIContent[] lightingFullScreenDebugStrings => s_LightingFullScreenDebugStrings;
/// List of Full Screen Lighting Debug mode values.
public static int[] lightingFullScreenDebugValues => s_LightingFullScreenDebugValues;
internal DebugDisplaySettings()
{
FillFullScreenDebugEnum(ref s_LightingFullScreenDebugStrings, ref s_LightingFullScreenDebugValues, FullScreenDebugMode.MinLightingFullScreenDebug, FullScreenDebugMode.MaxLightingFullScreenDebug);
FillFullScreenDebugEnum(ref s_RenderingFullScreenDebugStrings, ref s_RenderingFullScreenDebugValues, FullScreenDebugMode.MinRenderingFullScreenDebug, FullScreenDebugMode.MaxRenderingFullScreenDebug);
FillFullScreenDebugEnum(ref s_MaterialFullScreenDebugStrings, ref s_MaterialFullScreenDebugValues, FullScreenDebugMode.MinMaterialFullScreenDebug, FullScreenDebugMode.MaxMaterialFullScreenDebug);
var device = SystemInfo.graphicsDeviceType;
if (device == GraphicsDeviceType.Metal)
{
s_RenderingFullScreenDebugStrings = s_RenderingFullScreenDebugStrings.Where((val, idx) => (idx + FullScreenDebugMode.MinRenderingFullScreenDebug) != FullScreenDebugMode.VertexDensity).ToArray();
s_RenderingFullScreenDebugValues = s_RenderingFullScreenDebugValues.Where((val, idx) => (idx + FullScreenDebugMode.MinRenderingFullScreenDebug) != FullScreenDebugMode.VertexDensity).ToArray();
}
if (device == GraphicsDeviceType.Metal || device == GraphicsDeviceType.PlayStation4 || device == GraphicsDeviceType.PlayStation5)
{
s_RenderingFullScreenDebugStrings = s_RenderingFullScreenDebugStrings.Where((val, idx) => (idx + FullScreenDebugMode.MinRenderingFullScreenDebug) != FullScreenDebugMode.QuadOverdraw).ToArray();
s_RenderingFullScreenDebugValues = s_RenderingFullScreenDebugValues.Where((val, idx) => (idx + FullScreenDebugMode.MinRenderingFullScreenDebug) != FullScreenDebugMode.QuadOverdraw).ToArray();
}
FillTileClusterDebugEnum();
s_MaterialFullScreenDebugStrings[(int)FullScreenDebugMode.ValidateDiffuseColor - ((int)FullScreenDebugMode.MinMaterialFullScreenDebug)] = new GUIContent("Diffuse Color");
s_MaterialFullScreenDebugStrings[(int)FullScreenDebugMode.ValidateSpecularColor - ((int)FullScreenDebugMode.MinMaterialFullScreenDebug)] = new GUIContent("Metal or SpecularColor");
s_MsaaSamplesDebugStrings = Enum.GetNames(typeof(MSAASamples))
.Select(t => new GUIContent(t))
.ToArray();
s_MsaaSamplesDebugValues = (int[])Enum.GetValues(typeof(MSAASamples));
m_Data = new DebugData();
}
///
/// Get Reset action.
///
///
Action IDebugData.GetReset() => () => m_Data = new DebugData();
internal float[] GetDebugMaterialIndexes()
{
return data.materialDebugSettings.GetDebugMaterialIndexes();
}
///
/// Returns the current Light filtering mode.
///
/// Current Light filtering mode.
public DebugLightFilterMode GetDebugLightFilterMode()
{
return data.lightingDebugSettings.debugLightFilterMode;
}
///
/// Returns the current Lighting Debug Mode.
///
/// Current Lighting Debug Mode.
public DebugLightingMode GetDebugLightingMode()
{
return data.lightingDebugSettings.debugLightingMode;
}
///
/// Returns the current Light Layers Debug Mask.
///
/// Current Light Layers Debug Mask.
public DebugLightLayersMask GetDebugLightLayersMask()
{
var settings = data.lightingDebugSettings;
if (!settings.debugLightLayers)
return 0;
#if UNITY_EDITOR
if (settings.debugSelectionLightLayers)
{
if (UnityEditor.Selection.activeGameObject == null)
return 0;
var light = UnityEditor.Selection.activeGameObject.GetComponent();
if (light == null)
return 0;
if (settings.debugSelectionShadowLayers)
return (DebugLightLayersMask)light.GetShadowLayers();
return (DebugLightLayersMask)light.GetLightLayers();
}
#endif
return settings.debugLightLayersFilterMask;
}
///
/// Returns the current Shadow Map Debug Mode.
///
/// Current Shadow Map Debug Mode.
public ShadowMapDebugMode GetDebugShadowMapMode()
{
return data.lightingDebugSettings.shadowDebugMode;
}
///
/// Returns the current Mip Map Debug Mode.
///
/// Current Mip Map Debug Mode.
public DebugMipMapMode GetDebugMipMapMode()
{
return data.mipMapDebugSettings.debugMipMapMode;
}
///
/// Returns the current Terrain Texture Mip Map Debug Mode.
///
/// Current Terrain Texture Mip Map Debug Mode.
public DebugMipMapModeTerrainTexture GetDebugMipMapModeTerrainTexture()
{
return data.mipMapDebugSettings.terrainTexture;
}
///
/// Returns the current Color Picker Mode.
///
/// Current Color Picker Mode.
public ColorPickerDebugMode GetDebugColorPickerMode()
{
return data.colorPickerDebugSettings.colorPickerMode;
}
///
/// Returns the current Probe Volume Debug Mode.
///
/// Current Probe Volume Debug Mode.
internal ProbeVolumeDebugMode GetProbeVolumeDebugMode()
{
return data.lightingDebugSettings.probeVolumeDebugMode;
}
///
/// Returns true if camera visibility is frozen.
///
/// True if camera visibility is frozen
public bool IsCameraFreezeEnabled()
{
return data.debugCameraToFreeze != 0;
}
///
/// Returns true if a specific camera is frozen for visibility.
///
/// Camera to be tested.
/// True if a specific camera is frozen for visibility.
public bool IsCameraFrozen(Camera camera)
{
return IsCameraFreezeEnabled() && camera.name.Equals(s_CameraNamesStrings[data.debugCameraToFreeze].text);
}
///
/// Returns true if any debug display is enabled.
///
/// True if any debug display is enabled.
public bool IsDebugDisplayEnabled()
{
return data.materialDebugSettings.IsDebugDisplayEnabled() || data.lightingDebugSettings.IsDebugDisplayEnabled() || data.mipMapDebugSettings.IsDebugDisplayEnabled() || IsDebugFullScreenEnabled();
}
///
/// Returns true if any material debug display is enabled.
///
/// True if any material debug display is enabled.
public bool IsDebugMaterialDisplayEnabled()
{
return data.materialDebugSettings.IsDebugDisplayEnabled();
}
///
/// Returns true if any full screen debug display is enabled.
///
/// True if any full screen debug display is enabled.
public bool IsDebugFullScreenEnabled()
{
return data.fullScreenDebugMode != FullScreenDebugMode.None;
}
///
/// Returns true if a full screen debug display supporting the FullScreenDebug pass is enabled.
///
/// True if a full screen debug display supporting the FullScreenDebug pass is enabled.
internal bool IsFullScreenDebugPassEnabled()
{
return data.fullScreenDebugMode == FullScreenDebugMode.QuadOverdraw ||
data.fullScreenDebugMode == FullScreenDebugMode.VertexDensity;
}
///
/// Returns true if any full screen exposure debug display is enabled.
///
/// True if any full screen exposure debug display is enabled.
public bool IsDebugExposureModeEnabled()
{
return data.lightingDebugSettings.exposureDebugMode != ExposureDebugMode.None;
}
///
/// Returns true if material validation is enabled.
///
/// True if any material validation is enabled.
public bool IsMaterialValidationEnabled()
{
return (data.fullScreenDebugMode == FullScreenDebugMode.ValidateDiffuseColor) || (data.fullScreenDebugMode == FullScreenDebugMode.ValidateSpecularColor);
}
///
/// Returns true if mip map debug display is enabled.
///
/// True if any mip mapdebug display is enabled.
public bool IsDebugMipMapDisplayEnabled()
{
return data.mipMapDebugSettings.IsDebugDisplayEnabled();
}
///
/// Returns true if matcap view is enabled for a particular camera.
///
/// Input camera.
/// True if matcap view is enabled for a particular camera.
public bool IsMatcapViewEnabled(HDCamera camera)
{
bool sceneViewLightingDisabled = CoreUtils.IsSceneLightingDisabled(camera.camera);
return sceneViewLightingDisabled || GetDebugLightingMode() == DebugLightingMode.MatcapView;
}
private void DisableNonMaterialDebugSettings()
{
data.fullScreenDebugMode = FullScreenDebugMode.None;
data.lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
data.mipMapDebugSettings.debugMipMapMode = DebugMipMapMode.None;
data.lightingDebugSettings.debugLightLayers = false;
}
///
/// Set the current shared material properties debug view.
///
/// Desired shared material property to display.
public void SetDebugViewCommonMaterialProperty(MaterialSharedProperty value)
{
if (value != MaterialSharedProperty.None)
DisableNonMaterialDebugSettings();
data.materialDebugSettings.SetDebugViewCommonMaterialProperty(value);
}
///
/// Set the current material debug view.
///
/// Desired material debug view.
public void SetDebugViewMaterial(int value)
{
if (value != 0)
DisableNonMaterialDebugSettings();
data.materialDebugSettings.SetDebugViewMaterial(value);
}
///
/// Set the current engine debug view.
///
/// Desired engine debug view.
public void SetDebugViewEngine(int value)
{
if (value != 0)
DisableNonMaterialDebugSettings();
data.materialDebugSettings.SetDebugViewEngine(value);
}
///
/// Set current varying debug view.
///
/// Desired varying debug view.
public void SetDebugViewVarying(DebugViewVarying value)
{
if (value != 0)
DisableNonMaterialDebugSettings();
data.materialDebugSettings.SetDebugViewVarying(value);
}
///
/// Set the current Material Property debug view.
///
/// Desired property debug view.
public void SetDebugViewProperties(DebugViewProperties value)
{
if (value != 0)
DisableNonMaterialDebugSettings();
data.materialDebugSettings.SetDebugViewProperties(value);
}
///
/// Set the current GBuffer debug view.
///
/// Desired GBuffer debug view.
public void SetDebugViewGBuffer(int value)
{
if (value != 0)
DisableNonMaterialDebugSettings();
data.materialDebugSettings.SetDebugViewGBuffer(value);
}
///
/// Set the current Full Screen Debug Mode.
///
/// Desired Full Screen Debug mode.
public void SetFullScreenDebugMode(FullScreenDebugMode value)
{
if (data.lightingDebugSettings.shadowDebugMode == ShadowMapDebugMode.SingleShadow)
value = 0;
if (value != FullScreenDebugMode.None)
{
data.lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
data.lightingDebugSettings.debugLightLayers = false;
data.materialDebugSettings.DisableMaterialDebug();
data.mipMapDebugSettings.debugMipMapMode = DebugMipMapMode.None;
}
data.fullScreenDebugMode = value;
}
///
/// Set the current Shadow Map Debug Mode.
///
/// Desired Shadow Map debug mode.
public void SetShadowDebugMode(ShadowMapDebugMode value)
{
// When SingleShadow is enabled, we don't render full screen debug modes
if (value == ShadowMapDebugMode.SingleShadow)
data.fullScreenDebugMode = 0;
data.lightingDebugSettings.shadowDebugMode = value;
}
///
/// Set the current Light Filtering.
///
/// Desired Light Filtering.
public void SetDebugLightFilterMode(DebugLightFilterMode value)
{
if (value != 0)
{
data.materialDebugSettings.DisableMaterialDebug();
data.mipMapDebugSettings.debugMipMapMode = DebugMipMapMode.None;
data.lightingDebugSettings.debugLightLayers = false;
}
data.lightingDebugSettings.debugLightFilterMode = value;
}
///
/// Set the current Light layers Debug Mode
///
/// Desired Light Layers Debug Mode.
public void SetDebugLightLayersMode(bool value)
{
if (value)
{
data.ResetExclusiveEnumIndices();
data.lightingDebugSettings.debugLightFilterMode = DebugLightFilterMode.None;
var builtins = typeof(Builtin.BuiltinData);
var attr = builtins.GetCustomAttributes(true)[0] as GenerateHLSL;
var renderingLayers = Array.IndexOf(builtins.GetFields(), builtins.GetField("renderingLayers"));
SetDebugViewMaterial(attr.paramDefinesStart + renderingLayers);
}
else
{
SetDebugViewMaterial(0);
}
data.lightingDebugSettings.debugLightLayers = value;
}
///
/// Set the current Lighting Debug Mode.
///
/// Desired Lighting Debug Mode.
public void SetDebugLightingMode(DebugLightingMode value)
{
if (value != 0)
{
data.fullScreenDebugMode = FullScreenDebugMode.None;
data.materialDebugSettings.DisableMaterialDebug();
data.mipMapDebugSettings.debugMipMapMode = DebugMipMapMode.None;
data.lightingDebugSettings.debugLightLayers = false;
}
data.lightingDebugSettings.debugLightingMode = value;
}
///
/// Set the current Probe Volume Debug Mode.
///
/// Desired Probe Volume Debug Mode.
internal void SetProbeVolumeDebugMode(ProbeVolumeDebugMode value)
{
data.lightingDebugSettings.probeVolumeDebugMode = value;
}
///
/// Set the current Probe Volume Atlas Mode.
///
/// Desired Probe Volume Atlas Mode.
internal void SetProbeVolumeAtlasSliceMode(ProbeVolumeAtlasSliceMode value)
{
data.lightingDebugSettings.probeVolumeAtlasSliceMode = value;
}
///
/// Set the current Exposure Debug Mode.
///
/// Desired Probe Volume Debug Mode.
internal void SetExposureDebugMode(ExposureDebugMode value)
{
data.lightingDebugSettings.exposureDebugMode = value;
}
///
/// Set the current Mip Map Debug Mode.
///
/// Desired Mip Map debug mode.
public void SetMipMapMode(DebugMipMapMode value)
{
if (value != 0)
{
data.materialDebugSettings.DisableMaterialDebug();
data.lightingDebugSettings.debugLightingMode = DebugLightingMode.None;
data.lightingDebugSettings.debugLightLayers = false;
data.fullScreenDebugMode = FullScreenDebugMode.None;
}
data.mipMapDebugSettings.debugMipMapMode = value;
}
void EnableProfilingRecorders()
{
Debug.Assert(m_RecordedSamplers.Count == 0);
m_RecordedSamplers.Add(ProfilingSampler.Get(HDProfileId.HDRenderPipelineAllRenderRequest));
m_RecordedSamplers.Add(ProfilingSampler.Get(HDProfileId.VolumeUpdate));
m_RecordedSamplers.Add(ProfilingSampler.Get(HDProfileId.RenderShadowMaps));
m_RecordedSamplers.Add(ProfilingSampler.Get(HDProfileId.GBuffer));
m_RecordedSamplers.Add(ProfilingSampler.Get(HDProfileId.PrepareLightsForGPU));
m_RecordedSamplers.Add(ProfilingSampler.Get(HDProfileId.VolumeVoxelization));
m_RecordedSamplers.Add(ProfilingSampler.Get(HDProfileId.VolumetricLighting));
m_RecordedSamplers.Add(ProfilingSampler.Get(HDProfileId.RenderDeferredLightingCompute));
m_RecordedSamplers.Add(ProfilingSampler.Get(HDProfileId.ForwardOpaque));
m_RecordedSamplers.Add(ProfilingSampler.Get(HDProfileId.ForwardTransparent));
m_RecordedSamplers.Add(ProfilingSampler.Get(HDProfileId.ForwardPreRefraction));
m_RecordedSamplers.Add(ProfilingSampler.Get(HDProfileId.ColorPyramid));
m_RecordedSamplers.Add(ProfilingSampler.Get(HDProfileId.DepthPyramid));
m_RecordedSamplers.Add(ProfilingSampler.Get(HDProfileId.PostProcessing));
}
void DisableProfilingRecorders()
{
foreach (var sampler in m_RecordedSamplers)
{
sampler.enableRecording = false;
}
m_RecordedSamplers.Clear();
}
void EnableProfilingRecordersRT()
{
Debug.Assert(m_RecordedSamplersRT.Count == 0);
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingBuildCluster));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingCullLights));
// Ray Traced Reflections
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingReflectionDirectionGeneration));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingReflectionEvaluation));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingReflectionAdjustWeight));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingReflectionUpscale));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingReflectionFilter));
// Ray Traced Ambient Occlusion
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingAmbientOcclusion));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingFilterAmbientOcclusion));
// Ray Traced Shadows
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingDirectionalLightShadow));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingLightShadow));
// Ray Traced Indirect Diffuse
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingIndirectDiffuseDirectionGeneration));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingIndirectDiffuseEvaluation));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingIndirectDiffuseUpscale));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingFilterIndirectDiffuse));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingDebugOverlay));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.ForwardPreRefraction));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RayTracingRecursiveRendering));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RayTracingPrepass));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingDeferredLighting));
}
void DisableProfilingRecordersRT()
{
foreach (var sampler in m_RecordedSamplersRT)
{
sampler.enableRecording = false;
}
m_RecordedSamplersRT.Clear();
}
float GetSamplerTiming(DebugProfilingType type, ProfilingSampler sampler)
{
if (data.averageProfilerTimingsOverASecond)
{
// Find the right accumulated dictionary
var accumulatedDictionary = type == DebugProfilingType.CPU ? m_AccumulatedCPUTiming :
type == DebugProfilingType.InlineCPU ? m_AccumulatedInlineCPUTiming :
m_AccumulatedGPUTiming;
AccumulatedTiming accTiming = null;
if (accumulatedDictionary.TryGetValue(sampler.name, out accTiming))
return accTiming.lastAverage;
}
else
{
return (type == DebugProfilingType.CPU) ? sampler.cpuElapsedTime : ((type == DebugProfilingType.GPU) ? sampler.gpuElapsedTime : sampler.inlineCpuElapsedTime);
}
return 0.0f;
}
ObservableList BuildProfilingSamplerList(DebugProfilingType type)
{
var result = new ObservableList();
// Find the right accumulated dictionary and add it there if not existing yet.
var accumulatedDictionary = type == DebugProfilingType.CPU ? m_AccumulatedCPUTiming :
type == DebugProfilingType.InlineCPU ? m_AccumulatedInlineCPUTiming :
m_AccumulatedGPUTiming;
foreach (var sampler in m_RecordedSamplers)
{
sampler.enableRecording = true;
if (!accumulatedDictionary.ContainsKey(sampler.name))
{
accumulatedDictionary.Add(sampler.name, new AccumulatedTiming());
}
result.Add(new DebugUI.Value
{
displayName = sampler.name,
getter = () => string.Format("{0:F2}", GetSamplerTiming(type, sampler)),
refreshRate = 1.0f / 5.0f
});
}
return result;
}
ObservableList BuildProfilingSamplerListRT(DebugProfilingType type)
{
var result = new ObservableList();
// Find the right accumulated dictionary and add it there if not existing yet.
var accumulatedDictionary = type == DebugProfilingType.CPU ? m_AccumulatedCPUTiming :
type == DebugProfilingType.InlineCPU ? m_AccumulatedInlineCPUTiming :
m_AccumulatedGPUTiming;
foreach (var sampler in m_RecordedSamplersRT)
{
sampler.enableRecording = true;
if (!accumulatedDictionary.ContainsKey(sampler.name))
{
accumulatedDictionary.Add(sampler.name, new AccumulatedTiming());
}
result.Add(new DebugUI.Value
{
displayName = sampler.name,
getter = () => string.Format("{0:F2}", GetSamplerTiming(type, sampler)),
refreshRate = 1.0f / 5.0f
});
}
return result;
}
void UpdateListOfAveragedProfilerTimings(List samplers, bool needUpdatingAverages)
{
foreach (var sampler in samplers)
{
// Accumulate.
AccumulatedTiming accCPUTiming = null;
if (m_AccumulatedCPUTiming.TryGetValue(sampler.name, out accCPUTiming))
accCPUTiming.accumulatedValue += sampler.cpuElapsedTime;
AccumulatedTiming accInlineCPUTiming = null;
if (m_AccumulatedInlineCPUTiming.TryGetValue(sampler.name, out accInlineCPUTiming))
accInlineCPUTiming.accumulatedValue += sampler.inlineCpuElapsedTime;
AccumulatedTiming accGPUTiming = null;
if (m_AccumulatedGPUTiming.TryGetValue(sampler.name, out accGPUTiming))
accGPUTiming.accumulatedValue += sampler.gpuElapsedTime;
if (needUpdatingAverages)
{
if (accCPUTiming != null)
accCPUTiming.UpdateLastAverage(m_AccumulatedFrames);
if (accInlineCPUTiming != null)
accInlineCPUTiming.UpdateLastAverage(m_AccumulatedFrames);
if (accGPUTiming != null)
accGPUTiming.UpdateLastAverage(m_AccumulatedFrames);
}
}
}
internal void UpdateAveragedProfilerTimings()
{
m_TimeSinceLastAvgValue += Time.unscaledDeltaTime;
m_AccumulatedFrames++;
bool needUpdatingAverages = m_TimeSinceLastAvgValue >= k_AccumulationTimeInSeconds;
UpdateListOfAveragedProfilerTimings(m_RecordedSamplers, needUpdatingAverages);
UpdateListOfAveragedProfilerTimings(m_RecordedSamplersRT, needUpdatingAverages);
if (needUpdatingAverages)
{
m_TimeSinceLastAvgValue = 0.0f;
m_AccumulatedFrames = 0;
}
}
void RegisterDisplayStatsDebug()
{
var list = new List();
list.Add(new DebugUI.Value { displayName = "Frame Rate (fps)", getter = () => 1f / Time.smoothDeltaTime, refreshRate = 1f / 5f });
list.Add(new DebugUI.Value { displayName = "Frame Time (ms)", getter = () => Time.smoothDeltaTime * 1000f, refreshRate = 1f / 5f });
EnableProfilingRecorders();
list.Add(new DebugUI.BoolField { displayName = "Update every second with average", getter = () => data.averageProfilerTimingsOverASecond, setter = value => data.averageProfilerTimingsOverASecond = value });
list.Add(new DebugUI.Foldout("CPU timings (Command Buffers)", BuildProfilingSamplerList(DebugProfilingType.CPU)));
list.Add(new DebugUI.Foldout("GPU timings", BuildProfilingSamplerList(DebugProfilingType.GPU)));
if (HDRenderPipeline.currentAsset?.currentPlatformRenderPipelineSettings.supportRayTracing ?? true)
{
EnableProfilingRecordersRT();
list.Add(new DebugUI.Foldout("CPU timings RT (Command Buffers)", BuildProfilingSamplerListRT(DebugProfilingType.CPU)));
list.Add(new DebugUI.Foldout("GPU timings RT", BuildProfilingSamplerListRT(DebugProfilingType.GPU)));
}
list.Add(new DebugUI.Foldout("Inline CPU timings", BuildProfilingSamplerList(DebugProfilingType.InlineCPU)));
list.Add(new DebugUI.BoolField { displayName = "Count Rays (MRays/Frame)", getter = () => data.countRays, setter = value => data.countRays = value, onValueChanged = RefreshDisplayStatsDebug });
if (data.countRays)
{
list.Add(new DebugUI.Container
{
children =
{
new DebugUI.Value { displayName = "Ambient Occlusion", getter = () => ((float)(RenderPipelineManager.currentPipeline as HDRenderPipeline).GetRaysPerFrame(RayCountValues.AmbientOcclusion)) / 1e6f, refreshRate = 1f / 30f },
new DebugUI.Value { displayName = "Shadows Directional", getter = () => ((float)(RenderPipelineManager.currentPipeline as HDRenderPipeline).GetRaysPerFrame(RayCountValues.ShadowDirectional)) / 1e6f, refreshRate = 1f / 30f },
new DebugUI.Value { displayName = "Shadows Area", getter = () => ((float)(RenderPipelineManager.currentPipeline as HDRenderPipeline).GetRaysPerFrame(RayCountValues.ShadowAreaLight)) / 1e6f, refreshRate = 1f / 30f },
new DebugUI.Value { displayName = "Shadows Point/Spot", getter = () => ((float)(RenderPipelineManager.currentPipeline as HDRenderPipeline).GetRaysPerFrame(RayCountValues.ShadowPointSpot)) / 1e6f, refreshRate = 1f / 30f },
new DebugUI.Value { displayName = "Reflections Forward ", getter = () => ((float)(RenderPipelineManager.currentPipeline as HDRenderPipeline).GetRaysPerFrame(RayCountValues.ReflectionForward)) / 1e6f, refreshRate = 1f / 30f },
new DebugUI.Value { displayName = "Reflections Deferred", getter = () => ((float)(RenderPipelineManager.currentPipeline as HDRenderPipeline).GetRaysPerFrame(RayCountValues.ReflectionDeferred)) / 1e6f, refreshRate = 1f / 30f },
new DebugUI.Value { displayName = "Diffuse GI Forward", getter = () => ((float)(RenderPipelineManager.currentPipeline as HDRenderPipeline).GetRaysPerFrame(RayCountValues.DiffuseGI_Forward)) / 1e6f, refreshRate = 1f / 30f },
new DebugUI.Value { displayName = "Diffuse GI Deferred", getter = () => ((float)(RenderPipelineManager.currentPipeline as HDRenderPipeline).GetRaysPerFrame(RayCountValues.DiffuseGI_Deferred)) / 1e6f, refreshRate = 1f / 30f },
new DebugUI.Value { displayName = "Recursive Rendering", getter = () => ((float)(RenderPipelineManager.currentPipeline as HDRenderPipeline).GetRaysPerFrame(RayCountValues.Recursive)) / 1e6f, refreshRate = 1f / 30f },
new DebugUI.Value { displayName = "Total", getter = () => ((float)(RenderPipelineManager.currentPipeline as HDRenderPipeline).GetRaysPerFrame(RayCountValues.Total)) / 1e6f, refreshRate = 1f / 30f },
}
});
}
#if DEVELOPMENT_BUILD || UNITY_EDITOR
list.Add(new DebugUI.BoolField { displayName = "Debug XR Layout", getter = () => XRSystem.dumpDebugInfo, setter = value => XRSystem.dumpDebugInfo = value, onValueChanged = RefreshDisplayStatsDebug });
if (XRSystem.dumpDebugInfo)
{
Func