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 support for dynamic rendering #1902

Merged
merged 1 commit into from
May 29, 2022
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
44 changes: 1 addition & 43 deletions examples/src/bin/clear_attachments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ use vulkano::{
},
image::{view::ImageView, ImageUsage, SwapchainImage},
instance::{Instance, InstanceCreateInfo},
pipeline::{graphics::viewport::ViewportState, GraphicsPipeline},
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass, Subpass},
render_pass::{Framebuffer, FramebufferCreateInfo, RenderPass},
swapchain::{
acquire_next_image, AcquireError, Swapchain, SwapchainCreateInfo, SwapchainCreationError,
},
Expand Down Expand Up @@ -118,37 +117,6 @@ fn main() {
.unwrap()
};

mod vs {
vulkano_shaders::shader! {
ty: "vertex",
src: "
#version 450


void main() {
}
"
}
}

mod fs {
vulkano_shaders::shader! {
ty: "fragment",
src: "
#version 450

layout(location = 0) out vec4 f_color;

void main() {
f_color = vec4(1.0, 0.0, 0.0, 1.0);
}
"
}
}

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

let render_pass = vulkano::single_pass_renderpass!(device.clone(),
attachments: {
color: {
Expand All @@ -165,15 +133,6 @@ fn main() {
)
.unwrap();

let subpass = Subpass::from(render_pass.clone(), 0).unwrap();
let pipeline = GraphicsPipeline::start()
.vertex_shader(vs.entry_point("main").unwrap(), ())
.viewport_state(ViewportState::viewport_dynamic_scissor_irrelevant())
.fragment_shader(fs.entry_point("main").unwrap(), ())
.render_pass(subpass)
.build(device.clone())
.unwrap();

let mut width = swapchain.image_extent()[0];
let mut height = swapchain.image_extent()[1];
let mut framebuffers = window_size_dependent_setup(&images, render_pass.clone());
Expand Down Expand Up @@ -243,7 +202,6 @@ fn main() {
SubpassContents::Inline,
)
.unwrap()
.bind_pipeline_graphics(pipeline.clone())
// Clear attachments with clear values and rects information, all the rects will be cleared by the same value
// Note that the ClearRect offsets and extents are not affected by the viewport,
// they are directly applied to the rendering image
Expand Down
16 changes: 12 additions & 4 deletions examples/src/bin/deferred/frame/ambient_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use bytemuck::{Pod, Zeroable};
use std::sync::Arc;
use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage, SecondaryAutoCommandBuffer},
command_buffer::{
AutoCommandBufferBuilder, CommandBufferInheritanceInfo, CommandBufferUsage,
SecondaryAutoCommandBuffer,
},
descriptor_set::{PersistentDescriptorSet, WriteDescriptorSet},
device::Queue,
image::ImageViewAbstract,
Expand All @@ -32,6 +35,7 @@ use vulkano::{
pub struct AmbientLightingSystem {
gfx_queue: Arc<Queue>,
vertex_buffer: Arc<CpuAccessibleBuffer<[Vertex]>>,
subpass: Subpass,
pipeline: Arc<GraphicsPipeline>,
}

Expand Down Expand Up @@ -81,14 +85,15 @@ impl AmbientLightingSystem {
alpha_destination: BlendFactor::One,
},
))
.render_pass(subpass)
.render_pass(subpass.clone())
.build(gfx_queue.device().clone())
.unwrap()
};

AmbientLightingSystem {
gfx_queue,
vertex_buffer,
subpass,
pipeline,
}
}
Expand Down Expand Up @@ -128,11 +133,14 @@ impl AmbientLightingSystem {
depth_range: 0.0..1.0,
};

let mut builder = AutoCommandBufferBuilder::secondary_graphics(
let mut builder = AutoCommandBufferBuilder::secondary(
self.gfx_queue.device().clone(),
self.gfx_queue.family(),
CommandBufferUsage::MultipleSubmit,
self.pipeline.subpass().clone(),
CommandBufferInheritanceInfo {
render_pass: Some(self.subpass.clone().into()),
..Default::default()
},
)
.unwrap();
builder
Expand Down
16 changes: 12 additions & 4 deletions examples/src/bin/deferred/frame/directional_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use cgmath::Vector3;
use std::sync::Arc;
use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage, SecondaryAutoCommandBuffer},
command_buffer::{
AutoCommandBufferBuilder, CommandBufferInheritanceInfo, CommandBufferUsage,
SecondaryAutoCommandBuffer,
},
descriptor_set::{PersistentDescriptorSet, WriteDescriptorSet},
device::Queue,
image::ImageViewAbstract,
Expand All @@ -33,6 +36,7 @@ use vulkano::{
pub struct DirectionalLightingSystem {
gfx_queue: Arc<Queue>,
vertex_buffer: Arc<CpuAccessibleBuffer<[Vertex]>>,
subpass: Subpass,
pipeline: Arc<GraphicsPipeline>,
}

Expand Down Expand Up @@ -82,14 +86,15 @@ impl DirectionalLightingSystem {
alpha_destination: BlendFactor::One,
},
))
.render_pass(subpass)
.render_pass(subpass.clone())
.build(gfx_queue.device().clone())
.unwrap()
};

