fix(wayland): use an actual timestamp for the frame callback

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2025-08-07 03:33:18 +02:00
parent 9e72edae67
commit b31f6bc983
4 changed files with 9 additions and 5 deletions

1
Cargo.lock generated
View File

@@ -5475,6 +5475,7 @@ dependencies = [
"parking_lot 0.12.4", "parking_lot 0.12.4",
"rand", "rand",
"rustc-hash 2.1.1", "rustc-hash 2.1.1",
"rustix 1.0.8",
"serde", "serde",
"serde_repr", "serde_repr",
"slotmap", "slotmap",

View File

@@ -151,6 +151,7 @@ memfd = { version = "0.6.4", optional = true }
vulkano = { git = "https://github.com/Schmarni-Dev/vulkano", branch = "0_35_dmabuf_fixes", optional = true } vulkano = { git = "https://github.com/Schmarni-Dev/vulkano", branch = "0_35_dmabuf_fixes", optional = true }
wgpu-hal = { version = "24", optional = true, features = ["vulkan"] } wgpu-hal = { version = "24", optional = true, features = ["vulkan"] }
ash = { version = "0.38.0", optional = true, default-features = false } ash = { version = "0.38.0", optional = true, default-features = false }
rustix = { version = "1.0.8", features = ["time"] }
[dependencies.stardust-xr] [dependencies.stardust-xr]
workspace = true workspace = true

View File

@@ -181,6 +181,7 @@ fn build_line_mesh(
MeshMaterial3d(materials.add(BevyMaterial { MeshMaterial3d(materials.add(BevyMaterial {
base_color: Color::WHITE, base_color: Color::WHITE,
perceptual_roughness: 1.0, perceptual_roughness: 1.0,
// TODO: this should be Blend
alpha_mode: AlphaMode::Opaque, alpha_mode: AlphaMode::Opaque,
..default() ..default()
})), })),

View File

@@ -32,6 +32,7 @@ use core::{buffer::Buffer, callback::Callback, surface::WL_SURFACE_REGISTRY};
use display::Display; use display::Display;
use mint::Vector2; use mint::Vector2;
use std::fs::File; use std::fs::File;
use std::time::Duration;
use std::{ use std::{
fs::{self, OpenOptions}, fs::{self, OpenOptions},
io::{self, ErrorKind}, io::{self, ErrorKind},
@@ -169,15 +170,13 @@ impl WaylandClient {
} }
Err(e) => { Err(e) => {
// wayland clients really aren't nice when disconnecting properly, are they? :p // wayland clients really aren't nice when disconnecting properly, are they? :p
if let server::Error::Decode(DecodeError::IoError(e)) = &e { if let server::Error::Decode(DecodeError::IoError(e)) = &e && e.kind() == io::ErrorKind::ConnectionReset {
if e.kind() == io::ErrorKind::ConnectionReset {
if let Some(pid) = client.get::<Display>(ObjectId::DISPLAY).and_then(|d| d.pid) { if let Some(pid) = client.get::<Display>(ObjectId::DISPLAY).and_then(|d| d.pid) {
tracing::info!("Wayland: Client with pid: {pid} disconnected from server"); tracing::info!("Wayland: Client with pid: {pid} disconnected from server");
} else { } else {
tracing::info!("Wayland: Unknown client disconnected from server"); tracing::info!("Wayland: Unknown client disconnected from server");
} }
break; break;
}
} }
tracing::error!("Wayland: Error reading message: {:?}", e); tracing::error!("Wayland: Error reading message: {:?}", e);
break; break;
@@ -205,8 +204,10 @@ impl WaylandClient {
match message { match message {
Message::Disconnect => return Ok(true), Message::Disconnect => return Ok(true),
Message::Frame(callback) => { Message::Frame(callback) => {
let serial = client.next_event_serial(); let now = rustix::time::clock_gettime(rustix::time::ClockId::Monotonic);
callback.done(client, callback.0, serial).await?; let now = Duration::new(now.tv_sec as u64, now.tv_nsec as u32);
let ms = (now.as_millis() % (u32::MAX as u128)) as u32;
callback.done(client, callback.0, ms).await?;
client client
.get::<Display>(ObjectId::DISPLAY) .get::<Display>(ObjectId::DISPLAY)
.unwrap() .unwrap()