Document Metal buffer view ownership

This commit is contained in:
Georg Bauer
2026-07-25 13:02:13 +02:00
parent 8f91a06336
commit 44fce6585c

View File

@@ -846,6 +846,10 @@ impl Buffer {
} }
pub(super) fn view(&self, offset: u64, bytes: u64) -> Result<Self, String> { pub(super) fn view(&self, offset: u64, bytes: u64) -> Result<Self, String> {
// SAFETY: native/metal/ds4_metal.m:7916-7940 bounds-checks the view,
// ARC-retains base_obj.buffer at :7926, and marks the view non-owning at
// :7929, so it may outlive and be freed independently of this wrapper.
// Recheck those guarantees whenever the vendored Metal file is re-synced.
NonNull::new(unsafe { ds4_gpu_tensor_view(self.raw(), offset, bytes) }) NonNull::new(unsafe { ds4_gpu_tensor_view(self.raw(), offset, bytes) })
.map(Self) .map(Self)
.ok_or_else(|| "Metal could not create a tensor view".to_owned()) .ok_or_else(|| "Metal could not create a tensor view".to_owned())