diff --git a/vulkano/examples/image.rs b/vulkano/examples/image.rs index 5837acfb..42d406d3 100644 --- a/vulkano/examples/image.rs +++ b/vulkano/examples/image.rs @@ -85,20 +85,23 @@ fn main() { mod fs { include!{concat!(env!("OUT_DIR"), "/shaders/examples/image_fs.glsl")} } let fs = fs::Shader::load(&device).expect("failed to create shader module"); - let renderpass = single_pass_renderpass!{ - device: &device, - attachments: { - color: { - load: Clear, - store: Store, - format: B8G8R8A8Srgb, + mod renderpass { + single_pass_renderpass!{ + attachments: { + color: { + load: Clear, + store: Store, + format: B8G8R8A8Srgb, + } + }, + pass: { + color: [color], + depth_stencil: {} } - }, - pass: { - color: [color], - depth_stencil: {} } - }.unwrap(); + } + + let renderpass = vulkano::framebuffer::RenderPass::new(&device, renderpass::Layout).unwrap(); let texture = vulkano::image::Image::::new(&device, &vulkano::image::Usage::all(), vulkano::memory::DeviceLocal, &queue, diff --git a/vulkano/examples/teapot.rs b/vulkano/examples/teapot.rs index a5716709..48c6a6b4 100644 --- a/vulkano/examples/teapot.rs +++ b/vulkano/examples/teapot.rs @@ -130,25 +130,28 @@ fn main() { vulkano::image::ImageView::new(&image).expect("failed to create image view") }).collect::>(); - let renderpass = single_pass_renderpass!{ - device: &device, - attachments: { - color: { - load: Clear, - store: Store, - format: B8G8R8A8Srgb, + mod renderpass { + single_pass_renderpass!{ + attachments: { + color: { + load: Clear, + store: Store, + format: B8G8R8A8Srgb, + }, + depth: { + load: Clear, + store: DontCare, + format: D16Unorm, + } }, - depth: { - load: Clear, - store: DontCare, - format: D16Unorm, + pass: { + color: [color], + depth_stencil: {depth} } - }, - pass: { - color: [color], - depth_stencil: {depth} } - }.unwrap(); + } + + let renderpass = vulkano::framebuffer::RenderPass::new(&device, renderpass::Layout).unwrap(); let descriptor_pool = vulkano::descriptor_set::DescriptorPool::new(&device).unwrap(); let descriptor_set_layout = { diff --git a/vulkano/src/framebuffer.rs b/vulkano/src/framebuffer.rs index 916600ee..69c7e5bb 100644 --- a/vulkano/src/framebuffer.rs +++ b/vulkano/src/framebuffer.rs @@ -310,7 +310,6 @@ unsafe impl RenderPassLayout for EmptySinglePassLayout { #[macro_export] macro_rules! single_pass_renderpass { ( - device: $device:expr, attachments: { $( $atch_name:ident: { @@ -324,91 +323,88 @@ macro_rules! single_pass_renderpass { color: [$($color_atch:ident),*], depth_stencil: {$($depth_atch:ident)*} } - ) => ( - { - use std::sync::Arc; + ) => { + use std; // TODO: import everything instead + use std::sync::Arc; - struct Layout; - unsafe impl $crate::framebuffer::RenderPassLayout for Layout { - type ClearValues = ($(<$crate::format::$format as $crate::format::FormatDesc>::ClearValue,)*); // TODO: only attachments with ClearOp should be in there - type ClearValuesIter = std::vec::IntoIter<$crate::format::ClearValue>; - type AttachmentsDescIter = std::vec::IntoIter<$crate::framebuffer::AttachmentDescription>; - type PassesIter = std::option::IntoIter<$crate::framebuffer::PassDescription>; - type PassDependenciesIter = std::option::IntoIter<$crate::framebuffer::PassDependencyDescription>; - type AttachmentsIter = std::vec::IntoIter>; + pub struct Layout; + unsafe impl $crate::framebuffer::RenderPassLayout for Layout { + type ClearValues = ($(<$crate::format::$format as $crate::format::FormatDesc>::ClearValue,)*); // TODO: only attachments with ClearOp should be in there + type ClearValuesIter = std::vec::IntoIter<$crate::format::ClearValue>; + type AttachmentsDescIter = std::vec::IntoIter<$crate::framebuffer::AttachmentDescription>; + type PassesIter = std::option::IntoIter<$crate::framebuffer::PassDescription>; + type PassDependenciesIter = std::option::IntoIter<$crate::framebuffer::PassDependencyDescription>; + type AttachmentsIter = std::vec::IntoIter>; - // FIXME: should be stronger-typed - type AttachmentsList = ( - $( - Arc<$crate::image::AbstractTypedImageView<$crate::image::Type2d, $crate::format::$format>>, - )* - ); + // FIXME: should be stronger-typed + type AttachmentsList = ( + $( + Arc<$crate::image::AbstractTypedImageView<$crate::image::Type2d, $crate::format::$format>>, + )* + ); - #[inline] - fn convert_clear_values(&self, val: Self::ClearValues) -> Self::ClearValuesIter { - $crate::format::ClearValuesTuple::iter(val) - } - - #[inline] - fn attachments(&self) -> Self::AttachmentsDescIter { - vec![ - $( - $crate::framebuffer::AttachmentDescription { - format: $crate::format::FormatDesc::format(&$crate::format::$format), // FIXME: only works with markers - samples: 1, // FIXME: - load: $crate::framebuffer::LoadOp::$load, - store: $crate::framebuffer::StoreOp::$store, - initial_layout: $crate::image::Layout::PresentSrc, // FIXME: - final_layout: $crate::image::Layout::PresentSrc, // FIXME: - }, - )* - ].into_iter() - } - - #[inline] - #[allow(unused_mut)] - #[allow(unused_assignments)] - fn passes(&self) -> Self::PassesIter { - let mut attachment_num = 0; - $( - let $atch_name = attachment_num; - attachment_num += 1; - )* - - let mut depth = None; - $( - depth = Some(($depth_atch, $crate::image::Layout::DepthStencilAttachmentOptimal)); - )* - - Some( - $crate::framebuffer::PassDescription { - color_attachments: vec![ - $( - ($color_atch, $crate::image::Layout::ColorAttachmentOptimal) - ),* - ], - depth_stencil: depth, - input_attachments: vec![], - resolve_attachments: vec![], - preserve_attachments: vec![], - } - ).into_iter() - } - - #[inline] - fn pass_dependencies(&self) -> Self::PassDependenciesIter { - None.into_iter() - } - - #[inline] - fn convert_attachments_list(&self, l: Self::AttachmentsList) -> Self::AttachmentsIter { - $crate::image::AbstractTypedImageViewsTuple::iter(l) - } + #[inline] + fn convert_clear_values(&self, val: Self::ClearValues) -> Self::ClearValuesIter { + $crate::format::ClearValuesTuple::iter(val) } - $crate::framebuffer::RenderPass::::new($device, Layout) + #[inline] + fn attachments(&self) -> Self::AttachmentsDescIter { + vec![ + $( + $crate::framebuffer::AttachmentDescription { + format: $crate::format::FormatDesc::format(&$crate::format::$format), // FIXME: only works with markers + samples: 1, // FIXME: + load: $crate::framebuffer::LoadOp::$load, + store: $crate::framebuffer::StoreOp::$store, + initial_layout: $crate::image::Layout::PresentSrc, // FIXME: + final_layout: $crate::image::Layout::PresentSrc, // FIXME: + }, + )* + ].into_iter() + } + + #[inline] + #[allow(unused_mut)] + #[allow(unused_assignments)] + fn passes(&self) -> Self::PassesIter { + let mut attachment_num = 0; + $( + let $atch_name = attachment_num; + attachment_num += 1; + )* + + let mut depth = None; + $( + depth = Some(($depth_atch, $crate::image::Layout::DepthStencilAttachmentOptimal)); + )* + + Some( + $crate::framebuffer::PassDescription { + color_attachments: vec![ + $( + ($color_atch, $crate::image::Layout::ColorAttachmentOptimal) + ),* + ], + depth_stencil: depth, + input_attachments: vec![], + resolve_attachments: vec![], + preserve_attachments: vec![], + } + ).into_iter() + } + + #[inline] + fn pass_dependencies(&self) -> Self::PassDependenciesIter { + None.into_iter() + } + + #[inline] + fn convert_attachments_list(&self, l: Self::AttachmentsList) -> Self::AttachmentsIter { + $crate::image::AbstractTypedImageViewsTuple::iter(l) + } } - ); + }; } /// Describes what the implementation should do with an attachment after all the subpasses have