software-mansion / software-mansion/TypeGPU
bug: WGSL-implemented entry function args can shadow local definitions
Open
bug
- Dominant language
- TypeScript
- Stars
- 3.2k
- Forks
- 122
- Avg merge
- 3d 5h
- Merged PRs (30d)
- 34
Description
The following WGSL-implemented vertex function:
const mainVertex = tgpu.vertexFn({
in: { vi: d.builtin.vertexIndex },
out: { outPos: d.builtin.position },
})(/* wgsl */ `{
var pos = array<vec2f, 3>(
vec2(0.0, 0.5),
vec2(-0.5, -0.5),
vec2(0.5, -0.5)
);
var vi = in.vi;
return Out(vec4f(pos[in.vertexIndex], 0.0, 1.0));
}`);
Currently generates the following WGSL:
struct mainVertex_Output {
@builtin(position) outPos: vec4f,
}
@vertex fn mainVertex(@builtin(vertex_index) vi: u32) -> mainVertex_Output {
var pos = array<vec2f, 3>(
vec2(0.0, 0.5),
vec2(-0.5, -0.5),
vec2(0.5, -0.5)
);
var vi = vi;
return mainVertex_Output(vec4f(pos[in.vertexIndex], 0.0, 1.0));
}
Notice the var vi = vi line.
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
Reproduce the issue with the provided TypeScript vertexFn example and inspect the generated WGSL around the entry-function parameters and local definitions. The fix is complete when an entry argument and a local declaration with the same name no longer produce a self-shadowing assignment such as var vi = vi; verify the generated shader remains valid.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100