Rust-GPU / Rust-GPU/rust-gpu

Using an array as a slice causes a compiler error

Open
#465 2 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

I'm surprised I haven't hit this earlier, but it's not possible to pass an array as a slice. Is this a known limitation? Is there an easy workaround?

Expected Behaviour

I would expect to be able to pass an array like [u32; 3] as a parameter to a function that takes a slice.

Example & Steps To Reproduce

Here is a minimal reproducible example:

#![no_std]
#![allow(unexpected_cfgs)]

fn do_work(data: &[u32], slab: &mut [u32]) {
    slab[0] = data[0];
    slab[1] = data[1];
    slab[2] = data[2];
}

#[spirv(compute(threads(16)))]
pub fn compute_shader(
    #[spirv(storage_buffer, descriptor_set = 0, binding = 0)] slab: &mut [u32],
    #[spirv(global_invocation_id)] global_id: glam::UVec3,
) {
    let data = [global_id.x, global_id.y, global_id.z];
    do_work(&data, slab);
}

System Info

  • Rustc version: 1.90
  • spirv-std: from the latest main, b3eda4df9814b6176d3c0844eb67f70a22ebb378 as of this writing
  • SPIR-V version:
    ❯ spirv-val --version
    SPIRV-Tools v2025.3 unknown hash, 2025-06-23T19:59:33+00:00
    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 by compiling the minimal Rust example in the issue, focusing on the do_work call that passes &data to a &[u32] parameter. Trace the compiler's handling of the array-to-slice conversion and verify the example compiles successfully with the compute shader entry point.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.