Workgroup sizes of 8 along with reducing the amount of work groups improves performance 20x

This commit is contained in:
2019-09-06 00:21:50 -07:00
parent 711e678969
commit 314fa3e4af
5 changed files with 67 additions and 121 deletions

View File

@@ -95,7 +95,7 @@ impl<'a> VkProcessor<'a> {
Swapchain::new(self.device.clone(),
surface.clone(),
capabilities.min_image_count + 10, // number of attachment images
capabilities.min_image_count, // number of attachment images
format,
initial_dimensions,
1, // Layers
@@ -103,7 +103,7 @@ impl<'a> VkProcessor<'a> {
&self.queue,
SurfaceTransform::Identity,
alpha,
PresentMode::Mailbox, true, None).unwrap()
PresentMode::Immediate, true, None).unwrap()
};
self.swapchain = Some(swapchain);
@@ -174,12 +174,10 @@ impl<'a> VkProcessor<'a> {
pub fn run(&mut self,
surface: &'a Arc<Surface<Window>>,
// mut frame_future: Box<dyn GpuFuture>,
canvas_frame: CanvasFrame,
compute_frame: CompuFrame,
)
// -> Box<dyn GpuFuture> {
{
) {
{
let g = hprof::enter("Waiting at queue");
self.queue.wait();
@@ -189,9 +187,6 @@ impl<'a> VkProcessor<'a> {
let mut framebuffers =
self.canvas.window_size_dependent_setup(&self.swapchain_images.clone().unwrap().clone());
// The docs said to call this on each loop.
// frame_future.cleanup_finished();
// Whenever the window resizes we need to recreate everything dependent on the window size.
// In this example that includes the swapchain, the framebuffers and the dynamic state viewport.
if self.swapchain_recreate_needed {
@@ -201,33 +196,27 @@ impl<'a> VkProcessor<'a> {
self.swapchain_recreate_needed = false;
}
// This function can block if no image is available. The parameter is an optional timeout
// after which the function call will return an error.
let (image_num, acquire_future) =
match vulkano::swapchain::acquire_next_image(
self.swapchain.clone().unwrap().clone(),
//Some(Duration::from_millis(3)),
None,
) {
Ok(r) => r,
Err(AcquireError::OutOfDate) => {
self.swapchain_recreate_needed = true;
//return Box::new(sync::now(self.device.clone())) as Box<_>;
return;
}
Err(err) => panic!("{:?}", err)
};
drop(g);
let g = hprof::enter("Joining the future");
// let future = frame_future.join(acquire_future);
drop(g);
{
let g = hprof::enter("Canvas creates GPU buffers");
// take the canvas frame and create the vertex buffers
// TODO: This performs gpu buffer creation. Shouldn't be in hotpath
// TODO: This performs gpu buffer creation. Shouldn't be in hotpath??
self.canvas.draw(canvas_frame);
}
@@ -236,41 +225,43 @@ impl<'a> VkProcessor<'a> {
let g = hprof::enter("Push compute commands to command buffer");
// Add the compute commands
// let mut command_buffer = self.compute_state.compute_commands(compute_frame, command_buffer, &self.canvas);
let mut command_buffer = self.compute_state.compute_commands(compute_frame, command_buffer, &self.canvas);
drop(g);
let g = hprof::enter("Push draw commands to command buffer");
// Add the draw commands
// let mut command_buffer = self.canvas.draw_commands(command_buffer, framebuffers, image_num);
drop(g);
let mut command_buffer = self.canvas.draw_commands(command_buffer, framebuffers, image_num);
// And build
let command_buffer = command_buffer.build().unwrap();
drop(g);
// Wait on the previous frame, then execute the command buffer and present the image
{
let g = hprof::enter("Mussing with the frame future");
//let future = future //frame_future.join(acquire_future)
let future = sync::now(self.device.clone())
let g = hprof::enter("Joining on the framebuffer");
let mut future = sync::now(self.device.clone())
.join(acquire_future);
drop(g);
let g = hprof::enter("Running the kernel and waiting on the future");
let future = future
.then_execute(self.queue.clone(), command_buffer).unwrap()
.then_swapchain_present(self.queue.clone(), self.swapchain.clone().unwrap().clone(), image_num)
.then_signal_fence_and_flush();
future.unwrap().wait(None).unwrap();
// match future {
// Ok(future) => {
// (Box::new(future) as Box<_>)
// }
// Err(FlushError::OutOfDate) => {
// self.swapchain_recreate_needed = true;
// (Box::new(sync::now(self.device.clone())) as Box<_>)
// }
// Err(e) => {
// println!("{:?}", e);
// (Box::new(sync::now(self.device.clone())) as Box<_>)
// }
// }
match future {
Ok(future) => {
future.wait(None).unwrap();
}
Err(FlushError::OutOfDate) => {
self.swapchain_recreate_needed = true;
}
Err(e) => {
println!("{:?}", e);
}
}
}
}
}