Skip to content

Added CPU and GPU timings for ray tracing effects. #774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.render-pipelines.high-definition/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Added an override for the shadow culling that allows better directional shadow maps in ray tracing effects (RTR, RTGI, RTSSS and RR).
- Added a Cloud Layer volume override.
- Added Fast Memory support for platform that support it.
- Added CPU and GPU timings for ray tracing effects.

### Fixed
- Fix when rescale probe all direction below zero (1219246)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public class DebugDisplaySettings : IDebugData
static bool needsRefreshingCameraFreezeList = true;

List<ProfilingSampler> m_RecordedSamplers = new List<ProfilingSampler>();
List<ProfilingSampler> m_RecordedSamplersRT = new List<ProfilingSampler>();
enum DebugProfilingType
{
CPU,
Expand Down Expand Up @@ -691,6 +692,36 @@ void DisableProfilingRecorders()
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));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingIntegrateReflection));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingFilterReflection));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingAmbientOcclusion));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingFilterAmbientOcclusion));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingDirectionalLightShadow));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingLightShadow));
m_RecordedSamplersRT.Add(ProfilingSampler.Get(HDProfileId.RaytracingIntegrateIndirectDiffuse));
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));
}

void DisableProfilingRecordersRT()
{
foreach (var sampler in m_RecordedSamplersRT)
{
sampler.enableRecording = false;
}

m_RecordedSamplersRT.Clear();
}

ObservableList<DebugUI.Widget> BuildProfilingSamplerList(DebugProfilingType type)
{
var result = new ObservableList<DebugUI.Widget>();
Expand All @@ -708,17 +739,40 @@ void DisableProfilingRecorders()
return result;
}

ObservableList<DebugUI.Widget> BuildProfilingSamplerListRT(DebugProfilingType type)
{
var result = new ObservableList<DebugUI.Widget>();
foreach (var sampler in m_RecordedSamplersRT)
{
sampler.enableRecording = true;
result.Add(new DebugUI.Value
{
displayName = sampler.name,
getter = () => string.Format("{0:F2}", (type == DebugProfilingType.CPU) ? sampler.cpuElapsedTime : ((type == DebugProfilingType.GPU) ? sampler.gpuElapsedTime : sampler.inlineCpuElapsedTime)),
refreshRate = 1.0f / 5.0f
});
}

return result;
}

void RegisterDisplayStatsDebug()
{
var list = new List<DebugUI.Widget>();
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.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)
{
Expand Down Expand Up @@ -1551,6 +1605,8 @@ internal void UnregisterDebug()
UnregisterDebugItems(k_PanelDecals, m_DebugDecalsAffectingTransparentItems);

DisableProfilingRecorders();
if (HDRenderPipeline.currentAsset?.currentPlatformRenderPipelineSettings.supportRayTracing ?? true)
DisableProfilingRecordersRT();
UnregisterDebugItems(k_PanelDisplayStats, m_DebugDisplayStatsItems);

UnregisterDebugItems(k_PanelMaterials, m_DebugMaterialItems);
Expand Down