Update the examples to use the new system

This commit is contained in:
Pierre Krieger 2017-05-21 19:04:14 +02:00
parent f1dac0b9c8
commit 3c51a3eb0b
3 changed files with 20 additions and 23 deletions

View File

@ -164,12 +164,10 @@ fn main() {
vulkano::framebuffer::Framebuffer::new(renderpass.clone(), dimensions, attachments).unwrap()
}).collect::<Vec<_>>();
let mut submissions: Vec<Box<GpuFuture>> = Vec::new();
let mut previous_frame_end = Box::new(vulkano::sync::now(device.clone())) as Box<GpuFuture>;
loop {
while submissions.len() >= 4 {
submissions.remove(0);
}
previous_frame_end.cleanup_finished();
let (image_num, future) = swapchain.acquire_next_image(Duration::new(10, 0)).unwrap();
@ -187,11 +185,11 @@ fn main() {
.end_render_pass().unwrap()
.build().unwrap();
let future = future
let future = previous_frame_end.join(future)
.then_execute(queue.clone(), cb).unwrap()
.then_swapchain_present(queue.clone(), swapchain.clone(), image_num)
.then_signal_fence_and_flush().unwrap();
submissions.push(Box::new(future) as Box<_>);
previous_frame_end = Box::new(future) as Box<_>;
let mut done = false;
events_loop.poll_events(|ev| {

View File

@ -161,12 +161,10 @@ fn main() {
}).collect::<Vec<_>>();
let mut submissions: Vec<Box<GpuFuture>> = Vec::new();
let mut previous_frame = Box::new(vulkano::sync::now(device.clone())) as Box<GpuFuture>;
loop {
while submissions.len() >= 4 {
submissions.remove(0);
}
previous_frame.cleanup_finished();
{
// aquiring write lock for the uniform buffer
@ -179,7 +177,7 @@ fn main() {
buffer_content.world = cgmath::Matrix4::from(rotation).into();
}
let (image_num, future) = swapchain.acquire_next_image(std::time::Duration::new(1, 0)).unwrap();
let (image_num, acquire_future) = swapchain.acquire_next_image(std::time::Duration::new(1, 0)).unwrap();
let command_buffer = vulkano::command_buffer::AutoCommandBufferBuilder::new(device.clone(), queue.family()).unwrap()
.begin_render_pass(
@ -193,11 +191,11 @@ fn main() {
.end_render_pass().unwrap()
.build().unwrap();
let future = future
let future = previous_frame.join(acquire_future)
.then_execute(queue.clone(), command_buffer).unwrap()
.then_swapchain_present(queue.clone(), swapchain.clone(), image_num)
.then_signal_fence_and_flush().unwrap();
submissions.push(Box::new(future) as Box<_>);
previous_frame = Box::new(future) as Box<_>;
let mut done = false;
events_loop.poll_events(|ev| {

View File

@ -55,6 +55,7 @@ use vulkano::pipeline::viewport::Viewport;
use vulkano::pipeline::viewport::Scissor;
use vulkano::swapchain::SurfaceTransform;
use vulkano::swapchain::Swapchain;
use vulkano::sync::now;
use vulkano::sync::GpuFuture;
use std::sync::Arc;
@ -348,15 +349,15 @@ fn main() {
// they are in use by the GPU.
//
// Destroying the `GpuFuture` blocks until the GPU is finished executing it. In order to avoid
// that, we store them in a `Vec` and clean them from time to time.
let mut submissions: Vec<Box<GpuFuture>> = Vec::new();
// that, we store the submission of the previous frame here.
let mut previous_frame_end = Box::new(now(device.clone())) as Box<GpuFuture>;
loop {
// Clearing the old submissions by keeping alive only the ones which probably aren't
// finished.
while submissions.len() >= 4 {
submissions.remove(0);
}
// It is important to call this function from time to time, otherwise resources will keep
// accumulating and you will eventually reach an out of memory error.
// Calling this function polls various fences in order to determine what the GPU has
// already processed, and frees the resources that are no longer needed.
previous_frame_end.cleanup_finished();
// Before we can draw on the output, we have to *acquire* an image from the swapchain. If
// no image is available (which happens if you submit draw commands too quickly), then the
@ -365,7 +366,7 @@ fn main() {
//
// This function can block if no image is available. The parameter is a timeout after
// which the function call will return an error.
let (image_num, future) = swapchain.acquire_next_image(Duration::new(1, 0)).unwrap();
let (image_num, acquire_future) = swapchain.acquire_next_image(Duration::new(1, 0)).unwrap();
// In order to draw, we have to build a *command buffer*. The command buffer object holds
// the list of commands that are going to be executed.
@ -404,7 +405,7 @@ fn main() {
// Finish building the command buffer by calling `build`.
.build().unwrap();
let future = future
let future = previous_frame_end.join(acquire_future)
.then_execute(queue.clone(), command_buffer).unwrap()
// The color output is now expected to contain our triangle. But in order to show it on
@ -415,7 +416,7 @@ fn main() {
// the GPU has finished executing the command buffer that draws the triangle.
.then_swapchain_present(queue.clone(), swapchain.clone(), image_num)
.then_signal_fence_and_flush().unwrap();
submissions.push(Box::new(future) as Box<_>);
previous_frame_end = Box::new(future) as Box<_>;
// Note that in more complex programs it is likely that one of `acquire_next_image`,
// `command_buffer::submit`, or `present` will block for some time. This happens when the