Skip to content

Renderers: Cache pixel storage parameters.#33227

Merged
Mugen87 merged 3 commits into
mrdoob:devfrom
Mugen87:dev6
Mar 23, 2026
Merged

Renderers: Cache pixel storage parameters.#33227
Mugen87 merged 3 commits into
mrdoob:devfrom
Mugen87:dev6

Conversation

@Mugen87

@Mugen87 Mugen87 commented Mar 23, 2026

Copy link
Copy Markdown
Collaborator

Fixed #33223.

Description

I've realized today setting pixel storage modes in WebGL 2 is actually a global setting that affects all subsequent texture operations. Because of that, we can cache it in WebGLState. This is now in done in WebGLRenderer and the WebGL 2 backend of WebGPURenderer.

The PR also introduces state.getParameter() for requesting cached parameters. If nothing is cached, it request the parameter value via gl.getParameter() instead.

As mentioned in #33223, getParameter() can indeed introduce performance issue. It seems depending on the WebGL implementation and the requested parameter, getParameter() can lead to a flush (which essentially means WebGL waits until all queue commands are finished by the GPU before returning the parameter value) so we should access the cache first whenever possible.

@Mugen87 Mugen87 changed the title Renderer: Cache pixel storage parameters. Renderers: Cache pixel storage parameters. Mar 23, 2026
@github-actions

github-actions Bot commented Mar 23, 2026

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 360.82
85.68
360.82
85.68
+0 B
+0 B
WebGPU 632.75
175.53
632.75
175.53
+0 B
+0 B
WebGPU Nodes 630.87
175.24
630.87
175.24
+0 B
+0 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 493.02
120.25
493.02
120.25
+0 B
+0 B
WebGPU 705.18
190.51
705.18
190.51
+0 B
+0 B
WebGPU Nodes 654.4
177.79
654.4
177.79
+0 B
+0 B

const glayer = xr.getBinding().getSubImage( guiLayer, frame );
renderer.state.bindTexture( gl.TEXTURE_2D, glayer.colorTexture );
gl.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, true );
renderer.state.pixelStorei( gl.UNPACK_FLIP_Y_WEBGL, true );

@Mugen87 Mugen87 Mar 23, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Since users might access gl.pixelStorei() as well, I'm going to put this change into the migration guide so users switch to state.pixelStorei().

@Mugen87 Mugen87 added this to the r184 milestone Mar 23, 2026
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.

renderTextureToTexture slows down with getParameter

1 participant