DirectionalLightingSystem {
gfx_queue,
vertex_buffer,
subpass,
pipeline,
}
}
Expand Down Expand Up @@ -142,11 +147,14 @@ impl DirectionalLightingSystem {
depth_range: 0.0..1.0,
};

let mut builder = AutoCommandBufferBuilder::secondary_graphics(
let mut builder = AutoCommandBufferBuilder::secondary(
self.gfx_queue.device().clone(),
self.gfx_queue.family(),
CommandBufferUsage::MultipleSubmit,
self.pipeline.subpass().clone(),
CommandBufferInheritanceInfo {
render_pass: Some(self.subpass.clone().into()),
..Default::default()
},
)
.unwrap();
builder
Expand Down
16 changes: 12 additions & 4 deletions examples/src/bin/deferred/frame/point_lighting_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ use cgmath::{Matrix4, Vector3};
use std::sync::Arc;
use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage, SecondaryAutoCommandBuffer},
command_buffer::{
AutoCommandBufferBuilder, CommandBufferInheritanceInfo, CommandBufferUsage,
SecondaryAutoCommandBuffer,
},
descriptor_set::{PersistentDescriptorSet, WriteDescriptorSet},
device::Queue,
image::ImageViewAbstract,
Expand All @@ -32,6 +35,7 @@ use vulkano::{
pub struct PointLightingSystem {
gfx_queue: Arc<Queue>,
vertex_buffer: Arc<CpuAccessibleBuffer<[Vertex]>>,
subpass: Subpass,
pipeline: Arc<GraphicsPipeline>,
}

Expand Down Expand Up @@ -81,14 +85,15 @@ impl PointLightingSystem {
alpha_destination: BlendFactor::One,
},
))
.render_pass(subpass)
.render_pass(subpass.clone())
.build(gfx_queue.device().clone())
.unwrap()
};

PointLightingSystem {
gfx_queue,
vertex_buffer,
subpass,
pipeline,
}
}
Expand Down Expand Up @@ -154,11 +159,14 @@ impl PointLightingSystem {
depth_range: 0.0..1.0,
};

