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

Implement low / high refresh rates on WebXR devices #5217

Merged
merged 4 commits into from
Jan 16, 2023

Conversation

diarmidmackenzie
Copy link
Contributor

@diarmidmackenzie diarmidmackenzie commented Jan 13, 2023

Description:

The renderer component offers a property highRefreshRate.
https://aframe.io/docs/1.4.0/components/renderer.html#properties_highrefreshrate

Currently this is only implemented for WebVR.(sets the highRefreshRate value in presentationAttributes)

This means that in WebXR, A-Frame does not influence frame rate, meaning expriences run at the frame rate preferred by the browser. On Quest 2 that is 90fps, which is arguably too high (and often results in experiences missing frames & hitting 45fps).

Changes proposed:

This PR provides a WebXR implementation of the highRefreshRate for devices/browsers that support the WebXR API to control frame rate:
https://www.w3.org/TR/webxr/#dom-xrsession-updatetargetframerate

Proposed behaviour:
1 - if device does not support 90fps, low -> 60, high -> 72
2 - if device supports 90fps, low -> 72, high -> 90

Currently 1 = Quest 1; 2 = Quest 2 & Quest Pro.

Other browsers / devices do not yet support the WebXR spec linked above, but when they do this seems like sensible default behaviour - it can be further tuned when additional info is known about what frame rates these browsers support.

Other notes

This PR is not ready to merge yet. Sharing for an initial view of what the code / function should be. If we get agreement on that, I'll add UTs & updated documentation to reflect the changes.

const rates = xrSession.supportedFrameRates;
if (rates && xrSession.updateTargetFrameRate) {
let targetRate;
if (rates.includes(90)) {
Copy link
Contributor Author

@diarmidmackenzie diarmidmackenzie Jan 13, 2023

Choose a reason for hiding this comment

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

Usually I prefer to avoid "magic numbers" in code, but I'm not sure that replacing these numbers with constants would do anything to aid maintenance or readability.

If you'd like me to use constants like FRAME_RATE_90 etc., please point me to where you'd like them defined. Top of this module? constants/index.js? Or somewhere else?

Copy link
Member

Choose a reason for hiding this comment

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

can this be factored out to a function? setImmersiveModeRefreshRate. May be the code should be part of the renderer component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK, good suggestion - I made this a function on the renderer component & added unit tets for that

@diarmidmackenzie diarmidmackenzie marked this pull request as ready for review January 13, 2023 12:16
@@ -301,6 +301,19 @@ class AScene extends AEntity {
vrManager.setSession(xrSession).then(function () {
vrManager.setFoveation(rendererSystem.foveationLevel);
});
const rates = xrSession.supportedFrameRates;
Copy link
Member

Choose a reason for hiding this comment

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

no const / let only var

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@diarmidmackenzie
Copy link
Contributor Author

Docs & UTs up to date, so I think this is now mergeable.

@dmarcos
Copy link
Member

dmarcos commented Jan 16, 2023

Thank you!

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.

2 participants