software-mansion / software-mansion/TypeGPU
[RFC] fix: `_typedExpression` casts boolean to int
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 3.2k
- Forks
- 122
- Avg merge
- 3d 5h
- Merged PRs (30d)
- 34
Description
Bug or feature?
it('...', () => {
const fn = tgpu.fn(() => {
'use gpu';
let a = d.u32();
a = true;
});
expect(tgpu.resolve([fn])).toMatchInlineSnapshot(`
"fn fn_1() {
var a = 0u;
a = 1u;
}"
`);
});
This means that booleans are allowed where they shouldn't be:
it('...', () => {
const fn = tgpu.fn(() => {
'use gpu';
let a = std.sin(true);
});
expect(tgpu.resolve([fn])).toMatchInlineSnapshot(`
"fn fn_1() {
let a = 0.8414709848078965f;
}"
`);
});
This is a bigger issue when boolean type is allowed by TS and disallowed by WGSL, eg. in switch tests
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 the _typedExpression implementation and reproduce the two tgpu.fn/tgpu.resolve examples from the issue, then inspect the referenced switch tests. The fix is done when boolean expressions are no longer accepted or emitted as numeric values where the target shader type disallows them.
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
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100