From ca6e3891af82f8b8c5b57f402dbb06a52dade044 Mon Sep 17 00:00:00 2001 From: Julian Orth Date: Tue, 24 Feb 2026 19:56:51 +0100 Subject: [PATCH] gfx-api: add GfxApi --- src/backend.rs | 4 +-- src/backends/metal/video.rs | 3 +- src/backends/x.rs | 5 +-- src/compositor.rs | 7 ++--- src/config/handler.rs | 5 +++ src/gfx_api.rs | 48 ++++++++++++++++++++++++++++- src/gfx_apis.rs | 4 +-- src/gfx_apis/gl/renderer/context.rs | 6 ++-- src/gfx_apis/vulkan.rs | 3 +- src/ifs/jay_randr.rs | 7 ++--- src/it/test_gfx_api.rs | 3 +- src/portal/ptl_display.rs | 3 +- src/state.rs | 9 ++---- src/utils.rs | 1 - src/utils/gfx_api_ext.rs | 25 --------------- 15 files changed, 72 insertions(+), 61 deletions(-) delete mode 100644 src/utils/gfx_api_ext.rs diff --git a/src/backend.rs b/src/backend.rs index fd733270..ddfc98c0 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -9,7 +9,7 @@ use { drm_feedback::DrmFeedback, fixed::Fixed, format::Format, - gfx_api::{GfxFramebuffer, SyncFile}, + gfx_api::{GfxApi, GfxFramebuffer, SyncFile}, ifs::{ wl_output::OutputId, wl_seat::{ @@ -28,7 +28,7 @@ use { HDMI_EOTF_TRADITIONAL_GAMMA_SDR, }, }, - jay_config::{input::SwitchEvent, video::GfxApi}, + jay_config::input::SwitchEvent, linearize::Linearize, std::{ any::Any, diff --git a/src/backends/metal/video.rs b/src/backends/metal/video.rs index 8509b0bf..a8a1e720 100644 --- a/src/backends/metal/video.rs +++ b/src/backends/metal/video.rs @@ -26,7 +26,7 @@ use { drm_feedback::DrmFeedback, edid::{CtaDataBlock, Descriptor, EdidExtension}, format::{Format, XRGB8888}, - gfx_api::{GfxContext, GfxFramebuffer, SyncFile}, + gfx_api::{GfxApi, GfxContext, GfxFramebuffer, SyncFile}, ifs::{ wl_output::OutputId, wp_presentation_feedback::{KIND_HW_COMPLETION, KIND_VSYNC, KIND_ZERO_COPY}, @@ -57,7 +57,6 @@ use { bstr::{BString, ByteSlice}, indexmap::{IndexSet, indexset}, isnt::std_1::collections::IsntHashMapExt, - jay_config::video::GfxApi, std::{ cell::{Cell, OnceCell, RefCell}, collections::hash_map::Entry, diff --git a/src/backends/x.rs b/src/backends/x.rs index 866f8a08..f338c446 100644 --- a/src/backends/x.rs +++ b/src/backends/x.rs @@ -17,7 +17,9 @@ use { cmm::cmm_primaries::Primaries, fixed::Fixed, format::{Format, XRGB8888}, - gfx_api::{AcquireSync, GfxContext, GfxError, GfxFramebuffer, GfxTexture, ReleaseSync}, + gfx_api::{ + AcquireSync, GfxApi, GfxContext, GfxError, GfxFramebuffer, GfxTexture, ReleaseSync, + }, ifs::wl_output::OutputId, state::State, time::Time, @@ -57,7 +59,6 @@ use { }, }, ahash::AHashMap, - jay_config::video::GfxApi, std::{ any::Any, borrow::Cow, diff --git a/src/compositor.rs b/src/compositor.rs index 28901c13..15550c80 100644 --- a/src/compositor.rs +++ b/src/compositor.rs @@ -28,6 +28,7 @@ use { ei::ei_client::EiClients, forker, format::XRGB8888, + gfx_api::GfxApi, globals::Globals, ifs::{ head_management::{ @@ -81,11 +82,7 @@ use { }, ahash::AHashSet, forker::ForkerProxy, - jay_config::{ - _private::DEFAULT_SEAT_NAME, - video::{GfxApi, Transform}, - workspace::WorkspaceDisplayOrder, - }, + jay_config::{_private::DEFAULT_SEAT_NAME, video::Transform, workspace::WorkspaceDisplayOrder}, std::{ cell::{Cell, RefCell}, env, diff --git a/src/config/handler.rs b/src/config/handler.rs index e9fdd404..042af16b 100644 --- a/src/config/handler.rs +++ b/src/config/handler.rs @@ -954,6 +954,9 @@ impl ConfigProxyHandler { } fn handle_set_gfx_api(&self, device: Option, api: GfxApi) -> Result<(), CphError> { + let Ok(api) = api.try_into() else { + return Err(CphError::UnknownGfxApi(api)); + }; match device { Some(dev) => self.get_drm_device(dev)?.dev.set_gfx_api(api), _ => self.state.default_gfx_api.set(api), @@ -3532,6 +3535,8 @@ enum CphError { UnknownBlendSpace(ConfigBlendSpace), #[error("Unknown bar position {0:?}")] UnknownBarPosition(BarPosition), + #[error("Unknown gfx API {0:?}")] + UnknownGfxApi(GfxApi), } trait WithRequestName { diff --git a/src/gfx_api.rs b/src/gfx_api.rs index cb4f6643..d5104b60 100644 --- a/src/gfx_api.rs +++ b/src/gfx_api.rs @@ -18,7 +18,8 @@ use { }, ahash::AHashMap, indexmap::{IndexMap, IndexSet}, - jay_config::video::{GfxApi, Transform}, + jay_config::video::{GfxApi as ConfigGfxApi, Transform}, + linearize::Linearize, std::{ any::Any, cell::Cell, @@ -33,6 +34,51 @@ use { uapi::OwnedFd, }; +#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Linearize)] +pub enum GfxApi { + OpenGl, + Vulkan, +} + +impl TryFrom for GfxApi { + type Error = (); + + fn try_from(value: ConfigGfxApi) -> Result { + let v = match value { + ConfigGfxApi::OpenGl => GfxApi::OpenGl, + ConfigGfxApi::Vulkan => GfxApi::Vulkan, + _ => return Err(()), + }; + Ok(v) + } +} + +impl Into for GfxApi { + fn into(self) -> ConfigGfxApi { + match self { + GfxApi::OpenGl => ConfigGfxApi::OpenGl, + GfxApi::Vulkan => ConfigGfxApi::Vulkan, + } + } +} + +impl GfxApi { + pub fn to_str(&self) -> &'static str { + match self { + GfxApi::OpenGl => "OpenGl", + GfxApi::Vulkan => "Vulkan", + } + } + + pub fn from_str_lossy(s: &str) -> Option { + match &*s.to_ascii_lowercase() { + "opengl" => Some(Self::OpenGl), + "vulkan" => Some(Self::Vulkan), + _ => None, + } + } +} + pub enum GfxApiOpt { Sync, FillRect(FillRect), diff --git a/src/gfx_apis.rs b/src/gfx_apis.rs index 261b0b1b..f0d1aaa2 100644 --- a/src/gfx_apis.rs +++ b/src/gfx_apis.rs @@ -2,13 +2,12 @@ pub use vulkan::create_vulkan_allocator; use { crate::{ async_engine::AsyncEngine, - gfx_api::{GfxContext, GfxError}, + gfx_api::{GfxApi, GfxContext, GfxError}, io_uring::IoUring, pr_caps::PrCapsThread, utils::errorfmt::ErrorFmt, video::drm::Drm, }, - jay_config::video::GfxApi, std::rc::Rc, }; @@ -57,6 +56,5 @@ fn create_gfx_context_( match api { GfxApi::OpenGl => gl::create_gfx_context(drm, software), GfxApi::Vulkan => vulkan::create_graphics_context(eng, ring, drm, caps_thread, software), - _ => unreachable!(), } } diff --git a/src/gfx_apis/gl/renderer/context.rs b/src/gfx_apis/gl/renderer/context.rs index 17441ea3..7c50214f 100644 --- a/src/gfx_apis/gl/renderer/context.rs +++ b/src/gfx_apis/gl/renderer/context.rs @@ -4,8 +4,9 @@ use { cpu_worker::CpuWorker, format::{Format, XRGB8888}, gfx_api::{ - AsyncShmGfxTexture, BufferResvUser, GfxBlendBuffer, GfxContext, GfxError, GfxFormat, - GfxFramebuffer, GfxImage, GfxInternalFramebuffer, ResetStatus, ShmGfxTexture, + AsyncShmGfxTexture, BufferResvUser, GfxApi, GfxBlendBuffer, GfxContext, GfxError, + GfxFormat, GfxFramebuffer, GfxImage, GfxInternalFramebuffer, ResetStatus, + ShmGfxTexture, }, gfx_apis::gl::{ GfxGlState, RenderError, Texture, @@ -24,7 +25,6 @@ use { }, }, ahash::AHashMap, - jay_config::video::GfxApi, linearize::{Linearize, StaticMap, static_map}, std::{ cell::{Cell, RefCell}, diff --git a/src/gfx_apis/vulkan.rs b/src/gfx_apis/vulkan.rs index 36662e47..90928525 100644 --- a/src/gfx_apis/vulkan.rs +++ b/src/gfx_apis/vulkan.rs @@ -30,7 +30,7 @@ use { cpu_worker::{CpuWorker, jobs::read_write::ReadWriteJobError}, format::Format, gfx_api::{ - AsyncShmGfxTexture, GfxBlendBuffer, GfxBuffer, GfxContext, GfxError, GfxFormat, + AsyncShmGfxTexture, GfxApi, GfxBlendBuffer, GfxBuffer, GfxContext, GfxError, GfxFormat, GfxImage, GfxInternalFramebuffer, GfxStagingBuffer, GfxTexture, ResetStatus, STAGING_DOWNLOAD, STAGING_UPLOAD, ShmGfxTexture, StagingBufferUsecase, }, @@ -51,7 +51,6 @@ use { ahash::AHashMap, ash::vk, gpu_alloc::{AllocationError, MapError}, - jay_config::video::GfxApi, log::Level, std::{ cell::Cell, diff --git a/src/ifs/jay_randr.rs b/src/ifs/jay_randr.rs index 64915be9..f80d15e9 100644 --- a/src/ifs/jay_randr.rs +++ b/src/ifs/jay_randr.rs @@ -4,18 +4,17 @@ use { client::{Client, ClientError}, compositor::MAX_EXTENTS, format::named_formats, + gfx_api::GfxApi, ifs::wl_output, leaks::Tracker, object::{Object, Version}, scale::Scale, state::{ConnectorData, DrmDevData, OutputData, State}, tree::{OutputNode, TearingMode, VrrMode}, - utils::{errorfmt::ErrorFmt, gfx_api_ext::GfxApiExt, transform_ext::TransformExt}, + utils::{errorfmt::ErrorFmt, transform_ext::TransformExt}, wire::{JayRandrId, jay_randr::*}, }, - jay_config::video::{ - GfxApi, TearingMode as ConfigTearingMode, Transform, VrrMode as ConfigVrrMode, - }, + jay_config::video::{TearingMode as ConfigTearingMode, Transform, VrrMode as ConfigVrrMode}, linearize::LinearizeExt, std::rc::Rc, thiserror::Error, diff --git a/src/it/test_gfx_api.rs b/src/it/test_gfx_api.rs index 44993212..9d225aef 100644 --- a/src/it/test_gfx_api.rs +++ b/src/it/test_gfx_api.rs @@ -6,7 +6,7 @@ use { format::{ARGB8888, Format, XRGB8888}, gfx_api::{ AcquireSync, AsyncShmGfxTexture, AsyncShmGfxTextureCallback, CopyTexture, FillRect, - FramebufferRect, GfxApiOpt, GfxBlendBuffer, GfxContext, GfxError, GfxFormat, + FramebufferRect, GfxApi, GfxApiOpt, GfxBlendBuffer, GfxContext, GfxError, GfxFormat, GfxFramebuffer, GfxImage, GfxInternalFramebuffer, GfxStagingBuffer, GfxTexture, GfxWriteModifier, PendingShmTransfer, ReleaseSync, ResetStatus, ShmGfxTexture, ShmMemory, SyncFile, @@ -17,7 +17,6 @@ use { }, ahash::AHashMap, indexmap::IndexSet, - jay_config::video::GfxApi, std::{ any::Any, cell::{Cell, RefCell}, diff --git a/src/portal/ptl_display.rs b/src/portal/ptl_display.rs index e52e2e0c..2c59eeb4 100644 --- a/src/portal/ptl_display.rs +++ b/src/portal/ptl_display.rs @@ -1,6 +1,6 @@ use { crate::{ - gfx_api::{GfxFormat, cross_intersect_formats}, + gfx_api::{GfxApi, GfxFormat, cross_intersect_formats}, gfx_apis::create_gfx_context, ifs::wl_seat::POINTER, object::Version, @@ -46,7 +46,6 @@ use { }, }, ahash::AHashMap, - jay_config::video::GfxApi, std::{ cell::{Cell, RefCell}, ops::Deref, diff --git a/src/state.rs b/src/state.rs index 1e03be08..e349bd3f 100644 --- a/src/state.rs +++ b/src/state.rs @@ -31,7 +31,7 @@ use { forker::ForkerProxy, format::Format, gfx_api::{ - AcquireSync, AlphaMode, BufferResv, GfxBlendBuffer, GfxContext, GfxError, + AcquireSync, AlphaMode, BufferResv, GfxApi, GfxBlendBuffer, GfxContext, GfxError, GfxFramebuffer, GfxTexture, PendingShmTransfer, ReleaseSync, STAGING_DOWNLOAD, SampleRect, SyncFile, }, @@ -135,12 +135,7 @@ use { }, ahash::AHashMap, bstr::ByteSlice, - jay_config::{ - PciId, - video::{GfxApi, Transform}, - window::TileState, - workspace::WorkspaceDisplayOrder, - }, + jay_config::{PciId, video::Transform, window::TileState, workspace::WorkspaceDisplayOrder}, std::{ cell::{Cell, RefCell}, fmt::{Debug, Formatter}, diff --git a/src/utils.rs b/src/utils.rs index 46356d09..55e1df56 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -21,7 +21,6 @@ pub mod event_listener; pub mod fdcloser; pub mod free_list; pub mod geometric_decay; -pub mod gfx_api_ext; pub mod hash_map_ext; pub mod line_logger; pub mod linkedlist; diff --git a/src/utils/gfx_api_ext.rs b/src/utils/gfx_api_ext.rs deleted file mode 100644 index 4dd7fc0d..00000000 --- a/src/utils/gfx_api_ext.rs +++ /dev/null @@ -1,25 +0,0 @@ -use jay_config::video::GfxApi; - -pub trait GfxApiExt: Sized { - fn to_str(&self) -> &'static str; - - fn from_str_lossy(s: &str) -> Option; -} - -impl GfxApiExt for GfxApi { - fn to_str(&self) -> &'static str { - match self { - GfxApi::OpenGl => "OpenGl", - GfxApi::Vulkan => "Vulkan", - _ => "unknown", - } - } - - fn from_str_lossy(s: &str) -> Option { - match &*s.to_ascii_lowercase() { - "opengl" => Some(Self::OpenGl), - "vulkan" => Some(Self::Vulkan), - _ => None, - } - } -}