Improve sub pass

This commit is contained in:
hodasemi 2023-01-21 22:47:40 +01:00
parent d33f89be02
commit 52b2d5a06a

View file

@ -61,7 +61,7 @@ impl CustomTarget {
store_operation, store_operation,
VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_LOAD_OP_DONT_CARE,
VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
if self.attach_sampler || self.use_as_input { if self.attach_sampler || self.use_as_input {
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL
} else { } else {
@ -87,7 +87,7 @@ impl CustomTarget {
store_operation, store_operation,
VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_LOAD_OP_DONT_CARE,
VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL,
); );
@ -114,6 +114,8 @@ impl CustomTarget {
let image = image_builder.build(device, queue)?; let image = image_builder.build(device, queue)?;
image.convert_layout(layout)?;
match aspect { match aspect {
VK_IMAGE_ASPECT_DEPTH_BIT => { VK_IMAGE_ASPECT_DEPTH_BIT => {
Image::convert_layout(&image, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL)? Image::convert_layout(&image, VK_IMAGE_LAYOUT_DEPTH_STENCIL_READ_ONLY_OPTIMAL)?
@ -136,7 +138,7 @@ impl CustomTarget {
pub enum ResolveTarget { pub enum ResolveTarget {
CustomTarget(CustomTarget), CustomTarget(CustomTarget),
PreparedTargets(Vec<Arc<Image>>), PreparedTargets((Vec<Arc<Image>>, bool)),
} }
impl From<CustomTarget> for ResolveTarget { impl From<CustomTarget> for ResolveTarget {
@ -145,19 +147,19 @@ impl From<CustomTarget> for ResolveTarget {
} }
} }
impl From<Vec<Arc<Image>>> for ResolveTarget { impl From<(Vec<Arc<Image>>, bool)> for ResolveTarget {
fn from(prepared_targets: Vec<Arc<Image>>) -> Self { fn from((prepared_targets, clear_on_load): (Vec<Arc<Image>>, bool)) -> Self {
Self::PreparedTargets(prepared_targets) Self::PreparedTargets((prepared_targets, clear_on_load))
} }
} }
impl<'a> From<&'a Vec<Arc<Image>>> for ResolveTarget { impl<'a> From<(&'a Vec<Arc<Image>>, bool)> for ResolveTarget {
fn from(prepared_targets: &'a Vec<Arc<Image>>) -> Self { fn from((prepared_targets, clear_on_load): (&'a Vec<Arc<Image>>, bool)) -> Self {
Self::PreparedTargets(prepared_targets.clone()) Self::PreparedTargets((prepared_targets.clone(), clear_on_load))
} }
} }
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq, Clone)]
pub struct InputAttachmentInfo { pub struct InputAttachmentInfo {
pub sub_pass_index: usize, pub sub_pass_index: usize,
pub input_indices: Vec<usize>, pub input_indices: Vec<usize>,
@ -236,23 +238,21 @@ impl<'a> SubPassBuilder<'a> {
} }
pub fn build(self, device: &Arc<Device>) -> Result<SubPass> { pub fn build(self, device: &Arc<Device>) -> Result<SubPass> {
let attachments = self.create_images(device)?;
Ok(SubPass { Ok(SubPass {
extent: VkExtent2D { extent: VkExtent2D {
width: self.width, width: self.width,
height: self.height, height: self.height,
}, },
input_info: self.input_info, input_info: self.input_info.clone(),
attachments,
output_usage: self.output_usage, output_usage: self.output_usage,
attachments: self.create_images(device)?,
}) })
} }
#[inline] #[inline]
fn create_images(&self, device: &Arc<Device>) -> Result<Vec<AttachmentInfo>> { fn create_images(self, device: &Arc<Device>) -> Result<Vec<AttachmentInfo>> {
// check for correct sample count // check for correct sample count
let checked_sample_count = device.max_supported_sample_count(self.sample_count); let checked_sample_count = device.max_supported_sample_count(self.sample_count);
@ -263,7 +263,7 @@ impl<'a> SubPassBuilder<'a> {
let mut attachment_infos = Vec::new(); let mut attachment_infos = Vec::new();
for target_info in self.target_infos.iter() { for target_info in self.target_infos {
attachment_infos.push(target_info.to_attachment_info( attachment_infos.push(target_info.to_attachment_info(
device, device,
self.queue.as_ref().ok_or(anyhow::anyhow!( self.queue.as_ref().ok_or(anyhow::anyhow!(
@ -302,7 +302,7 @@ impl<'a> SubPassBuilder<'a> {
} }
// add resolve target if possible // add resolve target if possible
for resolve_target in self.resolve_targets.iter() { for resolve_target in self.resolve_targets {
match resolve_target { match resolve_target {
ResolveTarget::CustomTarget(custom_target) => { ResolveTarget::CustomTarget(custom_target) => {
let mut attachment_info = custom_target.to_attachment_info( let mut attachment_info = custom_target.to_attachment_info(
@ -319,7 +319,7 @@ impl<'a> SubPassBuilder<'a> {
attachment_infos.push(attachment_info); attachment_infos.push(attachment_info);
} }
ResolveTarget::PreparedTargets(prepared_targets) => { ResolveTarget::PreparedTargets((prepared_targets, clear_on_load)) => {
attachment_infos.push(AttachmentInfo { attachment_infos.push(AttachmentInfo {
images: prepared_targets.iter().map(|image| image.clone()).collect(), images: prepared_targets.iter().map(|image| image.clone()).collect(),
clear_value: VkClearValue::color(VkClearColorValue::float32([ clear_value: VkClearValue::color(VkClearColorValue::float32([
@ -330,7 +330,7 @@ impl<'a> SubPassBuilder<'a> {
0, 0,
prepared_targets[0].vk_format(), prepared_targets[0].vk_format(),
VK_SAMPLE_COUNT_1_BIT, VK_SAMPLE_COUNT_1_BIT,
VK_ATTACHMENT_LOAD_OP_CLEAR, Self::clear_op(clear_on_load),
VK_ATTACHMENT_STORE_OP_STORE, VK_ATTACHMENT_STORE_OP_STORE,
VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_LOAD_OP_DONT_CARE,
VK_ATTACHMENT_STORE_OP_DONT_CARE, VK_ATTACHMENT_STORE_OP_DONT_CARE,