Skip to content

Conversation

cmhhelgeson
Copy link
Contributor

@cmhhelgeson cmhhelgeson commented Aug 29, 2025

Related issue: #31735

Description

Adds specialized blocks for translating bitcast functionality.

image

@sunag
Copy link
Collaborator

sunag commented Aug 29, 2025

Instead of modifying the transpiler, could you create these functions as aliases in BitcastNode?

I think the GLSL functions have better names and this would also make migration easier since the transpiler is optional.

Copy link

github-actions bot commented Aug 30, 2025

📦 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.29
159.67
579.78
159.79
+490 B
+120 B
WebGPU Nodes 577.9
159.43
578.39
159.55
+490 B
+120 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.44
175.54
649.44
175.54
+0 B
+0 B
WebGPU Nodes 603.54
164.69
603.54
164.69
+0 B
+0 B

@cmhhelgeson
Copy link
Contributor Author

cmhhelgeson commented Aug 30, 2025

Example Code:

// ToVar() added for clarity
const instanceIndexBitcastFloat = uintBitsToFloat( float( instanceIndex ) );
const instanceIndexBitcastUint = floatBitsToUint( uint( instanceIndexBitcastFloat ) );
const floatToFloat = bitcast( instanceIndex, 'uint' ).toVar();

// vectors

const vec2Example = uintBitsToFloat( vec2(instanceIndex));
const vec2NativeBitcast = bitcast(instanceIndex, 'vec2')
// Note how with GLSL alias functions, inputType of original GLSL function is enforced
nodeVar0 = bitcast<f32>( u32( f32( instanceIndex ) ) );
nodeVar1 = bitcast<u32>( f32( u32( nodeVar0 ) ) );
// Whereas WGSL implementation is more freeform
nodeVar3 = bitcast<u32>( instanceIndex );


// vectors

nodeVar4 = bitcast<vec2<f32>>(vec2<u32>(instanceIndex, instanceIndex));
// regular bitcast will just translate what is given to it
nodeVar5 = bitcast<vec2<f32>>(instanceIndex);

@cmhhelgeson cmhhelgeson marked this pull request as ready for review August 31, 2025 18:03
@cmhhelgeson cmhhelgeson changed the title Transpiler - Add Bitcast Transpiler/BitcastNode - Add Bitcast and GLSL Alias Functions Sep 1, 2025
@sunag sunag added this to the r180 milestone Sep 2, 2025
@sunag sunag changed the title Transpiler/BitcastNode - Add Bitcast and GLSL Alias Functions TSL: Add bitcast functions and transpiler support Sep 2, 2025
@sunag sunag merged commit 8e16eaf into mrdoob:dev Sep 2, 2025
9 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