The slider wrote world_post.scale, but with HD on the world target's scale
came from hd::scale_override(): with DLSS enabled and its SDK open it always
returned Some(2/3), and prepare() takes hd_scale.unwrap_or(scale) — so the
slider was never read. Moving it 50/80/100/200% changed neither the picture
nor FPS; only the DLSS toggle did. Without DLSS and HORIZON_HD_SCALE the
slider worked (native TAAU), which hid the bug on non-RTX machines.
scale_override(slider) now reconciles the two, first match wins: film
quality (full size), HORIZON_HD_SCALE (the explicit launch-time override,
still read once), then the slider — with DLSS evaluating capped at the
output (an upscaler renders no larger), the default 100% keeping DLSS's 2/3
auto ratio and >100% rendering at the output; without DLSS the slider
applies as-is, >1 supersampling included. The decision is a pure scale_for,
unit-tested on every platform (the_resolution_slider_drives_hd_scale).
Live: gfx.rs decides hd_scale every frame before the jitter, and the jitter
and the motion globals (hd_motion.xy) read world_post.scaled_size so they
match the size this frame draws, not the previous frame's target. prepare()
resizes the world target; Hd::resize -> Taa::resize resets the histories and
resizes DLSS. Dlss::resize keeps the NGX context while the new render size
fits its render_resolution_range (the render size rides per evaluate as
partial_texture_size); recreating waits the device idle in the context's
Drop, which a live slider would feel. The first evaluate after a change
resets NGX (InReset), so no ghosting across scales. The #143 motion/jitter
contract is untouched: MVJittered, MVLowRes, jitter in render pixels,
motion_vector_scale [1,1].
Verified on macOS/Metal (no DLSS device): the lib suite (1243 passed), the
new GPU test the_world_target_follows_the_resolution_slider (50/100/200% ->
960x540 / 1920x1080 / 3840x2160, live resize, hd_scale precedence) and
taau_gpu_smoke_still_surface_ab. The dlss-gated code cross-checks for
x86_64-pc-windows-gnu --features dlss against the NGX v310.9.1 headers; the
DLSS evaluation itself awaits an RTX run.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
A large raid viewed in the fullscreen map OOM-trapped the mod at the old
64 MiB cap: the ground/section caches plus >200 objects and the recording
exhausted it during a hash rehash (Ground::answer). The caches are already
count-bounded; 512 MiB gives ample headroom on a desktop while still
bounding a runaway guest. Fuel budgets unchanged.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
The terrain vertex shader built prev_clip from the current wind-displaced position plus the
camera step, so the motion buffer knew only the camera: leaves and plants sway at 0.2-0.6 Hz
with up to 0.14 blocks of amplitude, and their history lagged the sway — the shimmer on foliage
and the distant treeline. The wind is a sum of whole-cycle waves over 256 blocks and 600 s, so
the previous frame's displacement is the same sway evaluated at the previous wind time and
strength: gfx.rs keeps them in taa_prev and passes them in Globals.hd_motion.zw (this frame's
when there is no previous one, so the wind's own motion is zero then), and terrain.wgsl's
wind_offset_at evaluates them for prev_clip. The spatial argument stays this frame's camera
wrap: the vertex's world position does not move. World-pass colour is unchanged (prev_clip
feeds only the motion buffer); the shadow pass inherits the globals and ignores prev_clip.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
Water animates in place — the waves tilt the normals, so the refraction, the SSR/sky reflection
and the sun's glint move with no geometric motion to reproject by — and its history conflicts
with the frame instead of steadying it: the shimmer most visible on water. The TAA passes now
read the water's own depth (binding 7) and trust the history less where water animates fastest:
near the camera (the fine ripples and sparkles change every frame up close; far water keeps only
the slow waves, the fine ones fade out by footprint, so it keeps the full weight). The cap is
0.8 for fs_taa and 0.7 for fs_taau, faded out to 96 blocks; no water this frame means no change,
and the GPU A/B smoke (no water in its scene) resolves bit-identically. Also pins the wind
motion contract numerically: a wind-blown plant's previous position is the same vertex at the
previous frame's wind time and strength, and the camera-only decode misses by the wind's move.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
The G-buffer's motion buffer is current-to-previous in jittered render pixels, but the DLSS
create flags left MVJittered unset: NGX used the vectors unadjusted while still applying the
per-evaluate jitter offset, counting the camera jitter twice — the severe whole-image shaking
on RTX. The DLSS Programming Guide (31 March 2026) §3.6.2 documents the flag: with it NGX
subtracts the jitter difference itself from the jitter_offset values. The rest of the contract
is confirmed unchanged: render-resolution pixel vectors with MVLowRes (§3.6.2), scale [1,1]
for pixel space (§3.6.1/§3.6.3 — Streamline's {1/w,1/h} is its own constant, which its plugin
multiplies back by the render size), jitter in render pixels within ±0.5 (§3.7.3), reversed-Z
depth (§3.8.1). The native TAA/TAAU path is untouched.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
The display<->linear conversion shaders sample the source with
textureSampleLevel and the filtering HD sampler, but the bind group layout
declared the source UNFILTERED (Float filterable:false). wgpu rejects a
non-filterable texture paired with a filtering sampler when the pipeline is
created, which only happens on a real DLSS device (the colour pipelines are
built when DLSS initialises, never on the native-TAAU fallback). HDR is
Rgba16Float, filterable, so bind the source as FLOAT (filterable:true).
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
The HORIZON_DLSS env gate becomes the `dlss` entry of horizon-graphics.txt
(default on), still overridable by HORIZON_DLSS=1|0. The renderer opens its
Vulkan device for DLSS at the start only while the choice is on; a failed
DLSS instance/device now keeps Vulkan and falls back to the native TAAU
instead of skipping the backend.
The evaluation itself switches live, like model-instancing: gfx::set_dlss
gates the DLSS branch of Hd::taa, and the #137 separated histories make both
directions clean (a native frame resets NGX on resume; a DLSS frame leaves
the native history unusable). The 2/3 resolution default follows the live
request AND an opened DLSS SDK, so a requested-but-unavailable DLSS never
changes the picture's scale. Off is the native TAAU, bit-identical to the
old fallback.
The `dlss on|off|status` control command and the new mod SDK imports
render.set-dlss / render.dlss-status (API level 33) drive the switch and
persist the choice; an on-switch after a start with DLSS off applies at the
next launch. The UI test guest calls the newest level's functions again
(its level assertion was stale since level 32).
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
The #147 step 3.1 bench must measure a real battle on the default
server-thread single-player path, where the window is a client of its own
integrated server. Two control-socket handlers bypassed the client mod there:
- chat sent raw to the server (send_chat) in remote mode, skipping the
chat-box's client-mod interception (handle_chat_input -> mod_command), so
/airdef deploy|wave|stats never reached the client-side mod and no battle
deployed (fingerprints null, tick fuel 395K vs 12.7M in-frame).
- chat-log read the connection's raw buffer (remote_chat), which never holds
a client mod's own lines (they land in ui.chat via add_mod_chat_line; the
server's lines are mirrored into ui.chat by chat_line).
Both now behave as the player's chat box: chat routes through
handle_chat_input (client-mod command first, else the server), chat-log reads
the player-visible ui.chat. status.chat (remote_chat) is unchanged; the
in-frame path is unchanged. Harness only — no sim rule, frequency, limit or
combat decision touched.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
Host-side per-tick CPU spans of tick_mods (ground answers, world rays/
sections, snapshot, the WASM tick wall time, model prep, output), gated by
HORIZON_MOD_CPU_PROFILE=1 like the fuel profile and bounded like FrameStats.
Each record carries the game tick and the frame index it ran in, so the bench
can join the spans with the frame/CPU/GPU trace; stats reports per-span
percentiles and stats raw the per-tick records, cleared by stats reset/bench.
game.monotonic-nanos (API level 32): a monotonic clock a mod reads to time its
own phases, never simulation time. Additive to the game interface, so older
mods still link; api_level and the generated reference updated.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
After the retained meshes of #126 a frame still transformed and uploaded
every model's vertices every frame (~3.1 MB vertex + ~4 MB motion at ~135
models in the #126 M5 report). The one mass group of identical models now
draws from a GPU mesh retained per pack generation: a frame writes only
instance records (current and previous drawn pose, model id, light, glow)
and the same stream feeds the HD G-buffer, the HD motion pass, the sun
shadow cascades and the classic entity pass (main and mod cameras). The
instance shader mirrors the CPU bake's transform, normal quantization and
light/material rules; a static model carries identical poses and keeps
zero object velocity (#143's contract, unchanged jitter conventions).
Everything else stays on the per-vertex path, bit-identical to before:
groups under eight models, HORIZON_MODEL_INSTANCING=0, a shader pack that
draws entities, or a missing renderer fall back whole. The diagnostic
runtime toggle `model-instancing on|off` (control command) switches paths
without a restart so the bench driver can compare both on one recording;
the drawn-pose history both paths keep makes the switch seamless for
motion. Reload and world unload drop the GPU meshes with the #126 cache;
the pack generation guard catches a reload too. Counters in `stats`:
instanced_models, instanced_quads, instance_bytes, gpu_mesh_builds.
Driver support for the #147 bench: `stats raw` reports every recorded
frame/CPU/GPU time; HORIZON_MOD_FUEL_PROFILE=1 reports the guests' observed
fuel per callback and average wall time per call in `stats`.
Tests: mod_models::tests (group choice and tie-break, GPU mesh faces,
shader math vs the CPU matrix, static zero velocity, the #126 parity test
unchanged), gfx attribute-layout and WGSL validation tests.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
The G-buffer's motion buffer is current-to-previous in jittered render
pixels: both positions are projected with their frame's drawn matrix, so
even a still surface writes the two frames' jitter difference. fs_taa
(1:1) keeps its history on the jittered grid and needs that difference as
written, but native TAAU resolves a full-size history on the stable output
grid, so using the buffer raw shifted every still pixel's history lookup
by the jitter difference — (+0.375, +0.5) output pixels at 1280x720 ->
1920x1080 on the first Halton(2,3) pair.
State the contract explicitly (gfx/hd/mod.rs, taa.rs, frame.rs and the
motion producers in terrain.wgsl / entity.wgsl) and pass the previous
frame's jitter to the shaders (HdFrame.prev_jitter, HdScene::prev_jitter_px,
Renderer::taa_prev). fs_taau now adds the current jitter and subtracts the
previous one, so a still surface reads the same output pixel on every
phase; fs_taa is unchanged. The DLSS backend receives the buffer and its
flags unchanged — NGX's input contract is verified on that path separately
(#137), not inferred here.
Numerical tests cover every jitter phase at 1:1 and fractional scales:
the still-surface lookup, the 1:1 correction, a moving camera (the motion
path and the depth/camera fallback agree on one continuous surface), a
moving model's known shift, the issue's worked numbers, and the
jittered-depth unprojection. An ignored GPU smoke runs the real fs_taau
A/B on a still finely patterned surface at 1280x720 -> 1920x1080: the old
decode against the fixed one, the depth fallback (must agree with the
fixed decode), and the spatial filter alone (the production lanczos
gather's own sub-pixel error is the floor the temporal path must not add
to).
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
The HD film/tonemap/final-frame passes were recorded into the first command
buffer and read `taa.target` before NGX wrote the DLSS result into it: the
submit was `once(world).chain([NGX, delinearize])`, so the first frame read
the target's initial contents and later frames read the previous result.
Successful DLSS init in the log did not mean the current frame was shown.
Finish the world encoder (world + display->linear) right after `Hd::taa`
records the DLSS input, then record film, bloom, the tone curve, the hand,
the HUD, capture and present into a fresh encoder. One `queue.submit` of
[world+linearize, NGX, delinearize, rest] keeps that GPU order with no CPU
sync; `submission_order` builds the list and stays the single-buffer path
when DLSS is off. Staging-belt recall, GPU/HD pass timing and the capture
readback all stay within the one submission, so they keep working across
the split (HD pass timestamps resolve in a later frame, as before).
Track native and NGX history readiness separately (`HistoryReady`): a
successful DLSS frame no longer marks the native history usable, so the
first fallback frame after DLSS starts over instead of blending a stale or
empty native texture; a native frame resets NGX in turn. A cut/teleport,
resize or TAA off clears both. `HdFrame.taa.w` now reflects native history
usability, so film motion blur sits out DLSS frames rather than reproject
a history it does not own.
Narrow tests: the submission order, and the native/DLSS history lifecycle
including the first fallback frame and reset. The DLSS-gated tests and the
real-RTX acceptance (docs/DLSS-TESTING.md) remain pending on Windows/Linux
with an RTX; no RTX is available here, so this is verified by the ordering
and history unit tests plus the native suite, not a DLSS capture.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
render.project (API level 31) returns where a world point lands on the
screen, in GUI pixels, through the camera the last drawn frame used:
the player's own view or a mod's set-main-view camera, the bob and the
spin included, at most a frame behind. None for a point behind the
camera, and with no world or drawn frame yet; a point off the screen
still projects past its edges, for the caller to clip.
The game copies the frame's eye and view-projection into the mod
snapshot after a world frame is drawn, and clears it when another world
is entered, so a stale camera never projects into the new one. The
projection is camera-relative, as the world's geometry is drawn, with
the renderer's own f32 precision far from the origin.
For AirDef's world overlay: square markers over visible targets while
a key is held, on top of normal gameplay. The UI test guest calls the
new function so the sandbox checks the level-31 contract.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
mod_model_geometry baked every model twice a frame (current + HD motion):
collect_seeded, two atlas hash lookups and a normal derivation per face, a
full-atlas special-material scan, and a linear material search per quad.
Resolve the faces once per pack generation instead (MeshCache keyed by
BlockStateId, generation = the pack's Arc<RenderAssets>, ptr_eq): sprite
rect, model-space quad/normal, emission and the quad's special material.
A frame only transforms and lights the retained faces; the normal matrix
is built once per instance, and the motion pass (#124) re-transforms the
same faces for previous positions instead of a second bake. Vertices are
bit-identical to the old path (unit test over the transform/glow/light
matrix). Reload (apply_staged_pack) and world unload (clear_entities,
leave_server) drop the cache; the generation guard catches any pack swap.
stats/bench expose mod_models counters (frames/models/quads/motion_quads/
vertex_bytes/motion_bytes/mesh_builds/atlas_scans); span mod_models inside
entity_geometry. Measured on M5/Metal 2560x1440 HD, Polygon raid scene
(14 batteries + 3 waves, ~135 models/frame): entity_geometry CPU
5.71 -> 1.57 ms avg (p95 8.7 -> 2.2), prepare phase 23.5 -> 7.05 ms;
static scene pixel-identical at converged LOD. Upload bytes unchanged;
GPU instancing is the next stage of #126 direction A.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
Compose NGX and HDR Vulkan device creation, retain one SDK per device and a context per output size, and evaluate DLSS with existing motion/depth/jitter. Bracket NGX with explicit display-linear color conversion and ordered command buffers. Native TAA/TAAU remains the fallback; Windows compile check passes, runtime acceptance still requires RTX.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
Keep each mod model's last rendered world transform and emit a separate previous-position vertex stream. A depth-read-only motion pass overwrites camera-only vectors with exact previous-frame object motion and matching alpha cutouts. Add HORIZON_HD_DEBUG_MOTION for visual verification.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
The near colour-shadow pass leaves leaves out of depth while the far cascade includes them. Blend both filters over six blocks and fade tint on the same curve so the boundary no longer reads as a circle around the camera.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
Add an RG16F current-to-previous render-pixel target to the HD G-buffer. Terrain and entities write previous drawn-camera projections; TAA/TAAU use matching opaque vectors and retain the depth fallback elsewhere. Object-local previous transforms and vendor SDK evaluation remain separate phases.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
Uploads staged every buffer write through wgpu's StagingBelt, which gives a
write larger than its chunk a buffer of exactly that size, keeps it for good
and only reuses it for writes that fit. The entity batch outgrows the 1 MiB
chunk with a few hundred mobs and grows a little each tick while more appear,
so every tick took a new buffer: about 1 GB more per hundred mobs past ~750,
never given back, until the game was killed (upstream #2826).
Writes larger than the chunk now take a power-of-two slice and copy only
their bytes, so the buffers the belt keeps are reused: one per doubling.
Backport of horizon-rust/horizon@f7b77fbc88,
whose file moved from crates/horizon-client-render/src/gfx/upload.rs to
crates/horizon-client/src/gfx/upload.rs. Takes its growth test
(growing_large_writes_reuse_the_belt_buffers) and the kept_buffers helper as
written. Fork issue: #130.
Co-Authored-By: Kimi Code <noreply@moonshot.cn>
A camera shown only as the screen's own view was never prepared: the note
required a non-empty picture list. Two runs picking the same local id both
claimed the screen's frame, though only the first one's camera was drawn
from it. The client now notes whether the frame was a world frame and the
(run, camera id) the screen's world was drawn from, so the main-view
milestone belongs to the run whose selection the screen used, and a title
or loading frame reports the path off without erasing earlier milestones.
A world transition clears the submission, the main-view selection and the
milestones: another world's cameras are not drawn. A camera given to
set-main-view drops its picture target, so its milestone starts over until
a frame is drawn from it. prepared stays a host-side encoding milestone,
not target registration, not a GPU fence, not a visible pixel.
Also gate the client's note on the `mods` feature: without it the default
horizon-client build did not compile.
Verified: horizon-mods 37 unit, 44 sandbox (1 ignored; real Wasmtime
guests, the two-run test shows each id 7 follows only its own pictures and
selection) and 4 api_reference; client checks and build with and without
`mods`; gfx lib tests.
Co-Authored-By: Kimi Code <noreply@moonshot.cn>
API 30 adds render.camera-status: availability, the last noted frame's
mod-camera picture path, the calling run's accepted set-views submission
for this world generation, and per-camera prepared flags. A camera is
prepared when the renderer encoded its picture into the texture target
in a real frame of this generation, or a world frame rendered from it as
the set-main-view selection: a host-side encoding milestone, not target
registration, not a GPU fence, not a visible pixel. An empty set-views
clears the request; a resubmission, world transition or mod reload waits
for a new frame. The renderer reports the pictures it drew each frame;
the game notes the frame after a successful render. Verified with two
real Wasmtime guests sharing local camera id 7: each run's readiness
follows only its own submission and main-view choice, and a world
transition resets both.
Co-Authored-By: Kimi Code <noreply@moonshot.cn>
The writer removed its video, raw sound and log only when a take was
cancelled, so an encoder error or a non-zero ffmpeg exit left them in the
films folder. A failed take now removes exactly the files it wrote; the
log's last lines move into the error, since the log itself goes.
The encoder always writes <name>.video.mp4, and <name>.mp4 appears only
after a successful mux or rename. A failed, cancelled or no-audio take
therefore cannot overwrite or delete a film of an earlier export with the
same name. The writer's entry point takes the ffmpeg and its arguments so
a test can drive a failing encoder.
Co-Authored-By: Kimi Code <noreply@moonshot.ai>
Preserve AirDef replay lighting and acoustic commands while retaining upstream shadow and HDR fixes. Give the two entity shadow shaders distinct entry points.
Co-Authored-By: Codex <noreply@openai.com>