mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-25 17:01:15 +01:00
Add a way to destroy a pass by a mutable reference (#647)
This commit is contained in:
1 parent
e2d713a0d9
commit
4c448c3fc5
2 files changed
+15
-4
No files matched your search
@@ -93,7 +93,16 @@ impl RawPass {
|
||||
self.data as usize - self.base as usize
|
||||
}
|
||||
|
||||
pub unsafe fn into_vec(self) -> (Vec<u8>, id::CommandEncoderId) {
|
||||
/// Recover the data vector of the pass, consuming `self`.
|
||||
unsafe fn into_vec(mut self) -> (Vec<u8>, id::CommandEncoderId) {
|
||||
(self.invalidate(), self.parent)
|
||||
}
|
||||
|
||||
/// Make pass contents invalid, return the contained data.
|
||||
///
|
||||
/// Any following access to the pass will result in a crash
|
||||
/// for accessing address 0.
|
||||
pub unsafe fn invalidate(&mut self) -> Vec<u8> {
|
||||
let size = self.size();
|
||||
assert!(
|
||||
size <= self.capacity,
|
||||
@@ -102,7 +111,10 @@ impl RawPass {
|
||||
self.capacity
|
||||
);
|
||||
let vec = Vec::from_raw_parts(self.base, size, self.capacity);
|
||||
(vec, self.parent)
|
||||
self.data = ptr::null_mut();
|
||||
self.base = ptr::null_mut();
|
||||
self.capacity = 0;
|
||||
vec
|
||||
}
|
||||
|
||||
unsafe fn ensure_extra_size(&mut self, extra_size: usize) {
|
||||
|
||||
@@ -160,8 +160,7 @@ impl super::RawPass {
|
||||
|
||||
pub unsafe fn finish_render(mut self) -> (Vec<u8>, id::CommandEncoderId) {
|
||||
self.finish(RenderCommand::End);
|
||||
let (vec, parent_id) = self.into_vec();
|
||||
(vec, parent_id)
|
||||
self.into_vec()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user