diff --git a/Cargo.toml b/Cargo.toml index bd67c48..fd0eb94 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,3 +64,4 @@ osc = ["dep:rosc"] x11 = ["wlx-capture/xshm"] wayland = ["wlx-capture/pipewire", "wlx-capture/wlr"] uidev = ["dep:winit"] +no-dmabuf = [] diff --git a/src/graphics.rs b/src/graphics.rs index cffe3bd..1cb4c4e 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -107,6 +107,11 @@ pub struct Vert2Uv { pub const INDICES: [u16; 6] = [2, 1, 0, 1, 2, 3]; +#[cfg(not(feature = "no-dmabuf"))] +pub const DMA_BUF_SUPPORTED: bool = true; +#[cfg(feature = "no-dmabuf")] +pub const DMA_BUF_SUPPORTED: bool = false; + pub const BLEND_ALPHA: AttachmentBlend = AttachmentBlend { src_color_blend_factor: BlendFactor::SrcAlpha, dst_color_blend_factor: BlendFactor::OneMinusSrcAlpha, @@ -133,6 +138,19 @@ pub struct WlxGraphics { pub shared_shaders: RwLock>>, } +fn get_device_extensions() -> DeviceExtensions { + #[cfg(not(feature = "no-dmabuf"))] + return DeviceExtensions { + khr_external_memory: true, + khr_external_memory_fd: true, + ext_external_memory_dma_buf: true, + ext_image_drm_format_modifier: true, + ..DeviceExtensions::empty() + }; + #[cfg(feature = "no-dmabuf")] + return DeviceExtensions::empty(); +} + static VULKAN_LIBRARY: OnceLock> = OnceLock::new(); fn get_vulkan_library() -> &'static Arc { VULKAN_LIBRARY.get_or_init(|| vulkano::VulkanLibrary::new().unwrap()) // want panic @@ -243,15 +261,7 @@ impl WlxGraphics { .position(|(_, q)| q.queue_flags.intersects(QueueFlags::GRAPHICS)) .expect("Vulkan device has no graphics queue") as u32; - let device_extensions = DeviceExtensions { - khr_swapchain: true, - khr_external_memory: true, - khr_external_memory_fd: true, - ext_external_memory_dma_buf: true, - ext_image_drm_format_modifier: true, - ..DeviceExtensions::empty() - }; - + let device_extensions = get_device_extensions(); let device_extensions_raw = device_extensions .into_iter() .filter_map(|(name, enabled)| { @@ -382,14 +392,7 @@ impl WlxGraphics { }, )?; - let device_extensions = DeviceExtensions { - khr_external_memory: true, - khr_external_memory_fd: true, - ext_external_memory_dma_buf: true, - ext_image_drm_format_modifier: true, - ..DeviceExtensions::empty() - }; - + let device_extensions = get_device_extensions(); log::debug!("Device exts for app: {:?}", &device_extensions); let (physical_device, my_extensions, queue_family_index) = instance @@ -517,14 +520,8 @@ impl WlxGraphics { let window = Arc::new(WindowBuilder::new().build(&event_loop).unwrap()); let surface = Surface::from_window(instance.clone(), window.clone())?; - let device_extensions = DeviceExtensions { - khr_swapchain: true, - khr_external_memory: true, - khr_external_memory_fd: true, - ext_external_memory_dma_buf: true, - ext_image_drm_format_modifier: true, - ..DeviceExtensions::empty() - }; + let mut device_extensions = get_device_extensions(); + device_extensions.khr_swapchain = true; log::debug!("Device exts for app: {:?}", &device_extensions); diff --git a/src/overlays/screen.rs b/src/overlays/screen.rs index 807b3d7..27934ce 100644 --- a/src/overlays/screen.rs +++ b/src/overlays/screen.rs @@ -44,7 +44,7 @@ use crate::{ overlay::{OverlayRenderer, OverlayState, SplitOverlayBackend}, }, config::{def_pw_tokens, PwTokenMap}, - graphics::{fourcc_to_vk, WlxCommandBuffer, WlxPipeline, WlxPipelineLegacy}, + graphics::{fourcc_to_vk, WlxCommandBuffer, WlxPipeline, WlxPipelineLegacy, DMA_BUF_SUPPORTED}, hid::{MOUSE_LEFT, MOUSE_MIDDLE, MOUSE_RIGHT}, state::{AppSession, AppState, ScreenMeta}, }; @@ -350,7 +350,7 @@ impl OverlayRenderer for ScreenRenderer { } fn render(&mut self, app: &mut AppState) -> anyhow::Result<()> { if !self.capture.is_ready() { - let supports_dmabuf = self.capture.supports_dmbuf(); + let supports_dmabuf = DMA_BUF_SUPPORTED && self.capture.supports_dmbuf(); let allow_dmabuf = &*app.session.config.capture_method != "pw_fallback" && &*app.session.config.capture_method != "screencopy"; @@ -778,7 +778,7 @@ pub fn create_screens_x11(app: &mut AppState) -> anyhow::Result