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 intermediary image to Frame for user graphics #242

Merged
merged 4 commits into from
Feb 14, 2019
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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ path = "examples/basics/7_modules/7_modules.rs"
name = "vk_triangle"
path = "examples/vulkan/vk_triangle.rs"
[[example]]
name = "vk_triangle_raw_frame"
path = "examples/vulkan/vk_triangle_raw_frame.rs"
[[example]]
name = "vk_teapot"
path = "examples/vulkan/vk_teapot.rs"
[[example]]
Expand Down
15 changes: 7 additions & 8 deletions examples/vulkan/vk_image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use nannou::vulkano::image::{Dimensions, ImmutableImage};
use nannou::vulkano::pipeline::viewport::Viewport;
use nannou::vulkano::pipeline::{GraphicsPipeline, GraphicsPipelineAbstract};
use nannou::vulkano::sampler::{Filter, MipmapMode, Sampler, SamplerAddressMode};
use nannou::window::SwapchainFramebuffers;

fn main() {
nannou::app(model).run();
Expand All @@ -25,7 +24,7 @@ struct Model {
render_pass: Arc<RenderPassAbstract + Send + Sync>,
pipeline: Arc<GraphicsPipelineAbstract + Send + Sync>,
vertex_buffer: Arc<CpuAccessibleBuffer<[Vertex]>>,
framebuffers: RefCell<SwapchainFramebuffers>,
framebuffer: RefCell<ViewFramebuffer>,
desciptor_set: Arc<DescriptorSet + Send + Sync>,
}

Expand Down Expand Up @@ -77,7 +76,7 @@ fn model(app: &App) -> Model {
load: Clear,
store: Store,
format: app.main_window().swapchain().format(),
samples: 1,
samples: app.main_window().msaa_samples(),
initial_layout: ImageLayout::PresentSrc,
final_layout: ImageLayout::PresentSrc,
}
Expand Down Expand Up @@ -142,13 +141,13 @@ fn model(app: &App) -> Model {
.unwrap(),
);

let framebuffers = RefCell::new(SwapchainFramebuffers::default());
let framebuffer = RefCell::new(ViewFramebuffer::default());

Model {
render_pass,
pipeline,
vertex_buffer,
framebuffers,
framebuffer,
desciptor_set,
}
}
Expand All @@ -166,8 +165,8 @@ fn view(app: &App, model: &Model, frame: Frame) -> Frame {
scissors: None,
};

// Update framebuffers so that count matches swapchain image count and dimensions match.
model.framebuffers.borrow_mut()
// Update framebuffer in case of resize.
model.framebuffer.borrow_mut()
.update(&frame, model.render_pass.clone(), |builder, image| builder.add(image))
.unwrap();

