-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[naga wgsl-out] Represent min value i64 literals as -9223372036854775807li - 1li
#7424
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…5807li - 1li` ie the second-most negative value minus 1. The most negative value of an integer type is not directly expressible in WGSL, as it relies on applying the unary negation operator to a value which is one larger than the largest value representable by the type. To avoid this issue for i32, we negate the required value as an AbstractInt before converting to i32. AbstractInt, being 64 bits, is capable of representing the maximum i32 value + 1. However, for i64 this is not the case. Instead this patch makes us express the mimimum i64 value as the second most negative i64 value, minus 1, ie `-9223372036854775807li - 1li`, thereby avoiding the issue.
Merged
4 tasks
ErichDonGubler
approved these changes
Mar 25, 2025
jamienicol
added a commit
to LegNeato/wgpu
that referenced
this pull request
Mar 27, 2025
gfx-rs#7424 fixed a bug where the representation of the minimum int64 literal generated by naga was invalid WGSL. It changed us from expressing it as `-9223372036854775808` which was invalid, to `-9223372036854775807li - 1li`. This is valid WGSL. However, as the values are concrete i64 types if the shader is parsed again by naga the expression does not get const evaluated away, leading to suboptimal code generated by the backends. This patch makes us perform the subtraction using abstract integers before casting to i64, solving this problem. Additionally the input WGSL test is updated to use the same construct.
jamienicol
added a commit
to LegNeato/wgpu
that referenced
this pull request
Mar 27, 2025
gfx-rs#7424 fixed a bug where the representation of the minimum int64 literal generated by naga was invalid WGSL. It changed us from expressing it as `-9223372036854775808` which was invalid, to `-9223372036854775807li - 1li`. This is valid WGSL. However, as the values are concrete i64 types if the shader is parsed again by naga the expression does not get const evaluated away, leading to suboptimal code generated by the backends. This patch makes us perform the subtraction using abstract integers before casting to i64, solving this problem. Additionally the input WGSL test is updated to use the same construct.
6 tasks
jamienicol
added a commit
to LegNeato/wgpu
that referenced
this pull request
Mar 27, 2025
gfx-rs#7424 fixed a bug where the representation of the minimum int64 literal generated by naga was invalid WGSL. It changed us from expressing it as `-9223372036854775808` which was invalid, to `-9223372036854775807li - 1li`. This is valid WGSL. However, as the values are concrete i64 types if the shader is parsed again by naga the expression does not get const evaluated away, leading to suboptimal code generated by the backends. This patch makes us perform the subtraction using abstract integers before casting to i64, solving this problem. Additionally the input WGSL test is updated to use the same construct.
jamienicol
added a commit
to LegNeato/wgpu
that referenced
this pull request
Mar 27, 2025
In gfx-rs#7424 we fixed a bug where the representation of the minimum int64 literal generated by naga was invalid WGSL. It changed us from expressing it as `-9223372036854775808` which was invalid, to `-9223372036854775807li - 1li`. This is valid WGSL. However, as the values are concrete i64 types if the shader is parsed again by naga the expression does not get const evaluated away, leading to suboptimal code generated by the backends. This patch makes us perform the subtraction using abstract integers before casting to i64, solving this problem. Additionally the input WGSL test is updated to use the same construct.
jamienicol
added a commit
to LegNeato/wgpu
that referenced
this pull request
Mar 27, 2025
In gfx-rs#7424 we fixed a bug where the representation of the minimum int64 literal generated by naga was invalid WGSL. It changed us from expressing it as `-9223372036854775808` which was invalid, to `-9223372036854775807li - 1li`. This is valid WGSL. However, as the values are concrete i64 types if the shader is parsed again by naga the expression does not get const evaluated away, leading to suboptimal code generated by the backends. This patch makes us perform the subtraction using abstract integers before casting to i64, solving this problem. Additionally the input WGSL test is updated to use the same construct.
LegNeato
pushed a commit
to LegNeato/wgpu
that referenced
this pull request
Apr 9, 2025
In gfx-rs#7424 we fixed a bug where the representation of the minimum int64 literal generated by naga was invalid WGSL. It changed us from expressing it as `-9223372036854775808` which was invalid, to `-9223372036854775807li - 1li`. This is valid WGSL. However, as the values are concrete i64 types if the shader is parsed again by naga the expression does not get const evaluated away, leading to suboptimal code generated by the backends. This patch makes us perform the subtraction using abstract integers before casting to i64, solving this problem. Additionally the input WGSL test is updated to use the same construct.
ErichDonGubler
pushed a commit
that referenced
this pull request
Apr 9, 2025
In #7424 we fixed a bug where the representation of the minimum int64 literal generated by naga was invalid WGSL. It changed us from expressing it as `-9223372036854775808` which was invalid, to `-9223372036854775807li - 1li`. This is valid WGSL. However, as the values are concrete i64 types if the shader is parsed again by naga the expression does not get const evaluated away, leading to suboptimal code generated by the backends. This patch makes us perform the subtraction using abstract integers before casting to i64, solving this problem. Additionally the input WGSL test is updated to use the same construct.
Vecvec
pushed a commit
to Vecvec/wgpu
that referenced
this pull request
Apr 11, 2025
In gfx-rs#7424 we fixed a bug where the representation of the minimum int64 literal generated by naga was invalid WGSL. It changed us from expressing it as `-9223372036854775808` which was invalid, to `-9223372036854775807li - 1li`. This is valid WGSL. However, as the values are concrete i64 types if the shader is parsed again by naga the expression does not get const evaluated away, leading to suboptimal code generated by the backends. This patch makes us perform the subtraction using abstract integers before casting to i64, solving this problem. Additionally the input WGSL test is updated to use the same construct.
jimblandy
pushed a commit
to jimblandy/wgpu
that referenced
this pull request
Apr 18, 2025
In gfx-rs#7424 we fixed a bug where the representation of the minimum int64 literal generated by naga was invalid WGSL. It changed us from expressing it as `-9223372036854775808` which was invalid, to `-9223372036854775807li - 1li`. This is valid WGSL. However, as the values are concrete i64 types if the shader is parsed again by naga the expression does not get const evaluated away, leading to suboptimal code generated by the backends. This patch makes us perform the subtraction using abstract integers before casting to i64, solving this problem. Additionally the input WGSL test is updated to use the same construct.
sharmajai
pushed a commit
to sharmajai/wgpu
that referenced
this pull request
Oct 12, 2025
…5807li - 1li` (gfx-rs#7424) ie the second-most negative value minus 1. The most negative value of an integer type is not directly expressible in WGSL, as it relies on applying the unary negation operator to a value which is one larger than the largest value representable by the type. To avoid this issue for i32, we negate the required value as an AbstractInt before converting to i32. AbstractInt, being 64 bits, is capable of representing the maximum i32 value + 1. However, for i64 this is not the case. Instead this patch makes us express the mimimum i64 value as the second most negative i64 value, minus 1, ie `-9223372036854775807li - 1li`, thereby avoiding the issue.
sharmajai
pushed a commit
to sharmajai/wgpu
that referenced
this pull request
Oct 12, 2025
In gfx-rs#7424 we fixed a bug where the representation of the minimum int64 literal generated by naga was invalid WGSL. It changed us from expressing it as `-9223372036854775808` which was invalid, to `-9223372036854775807li - 1li`. This is valid WGSL. However, as the values are concrete i64 types if the shader is parsed again by naga the expression does not get const evaluated away, leading to suboptimal code generated by the backends. This patch makes us perform the subtraction using abstract integers before casting to i64, solving this problem. Additionally the input WGSL test is updated to use the same construct.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Connections
Fixes #7423
Description
See #7423
Testing
Added line to int64 snapshot test. WGSL output previously failed validation but now passes
Squash or Rebase?
Either
Checklist
cargo fmt.taplo format.cargo clippy --tests. If applicable, add:cargo xtask testto run tests.