playcanvas / playcanvas/engine
Async Batching in WebWorker
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:
- 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.
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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