Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dmabuf v6 #1430

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ renderer_glow = ["renderer_gl", "glow"]
renderer_multi = ["backend_drm"]
renderer_pixman = ["pixman"]
renderer_test = []
use_system_lib = ["wayland_frontend", "wayland-backend/server_system", "wayland-sys", "gbm?/import-wayland"]
use_system_lib = ["wayland_frontend", "wayland-backend/server_system", "wayland-sys"]
use_bindgen = ["drm-ffi/use_bindgen", "gbm/use_bindgen", "input/use_bindgen"]
wayland_frontend = ["wayland-server", "wayland-protocols", "wayland-protocols-wlr", "wayland-protocols-misc", "tempfile"]
x11rb_event_source = ["x11rb"]
Expand Down Expand Up @@ -140,3 +140,15 @@ harness = false
[profile.release-with-debug]
inherits = "release"
debug = true

[patch.crates-io]
wayland-egl = { git = "https://github.com/Drakulix/wayland-rs", branch = "multi-gpu-dmabuf" }
wayland-protocols = { git = "https://github.com/Drakulix/wayland-rs", branch = "multi-gpu-dmabuf" }
wayland-protocols-wlr = { git = "https://github.com/Drakulix/wayland-rs", branch = "multi-gpu-dmabuf" }
wayland-protocols-misc = { git = "https://github.com/Drakulix/wayland-rs", branch = "multi-gpu-dmabuf" }
wayland-server = { git = "https://github.com/Drakulix/wayland-rs", branch = "multi-gpu-dmabuf" }
wayland-cursor = { git = "https://github.com/Drakulix/wayland-rs", branch = "multi-gpu-dmabuf" }
wayland-client = { git = "https://github.com/Drakulix/wayland-rs", branch = "multi-gpu-dmabuf" }
wayland-sys = { git = "https://github.com/Drakulix/wayland-rs", branch = "multi-gpu-dmabuf" }
wayland-backend = { git = "https://github.com/Drakulix/wayland-rs", branch = "multi-gpu-dmabuf" }
wayland-scanner = { git = "https://github.com/Drakulix/wayland-rs", branch = "multi-gpu-dmabuf" }
18 changes: 14 additions & 4 deletions anvil/src/udev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ impl DmabufHandler for AnvilState<UdevData> {
.and_then(|mut renderer| renderer.import_dmabuf(&dmabuf, None))
.is_ok()
{
dmabuf.set_node(self.backend_data.primary_gpu);
if dmabuf.node().is_none() {
dmabuf.set_node(self.backend_data.primary_gpu);
}
let _ = notifier.successful::<AnvilState<UdevData>>();
} else {
notifier.failed();
Expand Down Expand Up @@ -831,17 +833,25 @@ fn get_surface_dmabuf_feedback(
let builder = DmabufFeedbackBuilder::new(primary_gpu.dev_id(), primary_formats);
let render_feedback = builder
.clone()
.add_preference_tranche(render_node.dev_id(), None, render_formats.clone())
.add_preference_tranche(
render_node.dev_id(),
zwp_linux_dmabuf_feedback_v1::TrancheFlags::Sampling,
render_formats.clone(),
)
.build()
.unwrap();

let scanout_feedback = builder
.add_preference_tranche(
surface.device_fd().dev_id().unwrap(),
Some(zwp_linux_dmabuf_feedback_v1::TrancheFlags::Scanout),
zwp_linux_dmabuf_feedback_v1::TrancheFlags::Scanout,
planes_formats,
)
.add_preference_tranche(render_node.dev_id(), None, render_formats)
.add_preference_tranche(
render_node.dev_id(),
zwp_linux_dmabuf_feedback_v1::TrancheFlags::Sampling,
render_formats,
)
.build()
.unwrap();

Expand Down
2 changes: 2 additions & 0 deletions src/backend/drm/gbm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ pub fn framebuffer_from_wayland_buffer<A: AsFd + 'static>(
}
}

/*
#[cfg(all(feature = "backend_egl", feature = "use_system_lib"))]
if matches!(
crate::backend::renderer::buffer_type(buffer),
Expand Down Expand Up @@ -118,6 +119,7 @@ pub fn framebuffer_from_wayland_buffer<A: AsFd + 'static>(
drm: drm.clone(),
}));
}
*/

Ok(None)
}
Expand Down
13 changes: 11 additions & 2 deletions src/wayland/dmabuf/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ where
formats: data.formats.clone(),
modifier: Mutex::new(None),
planes: Mutex::new(Vec::with_capacity(MAX_PLANES)),
node: Mutex::new(None),
},
);
}
Expand Down Expand Up @@ -294,14 +295,20 @@ where
}
}

zwp_linux_buffer_params_v1::Request::SetTargetDevice { device } => {
*data.node.lock().unwrap() = device[0..8].try_into().ok().map(u64::from_ne_bytes);
}

