webgpu / webgpu-samples

WebGPU Samples
https://webgpu.github.io/webgpu-samples/
BSD 3-Clause "New" or "Revised" License
1.69k stars 291 forks source link

Indirect Draw Call Sample #410

Open cmhhelgeson opened 3 months ago

cmhhelgeson commented 3 months ago

Should there be an example that demonstrates best practices for using indirect draw calls, ala the renderBundles example? Or perhaps indirect draw calls could be an option in a separate sample?

kainino0x commented 3 months ago

@toji did you have a demo doing some interesting things with indirect draws?

greggman commented 3 months ago

AFAIK this sample https://webgpu.github.io/webgpu-samples/?sample=bundleCulling uses indirect draw calls.

https://github.com/toji/webgpu-bundle-culling/blob/3098596aef18acd91e93d85156b49f08fcee9831/index.html#L694

toji commented 3 months ago

Yeah, the bundle culling code does use indirect draws, and I talk about their usage in that sample here: https://toji.dev/webgpu-best-practices/render-bundles#indirect-draws (Plus some additional optimization information here: https://toji.dev/webgpu-best-practices/indirect-draws) For what it's worth https://webgpu.github.io/webgpu-samples/?sample=metaballs also uses indirect draws, and is probably a more straightforward use case for them. They're both reasonably complex samples, though, and focused on techniques other than the indirect part.

It may be worthwhile to create a simpler sample focused specifically on indirect draws. It could be as basic as a variant of the spinning cube that uses an indirect draw instead of a traditional one, but that doesn't really touch on the "why" of indirect drawing. A sample with some simple generative geometry (like the metaballs, but ideally even more basic) would serve as a better illustration but it's easy for that to get overly complex fast.