diff --git a/crates/spirv-std/src/byte_addressable_buffer.rs b/crates/spirv-std/src/byte_addressable_buffer.rs index 216ef027f8..019c1b7b7a 100644 --- a/crates/spirv-std/src/byte_addressable_buffer.rs +++ b/crates/spirv-std/src/byte_addressable_buffer.rs @@ -2,11 +2,19 @@ use core::mem; +/// Loads an arbitrary type from the buffer. `byte_index` must be a multiple of 4, otherwise, +/// it will get silently rounded down to the nearest multiple of 4. Bounds checking is not +/// performed. +/// +/// # Safety +/// This function allows writing a type to an untyped buffer, then reading a different type +/// from the same buffer, allowing all sorts of safety guarantees to be bypassed (effectively a +/// transmute). Additionally, bounds checking is not performed. #[spirv(buffer_load_intrinsic)] // HACK(eddyb) try to prevent MIR inlining from breaking our intrinsics. #[inline(never)] #[spirv_std_macros::gpu_only] -unsafe fn buffer_load_intrinsic( +pub unsafe fn buffer_load_intrinsic( buffer: &[u32], // FIXME(eddyb) should be `usize`. offset: u32, @@ -22,11 +30,19 @@ unsafe fn buffer_load_intrinsic( .read() } +/// Stores an arbitrary type int the buffer. `byte_index` must be a multiple of 4, otherwise, +/// it will get silently rounded down to the nearest multiple of 4. Bounds checking is not +/// performed. +/// +/// # Safety +/// This function allows writing a type to an untyped buffer, then reading a different type +/// from the same buffer, allowing all sorts of safety guarantees to be bypassed (effectively a +/// transmute). Additionally, bounds checking is not performed. #[spirv(buffer_store_intrinsic)] // HACK(eddyb) try to prevent MIR inlining from breaking our intrinsics. #[inline(never)] #[spirv_std_macros::gpu_only] -unsafe fn buffer_store_intrinsic( +pub unsafe fn buffer_store_intrinsic( buffer: &mut [u32], // FIXME(eddyb) should be `usize`. offset: u32,