1 // Copyright (c) 2016 The vulkano developers 2 // Licensed under the Apache License, Version 2.0 3 // <LICENSE-APACHE or 4 // https://www.apache.org/licenses/LICENSE-2.0> or the MIT 5 // license <LICENSE-MIT or https://opensource.org/licenses/MIT>, 6 // at your option. All files in the project carrying such 7 // notice may not be copied, modified, or distributed except 8 // according to those terms. 9 10 use smallvec::SmallVec; 11 12 use crate::command_buffer::submit::SubmitCommandBufferBuilder; 13 use crate::command_buffer::submit::SubmitPresentBuilder; 14 use crate::sync::PipelineStages; 15 use crate::sync::Semaphore; 16 17 /// Prototype for a submission that waits on semaphores. 18 /// 19 /// This prototype can't actually be submitted because it doesn't correspond to anything in Vulkan. 20 /// However you can convert it into another builder prototype through the `Into` trait. 21 #[derive(Debug)] 22 pub struct SubmitSemaphoresWaitBuilder<'a> { 23 semaphores: SmallVec<[&'a Semaphore; 8]>, 24 } 25 26 impl<'a> SubmitSemaphoresWaitBuilder<'a> { 27 /// Builds a new empty `SubmitSemaphoresWaitBuilder`. 28 #[inline] new() -> SubmitSemaphoresWaitBuilder<'a>29 pub fn new() -> SubmitSemaphoresWaitBuilder<'a> { 30 SubmitSemaphoresWaitBuilder { 31 semaphores: SmallVec::new(), 32 } 33 } 34 35 /// Adds an operation that waits on a semaphore. 36 /// 37 /// The semaphore must be signaled by a previous submission. 38 #[inline] add_wait_semaphore(&mut self, semaphore: &'a Semaphore)39 pub unsafe fn add_wait_semaphore(&mut self, semaphore: &'a Semaphore) { 40 self.semaphores.push(semaphore); 41 } 42 43 /// Merges this builder with another builder. 44 #[inline] merge(&mut self, mut other: SubmitSemaphoresWaitBuilder<'a>)45 pub fn merge(&mut self, mut other: SubmitSemaphoresWaitBuilder<'a>) { 46 self.semaphores.extend(other.semaphores.drain(..)); 47 } 48 } 49 50 impl<'a> Into<SubmitCommandBufferBuilder<'a>> for SubmitSemaphoresWaitBuilder<'a> { 51 #[inline] into(mut self) -> SubmitCommandBufferBuilder<'a>52 fn into(mut self) -> SubmitCommandBufferBuilder<'a> { 53 unsafe { 54 let mut builder = SubmitCommandBufferBuilder::new(); 55 for sem in self.semaphores.drain(..) { 56 builder.add_wait_semaphore( 57 sem, 58 PipelineStages { 59 // TODO: correct stages ; hard 60 all_commands: true, 61 ..PipelineStages::none() 62 }, 63 ); 64 } 65 builder 66 } 67 } 68 } 69 70 impl<'a> Into<SubmitPresentBuilder<'a>> for SubmitSemaphoresWaitBuilder<'a> { 71 #[inline] into(mut self) -> SubmitPresentBuilder<'a>72 fn into(mut self) -> SubmitPresentBuilder<'a> { 73 unsafe { 74 let mut builder = SubmitPresentBuilder::new(); 75 for sem in self.semaphores.drain(..) { 76 builder.add_wait_semaphore(sem); 77 } 78 builder 79 } 80 } 81 } 82