From 0d3c7ab727b321a36ffea66c461221b14bbc48d8 Mon Sep 17 00:00:00 2001 From: srdusr <99972264+srdusr@users.noreply.github.com> Date: Wed, 26 Mar 2025 00:26:00 +0200 Subject: Wire real GBM+EGL+DrmCompositor rendering for one head (GPU Phase 2) Extends the SRDWM_GPU=1 opt-in path (Phase 1, fa0c7f1) from a capability probe into an actual, working GPU render pipeline for exactly one head, per the plan this was built from the plan file. gpu.rs: probe now goes all the way through EGLContext, GlesRenderer, DrmDevice (real DRM device, separate duped fd from the existing legacy Card), and DrmOutputManager construction, returning both a GpuContext and its DrmDeviceNotifier on success. GpuContext::initialize_output drives one crtc/mode/connector through DrmOutputManager, storing the resulting GpuOutput for the render loop to find. Confirmed while reading smithay's own source directly (not assumed): DrmDevice::new's disable_connectors parameter is not an atomic-vs- legacy switch - DrmDevice::create_internal tries atomic capability first and falls back to a Legacy internal variant automatically, exposed via DrmDevice::is_atomic(), logged here rather than assumed. platform.rs: probes at startup, calls initialize_output for the first head only (Phase 2's deliberate scope - see the plan), registers the DrmDeviceNotifier as its own calloop event source alongside (not replacing) the existing legacy DRM-fd registration. render.rs: render_udev_frame's per-head loop checks, before any of the existing Pixman-specific element-building logic runs, whether this head's crtc matches the GPU context's initialized output; if so, renders a plain clear color through render_frame/queue_frame and continues to the next head, completely bypassing the Pixman path for that head. Every other head, and this same head whenever the GPU context or its output is absent, is entirely unaffected. session.rs: register_gpu_drm_notifier handles DrmEvent::VBlank by calling frame_submitted() on the matching GpuOutput (required per queue_frame's own doc comment, or the swapchain runs out of buffers) and logs DrmEvent::Error without treating it as fatal. Deliberately out of scope for this phase (documented in the plan): window content/decorations/cursor on the GPU head (clear color only), multi-monitor GPU rendering (one head only), and VT-switch pause/ resume for the GPU head specifically (DrmOutputManager's own pause()/ activate() calls are a different API surface from the existing manual set_crtc+DPMS reassertion, and porting that pairing correctly needs its own isolated verification pass). SRDWM_GPU unset (the default) is unaffected: every step above only runs when it's set to "1", and every failure at any step falls back to the existing, untouched Pixman path with a logged reason, same fallback contract Phase 1 already established. --- crates/wayland/src/udev/platform.rs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'crates/wayland/src/udev/platform.rs') diff --git a/crates/wayland/src/udev/platform.rs b/crates/wayland/src/udev/platform.rs index 3f25c2e..6826cde 100644 --- a/crates/wayland/src/udev/platform.rs +++ b/crates/wayland/src/udev/platform.rs @@ -1,6 +1,6 @@ use super::*; use super::drm::{bring_up_head, pick_crtc, probe_connected}; -use super::session::{register_drm_fd, register_libinput, register_session_notifier, register_udev_monitor}; +use super::session::{register_drm_fd, register_gpu_drm_notifier, register_libinput, register_session_notifier, register_udev_monitor}; pub struct UdevPlatform { event_loop: EventLoop<'static, CompState>, @@ -39,8 +39,15 @@ impl UdevPlatform { // Opt-in only (`SRDWM_GPU=1`, unset by default) - see `gpu::probe`'s // own doc comment for exactly what this does and does not do yet. // A no-op unless that variable is set, so this line changes nothing - // about any session that doesn't set it. - let _gpu_probe = super::gpu::probe(&card); + // about any session that doesn't set it. `gpu_notifier` is + // registered as its own calloop event source further down + // (alongside `register_drm_fd`'s own registration for the + // existing legacy heads); `gpu_context` is stored on `UdevState` + // below and consulted by `render_udev_frame`. + let (mut gpu_context, gpu_notifier) = match super::gpu::probe(&card) { + Some((ctx, notifier)) => (Some(ctx), Some(notifier)), + None => (None, None), + }; // Every connected connector becomes a head, laid out left-to-right. let connected = probe_connected(&card)?; @@ -94,6 +101,15 @@ impl UdevPlatform { // `WaylandPlatform::connect` for why this isn't optional. smithay::wayland::output::OutputManagerState::new_with_xdg_output::(&display_handle); + // Phase 2 of the GPU-rendering plan (`gpu.rs`'s own module doc + // comment) only ever targets one head - the first, same as the + // pointer-centring choice just above - not every head at once. + // A no-op whenever `gpu_context` is `None` (every session that + // doesn't set `SRDWM_GPU=1`, or where `gpu::probe` itself failed). + if let Some(ctx) = gpu_context.as_mut() { + ctx.initialize_output(first.crtc, first.mode, first.connector, &first.output); + } + let compositor_state = CompositorState::new::(&display_handle); let xdg_shell_state = XdgShellState::new::(&display_handle); let xdg_decoration_state = XdgDecorationState::new::(&display_handle); @@ -136,6 +152,7 @@ impl UdevPlatform { disabled_connectors: std::collections::HashSet::new(), last_rendered_workspace: None, last_rendered_layout: None, + gpu: gpu_context, }; let mut state = CompState { @@ -275,6 +292,17 @@ impl UdevPlatform { let handle = event_loop.handle(); register_drm_fd(&handle, &card)?; + // Only when `SRDWM_GPU=1` and `gpu::probe` succeeded - see + // `register_gpu_drm_notifier`'s own doc comment. A failure here + // (this specific registration, not the probe itself) is logged, + // not fatal: the GPU head just never gets a `frame_submitted()` + // call and its swapchain eventually stalls, no worse than the + // probe never having succeeded at all. + if let Some(gpu_notifier) = gpu_notifier { + if let Err(e) = register_gpu_drm_notifier(&handle, gpu_notifier) { + log::warn!("udev: SRDWM_GPU=1 but failed to register the GPU DRM notifier: {e}"); + } + } let libinput_handle = register_libinput(&handle, &session, &seat_name)?; register_session_notifier(&handle, notifier, libinput_handle)?; if let Err(e) = register_udev_monitor(&handle, &seat_name) { -- cgit v1.2.3