let mut builder = AutoCommandBufferBuilder::secondary_graphics(
let mut builder = AutoCommandBufferBuilder::secondary(
self.gfx_queue.device().clone(),
self.gfx_queue.family(),
CommandBufferUsage::MultipleSubmit,
self.pipeline.subpass().clone(),
CommandBufferInheritanceInfo {
render_pass: Some(self.subpass.clone().into()),
..Default::default()
},
)
.unwrap();
builder
Expand Down
16 changes: 12 additions & 4 deletions examples/src/bin/deferred/triangle_draw_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use bytemuck::{Pod, Zeroable};
use std::sync::Arc;
use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage, SecondaryAutoCommandBuffer},
command_buffer::{
AutoCommandBufferBuilder, CommandBufferInheritanceInfo, CommandBufferUsage,
SecondaryAutoCommandBuffer,
},
device::Queue,
impl_vertex,
pipeline::{
Expand All @@ -29,6 +32,7 @@ use vulkano::{
pub struct TriangleDrawSystem {
gfx_queue: Arc<Queue>,
vertex_buffer: Arc<CpuAccessibleBuffer<[Vertex]>>,
subpass: Subpass,
pipeline: Arc<GraphicsPipeline>,
}

Expand Down Expand Up @@ -67,25 +71,29 @@ impl TriangleDrawSystem {
.viewport_state(ViewportState::viewport_dynamic_scissor_irrelevant())
.fragment_shader(fs.entry_point("main").unwrap(), ())
.depth_stencil_state(DepthStencilState::simple_depth_test())
.render_pass(subpass)
.render_pass(subpass.clone())
.build(gfx_queue.device().clone())
.unwrap()
};

TriangleDrawSystem {
gfx_queue,
vertex_buffer,
subpass,
pipeline,
}
}

/// Builds a secondary command buffer that draws the triangle on the current subpass.
pub fn draw(&self, viewport_dimensions: [u32; 2]) -> SecondaryAutoCommandBuffer {
let mut builder = AutoCommandBufferBuilder::secondary_graphics(
let mut builder = AutoCommandBufferBuilder::secondary(
self.gfx_queue.device().clone(),
self.gfx_queue.family(),
CommandBufferUsage::MultipleSubmit,
self.pipeline.subpass().clone(),
CommandBufferInheritanceInfo {
render_pass: Some(self.subpass.clone().into()),
..Default::default()
},
)
.unwrap();
builder
Expand Down
16 changes: 12 additions & 4 deletions examples/src/bin/interactive_fractal/pixels_draw_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ use bytemuck::{Pod, Zeroable};
use std::sync::Arc;
use vulkano::{
buffer::{BufferUsage, CpuAccessibleBuffer, TypedBufferAccess},
command_buffer::{AutoCommandBufferBuilder, CommandBufferUsage, SecondaryAutoCommandBuffer},
command_buffer::{
AutoCommandBufferBuilder, CommandBufferInheritanceInfo, CommandBufferUsage,
SecondaryAutoCommandBuffer,
},
descriptor_set::{PersistentDescriptorSet, WriteDescriptorSet},
device::Queue,
image::ImageViewAbstract,
Expand Down Expand Up @@ -64,6 +67,7 @@ pub fn textured_quad(width: f32, height: f32) -> (Vec<TexturedVertex>, Vec<u32>)
/// A subpass pipeline that fills a quad over frame
pub struct PixelsDrawPipeline {
gfx_queue: Arc<Queue>,
subpass: Subpass,
pipeline: Arc<GraphicsPipeline>,
vertices: Arc<CpuAccessibleBuffer<[TexturedVertex]>>,
indices: Arc<CpuAccessibleBuffer<[u32]>>,
Expand Down Expand Up @@ -96,12 +100,13 @@ impl PixelsDrawPipeline {
.input_assembly_state(InputAssemblyState::new())
.fragment_shader(fs.entry_point("main").unwrap(), ())
.viewport_state(ViewportState::viewport_dynamic_scissor_irrelevant())
.render_pass(subpass)
.render_pass(subpass.clone())
.build(gfx_queue.device().clone())
.unwrap()
};
PixelsDrawPipeline {
gfx_queue,
subpass,
pipeline,
vertices: vertex_buffer,
indices: index_buffer,
Expand Down Expand Up @@ -142,11 +147,14 @@ impl PixelsDrawPipeline {
viewport_dimensions: [u32; 2],
image: Arc<dyn ImageViewAbstract>,
) -> SecondaryAutoCommandBuffer {
let mut builder = AutoCommandBufferBuilder::secondary_graphics(
let mut builder = AutoCommandBufferBuilder::secondary(
self.gfx_queue.device().clone(),
self.gfx_queue.family(),
CommandBufferUsage::MultipleSubmit,
self.pipeline.subpass().clone(),
CommandBufferInheritanceInfo {
render_pass: Some(self.subpass.clone().into()),
..Default::default()
},
)
.unwrap();
let desc_set = self.create_descriptor_set(image);
Expand Down
8 changes: 7 additions & 1 deletion examples/src/bin/msaa-renderpass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ use vulkano::{
instance::{Instance, InstanceCreateInfo},
pipeline::{
graphics::{
multisample::MultisampleState,
vertex_input::BuffersDefinition,
viewport::{Viewport, ViewportState},
},
Expand Down Expand Up @@ -275,12 +276,17 @@ fn main() {
CpuAccessibleBuffer::from_iter(device.clone(), BufferUsage::all(), false, vertices)
.unwrap();

let subpass = Subpass::from(render_pass.clone(), 0).unwrap();
let pipeline = GraphicsPipeline::start()
.vertex_input_state(BuffersDefinition::new().vertex::<Vertex>())
.vertex_shader(vs.entry_point("main").unwrap(), ())
.viewport_state(ViewportState::viewport_dynamic_scissor_irrelevant())
.fragment_shader(fs.entry_point("main").unwrap(), ())
.render_pass(Subpass::from(render_pass.clone(), 0).unwrap())
.multisample_state(MultisampleState {
rasterization_samples: subpass.num_samples().unwrap(),
..Default::default()
})
.render_pass(subpass)
.build(device.clone())
.unwrap();

Expand Down
Loading