HD: the Resolution Scale slider drives the world render size, DLSS included

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>
This commit is contained in:
2026-11-22 12:05:04 +03:00
parent 182d553508
commit 4e441de6af
5 changed files with 187 additions and 21 deletions
+15 -4
View File
@@ -4661,6 +4661,15 @@ impl Renderer {
&& frame.hd.is_some()
&& !self.pack_post.as_ref().is_some_and(|p| p.1.is_some())
&& !self.native.as_ref().is_some_and(|n| n.post.is_some());
// AirDef fork: HD's world scale this frame — the Resolution Scale slider reconciled with
// film quality, HORIZON_HD_SCALE and DLSS (`hd::scale_override`). Decided before the
// jitter and the motion globals so both match the size the world renders at this frame,
// and re-decided every frame so moving the slider resizes the world (and DLSS) live.
self.world_post.hd_scale = if hd_wanted {
hd::scale_override(self.world_post.scale)
} else {
None
};
// AirDef fork: HD's temporal anti-aliasing shifts the whole projection by a sub-pixel
// offset each frame; `unjittered` is what the next frame reprojects a stable history with.
// The motion buffer keeps both frames' jitter (Globals.prev_view_proj is the previous
@@ -4679,7 +4688,7 @@ impl Renderer {
let mut jitter_px = [0.0; 2];
let view_proj = if taa {
let window = [self.config.width, self.config.height];
let size = self.world_post.size().unwrap_or(window);
let size = self.world_post.scaled_size(window);
// Upscaling (the world smaller than the window) cycles through more positions.
let ratio = window[0] as f32 / size[0].max(1) as f32;
let j = hd::jitter(self.taa_frame, size, hd::jitter_count(ratio));
@@ -4808,7 +4817,9 @@ impl Renderer {
[d.x, d.y, d.z, 0.0]
},
hd_motion: {
let size = self.world_post.size().unwrap_or([self.config.width, self.config.height]);
let size = self
.world_post
.scaled_size([self.config.width, self.config.height]);
// zw: the previous frame's wind (seconds, strength) for the motion vectors; this
// frame's when there is no previous one, so the wind's own motion is zero then.
let was = taa_prev.map_or(wind_now, |p| p.4);
@@ -5855,8 +5866,8 @@ impl Renderer {
.as_ref()
.and_then(|p| p.1.as_ref())
.is_some_and(|p| p.has_weather());
// AirDef fork: HD renders the world at its own scale and upscales it in the TAA pass.
self.world_post.hd_scale = hd_on.then(hd::scale_override).flatten();
// AirDef fork: HD renders the world at its own scale and upscales it in the TAA pass;
// `hd_scale` was decided with the jitter above, so the target matches it this frame.
let scaled = self.world_post.prepare(
&self.device,
[self.config.width, self.config.height],
+20
View File
@@ -1,5 +1,8 @@
//! DLSS Super Resolution behind the native TAA interface. NGX never sees the display-space
//! colour used by Horizon: two small conversion passes bracket its command buffer.
//! The render size is the world target's (the Resolution Scale slider, `hd::scale_override`:
//! DLSS caps it at the output, an upscaler renders no larger); it reaches NGX per evaluate as
//! `partial_texture_size`, and `resize` follows it live.
use super::{entries, module, target, FLOAT, SAMPLER};
use dlss_wgpu::{
DlssFeatureFlags, DlssPerfQualityMode, DlssSdk,
@@ -188,6 +191,13 @@ impl Dlss {
self.failed = true;
}
/// The render size (`world`, the Resolution Scale slider's world target) and the output
/// size (`out`, the window). The context belongs to the output size; the render size rides
/// along per evaluate (`partial_texture_size`), so a slider move resizes the conversion
/// targets and keeps the context while the new render size fits its dynamic-resolution
/// range — recreating it waits the device idle (`DlssSuperResolution::drop`), which a live
/// slider would feel. The caller resets the history on any resize, so the first evaluate
/// after a scale change starts NGX over (`InReset`).
pub fn resize(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, world: [u32; 2], out: [u32; 2]) {
if self.world == world && self.out == out {
return;
@@ -195,6 +205,16 @@ impl Dlss {
self.world = world;
self.out = out;
self.convert.resize(device, world, out);
let fits = self.context.as_ref().is_some_and(|c| {
let range = c.render_resolution_range();
let (min, max) = (range.start(), range.end());
c.upscaled_resolution() == out
&& (0..2).all(|i| world[i] >= min[i] && world[i] <= max[i])
});
if fits {
log::info!("DLSS Super Resolution: {world:?} -> {out:?}");
return;
}
match DlssSuperResolution::new(
out,
DlssPerfQualityMode::Auto,
+2 -1
View File
@@ -18,7 +18,8 @@
//! # Contracts (the same words are repeated at the top of each pass file)
//!
//! Frame order and what each pass reads (R) and writes (W). Sizes: *world* = the scaled world target
//! (`HORIZON_HD_SCALE`), *out* = the window.
//! (the Resolution Scale slider via `hd::scale_override`; `HORIZON_HD_SCALE` overrides it),
//! *out* = the window (or the world itself when it is supersampled larger).
//!
//! | # | Pass | R | W |
//! |---|---|---|---|
+69 -12
View File
@@ -73,23 +73,53 @@ fn halton(mut index: u32, base: u32) -> f32 {
/// are kept than without; `fs_taau` lowers it where the frame's sample is near).
pub(super) const UPSCALE_HISTORY: f32 = 0.92;
/// The world's size relative to the output (`HORIZON_HD_SCALE`, per axis, 0.25..=1) while HD is on, if
/// set: it replaces the resolution scale of Horizon's settings for HD. 1 renders at full size.
pub fn scale_override() -> Option<f32> {
// Film quality renders the world at the window's full size.
if film_quality() {
return Some(1.0);
}
/// The `HORIZON_HD_SCALE` environment override (per axis, 0.25..=1), read once at its first
/// use: an explicit launch-time choice for probes and weak GPUs, it wins over the slider.
fn env_scale() -> Option<f32> {
static SCALE: std::sync::OnceLock<Option<f32>> = std::sync::OnceLock::new();
let configured = *SCALE.get_or_init(|| {
*SCALE.get_or_init(|| {
let v: f32 = std::env::var("HORIZON_HD_SCALE").ok()?.parse().ok()?;
v.is_finite().then(|| v.clamp(0.25, 1.0))
});
})
}
/// HD's world scale for this frame, given the player's Resolution Scale slider
/// (`world_post.scale`, 0.25..=2.0). `None`: the slider applies unchanged. Precedence,
/// first match wins:
/// 1. film quality — a capture renders the world at the window's full size;
/// 2. `HORIZON_HD_SCALE` — the explicit environment override;
/// 3. DLSS evaluating — an upscaler renders no larger than its output, so the slider drives
/// the render size capped at 1: at the slider's default (100%) DLSS keeps its own 2/3
/// auto ratio, any other value is the render scale, and above 100% the world renders at
/// the output size (supersampling is the native TAAU's, with DLSS off);
/// 4. otherwise the slider itself, including above 1 (supersampling) — `None`.
///
/// The slider is read every frame, so moving it resizes the world target and DLSS's render
/// size live; only the environment override is frozen at its first read.
pub fn scale_override(slider: f32) -> Option<f32> {
#[cfg(all(feature = "dlss", any(windows, target_os = "linux")))]
if configured.is_none() && crate::gfx::dlss_enabled() && crate::gfx::dlss_ready() {
return Some(2.0 / 3.0);
let dlss = crate::gfx::dlss_enabled() && crate::gfx::dlss_ready();
#[cfg(not(all(feature = "dlss", any(windows, target_os = "linux"))))]
let dlss = false;
scale_for(slider, env_scale(), film_quality(), dlss)
}
/// The scale precedence as a pure decision, so every branch is unit-testable on any platform.
fn scale_for(slider: f32, env: Option<f32>, film: bool, dlss: bool) -> Option<f32> {
if film {
return Some(1.0);
}
configured
if let Some(v) = env {
return Some(v.clamp(0.25, 1.0));
}
if dlss {
return Some(if slider == 1.0 {
2.0 / 3.0
} else {
slider.clamp(0.25, 1.0)
});
}
None
}
static FILM: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
@@ -467,6 +497,33 @@ mod tests {
assert_eq!(seen.len(), count as usize);
}
/// The Resolution Scale slider drives HD's world size: on the native TAAU path it applies
/// as-is (including above 1, supersampling); with DLSS evaluating it is the render size
/// capped at the output — an upscaler renders no larger — and the slider's default 100%
/// keeps DLSS's 2/3 auto ratio. The `HORIZON_HD_SCALE` override and film quality win over
/// the slider. This is the bug fix: DLSS used to pin the world at 2/3 whatever the slider.
#[test]
fn the_resolution_slider_drives_hd_scale() {
// Native TAAU: the slider applies unchanged (`None` = `world_post.scale`).
for slider in [0.5, 0.8, 1.0, 1.5, 2.0] {
assert_eq!(scale_for(slider, None, false, false), None);
}
// DLSS: the slider is the render size, capped at the output.
assert_eq!(scale_for(0.5, None, false, true), Some(0.5));
assert_eq!(scale_for(0.8, None, false, true), Some(0.8));
assert_eq!(scale_for(1.5, None, false, true), Some(1.0));
assert_eq!(scale_for(2.0, None, false, true), Some(1.0));
// At the slider's default 100%, DLSS keeps its auto ratio.
assert_eq!(scale_for(1.0, None, false, true), Some(2.0 / 3.0));
// The environment override wins over the slider and DLSS's auto.
assert_eq!(scale_for(0.5, Some(0.75), false, false), Some(0.75));
assert_eq!(scale_for(1.0, Some(0.75), false, true), Some(0.75));
assert_eq!(scale_for(2.0, Some(0.75), false, true), Some(0.75));
// Film quality renders at full size whatever the slider says.
assert_eq!(scale_for(0.5, None, true, false), Some(1.0));
assert_eq!(scale_for(0.5, Some(0.75), true, true), Some(1.0));
}
/// The native history starts unusable, becomes usable once the native pass writes it, and a
/// cut/teleport/resize/TAA-off (`reset`) starts it over. This is what drives `HdFrame.taa.w`.
#[test]
+81 -4
View File
@@ -16,9 +16,10 @@ pub struct Post {
copy: wgpu::RenderPipeline,
fxaa: wgpu::RenderPipeline,
format: wgpu::TextureFormat,
/// World resolution relative to the window (0.5..=2.0).
/// World resolution relative to the window (0.5..=2.0): the Resolution Scale slider.
pub scale: f32,
/// HD's own scale for this frame (`HORIZON_HD_SCALE`), instead of `scale`.
/// HD's scale decision for this frame instead of `scale` (`hd::scale_override`: film
/// quality, `HORIZON_HD_SCALE`, or the slider reconciled with DLSS). `None`: the slider.
pub hd_scale: Option<f32>,
pub antialias: bool,
target: Option<WorldTarget>,
@@ -102,6 +103,18 @@ impl Post {
}
}
/// The scale the world renders at this frame: HD's decision when set, else the slider.
pub fn effective_scale(&self) -> f32 {
self.hd_scale.unwrap_or(self.scale)
}
/// The world target's size for a window at `effective_scale` — what `prepare` builds.
/// The TAA jitter reads it before `prepare` runs, so it matches the size this frame draws.
pub fn scaled_size(&self, window: [u32; 2]) -> [u32; 2] {
let scale = self.effective_scale();
window.map(|v| ((v as f32 * scale).round() as u32).clamp(1, 8192))
}
/// The world's colour and depth targets this frame, or `None` to draw
/// it straight to the screen.
/// `always`: a target even at scale 1 without FXAA (a shader pack reads it).
@@ -111,12 +124,12 @@ impl Post {
window: [u32; 2],
always: bool,
) -> Option<(wgpu::TextureView, wgpu::TextureView)> {
let scale = self.hd_scale.unwrap_or(self.scale);
let scale = self.effective_scale();
if scale == 1.0 && !self.antialias && !always {
self.target = None;
return None;
}
let size = window.map(|v| ((v as f32 * scale).round() as u32).clamp(1, 8192));
let size = self.scaled_size(window);
if self.target.as_ref().is_none_or(|t| t.size != size) {
let extent = wgpu::Extent3d {
width: size[0],
@@ -220,3 +233,67 @@ impl Post {
pass.draw(0..3, 0..1);
}
}
#[cfg(test)]
mod tests {
use super::*;
/// The Resolution Scale slider resizes the world target live: `prepare` at 50 / 100 / 200%
/// builds targets of exactly those sizes (HD reads the target even at 100%, `always`), and
/// HD's per-frame decision (`hd_scale`, `hd::scale_override`) replaces the slider when set —
/// DLSS's auto ratio, the env override, film quality. Without HD, scale 1 and no FXAA still
/// draw straight to the screen. Needs a GPU adapter:
/// `cargo test -p horizon-client --lib gfx::world_post::tests:: -- --ignored`.
#[test]
#[ignore = "requires a Vulkan/Metal/DX12 adapter"]
fn the_world_target_follows_the_resolution_slider() {
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle());
let Ok(adapter) =
pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions::default()))
else {
eprintln!("no GPU adapter; skipping the world-target scale test");
return;
};
eprintln!("world-target scale adapter: {:?}", adapter.get_info());
let (device, _queue) =
pollster::block_on(adapter.request_device(&wgpu::DeviceDescriptor::default())).unwrap();
let window = [1920u32, 1080];
let mut post = Post::new(&device, wgpu::TextureFormat::Rgba8UnormSrgb);
// The slider at 50 / 100 / 200%: three different world sizes, on the same Post.
for (percent, size) in [(50, [960, 540]), (100, [1920, 1080]), (200, [3840, 2160])] {
post.scale = percent as f32 / 100.0;
post.hd_scale = None;
assert_eq!(post.scaled_size(window), size, "slider at {percent}%");
assert!(post.prepare(&device, window, true).is_some());
assert_eq!(post.size(), Some(size), "slider at {percent}%");
}
// Live: moving the slider resizes the existing target, no restart.
post.scale = 0.8;
post.prepare(&device, window, true);
assert_eq!(post.size(), Some([1536, 864]));
// HD's decision replaces the slider: DLSS's 2/3 auto ratio at the default 100%...
post.scale = 1.0;
post.hd_scale = Some(2.0 / 3.0);
post.prepare(&device, window, true);
assert_eq!(post.size(), Some([1280, 720]));
// ...the slider under DLSS (50% renders at half, 200% caps at the output)...
post.scale = 0.5;
post.hd_scale = Some(0.5);
post.prepare(&device, window, true);
assert_eq!(post.size(), Some([960, 540]));
post.scale = 2.0;
post.hd_scale = Some(1.0);
post.prepare(&device, window, true);
assert_eq!(post.size(), Some(window));
// ...and film quality's full size.
post.hd_scale = Some(1.0);
post.prepare(&device, window, true);
assert_eq!(post.size(), Some(window));
// Without HD (`always` false), scale 1 and no FXAA draw straight to the screen.
post.hd_scale = None;
post.scale = 1.0;
post.antialias = false;
assert!(post.prepare(&device, window, false).is_none());
assert_eq!(post.size(), None);
}
}