Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 1s
56 lines
1.9 KiB
Rust
56 lines
1.9 KiB
Rust
use super::{VkDevice, VkSwapchain};
|
|
use ash::prelude::VkResult;
|
|
use ash::vk;
|
|
use std::sync::Arc;
|
|
|
|
pub struct VkRenderPass {
|
|
device: Arc<VkDevice>,
|
|
|
|
pub handle: vk::RenderPass,
|
|
}
|
|
|
|
impl VkRenderPass {
|
|
pub fn new(device: &Arc<VkDevice>, swapchain: &Arc<VkSwapchain>) -> VkResult<Self> {
|
|
let color_attachment = vk::AttachmentDescription::default()
|
|
.format(swapchain.surface_format.format)
|
|
.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 color_attachment_ref = vk::AttachmentReference::default()
|
|
.attachment(0)
|
|
.layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL);
|
|
|
|
let color_attachments = [color_attachment_ref];
|
|
let subpass = vk::SubpassDescription::default()
|
|
.pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS)
|
|
.color_attachments(&color_attachments);
|
|
|
|
let attachments = [color_attachment];
|
|
let subpasses = [subpass];
|
|
let render_pass_info = vk::RenderPassCreateInfo::default()
|
|
.attachments(&attachments)
|
|
.subpasses(&subpasses);
|
|
|
|
let render_pass = unsafe { device.handle.create_render_pass(&render_pass_info, None)? };
|
|
log::debug!("Render pass created ({render_pass:?})");
|
|
|
|
Ok(Self {
|
|
device: device.clone(),
|
|
handle: render_pass,
|
|
})
|
|
}
|
|
}
|
|
|
|
impl Drop for VkRenderPass {
|
|
fn drop(&mut self) {
|
|
unsafe {
|
|
self.device.handle.destroy_render_pass(self.handle, None);
|
|
log::debug!("Render pass destroyed ({:?})", self.handle);
|
|
}
|
|
}
|
|
}
|