Skip to content

feat(webgpu): pipelines can be created without holding up the browser's GPU thread - #7

Closed
MichaelBradetLegris wants to merge 1 commit into
patch-27.0.1from
async-pipelines
Closed

MichaelBradetLegris wants to merge 1 commit into
patch-27.0.1from
async-pipelines

Conversation

@MichaelBradetLegris

Copy link
Copy Markdown

Connections

An alternative to #6, which adds the same render pipeline call for the browser only. This is the dependency of fslabs/fsl_libs#4801, whose vendored bevy_render creates every pipeline this way in a browser. fslabs/fsl_libs#4798 takes the other route, with #6.

Description

Device::create_render_pipeline_async and Device::create_compute_pipeline_async resolve to the pipeline once it is ready, or to the error its creation reports. The WebGPU backend creates the pipeline with createRenderPipelineAsync or createComputePipelineAsync, so the browser compiles it off the thread that serves the page's other GPU calls. Chrome on Direct3D compiles with DXC on that thread. A synchronously created pipeline held every tab's drawing for as long as its compile took, which was tens of seconds for the SpatialEngine map and atmosphere shaders.

Every other backend creates the pipeline before the call returns, as the synchronous methods do, through default methods on DeviceInterface. Callers need no cfg, and a custom backend needs no change. A rejected creation's GPUPipelineError becomes Error::Validation or Error::Internal, depending on its reason. The WebGPU backend maps each descriptor once for both paths.

Compared with #6, this also covers compute pipelines, is available on every backend, and reports a wgpu::Error rather than a String. The two touch the same functions, so only one should land.

Testing

I built it into SpatialEngine and ran Geoid in Chrome 156 on Windows (Ryzen 9 5950X, RTX 3050). The engine created 70 pipelines this way, and the longest startup frame went from 29 s to 1.2 s with no WebGPU errors. Check, clippy and fmt for wgpu on wasm32-unknown-unknown pass, and clippy's three warnings are in code this change doesn't touch.

I did not run it against wgpu's own test suite. Native backends only gain the default methods, which call the synchronous ones.

Squash or Rebase?

Single commit, ready to rebase.

…'s GPU thread

`Device::create_render_pipeline_async` and `Device::create_compute_pipeline_async` resolve to the pipeline once it is ready, or to the error its creation reports. The WebGPU backend creates it with `createRenderPipelineAsync` or `createComputePipelineAsync`, so the browser compiles it off the thread that serves the page's other GPU calls. A synchronously created pipeline compiles on that thread, and Chrome on Direct3D, which compiles with DXC, drew nothing in any tab until a compile of up to tens of seconds ended.

Every other backend creates the pipeline before the call returns, as the synchronous methods do, through default methods on `DeviceInterface`, so a custom backend needs no change. A rejected creation's `GPUPipelineError` becomes `Error::Validation` or `Error::Internal` by its reason. The WebGPU backend maps both descriptors once for both paths.
@fslabs-bot fslabs-bot Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 2, 2026
@fslabs-bot

fslabs-bot Bot commented Nov 2, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@fslabs-bot fslabs-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 2, 2026
@MichaelBradetLegris

Copy link
Copy Markdown
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant