diff --git a/crates/renderer/src/device.rs b/crates/renderer/src/device.rs index 6d9e103..233475a 100644 --- a/crates/renderer/src/device.rs +++ b/crates/renderer/src/device.rs @@ -446,10 +446,10 @@ impl PhysicalDeviceInfo { #[derive(Debug)] pub(crate) struct DevicePools { + pub(crate) pipeline_cache: asdf::DeviceObject>, pub(crate) fences: Arc>, pub(crate) binary_semaphores: Pool, pub(crate) timeline_semaphores: Pool, - pub(crate) pipeline_cache: asdf::DeviceObject>, } impl AsRef for DevicePools { diff --git a/crates/renderer/src/lib.rs b/crates/renderer/src/lib.rs index c7cddfa..f2467e4 100644 --- a/crates/renderer/src/lib.rs +++ b/crates/renderer/src/lib.rs @@ -205,6 +205,7 @@ impl PhysicalDeviceFeatures { mut create_info: vk::DeviceCreateInfo<'a>, ) -> vk::DeviceCreateInfo<'a> { create_info = create_info + .enabled_features(&self.core) .push_next(&mut self.core11) .push_next(&mut self.core12) .push_next(&mut self.core13); @@ -923,7 +924,7 @@ impl EguiState { } pub struct Renderer2 { - device: Device, + pub device: Device, pub samplers: SamplerCache, pub texture_manager: texture::TextureManager, @@ -943,6 +944,10 @@ impl Renderer2 { &instance, &[], PhysicalDeviceFeatures { + core: vk::PhysicalDeviceFeatures { + multi_draw_indirect: vk::TRUE, + ..Default::default() + }, core11: vk::PhysicalDeviceVulkan11Features { shader_draw_parameters: vk::TRUE, ..Default::default() diff --git a/crates/renderer/src/pipeline.rs b/crates/renderer/src/pipeline.rs index c5a221c..412eff2 100644 --- a/crates/renderer/src/pipeline.rs +++ b/crates/renderer/src/pipeline.rs @@ -714,7 +714,13 @@ pub(crate) mod pipeline_cache { impl crate::device::asdf::traits::ExternallyManagedObject> for PipelineCache { unsafe fn destroy(self, owner: &Arc) { + tracing::info!("destroying pipeline cache with key {:x}", self.key); if let Ok(data) = self.export(&owner.raw) { + tracing::info!( + "exported pipeline cache with key {:x} and size {} bytes", + self.key, + data.len() + ); _ = Self::write_to_disk(self.key, &data).inspect_err(|err| { tracing::error!("failed to write pipeline cache to disk: {err}"); }); diff --git a/crates/renderer/src/swapchain.rs b/crates/renderer/src/swapchain.rs index b89d824..1d33162 100644 --- a/crates/renderer/src/swapchain.rs +++ b/crates/renderer/src/swapchain.rs @@ -335,9 +335,6 @@ pub struct Swapchain { acquire_semaphores: Vec, release_semaphores: Vec, - // one fence per in-flight frame, to synchronize image acquisition - fences: Vec, - current_frame: AtomicU32, // Some of the swapchain operations require external synchronisation; this mutex allows `Swapchain` to be `Sync`. @@ -354,11 +351,7 @@ impl Swapchain { /// This function MUST be called once and only once before the swapchain is dropped. pub unsafe fn release_resources(&self) { _ = self.swapchain.device().wait_idle(); - for fence in &self.fences { - unsafe { - self.swapchain.device().raw.destroy_fence(*fence, None); - } - } + for &semaphore in self .acquire_semaphores .iter() @@ -467,7 +460,7 @@ impl Swapchain { }; let release_semaphores = { - (0..inflight_frames) + (0..images.len()) .map(|i| unsafe { device .dev() @@ -483,18 +476,6 @@ impl Swapchain { .collect::>>()? }; - let fences = { - (0..inflight_frames) - .map(|i| unsafe { - let fence = device - .raw - .create_fence(&vk::FenceCreateInfo::default(), None)?; - device.debug_name_object(fence, &format!("fence-{:x}_{i}", swapchain.as_raw())); - Ok(fence) - }) - .collect::>>()? - }; - tracing::trace!( image_count = images.len(), min_image_count = surface_caps.capabilities.min_image_count, @@ -518,7 +499,6 @@ impl Swapchain { min_image_count: surface_caps.capabilities.min_image_count, acquire_semaphores, release_semaphores, - fences, current_frame: AtomicU32::new(0), present_id: AtomicU64::new(1), }) @@ -553,7 +533,6 @@ impl Swapchain { async move { let fence = Fence::from_pool(&self.swapchain.device().pools.fences, None)?; let acquire = self.acquire_semaphores[frame]; - let release = self.release_semaphores[frame]; // spawn on threadpool because it might block. let (idx, suboptimal) = smol::unblock({ @@ -568,6 +547,8 @@ impl Swapchain { }) .await?; + let release = self.release_semaphores[idx as usize]; + let idx = idx as usize; let image = self.images[idx]; let image = Arc::new(images::Image::from_swapchain_image(image, &self)); diff --git a/crates/renderer/src/sync.rs b/crates/renderer/src/sync.rs index ec630cd..a3a2c4b 100644 --- a/crates/renderer/src/sync.rs +++ b/crates/renderer/src/sync.rs @@ -204,7 +204,7 @@ impl Fence { .create_fence(&vk::FenceCreateInfo::default(), None)? }; Ok(Self::Dedicated { - fence: DeviceObject::new_debug_named(device.shared, fence, name), + fence: DeviceObject::new_debug_named(device.shared.clone(), fence, name), }) } pub fn from_pool(pool: &Arc>, name: Option<&'static str>) -> Result { @@ -418,7 +418,7 @@ impl Semaphore { }; Ok(Self::Dedicated { - semaphore: DeviceObject::new_debug_named(device.shared, inner, name), + semaphore: DeviceObject::new_debug_named(device.shared.clone(), inner, name), }) } @@ -431,7 +431,7 @@ impl Semaphore { SemaphoreType::Binary => { let semaphore: SemaphoreInner = device.pools.binary_semaphores.get_debug_named(name)?.into(); - PoolObject::new(semaphore, device.pools) + PoolObject::new(semaphore, device.pools.clone()) } SemaphoreType::Timeline(value) => { let semaphore: SemaphoreInner = device @@ -447,7 +447,7 @@ impl Semaphore { device.raw.signal_semaphore(&info)?; } - PoolObject::new(semaphore, device.pools) + PoolObject::new(semaphore, device.pools.clone()) } };