feat(wayland): implement infrastructure for async dmatex importing

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2025-07-12 06:17:12 +02:00
parent 49224ad6b5
commit c59198b4a2
3 changed files with 46 additions and 23 deletions

21
Cargo.lock generated
View File

@@ -591,9 +591,9 @@ dependencies = [
[[package]]
name = "bevy-dmabuf"
version = "0.1.0"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "321fa0b7c6b02ac16d5f85f1703b9d4a9a50e2ad3f9adae3b52138868a2747e8"
checksum = "f4af0a7897ed821f1e8fd5e1782711b8b54722f49a9398c9713f7f72ec2c5c0e"
dependencies = [
"ash",
"bevy",
@@ -1594,7 +1594,7 @@ dependencies = [
"bitflags 2.9.1",
"cexpr",
"clang-sys",
"itertools 0.13.0",
"itertools 0.11.0",
"log",
"prettyplease",
"proc-macro2",
@@ -1614,7 +1614,7 @@ dependencies = [
"bitflags 2.9.1",
"cexpr",
"clang-sys",
"itertools 0.13.0",
"itertools 0.11.0",
"proc-macro2",
"quote",
"regex",
@@ -3314,15 +3314,6 @@ dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.14.0"
@@ -3481,7 +3472,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667"
dependencies = [
"cfg-if",
"windows-targets 0.48.5",
"windows-targets 0.53.2",
]
[[package]]
@@ -6034,7 +6025,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f9612d9503675b07b244922ea6f6f3cdd88c43add1b3498084613fc88cdf69d"
dependencies = [
"cc",
"windows-targets 0.48.5",
"windows-targets 0.52.6",
]
[[package]]

View File

@@ -6,15 +6,15 @@ use bevy::{
};
use bevy_dmabuf::{
dmatex::{Dmatex, DmatexPlane, Resolution},
import::ImportedDmatexs,
import::{ImportedDmatexs, ImportedTexture},
};
use drm_fourcc::DrmFourcc;
use mint::Vector2;
use parking_lot::Mutex;
use std::sync::{Arc, OnceLock};
use waynest::server::protocol::stable::linux_dmabuf_v1::zwp_linux_buffer_params_v1::Flags;
/// Parameters for a shared memory buffer
#[derive(Debug)]
pub struct DmabufBacking {
message_sink: Option<MessageSink>,
params: Arc<BufferParams>,
@@ -22,6 +22,20 @@ pub struct DmabufBacking {
format: DrmFourcc,
_flags: Flags,
tex: OnceLock<Handle<Image>>,
pending_imported_dmatex: Mutex<Option<ImportedTexture>>,
}
impl std::fmt::Debug for DmabufBacking {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DmabufBacking")
.field("message_sink", &self.message_sink)
.field("params", &self.params)
.field("size", &self.size)
.field("format", &self.format)
.field("_flags", &self._flags)
.field("tex", &self.tex)
.finish()
}
}
impl DmabufBacking {
@@ -40,6 +54,7 @@ impl DmabufBacking {
format,
_flags: flags,
tex: OnceLock::new(),
pending_imported_dmatex: Mutex::new(None),
}
}
@@ -96,12 +111,16 @@ impl DmabufBacking {
images: &mut Assets<Image>,
buffer: Arc<Buffer>,
) -> Option<Handle<Image>> {
if self.tex.get().is_none()
&& let Some(dmatex) = self.import_dmabuf(dmatexes, images, buffer)
{
let _ = self.tex.set(dmatex);
}
self.tex.get().cloned()
self.pending_imported_dmatex
.lock()
.take()
.map(|tex| dmatexes.insert_imported_dmatex(images, tex))
// if self.tex.get().is_none()
// && let Some(dmatex) = self.import_dmabuf(dmatexes, images, buffer)
// {
// let _ = self.tex.set(dmatex);
// }
// self.tex.get().cloned()
}
pub fn is_transparent(&self) -> bool {

View File

@@ -13,7 +13,10 @@ use crate::{
},
};
use bevy::app::{App, Plugin, Update};
use bevy::ecs::schedule::IntoScheduleConfigs;
use bevy::ecs::system::{Res, ResMut};
use bevy::render::renderer::RenderDevice;
use bevy::render::{Render, RenderApp};
use bevy::{asset::Assets, ecs::resource::Resource, image::Image};
use bevy_dmabuf::import::ImportedDmatexs;
use cluFlock::ToFlock;
@@ -286,14 +289,24 @@ impl Drop for Wayland {
}
}
static RENDER_DEVICE: OnceLock<RenderDevice> = OnceLock::new();
pub struct WaylandPlugin;
impl Plugin for WaylandPlugin {
fn build(&self, app: &mut App) {
app.add_systems(PreFrameWait, early_frame);
app.add_systems(Update, update_graphics);
app.sub_app_mut(RenderApp).add_systems(
Render,
init_render_device.run_if(|| RENDER_DEVICE.get().is_none()),
);
}
}
fn init_render_device(dev: Res<RenderDevice>) {
_ = RENDER_DEVICE.set(dev.clone());
}
fn early_frame() {
info!("test");
for buffer in WL_BUFFER_REGISTRY.get_valid_contents() {