Skip to content

ByteAddressableBuffer: storing a Scalar and ScalarPair within the same codebase fails to compile #428

@Firestar99

Description

@Firestar99

Compiletest

The following compiletest fails to compile:

// build-pass

use spirv_std::ByteAddressableBuffer;
use spirv_std::spirv;

#[derive(Copy, Clone, Debug)]
pub struct MyScalar(i32);

#[spirv(fragment)]
pub fn store_scalar(
    #[spirv(descriptor_set = 0, binding = 0, storage_buffer)] buf: &mut [u32],
    #[spirv(flat)] scalar: MyScalar,
) {
    unsafe {
        let mut buf = ByteAddressableBuffer::from_mut_slice(buf);
        buf.store(5, scalar);
    }
}

#[derive(Copy, Clone, Debug)]
pub struct MyScalarPair(i32, i32);

#[spirv(fragment)]
pub fn store_scalar_pair(
    #[spirv(descriptor_set = 0, binding = 0, storage_buffer)] buf: &mut [u32],
    #[spirv(flat)] pair0: i32,
    #[spirv(flat)] pair1: i32,
) {
    unsafe {
        let mut buf = ByteAddressableBuffer::from_mut_slice(buf);
        buf.store(5, MyScalarPair(pair0, pair1));
    }
}

Error

error: buffer_store_intrinsic should have 4 args, it has 5
   --> /home/firestar99/workspace/rust-gpu/crates/spirv-std/src/byte_addressable_buffer.rs:155:13
    |
155 |             buffer_store_intrinsic(self.data, byte_index, value);
    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Error from a different project

Note the reversed arg count!

  error: buffer_store_intrinsic should have 5 args, it has 4
     --> /home/firestar99/.cargo/git/checkouts/rust-gpu-d06d15e2ba0f0ae2/dfcff49/crates/spirv-std/src/byte_addressable_buffer.rs:166:13
      |
  166 |             buffer_store_intrinsic(self.data, byte_index, value);
      |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Notes

  • only stores are affected, loads work fine since they don't have any special handling for scalar pairs
  • stores expect 5 args when passing a scalar pair, 4 when passing a scalar
  • it seems like the presence of a scalar pair store converts the scalar store to a scalar pair one, and the other way around?
    • May indicate a data race, since stores are written to a map DefId -> PassMode
  • my bindless API primarily does loads with very few stores, so I never noticed this previously

System Info

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions