feat: no-dmabuf feature (#33)

This commit is contained in:
galister
2024-04-16 02:43:52 +02:00
committed by GitHub
parent 461657e4c3
commit f2a5ec0c37
3 changed files with 26 additions and 28 deletions

View File

@@ -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<HashMap<&'static str, Arc<ShaderModule>>>,
}
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<Arc<vulkano::VulkanLibrary>> = OnceLock::new();
fn get_vulkan_library() -> &'static Arc<vulkano::VulkanLibrary> {
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);

View File

@@ -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<ScreenCreateData
let renderer = ScreenRenderer::new_xshm(s.clone());
log::info!(
"{}: Init screen of res {:?} at {:?}",
"{}: Init X11 screen of res {:?} at {:?}",
s.name.clone(),
size,
pos,