Skip to content

Conversation

cdxntchou
Copy link

@cdxntchou cdxntchou commented Jul 19, 2021

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

  • Tested on Windows with debug logging enabled, to see that preview rendering is called at most 60 times/second.
  • Tested on Windows, with another Unity window focused, to see that preview rendering is called at most 10 times/second.
  • Tested on Windows, with another program active, to see that preview rendering is called at most 2 times/second.
  • Tested with two ShaderGraph editor windows open -- the focused one gets updated at 60 fps, the other at 10 fps.

Before with two animated graphs of 8 nodes: ~35% GPU usage
Same independent of which window focused, or if Unity app is focused.
image

After:
Similar / slightly reduced cost, but much more stable behavior (less oscillation):
image
Note: user who reported the 50% GPU usage noted that in his project this PR dropped it to around ~5% usage. I think with my settings the project is already getting throttled approximately to the desired framerate through the update calls.

When a non-ShaderGraph unity window selected: ~20% (10 fps)
image

When another app selected: ~7% (2 fps)
image

Yamato:

ShaderGraph PR job: 🟢
https://yamato.cds.internal.unity3d.com/jobs/902-Graphics/tree/sg%252Fthrottle-preview/.yamato%252Fall-shadergraph.yml%2523PR_ShaderGraph_2021.2/7747012/job/pipeline


Comments to reviewers

Notes for the reviewers you have assigned.

@github-actions
Copy link

Hi! This comment will help you figure out which jobs to run before merging your PR. The suggestions are dynamic based on what files you have changed.
Link to Yamato: https://yamato.cds.internal.unity3d.com/jobs/902-Graphics
Search for your PR branch using the sidebar on the left, then add the following segment(s) to the end of the URL (you may need multiple tabs depending on how many packages you change)

Shader Graph
/.yamato%252Fall-shadergraph.yml%2523PR_ShaderGraph_2021.2

Depending on the scope of your PR, you may need to run more jobs than what has been suggested. Please speak to your lead or a Graphics SDET (#devs-graphics-automation) if you are unsure.

@cdxntchou cdxntchou changed the title [ShaderGraph][2021.2] Adding animated preview throttle, removing old dead code [ShaderGraph][2021.2] Throttling animated preview framerate Jul 19, 2021
@cdxntchou cdxntchou marked this pull request as ready for review July 19, 2021 21:31
@cdxntchou cdxntchou requested a review from a team as a code owner July 19, 2021 21:31
@cdxntchou cdxntchou requested a review from a user July 19, 2021 21:32
Copy link
Contributor

@jessebarker jessebarker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@marctem marctem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, clean improvement.

@cdxntchou cdxntchou requested a review from marctem July 20, 2021 21:11
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this for a pretty long period of time, as well as on mac - seems to work great!

@jessebarker jessebarker merged commit 1985929 into master Jul 21, 2021
@jessebarker jessebarker deleted the sg/throttle-preview branch July 21, 2021 19:35
cdxntchou pushed a commit that referenced this pull request Sep 8, 2021
Cherry pick from 1985929

# Conflicts:
#	com.unity.shadergraph/CHANGELOG.md
#	com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs
cdxntchou pushed a commit that referenced this pull request Sep 8, 2021
Cherry picked from 1985929

# Conflicts:
#	com.unity.shadergraph/CHANGELOG.md
#	com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs
cdxntchou pushed a commit that referenced this pull request Sep 10, 2021
…5575)

Cherry picked from 1985929

# Conflicts:
#	com.unity.shadergraph/CHANGELOG.md
#	com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs
marctem pushed a commit that referenced this pull request Sep 18, 2021
…5574)

Cherry pick from 1985929

# Conflicts:
#	com.unity.shadergraph/CHANGELOG.md
#	com.unity.shadergraph/Editor/Drawing/Views/GraphEditorView.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants