This commit is contained in:
parent
f67804abd9
commit
504fdada42
5 changed files with 245 additions and 63 deletions
63
src/vulkan/vk_render_pass.rs
Normal file
63
src/vulkan/vk_render_pass.rs
Normal file
|
@ -0,0 +1,63 @@
|
|||
use crate::vulkan::{VkDevice, VkSwapchain};
|
||||
use ash::prelude::VkResult;
|
||||
use ash::vk;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct VkRenderPass {
|
||||
device: Arc<VkDevice>,
|
||||
swapchain: Arc<VkSwapchain>,
|
||||
|
||||
pub(super) 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::LOAD)
|
||||
.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,
|
||||
swapchain,
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue