Skip to content

Conversation

@Mugen87
Copy link
Collaborator

@Mugen87 Mugen87 commented Aug 27, 2025

Fixed #31658.

Description

Turns out we have a bug in our readback buffer size computation in the WebGPU backend. We must honor the row padding in the buffer computation except for the last row. Credits to @greggman who explained the fix at the Chromium bug tracker and here: #31658 (comment) 🙌 !

@Mugen87 Mugen87 added this to the r180 milestone Aug 27, 2025
@github-actions
Copy link

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 338.91
79.11
338.91
79.11
+0 B
+0 B
WebGPU 579.38
159.66
579.39
159.66
+6 B
+4 B
WebGPU Nodes 577.99
159.41
578
159.42
+6 B
+5 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 470.78
113.9
470.78
113.9
+0 B
+0 B
WebGPU 649.53
175.52
649.54
175.53
+6 B
+5 B
WebGPU Nodes 603.63
164.66
603.64
164.67
+6 B
+4 B

@Mugen87 Mugen87 merged commit cf60b96 into mrdoob:dev Aug 28, 2025
9 checks passed
const readBuffer = device.createBuffer(
{
size: width * height * bytesPerTexel,
size: ( height - 1 ) * bytesPerRow + width * bytesPerTexel, // see https://github.com/mrdoob/three.js/issues/31658#issuecomment-3229442010
Copy link
Owner

Choose a reason for hiding this comment

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

Is this more readable?

( width * bytesPerTexel ) + ( ( height - 1 ) * bytesPerRow )

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IMO, the "( height - 1 ) * bytesPerRow" bit should come first since "( width * bytesPerTexel )" represents the last row of data.

Copy link
Owner

Choose a reason for hiding this comment

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

Then this?

( height - 1 ) * bytesPerRow + ( width * bytesPerTexel )

Or even this?

( ( height - 1 ) * bytesPerRow ) + ( width * bytesPerTexel )

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I vote for the last one!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated: 6c7d807

Definitely improves code clarity 👍 .

@mrdoob
Copy link
Owner

mrdoob commented Aug 28, 2025

Thanks @greggman!

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.

RenderTarget + WebGPU Backend: 'readRenderTargetPixelsAsync' returns blank data regardless of configuration

2 participants