Repository navigation
Mac and Windows: shader clock re-bases out of sight, so scenes no longer jump every 13 h 20 min - #137
Open
narrowstacks wants to merge 1 commit into
Open
narrowstacks wants to merge 1 commit into
narrowstacks wants to merge 1 commit into
Conversation
narrowstacks
force-pushed
the
fix-c1-shader-time
branch
from
December 1, 2026 03:09
718d034 to
4c4964a
Compare
…ger jump every 13 h 20 min
narrowstacks
force-pushed
the
fix-c1-shader-time
branch
from
December 1, 2026 03:18
4c4964a to
1d0fda9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The shaders' clock (
FrameParams.time) wrapped at 48,000 s (elapsed % 48000inframe_params) to keep float precision. Only the black hole disk's flow (48 s period) and the planetary nebula's 400 s cycle actually repeat at that wrap; every other use in every scene jumped in one frame every 13 h 20 min of uptime, on both apps. Black Hole Merger's own clock wrapped at 100,000 s of scene time, and Quasar's knots and lobes at their own periods (the review item didn't list Quasar).Audit
Every use of the clock in
shaders/metal/*.metal. "Periodic" means periodic in a way that divides the wrap.skyColor(every scene)sin(T*5.71), comet ion-tail streaksshadeDiskfract(T / flowPeriod)two-phase flowT*0.02, stream driftT*0.012, jet knotsT*0.25, pulsesin(T*0.5)flowingDisk(periodG.motion.w), star-forming regionsom*T, dustT*0.003, lumpsT*0.006, burstssin(T*0.15), cellsom*TflowingDisk(..., 72), torusT*0.06, flickerT*0.35; CPU: knot travel% 1.4*4096, lobe drift% 500st.y + ws*0.12*T,T/cycle(40 s) trace-back, lightning slotsrgDriftband drift, churnT*0.02, ringT*2pi/period, ring sparkleT*0.012; CPU: storm start% 48000T/cyc, gap planetsom0*pow(g,-1.5)*T, spokesfract(T/110)T*0.004/0.006/0.003, knot flickerT*0.12; shellsfract(T/400)auroraLUTkernel (curtain noise and folds), emissionT*0.01, cloudsT*0.0004, lightningT*0.02toT*0.7), city flickerT*0.6T/life, prominences, loops, jetssin(T*(0.12+...)), granulationT*0.05, raysT*0.06, flickerT*0.6sin(T*0.14), pulsesin(T*0.11)sin(c*7 - T*2.5)T*0.04, lanes, clumps, wisps, lobes, churn, beam knotsT*3sin(T*2pi/S.a.x)breathing, shimmersin(T*0.3)S.p.w, own clock)T*0.8, gasfract(T/per),cos(th - T*0.9*...), clustercos(om*T)No common wrap period exists, since noise isn't periodic, and a per-use fix would have needed about a hundred slots. So the clock moves only where nobody can see it, with a cross-fade as the fallback.
Fix
One clock per desktop, restarted only unseen. All screens of a desktop count the shader clock from one base, so displays showing one scene stay in step. It lives in
DesktopClockincore/src/scene_params.rs:CoreClock.desktopon the Mac, and one per wallpaper process on Windows. The Customize preview on the Mac keeps its own, and the Windows Customize window renders from 0. The core moves the base to the last multiple of 19,200 s (400 × 48, so the disk flow and planetary shells keep their phase) only:CLOCK_REVEAL_AFTER), or the displays slept, the session was locked or another user had it in between. What shows first on a reveal is the last frame drawn before hiding, so a short look away (swiping back from a full-screen app) doesn't restart the clock: that would re-roll every drifting feature in one frame. After a minute away the scene has moved on anyway.isOnScreenanddisplayHidden(sleep, another session) to the shared clock.visibility::desktop_hidden()(displays off, locked, other user).Fadeuntil it's gone.transition(id, start)returns the same pair for every screen. A cut to a new scene restarts it too.Forced fallback. A look in view for 16 h (57,600 s = 3 × 19,200) without a restart wraps on screen. For 120 s after, the scene is drawn at both clocks and cross-faded with a smoothstep weight. That uses
F.clock, the<name>Scene(FRAME_ARGS, ..., float T)bodies looped overclockPasses, Aurora's table blended the same way, and Black Hole Merger's and Quasar's pre-wrap values inF.clock.z,S.handS.j.cell - cells, and the ripple's noise takes the cells as a whole-number lattice offset (qsrNoise). So the travel never wraps (no jump), and the part in float arithmetic stays under 1,400 (0.1 ms of travel at Knot speed 3), however long the clock runs. At normal times the split is 0, so the math is bit-for-bit the old one.Outside the fade there is one pass with weight exactly 1.0, so renders at normal times are byte-identical to main. Snapshots,
deepfield render, captures and the lock-screen still count from 0.API.
frame()takesclock_base;scene_params::{DesktopClock, ShaderClock, rebase_clock, CLOCK_PERIOD, CLOCK_MAX_AGE, CLOCK_FADE, CLOCK_REVEAL_AFTER}.df_frame(..., clock_base, ...)anddf_clock_new/free/base/seen/cut/transition, all insideguard(every_export_is_guardedpasses), plus the header.Renderer::encode_frame_clocked.CoreClock,Core.frame(clockBase:),encodeFrame(clockBase:).Verification
Core tests (
cargo test --workspace --lib: 122 + 30 (ffi, including the guard test) + 17 pass):frames_carry_on_across_a_forced_wrap: every scene, from base 0 and from a restarted base, at 1, 2, 3, 52 and 2000 forced wraps, across the wrap and the fade's end. The largest change in any float handed to the GPU over a 1/60 s frame is ≤ 2× the frame before (+1e-3, a whole turn counting as none). The dominant clock advances one frame, as does Black Hole Merger's own at 4× and Quasar's knots at Knot speed 3.a_rebase_changes_only_the_clock: every scene, with all Show Me events active. A restart (unseen, so not required to be continuous) restarts the clock under 19,200 s with one pass, keeps the 48 s and 400 s phases, and changes no float but the clock slots. Events, orbits, colors and event placements are identical, and frames after it carry on.a_transition_rebases_only_the_incoming_look: starting 1 s before the outgoing look's forced wrap. The outgoing look carries on through its wrap on its own base, and the incoming one carries on with one pass.the_desktop_clock_restarts_only_unseen: a 5 s look away doesn't restart, 60 s does, sleep does however short, showing all along never does, and a transition gives every screen the same pair.quasar_knots_keep_their_precision,frame_time_wraps,clock_fade_is_smooth.Other checks:
--time 300, every scene, against a main build: byte-identical, 22 of 22. Live Earth was compared with its time frozen; unfrozen it reads the wall clock and differs run to run on main too.Quasar at Knot speed 3: 2052 across the forced wrap, against 1269 for a normal step at 40,000 s.
cargo run --features check -- --check(msl2wgsl): every module ok.--check-core,--check-customization: ok.scripts/parity/compare.py(default times): 88 of 88 ok (events included).--benchmark --defaults --time 300: every scene under 2 ms, within noise of main. During the forced fade, about 2×, for 120 s at most once in 16 h of a screen in view.windows/src/wallpaper.rs) can't build on a Mac (a crosscargo checkstops inring's C build); CI's Windows job builds it.Screenshots
Before (main) at 47999.9 | 48000.1 s, and this PR's forced fallback at 57599.9 | 57600.1 s (base 0, no restart for 16 h):
(attached by the coordinator)