Rust-GPU / Rust-GPU/rust-gpu

Volatile Loads/Stores

Open
#513 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I'm trying to use volatile loads and stores like so:

#[inline(always)]
pub fn get_item(&self, offset: u32) -> T {
    unsafe {
        let ptr = self
            .items
            .get_unchecked(((self.start_ticket + offset) % self.max_capacity) as usize);
        core::ptr::read_volatile(ptr)
    }
}

#[inline(always)]
pub fn set_item(&mut self, offset: u32, item: T) {
    unsafe {
        let ptr = self
            .items
            .get_unchecked_mut(((self.start_ticket + offset) % self.max_capacity) as usize);
        core::ptr::write_volatile(ptr, item);
    }
}

But when compiling I get an error saying this is not supported yet.

error: store_with_flags is not supported yet: MemFlags(VOLATILE)
      --> /home/peyton/.rustup/toolchains/nightly-2025-06-30-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:2180:9
       |
  2180 |         intrinsics::volatile_store(dst, src);
       |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

It would be very useful to be able to specify this in loads. It seems like its possible in SPIRV using Memory Operands is there any way to do this currently?

System Info

  • SPIR-V: SPIRV-Tools v2025.4 v2025.4-0-g7f2d9ee9
    Targets:
    SPIR-V 1.0
    SPIR-V 1.1
    SPIR-V 1.2
    SPIR-V 1.3
    SPIR-V 1.4
    SPIR-V 1.5
    SPIR-V 1.6
    SPIR-V 1.2 (under OpenCL 2.2 Full Profile semantics)
    SPIR-V 1.0 (under Vulkan 1.0 semantics)
    SPIR-V 1.3 (under Vulkan 1.1 semantics)
    SPIR-V 1.4 (under Vulkan 1.1 semantics)
    SPIR-V 1.5 (under Vulkan 1.2 semantics)
    SPIR-V 1.6 (under Vulkan 1.3 semantics) SPIR-V 1.6 (under Vulkan 1.4 semantics)

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 reported core/src/ptr/mod.rs call to intrinsics::volatile_store and trace how Rust-GPU lowers volatile loads and stores to SPIR-V. Compare that path with the SPIR-V Memory Operands mentioned in the issue; done means the requested volatile operations are supported without the reported MemFlags(VOLATILE) error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.