diff --git a/Cargo.toml b/Cargo.toml index 0a6299a..741e9dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "pinnacle" -version = "0.1.0" +version = "0.0.1" edition = "2021" license = "MPL-2.0" @@ -9,14 +9,14 @@ license = "MPL-2.0" [dependencies] tracing = "0.1.37" tracing-subscriber = { version = "0.3.17", features = ["env-filter"] } -smithay = { git = "https://github.com/Smithay/smithay", rev = "9b3d173" } +smithay = { git = "https://github.com/Smithay/smithay", rev = "ae7fb22" } smithay-drm-extras = { git = "https://github.com/Smithay/smithay", optional = true } -thiserror = "1.0.40" +thiserror = "1.0.44" xcursor = {version = "0.3.4", optional = true } -image = {version = "0.24.0", default-features = false, optional = true} -serde = { version = "1.0.164", features = ["derive"] } -rmp = { version = "0.8.11" } -rmp-serde = { version = "1.1.1" } +image = {version = "0.24.6", default-features = false, optional = true} +serde = { version = "1.0.174", features = ["derive"] } +rmp = { version = "0.8.12" } +rmp-serde = { version = "1.1.2" } calloop = { version = "0.10.1", features = ["executor", "futures-io"] } futures-lite = { version = "1.13.0" } async-process = { version = "1.7.0" } diff --git a/src/backend/udev.rs b/src/backend/udev.rs index 9821946..e8f2171 100644 --- a/src/backend/udev.rs +++ b/src/backend/udev.rs @@ -26,8 +26,9 @@ use smithay::{ Allocator, Fourcc, }, drm::{ - compositor::DrmCompositor, CreateDrmNodeError, DrmDevice, DrmDeviceFd, DrmError, - DrmEvent, DrmEventMetadata, DrmNode, DrmSurface, GbmBufferedSurface, NodeType, + compositor::{DrmCompositor, PrimaryPlaneElement}, + CreateDrmNodeError, DrmDevice, DrmDeviceFd, DrmError, DrmEvent, DrmEventMetadata, + DrmNode, DrmSurface, GbmBufferedSurface, NodeType, }, egl::{self, EGLDevice, EGLDisplay}, libinput::{LibinputInputBackend, LibinputSessionInterface}, @@ -39,6 +40,7 @@ use smithay::{ }, gles::{GlesRenderer, GlesTexture}, multigpu::{gbm::GbmGlesBackend, GpuManager, MultiRenderer, MultiTexture}, + sync::SyncPoint, Bind, ExportMem, ImportDma, ImportEgl, ImportMemWl, Offscreen, Renderer, }, session::{ @@ -80,7 +82,9 @@ use smithay::{ backend::GlobalId, protocol::wl_surface::WlSurface, Display, DisplayHandle, }, }, - utils::{Clock, DeviceFd, IsAlive, Logical, Monotonic, Point, Scale, Transform}, + utils::{ + Clock, DeviceFd, IsAlive, Logical, Monotonic, Physical, Point, Rectangle, Scale, Transform, + }, wayland::{ compositor, dmabuf::{ @@ -592,6 +596,13 @@ enum SurfaceComposition { Compositor(GbmDrmCompositor), } +struct SurfaceCompositorRenderResult { + rendered: bool, + states: RenderElementStates, + sync: Option, + damage: Option>>, +} + impl SurfaceComposition { fn frame_submitted(&mut self) -> Result, SwapBuffersError> { match self { @@ -629,11 +640,13 @@ impl SurfaceComposition { fn queue_frame( &mut self, + sync: Option, + damage: Option>>, user_data: Option, ) -> Result<(), SwapBuffersError> { match self { SurfaceComposition::Surface { surface, .. } => surface - .queue_buffer(None, user_data) + .queue_buffer(sync, damage, user_data) .map_err(Into::::into), SurfaceComposition::Compositor(c) => c .queue_frame(user_data) @@ -646,7 +659,7 @@ impl SurfaceComposition { renderer: &mut R, elements: &[E], clear_color: [f32; 4], - ) -> Result<(bool, RenderElementStates), SwapBuffersError> + ) -> Result where R: Renderer + Bind + Bind + Offscreen + ExportMem, ::TextureId: 'static, @@ -670,7 +683,16 @@ impl SurfaceComposition { let res = damage_tracker .render_output(renderer, age.into(), elements, clear_color) - .map(|(damage, states)| (damage.is_some(), states)) + .map(|res| { + res.sync.wait(); // feature flag here + let rendered = res.damage.is_some(); + SurfaceCompositorRenderResult { + rendered, + damage: res.damage, + states: res.states, + sync: rendered.then_some(res.sync), + } + }) .map_err(|err| match err { damage::Error::Rendering(err) => err.into(), _ => unreachable!(), @@ -681,10 +703,18 @@ impl SurfaceComposition { SurfaceComposition::Compositor(compositor) => compositor .render_frame(renderer, elements, clear_color) .map(|render_frame_result| { - ( - render_frame_result.damage.is_some(), - render_frame_result.states, - ) + // feature flag here + if let PrimaryPlaneElement::Swapchain(element) = + render_frame_result.primary_element + { + element.sync.wait(); + } + SurfaceCompositorRenderResult { + rendered: render_frame_result.damage.is_some(), + states: render_frame_result.states, + sync: None, + damage: None, + } }) .map_err(|err| match err { smithay::backend::drm::compositor::RenderFrameError::PrepareFrame(err) => { @@ -1518,7 +1548,7 @@ fn render_surface<'a>( .map(OutputRenderElements::Space), ); - let (rendered, states) = surface.compositor.render_frame::<_, _, GlesTexture>( + let res = surface.compositor.render_frame::<_, _, GlesTexture>( renderer, &output_render_elements, [0.6, 0.6, 0.6, 1.0], @@ -1533,7 +1563,7 @@ fn render_surface<'a>( surface, output, states_inner, - &states, + &res.states, element::default_primary_scanout_output_compare, ); @@ -1568,7 +1598,7 @@ fn render_surface<'a>( |surface, _| { select_dmabuf_feedback( surface, - &states, + &res.states, dmabuf_feedback.render_feedback, dmabuf_feedback.scanout_feedback, ) @@ -1579,15 +1609,15 @@ fn render_surface<'a>( }); } - if rendered { - let output_presentation_feedback = take_presentation_feedback(output, space, &states); + if res.rendered { + let output_presentation_feedback = take_presentation_feedback(output, space, &res.states); surface .compositor - .queue_frame(Some(output_presentation_feedback)) + .queue_frame(res.sync, res.damage, Some(output_presentation_feedback)) .map_err(Into::::into)?; } - Ok(rendered) + Ok(res.rendered) } fn initial_render( @@ -1601,7 +1631,7 @@ fn initial_render( &[], [0.6, 0.6, 0.6, 1.0], )?; - surface.compositor.queue_frame(None)?; + surface.compositor.queue_frame(None, None, None)?; surface.compositor.reset_buffers(); Ok(()) diff --git a/src/backend/winit.rs b/src/backend/winit.rs index f9ead41..d80ab3b 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -315,9 +315,9 @@ pub fn run_winit() -> Result<(), Box> { }); match render_res { - Ok((damage, states)) => { - let has_rendered = damage.is_some(); - if let Some(damage) = damage { + Ok(render_output_result) => { + let has_rendered = render_output_result.damage.is_some(); + if let Some(damage) = render_output_result.damage { if let Err(err) = state.backend_data.backend.submit(Some(&damage)) { tracing::warn!("{}", err); } @@ -337,7 +337,7 @@ pub fn run_winit() -> Result<(), Box> { surface, &output, states_inner, - &states, + &render_output_result.states, default_primary_scanout_output_compare, );