Skip to content

Avoid minimum integer literals in HLSL (and remaining ones in MSL) #7504

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
merged 2 commits into from
Apr 10, 2025

Conversation

jamienicol
Copy link
Contributor

Connections
Follow up from #7437

Description
DXC and FXC currently can parse the most negative value integer literals fine (unlike the metal compiler). However, we have been informed on the DX discord that this is not guaranteed. So let's avoid them on HLSL too just to be safe.

Additionally we need to update the workarounds for signed integer division and modulo to avoid using them.

Testing
Snapshots cover it well

Squash or Rebase?

Rebase plz

Checklist

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

…-negative value minus one

As we did for MSL in gfx-rs#7437. eg `-2147483648` becomes `-2147483647 - 1`.

Neither FXC nor DXC currently have any issues parsing the most negative
value literals. However, we have been informed this is not guaranteed to
always be the case, so are making this change as a precaution.
… and modulo avoid using minimum value literals

As we know that minimum value integer literals can cause problems for
some compilers. (See gfx-rs#7437)

Make the code which generates these functions call
msl::Writer::put_literal() and hlsl::Writer::write_literal()
respectively to output the minimum value integer literals instead of
just writing them directly, ensuring we only have to handle this
workaround in a single location (per backend).
@ErichDonGubler ErichDonGubler merged commit 08d3bb5 into gfx-rs:trunk Apr 10, 2025
37 checks passed
@jamienicol jamienicol deleted the more-min-int-literal-fun branch April 10, 2025 14:45
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.

2 participants