added pipeline for cuboid
This commit is contained in:
parent
c5bcd148ca
commit
4494b68c26
4 changed files with 98 additions and 33 deletions
src
116
src/main.rs
116
src/main.rs
|
@ -349,7 +349,8 @@ impl App {
|
|||
.iter()
|
||||
.for_each(|f| self.device.destroy_framebuffer(*f, None));
|
||||
self.device.free_command_buffers(self.data.command_pool, &self.data.command_buffers);
|
||||
self.device.destroy_pipeline(self.data.pipeline, None);
|
||||
self.device.destroy_pipeline(self.data.pipeline_cube, None);
|
||||
self.device.destroy_pipeline(self.data.pipeline_cuboid, None);
|
||||
self.device.destroy_pipeline_layout(self.data.pipeline_layout, None);
|
||||
self.device.destroy_render_pass(self.data.render_pass, None);
|
||||
self.data.swapchain_image_views
|
||||
|
@ -642,34 +643,63 @@ unsafe fn create_logical_device(
|
|||
}
|
||||
|
||||
unsafe fn create_pipeline(device: &Device, data: &mut app_data::AppData) -> Result<()> {
|
||||
let vert = include_bytes!("../shaders/vert_cube.spv");
|
||||
let geo = include_bytes!("../shaders/geo_cube.spv");
|
||||
let frag = include_bytes!("../shaders/frag_cube.spv");
|
||||
let vert_cube = include_bytes!("../shaders/vert_cube.spv");
|
||||
let geo_cube = include_bytes!("../shaders/geo_cube.spv");
|
||||
let frag_cube = include_bytes!("../shaders/frag_cube.spv");
|
||||
|
||||
let vert_shader_module = create_shader_module(device, &vert[..])?;
|
||||
let geo_shader_module = create_shader_module(device, &geo[..])?;
|
||||
let frag_shader_module = create_shader_module(device, &frag[..])?;
|
||||
let vert_shader_module_cube = create_shader_module(device, &vert_cube[..])?;
|
||||
let geo_shader_module_cube = create_shader_module(device, &geo_cube[..])?;
|
||||
let frag_shader_module_cube = create_shader_module(device, &frag_cube[..])?;
|
||||
|
||||
let vert_stage = vk::PipelineShaderStageCreateInfo::builder()
|
||||
let vert_stage_cube = vk::PipelineShaderStageCreateInfo::builder()
|
||||
.stage(vk::ShaderStageFlags::VERTEX)
|
||||
.module(vert_shader_module)
|
||||
.module(vert_shader_module_cube)
|
||||
.name(b"main\0");
|
||||
|
||||
let geo_stage = vk::PipelineShaderStageCreateInfo::builder()
|
||||
let geo_stage_cube = vk::PipelineShaderStageCreateInfo::builder()
|
||||
.stage(vk::ShaderStageFlags::GEOMETRY)
|
||||
.module(geo_shader_module)
|
||||
.module(geo_shader_module_cube)
|
||||
.name(b"main\0");
|
||||
|
||||
let frag_stage = vk::PipelineShaderStageCreateInfo::builder()
|
||||
let frag_stage_cube = vk::PipelineShaderStageCreateInfo::builder()
|
||||
.stage(vk::ShaderStageFlags::FRAGMENT)
|
||||
.module(frag_shader_module)
|
||||
.module(frag_shader_module_cube)
|
||||
.name(b"main\0");
|
||||
|
||||
let binding_descriptions = &[vertex::Vertex::binding_description()];
|
||||
let attribute_descriptions = vertex::Vertex::attribute_descriptions();
|
||||
let vertex_input_state = vk::PipelineVertexInputStateCreateInfo::builder()
|
||||
.vertex_binding_descriptions(binding_descriptions)
|
||||
.vertex_attribute_descriptions(&attribute_descriptions);
|
||||
let binding_descriptions_cube = &[vertex::Vertex::binding_description()];
|
||||
let attribute_descriptions_cube = vertex::Vertex::attribute_descriptions();
|
||||
let vertex_input_state_cube = vk::PipelineVertexInputStateCreateInfo::builder()
|
||||
.vertex_binding_descriptions(binding_descriptions_cube)
|
||||
.vertex_attribute_descriptions(&attribute_descriptions_cube);
|
||||
|
||||
let vert_cuboid = include_bytes!("../shaders/vert_cuboid.spv");
|
||||
let geo_cuboid = include_bytes!("../shaders/geo_cuboid.spv");
|
||||
let frag_cuboid = include_bytes!("../shaders/frag_cuboid.spv");
|
||||
|
||||
let vert_shader_module_cuboid = create_shader_module(device, &vert_cuboid[..])?;
|
||||
let geo_shader_module_cuboid = create_shader_module(device, &geo_cuboid[..])?;
|
||||
let frag_shader_module_cuboid = create_shader_module(device, &frag_cuboid[..])?;
|
||||
|
||||
let vert_stage_cuboid = vk::PipelineShaderStageCreateInfo::builder()
|
||||
.stage(vk::ShaderStageFlags::VERTEX)
|
||||
.module(vert_shader_module_cuboid)
|
||||
.name(b"main\0");
|
||||
|
||||
let geo_stage_cuboid = vk::PipelineShaderStageCreateInfo::builder()
|
||||
.stage(vk::ShaderStageFlags::GEOMETRY)
|
||||
.module(geo_shader_module_cuboid)
|
||||
.name(b"main\0");
|
||||
|
||||
let frag_stage_cuboid = vk::PipelineShaderStageCreateInfo::builder()
|
||||
.stage(vk::ShaderStageFlags::FRAGMENT)
|
||||
.module(frag_shader_module_cuboid)
|
||||
.name(b"main\0");
|
||||
|
||||
let binding_descriptions_cuboid = &[vertex::SizedVertex::binding_description()];
|
||||
let attribute_descriptions_cuboid = vertex::SizedVertex::attribute_descriptions();
|
||||
let vertex_input_state_cuboid = vk::PipelineVertexInputStateCreateInfo::builder()
|
||||
.vertex_binding_descriptions(binding_descriptions_cuboid)
|
||||
.vertex_attribute_descriptions(&attribute_descriptions_cuboid);
|
||||
|
||||
let mut topology = vk::PrimitiveTopology::TRIANGLE_LIST;
|
||||
if data.use_geometry_shader {
|
||||
|
@ -744,11 +774,11 @@ unsafe fn create_pipeline(device: &Device, data: &mut app_data::AppData) -> Resu
|
|||
|
||||
data.pipeline_layout = device.create_pipeline_layout(&layout_info, None)?;
|
||||
|
||||
let stages = &[vert_stage, frag_stage];
|
||||
let stages_geom = &[vert_stage, geo_stage,frag_stage];
|
||||
let stages_cube = &[vert_stage_cube, frag_stage_cube];
|
||||
let stages_geom_cube = &[vert_stage_cube, geo_stage_cube,frag_stage_cube];
|
||||
|
||||
let mut info = vk::GraphicsPipelineCreateInfo::builder()
|
||||
.vertex_input_state(&vertex_input_state)
|
||||
let mut info_cube = vk::GraphicsPipelineCreateInfo::builder()
|
||||
.vertex_input_state(&vertex_input_state_cube)
|
||||
.input_assembly_state(&input_assembly_state)
|
||||
.viewport_state(&viewport_state)
|
||||
.rasterization_state(&rasterization_state)
|
||||
|
@ -760,18 +790,46 @@ unsafe fn create_pipeline(device: &Device, data: &mut app_data::AppData) -> Resu
|
|||
.subpass(0);
|
||||
|
||||
if data.use_geometry_shader {
|
||||
info = info.stages(stages_geom);
|
||||
info_cube = info_cube.stages(stages_geom_cube);
|
||||
}
|
||||
else {
|
||||
info = info.stages(stages);
|
||||
info_cube = info_cube.stages(stages_cube);
|
||||
}
|
||||
|
||||
data.pipeline = device.create_graphics_pipelines(
|
||||
vk::PipelineCache::null(), &[info], None)?.0[0];
|
||||
let stages_cuboid = &[vert_stage_cuboid, frag_stage_cuboid];
|
||||
let stages_geom_cuboid = &[vert_stage_cuboid, geo_stage_cuboid,frag_stage_cuboid];
|
||||
|
||||
device.destroy_shader_module(vert_shader_module, None);
|
||||
device.destroy_shader_module(geo_shader_module, None);
|
||||
device.destroy_shader_module(frag_shader_module, None);
|
||||
let mut info_cuboid = vk::GraphicsPipelineCreateInfo::builder()
|
||||
.vertex_input_state(&vertex_input_state_cuboid)
|
||||
.input_assembly_state(&input_assembly_state)
|
||||
.viewport_state(&viewport_state)
|
||||
.rasterization_state(&rasterization_state)
|
||||
.multisample_state(&multisample_state)
|
||||
.depth_stencil_state(&depth_stencil_state)
|
||||
.color_blend_state(&color_blend_state)
|
||||
.layout(data.pipeline_layout)
|
||||
.render_pass(data.render_pass)
|
||||
.subpass(0);
|
||||
|
||||
if data.use_geometry_shader {
|
||||
info_cuboid = info_cuboid.stages(stages_geom_cuboid);
|
||||
}
|
||||
else {
|
||||
info_cuboid = info_cuboid.stages(stages_cuboid);
|
||||
}
|
||||
|
||||
let pipelines = device.create_graphics_pipelines(vk::PipelineCache::null(), &[info_cube, info_cuboid], None)?.0;
|
||||
|
||||
data.pipeline_cube = pipelines[0];
|
||||
data.pipeline_cuboid = pipelines[1];
|
||||
|
||||
device.destroy_shader_module(vert_shader_module_cube, None);
|
||||
device.destroy_shader_module(geo_shader_module_cube, None);
|
||||
device.destroy_shader_module(frag_shader_module_cube, None);
|
||||
|
||||
device.destroy_shader_module(vert_shader_module_cuboid, None);
|
||||
device.destroy_shader_module(geo_shader_module_cuboid, None);
|
||||
device.destroy_shader_module(frag_shader_module_cuboid, None);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue