Skip to content

Support for indirect draw calls for WebGPU #7777

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

Merged
merged 12 commits into from
Jun 19, 2025
Merged

Support for indirect draw calls for WebGPU #7777

merged 12 commits into from
Jun 19, 2025

Conversation

mvaligursky
Copy link
Contributor

@mvaligursky mvaligursky commented Jun 18, 2025

Implementation of indirect draw calls on WebGPU )both indexed and non indexed). The implementation uses a single storage buffer to store draw call parameters, allowing their batching into a small number of compute shaders to get the best performance, based on this.

Live example: https://engine-fwazdfd1j-playcanvas.vercel.app/#/compute/indirect-draw

Public API:

// storage buffer which stores the draw call parameters
GraphicsDevice.indirectDrawBuffer() 

// function to allocate a slot in this buffer
GraphicsDevice.getIndirectDrawSlot()

// read - write property controlling the size of that buffer (number of indirect draw calls)
GraphicsDevice.maxIndirectDrawCount = 1024;

// enabled MeshInstance rendering by indirect parameters from a slot
// for a camera. Camera can be null to use for all cameras
MeshInstance.setIndirect(camera|null, slot)

Graphics Device docs:
device
device2
device 3

Mesh Instance docs:
mi

example:
Screenshot 2025-06-18 at 13 29 17

@LeXXik
Copy link
Contributor

LeXXik commented Jun 18, 2025

Nice! Couple of questions:

@mvaligursky
Copy link
Contributor Author

| Does this work in Safari?

It works in my local WebKit browser using WebGPU, so I suspect when Safari with WebGPU is officially out, it will just work.

@willeastcott
Copy link
Contributor

It might be a good idea to add one or more @example blocks to the JSDocs showing how to use the new API.

/**
* Retrieves the slot in the indirect buffer for a specific camera.
*
* @param {CameraComponent|null} camera - The camera component to retrieve the slot for, or null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know there are other places in the scene layer that import from the framework layers...but here's a new one!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'm stuck with it here. Camera is not public so I cannot use that, and don't see a good way around it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed all other comments, thanks!

Martin Valigursky added 2 commits June 18, 2025 16:58
Copy link
Contributor

@willeastcott willeastcott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving assuming you're gonna add some example code or link to the example as an alternative.

@mvaligursky
Copy link
Contributor Author

Approving assuming you're gonna add some example code or link to the example as an alternative.

added this:

Screenshot 2025-06-19 at 10 40 57

mvaligursky and others added 3 commits June 19, 2025 10:56
@mvaligursky
Copy link
Contributor Author

updated

Screenshot 2025-06-19 at 10 58 06

@mvaligursky mvaligursky merged commit 743ff85 into main Jun 19, 2025
7 checks passed
@mvaligursky mvaligursky deleted the mv-indirect-draw branch June 19, 2025 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: graphics Graphics related issue feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants