move drm modifiers to WlxGraphics
This commit is contained in:
@@ -80,8 +80,8 @@ use vulkano::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use wlx_capture::frame::{
|
use wlx_capture::frame::{
|
||||||
DmabufFrame, FourCC, DRM_FORMAT_ABGR2101010, DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB8888,
|
DmabufFrame, DrmFormat, FourCC, DRM_FORMAT_ABGR2101010, DRM_FORMAT_ABGR8888,
|
||||||
DRM_FORMAT_XBGR2101010, DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888,
|
DRM_FORMAT_ARGB8888, DRM_FORMAT_XBGR2101010, DRM_FORMAT_XBGR8888, DRM_FORMAT_XRGB8888,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type Vert2Buf = Subbuffer<[Vert2Uv]>;
|
pub type Vert2Buf = Subbuffer<[Vert2Uv]>;
|
||||||
@@ -127,6 +127,7 @@ pub struct WlxGraphics {
|
|||||||
pub quad_indices: IndexBuf,
|
pub quad_indices: IndexBuf,
|
||||||
|
|
||||||
pub shared_shaders: RwLock<HashMap<&'static str, Arc<ShaderModule>>>,
|
pub shared_shaders: RwLock<HashMap<&'static str, Arc<ShaderModule>>>,
|
||||||
|
pub drm_formats: Vec<DrmFormat>,
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn get_dmabuf_extensions() -> DeviceExtensions {
|
const fn get_dmabuf_extensions() -> DeviceExtensions {
|
||||||
@@ -368,6 +369,7 @@ impl WlxGraphics {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let (quad_verts, quad_indices) = Self::default_quad(memory_allocator.clone())?;
|
let (quad_verts, quad_indices) = Self::default_quad(memory_allocator.clone())?;
|
||||||
|
let drm_formats = Self::get_drm_formats(device.clone());
|
||||||
|
|
||||||
let me = Self {
|
let me = Self {
|
||||||
instance,
|
instance,
|
||||||
@@ -381,6 +383,7 @@ impl WlxGraphics {
|
|||||||
quad_indices,
|
quad_indices,
|
||||||
quad_verts,
|
quad_verts,
|
||||||
shared_shaders: RwLock::new(HashMap::new()),
|
shared_shaders: RwLock::new(HashMap::new()),
|
||||||
|
drm_formats,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Arc::new(me))
|
Ok(Arc::new(me))
|
||||||
@@ -522,6 +525,7 @@ impl WlxGraphics {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let (quad_verts, quad_indices) = Self::default_quad(memory_allocator.clone())?;
|
let (quad_verts, quad_indices) = Self::default_quad(memory_allocator.clone())?;
|
||||||
|
let drm_formats = Self::get_drm_formats(device.clone());
|
||||||
|
|
||||||
let me = Self {
|
let me = Self {
|
||||||
instance,
|
instance,
|
||||||
@@ -535,6 +539,7 @@ impl WlxGraphics {
|
|||||||
quad_indices,
|
quad_indices,
|
||||||
quad_verts,
|
quad_verts,
|
||||||
shared_shaders: RwLock::new(HashMap::new()),
|
shared_shaders: RwLock::new(HashMap::new()),
|
||||||
|
drm_formats,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Arc::new(me))
|
Ok(Arc::new(me))
|
||||||
@@ -665,6 +670,7 @@ impl WlxGraphics {
|
|||||||
));
|
));
|
||||||
|
|
||||||
let (quad_verts, quad_indices) = Self::default_quad(memory_allocator.clone())?;
|
let (quad_verts, quad_indices) = Self::default_quad(memory_allocator.clone())?;
|
||||||
|
let drm_formats = Self::get_drm_formats(device.clone());
|
||||||
|
|
||||||
let me = Self {
|
let me = Self {
|
||||||
instance,
|
instance,
|
||||||
@@ -678,6 +684,7 @@ impl WlxGraphics {
|
|||||||
quad_indices,
|
quad_indices,
|
||||||
quad_verts,
|
quad_verts,
|
||||||
shared_shaders: RwLock::new(HashMap::new()),
|
shared_shaders: RwLock::new(HashMap::new()),
|
||||||
|
drm_formats,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((Arc::new(me), event_loop, window, surface))
|
Ok((Arc::new(me), event_loop, window, surface))
|
||||||
@@ -796,7 +803,46 @@ impl WlxGraphics {
|
|||||||
)?)
|
)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dmabuf_texture_ex(
|
fn get_drm_formats(device: Arc<Device>) -> Vec<DrmFormat> {
|
||||||
|
let possible_formats = [
|
||||||
|
DRM_FORMAT_ABGR8888.into(),
|
||||||
|
DRM_FORMAT_XBGR8888.into(),
|
||||||
|
DRM_FORMAT_ARGB8888.into(),
|
||||||
|
DRM_FORMAT_XRGB8888.into(),
|
||||||
|
DRM_FORMAT_ABGR2101010.into(),
|
||||||
|
DRM_FORMAT_XBGR2101010.into(),
|
||||||
|
];
|
||||||
|
|
||||||
|
let mut final_formats = vec![];
|
||||||
|
|
||||||
|
for &f in &possible_formats {
|
||||||
|
let Ok(vk_fmt) = fourcc_to_vk(f) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let Ok(props) = device.physical_device().format_properties(vk_fmt) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let mut fmt = DrmFormat {
|
||||||
|
fourcc: f,
|
||||||
|
modifiers: props
|
||||||
|
.drm_format_modifier_properties
|
||||||
|
.iter()
|
||||||
|
// important bit: only allow single-plane
|
||||||
|
.filter(|m| m.drm_format_modifier_plane_count == 1)
|
||||||
|
.map(|m| m.drm_format_modifier)
|
||||||
|
.collect(),
|
||||||
|
};
|
||||||
|
fmt.modifiers.push(DRM_FORMAT_MOD_INVALID); // implicit modifiers support
|
||||||
|
final_formats.push(fmt);
|
||||||
|
}
|
||||||
|
log::debug!("Supported DRM formats:");
|
||||||
|
for f in &final_formats {
|
||||||
|
log::debug!(" {} {:?}", f.fourcc, f.modifiers);
|
||||||
|
}
|
||||||
|
final_formats
|
||||||
|
}
|
||||||
|
|
||||||
|
fn dmabuf_texture_ex(
|
||||||
&self,
|
&self,
|
||||||
frame: DmabufFrame,
|
frame: DmabufFrame,
|
||||||
tiling: ImageTiling,
|
tiling: ImageTiling,
|
||||||
@@ -806,8 +852,7 @@ impl WlxGraphics {
|
|||||||
let extent = [frame.format.width, frame.format.height, 1];
|
let extent = [frame.format.width, frame.format.height, 1];
|
||||||
let format = fourcc_to_vk(frame.format.fourcc)?;
|
let format = fourcc_to_vk(frame.format.fourcc)?;
|
||||||
|
|
||||||
let image = unsafe {
|
let image = RawImage::new(
|
||||||
RawImage::new_unchecked(
|
|
||||||
self.device.clone(),
|
self.device.clone(),
|
||||||
ImageCreateInfo {
|
ImageCreateInfo {
|
||||||
format,
|
format,
|
||||||
@@ -819,8 +864,7 @@ impl WlxGraphics {
|
|||||||
drm_format_modifier_plane_layouts: layouts,
|
drm_format_modifier_plane_layouts: layouts,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
)?
|
)?;
|
||||||
};
|
|
||||||
|
|
||||||
let requirements = image.memory_requirements()[0];
|
let requirements = image.memory_requirements()[0];
|
||||||
let memory_type_index = self
|
let memory_type_index = self
|
||||||
|
|||||||
@@ -72,8 +72,6 @@ pub(crate) type WlxClientAlias = ();
|
|||||||
|
|
||||||
const CURSOR_SIZE: f32 = 16. / 1440.;
|
const CURSOR_SIZE: f32 = 16. / 1440.;
|
||||||
|
|
||||||
static DRM_FORMATS: once_cell::sync::OnceCell<Vec<DrmFormat>> = once_cell::sync::OnceCell::new();
|
|
||||||
|
|
||||||
static START: Lazy<Instant> = Lazy::new(Instant::now);
|
static START: Lazy<Instant> = Lazy::new(Instant::now);
|
||||||
static NEXT_MOVE: AtomicU64 = AtomicU64::new(0);
|
static NEXT_MOVE: AtomicU64 = AtomicU64::new(0);
|
||||||
|
|
||||||
@@ -521,59 +519,20 @@ impl OverlayRenderer for ScreenRenderer {
|
|||||||
|
|
||||||
let capture_method = app.session.config.capture_method.clone();
|
let capture_method = app.session.config.capture_method.clone();
|
||||||
|
|
||||||
let dmabuf_formats = DRM_FORMATS.get_or_init({
|
let dmabuf_formats = if !supports_dmabuf {
|
||||||
let graphics = app.graphics.clone();
|
|
||||||
move || {
|
|
||||||
if !supports_dmabuf {
|
|
||||||
log::info!("Capture method does not support DMA-buf");
|
log::info!("Capture method does not support DMA-buf");
|
||||||
return vec![];
|
&Vec::new()
|
||||||
}
|
} else if !allow_dmabuf {
|
||||||
if !allow_dmabuf {
|
|
||||||
log::info!("Not using DMA-buf capture due to {capture_method}");
|
log::info!("Not using DMA-buf capture due to {capture_method}");
|
||||||
return vec![];
|
&Vec::new()
|
||||||
}
|
} else {
|
||||||
log::warn!("Using DMA-buf capture. If screens are blank for you, switch to SHM using:");
|
log::warn!(
|
||||||
|
"Using DMA-buf capture. If screens are blank for you, switch to SHM using:"
|
||||||
|
);
|
||||||
log::warn!("echo 'capture_method: pw_fallback' > ~/.config/wlxoverlay/conf.d/pw_fallback.yaml");
|
log::warn!("echo 'capture_method: pw_fallback' > ~/.config/wlxoverlay/conf.d/pw_fallback.yaml");
|
||||||
|
|
||||||
let possible_formats = [
|
&app.graphics.drm_formats
|
||||||
DRM_FORMAT_ABGR8888.into(),
|
|
||||||
DRM_FORMAT_XBGR8888.into(),
|
|
||||||
DRM_FORMAT_ARGB8888.into(),
|
|
||||||
DRM_FORMAT_XRGB8888.into(),
|
|
||||||
DRM_FORMAT_ABGR2101010.into(),
|
|
||||||
DRM_FORMAT_XBGR2101010.into(),
|
|
||||||
];
|
|
||||||
|
|
||||||
let mut final_formats = vec![];
|
|
||||||
|
|
||||||
for &f in &possible_formats {
|
|
||||||
let Ok(vk_fmt) = fourcc_to_vk(f) else {
|
|
||||||
continue;
|
|
||||||
};
|
};
|
||||||
let Ok(props) = graphics.device.physical_device().format_properties(vk_fmt)
|
|
||||||
else {
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let mut fmt = DrmFormat {
|
|
||||||
fourcc: f,
|
|
||||||
modifiers: props
|
|
||||||
.drm_format_modifier_properties
|
|
||||||
.iter()
|
|
||||||
// important bit: only allow single-plane
|
|
||||||
.filter(|m| m.drm_format_modifier_plane_count == 1)
|
|
||||||
.map(|m| m.drm_format_modifier)
|
|
||||||
.collect(),
|
|
||||||
};
|
|
||||||
fmt.modifiers.push(DRM_FORMAT_MOD_INVALID); // implicit modifiers support
|
|
||||||
final_formats.push(fmt);
|
|
||||||
}
|
|
||||||
log::debug!("Supported DRM formats:");
|
|
||||||
for f in &final_formats {
|
|
||||||
log::debug!(" {} {:?}", f.fourcc, f.modifiers);
|
|
||||||
}
|
|
||||||
final_formats
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let user_data = WlxCaptureIn {
|
let user_data = WlxCaptureIn {
|
||||||
name: self.name.clone(),
|
name: self.name.clone(),
|
||||||
|
|||||||
@@ -623,20 +623,7 @@ impl WayVRRenderer {
|
|||||||
|
|
||||||
drop(wayvr);
|
drop(wayvr);
|
||||||
|
|
||||||
let layouts: Vec<SubresourceLayout> = vec![SubresourceLayout {
|
let tex = self.graphics.dmabuf_texture(frame)?;
|
||||||
offset: data.offset as _,
|
|
||||||
size: 0,
|
|
||||||
row_pitch: data.stride as _,
|
|
||||||
array_pitch: None,
|
|
||||||
depth_pitch: None,
|
|
||||||
}];
|
|
||||||
|
|
||||||
let tex = self.graphics.dmabuf_texture_ex(
|
|
||||||
frame,
|
|
||||||
vulkano::image::ImageTiling::DrmFormatModifier,
|
|
||||||
layouts,
|
|
||||||
&data.mod_info.modifiers,
|
|
||||||
)?;
|
|
||||||
|
|
||||||
self.vk_image = Some(tex.clone());
|
self.vk_image = Some(tex.clone());
|
||||||
self.vk_image_view = Some(vulkano::image::view::ImageView::new_default(tex).unwrap());
|
self.vk_image_view = Some(vulkano::image::view::ImageView::new_default(tex).unwrap());
|
||||||
|
|||||||
Reference in New Issue
Block a user