diff --git a/examples/mip_map.rs b/examples/mip_map.rs index 6b028c7..ef93b18 100644 --- a/examples/mip_map.rs +++ b/examples/mip_map.rs @@ -52,14 +52,12 @@ fn main() -> Result<(), WindowError> { let swapchain_info = frame.render_graph.node_info(frame.swapchain_image); let stripe_width = swapchain_info.width / mip_level_count; - let mut pass = frame - .render_graph - .begin_pass("splat mips") - .bind_pipeline(&splat); - for mip_level in 0..mip_level_count { let stripe_x = mip_level * stripe_width; - pass = pass + frame + .render_graph + .begin_pass("splat mips") + .bind_pipeline(&splat) .read_descriptor_as( 0, image, @@ -69,6 +67,7 @@ fn main() -> Result<(), WindowError> { .base_mip_level(mip_level) .mip_level_count(Some(1)), ) + .load_color(0, frame.swapchain_image) .store_color(0, frame.swapchain_image) .set_render_area(stripe_x as _, 0, stripe_width, swapchain_info.height) .record_subpass(|subpass, _| { @@ -141,14 +140,13 @@ fn fill_mip_levels(device: &Arc, image: &Arc) -> Result<(), Drive )?); let mut render_graph = RenderGraph::new(); - let mut pass = render_graph - .begin_pass("fill mip levels") - .bind_pipeline(&vertical_gradient); let image_info = image.info; - let image = pass.bind_node(image); + let image = render_graph.bind_node(image); for mip_level in 0..image_info.mip_level_count { - pass = pass + render_graph + .begin_pass("fill mip levels") + .bind_pipeline(&vertical_gradient) .store_color_as( 0, image, @@ -244,6 +242,10 @@ fn splat(device: &Arc) -> Result, DriverError> { frag ) .as_slice(), + ) + .image_sampler( + 0, + SamplerInfoBuilder::default().mipmap_mode(vk::SamplerMipmapMode::LINEAR), ), ], )?)) diff --git a/src/driver/render_pass.rs b/src/driver/render_pass.rs index a15affc..d005b49 100644 --- a/src/driver/render_pass.rs +++ b/src/driver/render_pass.rs @@ -85,8 +85,6 @@ pub(crate) struct FramebufferAttachmentImageInfo { #[derive(Clone, Debug, Eq, Hash, PartialEq)] pub(crate) struct FramebufferInfo { pub attachments: Vec, - pub width: u32, - pub height: u32, } #[derive(Debug, Eq, Hash, PartialEq)] @@ -292,8 +290,8 @@ impl RenderPass { let mut create_info = vk::FramebufferCreateInfo::default() .flags(vk::FramebufferCreateFlags::IMAGELESS) .render_pass(this.render_pass) - .width(key.width) - .height(key.height) + .width(attachments[0].width) + .height(attachments[0].height) .layers(layers) .push_next(&mut imageless_info); create_info.attachment_count = this.info.attachments.len() as _; diff --git a/src/graph/resolver.rs b/src/graph/resolver.rs index 78e8092..338c76e 100644 --- a/src/graph/resolver.rs +++ b/src/graph/resolver.rs @@ -173,6 +173,7 @@ impl Resolver { #[profiling::function] fn allow_merge_passes(lhs: &Pass, rhs: &Pass) -> bool { + return false; let lhs_pipeline = lhs .execs .first() @@ -436,8 +437,8 @@ impl Resolver { attachment_image.flags = image.info.flags; attachment_image.usage = image.info.usage; - attachment_image.width = image.info.width; - attachment_image.height = image.info.height; + attachment_image.width = image.info.width >> attachment.base_mip_level; + attachment_image.height = image.info.height >> attachment.base_mip_level; attachment_image.layer_count = attachment.array_layer_count; attachment_image.view_formats.insert(idx, attachment.format); @@ -474,8 +475,8 @@ impl Resolver { attachment_image.flags = image.info.flags; attachment_image.usage = image.info.usage; - attachment_image.width = image.info.width; - attachment_image.height = image.info.height; + attachment_image.width = image.info.width >> attachment.base_mip_level; + attachment_image.height = image.info.height >> attachment.base_mip_level; attachment_image.layer_count = attachment.array_layer_count; attachment_image.view_formats.insert(idx, attachment.format); @@ -510,8 +511,8 @@ impl Resolver { attachment_image.flags = image.info.flags; attachment_image.usage = image.info.usage; - attachment_image.width = image.info.width; - attachment_image.height = image.info.height; + attachment_image.width = image.info.width >> attachment.base_mip_level; + attachment_image.height = image.info.height >> attachment.base_mip_level; attachment_image.layer_count = attachment.array_layer_count; attachment_image.view_formats.insert(idx, attachment.format); @@ -546,8 +547,8 @@ impl Resolver { attachment_image.flags = image.info.flags; attachment_image.usage = image.info.usage; - attachment_image.width = image.info.width; - attachment_image.height = image.info.height; + attachment_image.width = image.info.width >> attachment.base_mip_level; + attachment_image.height = image.info.height >> attachment.base_mip_level; attachment_image.layer_count = attachment.array_layer_count; attachment_image.view_formats.insert(idx, attachment.format); @@ -580,8 +581,8 @@ impl Resolver { attachment_image.flags = image.info.flags; attachment_image.usage = image.info.usage; - attachment_image.width = image.info.width; - attachment_image.height = image.info.height; + attachment_image.width = image.info.width >> attachment.base_mip_level; + attachment_image.height = image.info.height >> attachment.base_mip_level; attachment_image.layer_count = attachment.array_layer_count; attachment_image.view_formats.insert(idx, attachment.format); @@ -601,14 +602,8 @@ impl Resolver { } } - let framebuffer = RenderPass::framebuffer( - render_pass, - FramebufferInfo { - attachments, - width: render_area.width, - height: render_area.height, - }, - )?; + let framebuffer = + RenderPass::framebuffer(render_pass, FramebufferInfo { attachments })?; unsafe { cmd_buf.device.cmd_begin_render_pass( @@ -1984,7 +1979,7 @@ impl Resolver { trace!( "{trace_pad}buffer {:?} {}..{} {:?} -> {:?}", - binding.as_driver_buffer().unwrap(), + buf, range.start, range.end, next_access, @@ -2009,7 +2004,7 @@ impl Resolver { trace!( "{trace_pad}image {:?} {:?}-{:?} -> {:?}-{:?}", - binding.as_driver_image().unwrap(), + image, prev_access, image_access_layout(prev_access), next_access, @@ -2304,11 +2299,14 @@ impl Resolver { exec.depth_stencil, )?; - if is_graphic && pass.render_area.is_none() { + if is_graphic { let render_area = render_area.unwrap(); + // In this case we set the viewport and scissor for the user Self::set_viewport( cmd_buf, + render_area.x as _, + render_area.y as _, render_area.width as _, render_area.height as _, exec.depth_stencil @@ -2319,7 +2317,13 @@ impl Resolver { }) .unwrap_or(0.0..1.0), ); - Self::set_scissor(cmd_buf, render_area.width, render_area.height); + Self::set_scissor( + cmd_buf, + render_area.x, + render_area.y, + render_area.width, + render_area.height, + ); } Self::bind_descriptor_sets(cmd_buf, pipeline, physical_pass, exec_idx); @@ -2444,7 +2448,10 @@ impl Resolver { .map(|attachment| { let info = bindings[attachment.target].as_driver_image().unwrap().info; - (info.width, info.height) + ( + info.width >> attachment.base_mip_level, + info.height >> attachment.base_mip_level, + ) }) { width = width.min(attachment_width); @@ -2661,7 +2668,7 @@ impl Resolver { }); } - fn set_scissor(cmd_buf: &CommandBuffer, width: u32, height: u32) { + fn set_scissor(cmd_buf: &CommandBuffer, x: i32, y: i32, width: u32, height: u32) { use std::slice::from_ref; unsafe { @@ -2670,13 +2677,20 @@ impl Resolver { 0, from_ref(&vk::Rect2D { extent: vk::Extent2D { width, height }, - offset: vk::Offset2D { x: 0, y: 0 }, + offset: vk::Offset2D { x, y }, }), ); } } - fn set_viewport(cmd_buf: &CommandBuffer, width: f32, height: f32, depth: Range) { + fn set_viewport( + cmd_buf: &CommandBuffer, + x: f32, + y: f32, + width: f32, + height: f32, + depth: Range, + ) { use std::slice::from_ref; unsafe { @@ -2684,8 +2698,8 @@ impl Resolver { **cmd_buf, 0, from_ref(&vk::Viewport { - x: 0.0, - y: 0.0, + x, + y, width, height, min_depth: depth.start,