Skip to content

bitflags stuck at v1 from 2021 #544

Closed

Description

@git-staus

In beab6cf last year @Firestar99 downgraded bitflags in spirv-std to version 1.3.2 because the "backend fails with 2.X". This of course causes two instances of bitflags to be compiled in when rust-gpu is used alongside e.g. cargo-gpu-install or vulkano.

I tried upgrading spirv-std to the latest bitflags 2.11.0 anyway but I did not notice any apparent issues when building or running tests on today's main, but I have not a clue if I am doing it right.

Activity

  1. Firestar99 commented on Feb 27, 2026

    @Firestar99
    Member

    The commit links to #349 where I left this comment:

    For some reason, our backend doesn't like the following expression which bitflags 2.X expands to. I downgraded it back to 1.X for now. eddyb any ideas?

    error: cannot offset a pointer to an arbitrary element
        --> /home/firestar99/workspace/rust-gpu/crates/spirv-std/src/ray_tracing.rs:675:28
         |
    675  |                 let flag = <RayFlags as bitflags::Flags>::FLAGS[i].value().bits();
         |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         |

    Curious to hear it just works right now, cause I don't remember us changing anything that may lead to this being fixed.

    Feel free to PR in the version upgrade, I'll have a look if I can find the cause why this suddenly works.

  2. git-staus commented on Feb 27, 2026

    @git-staus
    Author

    I completely missed the link back to that issue, thanks!

  3. Firestar99 commented on Feb 27, 2026

    @Firestar99
    Member

    Upgrading to bitflags@2 on current main still fails the ray_query_get_ray_flags_khr compiletest (cargo compiletest ray_flags optional --bless), by that test calling RayFlags::from_bits_truncate(..) (via get_ray_flags()) which causes the compile error

  4. git-staus commented on Feb 27, 2026

    @git-staus
    Author

    You're so fast! My laptop is still frying my thighs running the tests on unmodified main as a sanity check.

    In that case the downgrade is still adequate and I have peace of mind telling Clippy to shut up. I suppose this issue could be left open to document this work-around until fixing it becomes feasible.

  5. nazar-pc commented on Mar 5, 2026

    @nazar-pc
    Contributor

    The issue with bitflags points to the same issue with pointers that qptr is supposed to resolve.

    The reason is that despite being known at compile time, bitflags converts array to a slice, which breaks indexing:

    impl ::bitflags::Flags for Semantics {
        const FLAGS: &'static [::bitflags::Flag<Semantics>] = &[ ... ];

    If only they made it look like this:

    impl ::bitflags::Flags for Semantics {
        const FLAGS: &'static [::bitflags::Flag<Semantics>; SIZE] = &[ ... ];

    or this:

    impl ::bitflags::Flags for Semantics {
        const FLAGS: [::bitflags::Flag<Semantics>; SIZE] = [ ... ];

    It would have worked just fine.

  6. Firestar99 commented on Mar 5, 2026

    @Firestar99
    Member

    Even funnier, this fixes it:

    Index: crates/spirv-std/src/ray_tracing.rs
    ===================================================================
    diff --git a/crates/spirv-std/src/ray_tracing.rs b/crates/spirv-std/src/ray_tracing.rs
    --- a/crates/spirv-std/src/ray_tracing.rs	(revision bc4b857b89483b7bfc899dd24282759c46bbb33c)
    +++ b/crates/spirv-std/src/ray_tracing.rs	(revision 78f12b7307eb48389e840223f5a14fb2a5bcb5c3)
    @@ -441,7 +441,7 @@
             ///   Convert from a bits value, unsetting any unknown bits.
             #[inline]
             pub const fn from_bits_truncate(bits: u32) -> Self {
    -            Self(bits & Self::all().0)
    +            Self(bits & const { Self::all() }.0)
             }
     
             ///   Convert from a bits value exactly.

    This works due to Self::all() now being evaluated by rustc's const eval engine (aka miri-ish) instead of passed onwards to our codegen backend. Would still result in broken code if you'd use Self::all() from outside this function without a const block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions