Skip to content

Commit 8e9f08b

Browse files
committed
pub buffer_[load|store]_intrinsic, allows reading from a non-mut slice
1 parent d7914ec commit 8e9f08b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

crates/spirv-std/src/byte_addressable_buffer.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@
22
33
use core::mem;
44

5+
/// Loads an arbitrary type from the buffer. `byte_index` must be a multiple of 4, otherwise,
6+
/// it will get silently rounded down to the nearest multiple of 4. Bounds checking is not
7+
/// performed.
8+
///
9+
/// # Safety
10+
/// This function allows writing a type to an untyped buffer, then reading a different type
11+
/// from the same buffer, allowing all sorts of safety guarantees to be bypassed (effectively a
12+
/// transmute). Additionally, bounds checking is not performed.
513
#[spirv(buffer_load_intrinsic)]
614
// HACK(eddyb) try to prevent MIR inlining from breaking our intrinsics.
715
#[inline(never)]
816
#[spirv_std_macros::gpu_only]
9-
unsafe fn buffer_load_intrinsic<T>(
17+
pub unsafe fn buffer_load_intrinsic<T>(
1018
buffer: &[u32],
1119
// FIXME(eddyb) should be `usize`.
1220
offset: u32,
@@ -22,11 +30,19 @@ unsafe fn buffer_load_intrinsic<T>(
2230
.read()
2331
}
2432

33+
/// Stores an arbitrary type int the buffer. `byte_index` must be a multiple of 4, otherwise,
34+
/// it will get silently rounded down to the nearest multiple of 4. Bounds checking is not
35+
/// performed.
36+
///
37+
/// # Safety
38+
/// This function allows writing a type to an untyped buffer, then reading a different type
39+
/// from the same buffer, allowing all sorts of safety guarantees to be bypassed (effectively a
40+
/// transmute). Additionally, bounds checking is not performed.
2541
#[spirv(buffer_store_intrinsic)]
2642
// HACK(eddyb) try to prevent MIR inlining from breaking our intrinsics.
2743
#[inline(never)]
2844
#[spirv_std_macros::gpu_only]
29-
unsafe fn buffer_store_intrinsic<T>(
45+
pub unsafe fn buffer_store_intrinsic<T>(
3046
buffer: &mut [u32],
3147
// FIXME(eddyb) should be `usize`.
3248
offset: u32,

0 commit comments

Comments
 (0)