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

Rewrite shader and specialization handling in pipelines #2181

Merged
merged 6 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
9 changes: 6 additions & 3 deletions examples/src/bin/basic-compute-shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use vulkano::{
instance::{Instance, InstanceCreateInfo},
memory::allocator::{AllocationCreateInfo, MemoryUsage, StandardMemoryAllocator},
pipeline::{ComputePipeline, Pipeline, PipelineBindPoint},
shader::PipelineShaderStageCreateInfo,
sync::{self, GpuFuture},
VulkanLibrary,
};
Expand Down Expand Up @@ -134,12 +135,14 @@ fn main() {
",
}
}
let shader = cs::load(device.clone()).unwrap();
let shader = cs::load(device.clone())
.unwrap()
.entry_point("main")
.unwrap();

ComputePipeline::new(
device.clone(),
shader.entry_point("main").unwrap(),
&(),
PipelineShaderStageCreateInfo::entry_point(shader),
None,
|_| {},
)
Expand Down
29 changes: 22 additions & 7 deletions examples/src/bin/buffer-allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ use vulkano::{
memory::allocator::StandardMemoryAllocator,
pipeline::{
graphics::{
color_blend::ColorBlendState,
input_assembly::InputAssemblyState,
multisample::MultisampleState,
rasterization::RasterizationState,
vertex_input::Vertex,
viewport::{Viewport, ViewportState},
},
GraphicsPipeline,
},
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass},
shader::PipelineShaderStageCreateInfo,
swapchain::{
acquire_next_image, AcquireError, Swapchain, SwapchainCreateInfo, SwapchainCreationError,
SwapchainPresentInfo,
Expand Down Expand Up @@ -202,9 +206,6 @@ fn main() {
}
}

let vs = vs::load(device.clone()).unwrap();
let fs = fs::load(device.clone()).unwrap();

let render_pass = vulkano::single_pass_renderpass!(
device.clone(),
attachments: {
Expand All @@ -222,13 +223,27 @@ 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 subpass = Subpass::from(render_pass.clone(), 0).unwrap();
let pipeline = GraphicsPipeline::start()
.stages([
PipelineShaderStageCreateInfo::entry_point(vs),
PipelineShaderStageCreateInfo::entry_point(fs),
])
.vertex_input_state(Vertex::per_vertex())
.vertex_shader(vs.entry_point("main").unwrap(), ())
.input_assembly_state(InputAssemblyState::new())
.input_assembly_state(InputAssemblyState::default())
.viewport_state(ViewportState::viewport_dynamic_scissor_irrelevant())
.fragment_shader(fs.entry_point("main").unwrap(), ())
.render_pass(Subpass::from(render_pass.clone(), 0).unwrap())
.rasterization_state(RasterizationState::default())
.multisample_state(MultisampleState::default())
.color_blend_state(ColorBlendState::new(subpass.num_color_attachments()))
.render_pass(subpass)
.build(device.clone())
.unwrap();

Expand Down
23 changes: 18 additions & 5 deletions examples/src/bin/deferred/frame/ambient_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@ use vulkano::{
graphics::{
color_blend::{AttachmentBlend, BlendFactor, BlendOp, ColorBlendState},
input_assembly::InputAssemblyState,
multisample::MultisampleState,
rasterization::RasterizationState,
vertex_input::Vertex,
viewport::{Viewport, ViewportState},
},
GraphicsPipeline, Pipeline, PipelineBindPoint,
},
render_pass::Subpass,
shader::PipelineShaderStageCreateInfo,
};

use super::LightingVertex;
Expand Down Expand Up @@ -81,15 +84,25 @@ impl AmbientLightingSystem {
.expect("failed to create buffer");

let pipeline = {
let vs = vs::load(gfx_queue.device().clone()).expect("failed to create shader module");
let fs = fs::load(gfx_queue.device().clone()).expect("failed to create shader module");
let vs = vs::load(gfx_queue.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())
.expect("failed to create shader module")
.entry_point("main")
.expect("shader entry point not found");

GraphicsPipeline::start()
.stages([
PipelineShaderStageCreateInfo::entry_point(vs),
PipelineShaderStageCreateInfo::entry_point(fs),
])
.vertex_input_state(LightingVertex::per_vertex())
.vertex_shader(vs.entry_point("main").unwrap(), ())
.input_assembly_state(InputAssemblyState::new())
.input_assembly_state(InputAssemblyState::default())
.viewport_state(ViewportState::viewport_dynamic_scissor_irrelevant())
.fragment_shader(fs.entry_point("main").unwrap(), ())
.rasterization_state(RasterizationState::default())
.multisample_state(MultisampleState::default())
.color_blend_state(ColorBlendState::new(subpass.num_color_attachments()).blend(
AttachmentBlend {
color_op: BlendOp::Add,
Expand Down
23 changes: 18 additions & 5 deletions examples/src/bin/deferred/frame/directional_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ use vulkano::{
graphics::{
color_blend::{AttachmentBlend, BlendFactor, BlendOp, ColorBlendState},
input_assembly::InputAssemblyState,
multisample::MultisampleState,
rasterization::RasterizationState,
vertex_input::Vertex,
viewport::{Viewport, ViewportState},
},
GraphicsPipeline, Pipeline, PipelineBindPoint,
},
render_pass::Subpass,
shader::PipelineShaderStageCreateInfo,
};

use super::LightingVertex;
Expand Down Expand Up @@ -84,15 +87,25 @@ impl DirectionalLightingSystem {
};

let pipeline = {
let vs = vs::load(gfx_queue.device().clone()).expect("failed to create shader module");
let fs = fs::load(gfx_queue.device().clone()).expect("failed to create shader module");
let vs = vs::load(gfx_queue.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())
.expect("failed to create shader module")
.entry_point("main")
.expect("shader entry point not found");

GraphicsPipeline::start()
.stages([
PipelineShaderStageCreateInfo::entry_point(vs),
PipelineShaderStageCreateInfo::entry_point(fs),
])
.vertex_input_state(LightingVertex::per_vertex())
.vertex_shader(vs.entry_point("main").unwrap(), ())
.input_assembly_state(InputAssemblyState::new())
.input_assembly_state(InputAssemblyState::default())
.viewport_state(ViewportState::viewport_dynamic_scissor_irrelevant())
.fragment_shader(fs.entry_point("main").unwrap(), ())
.rasterization_state(RasterizationState::default())
.multisample_state(MultisampleState::default())
.color_blend_state(ColorBlendState::new(subpass.num_color_attachments()).blend(
AttachmentBlend {
color_op: BlendOp::Add,
Expand Down
23 changes: 18 additions & 5 deletions examples/src/bin/deferred/frame/point_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ use vulkano::{
graphics::{
color_blend::{AttachmentBlend, BlendFactor, BlendOp, ColorBlendState},
input_assembly::InputAssemblyState,
multisample::MultisampleState,
rasterization::RasterizationState,
vertex_input::Vertex,
viewport::{Viewport, ViewportState},
},
GraphicsPipeline, Pipeline, PipelineBindPoint,
},
render_pass::Subpass,
shader::PipelineShaderStageCreateInfo,
};

use super::LightingVertex;
Expand Down Expand Up @@ -81,15 +84,25 @@ impl PointLightingSystem {
.expect("failed to create buffer");

let pipeline = {
let vs = vs::load(gfx_queue.device().clone()).expect("failed to create shader module");
let fs = fs::load(gfx_queue.device().clone()).expect("failed to create shader module");
let vs = vs::load(gfx_queue.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())
.expect("failed to create shader module")
.entry_point("main")
.expect("shader entry point not found");

GraphicsPipeline::start()
.stages([
PipelineShaderStageCreateInfo::entry_point(vs),
PipelineShaderStageCreateInfo::entry_point(fs),
])
.vertex_input_state(LightingVertex::per_vertex())
.vertex_shader(vs.entry_point("main").unwrap(), ())
.input_assembly_state(InputAssemblyState::new())
.input_assembly_state(InputAssemblyState::default())
.viewport_state(ViewportState::viewport_dynamic_scissor_irrelevant())
.fragment_shader(fs.entry_point("main").unwrap(), ())
.rasterization_state(RasterizationState::default())
.multisample_state(MultisampleState::default())
.color_blend_state(ColorBlendState::new(subpass.num_color_attachments()).blend(
AttachmentBlend {
color_op: BlendOp::Add,
Expand Down
25 changes: 20 additions & 5 deletions examples/src/bin/deferred/triangle_draw_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@ use vulkano::{
memory::allocator::{AllocationCreateInfo, MemoryUsage, StandardMemoryAllocator},
pipeline::{
graphics::{
color_blend::ColorBlendState,
depth_stencil::DepthStencilState,
input_assembly::InputAssemblyState,
multisample::MultisampleState,
rasterization::RasterizationState,
vertex_input::Vertex,
viewport::{Viewport, ViewportState},
},
GraphicsPipeline,
},
render_pass::Subpass,
shader::PipelineShaderStageCreateInfo,
};

pub struct TriangleDrawSystem {
Expand Down Expand Up @@ -70,16 +74,27 @@ impl TriangleDrawSystem {
.expect("failed to create buffer");

let pipeline = {
let vs = vs::load(gfx_queue.device().clone()).expect("failed to create shader module");
let fs = fs::load(gfx_queue.device().clone()).expect("failed to create shader module");
let vs = vs::load(gfx_queue.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())
.expect("failed to create shader module")
.entry_point("main")
.expect("shader entry point not found");

GraphicsPipeline::start()
.stages([
PipelineShaderStageCreateInfo::entry_point(vs),
PipelineShaderStageCreateInfo::entry_point(fs),
])
.vertex_input_state(TriangleVertex::per_vertex())
.vertex_shader(vs.entry_point("main").unwrap(), ())
.input_assembly_state(InputAssemblyState::new())
.input_assembly_state(InputAssemblyState::default())
.viewport_state(ViewportState::viewport_dynamic_scissor_irrelevant())
.fragment_shader(fs.entry_point("main").unwrap(), ())
.rasterization_state(RasterizationState::default())
.depth_stencil_state(DepthStencilState::simple_depth_test())
.multisample_state(MultisampleState::default())
.color_blend_state(ColorBlendState::new(subpass.num_color_attachments()))
.render_pass(subpass.clone())
.build(gfx_queue.device().clone())
.unwrap()
Expand Down
9 changes: 6 additions & 3 deletions examples/src/bin/dynamic-buffers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ use vulkano::{
instance::{Instance, InstanceCreateInfo},
memory::allocator::{AllocationCreateInfo, MemoryUsage, StandardMemoryAllocator},
pipeline::{ComputePipeline, Pipeline, PipelineBindPoint},
shader::PipelineShaderStageCreateInfo,
sync::{self, GpuFuture},
DeviceSize, VulkanLibrary,
};
Expand Down Expand Up @@ -118,11 +119,13 @@ fn main() {
}
}

let shader = shader::load(device.clone()).unwrap();
let shader = shader::load(device.clone())
.unwrap()
.entry_point("main")
.unwrap();
let pipeline = ComputePipeline::new(
device.clone(),
shader.entry_point("main").unwrap(),
&(),
PipelineShaderStageCreateInfo::entry_point(shader),
None,
|layout_create_infos| {
let binding = layout_create_infos[0].bindings.get_mut(&0).unwrap();
Expand Down
29 changes: 17 additions & 12 deletions examples/src/bin/dynamic-local-size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ use vulkano::{
instance::{Instance, InstanceCreateInfo, InstanceExtensions},
memory::allocator::{AllocationCreateInfo, MemoryUsage, StandardMemoryAllocator},
pipeline::{ComputePipeline, Pipeline, PipelineBindPoint},
shader::PipelineShaderStageCreateInfo,
sync::{self, GpuFuture},
VulkanLibrary,
};
Expand Down Expand Up @@ -149,8 +150,6 @@ fn main() {
}
}

let shader = cs::load(device.clone()).unwrap();

// Fetching subgroup size from the physical device properties to determine an appropriate
// compute shader local size.
//
Expand All @@ -175,18 +174,24 @@ fn main() {

println!("Local size will be set to: ({local_size_x}, {local_size_y}, 1)");

let spec_consts = cs::SpecializationConstants {
red: 0.2,
green: 0.5,
blue: 1.0,
// Specify the local size constants.
constant_1: local_size_x,
constant_2: local_size_y,
};
let shader = cs::load(device.clone())
.unwrap()
.entry_point("main")
.unwrap();
let pipeline = ComputePipeline::new(
device.clone(),
shader.entry_point("main").unwrap(),
&spec_consts,
PipelineShaderStageCreateInfo {
specialization_info: [
(0, 0.2f32.into()),
(1, local_size_x.into()),
(2, local_size_y.into()),
(3, 0.5f32.into()),
(4, 1.0f32.into()),
]
.into_iter()
.collect(),
..PipelineShaderStageCreateInfo::entry_point(shader)
},
None,
|_| {},
)
Expand Down
Loading