Rust-GPU / Rust-GPU/rust-gpu

incorrect bool/Option(bool) support

Open
#487 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
3.4k
Forks
125
PR merge metrics
No merged PRs in 30d

Description

Expected Behaviour

no crash when using bool / Option(bool) (note: in particular, the bug was observed when using iterators over bool)

Example & Steps To Reproduce

This code fail to compile:

#![cfg_attr(target_arch = "spirv", no_std)]

use spirv_std::glam::UVec3;
use spirv_std::spirv;

#[spirv(compute(threads(64)))]
pub fn main_cs(
    #[spirv(global_invocation_id)] id: UVec3,
    #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] buffer: &mut [u32],
) {
    let mut t =test();
    buffer[1] += t.next().unwrap() as u32;
}
struct T{}
#[inline(never)]
pub fn test()->impl Iterator<Item = bool>{
    T{}
}

impl  Iterator for T {
    type Item=bool;
    fn next(&mut self) -> Option<Self::Item> {
        return Some(true);
    }
}

The relevant part of the error

 error: error:0:0 - Expected Result Type to be a pointer or int or float vector or scalar type: Bitcast
           %40 = OpBitcast %bool %33

NB: the error also happen the other way arround (cast from bool to char).
It also seem that these cast force to use the Capability::Int8 when no Int8 is used in similar cases

System Info

  • Rust: rustc 1.90.0-nightly
  • OS: artix linux with kernel 6.17.8-artix1-1
  • GPU: NVIDIA Corporation GA102 [GeForce RTX 3080 Ti]
  • SPIR-V: SPIRV-Tools v2025.4 v2025.4-0-g7f2d9ee92

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust reproducer using an iterator over bool and the reported OpBitcast validation error. Trace how bool and Option are lowered to SPIR-V, including the reverse bool-to-char case and unexpected Int8 capability. Validate the result with the shown reproducer and SPIR-V Tools, with no invalid Bitcast or unnecessary Int8 capability.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.