Skip to content

Conversation

@jamienicol
Copy link
Contributor

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

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
  • Run cargo xtask test to run tests.

…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.
@ErichDonGubler ErichDonGubler self-assigned this Mar 25, 2025
@ErichDonGubler ErichDonGubler merged commit 7b6ff5f into gfx-rs:trunk Mar 25, 2025
37 checks passed
@jamienicol jamienicol deleted the min-i64-literal branch March 25, 2025 18:41
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.
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[naga wgsl-out] Invalid code emitted for minimum i64 value literal

2 participants