Skip to content
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

[naga] [msl-out] Error: as_type cast from 'long' to 'metal::uint' (aka 'unsigned int') is not allowed #7435

Open
LegNeato opened this issue Mar 26, 2025 · 6 comments · May be fixed by #7437

Comments

@LegNeato
Copy link
Contributor

LegNeato commented Mar 26, 2025

Description

When compiling this code with rust-gpu, I get valid spirv asm. I then pass it to naga to translate to metal (as I am on macOS) and I get these errors:

                        float _e11563 = function_119(metal::float2(_e7495 * 7.6543, _e7496 * 7.6543));
                              ^
program_source:16276:67: error: as_type cast from 'long' to 'metal::uint' (aka 'unsigned int') is not allowed
                    int _e13236 = as_type<int>(as_type<uint>(1) + as_type<uint>((_e13226 == _e13226) ? ((_e13226 > as_type<float>(1325400063u)) ? 2147483647 : ((_e13226 < as_type<float>(3472883712u)) ? -2147483648 : naga_f2i32(_e13226))) : 0));
                                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
program_source:16304:67: error: as_type cast from 'long' to 'metal::uint' (aka 'unsigned int') is not allowed
                    int _e13273 = as_type<int>(as_type<uint>(1) + as_type<uint>((_e13263 == _e13263) ? ((_e13263 > as_type<float>(1325400063u)) ? 2147483647 : ((_e13263 < as_type<float>(3472883712u)) ? -2147483648 : naga_f2i32(_e13263))) : 0));
                                                                  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Repro steps
It's a bit convoluted...

  1. Checkout Update deps Rust-GPU/rust-gpu-shadertoys#33
  2. Patch in Reduce repo MSRV from 1.85 to 1.84 #7425
  3. In build.rs, remove the check that turns it off on macos or in shaders/lib.rs, delete everything in the match except 21 => filtering_procedurals::Inputs

I'll work on getting the raw spirv.

Note I tested with the change from #7422 by @jamienicol and it still was not fixed.

Expected vs observed behavior
The shader to translate to metal code that compiles.

Platform
macOS, latest master of wgpu

@LegNeato LegNeato changed the title [msl-out] Error: as_type cast from 'long' to 'metal::uint' (aka 'unsigned int') is not allowed [naga] [msl-out] Error: as_type cast from 'long' to 'metal::uint' (aka 'unsigned int') is not allowed Mar 26, 2025
@LegNeato
Copy link
Contributor Author

@jamienicol I assume you are busy, but wanted to point you to this as you have been working in this space and might be able to see something quickly. I tried to find the issue but I am still getting up to speed on the code.

@jamienicol
Copy link
Contributor

jamienicol commented Mar 26, 2025

From a quick scan I would guess the issue is that like in #7423 -2147483648 is parsed as "unary negation of 2147483648". 2147483648 is too large to fit in a 32 bit int, and is therefore inferred to be a long. Which promotes the rest of the expression to a long. Which then errors when trying to bitcast it to a uint because as_type() must keep the same bitwidth

@jamienicol
Copy link
Contributor

Yep I think that's it. Here's a reduced case:

fn main() {
  var x = bitcast<u32>(-2147483648);
}

Same error message.

@LegNeato
Copy link
Contributor Author

@jamienicol great, found the fix. PR incoming soon. Thanks!

@LegNeato
Copy link
Contributor Author

LegNeato commented Mar 26, 2025

(unless you want to PR, up to you...don't want to step on your toes and you know more what you are doing and I don't know if this affects other backends)

@jamienicol
Copy link
Contributor

Please go ahead 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Todo
Development

Successfully merging a pull request may close this issue.

2 participants