diff --git a/crates/victory-gpu/src/draw.rs b/crates/victory-gpu/src/draw.rs index e4c456c..289e9df 100644 --- a/crates/victory-gpu/src/draw.rs +++ b/crates/victory-gpu/src/draw.rs @@ -4424,6 +4424,9 @@ impl State { self.window = None; #[cfg(feature = "diagnostics")] self.trace("draw", vertices, first); + if crate::streamline::hudless_wanted() { + self.before_shown_target(list, vertices == 3 && instances == 1); + } let ready = self.prepare(list, false); // A pipeline with the rectangle geometry stage draws the title's // vertices as they are; any other gets its rectangles expanded. @@ -4460,6 +4463,29 @@ impl State { } } + /// With frame generation (`crate::streamline`), before a draw into one + /// colour target without depth: if the target is one the title presents, + /// the draw is told there, where the colour without the interface is + /// copied in front of the title's interface composite. `triangle`: one + /// triangle, one instance (the composite's shape). Only copies and + /// barriers are recorded; the target is moved back to a render target by + /// the draw's own preparation. + fn before_shown_target(&self, list: &HostList, triangle: bool) { + if self.depth != 0 { + return; + } + let &[target] = self.targets.as_slice() else { + return; + }; + let Some(p) = crate::pipeline::host_pipeline(self.pipeline as This) else { + return; + }; + if p.compute || p.mesh { + return; + } + crate::streamline::before_target_draw(list, target as This, p, triangle); + } + /// Whether the bound pipeline completes rectangles itself, in the /// geometry stage rectangle pipelines get (`HostPipeline::rects`). fn completes_rects(&self) -> bool { @@ -4592,6 +4618,9 @@ impl State { self.window = None; #[cfg(feature = "diagnostics")] self.trace("indexed", indices, first); + if crate::streamline::hudless_wanted() { + self.before_shown_target(list, false); + } // Indexed rectangles are drawn by the rectangle geometry stage // alone (nothing expands them on the CPU). let lost = self.topology == RECTANGLES && !self.completes_rects(); diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs index 1140960..495d7e8 100644 --- a/crates/victory-gpu/src/host.rs +++ b/crates/victory-gpu/src/host.rs @@ -1279,6 +1279,9 @@ pub(crate) struct HostList { /// The upscaling (`crate::streamline`) recorded in the list, noted for /// the present after its submission; 0 for none. upscale: std::sync::atomic::AtomicU64, + /// The copy of the colour without the interface (`crate::streamline`) + /// recorded in the list, noted likewise; 0 for none. + hudless: std::sync::atomic::AtomicU64, /// Counts the list in [`ALIVE`] while it lives. _alive: Counted, /// The texts of the markers `note_op` set, in order (for device-removed @@ -4224,6 +4227,7 @@ impl Host { indirect_run: Mutex::default(), holding: std::sync::atomic::AtomicBool::new(false), upscale: std::sync::atomic::AtomicU64::new(0), + hudless: std::sync::atomic::AtomicU64::new(0), _alive: Counted::new(), #[cfg(feature = "diagnostics")] notes, @@ -5604,6 +5608,10 @@ impl Host { if id != 0 { crate::streamline::submitted(id); } + let id = run.take_hudless(); + if id != 0 { + crate::streamline::hudless_submitted(id); + } } let was_working = working(true); submitting(1, runs.len()); @@ -6460,6 +6468,7 @@ impl HostList { let _resetting = crate::timeline::span("resetting a host list"); self._alive.used(); self.upscale.store(0, Ordering::Relaxed); + self.hudless.store(0, Ordering::Relaxed); *self.coming.lock().unwrap_or_else(|e| e.into_inner()) = None; *self.deferred() = Deferred::default(); self.states.lock().unwrap_or_else(|e| e.into_inner()).clear(); @@ -7449,6 +7458,22 @@ impl HostList { self.upscale.swap(0, Ordering::Relaxed) } + /// The list recorded copy `id` of the colour without the interface + /// (`crate::streamline`, frame generation). + pub(crate) fn mark_hudless(&self, id: u64) { + self.hudless.store(id, Ordering::Relaxed); + } + + /// The copy the list recorded (0 for none). + pub(crate) fn hudless(&self) -> u64 { + self.hudless.load(Ordering::Relaxed) + } + + /// As [`HostList::hudless`], taken. + pub(crate) fn take_hudless(&self) -> u64 { + self.hudless.swap(0, Ordering::Relaxed) + } + /// Runs `work` when the list is submitted, in order with its copies. /// `work` may write title memory (refreshes after it copy again). pub(crate) fn defer(&self, work: impl Fn() + Send + 'static) { @@ -8874,7 +8899,7 @@ impl Host { /// The swap chain formats a presented texture can be copied into: its own /// family's. -fn swap_format(format: DXGI_FORMAT) -> Option { +pub(crate) fn swap_format(format: DXGI_FORMAT) -> Option { Some(match format.0 { 27..=32 => DXGI_FORMAT_R8G8B8A8_UNORM, 87 | 90 | 91 => DXGI_FORMAT_B8G8R8A8_UNORM, @@ -9624,6 +9649,14 @@ impl Host { } } + /// Lets the swap chain and what presents with it go, once everything + /// sent has run (`victory upscaler-check`: before Streamline is shut + /// down; nothing presents afterwards). + pub(crate) fn drop_presenter(&self) { + settle_now(WHY_SYNC); + *self.presenter.lock().unwrap_or_else(|e| e.into_inner()) = None; + } + fn presenter( &self, width: u32, @@ -9661,13 +9694,23 @@ impl Host { let swap_chain = match proxied { Some(Ok(swap_chain)) => { crate::streamline::swap_chain_made(true, None); + // Frame generation must be off across a change between + // windowed and full screen (Streamline's guide, 12.0): + // the system's own Alt+Enter is not taken for this window. + if let Ok(parent) = swap_chain.GetParent::() { + let _ = parent.MakeWindowAssociation(hwnd, DXGI_MWA_NO_ALT_ENTER); + } swap_chain } Some(Err(e)) => { crate::streamline::swap_chain_made(false, Some(&e)); factory.CreateSwapChainForHwnd(&self.queue, hwnd, &desc, None, None)?.cast::()? } - None => factory.CreateSwapChainForHwnd(&self.queue, hwnd, &desc, None, None)?.cast::()?, + // (`VICTORY_STREAMLINE_PRESENT=1`, DLSS without frame + // generation: Streamline's proxy of it, for its present hook.) + None => crate::streamline::present_hooked( + factory.CreateSwapChainForHwnd(&self.queue, hwnd, &desc, None, None)?.cast::()?, + ), }; let copy = self.new_list()?; copy.close(); diff --git a/crates/victory-gpu/src/streamline.rs b/crates/victory-gpu/src/streamline.rs index ebd9fe0..0f5c7f4 100644 --- a/crates/victory-gpu/src/streamline.rs +++ b/crates/victory-gpu/src/streamline.rs @@ -71,6 +71,14 @@ pub struct Asked { pub reactive: bool, /// `VICTORY_STREAMLINE_LOG=`: Streamline's own log there, verbose. pub log_dir: Option, + /// `VICTORY_FRAMEGEN_HUDLESS=0`: with frame generation, no colour + /// without the interface is copied or tagged where the title draws its + /// interface into the frame (Series X). + pub hudless: bool, + /// `VICTORY_STREAMLINE_PRESENT=1`: with DLSS and no frame generation, + /// our swap chain is Streamline's proxy of it, so that Streamline sees + /// the presents (its bookkeeping per frame). + pub present_hook: bool, } impl Asked { @@ -102,6 +110,8 @@ impl Asked { mvec: plan::pair(var("VICTORY_DLSS_MV").as_deref()), reactive: var("VICTORY_DLSS_REACTIVE").is_none_or(|v| v.trim() != "0"), log_dir: var("VICTORY_STREAMLINE_LOG").filter(|v| !v.trim().is_empty() && v.trim() != "0").map(PathBuf::from), + hudless: var("VICTORY_FRAMEGEN_HUDLESS").is_none_or(|v| v.trim() != "0"), + present_hook: on("VICTORY_STREAMLINE_PRESENT"), }) } @@ -194,6 +204,7 @@ struct Sl { get_feature_function: abi::SlGetFeatureFunction, get_new_frame_token: abi::SlGetNewFrameToken, set_d3d_device: abi::SlSetD3DDevice, + shutdown: abi::SlShutdown, } static SL: OnceLock = OnceLock::new(); @@ -237,6 +248,8 @@ unsafe impl Sync for Proxies {} static PROXIES: OnceLock = OnceLock::new(); /// Our present goes through Streamline's swap chain. static SWAP_CHAIN_PROXIED: AtomicBool = AtomicBool::new(false); +/// Our swap chain is Streamline's proxy of it ([`present_hooked`]). +static PRESENT_HOOKED: AtomicBool = AtomicBool::new(false); /// Library calls that are not thread safe, and what the upscaling keeps /// between frames, one caller at a time. @@ -537,6 +550,7 @@ fn load(path: &Path) -> Result { get_feature_function: get!(c"slGetFeatureFunction", abi::SlGetFeatureFunction), get_new_frame_token: get!(c"slGetNewFrameToken", abi::SlGetNewFrameToken), set_d3d_device: get!(c"slSetD3DDevice", abi::SlSetD3DDevice), + shutdown: get!(c"slShutdown", abi::SlShutdown), _library: library, }) } @@ -711,6 +725,7 @@ pub(crate) fn swap_chain_factory(factory: &IDXGIFactory2) -> Option<(IDXGIFactor /// frame generation stays off). pub(crate) fn swap_chain_made(proxied: bool, error: Option<&windows::core::Error>) { SWAP_CHAIN_PROXIED.store(proxied, Release); + HUDLESS_WANTED.store(proxied && FG_READY.load(Acquire) && PLAN.get().is_some_and(|p| p.asked.hudless), Release); if proxied { tracing::info!("Streamline: our swap chain is Streamline's proxy; DLSS Frame Generation can run on its presents"); } else { @@ -722,6 +737,36 @@ pub(crate) fn swap_chain_made(proxied: bool, error: Option<&windows::core::Error } } +/// `VICTORY_STREAMLINE_PRESENT=1`, DLSS without frame generation: Streamline's +/// proxy of `swap_chain`, whose Present, ResizeBuffers and GetBuffer run +/// Streamline's hooks first (its common plugin frees what it retired and +/// keeps its video memory budget at each present; without it, it logs +/// "presentCommon() was not observed" after 60 upscalings and frees nothing +/// it retired). `swap_chain` itself if the switch is off, frame generation +/// owns the swap chain, or the upgrade fails. +pub(crate) fn present_hooked(swap_chain: IDXGISwapChain3) -> IDXGISwapChain3 { + let (Some(plan), Some(sl)) = (PLAN.get(), SL.get()) else { return swap_chain }; + if !plan.asked.present_hook || !plan.dlss || !DLSS_READY.load(Acquire) || SWAP_CHAIN_PROXIED.load(Acquire) { + return swap_chain; + } + let mut raw = swap_chain.as_raw(); + // SAFETY: an owned reference of ours; on success `raw` is a new proxy + // that holds its own reference to the swap chain. + let code = unsafe { (sl.upgrade_interface)(&mut raw) }; + if code != 0 || raw.is_null() || raw == swap_chain.as_raw() { + tracing::warn!( + "Streamline: the swap chain was not upgraded: {} ({code}); presents stay unseen by Streamline", + abi::result_name(code) + ); + return swap_chain; + } + tracing::info!("Streamline: our swap chain is Streamline's proxy of it (VICTORY_STREAMLINE_PRESENT=1): it sees every present"); + PRESENT_HOOKED.store(true, Release); + // SAFETY: the proxy's one reference, now ours; it implements the swap + // chain interfaces up to IDXGISwapChain4 and holds the swap chain. + unsafe { IDXGISwapChain3::from_raw(raw) } +} + fn frame_token(sl: &Sl, index: u32) -> Option<*mut abi::FrameToken> { let mut token = std::ptr::null_mut(); // SAFETY: an out pointer and an index. @@ -1052,6 +1097,218 @@ pub fn upscaler_destroyed(context: usize) { tracing::info!(code, result = abi::result_name(code), "DLSS: the title's upscaler was destroyed; DLSS let go of its resources"); } +/// The title's interface composite where the interface is no plane of the +/// present (Series X): one triangle that blends the interface target +/// (3840x2160, premultiplied) over the frame's colour, with these vertex and +/// pixel shaders, the frame's last draw into the texture it presents. Seen +/// in every frame listing of 2026-11-26 (stock 3840x2160 output: once a +/// frame, after the scene's composite into the same texture) and bound from +/// frame 3 on in the 1440p runs with DLSS; `draw::State::native_frontend_viewport` +/// (DexNom's) names the same draw. +const INTERFACE_COMPOSITE: [&str; 2] = ["0602c2384acbb3b2", "a78d088fa55aa495"]; + +/// Whether draws are looked at for the colour without the interface: frame +/// generation runs on our swap chain and `VICTORY_FRAMEGEN_HUDLESS` is not 0. +#[inline] +pub(crate) fn hudless_wanted() -> bool { + HUDLESS_WANTED.load(Relaxed) +} + +static HUDLESS_WANTED: AtomicBool = AtomicBool::new(false); + +/// The host textures of the last presents (their addresses): the textures +/// the title presents (it has two, in turn). +static SHOWN: [std::sync::atomic::AtomicUsize; 4] = [const { std::sync::atomic::AtomicUsize::new(0) }; 4]; +static SHOWN_NEXT: AtomicU32 = AtomicU32::new(0); + +/// A copy of a presented texture taken in front of the interface composite. +struct Copied { + id: u64, + /// The host texture copied (its address). + target: usize, + texture: ID3D12Resource, +} + +// SAFETY: D3D12 resources are free-threaded. +unsafe impl Send for Copied {} + +/// The copies recorded in lists not submitted yet, and those submitted and +/// not presented yet, in submission order. +static HUD_PENDING: Mutex> = Mutex::new(Vec::new()); +static HUD_SUBMITTED: Mutex> = Mutex::new(Vec::new()); +static HUD_NEXT_ID: AtomicU64 = AtomicU64::new(0); + +/// The two textures the copies go to in turn (a present reads one while the +/// next frame's lists may already be recorded), with their size and format. +struct HudlessTextures { + size: [u32; 2], + format: i32, + textures: [ID3D12Resource; 2], +} + +// SAFETY: as above. +unsafe impl Send for HudlessTextures {} + +static HUD_TEXTURES: Mutex> = Mutex::new(None); + +// Since the last line about it (every ten seconds): copies recorded, presents +// tagged with one, presents with frame generation on that had none, composite +// draws, those after a copy in their list, draws of other pipelines into a +// presented texture. +static HUD_COUNTS: [AtomicU64; 6] = [const { AtomicU64::new(0) }; 6]; +const HUD_COPIES: usize = 0; +const HUD_TAGGED: usize = 1; +const HUD_MISSING: usize = 2; +const HUD_COMPOSITES: usize = 3; +const HUD_AGAIN: usize = 4; +const HUD_OTHERS: usize = 5; + +fn lock(mutex: &Mutex) -> std::sync::MutexGuard<'_, T> { + mutex.lock().unwrap_or_else(|e| e.into_inner()) +} + +/// Before a draw of `pipeline` into `target` alone (no depth), with frame +/// generation: if `target` is a texture the title presents and the draw is +/// the title's interface composite ([`INTERFACE_COMPOSITE`]; `triangle`: one +/// triangle, one instance), the target as it is now, the frame without the +/// interface, is copied into a texture of ours, recorded into `list` in +/// front of the draw; the present after the list's submission tags it as +/// the colour without the interface. One copy a list. Other pipelines that +/// draw into a presented texture are named in the log once each: the +/// interface is in the copy if one of them draws it before the composite. +pub(crate) fn before_target_draw( + list: &crate::host::HostList, + target: crate::object::This, + pipeline: &crate::pipeline::host::HostPipeline, + triangle: bool, +) { + let Some(texture) = crate::resource::host_resource(target) else { return }; + let shown = texture.as_raw() as usize; + if !SHOWN.iter().any(|s| s.load(Relaxed) == shown) { + return; + } + let composite = triangle && INTERFACE_COMPOSITE.iter().all(|hash| pipeline.stages.iter().any(|s| s.shader.hash == *hash)); + if !composite { + HUD_COUNTS[HUD_OTHERS].fetch_add(1, Relaxed); + static SEEN: Mutex> = Mutex::new(Vec::new()); + let key = std::ptr::from_ref(pipeline) as usize; + let mut seen = lock(&SEEN); + if !seen.contains(&key) && seen.len() < 24 { + seen.push(key); + tracing::info!( + pipeline = %pipeline.name, + state = %pipeline.state, + triangle, + after_the_copy_in_its_list = list.hudless() != 0, + "DLSS Frame Generation: this pipeline draws into the texture the title presents (the scene's composite does; an interface drawn here before the interface composite would be in the colour without the interface)" + ); + } + return; + } + HUD_COUNTS[HUD_COMPOSITES].fetch_add(1, Relaxed); + if list.hudless() != 0 { + HUD_COUNTS[HUD_AGAIN].fetch_add(1, Relaxed); + return; + } + let id = HUD_NEXT_ID.fetch_add(1, Relaxed) + 1; + let Some(copy) = hudless_texture(texture, id) else { return }; + // The target as a copy's source: the composite's own preparation makes + // it a render target again. + const COPY_SOURCE: u32 = 0x800; + crate::list::ensure_state(list, target, COPY_SOURCE); + // SAFETY: an open list; the source is in the copy source state in it, + // ours stays a copy's destination; same size, one level, formats of one + // family. + unsafe { list.list.CopyResource(©, texture) }; + list.keep(©); + list.keep(texture); + let mut pending = lock(&HUD_PENDING); + pending.retain(|c| id.saturating_sub(c.id) < 16); + pending.push(Copied { id, target: shown, texture: copy }); + drop(pending); + list.mark_hudless(id); + HUD_COUNTS[HUD_COPIES].fetch_add(1, Relaxed); + // SAFETY: a live texture. + let desc = unsafe { texture.GetDesc() }; + once!( + info, + width = desc.Width, + height = desc.Height, + format = desc.Format.0, + pipeline = %pipeline.name, + state = %pipeline.state, + "DLSS Frame Generation: the colour without the interface is copied in front of the title's interface composite (first time)" + ); +} + +/// One of the two textures the colour without the interface is copied to +/// (copy `id`'s), made like `target` in the swap chain's format; `None` if +/// `target` is no plain 2D texture of a format that is shown. +fn hudless_texture(target: &ID3D12Resource, id: u64) -> Option { + // SAFETY: a live texture. + let desc = unsafe { target.GetDesc() }; + let plain = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE2D + && desc.DepthOrArraySize == 1 + && desc.MipLevels == 1 + && desc.SampleDesc.Count == 1; + let format = crate::host::swap_format(desc.Format).filter(|_| plain); + let Some(format) = format else { + once!( + warn, + format = desc.Format.0, + levels = desc.MipLevels, + samples = desc.SampleDesc.Count, + "DLSS Frame Generation: the presented texture cannot be copied for the colour without the interface; none is tagged" + ); + return None; + }; + let size = [desc.Width as u32, desc.Height]; + let mut textures = lock(&HUD_TEXTURES); + if textures.as_ref().is_none_or(|t| t.size != size || t.format != format.0) { + let device = &crate::host::host()?.device; + let make = || texture(device, size, format, D3D12_RESOURCE_FLAG_NONE, COPY_DEST); + match (make(), make()) { + (Ok(a), Ok(b)) => *textures = Some(HudlessTextures { size, format: format.0, textures: [a, b] }), + (Err(e), _) | (_, Err(e)) => { + once!(warn, error = %e, "DLSS Frame Generation: no texture for the colour without the interface; none is tagged"); + return None; + } + } + } + textures.as_ref().map(|t| t.textures[(id % 2) as usize].clone()) +} + +/// A host list that recorded copy `id` of the colour without the interface +/// is submitted (in submission order, before the present that follows it). +pub(crate) fn hudless_submitted(id: u64) { + let copied = { + let mut pending = lock(&HUD_PENDING); + let at = pending.iter().position(|c| c.id == id); + at.map(|i| pending.swap_remove(i)) + }; + if let Some(copied) = copied { + let mut submitted = lock(&HUD_SUBMITTED); + if submitted.len() >= 8 { + submitted.remove(0); + } + submitted.push(copied); + } +} + +/// At a present of host texture `shown`: it is one the title presents +/// ([`SHOWN`]), and the first copy of it submitted since its last present, +/// if any, is the frame's colour without the interface. +fn hudless_for(shown: &ID3D12Resource) -> Option { + let shown = shown.as_raw() as usize; + if !SHOWN.iter().any(|s| s.load(Relaxed) == shown) { + SHOWN[SHOWN_NEXT.fetch_add(1, Relaxed) as usize % SHOWN.len()].store(shown, Relaxed); + } + let mut submitted = lock(&HUD_SUBMITTED); + let first = submitted.iter().position(|c| c.target == shown).map(|i| submitted.remove(i)); + submitted.retain(|c| c.target != shown); + first.map(|c| c.texture) +} + /// The planes a present shows (Series S: the scene and the interface over /// it), the host states they are in, and the back buffer's size. pub(crate) struct Planes<'a> { @@ -1077,9 +1334,13 @@ pub(crate) fn present_begins(frame: u64, planes: Planes<'_>) -> Option) -> Option) -> Option = resources .iter_mut() @@ -1140,6 +1413,15 @@ pub(crate) fn present_begins(frame: u64, planes: Planes<'_>) -> Option) -> Option Vec { + let mut lines = check_run(output, device, present); + lines.extend(shut_down()); + lines +} + +/// The host device was made for [`check`]. +static CHECK_DEVICE: AtomicBool = AtomicBool::new(false); + +/// The end of [`check`] with a device: frame generation off, our swap chain +/// let go, Streamline shut down (`slShutdown`), before the process ends. +/// Streamline's guide asks for the shutdown before the devices go. Without +/// it the process failed fast at its exit after `--present` (exit code +/// 0xC0000409, which some shells show as 9), with frame generation on and +/// its swap chain still up; with it the exit code is 0 (2026-11-27, SDK +/// 2.14.16). Nothing of Streamline is called afterwards. +/// `VICTORY_CHECK_TEARDOWN=0`: left out. +fn shut_down() -> Option { + if !CHECK_DEVICE.load(Relaxed) || std::env::var("VICTORY_CHECK_TEARDOWN").is_ok_and(|v| v.trim() == "0") { + return None; + } + let (sl, host) = (SL.get()?, crate::host::host()?); + resizing(); + host.drop_presenter(); + for ready in [&FG_READY, &DLSS_READY, &SWAP_CHAIN_PROXIED, &HUDLESS_WANTED] { + ready.store(false, Release); + } + *lock(&SUBMITTED) = None; + lock(&HUD_SUBMITTED).clear(); + // SAFETY: initialised; nothing of it is in use or called from here on. + let code = unsafe { (sl.shutdown)() }; + Some(format!("Streamline shut down: {} ({code})", abi::result_name(code))) +} + +fn check_run(output: [u32; 2], device: bool, present: bool) -> Vec { let mut lines = Vec::new(); let mut asked = match Asked::from_env() { Ok(asked) => asked, Err(why) => return vec![why], }; asked.dlss = true; - asked.framegen = true; + // (`VICTORY_STREAMLINE_PRESENT=1` is for DLSS without frame generation.) + asked.framegen = !asked.present_hook; let available = match load_and_init(&asked, false) { Ok(available) => available, Err(why) => return vec![format!("Streamline did not load from {}: {why}", asked.dir.display())], @@ -1260,7 +1589,13 @@ pub fn check(output: [u32; 2], device: bool, present: bool) -> Vec { "Streamline loaded from {}: DLSS {}, frame generation {} on this GPU", asked.dir.display(), if available.dlss { "supported" } else { "NOT supported" }, - if available.framegen { "supported" } else { "NOT supported" } + if available.framegen { + "supported" + } else if asked.framegen { + "NOT supported" + } else { + "not asked for (VICTORY_STREAMLINE_PRESENT=1)" + } )); if !device { return lines; @@ -1269,6 +1604,7 @@ pub fn check(output: [u32; 2], device: bool, present: bool) -> Vec { lines.push("no host D3D12 device".into()); return lines; }; + CHECK_DEVICE.store(true, Relaxed); let (dlss, framegen) = (DLSS_READY.load(Acquire), FG_READY.load(Acquire)); lines.push(format!("device handed over: DLSS ready {dlss}, frame generation ready {framegen} (queue through Streamline's device proxy)")); let render = asked.mode.render_size(output); @@ -1277,8 +1613,9 @@ pub fn check(output: [u32; 2], device: bool, present: bool) -> Vec { motion_scale: [render[0] as f32, render[1] as f32], render, output, - near: 0.1, - far: 10_000.0, + // (The far plane first, as the title names them.) + near: 10_000.0, + far: 0.15, fov_y: 1.0, reset: true, flags: plan::FFX_HIGH_DYNAMIC_RANGE | plan::FFX_DEPTH_INVERTED | plan::FFX_AUTO_EXPOSURE, @@ -1317,7 +1654,14 @@ pub fn check(output: [u32; 2], device: bool, present: bool) -> Vec { textures[DEPTH] = Some((depth.clone(), SHADER_READ)); textures[MOTION] = Some((motion.clone(), SHADER_READ)); textures[OUTPUT] = Some((out, UNORDERED)); - for round in 0..3 { + // (`VICTORY_STREAMLINE_PRESENT=1`: DLSS alone, with a present through + // Streamline's proxy of our swap chain after each upscaling, more of + // them than Streamline waits for a present.) + let hooked = present && asked.present_hook && !framegen; + for round in 0..if hooked { 120 } else { 3 } { + if hooked && round > 0 { + host.present_planes(&base, 0, None, round); + } let id = NEXT_ID.fetch_add(1, Relaxed) + 1; let list = match host.new_list() { Ok(list) => list, @@ -1349,11 +1693,26 @@ pub fn check(output: [u32; 2], device: bool, present: bool) -> Vec { } } } - lines.push("DLSS ran three times on stand-in textures; the device is fine".into()); + lines.push(if hooked { + format!( + "DLSS ran 120 times on stand-in textures with a present after each; our swap chain is {}Streamline's proxy of it (VICTORY_STREAMLINE_PRESENT=1); the device is fine", + if PRESENT_HOOKED.load(Relaxed) { "" } else { "NOT " } + ) + } else { + "DLSS ran three times on stand-in textures; the device is fine".into() + }); } if present && framegen { CHECKING.store(true, Relaxed); let (on, shown) = (FG_ON_ALL.load(Relaxed), FG_SHOWN_ALL.load(Relaxed)); + // A stand-in for the colour without the interface, tagged as the + // copies in front of the title's interface composite are: ours, a + // copy's destination, of the back buffer's size and format. + let copy = { + use windows::Win32::Graphics::Dxgi::Common::DXGI_FORMAT_R8G8B8A8_UNORM; + texture(device, output, DXGI_FORMAT_R8G8B8A8_UNORM, D3D12_RESOURCE_FLAG_NONE, COPY_DEST).ok() + }; + let tagged = HUD_COUNTS[HUD_TAGGED].load(Relaxed); for frame in 1..=180u64 { let id = NEXT_ID.fetch_add(1, Relaxed) + 1; *SUBMITTED.lock().unwrap_or_else(|e| e.into_inner()) = Some(Noted { @@ -1362,14 +1721,18 @@ pub fn check(output: [u32; 2], device: bool, present: bool) -> Vec { motion: Source::Fixed(motion.clone(), SHADER_READ), camera, }); + if let Some(copy) = © { + lock(&HUD_SUBMITTED).push(Copied { id: frame, target: base.as_raw() as usize, texture: copy.clone() }); + } host.present_planes(&base, 0, None, frame); std::thread::sleep(std::time::Duration::from_millis(16)); } crate::host::settle_for_fence(); lines.push(format!( - "frame generation: 180 presents, {} with it on, {} frames shown by it, status {:#x} (0 is fine){}", + "frame generation: 180 presents, {} with it on, {} frames shown by it, {} presents tagged with a colour without the interface, status {:#x} (0 is fine){}", FG_ON_ALL.load(Relaxed) - on, FG_SHOWN_ALL.load(Relaxed) - shown, + HUD_COUNTS[HUD_TAGGED].load(Relaxed) - tagged, FG_STATUS.load(Relaxed), if SWAP_CHAIN_PROXIED.load(Relaxed) { "" } else { "; the swap chain is NOT Streamline's proxy" } )); @@ -1385,6 +1748,7 @@ pub fn check(output: [u32; 2], device: bool, present: bool) -> Vec { const SHADER_READ: u32 = 0xc0; const UNORDERED: u32 = 0x8; +const COPY_DEST: u32 = 0x400; /// A stand-in texture for [`check`] (its contents are whatever the memory held). fn texture( @@ -1435,5 +1799,14 @@ pub(crate) fn line(frames: f64) { FG_STATUS.load(Relaxed), if FG_READY.load(Relaxed) && SWAP_CHAIN_PROXIED.load(Relaxed) { "" } else { "; not running (see above)" } ); + // Every tenth line (about ten seconds): the colour without the + // interface, where the title draws the interface into the frame. + static LINES: AtomicU32 = AtomicU32::new(0); + if hudless_wanted() && LINES.fetch_add(1, Relaxed) % 10 == 9 { + let [copies, tagged, missing, composites, again, others] = [0, 1, 2, 3, 4, 5].map(|i| HUD_COUNTS[i].swap(0, Relaxed)); + tracing::info!( + "DLSS Frame Generation, colour without the interface, last ten lines: {copies} copies in front of the title's interface composite, {tagged} presents tagged with one, {missing} presents with frame generation on had none; {composites} interface composite draws into a presented texture ({again} after a copy in their list), {others} draws of other pipelines into one" + ); + } } } diff --git a/crates/victory-gpu/src/streamline/plan.rs b/crates/victory-gpu/src/streamline/plan.rs index a4c8d3b..52323d9 100644 --- a/crates/victory-gpu/src/streamline/plan.rs +++ b/crates/victory-gpu/src/streamline/plan.rs @@ -197,6 +197,20 @@ impl Camera { self.flags & FFX_DISPLAY_RESOLUTION_MOTION_VECTORS != 0 } + /// The camera with its nearer plane as the near one. FidelityFX takes + /// the two distances in either order (its upscaler reads the smaller as + /// the near plane and lets the inverted-depth flag say which end of the + /// depth range it is), and the title, whose depth is inverted, names the + /// far plane first (near 10000, far 0.15 in the first dispatch of + /// 2026-11-26). Streamline's constants name them as they are. + pub fn planes_in_order(&self) -> Camera { + let mut camera = *self; + if self.near > self.far && self.far > 0.0 { + (camera.near, camera.far) = (self.far, self.near); + } + camera + } + /// The size the motion vectors cover. pub fn motion_size(&self) -> [u32; 2] { if self.display_motion_vectors() { self.output } else { self.render } @@ -462,6 +476,34 @@ mod tests { assert_eq!(invert(&[[0.0; 4]; 4]), None); } + /// The title names the far plane first (inverted depth): in order, the + /// projection puts the nearer plane at depth 1 and the farther at 0; as + /// named, it took the farther for the near plane of an endless range. + #[test] + fn planes_named_far_first_are_put_in_order() { + let mut named = camera(FFX_DEPTH_INVERTED); + (named.near, named.far) = (10_000.0, 0.15); + let ordered = named.planes_in_order(); + assert_eq!((ordered.near, ordered.far), (0.15, 10_000.0)); + assert_eq!(ordered.planes_in_order(), ordered); + let c = ordered.constants([1.0, 1.0], [1.0, 1.0]); + assert_eq!((c.camera_near, c.camera_far), (0.15, 10_000.0)); + let depth = |z: f32| { + let m = &c.camera_view_to_clip; + (z * m[2][2] + m[3][2]) / (z * m[2][3] + m[3][3]) + }; + assert!((depth(0.15) - 1.0).abs() < 1e-5 && depth(10_000.0).abs() < 1e-5); + // As named: an endless range from 10000 on. + let wrong = named.constants([1.0, 1.0], [1.0, 1.0]); + assert_eq!(wrong.camera_view_to_clip[3][2], 10_000.0); + // An endless far plane, or a plane at 0, is left alone. + let mut endless = camera(FFX_DEPTH_INVERTED); + (endless.near, endless.far) = (0.15, f32::MAX); + assert_eq!(endless.planes_in_order(), endless); + (endless.near, endless.far) = (0.15, 0.0); + assert_eq!(endless.planes_in_order(), endless); + } + #[test] fn multiplier_pairs() { assert_eq!(pair(None), [1.0, 1.0]);