From: Joshua Simmons Date: Sat, 12 Nov 2022 23:22:56 +0000 (+0100) Subject: Add const for magical swapchain destruction delay X-Git-Url: https://git.nega.tv//gitweb.cgi?a=commitdiff_plain;h=89456087b0f790a5b2f410c1064457a037a20b2b;p=josh%2Fnarcissus Add const for magical swapchain destruction delay --- diff --git a/narcissus-gpu/src/delay_queue.rs b/narcissus-gpu/src/delay_queue.rs index 9ba0cfa..44efaeb 100644 --- a/narcissus-gpu/src/delay_queue.rs +++ b/narcissus-gpu/src/delay_queue.rs @@ -1,13 +1,13 @@ use std::collections::VecDeque; pub struct DelayQueue { - delay: u64, - counter: u64, - values: VecDeque<(u64, T)>, + delay: usize, + counter: usize, + values: VecDeque<(usize, T)>, } impl DelayQueue { - pub fn new(delay: u64) -> Self { + pub fn new(delay: usize) -> Self { Self { delay, counter: 0, @@ -33,7 +33,7 @@ impl DelayQueue { } } - pub fn drain(&mut self, range: R) -> std::collections::vec_deque::Drain<'_, (u64, T)> + pub fn drain(&mut self, range: R) -> std::collections::vec_deque::Drain<'_, (usize, T)> where R: std::ops::RangeBounds, { diff --git a/narcissus-gpu/src/vulkan.rs b/narcissus-gpu/src/vulkan.rs index 7b6ca5a..e0339a5 100644 --- a/narcissus-gpu/src/vulkan.rs +++ b/narcissus-gpu/src/vulkan.rs @@ -26,6 +26,11 @@ use crate::{ const NUM_FRAMES: usize = 2; +/// How many frames to delay swapchain destruction. +/// +/// There's no correct answer here (spec bug) we're just picking a big number and hoping for the best. +const SWAPCHAIN_DESTROY_DELAY_FRAMES: usize = 8; + macro_rules! vk_check { ($e:expr) => ({ #[allow(unused_unsafe)] @@ -782,7 +787,7 @@ impl<'app> VulkanDevice<'app> { frames, swapchains: Mutex::new(HashMap::new()), - destroyed_swapchains: Mutex::new(DelayQueue::new(8)), + destroyed_swapchains: Mutex::new(DelayQueue::new(SWAPCHAIN_DESTROY_DELAY_FRAMES)), texture_pool: default(), buffer_pool: default(),