From b15f1ebfb7235db7c5b5f03a5a50e63282e2cd01 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Sat, 3 Jul 2021 00:23:11 -0400 Subject: [PATCH] halmark: fix the command pool recycling policy --- wgpu-hal/examples/halmark/main.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index 79f06ac082..716542e562 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -10,6 +10,7 @@ const MAX_BUNNIES: usize = 1 << 20; const BUNNY_SIZE: f32 = 0.15 * 256.0; const GRAVITY: f32 = -9.8 * 100.0; const MAX_VELOCITY: f32 = 750.0; +const COMMAND_BUFFER_PER_CONTEXT: usize = 100; #[repr(C)] #[derive(Clone, Copy)] @@ -34,7 +35,7 @@ struct ExecutionContext { fence_value: hal::FenceValue, used_views: Vec, used_cmd_bufs: Vec, - bunnies_recorded: usize, + frames_recorded: usize, } impl ExecutionContext { @@ -44,7 +45,7 @@ impl ExecutionContext { device.destroy_texture_view(view); } self.encoder.reset_all(self.used_cmd_bufs.drain(..)); - self.bunnies_recorded = 0; + self.frames_recorded = 0; } } @@ -466,7 +467,7 @@ impl Example { fence_value: 1, used_views: Vec::new(), used_cmd_bufs: Vec::new(), - bunnies_recorded: 0, + frames_recorded: 0, }], context_index: 0, extent: [window_size.0, window_size.1], @@ -641,8 +642,8 @@ impl Example { } } - ctx.bunnies_recorded += self.bunnies.len(); - let do_fence = ctx.bunnies_recorded > MAX_BUNNIES; + ctx.frames_recorded += 1; + let do_fence = ctx.frames_recorded > COMMAND_BUFFER_PER_CONTEXT; unsafe { ctx.encoder.end_render_pass(); @@ -673,7 +674,7 @@ impl Example { fence_value: 0, used_views: Vec::new(), used_cmd_bufs: Vec::new(), - bunnies_recorded: 0, + frames_recorded: 0, } }); }