Skip to content

TSL - Nested If-nodes cause wrong code compilation #31039

Closed
@holtsetio

Description

@holtsetio

Description

When nesting If- and Else-nodes in TSL, the code compilation gets messed up.

Consider for example the following TSL code:

const foo = float(1).mul(2);
const result = float(0).toVar();
If( instanceIndex.equal(uint(0)), () => {
	result.assign( foo );
} ).Else( () => {
	If( instanceIndex.equal(uint(1)), () => {
		result.assign( foo );
	} ).Else( () => {
		result.assign( foo );
	} );
} );
outputBuffer.element(instanceIndex).assign(result);

Here it is clear that every element of the outputBuffer should be set to 1*2=2, the initial value of variable foo.

However, it gets transpiled to the following wgsl code:

// #--- TSL debug - compute shader ---#
nodeVar0 = 0.0;
if ( ( instanceIndex == 0u ) ) {
	nodeVar0 = ( 1.0 * 2.0 );
} else {
	if ( ( instanceIndex == 1u ) ) {
		nodeVar1 = ( 1.0 * 2.0 );
		nodeVar0 = nodeVar1;
	} else {
		nodeVar0 = nodeVar1;
	}
}
NodeBuffer_529.value[ instanceIndex ] = nodeVar0;

Where nodeVar0 gets set to an uninitialized nodeVar1 for every instanceIndex except 0 and 1.

This breaks for example the mx_hsvtorgb() function in the current release r176.

See the attached jsfiddle for a live example.

Live example

Screenshots

No response

Version

r176-dev

Metadata

Metadata

Assignees

Labels

TSLThree.js Shading Language

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions