-
Notifications
You must be signed in to change notification settings - Fork 245
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
wgsl output doesn't use parenthesis for mixed operations, generating invalid code #6005
Comments
I have a fix ready for this, but I'll spend some more time tomorrow creating more exhaustive tests for this type of issue. |
Add parentheses for a few cases that Dawn/Tint (WGSL compiler) complains about. Closes shader-slang#6005.
With the above fix, the following WGSL code is now generated for the mentioned https://shader-playground.timjones.io/a6fbc241c06921e0e3b71c5dfd1ad03d |
Hey @aleino-nv, great work!
Same with
|
@expenses Thanks for reporting this! I will re-open this issue and look at some more cases. |
@aleino-nv this might help, to quote #6005:
|
But what's an 'associativity group'? Does it correspond to a box in that section? (That section is non-normative, btw.) In any case, I guess the important fact is that we've now seen several examples of various WGSL compilers requiring parentheses that are not really required by the implementation. Slang should produce WGSL that's compatible with as many browsers (or standalone WGSL compilers) as possible, and versions thereof. |
Perhaps @sagudev or someone else on the naga/tint/wgsl spec teams could comment? |
For your concrete example it this is relevant part:
I think the best place would be to ask on spec repo. |
@sagudev Thanks, but I think I understand how it works. I was just thinking about how to approach a fix in a way that's robust and will last basically no matter what the WGSL compilers do. I have a proposed patch for several similar issues now, and some pretty exhaustive tests. |
Almost there! I found one last remaining issue with operations on // Computes `dir > 0 ? 3.0 - pos : pos`
// with special case to avoid rounding.
static float3 GetMirroredPos(float3 pos, float3 dir, bool rangeCheck) {
float3 mirrored = asfloat(asuint(pos) ^ 0x7FFFFF);
// XOR'ing will only work if the coords are in range [1.0, 2.0),
// so just fallback to the original subtraction if that's not the case.
if (rangeCheck && any(pos < 1.0 | pos >= 2.0)) mirrored = 3.0 - pos;
return select(dir > 0, mirrored, pos);
} generates: |
There were some cases missing that were not caught by the tests I added because After another fix I'm now seeing https://shader-playground.timjones.io/f4fe1f09bd5ccb623c3b9b3476aabedd |
… operators This closes shader-slang#6005.
… operators This closes shader-slang#6005.
This is required since the Dawn WGSL compiler requires parentheses even though precedence rules could resolve order of operations. This closes shader-slang#6005.
This is required since the Dawn WGSL compiler requires parentheses even though precedence rules could resolve order of operations. This closes shader-slang#6005.
This is required since the Dawn WGSL compiler requires parentheses even though precedence rules could resolve order of operations. This closes shader-slang#6005.
See gfx-rs/wgpu#6857
I got this error in Chromium
slang code: https://github.com/NVIDIAGameWorks/Falcor/blob/9dc819c162b2070335c65060436041690b7937f8/Source/Falcor/Utils/Math/HashUtils.slang#L62-L74
The text was updated successfully, but these errors were encountered: