playcanvas / playcanvas/engine

Async Batching in WebWorker

Open
#8,432 9 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
16.8k
Forks
2k
Avg merge
4h 32m
Merged PRs (30d)
222

Description

Batching - is an amazing technique, that enables us to create complex scenes in runtime with loads of objects, and still have reduced number of drawcalls, when used tactically with materials.
We use spatial grid with LoD's. And have to batch/re-batch in runtime, as parts of our scenes can change.

But the sync nature of batching, and the fact it runs on CPU, has a significant drawbacks, where it can lead to significant main thread locks.

We would love if batching would be a bit more simplified in terms of data access - currently it heavily relies on VertexIterator, which abstracts away the underlying data. While it brings convenience abstracting away data variability.
But it makes harder to have raw buffers, that we could do a few things with:

  1. Have a dedicated WebWorker process, that would be able to accept mesh's data, meshInstance's data and batch them in buffers. This would offload main thread, and even allow speeding up batching by running multiple WebWorkers, benefiting from today's multi-core CPUs.
  2. Explore other capabilities by using GPU for such tasks, potentially TransformFeedback on WebGL2, and Compute Shaders on WebGPU. While combining buffers together is a fast operation, transforming every vertex by world matrix - is the time consuming part, and could be performed once on the GPU.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Review the current synchronous batching flow and its reliance on VertexIterator, then compare the proposed WebWorker and GPU approaches described in the issue. The scope is not yet a concrete implementation task; done would require an agreed design and a defined batching path that reduces main-thread work.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
computer-graphics, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.