85 lines
2.9 KiB
Rust
85 lines
2.9 KiB
Rust
use std::sync::Arc;
|
|
use vulkano::device::Device;
|
|
use vulkano::pipeline::graphics::vertex_input::{Vertex, VertexDefinition};
|
|
use vulkano::pipeline::{DynamicState, GraphicsPipeline, PipelineLayout, PipelineShaderStageCreateInfo};
|
|
use vulkano::pipeline::graphics::color_blend::{ColorBlendAttachmentState, ColorBlendState};
|
|
use vulkano::pipeline::graphics::GraphicsPipelineCreateInfo;
|
|
use vulkano::pipeline::graphics::input_assembly::InputAssemblyState;
|
|
use vulkano::pipeline::graphics::multisample::MultisampleState;
|
|
use vulkano::pipeline::graphics::rasterization::RasterizationState;
|
|
use vulkano::pipeline::graphics::subpass::PipelineRenderingCreateInfo;
|
|
use vulkano::pipeline::graphics::viewport::ViewportState;
|
|
use vulkano::pipeline::layout::PipelineDescriptorSetLayoutCreateInfo;
|
|
use vulkano::swapchain::Swapchain;
|
|
|
|
use crate::renderer::Vertex2D;
|
|
|
|
mod shaders {
|
|
pub mod vs {
|
|
vulkano_shaders::shader! {
|
|
ty: "vertex",
|
|
path: r"res/shaders/vertex.vert",
|
|
}
|
|
}
|
|
|
|
pub mod fs {
|
|
vulkano_shaders::shader! {
|
|
ty: "fragment",
|
|
path: r"res/shaders/vertex.frag",
|
|
}
|
|
}
|
|
}
|
|
|
|
pub fn create_triangle_pipeline(device: &Arc<Device>, swapchain: &Arc<Swapchain>) -> Arc<GraphicsPipeline> {
|
|
let vs = shaders::vs::load(device.clone())
|
|
.unwrap()
|
|
.entry_point("main")
|
|
.unwrap();
|
|
let fs = shaders::fs::load(device.clone())
|
|
.unwrap()
|
|
.entry_point("main")
|
|
.unwrap();
|
|
|
|
let vertex_input_state = Vertex2D::per_vertex()
|
|
.definition(&vs)
|
|
.unwrap();
|
|
|
|
let stages = [
|
|
PipelineShaderStageCreateInfo::new(vs),
|
|
PipelineShaderStageCreateInfo::new(fs),
|
|
];
|
|
|
|
let layout = PipelineLayout::new(
|
|
device.clone(),
|
|
PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages)
|
|
.into_pipeline_layout_create_info(device.clone())
|
|
.unwrap(),
|
|
)
|
|
.unwrap();
|
|
|
|
let subpass = PipelineRenderingCreateInfo {
|
|
color_attachment_formats: vec![Some(swapchain.image_format())],
|
|
..Default::default()
|
|
};
|
|
|
|
GraphicsPipeline::new(
|
|
device.clone(),
|
|
None,
|
|
GraphicsPipelineCreateInfo {
|
|
stages: stages.into_iter().collect(),
|
|
vertex_input_state: Some(vertex_input_state),
|
|
input_assembly_state: Some(InputAssemblyState::default()),
|
|
viewport_state: Some(ViewportState::default()),
|
|
rasterization_state: Some(RasterizationState::default()),
|
|
multisample_state: Some(MultisampleState::default()),
|
|
color_blend_state: Some(ColorBlendState::with_attachment_states(
|
|
subpass.color_attachment_formats.len() as u32,
|
|
ColorBlendAttachmentState::default(),
|
|
)),
|
|
dynamic_state: [DynamicState::Viewport].into_iter().collect(),
|
|
subpass: Some(subpass.into()),
|
|
..GraphicsPipelineCreateInfo::layout(layout)
|
|
},
|
|
)
|
|
.unwrap()
|
|
}
|