Frame generation: a present whose depth and motion vectors do not join it to the picture before is a reset

A present with nothing new from its frame (a menu, the map, a loading screen: no G-buffer pass or upscale
since the last present) carried the last frame's depth and motion vectors with reset false, so DLSS-G made a
frame between a game picture and a menu one along vectors that do not join them; so did the first fresh
present after such ones, and a pass whose depth or motion vectors are other textures than the last one's.
Each is now told as a reset (LEONIDA_FG_RESET_STALE, on; 0: only the upscale's own reset), counted in the
log. fg::native_swap_chain hands back the very pointer Streamline holds.

AI-assisted (Claude). Tested on an RTX 4060 Ti (driver 616.64): builds with and without diagnostics;
recorded runs with the pause menu opened and closed to follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
NotRexed
2026-11-30 10:07:25 -05:00
parent 8b6cbb3483
commit daa3f47a97

View File

@ -691,20 +691,19 @@ pub(crate) fn start(device: &ID3D12Device, factory: IDXGIFactory2) -> IDXGIFacto
unsafe { IDXGIFactory2::from_raw(raw) }
}
/// The native swap chain behind Streamline's proxy `proxy`, if frame generation started (`crate::shown`
/// hooks its presents); `None` without Streamline or when `proxy` is not one of its proxies.
/// The native swap chain behind Streamline's proxy `proxy`, as the very pointer Streamline holds, if
/// frame generation started (`crate::shown` hooks its presents); `None` without Streamline or when
/// `proxy` is not one of its proxies.
#[cfg(feature = "diagnostics")]
pub(crate) fn native_swap_chain(proxy: &windows::Win32::Graphics::Dxgi::IDXGISwapChain3) -> Option<windows::Win32::Graphics::Dxgi::IDXGISwapChain3> {
use windows::Win32::Graphics::Dxgi::{IDXGISwapChain, IDXGISwapChain3};
pub(crate) fn native_swap_chain(proxy: &windows::Win32::Graphics::Dxgi::IDXGISwapChain3) -> Option<windows::Win32::Graphics::Dxgi::IDXGISwapChain> {
let fg = STATE.get()?.as_ref()?;
// SAFETY: a live swap chain; SL gives back an added reference to the native one, or fails.
let raw = unsafe { fg.sl.get_native_interface(proxy.as_raw()) }.ok()?;
if raw.is_null() {
return None;
}
// SAFETY: SL's added reference, now ours; asked for the interface the caller needs.
let base = unsafe { IDXGISwapChain::from_raw(raw) };
base.cast::<IDXGISwapChain3>().ok()
// SAFETY: SL's added reference (a swap chain of the IDXGISwapChain family), now ours.
Some(unsafe { windows::Win32::Graphics::Dxgi::IDXGISwapChain::from_raw(raw) })
}
/// What the last DLSS upscale read: the frame's numbers and its depth and motion vectors (title
@ -860,6 +859,7 @@ fn gbuffer_at_present() {
{
let mut last = lock(&GBUFFER_LAST);
if *last != (0, 0) && *last != (depth, motion) {
GBUFFER_RESET.store(true, Ordering::Relaxed);
let n = GBUFFER_SWAPS.fetch_add(1, Ordering::Relaxed) + 1;
if n <= 8 || n.is_power_of_two() {
tracing::info!(
@ -1051,8 +1051,25 @@ pub(crate) fn present_start(frame: u64, presented: Option<&ID3D12Resource>) {
};
Some((l, look(l.depth)?, look(l.motion)?))
});
// A present with nothing new from its frame (a menu, the map, a loading screen: no G-buffer pass or
// upscale since the last present) carries the last frame's depth and motion vectors, which do not
// join it to the picture before; nor do they the first fresh present after such ones, nor a pass
// whose depth or motion vectors are other textures than the last one's. Each is told as a reset
// (`LEONIDA_FG_RESET_STALE`, on; `0`: only the upscale's own), so that no frame is made between two
// pictures the vectors do not join.
let was_fresh = LAST_FRESH.swap(fresh, Ordering::Relaxed);
let swapped = GBUFFER_RESET.swap(false, Ordering::Relaxed);
let stale = reset_stale_on() && (!fresh || !was_fresh || swapped);
if let Some((l, (depth, depth_state), (motion, motion_state))) = found {
let r = fg.sl.set_constants(&constants(l), token, &VIEWPORT);
let mut c = constants(l);
if stale {
c.reset = sl::Boolean::eTrue;
let n = STALE_RESETS.fetch_add(1, Ordering::Relaxed) + 1;
if n <= 4 || n.is_power_of_two() {
tracing::info!(n, index, fresh, was_fresh, swapped, "frame generation: a present told as a reset (no frame made before it)");
}
}
let r = fg.sl.set_constants(&c, token, &VIEWPORT);
let mut depth_res = sl::Resource::d3d12_tex2d(depth.texture.as_raw(), depth_state);
let mut motion_res = sl::Resource::d3d12_tex2d(motion.texture.as_raw(), motion_state);
let extent = Some(sl::Extent { top: 0, left: 0, width: l.render[0], height: l.render[1] });
@ -1103,6 +1120,20 @@ pub(crate) fn present_start(frame: u64, presented: Option<&ID3D12Resource>) {
/// The present now ending had constants and tags.
static PRESENT_TAGGED: AtomicBool = AtomicBool::new(false);
/// Whether the last present had a fresh G-buffer pass or upscale ([`present_start`]'s resets).
static LAST_FRESH: AtomicBool = AtomicBool::new(true);
/// The G-buffer pass tagged changed textures ([`gbuffer_at_present`]): the next present is a reset.
static GBUFFER_RESET: AtomicBool = AtomicBool::new(false);
/// Presents told as resets because nothing joined them to the picture before ([`present_start`]).
static STALE_RESETS: AtomicU64 = AtomicU64::new(0);
/// `LEONIDA_FG_RESET_STALE` (on; `0` off): presents whose depth and motion vectors do not join them to
/// the picture before are told as resets ([`present_start`]).
fn reset_stale_on() -> bool {
static ON: OnceLock<bool> = OnceLock::new();
*ON.get_or_init(|| std::env::var_os("LEONIDA_FG_RESET_STALE").is_none_or(|v| v != "0"))
}
/// Right after the proxy's `Present` of the title's present number `frame`: its PresentEnd, the
/// next frame's index, Reflex's sleep (without `LEONIDA_FG_MARKERS=1`: with it the sleep is at
/// the title's frame start, [`frame_begins`]), and now and then what the generator says of itself.