software-mansion / software-mansion/TypeGPU
fix: Resolve struct names when `tgpu.fn` is created from raw WGSL.
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.2k
- Forks
- 122
- Avg merge
- 3d 5h
- Merged PRs (30d)
- 34
Description
Currently, in functions we resolve the struct name either from externals or from the direct return/parameter types, for example:
const Point = d.struct({ a: d.u32, b: d.u32 }).$name('P');
const func = tgpu.fn([Point], Point)`(a: MyArbitraryNameForAStruct) -> MyArbitraryNameForAStruct {
return MyArbitraryNameForAStruct;
}`;
In generated wgsl, MyArbitraryNameForAStruct will be replaced by a name based on the label P.
This behavior is not present when the struct type is used indirectly, and the following code is resolved incorrectly:
const func = tgpu.fn([d.arrayOf(Point, 4)])`(a: array<MyStruct, 4>) : u32 {
return a.a;
}`;
Right now, an incorrect wgsl code is generated. I think that we should either expand on this functionality, or get rid of it all together and force the users to name their structs in externals (possibly throw when we detect this situation). What do you think @reczkok @mhawryluk @lursz @iwoplaza?
Edit: My bad, it doesn't work only for indirect uses
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at tgpu.fn creation from raw WGSL and trace how struct names are resolved for direct parameter and return types versus indirect uses such as arrayOf(Point, 4). Compare the generated WGSL for both examples, then verify that the indirect struct reference uses the labeled name P and no longer produces incorrect WGSL.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100