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

Rework how rendering works on the graphics thread #1416

Open
bghgary opened this issue Sep 4, 2024 · 0 comments
Open

Rework how rendering works on the graphics thread #1416

bghgary opened this issue Sep 4, 2024 · 0 comments
Milestone

Comments

@bghgary
Copy link
Contributor

bghgary commented Sep 4, 2024

Currently, the main rendering loop is a polling mechanism. The suggestion is to make this an event-based system and make it easier to use. Will fill in more details later.

Possible ramification:

  • Calling Start/FinishRenderingCurrentFrame while nothing is being drawn can cause huge slowdowns in performance. For example, calculation bounding boxes without rendering with the current code will cause the CPU to spike because nothing is stopping the rendering from polling.
  • If the JS side of things keep trying to add things to the native render queue without corresponding calls to StartRenderingCurrentFrame/FinishRenderingCurrentFrame, bgfx will run out of views the next time FinishRenderingCurrentFrame is called because all of the draw calls will be bunched up together. There is a related scenario where if the JS side is doing nothing (i.e., not rendering anything), then calling StartRenderingCurrentFrame/FinishRenderingCurrentFrame will also do nothing. If StartRenderingCurrentFrame/FinishRenderingCurrentFrame is being called in a tight loop, which it often is, then this will eat the CPU at 100%.

Also the JS side does not synchronously change bgfx state, it queues a bunch of commands into a buffer and that whole buffer is sent once per frame, and then all that state is applied on the native side to bgfx. This means the JS side could be working on the next frame (populating another command buffer) while the native side is processing the command buffer, setting bgfx state, rendering, etc.

We should also look at what is actually being queued from nativeEngine.ts. Some work may end up out-of-order if they are run immediately instead of queued.

Another problem is:

Setting a breakpoint in JS in Safari with Babylon Native will hang inside a NativeEngine::RequestAnimationFrame callback. It seems if the main thread in Babylon Native is blocked while stopped at a breakpoint in Safari web inspector, the web inspector will hang.

@bghgary bghgary transferred this issue from BabylonJS/JsRuntimeHost Sep 4, 2024
@thomlucc thomlucc added this to the 8.0 milestone Sep 5, 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

No branches or pull requests

2 participants