Skip to content

WebGPURenderer: Allow passing a custom backend#33623

Open
pepperoni505 wants to merge 1 commit into
mrdoob:devfrom
pepperoni505:feat/customizable-backend
Open

WebGPURenderer: Allow passing a custom backend#33623
pepperoni505 wants to merge 1 commit into
mrdoob:devfrom
pepperoni505:feat/customizable-backend

Conversation

@pepperoni505
Copy link
Copy Markdown

Description

Renderer already delegates all GPU work to a Backend and accepts one in its constructor, but WebGPURenderer always constructs its own - WebGPU, or WebGL when forceWebGL is set. There's no way to run the renderer against a backend that isn't one of those two, which rules out things like a headless/context-free backend or one that records the command stream instead of issuing GPU calls.

This adds a backend option to WebGPURenderer. If you pass one it's used directly. If you don't, the existing WebGPU/WebGL selection is untouched, so nothing changes for current code.

const renderer = new WebGPURenderer( { backend: myBackend } );

For this to be usable outside the library, Backend and WGSLNodeBuilder are now exported from three/webgpu (GLSLNodeBuilder already was). I dropped the @private tag on Backend and documented it as a low-level, experimental extension point whose interface may still change, since it seems the API around it is still moving.

@github-actions
Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 365.43
86.79
365.43
86.79
+0 B
+0 B
WebGPU 660.98
182.51
661.05
182.53
+71 B
+22 B
WebGPU Nodes 659.1
182.23
659.1
182.23
+0 B
+0 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 498.3
121.53
498.3
121.53
+0 B
+0 B
WebGPU 732.54
197.36
732.57
197.37
+35 B
+13 B
WebGPU Nodes 681.76
184.75
681.76
184.75
+0 B
+0 B

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant