Skip to content

Struct Not Generating in All Relevant WGSL Files #30434

@cmhhelgeson

Description

@cmhhelgeson

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugTSLThree.js Shading Language

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions