From: Josh Simmons Date: Mon, 4 Nov 2024 20:18:13 +0000 (+0100) Subject: narcissus-gpu: Add `copy_to_slice` to persistent buffer X-Git-Url: https://git.nega.tv//gitweb.cgi?a=commitdiff_plain;h=10c6aa3b967146e9dbf45b373859c040a352db12;p=josh%2Fnarcissus narcissus-gpu: Add `copy_to_slice` to persistent buffer --- diff --git a/engine/narcissus-gpu/src/mapped_buffer.rs b/engine/narcissus-gpu/src/mapped_buffer.rs index cdafabf..3e99aa3 100644 --- a/engine/narcissus-gpu/src/mapped_buffer.rs +++ b/engine/narcissus-gpu/src/mapped_buffer.rs @@ -75,6 +75,11 @@ impl<'a> PersistentBuffer<'a> { pub fn copy_with_offset(&mut self, offset: usize, src: &T) { unsafe { copy_from_with_offset(self.ptr, self.len, offset, src) } } + + pub unsafe fn copy_to_slice(&self, dst: &mut [T]) { + assert!(std::mem::size_of_val(dst) == self.len); + std::ptr::copy(self.ptr.cast().as_ptr(), dst.as_mut_ptr(), dst.len()); + } } /// Transient mapped buffer that is tied to the lifetime of the current frame.