Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CreateInfo for pipelines, require explicit pipeline layout creation #2186

Merged
merged 8 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions examples/src/bin/basic-compute-shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ use vulkano::{
},
instance::{Instance, InstanceCreateInfo},
memory::allocator::{AllocationCreateInfo, MemoryUsage, StandardMemoryAllocator},
pipeline::{ComputePipeline, Pipeline, PipelineBindPoint},
pipeline::{
compute::ComputePipelineCreateInfo, layout::PipelineDescriptorSetLayoutCreateInfo,
ComputePipeline, Pipeline, PipelineBindPoint, PipelineLayout,
},
shader::PipelineShaderStageCreateInfo,
sync::{self, GpuFuture},
VulkanLibrary,
Expand Down Expand Up @@ -135,16 +138,22 @@ fn main() {
",
}
}
let shader = cs::load(device.clone())
let cs = cs::load(device.clone())
.unwrap()
.entry_point("main")
.unwrap();

let stage = PipelineShaderStageCreateInfo::entry_point(cs);
let layout = PipelineLayout::new(
device.clone(),
PipelineDescriptorSetLayoutCreateInfo::from_stages([&stage])
.into_pipeline_layout_create_info(device.clone())
.unwrap(),
)
.unwrap();
ComputePipeline::new(
device.clone(),
PipelineShaderStageCreateInfo::entry_point(shader),
None,
|_| {},
ComputePipelineCreateInfo::stage_layout(stage, layout),
)
.unwrap()
};
Expand Down
65 changes: 41 additions & 24 deletions examples/src/bin/buffer-allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ use vulkano::{
rasterization::RasterizationState,
vertex_input::{Vertex, VertexDefinition},
viewport::{Viewport, ViewportState},
GraphicsPipelineCreateInfo,
},
GraphicsPipeline,
layout::PipelineDescriptorSetLayoutCreateInfo,
GraphicsPipeline, PipelineLayout,
},
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass},
shader::PipelineShaderStageCreateInfo,
Expand Down Expand Up @@ -223,32 +225,47 @@ fn main() {
)
.unwrap();

let vs = vs::load(device.clone())
.unwrap()
.entry_point("main")
.unwrap();
let fs = fs::load(device.clone())
.unwrap()
.entry_point("main")
.unwrap();
let vertex_input_state = Vertex::per_vertex()
.definition(&vs.info().input_interface)
.unwrap();
let subpass = Subpass::from(render_pass.clone(), 0).unwrap();
let pipeline = GraphicsPipeline::start()
.stages([
let pipeline = {
let vs = vs::load(device.clone())
.unwrap()
.entry_point("main")
.unwrap();
let fs = fs::load(device.clone())
.unwrap()
.entry_point("main")
.unwrap();
let vertex_input_state = Vertex::per_vertex()
.definition(&vs.info().input_interface)
.unwrap();
let stages = [
PipelineShaderStageCreateInfo::entry_point(vs),
PipelineShaderStageCreateInfo::entry_point(fs),
])
.vertex_input_state(vertex_input_state)
.input_assembly_state(InputAssemblyState::default())
.viewport_state(ViewportState::viewport_dynamic_scissor_irrelevant())
.rasterization_state(RasterizationState::default())
.multisample_state(MultisampleState::default())
.color_blend_state(ColorBlendState::new(subpass.num_color_attachments()))
.render_pass(subpass)
.build(device.clone())
];
let layout = PipelineLayout::new(
device.clone(),
PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages)
.into_pipeline_layout_create_info(device.clone())
.unwrap(),
)
.unwrap();
let subpass = Subpass::from(render_pass.clone(), 0).unwrap();
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::viewport_dynamic_scissor_irrelevant()),
rasterization_state: Some(RasterizationState::default()),
multisample_state: Some(MultisampleState::default()),
color_blend_state: Some(ColorBlendState::new(subpass.num_color_attachments())),
subpass: Some(subpass.into()),
..GraphicsPipelineCreateInfo::layout(layout)
},
)
.unwrap()
};

