Skip to content

Commit

Permalink
Break things to make example work
Browse files Browse the repository at this point in the history
  • Loading branch information
attackgoat committed Aug 31, 2024
1 parent fa16928 commit 3268cf5
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 43 deletions.
24 changes: 13 additions & 11 deletions examples/mip_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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, _| {
Expand Down Expand Up @@ -141,14 +140,13 @@ fn fill_mip_levels(device: &Arc<Device>, image: &Arc<Image>) -> 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,
Expand Down Expand Up @@ -244,6 +242,10 @@ fn splat(device: &Arc<Device>) -> Result<Arc<GraphicPipeline>, DriverError> {
frag
)
.as_slice(),
)
.image_sampler(
0,
SamplerInfoBuilder::default().mipmap_mode(vk::SamplerMipmapMode::LINEAR),
),
],
)?))
Expand Down
6 changes: 2 additions & 4 deletions src/driver/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,6 @@ pub(crate) struct FramebufferAttachmentImageInfo {
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub(crate) struct FramebufferInfo {
pub attachments: Vec<FramebufferAttachmentImageInfo>,
pub width: u32,
pub height: u32,
}

#[derive(Debug, Eq, Hash, PartialEq)]
Expand Down Expand Up @@ -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 _;
Expand Down
70 changes: 42 additions & 28 deletions src/graph/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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(
Expand Down Expand Up @@ -1984,7 +1979,7 @@ impl Resolver {

trace!(
"{trace_pad}buffer {:?} {}..{} {:?} -> {:?}",
binding.as_driver_buffer().unwrap(),
buf,
range.start,
range.end,
next_access,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -2670,22 +2677,29 @@ 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<f32>) {
fn set_viewport(
cmd_buf: &CommandBuffer,
x: f32,
y: f32,
width: f32,
height: f32,
depth: Range<f32>,
) {
use std::slice::from_ref;

unsafe {
cmd_buf.device.cmd_set_viewport(
**cmd_buf,
0,
from_ref(&vk::Viewport {
x: 0.0,
y: 0.0,
x,
y,
width,
height,
min_depth: depth.start,
Expand Down

0 comments on commit 3268cf5

Please sign in to comment.