From d425fe2de8ab57e56f5892be695929083054db14 Mon Sep 17 00:00:00 2001 From: sunag Date: Fri, 3 Nov 2023 16:02:33 -0300 Subject: [PATCH] draft --- examples/jsm/nodes/core/UniformNode.js | 2 ++ .../renderers/webgpu/nodes/WGSLNodeBuilder.js | 30 +++++++++++++------ .../webgpu/utils/WebGPUBindingUtils.js | 2 +- examples/webgpu_sandbox.html | 20 ++++++++----- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/examples/jsm/nodes/core/UniformNode.js b/examples/jsm/nodes/core/UniformNode.js index 76f01739531e9e..3f5a6b8ceff12f 100644 --- a/examples/jsm/nodes/core/UniformNode.js +++ b/examples/jsm/nodes/core/UniformNode.js @@ -10,6 +10,8 @@ class UniformNode extends InputNode { this.isUniformNode = true; + this.group = 'TEST'; + } getUniformHash( builder ) { diff --git a/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js b/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js index d8e703572ef399..c64ddce9d7bbbb 100644 --- a/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +++ b/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js @@ -270,7 +270,7 @@ class WGSLNodeBuilder extends NodeBuilder { } else { - return `NodeUniforms.${name}`; + return node.node.group + '.' + name; } @@ -345,14 +345,17 @@ class WGSLNodeBuilder extends NodeBuilder { } else { - let uniformsGroup = this.uniformsGroup[ shaderStage ]; + const uniformsStage = this.uniforms[ shaderStage ] || ( this.uniforms[ shaderStage ] = {} ); + const uniformsGroupName = node.group; + + let uniformsGroup = uniformsStage[ uniformsGroupName ]; if ( uniformsGroup === undefined ) { - uniformsGroup = new UniformsGroup( 'nodeUniforms' ); + uniformsGroup = new UniformsGroup( uniformsGroupName ); uniformsGroup.setVisibility( gpuShaderStageLib[ shaderStage ] ); - this.uniformsGroup[ shaderStage ] = uniformsGroup; + uniformsStage[ uniformsGroupName ] = uniformsGroup; bindings.push( uniformsGroup ); @@ -653,7 +656,9 @@ ${ flowData.code } const bindingSnippets = []; const bufferSnippets = []; - const groupSnippets = []; + const structSnippets = []; + + const uniformGroups = {}; let index = this.bindingsOffset[ shaderStage ]; @@ -720,6 +725,9 @@ ${ flowData.code } } else { const vectorType = this.getType( this.getVectorType( uniform.type ) ); + const groupName = uniform.node.group; + + const groupSnippets = uniformGroups[ groupName ] || ( uniformGroups[ groupName ] = [] ); if ( Array.isArray( uniform.value ) === true ) { @@ -737,15 +745,18 @@ ${ flowData.code } } - let code = bindingSnippets.join( '\n' ); - code += bufferSnippets.join( '\n' ); + for ( const group in uniformGroups ) { - if ( groupSnippets.length > 0 ) { + const groupSnippets = uniformGroups[ group ]; - code += this._getWGSLStructBinding( 'NodeUniforms', groupSnippets.join( ',\n' ), 'uniform', index ++ ); + structSnippets.push( this._getWGSLStructBinding( group, groupSnippets.join( ',\n' ), 'uniform', index ++ ) ); } + let code = bindingSnippets.join( '\n' ); + code += bufferSnippets.join( '\n' ); + code += structSnippets.join( '\n' ); + return code; } @@ -815,6 +826,7 @@ ${ flowData.code } this.vertexShader = this._getWGSLVertexCode( shadersData.vertex ); this.fragmentShader = this._getWGSLFragmentCode( shadersData.fragment ); + console.log( this.fragmentShader ); } else { diff --git a/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js b/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js index 1fa6a171375a3a..9a896081f3caab 100644 --- a/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js +++ b/examples/jsm/renderers/webgpu/utils/WebGPUBindingUtils.js @@ -120,7 +120,7 @@ class WebGPUBindingUtils { } updateBinding( binding ) { - +console.log( binding ); const backend = this.backend; const device = backend.device; diff --git a/examples/webgpu_sandbox.html b/examples/webgpu_sandbox.html index 89b5d291d2a9bc..0b9f1493804236 100644 --- a/examples/webgpu_sandbox.html +++ b/examples/webgpu_sandbox.html @@ -24,7 +24,7 @@