2023-01-12 12:52:44 +00:00
|
|
|
use anyhow::Result;
|
|
|
|
use vulkan_rs::prelude::*;
|
|
|
|
|
|
|
|
use std::{mem, sync::Arc};
|
|
|
|
|
2023-01-17 11:18:53 +00:00
|
|
|
use super::radar::PositionOnlyVertex;
|
2023-01-13 07:11:53 +00:00
|
|
|
|
2023-01-12 12:52:44 +00:00
|
|
|
pub struct SingleColorPipeline {
|
|
|
|
pipeline: Arc<Pipeline>,
|
2023-01-13 07:11:53 +00:00
|
|
|
descriptor_layout: Arc<DescriptorSetLayout>,
|
2023-01-12 12:52:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SingleColorPipeline {
|
2023-01-17 11:18:53 +00:00
|
|
|
pub fn new(
|
|
|
|
device: Arc<Device>,
|
|
|
|
renderpass: &Arc<RenderPass>,
|
|
|
|
width: u32,
|
|
|
|
height: u32,
|
|
|
|
) -> Result<Self> {
|
2023-01-12 12:52:44 +00:00
|
|
|
let vertex_shader = ShaderModule::from_slice(
|
|
|
|
device.clone(),
|
|
|
|
include_bytes!("shader/single_color.vert.spv"),
|
|
|
|
ShaderType::Vertex,
|
|
|
|
)?;
|
|
|
|
let fragment_shader = ShaderModule::from_slice(
|
|
|
|
device.clone(),
|
|
|
|
include_bytes!("shader/single_color.frag.spv"),
|
|
|
|
ShaderType::Fragment,
|
|
|
|
)?;
|
|
|
|
|
2023-01-13 07:11:53 +00:00
|
|
|
let descriptor_layout = DescriptorSetLayout::builder()
|
|
|
|
.add_layout_binding(
|
|
|
|
0,
|
|
|
|
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
|
|
|
|
VK_SHADER_STAGE_FRAGMENT_BIT,
|
|
|
|
0,
|
|
|
|
)
|
|
|
|
.build(device.clone())?;
|
|
|
|
|
|
|
|
let pipeline_layout = PipelineLayout::builder()
|
|
|
|
.add_descriptor_set_layout(&descriptor_layout)
|
|
|
|
.build(device.clone())?;
|
2023-01-12 12:52:44 +00:00
|
|
|
|
2023-01-17 11:18:53 +00:00
|
|
|
let viewport = VkViewport {
|
|
|
|
x: 0.0,
|
|
|
|
y: 0.0,
|
|
|
|
width: width as f32,
|
|
|
|
height: height as f32,
|
|
|
|
minDepth: 0.0,
|
|
|
|
maxDepth: 1.0,
|
|
|
|
};
|
|
|
|
|
|
|
|
let scissor = VkRect2D {
|
|
|
|
offset: VkOffset2D { x: 0, y: 0 },
|
|
|
|
extent: VkExtent2D {
|
|
|
|
width: width,
|
|
|
|
height: height,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-01-12 12:52:44 +00:00
|
|
|
let pipeline = Pipeline::new_graphics()
|
|
|
|
.set_vertex_shader(
|
|
|
|
vertex_shader.clone(),
|
|
|
|
vec![VkVertexInputBindingDescription {
|
|
|
|
binding: 0,
|
2023-01-13 07:11:53 +00:00
|
|
|
stride: mem::size_of::<PositionOnlyVertex>() as u32,
|
2023-01-12 12:52:44 +00:00
|
|
|
inputRate: VK_VERTEX_INPUT_RATE_VERTEX,
|
|
|
|
}],
|
|
|
|
vec![
|
|
|
|
// position
|
|
|
|
VkVertexInputAttributeDescription {
|
|
|
|
location: 0,
|
|
|
|
binding: 0,
|
|
|
|
format: VK_FORMAT_R32G32B32A32_SFLOAT,
|
|
|
|
offset: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
)
|
|
|
|
.set_fragment_shader(fragment_shader.clone())
|
|
|
|
.input_assembly(VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST, false)
|
|
|
|
.default_depth_stencil(false, false)
|
2023-01-12 16:45:06 +00:00
|
|
|
.default_color_blend(vec![VkPipelineColorBlendAttachmentState::default()])
|
2023-01-12 12:52:44 +00:00
|
|
|
.default_rasterization(VK_CULL_MODE_NONE, VK_FRONT_FACE_COUNTER_CLOCKWISE)
|
|
|
|
.default_multisample(VK_SAMPLE_COUNT_1_BIT)
|
2023-01-17 11:18:53 +00:00
|
|
|
.add_viewport(viewport)
|
|
|
|
.add_scissor(scissor)
|
2023-01-12 12:52:44 +00:00
|
|
|
.build(device, &pipeline_layout, &renderpass, 0)?;
|
|
|
|
|
|
|
|
Ok(Self {
|
2023-01-13 07:11:53 +00:00
|
|
|
descriptor_layout,
|
2023-01-12 12:52:44 +00:00
|
|
|
pipeline,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn pipeline(&self) -> &Arc<Pipeline> {
|
|
|
|
&self.pipeline
|
|
|
|
}
|
2023-01-13 07:11:53 +00:00
|
|
|
|
|
|
|
pub fn descriptor_layout(&self) -> &Arc<DescriptorSetLayout> {
|
|
|
|
&self.descriptor_layout
|
|
|
|
}
|
2023-01-12 12:52:44 +00:00
|
|
|
}
|