/
create_render_pass.rs
61 lines (49 loc) · 1.8 KB
/
create_render_pass.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use ash::vk;
pub fn create_render_pass(
device: &ash::Device,
surface_format: vk::Format,
debug_utils_loader: &ash::extensions::ext::DebugUtils,
) -> Result<vk::RenderPass, String> {
log::info!("creating render pass");
let mut attachment_descriptions = Vec::new();
attachment_descriptions.push(
vk::AttachmentDescription::builder()
.format(surface_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)
.build(),
);
let col_attachment_ref = vk::AttachmentReference::builder()
.attachment(0)
.layout(vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL)
.build();
let references = [col_attachment_ref];
let mut subpass_descriptions = Vec::new();
subpass_descriptions.push(
vk::SubpassDescription::builder()
.pipeline_bind_point(vk::PipelineBindPoint::GRAPHICS)
.color_attachments(&references)
.build(),
);
let create_info = vk::RenderPassCreateInfo::builder()
.attachments(&attachment_descriptions)
.subpasses(&subpass_descriptions);
let render_pass = unsafe {
device
.create_render_pass(&create_info, None)
.map_err(|_| String::from("failed to create render pass"))?
};
vulkan_utils::set_debug_utils_object_name(
debug_utils_loader,
device.handle(),
render_pass,
"render pass",
);
log::info!("render pass created");
Ok(render_pass)
}