You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

90 lines
2.3 KiB

use crate::render::Device;
use ash::{version::DeviceV1_0, vk};
use std::rc::Rc;
pub struct RenderPass {
handle: vk::RenderPass,
pub device: Rc<Device>,
}
impl RenderPass {
pub fn create(
device: Rc<Device>,
format: vk::Format,
) -> Result<Rc<Self>, vk::Result> {
let attachments = [
vk::AttachmentDescription {
format,
flags: vk::AttachmentDescriptionFlags::empty(),
samples: vk::SampleCountFlags::TYPE_1,
load_op: vk::AttachmentLoadOp::CLEAR,
store_op: vk::AttachmentStoreOp::STORE,
stencil_load_op: vk::AttachmentLoadOp::DONT_CARE,
stencil_store_op: vk::AttachmentStoreOp::DONT_CARE,
initial_layout: vk::ImageLayout::UNDEFINED,
final_layout: vk::ImageLayout::PRESENT_SRC_KHR,
}
];
let attachment_references = [
vk::AttachmentReference {
attachment: 0,
layout: vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL,
}
];
let subpasses = [
vk::SubpassDescription {
pipeline_bind_point: vk::PipelineBindPoint::GRAPHICS,
color_attachment_count: attachment_references.len() as u32,
p_color_attachments: attachment_references.as_ptr(),
..Default::default()
}
];
let dependencies = [
vk::SubpassDependency {
src_subpass: vk::SUBPASS_EXTERNAL,
dst_subpass: 0,
src_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT,
dst_stage_mask: vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT,
src_access_mask: vk::AccessFlags::empty(),
dst_access_mask:
vk::AccessFlags::COLOR_ATTACHMENT_READ |
vk::AccessFlags::COLOR_ATTACHMENT_WRITE,
dependency_flags: vk::DependencyFlags::empty(),
}
];
let create_info = vk::RenderPassCreateInfo {
attachment_count: attachments.len() as u32,
p_attachments: attachments.as_ptr(),
subpass_count: subpasses.len() as u32,
p_subpasses: subpasses.as_ptr(),
dependency_count: dependencies.len() as u32,
p_dependencies: dependencies.as_ptr(),
..Default::default()
};
let handle = unsafe { device.create_render_pass(&create_info, None)? };
Ok(Rc::new(Self { handle, device }))
}
}
impl Drop for RenderPass {
fn drop(&mut self) {
unsafe {
self.device.destroy_render_pass(self.handle, None);
}
}
}
impl std::ops::Deref for RenderPass {
type Target = vk::RenderPass;
fn deref(&self) -> &Self::Target {
&self.handle
}
}
// EOF