[ShaderGraph][2020.3] Throttling animated preview framerate #5575
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose of this PR
Addressing: https://fogbugz.unity3d.com/f/cases/1351801/
Backports:
2021.2: #5164
2021.1: #5574
2020.3: #5575
Fixing an issue where animated preview rendering can take huge amounts of GPU time.
Animated preview rendering is only throttled by the rate at which update is called, and this can be 300 fps or more, depending on your machine and setup, which can result in excessive GPU usage. Some users were seeing very hefty GPUs burning 50% of their time rendering the animated previews at thousands of FPS.
This PR adds a throttle, limiting animated previews to render at your monitor refresh rate.
When the ShaderGraph window is not focused, it further reduces that to 10 fps max.
And when Unity is not active (i.e. another app has focus), it drops it down to 2 fps.
Testing status
Describe what manual/automated tests were performed for this PR
Before with two animated graphs of 8 nodes: ~21-22% GPU usage

Same independent of which window focused, or if Unity app is focused.
After: ~10%

When a non-ShaderGraph unity window selected: ~3-4%

When another app selected: ~2-3%

Yamato:
ShaderGraph PR job: 🟢
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/10.x.x%252Fsg%252Fthrottle-preview/.yamato%252Fall-shadergraph.yml%2523PR_ShaderGraph_2020.3/8613998/job/pipeline
Comments to reviewers
Notes for the reviewers you have assigned.