Commit 11ae68e
fix(Gsplat): Sort Worker Message Starvation in GaussianSplattingMesh (BabylonJS#18554)
When a scene contains a Gsplat alongside geometry with other expensive
rendering passes (e.g., IBL shadows), the splat's depth sorting can feel
sluggish, where splats appear in the wrong order for up to 2 seconds
after the camera moves or a transformation is applied, even though the
sort itself finishes almost immediately. Sometimes the sorting even
stops working for more than 10 secs.
### Reason
The sort worker posts its result back to the main thread as a
regular-priority browser task. The browser's scheduler deprioritizes
regular tasks whenever a higher-priority frame request is pending. When
rendering passes are heavy enough to consume most of the frame budget,
the render loop continuously reschedules the next frame, starving the
worker's message handler. Therefore, the sort result may sit in the task
queue undelivered for an arbitrarily long time.
### Fix
We now install a `customAnimationFrameRequester` in
`GaussianSplattingMeshBase` that inserts a `setTimeout(0)` before each
frame request. This yields control back to the browser's event loop,
giving the scheduler an opportunity to deliver pending tasks, including
the sort result, before the next frame begins.
The wrapper is ref-counted, so it only exists while at least one
`GaussianSplattingMesh` is alive in the scene; there is no overhead for
scenes that don't use Gaussian splatting.
Note: If something else has already claimed
`customAnimationFrameRequester` (such as an immersive WebXR session), we
skip installation. For example, WebXR is not affected by this issue,
where its frame provider already yields to the task queue between frames
by design (refer to
[`xr_frame_provider.cc`](https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/xr/xr_frame_provider.cc),
[crbug.com/701444](https://crbug.com/701444).). For other modules
claiming the `customAnimationFrameRequester` in the future, they should
be responsible for yielding to the task queue between frames.
---------
Co-authored-by: Raymond Fei <yfei@adobe.com>1 parent a8ede5f commit 11ae68e
1 file changed
Lines changed: 73 additions & 0 deletions
Lines changed: 73 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
381 | 383 | | |
382 | 384 | | |
383 | 385 | | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
384 | 455 | | |
385 | 456 | | |
386 | 457 | | |
| |||
843 | 914 | | |
844 | 915 | | |
845 | 916 | | |
| 917 | + | |
846 | 918 | | |
847 | 919 | | |
848 | 920 | | |
| |||
2017 | 2089 | | |
2018 | 2090 | | |
2019 | 2091 | | |
| 2092 | + | |
2020 | 2093 | | |
2021 | 2094 | | |
2022 | 2095 | | |
| |||
0 commit comments