zwp_linux_buffer_params_v1::Request::Create {
width,
height,
format,
flags,
} => {
// create_dmabuf performs an implicit ensure_unused function call.
if let Some(dmabuf) = data.create_dmabuf(params, width, height, format, flags, None) {
if let Some(dmabuf) =
data.create_dmabuf(params, width, height, format, flags, *data.node.lock().unwrap())
{
if state.dmabuf_state().globals.contains_key(&data.id) {
let notifier = ImportNotifier::new(
params.clone(),
Expand All @@ -326,7 +333,9 @@ where
} => {
// Client is killed if the if statement is not taken.
// create_dmabuf performs an implicit ensure_unused function call.
if let Some(dmabuf) = data.create_dmabuf(params, width, height, format, flags, None) {
if let Some(dmabuf) =
data.create_dmabuf(params, width, height, format, flags, *data.node.lock().unwrap())
{
if state.dmabuf_state().globals.contains_key(&data.id) {
// The buffer isn't technically valid during data_init, but the client is not allowed to use the buffer until ready.
let buffer = data_init.init(buffer_id, dmabuf.clone());
Expand Down
27 changes: 18 additions & 9 deletions src/wayland/dmabuf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ use indexmap::{IndexMap, IndexSet};
use rustix::fs::{seek, SeekFrom};
use wayland_protocols::wp::linux_dmabuf::zv1::server::{
zwp_linux_buffer_params_v1::{self, ZwpLinuxBufferParamsV1},
zwp_linux_dmabuf_feedback_v1, zwp_linux_dmabuf_v1,
zwp_linux_dmabuf_feedback_v1::{self, TrancheFlags},
zwp_linux_dmabuf_v1,
};
use wayland_server::{
backend::{GlobalId, InvalidId},
Expand Down Expand Up @@ -317,7 +318,7 @@ impl DmabufFeedbackBuilder {
let feedback_formats: IndexSet<Format> = formats.into_iter().collect();
let format_indices: IndexSet<usize> = (0..feedback_formats.len()).collect();
let main_tranche = DmabufFeedbackTranche {
flags: zwp_linux_dmabuf_feedback_v1::TrancheFlags::empty(),
flags: zwp_linux_dmabuf_feedback_v1::TrancheFlags::Sampling,
indices: format_indices,
target_device: main_device,
};
Expand All @@ -342,11 +343,9 @@ impl DmabufFeedbackBuilder {
pub fn add_preference_tranche(
mut self,
target_device: libc::dev_t,
flags: Option<zwp_linux_dmabuf_feedback_v1::TrancheFlags>,
flags: zwp_linux_dmabuf_feedback_v1::TrancheFlags,
formats: impl IntoIterator<Item = Format>,
) -> Self {
let flags = flags.unwrap_or(zwp_linux_dmabuf_feedback_v1::TrancheFlags::empty());

let mut tranche = DmabufFeedbackTranche {
target_device,
flags,
Expand Down Expand Up @@ -448,15 +447,21 @@ impl PartialEq for DmabufFeedback {
impl DmabufFeedback {
/// Send this feedback to the provided [`ZwpLinuxDmabufFeedbackV1`](zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1)
pub fn send(&self, feedback: &zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1) {
feedback.main_device(self.0.main_device.to_ne_bytes().to_vec());
if feedback.version() <= 5 {
feedback.main_device(self.0.main_device.to_ne_bytes().to_vec());
}
feedback.format_table(
self.0.format_table.file.as_fd(),
self.0.format_table.file.size() as u32,
);

for tranche in self.0.tranches.iter() {
feedback.tranche_target_device(tranche.target_device.to_ne_bytes().to_vec());
feedback.tranche_flags(tranche.flags);
if feedback.version() <= 5 && tranche.flags.contains(TrancheFlags::Scanout) {
feedback.tranche_flags(TrancheFlags::Scanout);
} else {
feedback.tranche_flags(tranche.flags);
}
feedback.tranche_formats(
tranche
.indices
Expand All @@ -474,7 +479,9 @@ impl DmabufFeedback {
self.0
.tranches
.iter()
.filter(|tranche| tranche.target_device == self.0.main_device && tranche.flags.is_empty())
.filter(|tranche| {
tranche.target_device == self.0.main_device && tranche.flags == TrancheFlags::Sampling
})
.map(|tranche| tranche.indices.clone())
.reduce(|mut acc, item| {
acc.extend(item);
Expand Down Expand Up @@ -718,7 +725,7 @@ impl DmabufState {
);

let formats = Arc::new(formats);
let version = if default_feedback.is_some() { 5 } else { 3 };
let version = if default_feedback.is_some() { 6 } else { 3 };

let known_default_feedbacks = Arc::new(Mutex::new(Vec::new()));
let default_feedback = default_feedback.map(|f| Arc::new(Mutex::new(f.clone())));
Expand Down Expand Up @@ -837,6 +844,8 @@ pub struct DmabufParamsData {
/// Pending planes for the params.
modifier: Mutex<Option<Modifier>>,
planes: Mutex<Vec<Plane>>,

node: Mutex<Option<libc::dev_t>>,
}

/// A handle to a registered dmabuf global.
Expand Down
Loading