-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Multi-draw support, WebGL & WebGPU #8004
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
Conversation
|
Excellent! I'll try rewriting the terrain rendering to this technology; I think it'll be a great boost! |
Yep, let us know, fingers crossed it all works out. |
|
Can you explain what the comment is about please? |
This example demonstrates the use of multi-draw instancing in both WebGPU and WebGL2. |
Ah I see, yep nice, the solution ChatGPT was suggesting. I looked at that and hoped that would work without API changes, but it does not, the instancing data needs to go to texture and be manually fetched. I'm open to adjust engine shader chunks to make this easier for people to do as needed, and have an example to demonstrate as well. Feel free to create a PR here please. |

Fixes #1498
Multi-draw rendering: DrawCommands and MeshInstance.setMultiDraw
What and why
This PR adds first-class multi-draw support to the engine so multiple sub-draws can be submitted with a single API call. This reduces CPU/driver overhead when rendering many disjoint index ranges (submeshes/patches) under identical state. It integrates cleanly with existing rendering paths and complements instancing and indirect rendering.
How it works
DrawCommandscontainer holds per-draw parameters. On WebGL2, data is provided in structure-of-arrays form (counts, offsets, instanceCounts) compatible with theWEBGL_multi_drawextension. On WebGPU, data is stored as array-of-structs in aStorageBufferfor indirect multi-draw.MeshInstance.setMultiDraw(camera, maxCount)allocates per-camera storage and returns aDrawCommandsto populate viaadd(...)and finalize withupdate(count)when data changes.setMultiDraw(camera, 0). For indirect rendering, callsetIndirect(camera, -1).Platform support
firstInstance, so instanced multi-draw cannot select different instance ranges per sub-draw. Use WebGPU for that scenario.New Public API
MeshInstance.setMultiDraw(camera: CameraComponent|null, maxCount?: number): DrawCommands|undefined0to disable for the camera (or the shared entry whencamerais null).MeshInstance.setIndirect(camera: CameraComponent|null, slot: number, count?: number): void-1forslotto disable for the camera (or the shared entry whencamerais null).DrawCommandsadd(i, indexOrVertexCount, instanceCount, firstIndexOrVertex, baseVertex = 0, firstInstance = 0)update(count)— sets active draw count; uploads used portion on WebGPU.Examples
graphics/multi-draw.example.mjsDrawCommandsand callingupdate(visibleCount).graphics/multi-draw-instanced.example.mjs(WebGPU-only)baseInstance. TaggedWEBGL_DISABLEDbecause WebGL2 lacks per-drawfirstInstance.multi-draw.mov