let mut viewport = Viewport {
origin: [0.0, 0.0],
Expand Down
71 changes: 44 additions & 27 deletions examples/src/bin/deferred/frame/ambient_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ use vulkano::{
rasterization::RasterizationState,
vertex_input::{Vertex, VertexDefinition},
viewport::{Viewport, ViewportState},
GraphicsPipelineCreateInfo,
},
GraphicsPipeline, Pipeline, PipelineBindPoint,
layout::PipelineDescriptorSetLayoutCreateInfo,
GraphicsPipeline, Pipeline, PipelineBindPoint, PipelineLayout,
},
render_pass::Subpass,
shader::PipelineShaderStageCreateInfo,
Expand Down Expand Up @@ -84,41 +86,56 @@ impl AmbientLightingSystem {
.expect("failed to create buffer");

let pipeline = {
let vs = vs::load(gfx_queue.device().clone())
let device = gfx_queue.device();
let vs = vs::load(device.clone())
.expect("failed to create shader module")
.entry_point("main")
.expect("shader entry point not found");
let fs = fs::load(gfx_queue.device().clone())
let fs = fs::load(device.clone())
.expect("failed to create shader module")
.entry_point("main")
.expect("shader entry point not found");
let vertex_input_state = LightingVertex::per_vertex()
.definition(&vs.info().input_interface)
.unwrap();

GraphicsPipeline::start()
.stages([
PipelineShaderStageCreateInfo::entry_point(vs),
PipelineShaderStageCreateInfo::entry_point(fs),
])
.vertex_input_state(vertex_input_state)
.input_assembly_state(InputAssemblyState::default())
.viewport_state(ViewportState::viewport_dynamic_scissor_irrelevant())
.rasterization_state(RasterizationState::default())
.multisample_state(MultisampleState::default())
.color_blend_state(ColorBlendState::new(subpass.num_color_attachments()).blend(
AttachmentBlend {
color_op: BlendOp::Add,
color_source: BlendFactor::One,
color_destination: BlendFactor::One,
alpha_op: BlendOp::Max,
alpha_source: BlendFactor::One,
alpha_destination: BlendFactor::One,
},
))
.render_pass(subpass.clone())
.build(gfx_queue.device().clone())
.unwrap()
let stages = [
PipelineShaderStageCreateInfo::entry_point(vs),
PipelineShaderStageCreateInfo::entry_point(fs),
];
let layout = PipelineLayout::new(
device.clone(),
PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages)
.into_pipeline_layout_create_info(device.clone())
.unwrap(),
)
.unwrap();
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::viewport_dynamic_scissor_irrelevant()),
rasterization_state: Some(RasterizationState::default()),
multisample_state: Some(MultisampleState::default()),
color_blend_state: Some(
ColorBlendState::new(subpass.num_color_attachments()).blend(
AttachmentBlend {
color_op: BlendOp::Add,
color_source: BlendFactor::One,
color_destination: BlendFactor::One,
alpha_op: BlendOp::Max,
alpha_source: BlendFactor::One,
alpha_destination: BlendFactor::One,
},
),
),
subpass: Some(subpass.clone().into()),
..GraphicsPipelineCreateInfo::layout(layout)
},
)
.unwrap()
};

AmbientLightingSystem {
Expand Down
71 changes: 44 additions & 27 deletions examples/src/bin/deferred/frame/directional_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ use vulkano::{
rasterization::RasterizationState,
vertex_input::{Vertex, VertexDefinition},
viewport::{Viewport, ViewportState},
GraphicsPipelineCreateInfo,
},
GraphicsPipeline, Pipeline, PipelineBindPoint,
layout::PipelineDescriptorSetLayoutCreateInfo,
GraphicsPipeline, Pipeline, PipelineBindPoint, PipelineLayout,
},
render_pass::Subpass,
shader::PipelineShaderStageCreateInfo,
Expand Down Expand Up @@ -87,41 +89,56 @@ impl DirectionalLightingSystem {
};

let pipeline = {
let vs = vs::load(gfx_queue.device().clone())
let device = gfx_queue.device();
let vs = vs::load(device.clone())
.expect("failed to create shader module")
.entry_point("main")
.expect("shader entry point not found");
let fs = fs::load(gfx_queue.device().clone())
let fs = fs::load(device.clone())
.expect("failed to create shader module")
.entry_point("main")
.expect("shader entry point not found");
let vertex_input_state = LightingVertex::per_vertex()
.definition(&vs.info().input_interface)
.unwrap();

GraphicsPipeline::start()
.stages([
PipelineShaderStageCreateInfo::entry_point(vs),
PipelineShaderStageCreateInfo::entry_point(fs),
])
.vertex_input_state(vertex_input_state)
.input_assembly_state(InputAssemblyState::default())
.viewport_state(ViewportState::viewport_dynamic_scissor_irrelevant())
.rasterization_state(RasterizationState::default())
.multisample_state(MultisampleState::default())
.color_blend_state(ColorBlendState::new(subpass.num_color_attachments()).blend(
AttachmentBlend {
color_op: BlendOp::Add,
color_source: BlendFactor::One,
color_destination: BlendFactor::One,
alpha_op: BlendOp::Max,
alpha_source: BlendFactor::One,
alpha_destination: BlendFactor::One,
},
))
.render_pass(subpass.clone())
.build(gfx_queue.device().clone())
.unwrap()
let stages = [
PipelineShaderStageCreateInfo::entry_point(vs),
PipelineShaderStageCreateInfo::entry_point(fs),
];
let layout = PipelineLayout::new(
device.clone(),
PipelineDescriptorSetLayoutCreateInfo::from_stages(&stages)
.into_pipeline_layout_create_info(device.clone())
.unwrap(),
)
.unwrap();
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::viewport_dynamic_scissor_irrelevant()),
rasterization_state: Some(RasterizationState::default()),
multisample_state: Some(MultisampleState::default()),
color_blend_state: Some(
ColorBlendState::new(subpass.num_color_attachments()).blend(
AttachmentBlend {
color_op: BlendOp::Add,
color_source: BlendFactor::One,
color_destination: BlendFactor::One,
alpha_op: BlendOp::Max,
alpha_source: BlendFactor::One,
alpha_destination: BlendFactor::One,
},
),
),
subpass: Some(subpass.clone().into()),
..GraphicsPipelineCreateInfo::layout(layout)
},
)
.unwrap()
};

DirectionalLightingSystem {
Expand Down
Loading