Expand All @@ -180,7 +179,7 @@ fn view(app: &App, model: &Model, frame: Frame) -> Frame {
frame
.add_commands()
.begin_render_pass(
model.framebuffers.borrow()[frame.swapchain_image_index()].clone(),
model.framebuffer.borrow().as_ref().unwrap().clone(),
false,
clear_values,
)
Expand Down
15 changes: 7 additions & 8 deletions examples/vulkan/vk_image_sequence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use nannou::vulkano::image::{Dimensions, ImmutableImage};
use nannou::vulkano::pipeline::viewport::Viewport;
use nannou::vulkano::pipeline::{GraphicsPipeline, GraphicsPipelineAbstract};
use nannou::vulkano::sampler::{Filter, MipmapMode, Sampler, SamplerAddressMode};
use nannou::window::SwapchainFramebuffers;

fn main() {
nannou::app(model).run();
Expand All @@ -25,7 +24,7 @@ struct Model {
render_pass: Arc<RenderPassAbstract + Send + Sync>,
pipeline: Arc<GraphicsPipelineAbstract + Send + Sync>,
vertex_buffer: Arc<CpuAccessibleBuffer<[Vertex]>>,
framebuffers: RefCell<SwapchainFramebuffers>,
framebuffer: RefCell<ViewFramebuffer>,
desciptor_set: Arc<DescriptorSet + Send + Sync>,
}

Expand Down Expand Up @@ -78,7 +77,7 @@ fn model(app: &App) -> Model {
load: Clear,
store: Store,
format: app.main_window().swapchain().format(),
samples: 1,
samples: app.main_window().msaa_samples(),
initial_layout: ImageLayout::PresentSrc,
final_layout: ImageLayout::PresentSrc,
}
Expand Down Expand Up @@ -167,13 +166,13 @@ fn model(app: &App) -> Model {
.unwrap(),
);

let framebuffers = RefCell::new(SwapchainFramebuffers::default());
let framebuffer = RefCell::new(ViewFramebuffer::default());

Model {
render_pass,
pipeline,
vertex_buffer,
framebuffers,
framebuffer,
desciptor_set,
}
}
Expand All @@ -191,8 +190,8 @@ fn view(app: &App, model: &Model, frame: Frame) -> Frame {
scissors: None,
};

// Update framebuffers so that count matches swapchain image count and dimensions match.
model.framebuffers.borrow_mut()
// Update framebuffer in case of window resize.
model.framebuffer.borrow_mut()
.update(&frame, model.render_pass.clone(), |builder, image| builder.add(image))
.unwrap();

Expand All @@ -206,7 +205,7 @@ fn view(app: &App, model: &Model, frame: Frame) -> Frame {
frame
.add_commands()
.begin_render_pass(
model.framebuffers.borrow()[frame.swapchain_image_index()].clone(),
model.framebuffer.borrow().as_ref().unwrap().clone(),
false,
clear_values,
)
Expand Down
15 changes: 7 additions & 8 deletions examples/vulkan/vk_images.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use nannou::vulkano::image::{Dimensions, ImmutableImage};
use nannou::vulkano::pipeline::viewport::Viewport;
use nannou::vulkano::pipeline::{GraphicsPipeline, GraphicsPipelineAbstract};
use nannou::vulkano::sampler::{Filter, MipmapMode, Sampler, SamplerAddressMode};
use nannou::window::SwapchainFramebuffers;

fn main() {
nannou::app(model).run();
Expand All @@ -25,7 +24,7 @@ struct Model {
render_pass: Arc<RenderPassAbstract + Send + Sync>,
pipeline: Arc<GraphicsPipelineAbstract + Send + Sync>,
vertex_buffer: Arc<CpuAccessibleBuffer<[Vertex]>>,
framebuffers: RefCell<SwapchainFramebuffers>,
framebuffer: RefCell<ViewFramebuffer>,
desciptor_set: Arc<DescriptorSet + Send + Sync>,
}

Expand Down Expand Up @@ -78,7 +77,7 @@ fn model(app: &App) -> Model {
load: Clear,
store: Store,
format: app.main_window().swapchain().format(),
samples: 1,
samples: app.main_window().msaa_samples(),
initial_layout: ImageLayout::PresentSrc,
final_layout: ImageLayout::PresentSrc,
}
Expand Down Expand Up @@ -159,13 +158,13 @@ fn model(app: &App) -> Model {
.unwrap(),
);

let framebuffers = RefCell::new(SwapchainFramebuffers::default());
let framebuffer = RefCell::new(ViewFramebuffer::default());

Model {
render_pass,
pipeline,
vertex_buffer,
framebuffers,
framebuffer,
desciptor_set,
}
}
Expand All @@ -183,8 +182,8 @@ fn view(_app: &App, model: &Model, frame: Frame) -> Frame {
scissors: None,
};

// Update framebuffers so that count matches swapchain image count and dimensions match.
model.framebuffers.borrow_mut()
// Update framebuffer in case of window resize.
model.framebuffer.borrow_mut()
.update(&frame, model.render_pass.clone(), |builder, image| builder.add(image))
.unwrap();

Expand All @@ -193,7 +192,7 @@ fn view(_app: &App, model: &Model, frame: Frame) -> Frame {
frame
.add_commands()
.begin_render_pass(
model.framebuffers.borrow()[frame.swapchain_image_index()].clone(),
model.framebuffer.borrow().as_ref().unwrap().clone(),
false,
clear_values,
)
Expand Down
15 changes: 7 additions & 8 deletions examples/vulkan/vk_quad_warp/warp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use nannou::vulkano::framebuffer::{RenderPassAbstract, Subpass};
use nannou::vulkano::pipeline::viewport::Viewport;
use nannou::vulkano::pipeline::{GraphicsPipeline, GraphicsPipelineAbstract};
use nannou::vulkano::sampler::{Filter, MipmapMode, Sampler, SamplerAddressMode};
use nannou::window::SwapchainFramebuffers;
use nannou::vulkano::image::attachment::AttachmentImage;
use nannou::vulkano::sync::GpuFuture;
use nannou::math::Matrix4;
Expand All @@ -22,7 +21,7 @@ use crate::Model;
pub struct Warp {
render_pass: Arc<RenderPassAbstract + Send + Sync>,
pipeline: Arc<GraphicsPipelineAbstract + Send + Sync>,
framebuffers: RefCell<SwapchainFramebuffers>,
framebuffer: RefCell<ViewFramebuffer>,
uniform_buffer: CpuBufferPool<vs::ty::Data>,
sampler: Arc<Sampler>,
}
Expand Down Expand Up @@ -51,7 +50,7 @@ pub(crate) fn warp(app: &App) -> Warp {
load: Clear,
store: Store,
format: app.main_window().swapchain().format(),
samples: 1,
samples: app.main_window().msaa_samples(),
initial_layout: ImageLayout::PresentSrc,
final_layout: ImageLayout::PresentSrc,
}
Expand Down Expand Up @@ -92,12 +91,12 @@ pub(crate) fn warp(app: &App) -> Warp {
.unwrap(),
);

let framebuffers = RefCell::new(SwapchainFramebuffers::default());
let framebuffer = RefCell::new(ViewFramebuffer::default());

Warp {
render_pass,
pipeline,
framebuffers,
framebuffer,
sampler,
uniform_buffer,
}
Expand Down Expand Up @@ -191,8 +190,8 @@ pub(crate) fn view(app: &App, model: &Model, inter_image: Arc<AttachmentImage>,
scissors: None,
};

// Update framebuffers so that count matches swapchain image count and dimensions match.
warp.framebuffers.borrow_mut()
// Update framebuffer in case of window resize.
warp.framebuffer.borrow_mut()
.update(&frame, warp.render_pass.clone(), |builder, image| builder.add(image))
.expect("framebuffer failed to create");

Expand All @@ -213,7 +212,7 @@ pub(crate) fn view(app: &App, model: &Model, inter_image: Arc<AttachmentImage>,
frame
.add_commands()
.begin_render_pass(
warp.framebuffers.borrow()[frame.swapchain_image_index()].clone(),
warp.framebuffer.borrow().as_ref().unwrap().clone(),
false,
clear_values,
)
Expand Down
42 changes: 10 additions & 32 deletions examples/vulkan/vk_shader_include/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use std::sync::Arc;
use nannou::vulkano::buffer::{BufferUsage, CpuAccessibleBuffer};
use nannou::vulkano::command_buffer::DynamicState;
use nannou::vulkano::device::DeviceOwned;
use nannou::vulkano::framebuffer::{
Framebuffer, FramebufferAbstract, FramebufferCreationError, RenderPassAbstract, Subpass,
};
use nannou::vulkano::framebuffer::{RenderPassAbstract, Subpass};
use nannou::vulkano::pipeline::viewport::Viewport;
use nannou::vulkano::pipeline::{GraphicsPipeline, GraphicsPipelineAbstract};

Expand All @@ -22,7 +20,7 @@ struct Model {
render_pass: Arc<RenderPassAbstract + Send + Sync>,
pipeline: Arc<GraphicsPipelineAbstract + Send + Sync>,
vertex_buffer: Arc<CpuAccessibleBuffer<[Vertex]>>,
framebuffers: RefCell<Vec<Arc<FramebufferAbstract + Send + Sync>>>,
framebuffer: RefCell<ViewFramebuffer>,
}

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -75,7 +73,7 @@ fn model(app: &App) -> Model {
load: Clear,
store: Store,
format: app.main_window().swapchain().format(),
samples: 1,
samples: app.main_window().msaa_samples(),
initial_layout: ImageLayout::PresentSrc,
final_layout: ImageLayout::PresentSrc,
}
Expand All @@ -101,13 +99,13 @@ fn model(app: &App) -> Model {
.unwrap(),
);

let framebuffers = RefCell::new(Vec::new());
let framebuffer = RefCell::new(ViewFramebuffer::default());

Model {
render_pass,
pipeline,
vertex_buffer,
framebuffers,
framebuffer,
}
}

Expand All @@ -124,20 +122,10 @@ fn view(app: &App, model: &Model, frame: Frame) -> Frame {
scissors: None,
};

// Update the framebuffers if necessary.
while frame.swapchain_image_index() >= model.framebuffers.borrow().len() {
let fb =
create_framebuffer(model.render_pass.clone(), frame.swapchain_image().clone()).unwrap();
model.framebuffers.borrow_mut().push(Arc::new(fb));
}

// If the dimensions for the current framebuffer do not match, recreate it.
if frame.swapchain_image_is_new() {
let fb = &mut model.framebuffers.borrow_mut()[frame.swapchain_image_index()];
let new_fb =
create_framebuffer(model.render_pass.clone(), frame.swapchain_image().clone()).unwrap();
*fb = Arc::new(new_fb);
}
// Update the framebuffer in case of window resize.
model.framebuffer.borrow_mut()
.update(&frame, model.render_pass.clone(), |builder, image| builder.add(image))
.unwrap();

let clear_values = vec![[0.0, 1.0, 0.0, 1.0].into()];

Expand All @@ -150,7 +138,7 @@ fn view(app: &App, model: &Model, frame: Frame) -> Frame {
frame
.add_commands()
.begin_render_pass(
model.framebuffers.borrow()[frame.swapchain_image_index()].clone(),
model.framebuffer.borrow().as_ref().unwrap().clone(),
false,
clear_values,
)
Expand Down Expand Up @@ -236,13 +224,3 @@ void main() {
}"
}
}

fn create_framebuffer(
render_pass: Arc<RenderPassAbstract + Send + Sync>,
swapchain_image: Arc<nannou::window::SwapchainImage>,
) -> Result<Arc<FramebufferAbstract + Send + Sync>, FramebufferCreationError> {
let fb = Framebuffer::start(render_pass)
.add(swapchain_image)?
.build()?;
Ok(Arc::new(fb) as _)
}
Loading