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 crate::image::view::ImageViewAbstract; 11 use crate::SafeDeref; 12 use std::sync::Arc; 13 //use sync::AccessFlags; 14 //use sync::PipelineStages; 15 16 /// A list of attachments. 17 // TODO: rework this trait 18 pub unsafe trait AttachmentsList { num_attachments(&self) -> usize19 fn num_attachments(&self) -> usize; 20 as_image_view_access(&self, index: usize) -> Option<&dyn ImageViewAbstract>21 fn as_image_view_access(&self, index: usize) -> Option<&dyn ImageViewAbstract>; 22 } 23 24 unsafe impl<T> AttachmentsList for T 25 where 26 T: SafeDeref, 27 T::Target: AttachmentsList, 28 { 29 #[inline] num_attachments(&self) -> usize30 fn num_attachments(&self) -> usize { 31 (**self).num_attachments() 32 } 33 34 #[inline] as_image_view_access(&self, index: usize) -> Option<&dyn ImageViewAbstract>35 fn as_image_view_access(&self, index: usize) -> Option<&dyn ImageViewAbstract> { 36 (**self).as_image_view_access(index) 37 } 38 } 39 40 unsafe impl AttachmentsList for () { 41 #[inline] num_attachments(&self) -> usize42 fn num_attachments(&self) -> usize { 43 0 44 } 45 46 #[inline] as_image_view_access(&self, _: usize) -> Option<&dyn ImageViewAbstract>47 fn as_image_view_access(&self, _: usize) -> Option<&dyn ImageViewAbstract> { 48 None 49 } 50 } 51 52 unsafe impl AttachmentsList for Vec<Arc<dyn ImageViewAbstract + Send + Sync>> { 53 #[inline] num_attachments(&self) -> usize54 fn num_attachments(&self) -> usize { 55 self.len() 56 } 57 58 #[inline] as_image_view_access(&self, index: usize) -> Option<&dyn ImageViewAbstract>59 fn as_image_view_access(&self, index: usize) -> Option<&dyn ImageViewAbstract> { 60 self.get(index).map(|v| &**v as &_) 61 } 62 } 63 64 unsafe impl<A, B> AttachmentsList for (A, B) 65 where 66 A: AttachmentsList, 67 B: ImageViewAbstract, 68 { 69 #[inline] num_attachments(&self) -> usize70 fn num_attachments(&self) -> usize { 71 self.0.num_attachments() + 1 72 } 73 74 #[inline] as_image_view_access(&self, index: usize) -> Option<&dyn ImageViewAbstract>75 fn as_image_view_access(&self, index: usize) -> Option<&dyn ImageViewAbstract> { 76 if index == self.0.num_attachments() { 77 Some(&self.1) 78 } else { 79 self.0.as_image_view_access(index) 80 } 81 } 82 } 83