From 9e556142c02fa0dfc8ea6819e90fccf03b502a1d Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Sat, 17 Dec 2016 14:58:39 +0100 Subject: [PATCH] Only allow static in Submission --- vulkano/src/command_buffer/submit.rs | 37 ++++++++++------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/vulkano/src/command_buffer/submit.rs b/vulkano/src/command_buffer/submit.rs index 0564b5d2..5963d136 100644 --- a/vulkano/src/command_buffer/submit.rs +++ b/vulkano/src/command_buffer/submit.rs @@ -53,12 +53,11 @@ pub unsafe trait Submit { /// command buffers at once instead. To do so, you can use the `chain` method. /// /// Contrary to `submit`, this method preserves strong typing in the submission. This means - /// that it has a lower overhead but it is less convenient to store in a container. This method - /// also has the advantage of not requiring `Self: 'static`. + /// that it has a lower overhead but it is less convenient to store in a container. // TODO: add example #[inline] fn submit_precise(self, queue: &Arc) -> Result, Box> - where Self: Sized + where Self: Sized + 'static { submit(self, queue) } @@ -102,20 +101,6 @@ pub unsafe trait Submit { -> Result, Box>; } -unsafe impl<'a, S: ?Sized> Submit for &'a S where S: Submit + 'a { - #[inline] - fn device(&self) -> &Arc { - (**self).device() - } - - #[inline] - unsafe fn append_submission<'b>(&'b self, base: SubmitBuilder<'b>, queue: &Arc) - -> Result, Box> - { - (**self).append_submission(base, queue) - } -} - unsafe impl Submit for Box where S: Submit { #[inline] fn device(&self) -> &Arc { @@ -337,7 +322,7 @@ impl<'a> SubmitBuilder<'a> { // Implementation for `Submit::submit`. fn submit(submit: S, queue: &Arc) -> Result, Box> - where S: Submit + where S: Submit + 'static { let last_fence; let keep_alive_semaphores; @@ -438,13 +423,17 @@ unsafe impl Submit for SubmitChain where A: Submit, B: Submit { /// in a long-living container such as a `Vec`. From time to time, you can clean the obsolete /// objects by checking whether `destroying_would_block()` returns false. For example, if you use /// a `Vec` you can do `vec.retain(|s| s.destroying_would_block())`. -// TODO: docs -// # Leak safety -// -// The `Submission` object can hold borrows of command buffers. In order for it to be safe to leak -// a `Submission`, the borrowed object themselves must be protected by a fence. +/// +/// # Leak safety +/// +/// One of the roles of the `Submission` object is to keep alive the objects used by the GPU during +/// the submission. However if the user calls `std::mem::forget` on the `Submission`, all borrows +/// are immediately free'd. This is known as *the leakpocalypse*. +/// +/// In order to avoid this problem, only `'static` objects can be put in a `Submission`. +// TODO: ^ decide whether we allow to add an unsafe non-static constructor #[must_use] -pub struct Submission> { +pub struct Submission> { fence: FenceWithWaiting, // TODO: make optional queue: Arc, keep_alive_semaphores: SmallVec<[Arc; 8]>,