diff --git a/crates/horizon-client/src/entity.wgsl b/crates/horizon-client/src/entity.wgsl index 7fa8245ad..0b43c35b0 100644 --- a/crates/horizon-client/src/entity.wgsl +++ b/crates/horizon-client/src/entity.wgsl @@ -352,7 +352,8 @@ struct EntityGBufferOut { } // The motion buffer's contract: current-to-previous in jittered render pixels (both matrices as // drawn, so a still surface writes the two frames' jitter difference). The temporal passes decode -// it for their history grid (gfx/hd/taa.wgsl); DLSS receives it unchanged. +// it for their history grid (gfx/hd/taa.wgsl); DLSS receives it unchanged with the MVJittered flag +// (gfx/hd/dlss.rs), which tells NGX to undo the jitter difference itself. fn motion_pixels(pos: vec3, previous: vec4) -> vec2 { let current = globals.view_proj * vec4(pos, 1.0); if current.w <= 0.0 || previous.w <= 0.0 { return vec2(0.0); } diff --git a/crates/horizon-client/src/gfx/hd/dlss.rs b/crates/horizon-client/src/gfx/hd/dlss.rs index 65db70f99..ad4f282d4 100644 --- a/crates/horizon-client/src/gfx/hd/dlss.rs +++ b/crates/horizon-client/src/gfx/hd/dlss.rs @@ -7,6 +7,26 @@ use dlss_wgpu::{ }; use std::sync::{Arc, Mutex}; +/// NGX's input contract for this renderer, from the NVIDIA DLSS Programming Guide +/// (31 March 2026, the SDK 310.x `dlss_wgpu` 6 wraps): +/// - Motion vectors map current→previous in *render-resolution pixels*, origin top-left, y down +/// (§3.6/3.6.1) — exactly the G-buffer's buffer, so `motion_vector_scale` stays [1, 1] (§3.6.3: +/// 1.0 when no scaling is needed; the pixel→clip normalisation some wrappers document is theirs, +/// not NGX's). +/// - The buffer *includes* both frames' jitter (a still surface carries their difference). NGX +/// must be told with `MVJittered`: it then subtracts the jitter difference itself using the +/// per-evaluate `jitter_offset` (§3.6.2). Without the flag it uses the vectors unadjusted while +/// still applying the jitter offset — the camera jitter is counted twice and the image shakes. +/// - `jitter_offset` is the current frame's projection jitter in render pixels, same coordinate +/// system as the vectors, within ±0.5 (§3.7.3) — `scene.jitter_px` as passed. +/// - Render-resolution motion vectors take `MVLowRes` (NGX dilates them itself, §3.6.2); the +/// camera's reversed-Z takes `DepthInverted` (§3.8.1); the linearised HDR colour takes `IsHDR`. +const FEATURE_FLAGS: DlssFeatureFlags = DlssFeatureFlags::LowResolutionMotionVectors + .union(DlssFeatureFlags::JitteredMotionVectors) + .union(DlssFeatureFlags::InvertedDepth) + .union(DlssFeatureFlags::HighDynamicRange) + .union(DlssFeatureFlags::AutoExposure); + const COLOR: &str = include_str!("dlss_color.wgsl"); // The conversion shaders sample with `textureSampleLevel` and the filtering `linear` sampler, so // the source must be a filterable float texture (HDR is Rgba16Float). A non-filterable binding @@ -175,18 +195,10 @@ impl Dlss { self.world = world; self.out = out; self.convert.resize(device, world, out); - // NGX receives the motion buffer as written: current-to-previous in jittered render - // pixels, the current jitter passed separately as `jitter_offset`. Whether it wants the - // jitter inside the vectors is its own input contract, verified on this path separately - // (#137) — not inferred here, and these flags are left as they are. - let flags = DlssFeatureFlags::LowResolutionMotionVectors - | DlssFeatureFlags::InvertedDepth - | DlssFeatureFlags::HighDynamicRange - | DlssFeatureFlags::AutoExposure; match DlssSuperResolution::new( out, DlssPerfQualityMode::Auto, - flags, + FEATURE_FLAGS, self.sdk.clone(), device, queue, @@ -228,8 +240,11 @@ impl Dlss { bias: None, dlss_output: &self.convert.output, reset, + // The current jitter in render pixels (§3.7.3); with `JitteredMotionVectors` NGX + // removes the two frames' jitter difference from the buffer itself (§3.6.2). jitter_offset: jitter, partial_texture_size: Some(self.world), + // The buffer is already in render pixels, the units NGX expects (§3.6.1, §3.6.3). motion_vector_scale: Some([1.0, 1.0]), }; let commands = context.render(params, encoder, adapter).map_err(|e| e.to_string())?; @@ -237,3 +252,21 @@ impl Dlss { Ok(commands) } } +#[cfg(test)] +mod tests { + use super::*; + + /// The G-buffer's motion vectors carry both frames' jitter, so NGX must be told to remove + /// it (DLSS Programming Guide §3.6.2); without `JitteredMotionVectors` the jitter offset is + /// applied on top of the jittered vectors and the whole image shakes. The other flags match + /// the inputs as recorded: render-resolution vectors (§3.6.2), reversed-Z (§3.8.1), the + /// linearised HDR colour, and NGX-side auto-exposure. + #[test] + fn the_feature_flags_match_the_motion_contract() { + assert!(FEATURE_FLAGS.contains(DlssFeatureFlags::JitteredMotionVectors)); + assert!(FEATURE_FLAGS.contains(DlssFeatureFlags::LowResolutionMotionVectors)); + assert!(FEATURE_FLAGS.contains(DlssFeatureFlags::InvertedDepth)); + assert!(FEATURE_FLAGS.contains(DlssFeatureFlags::HighDynamicRange)); + assert!(FEATURE_FLAGS.contains(DlssFeatureFlags::AutoExposure)); + } +} diff --git a/crates/horizon-client/src/gfx/hd/mod.rs b/crates/horizon-client/src/gfx/hd/mod.rs index 0300fb519..d845cc20d 100644 --- a/crates/horizon-client/src/gfx/hd/mod.rs +++ b/crates/horizon-client/src/gfx/hd/mod.rs @@ -58,8 +58,8 @@ //! jittered grid) uses it as written; `fs_taau` (history on the stable output grid) adds the //! current jitter and subtracts the previous one (`HdFrame.prev_jitter`), leaving a still //! surface on the same output pixel on every phase. The DLSS backend receives the buffer -//! unchanged with the current jitter alongside; NGX's input contract is checked on that path -//! separately (#137), not inferred here. +//! unchanged and is told it carries jitter (`MVJittered`, `dlss.rs`): NGX subtracts the jitter +//! difference itself from the per-frame `jitter_offset` (DLSS Programming Guide §3.6.2/§3.7.3). //! - **Time.** `frame counter` (`HdFrame.params.w`, modulo 64, only for noise rotation); *water time* //! (`water.y`, wall-clock seconds since HD started modulo 600); *game time* (`clouds.w`, seconds //! from `HdScene::seconds` modulo 300000, drives cloud wind). They are separate on purpose: