ursus_core/vulkan/gfx_pipeline/
pipeline.rs1use crate::render::gfx::types::{BlendState, CompareOp, CullMode, Format, PushConstantRange, VertexLayout};
2use ash::vk;
3
4pub struct PipelineDesc<'a> {
6 pub(crate) vert_spv: &'a [u8],
7 pub(crate) frag_spv: &'a [u8],
8 pub(crate) color_formats: &'a [Format],
9 pub(crate) vertex_layout: &'a VertexLayout,
10 pub(crate) push_constant_ranges: &'a [PushConstantRange],
11 pub(crate) depth: DepthState,
12 pub(crate) cull_mode: CullMode,
13 pub(crate) blend_attachments: Option<&'a [BlendState]>,
14}
15
16#[derive(Clone, Copy)]
17pub(crate) struct DepthState {
18 pub format: Option<Format>,
19 pub test: bool,
20 pub write: bool,
21 pub compare: CompareOp,
22}
23
24impl<'a> PipelineDesc<'a> {
25 pub fn new(
33 vert_spv: &'a [u8],
34 frag_spv: &'a [u8],
35 color_formats: &'a [Format],
36 vertex_layout: &'a VertexLayout,
37 push_constant_ranges: &'a [PushConstantRange],
38 ) -> Self {
39 Self {
40 vert_spv,
41 frag_spv,
42 color_formats,
43 vertex_layout,
44 push_constant_ranges,
45 depth: DepthState { format: None, test: true, write: true, compare: CompareOp::Less },
46 cull_mode: CullMode::None,
47 blend_attachments: None,
48 }
49 }
50
51 pub fn depth_format(mut self, format: Format) -> Self {
52 self.depth.format = Some(format);
53 self
54 }
55
56 pub fn depth_test(mut self, test: bool) -> Self {
57 self.depth.test = test;
58 self
59 }
60
61 pub fn depth_write(mut self, write: bool) -> Self {
62 self.depth.write = write;
63 self
64 }
65
66 pub fn depth_compare(mut self, compare: CompareOp) -> Self {
67 self.depth.compare = compare;
68 self
69 }
70
71 pub fn cull_mode(mut self, cull_mode: CullMode) -> Self {
72 self.cull_mode = cull_mode;
73 self
74 }
75
76 pub fn blend_attachments(mut self, states: &'a [BlendState]) -> Self {
77 self.blend_attachments = Some(states);
78 self
79 }
80 }
116
117pub struct Pipeline {
118 pub handle: vk::Pipeline,
119 pub layout: vk::PipelineLayout,
120 device: ash::Device,
121}
122
123impl Drop for Pipeline {
124 fn drop(&mut self) {
125 unsafe {
126 self.device.destroy_pipeline(self.handle, None);
127 self.device.destroy_pipeline_layout(self.layout, None);
128 }
129 }
130}