Minecraft: Java Edition 26.3 rewritten from scratch in Rust, checked against vanilla with 281 differential harnesses. Get it with the Horizon launcher.
Rust differential-testinggame-enginegamedevlinuxminecraftminecraft-javareimplementationrustvoxelvulkanwgpu
Frame stats: waits for the submit thread count as waiting, not CPU
Ludovic Marie1fad808164cf
diff --git a/crates/horizon-client-render/src/gfx.rs b/crates/horizon-client-render/src/gfx.rsindex 5b3ee3b82..1af334df4 100644--- a/crates/horizon-client-render/src/gfx.rs+++ b/crates/horizon-client-render/src/gfx.rs@@ -742,7 +742,8 @@ pub struct Renderer {/// (F3+4 shows it).pub lightmap_pixels: [u8; 16 * 16 * 4],/// Time the last `render` spent blocked on the GPU or the display- /// (acquiring, presenting, offscreen pacing), excluded from CPU time.+ /// (acquiring, presenting, offscreen pacing, the submit thread holding the queue),+ /// excluded from CPU time.pub last_wait: std::time::Duration,/// CPU time of the last `render`, waits excluded.pub last_encode: std::time::Duration,@@ -5333,7 +5334,11 @@ impl Renderer {}/// `checks`: the error scopes of a scaled screenshot's frame, checked before its PNG is written.fn draw_frame(&mut self, frame: &Frame, checks: Option<GpuChecks>) -> Result<bool> {+ let landing = Instant::now();self.land_frame();+ // Waiting for the previous frame (offscreen: at most two on the GPU), not work.+ let landed = landing.elapsed();+ self.queue.take_waited();// World frames alone follow the shader pack: the game loads the picked one// before it draws one. Title frames draw no terrain and keep the layout// through a pack dropped (Shader Options) or not loaded yet (`Renderer::new`),@@ -5397,6 +5402,8 @@ impl Renderer {if !fg {self.frame_gen.stop();}+ // Waits for the submit thread since the last frame's present (this frame's uploads).+ let queued = self.queue.take_waited();let acquire = Instant::now();let fg_frames = fg.then(|| {@@ -5418,7 +5425,9 @@ impl Renderer {} else {self.surface.as_ref().map(|s| s.get_current_texture())};- self.last_wait = acquire.elapsed();+ self.last_wait = landed + queued + acquire.elapsed();+ // Inside the acquire's time already.+ self.queue.take_waited();let (surface_frame, reconfigure) = match acquired {None => (None, false),Some(wgpu::CurrentSurfaceTexture::Success(f)) => (Some(f), false),@@ -8089,6 +8098,8 @@ impl Renderer {match self.queue.submit_later(job) {Ok(()) => {self.deferred = Some(offscreen);+ // The frame's waits for the previous one on the submit thread.+ self.last_wait += self.queue.take_waited();self.last_encode = started.elapsed().saturating_sub(self.last_wait);self.visible = visible;self.visible_lods = visible_lods;@@ -8153,6 +8164,8 @@ impl Renderer {);}}+ // The frame's own waits for the submit thread (its queue writes and passes).+ self.last_wait += self.queue.take_waited();let present = Instant::now();if let Some(surface_frame) = surface_frame {// On Wayland this ties RedrawRequested to the compositor's frame@@ -8185,6 +8198,8 @@ impl Renderer {}}self.last_wait += present.elapsed();+ // Inside the present's time already.+ self.queue.take_waited();self.last_encode = started.elapsed().saturating_sub(self.last_wait);let _ = self.started;self.visible = visible;diff --git a/crates/horizon-client-render/src/gfx/submit.rs b/crates/horizon-client-render/src/gfx/submit.rsindex a0f2c3ce1..f048756aa 100644--- a/crates/horizon-client-render/src/gfx/submit.rs+++ b/crates/horizon-client-render/src/gfx/submit.rs@@ -7,7 +7,8 @@//! ([`Deref`]) first waits for that frame to be submitted, so writes, copies and//! submissions keep the order they had on one thread.use std::ops::Deref;-use std::sync::atomic::{AtomicBool, Ordering};+use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};+use std::time::{Duration, Instant};use std::sync::{Mutex, mpsc};/// Whether frames go to the submit thread, unless `HORIZON_SUBMIT_THREAD` says (`0` off, `1` on):@@ -50,6 +51,9 @@ pub struct Queue {/// A frame went to the submit thread and has not been waited for.pending: AtomicBool,landing: Mutex<Option<Landing>>,+ /// Nanoseconds the window's thread waited for the submit thread since the last+ /// [`take_waited`](Self::take_waited): the GPU or the display holding a frame back, not work.+ waited: AtomicU64,}impl Queue {@@ -60,6 +64,7 @@ impl Queue {thread: None,pending: AtomicBool::new(false),landing: Mutex::new(None),+ waited: AtomicU64::new(0),};if !threaded {return this;@@ -130,15 +135,24 @@ impl Queue {return;}if let Some(l) = landing.as_mut() {+ let started = Instant::now();// A thread that died (a wgpu panic on it) panics here, as it would have in place.let submission = l.done.recv().expect("Horizon renderer: the submit thread stopped");l.landed = Some(submission);+ let nanos = u64::try_from(started.elapsed().as_nanos()).unwrap_or(u64::MAX);+ self.waited.fetch_add(nanos, Ordering::Relaxed);}self.pending.store(false, Ordering::Release);}+ /// How long the window's thread waited for the submit thread since the last call: in a+ /// GPU-bound view, the previous frame's submission and present hold up every use of the+ /// queue (uploads in the frame's first half too), and that is waiting, not the frame's work.+ pub fn take_waited(&self) -> Duration {+ Duration::from_nanos(self.waited.swap(0, Ordering::Relaxed))+ }/// The submission of the frame [`submit_later`](Self::submit_later) took, once it is/// made; `None` if it was taken already.pub fn landed(&self) -> Option<wgpu::SubmissionIndex> {