DLSS: declare the jittered motion vectors (MVJittered)
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>
This commit is contained in:
@@ -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<f32>, previous: vec4<f32>) -> vec2<f32> {
|
||||
let current = globals.view_proj * vec4(pos, 1.0);
|
||||
if current.w <= 0.0 || previous.w <= 0.0 { return vec2<f32>(0.0); }
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user