Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TSL: Fix WGSL Functions using wrong type #28690

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Move outputType to WGSLNodeFunction
  • Loading branch information
sunag committed Jun 18, 2024
commit db9d8da6a298e6421b645369d874c1d81eb15a59
2 changes: 1 addition & 1 deletion examples/jsm/nodes/code/FunctionNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class FunctionNode extends CodeNode {

const propertyName = builder.getPropertyName( nodeCode );

let code = this.getNodeFunction( builder ).getCode( propertyName, builder.getType(type) );
let code = this.getNodeFunction( builder ).getCode( propertyName );

const keywords = this.keywords;
const keywordsProperties = Object.keys( keywords );
Expand Down
17 changes: 9 additions & 8 deletions examples/jsm/renderers/webgpu/nodes/WGSLNodeFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,18 @@ const parse = ( source ) => {
}

const blockCode = source.substring( declaration[ 0 ].length );
const outputType = declaration[ 3 ] || 'void';

const name = declaration[ 1 ] !== undefined ? declaration[ 1 ] : '';
let type = declaration[ 3 ] || 'void';

type = wgslTypeLib[type] || type;
const type = wgslTypeLib[ outputType ] || outputType;

return {
type,
inputs,
name,
inputsCode,
blockCode
blockCode,
outputType
};

} else {
Expand All @@ -123,20 +123,21 @@ class WGSLNodeFunction extends NodeFunction {

constructor( source ) {

const { type, inputs, name, inputsCode, blockCode } = parse( source );
const { type, inputs, name, inputsCode, blockCode, outputType } = parse( source );

super( type, inputs, name );

this.inputsCode = inputsCode;
this.blockCode = blockCode;
this.outputType = outputType;

}

getCode( name = this.name, outputType = this.type ) {
getCode( name = this.name ) {

const type = outputType !== 'void' ? '-> ' + outputType : '';
const outputType = this.outputType !== 'void' ? '-> ' + this.outputType : '';

return `fn ${ name } ( ${ this.inputsCode.trim() } ) ${ type }` + this.blockCode;
return `fn ${ name } ( ${ this.inputsCode.trim() } ) ${ outputType }` + this.blockCode;

}

Expand Down