From 0b4c7edc9240c63c2dfa75c5a821dd94639fd48d Mon Sep 17 00:00:00 2001 From: Schmarni Date: Tue, 15 Jul 2025 22:15:15 +0200 Subject: [PATCH] feat(wayland): set output refreshrate to i32::MAX and instrument a bunch of functions Signed-off-by: Schmarni --- Cargo.lock | 6 +- src/wayland/core/buffer.rs | 2 + src/wayland/core/output.rs | 2 +- src/wayland/core/shm_buffer_backing.rs | 1 + src/wayland/core/shm_pool.rs | 5 + src/wayland/core/surface.rs | 20 ++++ src/wayland/dmabuf/buffer_backing.rs | 4 + src/wayland/dmabuf/buffer_params.rs | 5 + src/wayland/dmabuf/feedback.rs | 7 +- src/wayland/dmabuf/mod.rs | 136 +++++++++++++++++++++---- 10 files changed, 162 insertions(+), 26 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f303a61..a8f748c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -592,7 +592,7 @@ dependencies = [ [[package]] name = "bevy-dmabuf" version = "0.2.0" -source = "git+https://github.com/Schmarni-Dev/bevy-dmabuf#8c9e3af6fecc62db684130674d48c64ba4adfe1d" +source = "git+https://github.com/Schmarni-Dev/bevy-dmabuf#c9f2ebc100f1c9ef74383d35bcdc6c36920d2741" dependencies = [ "ash", "bevy", @@ -4030,7 +4030,7 @@ version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77e878c846a8abae00dd069496dbe8751b16ac1c3d6bd2a7283a938e8228f90d" dependencies = [ - "proc-macro-crate 1.3.1", + "proc-macro-crate 3.3.0", "proc-macro2", "quote", "syn 2.0.104", @@ -6717,7 +6717,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/src/wayland/core/buffer.rs b/src/wayland/core/buffer.rs index 1521434..c945342 100644 --- a/src/wayland/core/buffer.rs +++ b/src/wayland/core/buffer.rs @@ -40,6 +40,7 @@ pub struct Buffer { } impl Buffer { + #[tracing::instrument("debug", skip_all)] pub fn new(client: &mut Client, id: ObjectId, backing: BufferBacking) -> Arc { let buffer = client.insert( id, @@ -55,6 +56,7 @@ impl Buffer { } /// Returns the tex if it was updated + #[tracing::instrument("debug", skip_all)] pub fn update_tex( &self, dmatexes: &ImportedDmatexs, diff --git a/src/wayland/core/output.rs b/src/wayland/core/output.rs index 4f2e87b..a9164ca 100644 --- a/src/wayland/core/output.rs +++ b/src/wayland/core/output.rs @@ -23,7 +23,7 @@ impl Output { ) .await?; - self.mode(client, self.0, Mode::Current, 2048, 2048, 0) + self.mode(client, self.0, Mode::Current, 2048, 2048, i32::MAX) .await?; self.done(client, self.0).await diff --git a/src/wayland/core/shm_buffer_backing.rs b/src/wayland/core/shm_buffer_backing.rs index 9ca2a0e..eed9ab7 100644 --- a/src/wayland/core/shm_buffer_backing.rs +++ b/src/wayland/core/shm_buffer_backing.rs @@ -38,6 +38,7 @@ impl ShmBufferBacking { } } + #[tracing::instrument("debug", skip_all)] pub fn update_tex(&self, images: &mut Assets) -> Option> { let mut image_handle = self.image.lock(); images.remove(image_handle.id()); diff --git a/src/wayland/core/shm_pool.rs b/src/wayland/core/shm_pool.rs index eed91f4..c2e5120 100644 --- a/src/wayland/core/shm_pool.rs +++ b/src/wayland/core/shm_pool.rs @@ -18,6 +18,7 @@ pub struct ShmPool { } impl ShmPool { + #[tracing::instrument("debug", skip_all)] pub fn new(fd: OwnedFd, size: i32) -> Result { let map = unsafe { MmapOptions::new() @@ -30,6 +31,7 @@ impl ShmPool { }) } + #[tracing::instrument("debug", skip_all)] pub fn data_lock(&self) -> MappedMutexGuard { MutexGuard::map(self.inner.lock(), |i| i.as_mut()) } @@ -37,6 +39,7 @@ impl ShmPool { impl WlShmPool for ShmPool { /// https://wayland.app/protocols/wayland#wl_shm_pool:request:create_buffer + #[tracing::instrument("debug", skip_all)] async fn create_buffer( &self, client: &mut Client, @@ -61,6 +64,7 @@ impl WlShmPool for ShmPool { } /// https://wayland.app/protocols/wayland#wl_shm_pool:request:resize + #[tracing::instrument("debug", skip_all)] async fn resize(&self, _client: &mut Client, _sender_id: ObjectId, size: i32) -> Result<()> { let mut inner = self.inner.lock(); unsafe { inner.remap(size as usize, RemapOptions::new().may_move(true))? }; @@ -68,6 +72,7 @@ impl WlShmPool for ShmPool { } /// https://wayland.app/protocols/wayland#wl_shm_pool:request:destroy + #[tracing::instrument("debug", skip_all)] async fn destroy(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> { Ok(()) } diff --git a/src/wayland/core/surface.rs b/src/wayland/core/surface.rs index 0f94552..6001bbc 100644 --- a/src/wayland/core/surface.rs +++ b/src/wayland/core/surface.rs @@ -85,6 +85,7 @@ impl std::fmt::Debug for Surface { } } impl Surface { + #[tracing::instrument("debug", skip_all)] pub fn new(client: &Client, id: ObjectId) -> Self { Surface { id, @@ -98,10 +99,12 @@ impl Surface { } } + #[tracing::instrument("debug", skip_all)] pub fn pending_state(&self) -> parking_lot::MutexGuard<'_, DoubleBuffer> { self.state.lock() } + #[tracing::instrument("debug", skip_all)] pub fn add_commit_handler bool + Send + Sync + 'static>( &self, handler: F, @@ -110,6 +113,7 @@ impl Surface { handlers.push(Box::new(handler)); } + #[tracing::instrument("debug", skip_all)] pub fn update_graphics( &self, dmatexes: &ImportedDmatexs, @@ -156,11 +160,13 @@ impl Surface { let _ = state_lock.current().clean_lock.set(()); } + #[tracing::instrument("debug", skip_all)] pub fn apply_material(&self, model_part: &Arc) { // tracing::info!("uwu applying material"); self.pending_material_applications.add_raw(model_part) } + #[tracing::instrument("debug", skip_all)] fn apply_surface_materials(&self) { let Some(mat) = self.material.get() else { return; @@ -171,12 +177,15 @@ impl Surface { } self.pending_material_applications.clear(); } + #[tracing::instrument("debug", skip_all)] fn mark_dirty(&self) { self.state.lock().pending.clean_lock = Default::default(); } + #[tracing::instrument("debug", skip_all)] pub fn current_state(&self) -> SurfaceState { self.state.lock().current().clone() } + #[tracing::instrument("debug", skip_all)] pub fn frame_event(&self) { if let Some(callback_obj) = self.frame_callback_object.lock().take() { let _ = self.message_sink.send(Message::Frame(callback_obj)); @@ -213,6 +222,7 @@ impl Surface { } impl WlSurface for Surface { /// https://wayland.app/protocols/wayland#wl_surface:request:attach + #[tracing::instrument("debug", skip_all)] async fn attach( &self, client: &mut Client, @@ -226,6 +236,7 @@ impl WlSurface for Surface { } /// https://wayland.app/protocols/wayland#wl_surface:request:damage + #[tracing::instrument("debug", skip_all)] async fn damage( &self, _client: &mut Client, @@ -241,6 +252,7 @@ impl WlSurface for Surface { } /// https://wayland.app/protocols/wayland#wl_surface:request:frame + #[tracing::instrument("debug", skip_all)] async fn frame( &self, client: &mut Client, @@ -253,6 +265,7 @@ impl WlSurface for Surface { } /// https://wayland.app/protocols/wayland#wl_surface:request:set_opaque_region + #[tracing::instrument("debug", skip_all)] async fn set_opaque_region( &self, _client: &mut Client, @@ -264,6 +277,7 @@ impl WlSurface for Surface { } /// https://wayland.app/protocols/wayland#wl_surface:request:set_input_region + #[tracing::instrument("debug", skip_all)] async fn set_input_region( &self, _client: &mut Client, @@ -275,6 +289,7 @@ impl WlSurface for Surface { } /// https://wayland.app/protocols/wayland#wl_surface:request:commit + #[tracing::instrument("debug", skip_all)] async fn commit(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> { { let mut lock = self.state.lock(); @@ -309,6 +324,7 @@ impl WlSurface for Surface { } /// https://wayland.app/protocols/wayland#wl_surface:request:set_buffer_transform + #[tracing::instrument("debug", skip_all)] async fn set_buffer_transform( &self, _client: &mut Client, @@ -320,6 +336,7 @@ impl WlSurface for Surface { } /// https://wayland.app/protocols/wayland#wl_surface:request:set_buffer_scale + #[tracing::instrument("debug", skip_all)] async fn set_buffer_scale( &self, _client: &mut Client, @@ -331,6 +348,7 @@ impl WlSurface for Surface { } /// https://wayland.app/protocols/wayland#wl_surface:request:damage_buffer + #[tracing::instrument("debug", skip_all)] async fn damage_buffer( &self, _client: &mut Client, @@ -346,6 +364,7 @@ impl WlSurface for Surface { } /// https://wayland.app/protocols/wayland#wl_surface:request:offset + #[tracing::instrument("debug", skip_all)] async fn offset( &self, _client: &mut Client, @@ -357,6 +376,7 @@ impl WlSurface for Surface { } /// https://wayland.app/protocols/wayland#wl_surface:request:destroy + #[tracing::instrument("debug", skip_all)] async fn destroy(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> { Ok(()) } diff --git a/src/wayland/dmabuf/buffer_backing.rs b/src/wayland/dmabuf/buffer_backing.rs index 5551319..c0b64ca 100644 --- a/src/wayland/dmabuf/buffer_backing.rs +++ b/src/wayland/dmabuf/buffer_backing.rs @@ -11,6 +11,7 @@ use bevy_dmabuf::{ use drm_fourcc::DrmFourcc; use mint::Vector2; use parking_lot::Mutex; +use tracing::info; use std::sync::{Arc, OnceLock}; use waynest::server::protocol::stable::linux_dmabuf_v1::zwp_linux_buffer_params_v1::Flags; @@ -39,6 +40,7 @@ impl std::fmt::Debug for DmabufBacking { } impl DmabufBacking { + #[tracing::instrument("debug", skip_all)] pub fn new( params: Arc, message_sink: Option, @@ -74,11 +76,13 @@ impl DmabufBacking { }) } + #[tracing::instrument("debug", skip_all)] pub fn update_tex( &self, dmatexes: &ImportedDmatexs, images: &mut Assets, ) -> Option> { + info!("updating dmabuf tex"); self.pending_imported_dmatex .lock() .take() diff --git a/src/wayland/dmabuf/buffer_params.rs b/src/wayland/dmabuf/buffer_params.rs index 2755db5..e6c2cc6 100644 --- a/src/wayland/dmabuf/buffer_params.rs +++ b/src/wayland/dmabuf/buffer_params.rs @@ -30,6 +30,7 @@ pub struct BufferParams { } impl BufferParams { + #[tracing::instrument("debug", skip_all)] pub fn new(id: ObjectId) -> Self { tracing::info!("Creating new BufferParams with id {:?}", id); Self { @@ -45,6 +46,7 @@ impl ZwpLinuxBufferParamsV1 for BufferParams { Ok(()) } + #[tracing::instrument("debug", skip_all)] async fn add( &self, _client: &mut Client, @@ -89,6 +91,7 @@ impl ZwpLinuxBufferParamsV1 for BufferParams { Ok(()) } + #[tracing::instrument("debug", skip_all)] async fn create( &self, client: &mut Client, @@ -123,6 +126,7 @@ impl ZwpLinuxBufferParamsV1 for BufferParams { } } + #[tracing::instrument("debug", skip_all)] async fn create_immed( &self, client: &mut Client, @@ -150,6 +154,7 @@ impl ZwpLinuxBufferParamsV1 for BufferParams { } impl Drop for BufferParams { + #[tracing::instrument("debug", skip_all)] fn drop(&mut self) { let planes = self.planes.get_mut(); tracing::info!("BufferParams being dropped with {} planes", planes.len()); diff --git a/src/wayland/dmabuf/feedback.rs b/src/wayland/dmabuf/feedback.rs index 7b0add7..081e5b9 100644 --- a/src/wayland/dmabuf/feedback.rs +++ b/src/wayland/dmabuf/feedback.rs @@ -19,8 +19,9 @@ use waynest::{ #[derive(Debug, Dispatcher)] pub struct DmabufFeedback(pub Arc); impl DmabufFeedback { + #[tracing::instrument("debug", skip_all)] pub async fn send_params(&self, client: &mut Client, sender_id: ObjectId) -> Result<()> { - let num_formats = self.0.formats.len(); + let num_formats = dbg!(self.0.formats.len()); // Send format table first self.send_format_table(client, sender_id).await?; @@ -44,7 +45,6 @@ impl DmabufFeedback { self.tranche_target_device(client, sender_id, dev_id) .await?; - // We only have one format at index 0 let indices = (0..num_formats).flat_map(|i| i.to_ne_bytes()).collect(); self.tranche_formats(client, sender_id, indices).await?; @@ -60,6 +60,7 @@ impl DmabufFeedback { Ok(()) } + #[tracing::instrument("debug", skip_all)] pub async fn send_format_table(&self, client: &mut Client, sender_id: ObjectId) -> Result<()> { // Format + modifier pair (16 bytes): // - format: u32 @@ -74,7 +75,7 @@ impl DmabufFeedback { mfd.as_file().set_len(size as u64)?; for (format, modifier) in self.0.formats.iter() { - let format = format.clone() as u32; + let format = *format as u32; // Write the format+modifier pair mfd.as_file().write_all(&format.to_ne_bytes())?; mfd.as_file().write_all(&0_u32.to_ne_bytes())?; diff --git a/src/wayland/dmabuf/mod.rs b/src/wayland/dmabuf/mod.rs index f9ef324..88243db 100644 --- a/src/wayland/dmabuf/mod.rs +++ b/src/wayland/dmabuf/mod.rs @@ -2,15 +2,9 @@ pub mod buffer_backing; pub mod buffer_params; pub mod feedback; -use super::{ - util::ClientExt, - vulkano_data::{DMA_CAPABLE_FORMATS, VULKANO_CONTEXT}, -}; +use super::{util::ClientExt, vulkano_data::VULKANO_CONTEXT}; use crate::core::registry::Registry; -use bevy_dmabuf::{ - format_mapping::{drm_fourcc_to_vk_format, vk_format_to_drm_fourcc}, - wgpu_init::vulkan_to_wgpu, -}; +use bevy_dmabuf::{format_mapping::drm_fourcc_to_vk_format, wgpu_init::vulkan_to_wgpu}; use buffer_params::BufferParams; use drm_fourcc::DrmFourcc; use feedback::DmabufFeedback; @@ -52,19 +46,16 @@ impl Dmabuf { /// Create a new DMA-BUF interface instance pub async fn new(client: &mut Client, id: ObjectId, version: u32) -> Result { let vk = VULKANO_CONTEXT.wait(); - let formats: FxHashSet<(DrmFourcc, u64)> = DMA_CAPABLE_FORMATS + let formats: FxHashSet<(DrmFourcc, u64)> = ALL_DRM_FOURCCS .iter() - .filter(|f| { - vk_format_to_drm_fourcc((**f).into()) - .and_then(drm_fourcc_to_vk_format) - .and_then(vulkan_to_wgpu) - .is_some() - }) - .filter_map(|f| { + .copied() + .filter_map(|f| Some((f, drm_fourcc_to_vk_format(f)?))) + .filter(|(_, vk_format)| vulkan_to_wgpu(*vk_format).is_some()) + .filter_map(|(f, vk_format)| { Some(( - vk_format_to_drm_fourcc((*f).into())?, + f, vk.phys_dev - .format_properties(*f) + .format_properties(vk_format.try_into().unwrap()) .ok()? .drm_format_modifier_properties .into_iter() @@ -78,7 +69,6 @@ impl Dmabuf { dbg!(&formats); let dmabuf = Self { - // formats: Mutex::new(formats), active_params: Registry::new(), version, formats, @@ -166,3 +156,111 @@ impl ZwpLinuxDmabufV1 for Dmabuf { self.get_default_feedback(client, sender_id, id).await } } + +pub const ALL_DRM_FOURCCS: [DrmFourcc; 105] = [ + DrmFourcc::Abgr1555, + DrmFourcc::Abgr16161616f, + DrmFourcc::Abgr2101010, + DrmFourcc::Abgr4444, + DrmFourcc::Abgr8888, + DrmFourcc::Argb1555, + DrmFourcc::Argb16161616f, + DrmFourcc::Argb2101010, + DrmFourcc::Argb4444, + DrmFourcc::Argb8888, + DrmFourcc::Axbxgxrx106106106106, + DrmFourcc::Ayuv, + DrmFourcc::Bgr233, + DrmFourcc::Bgr565, + DrmFourcc::Bgr565_a8, + DrmFourcc::Bgr888, + DrmFourcc::Bgr888_a8, + DrmFourcc::Bgra1010102, + DrmFourcc::Bgra4444, + DrmFourcc::Bgra5551, + DrmFourcc::Bgra8888, + DrmFourcc::Bgrx1010102, + DrmFourcc::Bgrx4444, + DrmFourcc::Bgrx5551, + DrmFourcc::Bgrx8888, + DrmFourcc::Bgrx8888_a8, + DrmFourcc::Big_endian, + DrmFourcc::C8, + DrmFourcc::Gr1616, + DrmFourcc::Gr88, + DrmFourcc::Nv12, + DrmFourcc::Nv15, + DrmFourcc::Nv16, + DrmFourcc::Nv21, + DrmFourcc::Nv24, + DrmFourcc::Nv42, + DrmFourcc::Nv61, + DrmFourcc::P010, + DrmFourcc::P012, + DrmFourcc::P016, + DrmFourcc::P210, + DrmFourcc::Q401, + DrmFourcc::Q410, + DrmFourcc::R16, + DrmFourcc::R8, + DrmFourcc::Rg1616, + DrmFourcc::Rg88, + DrmFourcc::Rgb332, + DrmFourcc::Rgb565, + DrmFourcc::Rgb565_a8, + DrmFourcc::Rgb888, + DrmFourcc::Rgb888_a8, + DrmFourcc::Rgba1010102, + DrmFourcc::Rgba4444, + DrmFourcc::Rgba5551, + DrmFourcc::Rgba8888, + DrmFourcc::Rgbx1010102, + DrmFourcc::Rgbx4444, + DrmFourcc::Rgbx5551, + DrmFourcc::Rgbx8888, + DrmFourcc::Rgbx8888_a8, + DrmFourcc::Uyvy, + DrmFourcc::Vuy101010, + DrmFourcc::Vuy888, + DrmFourcc::Vyuy, + DrmFourcc::X0l0, + DrmFourcc::X0l2, + DrmFourcc::Xbgr1555, + DrmFourcc::Xbgr16161616f, + DrmFourcc::Xbgr2101010, + DrmFourcc::Xbgr4444, + DrmFourcc::Xbgr8888, + DrmFourcc::Xbgr8888_a8, + DrmFourcc::Xrgb1555, + DrmFourcc::Xrgb16161616f, + DrmFourcc::Xrgb2101010, + DrmFourcc::Xrgb4444, + DrmFourcc::Xrgb8888, + DrmFourcc::Xrgb8888_a8, + DrmFourcc::Xvyu12_16161616, + DrmFourcc::Xvyu16161616, + DrmFourcc::Xvyu2101010, + DrmFourcc::Xyuv8888, + DrmFourcc::Y0l0, + DrmFourcc::Y0l2, + DrmFourcc::Y210, + DrmFourcc::Y212, + DrmFourcc::Y216, + DrmFourcc::Y410, + DrmFourcc::Y412, + DrmFourcc::Y416, + DrmFourcc::Yuv410, + DrmFourcc::Yuv411, + DrmFourcc::Yuv420, + DrmFourcc::Yuv420_10bit, + DrmFourcc::Yuv420_8bit, + DrmFourcc::Yuv422, + DrmFourcc::Yuv444, + DrmFourcc::Yuyv, + DrmFourcc::Yvu410, + DrmFourcc::Yvu411, + DrmFourcc::Yvu420, + DrmFourcc::Yvu422, + DrmFourcc::Yvu444, + DrmFourcc::Yvyu, +];