Skip to content

Commit

Permalink
const/let both backends?
Browse files Browse the repository at this point in the history
  • Loading branch information
RenaudRohlinger committed Jan 4, 2025
1 parent 4c56bad commit 5acf730
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/nodes/core/VarNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,30 @@ class VarNode extends Node {

const { node, name, readOnly } = this;

const nodeVar = builder.getVarFromNode( this, name, builder.getVectorType( this.getNodeType( builder ) ), undefined, readOnly );
// TODO: Is it enough to detect if a node is a constant and never reassigned?
const isConst = ( node.type === 'MathNode' || node.type === 'ConvertNode' || node.type === 'ConstNode' ) && readOnly === true;

const nodeVar = builder.getVarFromNode( this, name, builder.getVectorType( this.getNodeType( builder ) ), undefined, isConst );

const propertyName = builder.getPropertyName( nodeVar );

const snippet = node.build( builder, nodeVar.type );

if ( readOnly === true ) {

const isLet = builder.renderer.backend.isWebGPUBackend === true ? 'let' : 'const';

if ( readOnly === true && ( isConst === true || builder.renderer.backend.isWebGPUBackend === true ) ) {


const type = builder.getType( nodeVar.type );
let declarationType = `const ${type}`;

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

declarationType = isConst ? `const ${type}` : 'let';

}

builder.addLineFlowCode( `const ${type} ${propertyName} = ${snippet}`, this );
builder.addLineFlowCode( `${declarationType} ${propertyName} = ${snippet}`, this );

} else {

Expand Down

0 comments on commit 5acf730

Please sign in to comment.