Skip to content

WebGPURenderer: Ensure render targets have consistent default depth values.#33191

Merged
Mugen87 merged 2 commits intomrdoob:devfrom
Mugen87:dev6
Mar 17, 2026
Merged

WebGPURenderer: Ensure render targets have consistent default depth values.#33191
Mugen87 merged 2 commits intomrdoob:devfrom
Mugen87:dev6

Conversation

@Mugen87
Copy link
Copy Markdown
Collaborator

@Mugen87 Mugen87 commented Mar 16, 2026

Related issue: -

Description

This issue has driven me nuts^^. I've encountered a strange rendering issue in a complex render setup and couldn't find the root cause. It took a while to isolate this issue but the following test case demonstrates a bug in WebGPURenderer:

https://jsfiddle.net/2mdwzyge/

As you can see nothing is rendered but when switching to the WebGL 2 backend the result is as expected (a rotating cube producing trails).

When autoClear is set to false, the default values in a depth texture actually vary between WebGPU and WebGL (0 vs 1). This can produce hard to track bugs/inconsistent behavior so we should make sure WebGPURenderer setups depth textures with consistent default depth values.

The PR is doing this by checking for uninitialized render targets and clears the depth once if autoClear or autoClearDepth is disabled. When the auto clear flags are not changed, the render target will be guaranteed in a valid state because of the automatic clear.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 16, 2026

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 359.97
85.54
359.97
85.54
+0 B
+0 B
WebGPU 631.1
175.11
631.35
175.18
+252 B
+69 B
WebGPU Nodes 629.21
174.83
629.47
174.9
+252 B
+70 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 492.17
120.12
492.17
120.12
+0 B
+0 B
WebGPU 703.53
189.96
703.78
190.02
+252 B
+68 B
WebGPU Nodes 652.75
177.35
653
177.41
+252 B
+68 B

@sunag sunag added this to the r184 milestone Mar 16, 2026
@Mugen87 Mugen87 marked this pull request as draft March 16, 2026 15:35
@Mugen87
Copy link
Copy Markdown
Collaborator Author

Mugen87 commented Mar 16, 2026

Something with the framebuffer setup/clear in the WebGL backend isn't right. Investigating...

const renderTargetData = this._textures.get( renderTarget );

renderContext = this._renderContexts.get( renderTarget );
renderContext = this._renderContexts.get( renderTarget, null, - 1 ); // using - 1 for the call depth to get a render context for the clear operation
Copy link
Copy Markdown
Collaborator Author

@Mugen87 Mugen87 Mar 16, 2026

Choose a reason for hiding this comment

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

This was actually a bug. Nested calls of clear() corrupted the render context. It's not a common use case but the new clearDepth() call exposed it.

The callDepth approach introduced in #32546 for managing render contexts isn't ideal, tbh. While it helps to reduce the overall number of render contexts, it is error prone since you have to be careful not to request the wrong context like clear() did.

@Mugen87 Mugen87 marked this pull request as ready for review March 16, 2026 19:54
@Mugen87 Mugen87 merged commit ceeebef into mrdoob:dev Mar 17, 2026
10 checks passed
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.

2 participants