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

Struct Not Generating in All Relevant WGSL Files #30434

Closed
cmhhelgeson opened this issue Jan 31, 2025 · 2 comments · Fixed by #30439
Closed

Struct Not Generating in All Relevant WGSL Files #30434

cmhhelgeson opened this issue Jan 31, 2025 · 2 comments · Fixed by #30439
Labels
Bug TSL Three.js Shading Language
Milestone

Comments

@cmhhelgeson
Copy link
Contributor

cmhhelgeson commented Jan 31, 2025

Description

*Related Issues: #30394

@sunag
I'm now getting a different issue where a TSL inline function (i.e a function that generates code inline within the main function) that calls a setLayout function is not properly defining the structType in every file where that struct type appears.

For instance my computeHeight function calls an inline TSL function GetNeighborValues() which calls a setLayout function GetNeighborIndices(). My computeSmooth function calls the exact same function. However, on compilation, while both functions will properly generate the GetNeighborIndices function in WGSL, the computeHeight function generates the NeighborIndicesStructType in WGSL while the computeSmooth function does not.

I've updated the link with these changes. Clicking the computeSmooth function call will result in this compilation error:

Image

Reproduction steps

  1. In webgpu_compute_water, replace the current call to getNeighborIndicesTSL with a defined function executing the same code, but created with set layout.
  2. Have that function return a struct type for the relevant returned values.

Code

Relevant TSL calls are below. destructureStruct is simply a convenience function. The WGSL output does not meaningfully change irrespective of whether it is used or not

// Struct Definition

const NeighborIndicesStructure = {
	northIndex: 'uint',
	eastIndex: 'uint',
	southIndex: 'uint',
	westIndex: 'uint',
};
const NeighborIndicesStruct = struct( NeighborIndicesStructure, 'NeighborIndicesStructType' );
const NeighborValuesStruct = struct( NeighborValuesStructure, 'NeighborValuesStructType' );


// Compute Height shader
```ts
// This codepath calls GetNeighborIndices and properly generates the NeighborIndicesStructType returned by GetNeighborIndices
const { north, south, east, west } = destructureStruct( NeighborValuesStructure, GetNeighborValues( instanceIndex, heightStorage ) );

// Compute smooth shader

// This code path calls GetNeighborIndices and does not generate the NeighborIndicesStructType returned by GetNeighborIndices
const { north: northH, south: southH, east: eastH, west: westH } = destructureStruct( NeighborValuesStructure, GetNeighborValues( instanceIndex, heightStorage ) );

Live example

Live WebGPU Example

Screenshots

No response

Version

r173

Device

Desktop

Browser

Chrome

OS

Windows

@sunag
Copy link
Collaborator

sunag commented Jan 31, 2025

It seems to me here that the layout was defined in a function, but the structure was never used, so there was no declaration by NodeBuilder. I think if you return the structure this shouldn't happen? I couldn't see the error in your example.

@cmhhelgeson
Copy link
Contributor Author

cmhhelgeson commented Feb 1, 2025

It seems to me here that the layout was defined in a function, but the structure was never used, so there was no declaration by NodeBuilder. I think if you return the structure this shouldn't happen? I couldn't see the error in your example.

The compilation error should occur upon pressing the Compute Smooth button. I believe that function only gets compiled once the button is pressed.

@sunag sunag added this to the r174 milestone Feb 1, 2025
@sunag sunag added Bug TSL Three.js Shading Language labels Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug TSL Three.js Shading Language
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants