Add debug flag to wait for frame completion
Browse files at this commit092095ead005ff073344b723f00b08a5b845f186Parent: ef119755 changed files +28 -10
- src/backend/mod.rs +4 -2
- src/backend/tty.rs +9 -5
- src/backend/winit.rs +7 -0
- src/config.rs +3 -0
- src/niri.rs +5 -3
src/backend/mod.rsmodified+4 -2
| @@ -7,6 +7,7 @@ use smithay::backend::renderer::gles::GlesRenderer; | ||
| 7 | 7 | use smithay::output::Output; |
| 8 | 8 | use smithay::wayland::dmabuf::DmabufFeedback; |
| 9 | 9 | |
| 10 | +use crate::config::Config; | |
| 10 | 11 | use crate::input::CompositorMod; |
| 11 | 12 | use crate::niri::OutputRenderElements; |
| 12 | 13 | use crate::Niri; |
| @@ -46,13 +47,14 @@ impl Backend { | ||
| 46 | 47 | |
| 47 | 48 | pub fn render( |
| 48 | 49 | &mut self, |
| 50 | + config: &Config, | |
| 49 | 51 | niri: &mut Niri, |
| 50 | 52 | output: &Output, |
| 51 | 53 | elements: &[OutputRenderElements<GlesRenderer>], |
| 52 | 54 | ) -> Option<&DmabufFeedback> { |
| 53 | 55 | match self { |
| 54 | - Backend::Tty(tty) => tty.render(niri, output, elements), | |
| 55 | - Backend::Winit(winit) => winit.render(niri, output, elements), | |
| 56 | + Backend::Tty(tty) => tty.render(config, niri, output, elements), | |
| 57 | + Backend::Winit(winit) => winit.render(config, niri, output, elements), | |
| 56 | 58 | } |
| 57 | 59 | } |
| 58 | 60 |
src/backend/tty.rsmodified+9 -5
| @@ -8,7 +8,7 @@ use anyhow::{anyhow, Context}; | ||
| 8 | 8 | use smithay::backend::allocator::dmabuf::Dmabuf; |
| 9 | 9 | use smithay::backend::allocator::gbm::{GbmAllocator, GbmBufferFlags, GbmDevice}; |
| 10 | 10 | use smithay::backend::allocator::{Format as DrmFormat, Fourcc}; |
| 11 | -use smithay::backend::drm::compositor::DrmCompositor; | |
| 11 | +use smithay::backend::drm::compositor::{DrmCompositor, PrimaryPlaneElement}; | |
| 12 | 12 | use smithay::backend::drm::{DrmDevice, DrmDeviceFd, DrmEvent, DrmEventTime}; |
| 13 | 13 | use smithay::backend::egl::{EGLContext, EGLDisplay}; |
| 14 | 14 | use smithay::backend::libinput::{LibinputInputBackend, LibinputSessionInterface}; |
| @@ -33,6 +33,7 @@ use smithay::wayland::dmabuf::{DmabufFeedbackBuilder, DmabufGlobal, DmabufState, | ||
| 33 | 33 | use smithay_drm_extras::drm_scanner::{DrmScanEvent, DrmScanner}; |
| 34 | 34 | use smithay_drm_extras::edid::EdidInfo; |
| 35 | 35 | |
| 36 | +use crate::config::Config; | |
| 36 | 37 | use crate::niri::{OutputRenderElements, State}; |
| 37 | 38 | use crate::utils::get_monotonic_time; |
| 38 | 39 | use crate::{LoopData, Niri}; |
| @@ -626,6 +627,7 @@ impl Tty { | ||
| 626 | 627 | |
| 627 | 628 | pub fn render( |
| 628 | 629 | &mut self, |
| 630 | + config: &Config, | |
| 629 | 631 | niri: &mut Niri, |
| 630 | 632 | output: &Output, |
| 631 | 633 | elements: &[OutputRenderElements<GlesRenderer>], |
| @@ -645,10 +647,12 @@ impl Tty { | ||
| 645 | 647 | Ok(res) => { |
| 646 | 648 | assert!(!res.needs_sync()); |
| 647 | 649 | |
| 648 | - // if let PrimaryPlaneElement::Swapchain(element) = res.primary_element { | |
| 649 | - // let _span = tracy_client::span!("wait for sync"); | |
| 650 | - // element.sync.wait(); | |
| 651 | - // } | |
| 650 | + if config.debug.wait_for_frame_completion_before_queueing { | |
| 651 | + if let PrimaryPlaneElement::Swapchain(element) = res.primary_element { | |
| 652 | + let _span = tracy_client::span!("wait for completion"); | |
| 653 | + element.sync.wait(); | |
| 654 | + } | |
| 655 | + } | |
| 652 | 656 | |
| 653 | 657 | if res.damage.is_some() { |
| 654 | 658 | let presentation_feedbacks = |
src/backend/winit.rsmodified+7 -0
| @@ -15,6 +15,7 @@ use smithay::reexports::winit::window::WindowBuilder; | ||
| 15 | 15 | use smithay::utils::Transform; |
| 16 | 16 | use smithay::wayland::dmabuf::DmabufFeedback; |
| 17 | 17 | |
| 18 | +use crate::config::Config; | |
| 18 | 19 | use crate::niri::OutputRenderElements; |
| 19 | 20 | use crate::utils::get_monotonic_time; |
| 20 | 21 | use crate::{LoopData, Niri}; |
| @@ -136,6 +137,7 @@ impl Winit { | ||
| 136 | 137 | |
| 137 | 138 | pub fn render( |
| 138 | 139 | &mut self, |
| 140 | + config: &Config, | |
| 139 | 141 | niri: &mut Niri, |
| 140 | 142 | output: &Output, |
| 141 | 143 | elements: &[OutputRenderElements<GlesRenderer>], |
| @@ -149,6 +151,11 @@ impl Winit { | ||
| 149 | 151 | .render_output(self.backend.renderer(), age, elements, [0.1, 0.1, 0.1, 1.0]) |
| 150 | 152 | .unwrap(); |
| 151 | 153 | if let Some(damage) = res.damage { |
| 154 | + if config.debug.wait_for_frame_completion_before_queueing { | |
| 155 | + let _span = tracy_client::span!("wait for completion"); | |
| 156 | + res.sync.wait(); | |
| 157 | + } | |
| 158 | + | |
| 152 | 159 | self.backend.submit(Some(&damage)).unwrap(); |
| 153 | 160 | |
| 154 | 161 | let mut presentation_feedbacks = niri.take_presentation_feedbacks(output, &res.states); |
src/config.rsmodified+3 -0
| @@ -130,6 +130,8 @@ pub struct DebugConfig { | ||
| 130 | 130 | pub animation_slowdown: f64, |
| 131 | 131 | #[knuffel(child)] |
| 132 | 132 | pub screen_cast_in_non_session_instances: bool, |
| 133 | + #[knuffel(child)] | |
| 134 | + pub wait_for_frame_completion_before_queueing: bool, | |
| 133 | 135 | } |
| 134 | 136 | |
| 135 | 137 | impl Default for DebugConfig { |
| @@ -137,6 +139,7 @@ impl Default for DebugConfig { | ||
| 137 | 139 | Self { |
| 138 | 140 | animation_slowdown: 1., |
| 139 | 141 | screen_cast_in_non_session_instances: false, |
| 142 | + wait_for_frame_completion_before_queueing: false, | |
| 140 | 143 | } |
| 141 | 144 | } |
| 142 | 145 | } |
src/niri.rsmodified+5 -3
| @@ -690,7 +690,9 @@ impl Niri { | ||
| 690 | 690 | // Timer::immediate() adds a millisecond of delay for some reason. |
| 691 | 691 | // This should be fixed in calloop v0.11: https://github.com/Smithay/calloop/issues/142 |
| 692 | 692 | let idle = self.event_loop.insert_idle(move |data| { |
| 693 | - data.state.niri.redraw(&mut data.state.backend, &output); | |
| 693 | + data.state | |
| 694 | + .niri | |
| 695 | + .redraw(&data.state.config, &mut data.state.backend, &output); | |
| 694 | 696 | }); |
| 695 | 697 | state.queued_redraw = Some(idle); |
| 696 | 698 | } |
| @@ -835,7 +837,7 @@ impl Niri { | ||
| 835 | 837 | elements |
| 836 | 838 | } |
| 837 | 839 | |
| 838 | - fn redraw(&mut self, backend: &mut Backend, output: &Output) { | |
| 840 | + fn redraw(&mut self, config: &Config, backend: &mut Backend, output: &Output) { | |
| 839 | 841 | let _span = tracy_client::span!("Niri::redraw"); |
| 840 | 842 | |
| 841 | 843 | let state = self.output_state.get_mut(output).unwrap(); |
| @@ -852,7 +854,7 @@ impl Niri { | ||
| 852 | 854 | let elements = self.render(backend.renderer(), output); |
| 853 | 855 | |
| 854 | 856 | // Hand it over to the backend. |
| 855 | - let dmabuf_feedback = backend.render(self, output, &elements); | |
| 857 | + let dmabuf_feedback = backend.render(config, self, output, &elements); | |
| 856 | 858 | |
| 857 | 859 | // Send the dmabuf feedbacks. |
| 858 | 860 | if let Some(feedback) = dmabuf_feedback { |