Skip to content

TSL: Add support packed 4x8 integer operations - #34412

Open
bhouston wants to merge 3 commits into
mrdoob:devfrom
bhouston:wgsl-language-features
Open

TSL: Add support packed 4x8 integer operations#34412
bhouston wants to merge 3 commits into
mrdoob:devfrom
bhouston:wgsl-language-features

Conversation

@bhouston

@bhouston bhouston commented Aug 31, 2026

Copy link
Copy Markdown
Contributor
  • Add TSL support for the eight built-ins provided by WGSL's packed_4x8_integer_dot_product language extension.
  • Follow the pattern established by subgroup nodes: expose the WebGPU-only operations directly.
  • Placed in examples/jsm so as to avoid making the ThreeJS bundle larger.
  • Add WebGPU tests for signed and unsigned dot products, packing, unpacking, clamping, byte layout, and sign extension. The tests skip when the browser does not support the language feature.

@github-actions

Copy link
Copy Markdown

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
Core 389.13
102.11
389.13
102.11
+0 B
+0 B
WebGL 372.46
87.93
372.46
87.93
+0 B
+0 B
WebGPU 704.94
194.28
706.74
194.77
+1.79 kB
+498 B
WebGPU Nodes 702.93
193.96
704.72
194.45
+1.79 kB
+496 B

🌳 Bundle size after tree-shaking

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

Before After Diff
WebGL 515.87
124.88
515.87
124.88
+0 B
+0 B
WebGPU 762.71
204.8
762.71
204.8
+0 B
+0 B
WebGPU Nodes 711.37
192.07
711.37
192.07
+0 B
+0 B

@bhouston bhouston changed the title TSL:L Add support packed 4x8 integer operations TSL: Add support packed 4x8 integer operations Aug 31, 2026

generate( builder, output ) {

if ( builder.renderer.backend.isWebGPUBackend !== true ) {

@Mugen87 Mugen87 Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should also add below check in the if clause:

navigator.gpu.wgslLanguageFeatures.has( 'packed_4x8_integer_dot_product' )


if ( builder.renderer.backend.isWebGPUBackend !== true ) {

throw new Error( `THREE.TSL: "${this.method}" is only supported by the WebGPU backend.` );

@Mugen87 Mugen87 Sep 1, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Follow the pattern established by subgroup nodes: expose the WebGPU-only operations directly.

I'm not sure this is the right call here. Subgroup functions can't exist without hardware support, so it's fine to throw errors in that context. But in the context of packed_4x8_integer_dot_product , all eight builtins are emulatable with plain integer bit operations. We only loose hardware acceleration but that is acceptable, imo.

  • The pack/unpack functions are shift/mask sequences.
  • The dot functions basically unpack both operands and multiply-add the four lanes.

Let's try to use BitcountNode as a template instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would you like emulation just for WGSL? Or also for GLSL?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will add both for now.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, for both.

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown

🖼️ E2E screenshot tests

1 example(s) failed (full artifacts).

Example Expected Actual Diff
webgpu_video_panorama

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