diff --git a/crates/cargo-horizon-mod/src/check.rs b/crates/cargo-horizon-mod/src/check.rs index e94868348..c87df1b4c 100644 --- a/crates/cargo-horizon-mod/src/check.rs +++ b/crates/cargo-horizon-mod/src/check.rs @@ -291,6 +291,9 @@ fn play(path: &Path, report: &mut Report) -> Result<(), String> { Output::SetAcoustics { on } => { format!("turned acoustics {}", if on { "on" } else { "off" }) } + Output::SetDlss { on } => { + format!("turned DLSS {}", if on { "on" } else { "off" }) + } }); } let shapes = mods.hud_shapes().count(); diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 0db1f8607..42a2f8459 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -15119,6 +15119,9 @@ fn start_game<'a>( Some(settings) => settings, None => Settings::load(&std::env::current_dir()?.join("options.txt")), }; + // AirDef fork: the persisted DLSS choice seeds the renderer's startup + // gate before the first device opens (`HORIZON_DLSS` still overrides it). + horizon_client::gfx::configure_dlss(settings.horizon.dlss); if let Some(d) = options.distance_override { settings.render_distance = d; } diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs index d778fe856..285bec65b 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -37,6 +37,7 @@ const HELP: &[&str] = &[ "options [PAGE] open the options (video sound controls keybinds mouse chat accessibility language font packs mods graphics graphics-advanced)", "stats [reset|raw] frame-time summary since the last reset (raw: every frame/cpu/gpu time too)", "model-instancing on|off GPU instancing of the mod models' mass group (#147 diagnostic; off = per-vertex fallback)", + "dlss [on|off|status] NVIDIA DLSS upscaling (default on where supported; off = native TAAU live; on after an off start applies at the next launch)", "bench SECONDS reset stats, wait, then reply with the summary", "fly X1 Y1 Z1 X2 Y2 Z2 SECONDS [PITCH [raw]] fly the camera along a line at constant speed, then reply with the frame summary (raw: every frame time too)", "open WORLD [SEED] [creative] open or create a world from the title screen", @@ -783,6 +784,36 @@ impl Game<'_> { horizon_client::gfx::set_model_instancing(on); Ok(Some(json!({ "model_instancing": on }))) } + "dlss" => { + // AirDef fork: the player's DLSS toggle, persisted in + // horizon-graphics.txt. Off evaluates the native TAAU from + // the next frame (the #137 histories make the switch clean); + // on after a start with DLSS off applies at the next launch, + // when the device is opened for DLSS. Without a DLSS device + // the request is a graceful no-op. + let available = horizon_client::gfx::dlss_ready(); + match words.get(1).copied() { + None | Some("status") => Ok(Some(json!({ + "dlss": horizon_client::gfx::dlss_enabled(), + "available": available, + }))), + Some(word) => { + let on = match word { + "on" => true, + "off" => false, + other => return Err(format!("dlss needs on|off, not {other}").into()), + }; + horizon_client::gfx::set_dlss(on); + self.settings.horizon.dlss = on; + self.settings.save(&Self::options_path()); + Ok(Some(json!({ + "dlss": on, + "available": available, + "live": on && available, + }))) + } + } + } "bench" => { let seconds: f64 = arg(1)?.parse()?; if self.pending_bench.is_some() { diff --git a/crates/horizon-client/src/game/mods.rs b/crates/horizon-client/src/game/mods.rs index bb8521240..16ea628df 100644 --- a/crates/horizon-client/src/game/mods.rs +++ b/crates/horizon-client/src/game/mods.rs @@ -885,6 +885,9 @@ impl Game<'_> { .set_source_generation(self.audio.mod_sources.epoch); self.mods.mods.set_acoustics(self.audio.acoustics.is_some()); self.mods.mods.set_acoustics_output_ready(self.audio.acoustics_output_ready()); + self.mods + .mods + .set_dlss_status(horizon_client::gfx::dlss_ready(), horizon_client::gfx::dlss_enabled()); let t4 = Instant::now(); self.mods.mods.tick(self.ticks); let t5 = Instant::now(); @@ -1103,6 +1106,9 @@ impl Game<'_> { .set_source_generation(self.audio.mod_sources.epoch); self.mods.mods.set_acoustics(self.audio.acoustics.is_some()); self.mods.mods.set_acoustics_output_ready(self.audio.acoustics_output_ready()); + self.mods + .mods + .set_dlss_status(horizon_client::gfx::dlss_ready(), horizon_client::gfx::dlss_enabled()); self.mods.mods.frame(elapsed.as_secs_f32()); self.canvas_frame(); self.show_mod_output(); @@ -1278,6 +1284,14 @@ impl Game<'_> { self.audio.set_acoustics(on); continue; } + Output::SetDlss { on } => { + // AirDef fork: the mod settings' DLSS toggle — live for + // the evaluation, persisted for the next start's device. + horizon_client::gfx::set_dlss(on); + self.settings.horizon.dlss = on; + self.settings.save(&Self::options_path()); + continue; + } Output::PlaceRecipe { book_id, all } => { self.mod_place_recipe(book_id, all); continue; diff --git a/crates/horizon-client/src/gfx.rs b/crates/horizon-client/src/gfx.rs index fa5b3af58..96769e875 100644 --- a/crates/horizon-client/src/gfx.rs +++ b/crates/horizon-client/src/gfx.rs @@ -67,6 +67,63 @@ pub fn set_model_instancing(on: bool) { MODEL_INSTANCING.store(on, std::sync::atomic::Ordering::Relaxed); } +/// AirDef fork: the player's DLSS request, live. On by default; the startup +/// decision (`horizon-graphics.txt`'s `dlss` and `HORIZON_DLSS`) seeds it +/// once at renderer startup, on every build. Off evaluates the +/// native TAAU instead — the #137 separated histories make the switch clean +/// in both directions: a native frame leaves NGX's history stale (it resets +/// when DLSS resumes), a DLSS frame leaves the native history unusable (the +/// first fallback frame starts over). The `dlss` control command and the +/// mods' `render.set-dlss` drive it; without a DLSS device it is a graceful +/// no-op, and an on-switch after a start with DLSS off applies at the next +/// launch, when the device is opened for DLSS. +static DLSS_ENABLED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(true); +/// Whether a renderer actually opened a DLSS SDK (compiled, supported and +/// initialized): the resolution default and the status reports follow it, +/// so a requested-but-unavailable DLSS never changes the picture's scale. +static DLSS_READY: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false); + +/// Read the startup decision once, at renderer startup. +pub fn init_dlss_enabled() { + static INIT: std::sync::OnceLock<()> = std::sync::OnceLock::new(); + INIT.get_or_init(|| { + DLSS_ENABLED.store(dlss_startup_decision(), std::sync::atomic::Ordering::Relaxed); + }); +} + +pub fn dlss_enabled() -> bool { + DLSS_ENABLED.load(std::sync::atomic::Ordering::Relaxed) +} + +/// The live DLSS toggle: off falls back to the native TAAU from the next frame. +pub fn set_dlss(on: bool) { + DLSS_ENABLED.store(on, std::sync::atomic::Ordering::Relaxed); +} + +pub fn dlss_ready() -> bool { + DLSS_READY.load(std::sync::atomic::Ordering::Relaxed) +} + +/// The persisted `dlss` graphics setting (`horizon-graphics.txt`), fed before +/// the first renderer starts. On by default; every build honours it, so the +/// request a status report shows survives a restart even without DLSS. +static DLSS_CONFIGURED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(true); + +pub fn configure_dlss(on: bool) { + DLSS_CONFIGURED.store(on, std::sync::atomic::Ordering::Relaxed); +} + +/// The startup decision: `HORIZON_DLSS=1|0` overrides the persisted choice. +/// Seeds the live gate on every build and, where DLSS is compiled, the +/// device opening too (`dlss::requested`). +fn dlss_startup_decision() -> bool { + match std::env::var("HORIZON_DLSS").as_deref() { + Ok("1") => true, + Ok("0") => false, + _ => DLSS_CONFIGURED.load(std::sync::atomic::Ordering::Relaxed), + } +} + #[cfg(test)] mod crumbling_tests; mod entity_batch; @@ -1056,14 +1113,21 @@ async fn open_device( } #[cfg(all(feature = "dlss", any(windows, target_os = "linux")))] let mut dlss_support = dlss_wgpu::FeatureSupport::default(); + #[cfg(all(feature = "dlss", any(windows, target_os = "linux")))] + let mut dlss_wanted = dlss::requested() && backends == wgpu::Backends::VULKAN; let instance = { #[cfg(all(feature = "dlss", any(windows, target_os = "linux")))] - if dlss::requested() && backends == wgpu::Backends::VULKAN { + if dlss_wanted { match dlss::create_instance(&instance_descriptor(backends), &mut dlss_support) { Ok(instance) => instance, Err(e) => { - failures.push(format!("{name} DLSS instance: {e}")); - continue; + // DLSS is a preference, not a requirement: keep this + // backend and fall back to the native TAAU instead + // of skipping Vulkan for the next API in the order. + log::warn!("DLSS unavailable, using native TAAU: {e}"); + dlss_wanted = false; + dlss_support = dlss_wgpu::FeatureSupport::default(); + wgpu::Instance::new(instance_descriptor(backends)) } } } else { @@ -1147,8 +1211,14 @@ async fn open_device( None => adapter.request_device(&desc).await, }; #[cfg(all(feature = "dlss", any(windows, target_os = "linux")))] - let opened = if dlss::requested() && info.backend == wgpu::Backend::Vulkan { - dlss::request_device(&adapter, &desc, &mut dlss_support) + let opened = if dlss_wanted && info.backend == wgpu::Backend::Vulkan { + match dlss::request_device(&adapter, &desc, &mut dlss_support) { + Ok(opened) => Ok(opened), + Err(e) => { + log::warn!("DLSS unavailable, using native TAAU: {e}"); + opened.map_err(|e| e.to_string()) + } + } } else { opened.map_err(|e| e.to_string()) }; @@ -1250,6 +1320,7 @@ impl Renderer { hd_materials: hd::MaterialTable, ) -> Result { init_model_instancing(); + init_dlss_enabled(); let split = sprite_split(); if layers > split * SPRITE_ARRAYS { return Err(format!( @@ -1313,6 +1384,8 @@ impl Renderer { } } }; + #[cfg(all(feature = "dlss", any(windows, target_os = "linux")))] + DLSS_READY.store(dlss_sdk.is_some(), std::sync::atomic::Ordering::Relaxed); let info = adapter.get_info(); crate::graphics::suggest_reduced_far_detail(crate::graphics::lod_capped(&info)); let size = window.inner_size(); @@ -7223,6 +7296,22 @@ fn frustum(m: Mat4) -> [Vec4; 6] { #[cfg(test)] mod tests { + /// AirDef fork: the live DLSS toggle stores the player's request; the + /// renderer's readiness is a separate fact, so a requested-but-unavailable + /// DLSS stays a graceful no-op (native TAAU, the settings' own scale). + #[test] + fn the_dlss_toggle_stores_the_request_independently_of_readiness() { + let was = super::dlss_enabled(); + super::set_dlss(false); + assert!(!super::dlss_enabled()); + super::set_dlss(true); + assert!(super::dlss_enabled()); + super::set_dlss(was); + // No lib test opens a DLSS renderer, so readiness stays off. + #[cfg(not(all(feature = "dlss", any(windows, target_os = "linux"))))] + assert!(!super::dlss_ready()); + } + /// #137: the GPU must run the world (and DLSS's linearize) before NGX, and every consumer of /// the resolved frame after the delinearize. Without DLSS the frame stays a single buffer. #[test] diff --git a/crates/horizon-client/src/gfx/dlss.rs b/crates/horizon-client/src/gfx/dlss.rs index 06f13cfe4..b8112ac07 100644 --- a/crates/horizon-client/src/gfx/dlss.rs +++ b/crates/horizon-client/src/gfx/dlss.rs @@ -5,9 +5,13 @@ use wgpu::{Adapter, Device, DeviceDescriptor, Instance, InstanceDescriptor, Queu pub const PROJECT_ID: Uuid = Uuid::from_u128(0x7c35_0b91_38a4_4f8e_8c4a_66f2_5df9_1240); +/// Whether the renderer should open its device for DLSS at this start: the +/// same decision that seeds the live gate (`gfx::init_dlss_enabled`), from +/// `horizon-graphics.txt` and `HORIZON_DLSS=1|0`. Read once; the live +/// evaluation switch is `gfx::set_dlss`. pub fn requested() -> bool { static ON: std::sync::OnceLock = std::sync::OnceLock::new(); - *ON.get_or_init(|| std::env::var("HORIZON_DLSS").is_ok_and(|v| v == "1")) + *ON.get_or_init(super::dlss_startup_decision) } pub fn create_instance( diff --git a/crates/horizon-client/src/gfx/hd/taa.rs b/crates/horizon-client/src/gfx/hd/taa.rs index 5a638895d..2c76a0a6e 100644 --- a/crates/horizon-client/src/gfx/hd/taa.rs +++ b/crates/horizon-client/src/gfx/hd/taa.rs @@ -25,6 +25,9 @@ //! world encoder before NGX and records every consumer of the resolved frame after the //! delinearize, all in one submit (#137). Native TAA is the fallback; a DLSS frame leaves the //! native history unusable (`HistoryReady`) so the first fallback frame does not read it stale. +//! The player's `dlss` toggle (`gfx::set_dlss`) switches the evaluation live: off takes the +//! native path from the next frame, on resumes NGX with a history reset — no restart needed +//! while the device was opened for DLSS at the start. use super::{ DEPTH, FLOAT, HDR, Hd, HdSource, SAMPLER, UNFILTERED, UNIFORM, entries, module, stamp, }; @@ -78,7 +81,7 @@ pub fn scale_override() -> Option { v.is_finite().then(|| v.clamp(0.25, 1.0)) }); #[cfg(all(feature = "dlss", any(windows, target_os = "linux")))] - if configured.is_none() && crate::gfx::dlss::requested() { + if configured.is_none() && crate::gfx::dlss_enabled() && crate::gfx::dlss_ready() { return Some(2.0 / 3.0); } configured @@ -303,7 +306,7 @@ impl Hd { HdSource::Taa | HdSource::Film => return source, }; #[cfg(all(feature = "dlss", any(windows, target_os = "linux")))] - if self.taa.dlss.as_ref().is_some_and(dlss::Dlss::available) + if crate::gfx::dlss_enabled() && self.taa.dlss.as_ref().is_some_and(dlss::Dlss::available) { let mut after = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: Some("HD DLSS output conversion"), @@ -507,6 +510,25 @@ mod tests { assert!(h.dlss_reset()); } + /// The live `dlss` toggle (`gfx::set_dlss`): off evaluates the native TAAU from the next + /// frame, on resumes NGX — the separated histories make both directions clean without a + /// renderer restart, the same contract the per-frame DLSS failure fallback relies on. + #[cfg(all(feature = "dlss", any(windows, target_os = "linux")))] + #[test] + fn the_live_toggle_switches_histories_cleanly_both_ways() { + let mut h = HistoryReady::default(); + h.after_dlss(); + // Off: the first native frame must not blend the stale native textures. + assert!(!h.native_usable()); + h.after_native(); + assert!(h.native_usable()); + // On again: NGX's history is stale after the native frames, so it resets. + assert!(h.dlss_reset()); + h.after_dlss(); + assert!(!h.dlss_reset()); + assert!(!h.native_usable()); + } + // #143: the motion buffer's coordinate contract, checked numerically on every jitter phase. // The helpers mirror the shaders' math: `motion_pixels` (terrain.wgsl / entity.wgsl) writes // current→previous in jittered render pixels; `taa_lookup` is fs_taa's decode (history on the diff --git a/crates/horizon-client/src/graphics.rs b/crates/horizon-client/src/graphics.rs index f3e4c9487..b6e2cc8c2 100644 --- a/crates/horizon-client/src/graphics.rs +++ b/crates/horizon-client/src/graphics.rs @@ -274,6 +274,13 @@ pub struct Graphics { pub battery: bool, /// The graphics API (Windows only; see `GraphicsApi`). pub api: GraphicsApi, + /// NVIDIA DLSS upscaling instead of the native TAAU, where the renderer + /// offers it (the `dlss` feature on a Vulkan RTX device). On by default; + /// `HORIZON_DLSS=1|0` overrides it at the start. The device is opened for + /// DLSS at the start only while this is on; the `dlss` control command + /// and the mods' `render.set-dlss` switch the evaluation live, and a + /// start with it off applies an on-switch at the next launch. + pub dlss: bool, /// The shader pack picked in `shaderpacks/` (`shader_pack_list`); empty: none. Its key is /// not `shaderPack`, which versions before the clean-room rewrite saved and which stays /// ignored. @@ -304,6 +311,7 @@ impl Default for Graphics { hdr_peak: 1000, battery: false, api: GraphicsApi::Auto, + dlss: true, shader_pack: String::new(), } } @@ -366,6 +374,7 @@ impl Graphics { "hdrPeak" => g.hdr_peak = number(g.hdr_peak).clamp(200, 2000), "batteryMode" => g.battery = flag(g.battery), "graphicsApi" => g.api = GraphicsApi::from_name(value).unwrap_or_default(), + "dlss" => g.dlss = flag(g.dlss), "pickedShaderPack" => g.shader_pack = value.to_owned(), "overlay" => { g.overlay = match value { @@ -381,7 +390,7 @@ impl Graphics { } pub fn serialize(&self) -> String { format!( - "preset:{}\nlodDistance:{}\nfarDetail:{}\ncaveCulling:{}\nentityCulling:{}\nchunkUpdates:{}\nuploadBudgetKiB:{}\nsky:{}\nfog:{}\nweather:{}\nanimatedTextures:{}\npresentMode:{}\nframePacing:{}\nworkers:{}\noverlay:{}\nresolutionScale:{}\nfxaa:{}\nhdr:{}\nhdrPaperWhite:{}\nhdrPeak:{}\nbatteryMode:{}\ngraphicsApi:{}\npickedShaderPack:{}\n", + "preset:{}\nlodDistance:{}\nfarDetail:{}\ncaveCulling:{}\nentityCulling:{}\nchunkUpdates:{}\nuploadBudgetKiB:{}\nsky:{}\nfog:{}\nweather:{}\nanimatedTextures:{}\npresentMode:{}\nframePacing:{}\nworkers:{}\noverlay:{}\nresolutionScale:{}\nfxaa:{}\nhdr:{}\nhdrPaperWhite:{}\nhdrPeak:{}\nbatteryMode:{}\ngraphicsApi:{}\ndlss:{}\npickedShaderPack:{}\n", self.preset.name(), self.lod_distance, self.far_detail.name(), @@ -411,6 +420,7 @@ impl Graphics { self.hdr_peak, bool_text(self.battery), self.api.name(), + bool_text(self.dlss), self.shader_pack, ) } @@ -511,10 +521,15 @@ mod tests { hdr_peak: 1400, battery: true, api: GraphicsApi::Dx12, + dlss: false, shader_pack: "Golden Hour".into(), }; assert_eq!(Graphics::parse(&g.serialize()), g); assert_eq!(Graphics::parse(""), Graphics::default()); + // DLSS is on by default, and a file from before the option keeps it on. + assert!(Graphics::default().dlss); + assert!(Graphics::parse("graphicsApi:vulkan\n").dlss); + assert!(!Graphics::parse("dlss:false\n").dlss); // The old menus' Simple / Advanced choice is ignored, and so is the // shader pack older versions saved. assert_eq!(Graphics::parse("level:advanced\n"), Graphics::default()); diff --git a/crates/horizon-mod-sdk/wit/horizon.wit b/crates/horizon-mod-sdk/wit/horizon.wit index ada987fc7..2abbe7eac 100644 --- a/crates/horizon-mod-sdk/wit/horizon.wit +++ b/crates/horizon-mod-sdk/wit/horizon.wit @@ -1217,6 +1217,24 @@ interface render { /// Meant for replays and films; false restores the player's settings. A /// capture turns it on for its duration. set-film-quality: func(on: bool); + /// The DLSS upscaler's state (AirDef fork, API level 33). `available`: + /// this renderer opened a DLSS device (the `dlss` build feature on a + /// supported Vulkan GPU, started with DLSS on). `enabled`: the player's + /// live request — off evaluates the native TAAU from the next frame. + record dlss-state { + available: bool, + enabled: bool, + } + /// Whether NVIDIA DLSS upscaling is available and on (AirDef fork, API + /// level 33). Without `available` the renderer draws the native TAAU; + /// an on-request then applies at the next launch, when the device is + /// opened for DLSS. + dlss-status: func() -> dlss-state; + /// Turns DLSS on or off (AirDef fork, API level 33), from the next frame, + /// and persists the choice in the game's graphics settings + /// (`horizon-graphics.txt`). On renderers without DLSS the request is + /// kept as a graceful no-op, never an error. + set-dlss: func(on: bool); /// Starts a log of the world's block changes as the game's client sees /// them (AirDef fork, level 18): each change keeps its position, the /// state before and after, and the game tick (the number `tick` is diff --git a/crates/horizon-mods/src/api_level.rs b/crates/horizon-mods/src/api_level.rs index 95827b9e5..1816b8a4d 100644 --- a/crates/horizon-mods/src/api_level.rs +++ b/crates/horizon-mods/src/api_level.rs @@ -7,13 +7,13 @@ //! version's level so the launcher can tell before it installs. /// The newest level this Horizon serves. -pub const LEVEL: u32 = 32; +pub const LEVEL: u32 = 33; /// Every function the game offers mods, as `interface.function`, with its /// level. Level 0 is the contract of Horizon 0.2.67 to 0.2.69. A new /// function takes the next level and raises [`LEVEL`] (the `api_reference` /// test fails until it is listed here). -pub const FUNCTIONS: [(&str, u32); 99] = [ +pub const FUNCTIONS: [(&str, u32); 101] = [ ("log.write", 0), ("game.get-player", 0), ("game.get-clock", 0), @@ -130,6 +130,9 @@ pub const FUNCTIONS: [(&str, u32); 99] = [ ("render.project", 31), // AirDef fork: a monotonic clock for a mod to time its own work (#147 step 3.1). ("game.monotonic-nanos", 32), + // AirDef fork: the player's DLSS upscaling toggle from a mod's settings. + ("render.dlss-status", 33), + ("render.set-dlss", 33), ]; /// What the game's program carries so the launcher can read its level diff --git a/crates/horizon-mods/src/runtime.rs b/crates/horizon-mods/src/runtime.rs index 225d45622..340da3dd1 100644 --- a/crates/horizon-mods/src/runtime.rs +++ b/crates/horizon-mods/src/runtime.rs @@ -238,6 +238,8 @@ pub enum Output { Chat { name: String, text: String }, /// `render.set-acoustics`: the game's acoustics on or off. SetAcoustics { on: bool }, + /// `render.set-dlss`: the player's DLSS upscaling request, on or off. + SetDlss { on: bool }, /// A mod command's feedback, red when `error`. Feedback { text: String, error: bool }, /// `command.run`: a vanilla command line, without its slash, to run as @@ -359,6 +361,10 @@ pub struct ModelTable { acoustics: bool, acoustics_prepared: bool, acoustics_output_ready: bool, + /// `render.dlss-status`: the renderer opened a DLSS device, and the + /// player's live request (the game feeds both each tick and frame). + dlss_available: bool, + dlss_enabled: bool, capture_owner: Option<(u64, u64)>, } @@ -1691,6 +1697,14 @@ impl Mods { t.acoustics && t.acoustics_output_ready && t.smoke_world.is_some(); } } + /// The DLSS upscaler's state (`render.dlss-status`): whether a renderer + /// opened a DLSS device, and the player's live request. + pub fn set_dlss_status(&mut self, available: bool, enabled: bool) { + if let Ok(mut t) = self.model_table.lock() { + t.dlss_available = available; + t.dlss_enabled = enabled; + } + } /// The source changes every running mod made since the last call, tagged with the /// number of the mod's run ([`Mods::source_runs`]). pub fn take_source_changes(&mut self) -> Vec<(u64, crate::sources::SourceChange)> { @@ -3486,6 +3500,21 @@ impl render::Host for State { .map(|t| (t.smoke_generation, on)); self.out.push(Output::SetAcoustics { on }); } + fn set_dlss(&mut self, on: bool) { + self.out.push(Output::SetDlss { on }); + } + fn dlss_status(&mut self) -> render::DlssState { + let Ok(t) = self.model_table.lock() else { + return render::DlssState { + available: false, + enabled: false, + }; + }; + render::DlssState { + available: t.dlss_available, + enabled: t.dlss_enabled, + } + } fn acoustics(&mut self) -> bool { self.model_table.lock().is_ok_and(|t| t.acoustics) } diff --git a/crates/horizon-mods/tests/sandbox.rs b/crates/horizon-mods/tests/sandbox.rs index f26b1d275..366080ba1 100644 --- a/crates/horizon-mods/tests/sandbox.rs +++ b/crates/horizon-mods/tests/sandbox.rs @@ -603,9 +603,12 @@ fn smoke_handshake_keeps_fallback_until_the_current_world_is_ready() { .wasm .unwrap(); let functions = horizon_mods::api_level::imports(&wasm).unwrap(); - assert_eq!( - horizon_mods::api_level::needed(functions.iter().map(String::as_str)), - (31, Some("render.project")) + let (level, function) = + horizon_mods::api_level::needed(functions.iter().map(String::as_str)); + assert_eq!(level, 33); + assert!( + function.is_some_and(|f| f == "render.dlss-status" || f == "render.set-dlss"), + "the UI guest must call the newest level's functions: {function:?}" ); let mut mods = load("horizon_mods_test_ui_guest.hmod"); let snapshot = |world: &str| Snapshot { @@ -944,7 +947,7 @@ experimental = ["ui", "render", "input", "recipes"] needed(imports(&wasm).unwrap().iter().map(String::as_str)).0 }; assert_eq!(level("coords_hud.hmod"), 0); - // The UI guest calls the newest level's function (render.project). + // The UI guest calls the newest level's functions (render.dlss-status, render.set-dlss). assert_eq!(level("horizon_mods_test_ui_guest.hmod"), LEVEL); } diff --git a/crates/horizon-mods/tests/ui_guest/src/lib.rs b/crates/horizon-mods/tests/ui_guest/src/lib.rs index 5b7337b8c..a99839579 100644 --- a/crates/horizon-mods/tests/ui_guest/src/lib.rs +++ b/crates/horizon-mods/tests/ui_guest/src/lib.rs @@ -142,6 +142,7 @@ impl Mod for Guest { "view_main", "camera_status", "project", + "dlss", "recipes", "browser", "browser_poll", @@ -263,6 +264,11 @@ impl Mod for Guest { let p = render::project(1.0, 2.0, 3.0); chat::show(&format!("{p:?}")); } + "dlss" => { + let s = render::dlss_status(); + render::set_dlss(args == "on"); + chat::show(&format!("{} {}", s.available, s.enabled)); + } "cap_status" => { let a = render::acoustics_status(); let c = render::capture_owner_status(); diff --git a/docs/api/mods-reference.md b/docs/api/mods-reference.md index a73822830..765108196 100644 --- a/docs/api/mods-reference.md +++ b/docs/api/mods-reference.md @@ -904,6 +904,15 @@ Where a capture is. | `file` | `string` | The result: the MP4, or the folder of the PNG sequence when no `ffmpeg` was found. Empty until `done`. | | `message` | `string` | An error, or a note about the result (no encoder, no audio). | +### record `dlss-state` + +The DLSS upscaler's state (AirDef fork, API level 33). `available`: this renderer opened a DLSS device (the `dlss` build feature on a supported Vulkan GPU, started with DLSS on). `enabled`: the player's live request — off evaluates the native TAAU from the next frame. + +| Field | Type | | +| --- | --- | --- | +| `available` | `bool` | | +| `enabled` | `bool` | | + | Function | Signature | What it does | | --- | --- | --- | | `set-hud` | `func(shapes: list)` | Replaces the mod's HUD shapes: up to 1024, drawn every frame in order over the HUD (after the hotbar, under chat and screens), hidden with the HUD (F1). An empty list removes them. | @@ -960,6 +969,8 @@ Where a capture is. | `capture-stop` | `func(cancel: bool)` | Ends this mod run's capture: finishes the file, or (`cancel`) throws it away. A different mod cannot stop it. World transitions cancel mod-owned captures. | | `capture-status` | `func() -> capture-state` | The capture's state; `done` and `failed` stay until the next start. | | `set-film-quality` | `func(on: bool)` | Asks for the best picture the renderer can give (AirDef fork, level 17): the HD world at the full size of the window (no resolution scale, so no upscaling), and the volumetric clouds and fog marched with more steps. Meant for replays and films; false restores the player's settings. A capture turns it on for its duration. | +| `dlss-status` | `func() -> dlss-state` | Whether NVIDIA DLSS upscaling is available and on (AirDef fork, API level 33). Without `available` the renderer draws the native TAAU; an on-request then applies at the next launch, when the device is opened for DLSS. | +| `set-dlss` | `func(on: bool)` | Turns DLSS on or off (AirDef fork, API level 33), from the next frame, and persists the choice in the game's graphics settings (`horizon-graphics.txt`). On renderers without DLSS the request is kept as a graceful no-op, never an error. | | `world-log-start` | `func() -> u32` | Starts a log of the world's block changes as the game's client sees them (AirDef fork, level 18): each change keeps its position, the state before and after, and the game tick (the number `tick` is called with). It is bounded (about a million changes): the oldest go first. Returns the log's id, which stays the same while it runs (a second call returns it). Only the world open now has it: a new world (leaving, rejoining) loses it. Not kept when the world runs in the game's own frame (`--in-frame`), where `world-log-range` stays none. | | `world-log-stop` | `func(id: u32)` | Ends the log and forgets what it kept (a different id is ignored). | | `world-log-range` | `func(id: u32) -> option>` | What the log covers, as (the earliest tick whose world it can show, the tick it is at now); none for an unknown id, a log of another world, or one that has not been taken up yet (the tick after `world-log-start`). Asking for a time before the earliest shows the earliest. |