-
Notifications
You must be signed in to change notification settings - Fork 855
Realtime profiler (HDRP & URP) #5419
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
Conversation
- FrameTimingManager looks like the likely candidate where the frametime numbers would eventually come from. It required 3 things to start working: -- Switched gfx backend to D3D12 that has an implementation for FrameTimingManager (unlike D3D11) -- Enabled FrameTimingStats from project settings to see numbers. -- Made standalone build work, where we also get GPU numbers. - Upgraded project to use latest trunk version of Unity to make native debugging easier.
- Moved all code under com.unity.render-pipelines.core & renamed stuff - Removed all assets & prefabs from SRP_RealTimeProfiler project (gameobjects still manually placed in scene) - Test project now uses local packages instead of official ones. Temporarily removed com.unity.ui due to incompatibility with 2021.1
- Runtime components don't need com.unity.ui package anymore.
- All GOs are now created automatically through script, so profiling should work in any project. - Asset loading for builds still to be fixed.
- Removed UI Toolkit assets from project. - Added Theme & PanelSettings assets to Resources under the package, load using Resources.Load<>() to remove UnityEditor namespace use.
…nterValue API. - For this purpose, RT Core needs to temporarily depend on com.unity.profiling.core.
- Update test project to trunk version.
- Contains some hacks (workaround for Gfx tests leaking gameobjects, disabled in Player builds due to lack of "is FrameTiming enabled" API)
…neck. - Cleanup runtime UI.
… Foldouts. - Rearrange new Frame Stats in a column layout, show Avg/Min/Max for each value. - Rearrange HDRP detailed stats in a column layout, with CPU/CPUInline/GPU as the columns. - Pinning ValueTuples to PersistentCanvas is visualized by separating each column value with "/". Not ideal but needed something compact. - Fix a bug with Foldouts that allowed runtime and editor collapsed state getting out of sync.
- Duplicate profiler recorders were being added to the array which also messed up averages.
- Fix bug where RayCountManager would never get enabled.
- Use integer instead of string keys for Dictionary. 1.75ms -> 0.5ms (with deep profiling enabled, true cost is lower). - Also fixed bug where per-second average values were not updated unless runtime UI was active, meaning pinned values wouldn't update.
- Sometimes, backend may not provide a valid value for every counter, but provides 0 instead. These invalid values must be ignored when computing min/avg. - The refactor also hides implementation details better and reduces duplication. No performance impact (both old & new logic never exceeded 0.01ms).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved! great job @arttu-peltonen !
I have added a few comments I am sure you will know how to tackle
com.unity.render-pipelines.core/Editor/Debugging/DebugUIDrawer.Builtins.cs
Show resolved
Hide resolved
com.unity.render-pipelines.core/Editor/Debugging/DebugUIDrawer.Builtins.cs
Outdated
Show resolved
Hide resolved
com.unity.render-pipelines.core/Editor/Debugging/DebugUIDrawer.Builtins.cs
Show resolved
Hide resolved
com.unity.render-pipelines.core/Editor/Debugging/DebugUIDrawer.Builtins.cs
Show resolved
Hide resolved
com.unity.render-pipelines.core/Runtime/Debugging/Prefabs/Scripts/DebugUIHandlerEnumHistory.cs
Show resolved
Hide resolved
com.unity.render-pipelines.core/Runtime/Debugging/Prefabs/Scripts/DebugUIHandlerFoldout.cs
Show resolved
Hide resolved
com.unity.render-pipelines.core/Runtime/Debugging/Prefabs/Scripts/DebugUIHandlerValue.cs
Outdated
Show resolved
Hide resolved
com.unity.render-pipelines.core/Runtime/Debugging/Prefabs/Scripts/DebugUIHandlerValueTuple.cs
Outdated
Show resolved
Hide resolved
com.unity.render-pipelines.core/Tests/Runtime/RuntimeProfilerTests.cs
Outdated
Show resolved
Hide resolved
- Fix 15KB per frame alloc caused by compiler generating a new Func<float,float,float> every frame from a local function. Made them static Func objects directly to avoid this. - Avoid new(struct) in DebugFrameTimings.cs. Not sure why this causes an allocation, but use member variables to avoid it regardless. - Don't access Input.touches (which allocates) on old InputManager, unless touches are present.
Update: Added Performance Analysis section to the PR notes doc. |
/// <returns>The formatted value string.</returns> | ||
public virtual string FormatString(object value) | ||
{ | ||
return string.IsNullOrEmpty(formatString) ? $"{value}" : string.Format(formatString, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this would be a good place to switch to MutableString once available...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, absolutely. I've spent some time trying to eliminate allocs but this was the one place I couldn't easily fix without removing support for format strings altogether, which I would like to keep. Great to hear that there's work for a non-allocating StringBuilder/String.Format that I could use in the future!
I quickly tried with XR and the report seems accurate. |
Thanks! Yeah, I agree. I have only tested with MockHMD, not headset, and haven't investigated how XR is supported with uGUI. |
# Conflicts: # com.unity.render-pipelines.core/Runtime/Debugging/DebugUpdater.cs # com.unity.render-pipelines.core/Runtime/Debugging/Prefabs/Resources/DebugUICanvas.prefab # com.unity.render-pipelines.high-definition/Runtime/Debug/DebugDisplay.cs
# Conflicts: # com.unity.render-pipelines.core/Runtime/Debugging/IDebugDisplaySettingsData.cs # com.unity.render-pipelines.universal/Runtime/Debug/DebugDisplaySettingsCommon.cs
…ta change introduced earlier.
Note: there's a new version of the trunk PR now, so please use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Tested on two different macs (intel and apple silicon). Both behaved as expected. Apple silicon on Rosetta had issues, but not related to this PR. tested both Metal and GL. Different URP projects were used - Universal Rendering Examples, URP Template, Viking Village. Behaviour of the frame stats were accurate to the Display stats.
Overall, very useful tool. Only one suggestion I have is from UI/UX perspective. It would make sense to not hide "Display Stats" if it's not in Play Mode. I would add some info there like: "Please, press play to display the stats" or something similar. Otherwise, it might look confusing if it's the first time of using it. Other than that, looks good!
Profiling backend PR has landed in trunk, running some yamato tests against trunk 71d43f7a9c283602dfa9ca30d1612a5f96669ce6 now as a sanity check. |
Yamato status before merge:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approving on yamato state. Terrain failures are known issue on master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
# Conflicts: # com.unity.render-pipelines.high-definition/CHANGELOG.md
# Conflicts: # com.unity.render-pipelines.universal/CHANGELOG.md # com.unity.render-pipelines.universal/Runtime/Debug/DebugDisplaySettingsCommon.cs # com.unity.render-pipelines.universal/Runtime/Debug/DebugDisplaySettingsLighting.cs # com.unity.render-pipelines.universal/Runtime/Debug/DebugDisplaySettingsMaterial.cs # com.unity.render-pipelines.universal/Runtime/Debug/DebugDisplaySettingsRendering.cs
This PR fixes https://jira.unity3d.com/browse/UUM-13827. Sometimes after a build, DebugManager can fail to register debug systems in the editor because of the way `Debug.IsDebugBuild` works. To avoid crashes because of this, we shouldn't use `Debug.IsDebugBuild` but instead use conditional compilation. This has been fixed in 2022+ but a backport was never done. This was originally fixed in [an earlier PR](#5419) ([commit](5e4f2dd)). This PR only takes the relevant parts of the original PR required to fix the bug because the entire PR cannot be backported.
Purpose of this PR
This PR introduces the Realtime Profiler, which allows users to see cpu/gpu frame timings and bottlenecks detected out of these timings.
Details
Full description of the features with screenshots in this document.
This PR depends on New FrameTiming Backend PR by @bandures,
which hasn't landed in trunk yet. Therefore all testing & Yamato runs are done with the latest commit fromEDIT: Trunk PR has landed, works at latest trunk now.trunk/profiler/feature/universal-frame-timing-v3
.Testing status (status mid-September)
Matrix describing what I've tested:
Tested functionality on HDRP and URP, in editor, editor playmode and player builds.