Skip to content

Commit

Permalink
pub buffer_[load|store]_intrinsic, allows reading from a non-mut slice
Browse files Browse the repository at this point in the history
  • Loading branch information
Firestar99 committed Jun 11, 2024
1 parent d7914ec commit 8e9f08b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions crates/spirv-std/src/byte_addressable_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(
pub unsafe fn buffer_load_intrinsic<T>(
buffer: &[u32],
// FIXME(eddyb) should be `usize`.
offset: u32,
Expand All @@ -22,11 +30,19 @@ unsafe fn buffer_load_intrinsic<T>(
.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<T>(
pub unsafe fn buffer_store_intrinsic<T>(
buffer: &mut [u32],
// FIXME(eddyb) should be `usize`.
offset: u32,
Expand Down

0 comments on commit 8e9f08b

Please sign in to comment.