Frames shown as soon as presented, underwater shader back, warm-up restart only with frame generation

- Swap chain: DXGI's tearing support where the system has it, so a focused
  window (independent flip) no longer waits for each refresh, about 2 fps
  more in front. VICTORY_TEARING=0 turns it off; a refused present of that
  kind falls back to presenting at the next refresh for the rest of the run,
  and is logged.
- Shaders: a program that has no wave32 lowering with the loop step on
  (VICTORY_LOOPS_WAVE) is translated again without it, so the water compute
  shader 926c46bab3b86bd6 runs again (black or missing water underwater,
  #539, #570).
- The first start of a new exe restarts by itself only when DLSS frame
  generation is ready or on; without it a first run plays at full speed.
- F1: turning frame generation on in a run started without it says
  "RESTART REQUIRED TO ENABLE FRAME GENERATION".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
trustno1-coderandClaude Opus 5.5 committed 2026-11-27 18:44:17 -08:00
1 parent b4e1b08245
commit 8fc22547c8
4 files changed
+127 -4

No files matched your search

+3
View File
@@ -868,7 +868,10 @@ pub(crate) fn prepare(o: &Play) -> Result<Ready> {
// The first start of this victory.exe (no mark for its bytes yet): the game plays a little
// and starts again by itself (crates\victory-gpu\src\host\menu.rs, `warmup`), since a new
// exe's first run stays at about 14 fps. `--set VICTORY_WARMUP_RESTART=0`: not done.
// Only with DLSS Frame Generation ready or on: its swap chain (Streamline's) is what held
// a first run at 14 fps (#515, #574); without it a first run plays at full speed.
if !s.contains_key("VICTORY_WARMUP_RESTART")
&& s.get("VICTORY_FRAMEGEN").is_some_and(|v| v == "1")
&& let Some(mark) = warmup_mark(&home, &program)
&& !mark.exists()
{
+53 -2
View File
@@ -9638,6 +9638,41 @@ struct Presenter {
notice: panel::Notice,
/// The F1 settings menu.
menu: menu::Menu,
/// The swap chain lets a frame be shown at once ([`tearing`]): its flags, kept for
/// ResizeBuffers, which may not change them.
tearing: bool,
/// Presents ask for that; off for the rest of the run once one such present is refused.
presents_tearing: bool,
/// A refused present was logged.
present_refused: bool,
}
/// Whether the swap chain lets a frame be shown as soon as it is presented, not at the screen's
/// next refresh (`DXGI_FEATURE_PRESENT_ALLOW_TEARING`; `VICTORY_TEARING=0`: not). Without it a
/// window in front, which Windows then shows without its compositor ("independent flip"), had
/// each frame wait for a refresh with two buffers: frame times rounded up to whole refreshes,
/// about 2 fps fewer than the same window behind another (2026-11-28). On a G-SYNC or FreeSync
/// screen nothing tears; on others a frame may.
fn tearing(factory: &IDXGIFactory2) -> bool {
if std::env::var("VICTORY_TEARING").is_ok_and(|v| v.trim() == "0") {
return false;
}
let Ok(factory) = factory.cast::<IDXGIFactory5>() else { return false };
let mut allowed = windows::core::BOOL(0);
// SAFETY: a BOOL-sized answer for this feature.
let asked = unsafe {
factory.CheckFeatureSupport(
DXGI_FEATURE_PRESENT_ALLOW_TEARING,
(&raw mut allowed).cast(),
size_of_val(&allowed) as u32,
)
};
asked.is_ok() && allowed.as_bool()
}
/// The swap chain's flags for [`tearing`].
fn chain_flags(tearing: bool) -> DXGI_SWAP_CHAIN_FLAG {
if tearing { DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING } else { DXGI_SWAP_CHAIN_FLAG(0) }
}
/// The frame rate, shown in the window's caption every second and logged
@@ -10240,7 +10275,7 @@ impl Host {
// SAFETY: no back buffer is held; every submission was waited for.
let resized = unsafe {
p.swap_chain
.ResizeBuffers(BUFFERS, width, height, format, DXGI_SWAP_CHAIN_FLAG(0))
.ResizeBuffers(BUFFERS, width, height, format, chain_flags(p.tearing))
};
match resized {
Ok(()) => {
@@ -10478,7 +10513,17 @@ impl Host {
},
);
let called = crate::streamline::present_called(&presenting);
let _ = p.swap_chain.Present(0, DXGI_PRESENT(0));
let shown = p.swap_chain.Present(0, if p.presents_tearing { DXGI_PRESENT_ALLOW_TEARING } else { DXGI_PRESENT(0) });
if shown.is_err() && p.presents_tearing {
// A white window on an RTX 5070 at 1440p (2026-11-28): presents that may tear
// were not shown. The rest of the run presents at the next refresh.
tracing::warn!(code = %shown, frame, "a present shown at once was refused; presenting at the next refresh for the rest of the run");
p.presents_tearing = false;
let _ = p.swap_chain.Present(0, DXGI_PRESENT(0));
} else if shown.is_err() && !p.present_refused {
p.present_refused = true;
tracing::warn!(code = %shown, frame, "a present was refused (logged once)");
}
crate::streamline::present_returned(called);
crate::streamline::present_ends(presenting);
showing.next("the frame meter");
@@ -10515,6 +10560,8 @@ impl Host {
// SAFETY: plain object creation for our window.
unsafe {
let factory: IDXGIFactory2 = CreateDXGIFactory2(DXGI_CREATE_FACTORY_FLAGS(0))?;
let tearing = tearing(&factory);
tracing::info!(tearing, "swap chain: frames shown as soon as presented (VICTORY_TEARING=0: at the next refresh)");
let desc = DXGI_SWAP_CHAIN_DESC1 {
Width: width,
Height: height,
@@ -10526,6 +10573,7 @@ impl Host {
BufferUsage: DXGI_USAGE_RENDER_TARGET_OUTPUT,
BufferCount: BUFFERS,
SwapEffect: DXGI_SWAP_EFFECT_FLIP_DISCARD,
Flags: chain_flags(tearing).0 as u32,
..Default::default()
};
// FSR 3 frame generation (where DLSS Frame Generation does not
@@ -10576,6 +10624,9 @@ impl Host {
panel: panel::Panel::new(),
notice: panel::Notice::new(),
menu: menu::Menu::new(),
tearing,
presents_tearing: tearing,
present_refused: false,
})
}
}
+33
View File
@@ -102,6 +102,15 @@ const ABOUT_NO_DLSS: [&str; 3] = [
"DOWNLOADED FROM NVIDIA ON GITHUB AT THE NEXT START",
"(ABOUT 70 MB, ONCE). SAVE AND RESTART NOW DOES IT.",
];
/// Frame generation that this run did not start with: it is made ready only at a start with it
/// on (a start with it ready but off held some PCs at 14 fps, #515, #574), so turning it on takes
/// a restart; a run started with it on changes it, or turns it off, live.
const ABOUT_FRAMEGEN_RESTART: [&str; 3] = [
"RESTART REQUIRED TO ENABLE FRAME GENERATION: THIS RUN",
"STARTED WITHOUT IT. SAVE AND RESTART NOW TURNS IT ON.",
"AFTER THAT IT CHANGES, OR TURNS OFF, LIVE.",
];
const FRAMEGEN: &str = "VICTORY_MENU_FRAMEGEN";
/// The note after the first Enter on it: the second one does it.
const CONFIRM_PRELOAD: &str = "ENTER AGAIN: SAVE, CLOSE THE GAME AND PRELOAD";
/// The last line of the box: where this build comes from.
@@ -514,6 +523,10 @@ impl Menu {
&& std::env::var_os("VICTORY_STREAMLINE_DIR").is_none()
{
ABOUT_NO_DLSS
} else if ITEMS.get(self.at).is_some_and(|i| i.var == FRAMEGEN && !live(i))
&& !matches!(self.values[self.at].as_str(), "" | "0")
{
ABOUT_FRAMEGEN_RESTART
} else {
[""; 3]
};
@@ -558,6 +571,9 @@ impl Menu {
self.apply_live(i);
}
self.note.clear();
if item.var == FRAMEGEN && !live(item) && !matches!(self.values[i].as_str(), "" | "0") {
"RESTART REQUIRED TO ENABLE FRAME GENERATION".clone_into(&mut self.note);
}
}
/// A setting the build reads at each use: changed in this run's environment at once.
@@ -1041,6 +1057,23 @@ mod tests {
let lines = menu.lines();
assert!(lines[lines.len() - 5..lines.len() - 2].iter().all(String::is_empty));
assert_eq!(ITEMS.iter().filter(|i| i.var == MFG).count(), 1);
// Frame generation turned on in a run started without it (no Streamline in tests): a
// restart is required, and the menu says so; OFF needs no word.
for line in ABOUT_FRAMEGEN_RESTART {
assert!(line.len() <= COLUMNS as usize && line.bytes().all(|c| glyph(c) != glyph(b'#')), "{line}");
}
let fg = ITEMS.iter().position(|i| i.var == FRAMEGEN).expect("in the menu");
menu.at = fg;
menu.values[fg] = "0".to_owned();
menu.change(fg, 1);
assert_eq!(menu.values[fg], "2");
assert_eq!(menu.note, "RESTART REQUIRED TO ENABLE FRAME GENERATION");
let lines = menu.lines();
assert_eq!(&lines[lines.len() - 5..lines.len() - 2], ABOUT_FRAMEGEN_RESTART);
menu.change(fg, -1);
assert!(menu.note.is_empty());
let lines = menu.lines();
assert!(lines[lines.len() - 5..lines.len() - 2].iter().all(String::is_empty));
}
#[test]
+38 -2
View File
@@ -511,7 +511,11 @@ fn translate_plain(container: &[u8]) -> Result<HostShader, ShaderError> {
emit(&c, &native, &p, &st, &io, &res)
}
/// Emits a program whose earlier stages already ran.
/// Emits a program whose earlier stages already ran ([`emit_once`]). A wave64 compute program
/// that does not translate with the branches that close or leave its loops taken by each host
/// wave together ([`loops_wave`]) is tried once more without them, as before that step: the
/// underwater picture's program (`926c46bab3b86bd6`) translated before it and no longer did, so
/// its dispatch was dropped and diving showed a field of white flares (#539, #570).
pub fn emit(
c: &Container,
native: &NativeProgram,
@@ -519,6 +523,38 @@ pub fn emit(
st: &structure::Structured,
io: &io::Io,
res: &resource::Resources,
) -> Result<HostShader, ShaderError> {
let first = emit_once(c, native, p, st, io, res);
if !matches!(first, Err(ShaderError::Unsupported { .. })) || !loops_wave(native) {
return first;
}
LOOPS_OFF.with(|off| off.set(true));
let again = emit_once(c, native, p, st, io, res);
LOOPS_OFF.with(|off| off.set(false));
match again {
Ok(shader) => {
if std::env::var_os("VICTORY_WAVE_WHY").is_some() {
eprintln!("WAVE-LOOPS left out: the program translates without them");
}
Ok(shader)
}
Err(_) => first,
}
}
thread_local! {
/// [`emit`]'s second try: [`loops_wave`] off.
static LOOPS_OFF: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
}
/// One try of [`emit`].
fn emit_once(
c: &Container,
native: &NativeProgram,
p: &ir::Program,
st: &structure::Structured,
io: &io::Io,
res: &resource::Resources,
) -> Result<HostShader, ShaderError> {
// (what an earlier program's lowering on this thread left behind)
lower::take_needs();
@@ -903,7 +939,7 @@ fn widen(
/// - `2`: every compute program;
/// - `0`: none, as before.
fn loops_wave(native: &NativeProgram) -> bool {
if native.stage != HwStage::Cs {
if native.stage != HwStage::Cs || LOOPS_OFF.with(std::cell::Cell::get) {
return false;
}
match std::env::var("VICTORY_LOOPS_WAVE").ok().as_deref().map(str::trim) {