]> git.nega.tv - josh/narcissus/commitdiff
narcissus-gpu: Add `copy_to_slice` to persistent buffer
authorJosh Simmons <josh@nega.tv>
Mon, 4 Nov 2024 20:18:13 +0000 (21:18 +0100)
committerJosh Simmons <josh@nega.tv>
Mon, 4 Nov 2024 21:14:25 +0000 (22:14 +0100)
engine/narcissus-gpu/src/mapped_buffer.rs

index cdafabfa3c0d508df9f55f3c0588d8d36be66552..3e99aa3a8aa810662017372998f670e3d0e6e7b0 100644 (file)
@@ -75,6 +75,11 @@ impl<'a> PersistentBuffer<'a> {
     pub fn copy_with_offset<T: ?Sized>(&mut self, offset: usize, src: &T) {
         unsafe { copy_from_with_offset(self.ptr, self.len, offset, src) }
     }
+
+    pub unsafe fn copy_to_slice<T>(&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.