Skip to content

Commit

Permalink
Fix for incorrect framebuffer attachment handling
Browse files Browse the repository at this point in the history
  • Loading branch information
attackgoat committed Nov 30, 2024
1 parent 53823d0 commit e2f7244
Showing 1 changed file with 22 additions and 69 deletions.
91 changes: 22 additions & 69 deletions src/graph/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,7 @@ impl Resolver {

let mut subpasses = Vec::<SubpassInfo>::with_capacity(pass.execs.len());

// Add attachments: format, sample count, layout, and load ops (using the first
// execution)
// Add load op attachments using the first execution
{
let first_exec = &pass.execs[0];

Expand All @@ -919,7 +918,6 @@ impl Resolver {
attachment.sample_count = cleared_attachment.sample_count;
attachment.load_op = vk::AttachmentLoadOp::CLEAR;
attachment.initial_layout = vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL;
attachment.final_layout = attachment.initial_layout;
}

// Loaded color attachments
Expand All @@ -929,25 +927,6 @@ impl Resolver {
attachment.sample_count = loaded_attachment.sample_count;
attachment.load_op = vk::AttachmentLoadOp::LOAD;
attachment.initial_layout = vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL;
attachment.final_layout = attachment.initial_layout;
}

// Resolved color attachments
for (dst_attachment_idx, (resolved_attachment, _)) in &first_exec.color_resolves {
let attachment = &mut attachments[*dst_attachment_idx as usize];
attachment.fmt = resolved_attachment.format;
attachment.sample_count = resolved_attachment.sample_count;
attachment.initial_layout = vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL;
attachment.final_layout = attachment.initial_layout;
}

// Stored color attachments
for (attachment_idx, stored_attachment) in &first_exec.color_stores {
let attachment = &mut attachments[*attachment_idx as usize];
attachment.fmt = stored_attachment.format;
attachment.sample_count = stored_attachment.sample_count;
attachment.initial_layout = vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL;
attachment.final_layout = attachment.initial_layout;
}

// Cleared depth/stencil attachment
Expand Down Expand Up @@ -975,7 +954,6 @@ impl Resolver {

vk::ImageLayout::STENCIL_ATTACHMENT_OPTIMAL
};
attachment.final_layout = attachment.initial_layout;
} else if let Some(loaded_attachment) = first_exec.depth_stencil_load {
// Loaded depth/stencil attachment
let attachment = &mut attachments[color_attachment_count];
Expand All @@ -1001,72 +979,35 @@ impl Resolver {

vk::ImageLayout::STENCIL_READ_ONLY_OPTIMAL
};
attachment.final_layout = attachment.initial_layout;
}

// Stored depth/stencil attachment
if let Some(stored_attachment) = first_exec.depth_stencil_store {
let attachment = &mut attachments[color_attachment_count];
attachment.fmt = stored_attachment.format;
attachment.sample_count = stored_attachment.sample_count;
attachment.initial_layout = if stored_attachment
.aspect_mask
.contains(vk::ImageAspectFlags::DEPTH | vk::ImageAspectFlags::STENCIL)
{
vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL
} else if stored_attachment
.aspect_mask
.contains(vk::ImageAspectFlags::DEPTH)
{
vk::ImageLayout::DEPTH_ATTACHMENT_OPTIMAL
} else {
vk::ImageLayout::STENCIL_ATTACHMENT_OPTIMAL
};
attachment.final_layout = attachment.initial_layout;
}

// Resolved depth/stencil attachment
if let Some((resolved_attachment, ..)) = first_exec.depth_stencil_resolve {
let attachment = attachments.last_mut().unwrap();
attachment.fmt = resolved_attachment.format;
attachment.sample_count = resolved_attachment.sample_count;
attachment.initial_layout = if resolved_attachment
.aspect_mask
.contains(vk::ImageAspectFlags::DEPTH | vk::ImageAspectFlags::STENCIL)
{
vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL
} else if resolved_attachment
.aspect_mask
.contains(vk::ImageAspectFlags::DEPTH)
{
vk::ImageLayout::DEPTH_ATTACHMENT_OPTIMAL
} else {
vk::ImageLayout::STENCIL_ATTACHMENT_OPTIMAL
};
attachment.final_layout = attachment.initial_layout;
}
}

// Add attachments: store ops and final layout (using the last pass)
// Add store op attachments using the last execution
{
let last_exec = pass.execs.last().unwrap();

// Resolved color attachments
for attachment_idx in last_exec.color_resolves.keys() {
for (attachment_idx, (resolved_attachment, _)) in &last_exec.color_resolves {
let attachment = &mut attachments[*attachment_idx as usize];
attachment.fmt = resolved_attachment.format;
attachment.sample_count = resolved_attachment.sample_count;
attachment.final_layout = vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL;
}

// Stored color attachments
for attachment_idx in last_exec.color_stores.keys() {
for (attachment_idx, stored_attachment) in &last_exec.color_stores {
let attachment = &mut attachments[*attachment_idx as usize];
attachment.fmt = stored_attachment.format;
attachment.sample_count = stored_attachment.sample_count;
attachment.store_op = vk::AttachmentStoreOp::STORE;
attachment.final_layout = vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL;
}

// Stored depth/stencil attachment
if let Some(stored_attachment) = last_exec.depth_stencil_store {
let attachment = &mut attachments[color_attachment_count];
attachment.fmt = stored_attachment.format;
attachment.sample_count = stored_attachment.sample_count;
attachment.final_layout = if stored_attachment
.aspect_mask
.contains(vk::ImageAspectFlags::DEPTH | vk::ImageAspectFlags::STENCIL)
Expand All @@ -1092,6 +1033,8 @@ impl Resolver {
// Resolved depth/stencil attachment
if let Some((resolved_attachment, ..)) = last_exec.depth_stencil_resolve {
let attachment = attachments.last_mut().unwrap();
attachment.fmt = resolved_attachment.format;
attachment.sample_count = resolved_attachment.sample_count;
attachment.final_layout = if resolved_attachment
.aspect_mask
.contains(vk::ImageAspectFlags::DEPTH | vk::ImageAspectFlags::STENCIL)
Expand All @@ -1108,6 +1051,16 @@ impl Resolver {
}
}

for attachment in &mut attachments {
if attachment.load_op == vk::AttachmentLoadOp::DONT_CARE {
attachment.initial_layout = attachment.final_layout;
} else if attachment.store_op == vk::AttachmentStoreOp::DONT_CARE
&& attachment.stencil_store_op == vk::AttachmentStoreOp::DONT_CARE
{
attachment.final_layout = attachment.initial_layout;
}
}

// Add subpasses
for (exec_idx, exec) in pass.execs.iter().enumerate() {
let pipeline = exec
Expand Down

0 comments on commit e2f7244

Please sign in to comment.