Skip to content

Commit

Permalink
Code clean-up: graphic input attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
attackgoat committed Feb 19, 2024
1 parent 80f94e6 commit 1fe8fbe
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 44 deletions.
23 changes: 12 additions & 11 deletions src/driver/graphic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ pub struct GraphicPipeline {
/// Information used to create this object.
pub info: GraphicPipelineInfo,

pub(crate) input_attachments: HashSet<u32>,
pub(crate) input_attachments: Box<[u32]>,
pub(crate) layout: vk::PipelineLayout,

/// A descriptive name used in debugging messages.
Expand All @@ -365,10 +365,6 @@ pub struct GraphicPipeline {
pub(crate) push_constants: Vec<vk::PushConstantRange>,
pub(crate) shader_modules: Vec<vk::ShaderModule>,
pub(super) state: GraphicPipelineState,

// Used in debug mode
#[allow(dead_code)]
pub(crate) write_attachments: HashSet<u32>,
}

impl GraphicPipeline {
Expand Down Expand Up @@ -476,23 +472,29 @@ impl GraphicPipeline {
.filter_map(|mut push_const| push_const.take())
.collect::<Vec<_>>();

let (input_attachments, write_attachments) = {
let input_attachments = {
let (input, write) = shaders
.iter()
.find(|shader| shader.stage == vk::ShaderStageFlags::FRAGMENT)
.expect("fragment shader not found")
.attachments();
let (input, write) = (input.collect::<HashSet<_>>(), write.collect::<HashSet<_>>());

for input in &input {
let (input, write) = (
input
.collect::<HashSet<_>>()
.into_iter()
.collect::<Box<_>>(),
write.collect::<HashSet<_>>(),
);

for input in input.iter() {
trace!("detected input attachment {input}");
}

for write in &write {
trace!("detected write attachment {write}");
}

(input, write)
input
};

unsafe {
Expand Down Expand Up @@ -565,7 +567,6 @@ impl GraphicPipeline {
stages,
vertex_input,
},
write_attachments,
})
}
}
Expand Down
64 changes: 31 additions & 33 deletions src/graph/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1114,42 +1114,40 @@ impl Resolver {
let mut subpass_info = SubpassInfo::with_capacity(attachment_count);

// Add input attachments
for (_, (descriptor_info, _)) in pipeline.descriptor_bindings.iter() {
if let &DescriptorInfo::InputAttachment(_, attachment_idx) = descriptor_info {
debug_assert!(
!exec.color_clears.contains_key(&attachment_idx),
"cannot clear color attachment index {attachment_idx} because it uses subpass input"
);

let exec_attachment = exec
.color_attachments
.get(&attachment_idx)
.or_else(|| exec.color_loads.get(&attachment_idx))
.or_else(|| exec.color_stores.get(&attachment_idx))
.expect("subpass input attachment index not attached, loaded, or stored");
let is_random_access = exec.color_stores.contains_key(&attachment_idx);
subpass_info.input_attachments.push(AttachmentRef {
attachment: attachment_idx,
aspect_mask: exec_attachment.aspect_mask,
layout: Self::attachment_layout(
exec_attachment.aspect_mask,
is_random_access,
true,
),
});
for attachment_idx in pipeline.input_attachments.iter() {
debug_assert!(
!exec.color_clears.contains_key(attachment_idx),
"cannot clear color attachment index {attachment_idx} because it uses subpass input",
);

// We should preserve the attachment in the previous subpasses as needed
// (We're asserting that any input renderpasses are actually real subpasses
// here with prior passes..)
for prev_exec_idx in (0..exec_idx - 1).rev() {
let prev_exec = &pass.execs[prev_exec_idx];
if prev_exec.color_stores.contains_key(&attachment_idx) {
break;
}
let exec_attachment = exec
.color_attachments
.get(attachment_idx)
.or_else(|| exec.color_loads.get(attachment_idx))
.or_else(|| exec.color_stores.get(attachment_idx))
.expect("subpass input attachment index not attached, loaded, or stored");
let is_random_access = exec.color_stores.contains_key(attachment_idx);
subpass_info.input_attachments.push(AttachmentRef {
attachment: *attachment_idx,
aspect_mask: exec_attachment.aspect_mask,
layout: Self::attachment_layout(
exec_attachment.aspect_mask,
is_random_access,
true,
),
});

let prev_subpass = &mut subpasses[prev_exec_idx];
prev_subpass.preserve_attachments.push(attachment_idx);
// We should preserve the attachment in the previous subpasses as needed
// (We're asserting that any input renderpasses are actually real subpasses
// here with prior passes..)
for prev_exec_idx in (0..exec_idx - 1).rev() {
let prev_exec = &pass.execs[prev_exec_idx];
if prev_exec.color_stores.contains_key(attachment_idx) {
break;
}

let prev_subpass = &mut subpasses[prev_exec_idx];
prev_subpass.preserve_attachments.push(*attachment_idx);
}
}

Expand Down

0 comments on commit 1fe8fbe

Please sign in to comment.