Skip to content
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

[Sample] webgpu_performance_renderbundle sample could have more optimal usage of GPURenderBundles and GPUBindGroups #29075

Closed
mwyrzykowski opened this issue Aug 6, 2024 · 2 comments
Assignees
Labels

Comments

@mwyrzykowski
Copy link

Description

webgpu_performance_renderbundle shows the benefit render bundles, but instead of creating a single render bundle as done https://webgpu.github.io/webgpu-samples/?sample=renderBundles and encoding all draw commands, a render bundle per object is created. This seems unnecessary.

Solution

I would propose the sample builds a single GPURenderBundle instance, encoding all 4000 draws, rather than building 4000 GPURenderBundle instances and potentially allowing the browser implementation to coalesce the render bundle draws.

Additionally, as shown in https://webgpu.github.io/webgpu-samples/?sample=animometer, it is not necessary to create 4000 GPUBindGroup instances and 4000 GPUBuffer instances.

Instead, 1 GPUBuffer and 1 GPUBindGroup can be created. The GPUBindGroup's layout would get created with hasDynamicOffset: true and then the offset into the larger GPUBuffer can be passed to setBindGroup to draw object N of 4000.

This also reduces the number of GPUQueue.writeBuffer calls from 4000 to 1 per frame, a significant performance savings.

Alternatives

A browser implementation could internally optimize these calls, but this requires some level of caching which may or may not be necessary depending on workload and is difficult to predict.

The web engine / website has a bit more insight into how a GPUBuffer will be used and it is more optimal to perform the coalescing at that level.

Additional context

See https://webgpu.github.io/webgpu-samples/?sample=animometer for optimal usage of GPURenderBundles with GPUBindGroup and GPUBindGroupLayout instances

@RenaudRohlinger
Copy link
Collaborator

Using a single BindGroup is feasible, as demonstrated in #28719.

We should revisit this feature, but I recommend to first prioritize the overall performance improvements for the WebGPURenderer as discussed in #29066 (comment). Once those enhancements are in place, we can then focus on advanced optimizations like RenderBundles.

Let's keep this issue open as a reminder to complete the work on RenderBundles.

@RenaudRohlinger
Copy link
Collaborator

Related #29239

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants