From 2614bff28c0ca995fa4c24735e95331333ef6626 Mon Sep 17 00:00:00 2001 From: Christian Helgeson <62450112+cmhhelgeson@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:47:05 -0700 Subject: [PATCH 1/2] add polyfill for GLSLNodeBuilder --- .../webgl-fallback/nodes/GLSLNodeBuilder.js | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js b/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js index 7728c0bf741162..a106f5a7f10f45 100644 --- a/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +++ b/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js @@ -1,4 +1,4 @@ -import { GLSLNodeParser, NodeBuilder, TextureNode, vectorComponents } from '../../../nodes/Nodes.js'; +import { GLSLNodeParser, NodeBuilder, TextureNode, vectorComponents, CodeNode } from '../../../nodes/Nodes.js'; import NodeUniformBuffer from '../../common/nodes/NodeUniformBuffer.js'; import NodeUniformsGroup from '../../common/nodes/NodeUniformsGroup.js'; @@ -9,6 +9,11 @@ import { NoColorSpace, ByteType, ShortType, RGBAIntegerFormat, RGBIntegerFormat, import { DataTexture } from '../../../textures/DataTexture.js'; import { error } from '../../../utils.js'; +const glslPolyfills = { + bitcast_int_uint: new CodeNode( /* glsl */'uint tsl_bitcast_uint_to_int ( int x ) { return floatBitsToInt( uintBitsToFloat( x ) ); }' ), + bitcast_uint_int: new CodeNode( /* glsl */'uint tsl_bitcast_int_to_uint ( int x ) { return floatBitsToUint( intBitsToFloat ( x ) ); }' ) +}; + const glslMethods = { textureDimensions: 'textureSize', equals: 'equal', @@ -16,6 +21,8 @@ const glslMethods = { bitcast_int_float: 'intBitsToFloat', bitcast_uint_float: 'uintBitsToFloat', bitcast_float_uint: 'floatBitsToUint', + bitcast_uint_int: 'tsl_bitcast_uint_to_int', + bitcast_int_uint: 'tsl_bitcast_int_to_uint' }; const precisionLib = { @@ -127,6 +134,25 @@ class GLSLNodeBuilder extends NodeBuilder { } + /** + * Includes the given method name into the current + * function node. + * + * @private + * @param {string} name - The method name to include. + * @return {CodeNode} The respective code node. + */ + _include( name ) { + + const codeNode = glslPolyfills[ name ]; + codeNode.build( this ); + + this.addInclude( codeNode ); + + return codeNode; + + } + /** * Returns the native shader method name for a given generic name. * @@ -135,6 +161,12 @@ class GLSLNodeBuilder extends NodeBuilder { */ getMethod( method ) { + if ( glslPolyfills[ method ] !== undefined ) { + + this._include( method ); + + } + return glslMethods[ method ] || method; } @@ -148,7 +180,7 @@ class GLSLNodeBuilder extends NodeBuilder { */ getBitcastMethod( type, inputType ) { - return glslMethods[ `bitcast_${ inputType }_${ type }` ]; + return this.getMethod( `bitcast_${ inputType }_${ type }` ); } From 3e35cdf90ba1e8f93c48a96f4fd561e5d60c389e Mon Sep 17 00:00:00 2001 From: Christian Helgeson <62450112+cmhhelgeson@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:52:56 -0700 Subject: [PATCH 2/2] unify how GLSL _include and WGSL _include work --- src/renderers/webgpu/nodes/WGSLNodeBuilder.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js index cb7f1053376b09..b24000d1cbd4b2 100644 --- a/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/src/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -2068,11 +2068,7 @@ ${ flowData.code } const codeNode = wgslPolyfill[ name ]; codeNode.build( this ); - if ( this.currentFunctionNode !== null ) { - - this.currentFunctionNode.includes.push( codeNode ); - - } + this.addInclude( codeNode ); return codeNode;