Skip to content
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

Viewer auto suspend rendering when scene is idle #15864

Draft
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

ryantrem
Copy link
Member

This PR adds support for suspending rendering when the scene is idle (e.g. nothing is changing from frame to frame, and the same exact pixels would be rendered repeatedly). The idea is to reduce resource pressure and not destroy the battery on a mobile device.

I have two problems remaining for this PR:

  1. Sometimes (it's hard to repro) I can get into a state where the camera position jumps back and forth between two very close positions (like the y value of the position has a difference of .000000000001). This makes _isSynchronizedProjectionMatrix return true every frame. I don't think this has anything to do with my PR, I think this is a pre-existing bug that we just don't notice. Since it is hard to repro, I haven't been able to figure out what causes it yet.
  2. Very rarely I get an error related to WebGPU snapshot rendering mode where it thinks the gpu bundle is out of date, and then nothing renders (so rare, but catastrophic). I don't know why this happens, but I'm guessing some kind of timing issue.

For now, I will put this PR in draft.

@bjsplat
Copy link
Collaborator

bjsplat commented Nov 21, 2024

Please make sure to label your PR with "bug", "new feature" or "breaking change" label(s).
To prevent this PR from going to the changelog marked it with the "skip changelog" label.

@bjsplat
Copy link
Collaborator

bjsplat commented Nov 21, 2024

@bjsplat
Copy link
Collaborator

bjsplat commented Nov 21, 2024

@bjsplat
Copy link
Collaborator

bjsplat commented Nov 21, 2024

this._details.scene.incrementRenderId();
this._details.scene.executeWhenReady(() => {
this._sceneMutated = true;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

You should set the second parameter of executeWhenReady to true, to ensure that additional render targets (if any) are also ready. I think we should also make this change in the snapshot rendering helper, as we use executeWhenReady twice in this case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Would we expect additional render targets in the constrained case of the Viewer? Or would that require a user to do more advanced things, directly modifying the Babylon scene?

Copy link
Member

Choose a reason for hiding this comment

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

There could be some for shadows or diffuse_transmission in gltf for instance.

@bjsplat
Copy link
Collaborator

bjsplat commented Nov 21, 2024

@bjsplat
Copy link
Collaborator

bjsplat commented Nov 21, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants