From 8e9f08bab2453e563ded3775f01447ae6a7f22ea Mon Sep 17 00:00:00 2001 From: Firestar99 <4696087-firestar99@users.noreply.gitlab.com> Date: Tue, 11 Jun 2024 13:17:56 +0200 Subject: [PATCH] pub buffer_[load|store]_intrinsic, allows reading from a non-mut slice --- .../spirv-std/src/byte_addressable_buffer.rs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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,