2023-01-26 15:45:10 +11:00
|
|
|
use crate::error;
|
|
|
|
use ash::vk;
|
|
|
|
use ash::vk::{
|
|
|
|
AttachmentLoadOp, AttachmentStoreOp, ImageLayout, PipelineBindPoint, SampleCountFlags,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub struct VulkanRenderPass {
|
|
|
|
pub handle: vk::RenderPass,
|
|
|
|
pub format: vk::Format,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl VulkanRenderPass {
|
2023-01-29 18:30:58 +11:00
|
|
|
pub fn create_render_pass(device: &ash::Device, format: vk::Format) -> error::Result<Self> {
|
2023-01-26 15:45:10 +11:00
|
|
|
// format should never be undefined.
|
2023-02-16 14:57:20 +11:00
|
|
|
let attachment = vk::AttachmentDescription::builder()
|
2023-01-26 15:45:10 +11:00
|
|
|
.flags(vk::AttachmentDescriptionFlags::empty())
|
|
|
|
.format(format)
|
|
|
|
.samples(SampleCountFlags::TYPE_1)
|
|
|
|
.load_op(AttachmentLoadOp::DONT_CARE)
|
|
|
|
.store_op(AttachmentStoreOp::STORE)
|
|
|
|
.stencil_load_op(AttachmentLoadOp::DONT_CARE)
|
|
|
|
.stencil_store_op(AttachmentStoreOp::DONT_CARE)
|
|
|
|
.initial_layout(ImageLayout::COLOR_ATTACHMENT_OPTIMAL)
|
2023-02-16 14:57:20 +11:00
|
|
|
.final_layout(ImageLayout::COLOR_ATTACHMENT_OPTIMAL);
|
|
|
|
let attachment = [*attachment];
|
2023-01-26 15:45:10 +11:00
|
|
|
|
2023-02-16 14:57:20 +11:00
|
|
|
let attachment_ref = vk::AttachmentReference::builder()
|
2023-01-26 15:45:10 +11:00
|
|
|
.attachment(0)
|
2023-02-16 14:57:20 +11:00
|
|
|
.layout(ImageLayout::COLOR_ATTACHMENT_OPTIMAL);
|
|
|
|
let attachment_ref = [*attachment_ref];
|
2023-01-26 15:45:10 +11:00
|
|
|
|
2023-02-16 14:57:20 +11:00
|
|
|
let subpass = vk::SubpassDescription::builder()
|
2023-01-26 15:45:10 +11:00
|
|
|
.pipeline_bind_point(PipelineBindPoint::GRAPHICS)
|
2023-02-16 14:57:20 +11:00
|
|
|
.color_attachments(&attachment_ref);
|
|
|
|
let subpass = [*subpass];
|
2023-01-26 15:45:10 +11:00
|
|
|
|
|
|
|
let renderpass_info = vk::RenderPassCreateInfo::builder()
|
|
|
|
.flags(vk::RenderPassCreateFlags::empty())
|
|
|
|
.attachments(&attachment)
|
2023-02-17 09:33:47 +11:00
|
|
|
.subpasses(&subpass);
|
2023-01-26 15:45:10 +11:00
|
|
|
|
|
|
|
unsafe {
|
|
|
|
let rp = device.create_render_pass(&renderpass_info, None)?;
|
|
|
|
Ok(Self { handle: rp, format })
|
|
|
|
}
|
|
|
|
}
|
2023-01-29 18:30:58 +11:00
|
|
|
}
|