F1 settings menu, frame generation 2x-6x live, no frame rate cap, FPS line
On readmet3xt-lab/foxhound 02fc18a, which becomes this fork's base.
- host/menu.rs: the F1 settings menu, in every build (it was in the
diagnostics build only): DLSS mode and model, frame generation, frame
rate cap, console profile, picture size, the light estimates and the
main speed switches. Saved to victory-settings.txt, applied by the
launcher at the next start; "save and restart" from the menu. The title
gets no keyboard while it is shown (gameinput.rs).
- host/font.rs: the dot letters, moved out of the diagnostics panel so
that the menu has them in every build.
- streamline.rs: VICTORY_FRAMEGEN_X=2..6, the frames shown for each one
rendered (no more than the state says this card generates); 0: ready
but off. The amount and off/on change while the title runs
(set_framegen, from the menu). Result 39, "warning: out of VRAM", is
taken as set: asked again at every present it showed no generated
frame at all (1,828 times in one run on a full 12 GB card).
- The frame rate at the top left of the picture while the menu is closed:
frames rendered a second, and with frame generation those shown
(VICTORY_FPS_LINE=0: not). The window's caption says both too.
- scripts/play-foxhound.ps1: applies what the menu saved; -FrameGenX;
-Fps defaults to 1000 (no cap: VICTORY_FRAME_INTERVAL_US=1000); frame
generation is made ready at every start with Streamline so that the
menu can switch it (-NoFrameGenReady: not), with a share of the card's
memory held back for it (VICTORY_TEXTURE_ROOM_PERCENT 80 on, 86 ready);
NVIDIA's files are looked for in nvidia-sdk\ here; builds the layer when
it is not built. scripts/play-nvidia.ps1 is the same launcher under
this fork's old name.
- Get-NVIDIA-DLSS.cmd / scripts/get-nvidia-sdks.ps1: fetch the eight
NVIDIA files that are loaded (about 70 MB) out of NVIDIA's Streamline
release into nvidia-sdk\ (git-ignored). They are NVIDIA's, under
NVIDIA's licences, and are not part of this repository.
- README for this fork; foxhound's own is kept as docs/README-foxhound.md.
Measured on an RTX 5070 (Series X, native 2560x1440, DLSS Quality,
opening rooms): mostly 26-30 frames a second rendered; in Streamline's
own check 2x, 4x and 6x show exactly 2, 4 and 6 frames for each one
rendered.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
1 parent
02fc18a20a
commit
22c6be2e76
14 files changed
+1321
-224
No files matched your search
@@ -3838,6 +3838,8 @@ pub(crate) mod aside;
|
||||
pub(crate) mod awake;
|
||||
mod card_steps;
|
||||
pub(crate) mod indirects;
|
||||
mod font;
|
||||
mod menu;
|
||||
#[cfg(feature = "diagnostics")]
|
||||
mod panel;
|
||||
mod place;
|
||||
@@ -9233,10 +9235,16 @@ struct Presenter {
|
||||
composer: Option<crate::compose::Composer>,
|
||||
#[cfg(feature = "diagnostics")]
|
||||
panel: panel::Panel,
|
||||
/// The F1 settings menu.
|
||||
menu: menu::Menu,
|
||||
}
|
||||
|
||||
/// The frame rate, shown in the window's caption every second and logged
|
||||
/// every few seconds.
|
||||
/// The frame rate the meter last counted, in tenths of a frame a second (0: none yet): for the
|
||||
/// line at the top of the picture (`menu.rs`).
|
||||
pub(crate) static METER_FPS_TENTHS: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(0);
|
||||
|
||||
struct Meter {
|
||||
since: std::time::Instant,
|
||||
frames: u32,
|
||||
@@ -9287,6 +9295,7 @@ impl Meter {
|
||||
let frames = f64::from(self.frames);
|
||||
let fps = frames / elapsed.as_secs_f64();
|
||||
let ms = elapsed.as_secs_f64() * 1000.0 / frames;
|
||||
METER_FPS_TENTHS.store((fps * 10.0).round() as u32, Ordering::Relaxed);
|
||||
let draws = (drawn - self.drawn) as f64 / frames;
|
||||
(self.since, self.frames, self.drawn) = (std::time::Instant::now(), 0, drawn);
|
||||
// Of a frame, ms preparing submissions and ms waiting for the GPU.
|
||||
@@ -9692,7 +9701,11 @@ impl Meter {
|
||||
self.caption = Some(buffer);
|
||||
}
|
||||
let Some(caption) = &self.caption else { return };
|
||||
let text = format!(" | VIctory {fps:.0} fps {ms:.1} ms/frame {draws:.0} draws/frame");
|
||||
// With frame generation showing more frames than are rendered, both rates.
|
||||
let text = match crate::streamline::shown_per_frame() {
|
||||
1 => format!(" | VIctory {fps:.0} fps {ms:.1} ms/frame {draws:.0} draws/frame"),
|
||||
per => format!(" | VIctory {fps:.0} fps (frame gen {:.0} fps) {ms:.1} ms/frame {draws:.0} draws/frame", fps * f64::from(per)),
|
||||
};
|
||||
let mut text: Vec<u16> = caption.iter().copied().chain(text.encode_utf16()).collect();
|
||||
text.push(0);
|
||||
// Setting the text waits for the window's thread (a title thread,
|
||||
@@ -9960,6 +9973,7 @@ impl Host {
|
||||
};
|
||||
#[cfg(feature = "diagnostics")]
|
||||
p.panel.draw(self, copy, &back, (width, height), format);
|
||||
p.menu.draw(self, copy, &back, (width, height), format);
|
||||
#[cfg(not(feature = "diagnostics"))]
|
||||
let _ = frame;
|
||||
if composed {
|
||||
@@ -10021,6 +10035,7 @@ impl Host {
|
||||
showing.next("the frame meter");
|
||||
#[cfg(feature = "diagnostics")]
|
||||
p.panel.frame(p.meter.line_due());
|
||||
p.menu.frame();
|
||||
p.meter.frame(p.hwnd);
|
||||
showing.end();
|
||||
#[cfg(feature = "diagnostics")]
|
||||
@@ -10109,6 +10124,7 @@ impl Host {
|
||||
composer: None,
|
||||
#[cfg(feature = "diagnostics")]
|
||||
panel: panel::Panel::new(),
|
||||
menu: menu::Menu::new(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
//! The dot letters the stats panel (`panel.rs`, diagnostics builds) and the settings menu
|
||||
//! (`menu.rs`, every build) are written with, and the pixels they are painted in.
|
||||
|
||||
use windows::Win32::Graphics::Dxgi::Common::*;
|
||||
|
||||
/// Seven rows of five dots, the leftmost the highest bit.
|
||||
#[rustfmt::skip]
|
||||
pub(super) const fn glyph(c: u8) -> [u8; 7] {
|
||||
match c {
|
||||
b'0' => [0b01110, 0b10001, 0b10011, 0b10101, 0b11001, 0b10001, 0b01110],
|
||||
b'1' => [0b00100, 0b01100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110],
|
||||
b'2' => [0b01110, 0b10001, 0b00001, 0b00110, 0b01000, 0b10000, 0b11111],
|
||||
b'3' => [0b11110, 0b00001, 0b00001, 0b01110, 0b00001, 0b00001, 0b11110],
|
||||
b'4' => [0b00010, 0b00110, 0b01010, 0b10010, 0b11111, 0b00010, 0b00010],
|
||||
b'5' => [0b11111, 0b10000, 0b11110, 0b00001, 0b00001, 0b10001, 0b01110],
|
||||
b'6' => [0b00110, 0b01000, 0b10000, 0b11110, 0b10001, 0b10001, 0b01110],
|
||||
b'7' => [0b11111, 0b00001, 0b00010, 0b00010, 0b00100, 0b00100, 0b00100],
|
||||
b'8' => [0b01110, 0b10001, 0b10001, 0b01110, 0b10001, 0b10001, 0b01110],
|
||||
b'9' => [0b01110, 0b10001, 0b10001, 0b01111, 0b00001, 0b00010, 0b01100],
|
||||
b'A' => [0b00100, 0b01010, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001],
|
||||
b'B' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10001, 0b10001, 0b11110],
|
||||
b'C' => [0b01111, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b01111],
|
||||
b'D' => [0b11110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b11110],
|
||||
b'E' => [0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b11111],
|
||||
b'F' => [0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b10000],
|
||||
b'G' => [0b01111, 0b10000, 0b10000, 0b10011, 0b10001, 0b10001, 0b01111],
|
||||
b'H' => [0b10001, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001, 0b10001],
|
||||
b'I' => [0b01110, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110],
|
||||
b'J' => [0b00111, 0b00010, 0b00010, 0b00010, 0b00010, 0b10010, 0b01100],
|
||||
b'K' => [0b10001, 0b10010, 0b10100, 0b11000, 0b10100, 0b10010, 0b10001],
|
||||
b'L' => [0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b11111],
|
||||
b'M' => [0b10001, 0b11011, 0b10101, 0b10101, 0b10001, 0b10001, 0b10001],
|
||||
b'N' => [0b10001, 0b11001, 0b11001, 0b10101, 0b10011, 0b10011, 0b10001],
|
||||
b'O' => [0b01110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110],
|
||||
b'P' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10000, 0b10000, 0b10000],
|
||||
b'Q' => [0b01110, 0b10001, 0b10001, 0b10001, 0b10101, 0b10010, 0b01101],
|
||||
b'R' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10100, 0b10010, 0b10001],
|
||||
b'S' => [0b01111, 0b10000, 0b10000, 0b01110, 0b00001, 0b00001, 0b11110],
|
||||
b'T' => [0b11111, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100],
|
||||
b'U' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110],
|
||||
b'V' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01010, 0b00100],
|
||||
b'W' => [0b10001, 0b10001, 0b10001, 0b10101, 0b10101, 0b11011, 0b10001],
|
||||
b'X' => [0b10001, 0b10001, 0b01010, 0b00100, 0b01010, 0b10001, 0b10001],
|
||||
b'Y' => [0b10001, 0b10001, 0b01010, 0b00100, 0b00100, 0b00100, 0b00100],
|
||||
b'Z' => [0b11111, 0b00001, 0b00010, 0b00100, 0b01000, 0b10000, 0b11111],
|
||||
b'.' => [0, 0, 0, 0, 0, 0b01100, 0b01100],
|
||||
b'/' => [0b00001, 0b00010, 0b00010, 0b00100, 0b01000, 0b01000, 0b10000],
|
||||
b'-' => [0, 0, 0, 0b11111, 0, 0, 0],
|
||||
// For the settings menu (menu.rs).
|
||||
b'>' => [0b01000, 0b00100, 0b00010, 0b00001, 0b00010, 0b00100, 0b01000],
|
||||
b'<' => [0b00010, 0b00100, 0b01000, 0b10000, 0b01000, 0b00100, 0b00010],
|
||||
b'*' => [0, 0b00100, 0b10101, 0b01110, 0b10101, 0b00100, 0],
|
||||
b':' => [0, 0b01100, 0b01100, 0, 0b01100, 0b01100, 0],
|
||||
b'_' => [0, 0, 0, 0, 0, 0, 0b11111],
|
||||
b'=' => [0, 0, 0b11111, 0, 0b11111, 0, 0],
|
||||
b'(' => [0b00010, 0b00100, 0b01000, 0b01000, 0b01000, 0b00100, 0b00010],
|
||||
b')' => [0b01000, 0b00100, 0b00010, 0b00010, 0b00010, 0b00100, 0b01000],
|
||||
b'+' => [0, 0b00100, 0b00100, 0b11111, 0b00100, 0b00100, 0],
|
||||
b',' => [0, 0, 0, 0, 0b01100, 0b00100, 0b01000],
|
||||
b'!' => [0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0, 0b00100],
|
||||
b'?' => [0b01110, 0b10001, 0b00001, 0b00010, 0b00100, 0, 0b00100],
|
||||
b' ' => [0; 7],
|
||||
_ => [0b11111, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b11111],
|
||||
}
|
||||
}
|
||||
|
||||
/// The bytes of a black and a white pixel of a swap chain's format.
|
||||
pub(super) fn colours(format: DXGI_FORMAT) -> Option<[&'static [u8]; 2]> {
|
||||
Some(match format {
|
||||
DXGI_FORMAT_R8G8B8A8_UNORM | DXGI_FORMAT_B8G8R8A8_UNORM => [&[0, 0, 0, 0xFF], &[0xFF; 4]],
|
||||
DXGI_FORMAT_R10G10B10A2_UNORM => [&[0, 0, 0, 0xC0], &[0xFF; 4]],
|
||||
// Halves of 0 and 1.
|
||||
DXGI_FORMAT_R16G16B16A16_FLOAT => [
|
||||
&[0, 0, 0, 0, 0, 0, 0, 0x3C],
|
||||
&[0, 0x3C, 0, 0x3C, 0, 0x3C, 0, 0x3C],
|
||||
],
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,565 @@
|
||||
//! The F1 settings menu. F1 shows and hides it while our window has the
|
||||
//! focus; Up/Down pick a setting, Left/Right change it, Enter runs the line
|
||||
//! picked (save, save and restart, reset, close), Esc closes. While it is
|
||||
//! shown the title sees no keyboard (`crate::SETTINGS_MENU_OPEN`, read by the
|
||||
//! input module); a pad still works.
|
||||
//!
|
||||
//! The settings are read once at start, so a change is saved to the file
|
||||
//! `VICTORY_MENU_FILE` names (`scripts\play-foxhound.ps1` sets it to
|
||||
//! `victory-settings.txt` in the repository's folder and applies it at every
|
||||
//! start) and takes effect at the next start; "SAVE AND RESTART" starts the
|
||||
//! launcher again (`VICTORY_MENU_PLAY`, with `VICTORY_MENU_ARGS`) and ends
|
||||
//! this run. The `VICTORY_MENU_...` settings are the launcher's own choices
|
||||
//! (DLSS mode, frame generation, frame rate, console, picture size), which it
|
||||
//! turns into the layer's switches; the others are the switches themselves.
|
||||
//!
|
||||
//! In every build (the stats panel is in diagnostics builds only). Drawn as
|
||||
//! that panel is: white text on a black box, copied onto the swap chain's
|
||||
//! buffer, in the middle of the picture.
|
||||
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::{Mutex, OnceLock};
|
||||
use std::time::Duration;
|
||||
|
||||
use windows::Win32::Graphics::Direct3D12::*;
|
||||
use windows::Win32::Graphics::Dxgi::Common::*;
|
||||
use windows_sys::Win32::UI::Input::KeyboardAndMouse::{
|
||||
GetAsyncKeyState, VK_DOWN, VK_ESCAPE, VK_F1, VK_LEFT, VK_RETURN, VK_RIGHT, VK_UP,
|
||||
};
|
||||
use windows_sys::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, GetWindowThreadProcessId};
|
||||
|
||||
use super::font::{colours, glyph};
|
||||
use super::{Host, HostList, transition};
|
||||
|
||||
const GLYPH: (u32, u32) = (5, 7);
|
||||
const CELL: (u32, u32) = (6, 9);
|
||||
const COLUMNS: u32 = 60;
|
||||
/// Lines of the box: a title, a help line, a blank, the settings shown, a
|
||||
/// blank and a note.
|
||||
const ROWS: usize = 20;
|
||||
const LINES: u32 = ROWS as u32 + 5;
|
||||
const RIM: u32 = 4;
|
||||
const UPLOADS: usize = 4;
|
||||
|
||||
/// A setting: the variable, its name in the menu, the values it takes
|
||||
/// (`""`: not set, the build's own default), and whether a change applies at once.
|
||||
struct Item {
|
||||
var: &'static str,
|
||||
label: &'static str,
|
||||
values: &'static [(&'static str, &'static str)],
|
||||
live: bool,
|
||||
}
|
||||
|
||||
const ON_UNSET: &[(&str, &str)] = &[("1", "ON"), ("", "OFF")];
|
||||
const UNSET_ON: &[(&str, &str)] = &[("", "OFF"), ("1", "ON")];
|
||||
const STAGES: &[(&str, &str)] = &[("2", "2"), ("1", "1"), ("0", "0 OFF")];
|
||||
|
||||
/// The first value of each is what the launcher starts with.
|
||||
#[rustfmt::skip]
|
||||
const ITEMS: &[Item] = &[
|
||||
// The launcher's own choices.
|
||||
Item { var: "VICTORY_MENU_DLSS", label: "DLSS", values: &[("quality", "QUALITY"), ("balanced", "BALANCED"), ("performance", "PERFORMANCE"), ("dlaa", "DLAA (NATIVE)"), ("off", "OFF")], live: false },
|
||||
Item { var: "VICTORY_MENU_FRAMEGEN", label: "FRAME GENERATION", values: &[("0", "OFF"), ("2", "2X"), ("3", "3X"), ("4", "4X"), ("5", "5X"), ("6", "6X (MOST)")], live: false },
|
||||
Item { var: "VICTORY_MENU_FPS", label: "FRAME RATE CAP", values: &[("1000", "NONE"), ("120", "120"), ("60", "60"), ("30", "30 (THE GAME)")], live: false },
|
||||
Item { var: "VICTORY_FPS_LINE", label: "FPS AT THE TOP", values: &[("1", "ON"), ("0", "OFF")], live: true },
|
||||
Item { var: "VICTORY_MENU_CONSOLE", label: "CONSOLE", values: &[("series-x", "SERIES X"), ("series-s", "SERIES S (FASTER)")], live: false },
|
||||
Item { var: "VICTORY_MENU_RES", label: "SERIES X PICTURE", values: &[("1440", "2560X1440"), ("1080to1440", "1080P TO 1440P"), ("4k", "3840X2160")], live: false },
|
||||
// The layer's switches.
|
||||
Item { var: "VICTORY_DLSS_PRESET", label: "DLSS MODEL", values: &[("", "DEFAULT"), ("k", "K"), ("j", "J"), ("m", "M"), ("l", "L")], live: false },
|
||||
Item { var: "VICTORY_AMBIENT", label: "LIGHT ESTIMATE", values: &[("0.8", "0.8"), ("1", "1"), ("0.5", "0.5"), ("", "OFF")], live: false },
|
||||
Item { var: "VICTORY_AMBIENT_SPECULAR", label: "REFLECTION ESTIMATE", values: ON_UNSET, live: false },
|
||||
Item { var: "VICTORY_AMBIENT_AIR", label: "FOG CAP", values: &[("1.5", "1.5"), ("1", "1"), ("2", "2"), ("", "NONE")], live: false },
|
||||
Item { var: "VICTORY_BVH_BUILDER", label: "RAY TRACING (SLOW, BROKEN)", values: UNSET_ON, live: false },
|
||||
Item { var: "VICTORY_LEAVE_OUT", label: "HEAT HAZE AND DECAL DEFRAG", values: &[("02384a60fda6f2d0,731a39171b568298", "LEFT OUT"), ("", "RUN (SLOWER, SMEARS)")], live: false },
|
||||
Item { var: "VICTORY_EARLY_DEPTH", label: "EARLY DEPTH TEST", values: ON_UNSET, live: false },
|
||||
Item { var: "VICTORY_WC_NO_BACK", label: "SKIP BIG COPY-BACKS", values: ON_UNSET, live: false },
|
||||
Item { var: "VICTORY_SOFT_VIEWS", label: "SOFT VIEWS (NO CUT FREEZES)", values: &[("copies", "ON"), ("", "OFF")], live: false },
|
||||
Item { var: "VICTORY_TEXTURE_NO_WAIT", label: "TEXTURE NO WAIT", values: ON_UNSET, live: false },
|
||||
Item { var: "VICTORY_RELAY", label: "RELAY (SPEED, TRIANGLES)", values: STAGES, live: false },
|
||||
Item { var: "VICTORY_CARD_STEPS", label: "CARD STEPS", values: STAGES, live: false },
|
||||
Item { var: "VICTORY_INDIRECT_BATCH", label: "INDIRECT BATCH", values: STAGES, live: false },
|
||||
Item { var: "VICTORY_CARD_BUFFERS_MIN_KB", label: "CARD COMPARES FROM (KB)", values: &[("64", "64"), ("1024", "1024")], live: false },
|
||||
Item { var: "VICTORY_PORT_CONSTANTS", label: "CONSTANTS HEAP IN PLACE", values: UNSET_ON, live: false },
|
||||
];
|
||||
/// The lines after the settings.
|
||||
const ACTIONS: [&str; 4] = ["SAVE AND RESTART NOW", "SAVE FOR NEXT START", "RESET ALL TO PLAY DEFAULTS", "CLOSE"];
|
||||
|
||||
fn get(var: &str) -> String {
|
||||
std::env::var(var).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Whether a change of `item` shows at once. Frame generation does when this run started with
|
||||
/// it ready (the launcher asks for that whenever Streamline is there).
|
||||
fn live(item: &Item) -> bool {
|
||||
item.live || (item.var == "VICTORY_MENU_FRAMEGEN" && crate::streamline::framegen_live())
|
||||
}
|
||||
|
||||
/// Whether the frame-rate line is shown at the top while the menu is closed
|
||||
/// (`VICTORY_FPS_LINE=0`: not; the menu changes it).
|
||||
fn fps_line_on() -> &'static AtomicBool {
|
||||
static ON: OnceLock<AtomicBool> = OnceLock::new();
|
||||
ON.get_or_init(|| AtomicBool::new(std::env::var_os("VICTORY_FPS_LINE").is_none_or(|v| v != "0")))
|
||||
}
|
||||
|
||||
/// That line: the frames rendered a second and, while frame generation shows more, those shown.
|
||||
fn fps_line() -> Option<String> {
|
||||
if !fps_line_on().load(Ordering::Relaxed) {
|
||||
return None;
|
||||
}
|
||||
// The stats panel has that corner (diagnostics builds, F3).
|
||||
#[cfg(feature = "diagnostics")]
|
||||
if super::panel::shown().load(Ordering::Relaxed) {
|
||||
return None;
|
||||
}
|
||||
let fps = f64::from(super::METER_FPS_TENTHS.load(Ordering::Relaxed)) / 10.0;
|
||||
if fps <= 0.0 {
|
||||
return None;
|
||||
}
|
||||
Some(match crate::streamline::shown_per_frame() {
|
||||
1 => format!("FPS: {fps:.1}"),
|
||||
per => format!("FPS: {fps:.1} FG: {:.1}", fps * f64::from(per)),
|
||||
})
|
||||
}
|
||||
|
||||
/// The index of `value` among the item's values (an unknown value: shown as
|
||||
/// itself, at the end).
|
||||
fn index_of(item: &Item, value: &str) -> Option<usize> {
|
||||
item.values.iter().position(|(v, _)| *v == value)
|
||||
}
|
||||
|
||||
/// Keys pressed, gathered on a thread of their own every 10 ms: a frame
|
||||
/// lasts 50 ms and more, and a short press would fall between two frames.
|
||||
fn keys() -> &'static Mutex<Vec<u16>> {
|
||||
static KEYS: OnceLock<Mutex<Vec<u16>>> = OnceLock::new();
|
||||
KEYS.get_or_init(|| {
|
||||
let _ = std::thread::Builder::new().name("settings menu keys".into()).spawn(|| {
|
||||
const WATCHED: [u16; 7] = [VK_F1, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT, VK_RETURN, VK_ESCAPE];
|
||||
let mut was = [false; WATCHED.len()];
|
||||
loop {
|
||||
std::thread::sleep(Duration::from_millis(10));
|
||||
let mut process = 0;
|
||||
// SAFETY: plain queries; room for the answer.
|
||||
unsafe { GetWindowThreadProcessId(GetForegroundWindow(), &mut process) };
|
||||
let ours = process == std::process::id();
|
||||
for (i, &vk) in WATCHED.iter().enumerate() {
|
||||
// SAFETY: a plain query.
|
||||
let down = ours && unsafe { GetAsyncKeyState(i32::from(vk)) } < 0;
|
||||
if down && !was[i] {
|
||||
keys().lock().unwrap_or_else(|e| e.into_inner()).push(vk);
|
||||
}
|
||||
was[i] = down;
|
||||
}
|
||||
}
|
||||
});
|
||||
Mutex::new(Vec::new())
|
||||
})
|
||||
}
|
||||
|
||||
/// The box's size in pixels.
|
||||
const fn size(scale: u32) -> (u32, u32) {
|
||||
((COLUMNS * CELL.0 + 2 * RIM) * scale, (LINES * CELL.1 + 2 * RIM) * scale)
|
||||
}
|
||||
|
||||
fn lit(lines: &[String], x: u32, y: u32) -> bool {
|
||||
let (Some(x), Some(y)) = (x.checked_sub(RIM), y.checked_sub(RIM)) else {
|
||||
return false;
|
||||
};
|
||||
if x % CELL.0 >= GLYPH.0 || y % CELL.1 >= GLYPH.1 || x / CELL.0 >= COLUMNS {
|
||||
return false;
|
||||
}
|
||||
let Some(&c) = lines.get((y / CELL.1) as usize).and_then(|l| l.as_bytes().get((x / CELL.0) as usize)) else {
|
||||
return false;
|
||||
};
|
||||
(glyph(c.to_ascii_uppercase())[(y % CELL.1) as usize] >> (GLYPH.0 - 1 - x % CELL.0)) & 1 != 0
|
||||
}
|
||||
|
||||
fn painted(lines: &[String], scale: u32, colours: [&[u8]; 2], pitch: usize) -> Vec<u8> {
|
||||
let (width, height) = size(scale);
|
||||
let bytes = colours[0].len();
|
||||
let mut out = vec![0; pitch * height as usize];
|
||||
for y in 0..height / scale {
|
||||
let top = pitch * (y * scale) as usize;
|
||||
for x in 0..width / scale {
|
||||
let colour = colours[usize::from(lit(lines, x, y))];
|
||||
for i in 0..scale {
|
||||
let at = top + (x * scale + i) as usize * bytes;
|
||||
out[at..at + bytes].copy_from_slice(colour);
|
||||
}
|
||||
}
|
||||
for i in 1..scale as usize {
|
||||
out.copy_within(top..top + pitch, top + i * pitch);
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
struct Buffers {
|
||||
format: DXGI_FORMAT,
|
||||
scale: u32,
|
||||
pitch: u32,
|
||||
uploads: Vec<(ID3D12Resource, *mut u8)>,
|
||||
card: ID3D12Resource,
|
||||
turn: usize,
|
||||
fresh: bool,
|
||||
/// The card's buffer was copied into before (it is in the copy-source state;
|
||||
/// at first it is in the common state, promoted by the first copy).
|
||||
used: bool,
|
||||
}
|
||||
|
||||
// SAFETY: free-threaded resources, and memory only written under the presenter's lock.
|
||||
unsafe impl Send for Buffers {}
|
||||
|
||||
impl Buffers {
|
||||
fn new(host: &Host, format: DXGI_FORMAT, scale: u32) -> Option<Buffers> {
|
||||
let (width, height) = size(scale);
|
||||
let pitch = (width * colours(format)?[0].len() as u32).next_multiple_of(256);
|
||||
let bytes = u64::from(pitch) * u64::from(height);
|
||||
let uploads = (0..UPLOADS).map(|_| host.upload_buffer(bytes)).collect::<Option<Vec<_>>>()?;
|
||||
let heap = D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_DEFAULT, ..Default::default() };
|
||||
let desc = D3D12_RESOURCE_DESC {
|
||||
Dimension: D3D12_RESOURCE_DIMENSION_BUFFER,
|
||||
Width: bytes,
|
||||
Height: 1,
|
||||
DepthOrArraySize: 1,
|
||||
MipLevels: 1,
|
||||
SampleDesc: DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
|
||||
Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
|
||||
..Default::default()
|
||||
};
|
||||
let mut card: Option<ID3D12Resource> = None;
|
||||
// SAFETY: plain creation of a buffer.
|
||||
unsafe {
|
||||
host.device
|
||||
.CreateCommittedResource(&heap, D3D12_HEAP_FLAG_NONE, &desc, D3D12_RESOURCE_STATE_COMMON, None, &mut card)
|
||||
.ok()?;
|
||||
}
|
||||
Some(Buffers { format, scale, pitch, uploads, card: card?, turn: 0, fresh: false, used: false })
|
||||
}
|
||||
|
||||
fn write(&mut self, lines: &[String]) {
|
||||
let Some(colours) = colours(self.format) else { return };
|
||||
let picture = painted(lines, self.scale, colours, self.pitch as usize);
|
||||
self.turn = (self.turn + 1) % UPLOADS;
|
||||
// SAFETY: a mapped upload buffer of the picture's size, which the card read frames ago.
|
||||
unsafe { std::ptr::copy_nonoverlapping(picture.as_ptr(), self.uploads[self.turn].1, picture.len()) };
|
||||
self.fresh = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// The menu of a presenter.
|
||||
pub(super) struct Menu {
|
||||
/// The values chosen, by item (as at start until changed).
|
||||
values: Vec<String>,
|
||||
/// The values at start.
|
||||
started: Vec<String>,
|
||||
/// The line picked: an item, or an action after them.
|
||||
at: usize,
|
||||
note: String,
|
||||
changed: bool,
|
||||
/// What the buffer holds: the frame-rate line, or (none) the menu's lines.
|
||||
painted: Option<String>,
|
||||
buffers: Option<Buffers>,
|
||||
failed: bool,
|
||||
}
|
||||
|
||||
impl Menu {
|
||||
pub(super) fn new() -> Menu {
|
||||
// Start the key thread now: F1 must be seen while the menu is closed.
|
||||
let _ = keys();
|
||||
// `VICTORY_MENU_OPEN=1`: shown from the start (to look at it in a run nobody presses keys in).
|
||||
if std::env::var_os("VICTORY_MENU_OPEN").is_some_and(|v| v == "1") {
|
||||
crate::SETTINGS_MENU_OPEN.store(true, Ordering::Relaxed);
|
||||
}
|
||||
let values: Vec<String> = ITEMS.iter().map(|i| get(i.var)).collect();
|
||||
Menu { started: values.clone(), values, at: 0, note: String::new(), changed: true, painted: None, buffers: None, failed: false }
|
||||
}
|
||||
|
||||
fn open() -> bool {
|
||||
crate::SETTINGS_MENU_OPEN.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
fn lines(&self) -> Vec<String> {
|
||||
let total = ITEMS.len() + ACTIONS.len();
|
||||
let first = self.at.saturating_sub(ROWS / 2).min(total.saturating_sub(ROWS));
|
||||
let mut out = vec![
|
||||
"SETTINGS F1 OR ESC CLOSES".to_owned(),
|
||||
"UP/DOWN PICK LEFT/RIGHT CHANGE ENTER DOES IT".to_owned(),
|
||||
String::new(),
|
||||
];
|
||||
for row in first..(first + ROWS).min(total) {
|
||||
let cursor = if row == self.at { '>' } else { ' ' };
|
||||
let line = if let Some(item) = ITEMS.get(row) {
|
||||
let value = &self.values[row];
|
||||
let shown = index_of(item, value).map_or(value.to_ascii_uppercase(), |i| item.values[i].1.to_owned());
|
||||
let mark = if *value != self.started[row] { if live(item) { " *LIVE" } else { " *" } } else if live(item) { " LIVE" } else { "" };
|
||||
format!("{cursor} {:<27} < {shown} >{mark}", item.label)
|
||||
} else {
|
||||
format!("{cursor} {}", ACTIONS[row - ITEMS.len()])
|
||||
};
|
||||
out.push(line.chars().take(COLUMNS as usize).collect());
|
||||
}
|
||||
while out.len() < 3 + ROWS {
|
||||
out.push(String::new());
|
||||
}
|
||||
out.push(String::new());
|
||||
out.push(if self.note.is_empty() { "* = CHANGED: APPLIES AT THE NEXT START UNLESS LIVE".to_owned() } else { self.note.clone() });
|
||||
out
|
||||
}
|
||||
|
||||
/// Changes item `i` by `step` (+1 / -1) through its values.
|
||||
fn change(&mut self, i: usize, step: isize) {
|
||||
let item = &ITEMS[i];
|
||||
let n = item.values.len() as isize;
|
||||
let now = index_of(item, &self.values[i]).map_or(-1, |x| x as isize);
|
||||
let next = if now < 0 { if step > 0 { 0 } else { n - 1 } } else { (now + step).rem_euclid(n) };
|
||||
self.values[i] = item.values[next as usize].0.to_owned();
|
||||
if live(item) {
|
||||
self.apply_live(i);
|
||||
}
|
||||
self.note.clear();
|
||||
}
|
||||
|
||||
/// A setting the build reads at each use: changed in this run's environment at once.
|
||||
fn apply_live(&self, i: usize) {
|
||||
let (var, value) = (ITEMS[i].var, &self.values[i]);
|
||||
// SAFETY: the variables changed here are read by this build with
|
||||
// std::env::var at each use; Windows' environment block is locked by
|
||||
// the process heap's routines, and std holds its own lock.
|
||||
unsafe {
|
||||
if value.is_empty() {
|
||||
std::env::remove_var(var);
|
||||
} else {
|
||||
std::env::set_var(var, value);
|
||||
}
|
||||
}
|
||||
match var {
|
||||
// Off (0) or the frames shown for each one rendered, from the next present on.
|
||||
"VICTORY_MENU_FRAMEGEN" => crate::streamline::set_framegen(value.parse().unwrap_or(0)),
|
||||
"VICTORY_FPS_LINE" => fps_line_on().store(value != "0", Ordering::Relaxed),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
/// Writes the changed values over those in the settings file.
|
||||
fn save(&mut self) -> bool {
|
||||
let Some(path) = std::env::var_os("VICTORY_MENU_FILE") else {
|
||||
self.note = "NO SETTINGS FILE: START WITH PLAY-FOXHOUND.PS1".to_owned();
|
||||
return false;
|
||||
};
|
||||
let mut kept: Vec<(String, String)> = std::fs::read_to_string(&path)
|
||||
.unwrap_or_default()
|
||||
.lines()
|
||||
.filter_map(|l| l.split_once('=').map(|(k, v)| (k.trim().to_owned(), v.trim().to_owned())))
|
||||
.filter(|(k, _)| k.starts_with("VICTORY_"))
|
||||
.collect();
|
||||
for (i, item) in ITEMS.iter().enumerate() {
|
||||
if self.values[i] == self.started[i] {
|
||||
continue;
|
||||
}
|
||||
kept.retain(|(k, _)| k != item.var);
|
||||
kept.push((item.var.to_owned(), self.values[i].clone()));
|
||||
}
|
||||
let mut text = String::from("# Saved by the F1 menu; scripts\\play-foxhound.ps1 applies these over its own settings (an empty value: unset).\r\n");
|
||||
for (k, v) in &kept {
|
||||
text.push_str(&format!("{k}={v}\r\n"));
|
||||
}
|
||||
match std::fs::write(&path, text) {
|
||||
Ok(()) => {
|
||||
tracing::info!(path = %std::path::Path::new(&path).display(), "settings menu: saved");
|
||||
self.started = self.values.clone();
|
||||
self.note = "SAVED. APPLIES AT THE NEXT START".to_owned();
|
||||
true
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!(error = %e, "settings menu: not saved");
|
||||
self.note = "COULD NOT SAVE THE SETTINGS FILE".to_owned();
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Starts the launcher again in a new console, a few seconds on, and ends this run.
|
||||
fn restart(&mut self) {
|
||||
use std::os::windows::process::CommandExt;
|
||||
let Some(play) = std::env::var_os("VICTORY_MENU_PLAY") else {
|
||||
self.note = "SAVED. START THE LAUNCHER AGAIN YOURSELF".to_owned();
|
||||
return;
|
||||
};
|
||||
let play = play.to_string_lossy().replace('\'', "''");
|
||||
let args = get("VICTORY_MENU_ARGS");
|
||||
let command = format!("Start-Sleep 3; & '{play}' {args}");
|
||||
const CREATE_NEW_CONSOLE: u32 = 0x10;
|
||||
match std::process::Command::new("powershell.exe")
|
||||
.args(["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", &command])
|
||||
.creation_flags(CREATE_NEW_CONSOLE)
|
||||
.spawn()
|
||||
{
|
||||
Ok(_) => {
|
||||
tracing::info!(command, "settings menu: restarting");
|
||||
// Ended at once: std::process::exit runs the DLLs' unloading, which with
|
||||
// Streamline loaded did not come back (a windowless leftover process).
|
||||
// SAFETY: this process, with nothing of its own left to save.
|
||||
unsafe {
|
||||
use windows_sys::Win32::System::Threading::{GetCurrentProcess, TerminateProcess};
|
||||
TerminateProcess(GetCurrentProcess(), 0);
|
||||
}
|
||||
std::process::exit(0);
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::warn!(error = %e, "settings menu: restart failed");
|
||||
self.note = "SAVED, BUT THE RESTART FAILED".to_owned();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Removes the settings file: the launcher's own settings at the next start.
|
||||
fn reset(&mut self) {
|
||||
if let Some(path) = std::env::var_os("VICTORY_MENU_FILE") {
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
self.note = "RESET. PLAY DEFAULTS AT THE NEXT START".to_owned();
|
||||
}
|
||||
|
||||
/// A frame was presented: the keys pressed since the last one.
|
||||
pub(super) fn frame(&mut self) {
|
||||
let pressed = std::mem::take(&mut *keys().lock().unwrap_or_else(|e| e.into_inner()));
|
||||
if pressed.is_empty() {
|
||||
return;
|
||||
}
|
||||
let total = ITEMS.len() + ACTIONS.len();
|
||||
for vk in pressed {
|
||||
let open = Self::open();
|
||||
if vk == VK_F1 || (open && vk == VK_ESCAPE) {
|
||||
crate::SETTINGS_MENU_OPEN.store(!open && vk == VK_F1, Ordering::Relaxed);
|
||||
self.note.clear();
|
||||
self.changed = true;
|
||||
continue;
|
||||
}
|
||||
if !open {
|
||||
continue;
|
||||
}
|
||||
match vk {
|
||||
VK_UP => self.at = (self.at + total - 1) % total,
|
||||
VK_DOWN => self.at = (self.at + 1) % total,
|
||||
VK_LEFT if self.at < ITEMS.len() => self.change(self.at, -1),
|
||||
VK_RIGHT if self.at < ITEMS.len() => self.change(self.at, 1),
|
||||
VK_RETURN if self.at < ITEMS.len() => self.change(self.at, 1),
|
||||
VK_RETURN => match self.at - ITEMS.len() {
|
||||
0 => {
|
||||
if self.save() {
|
||||
self.restart();
|
||||
}
|
||||
}
|
||||
1 => {
|
||||
self.save();
|
||||
}
|
||||
2 => self.reset(),
|
||||
_ => crate::SETTINGS_MENU_OPEN.store(false, Ordering::Relaxed),
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
self.changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// Records the copy of the box onto `back` (in the copy-destination state).
|
||||
pub(super) fn draw(&mut self, host: &Host, list: &HostList, back: &ID3D12Resource, (width, height): (u32, u32), format: DXGI_FORMAT) {
|
||||
if self.failed {
|
||||
return;
|
||||
}
|
||||
// Closed: the frame-rate line in the top left corner, if it is wanted and there is a rate.
|
||||
let open = Self::open();
|
||||
let line = if open { None } else { fps_line() };
|
||||
if !open && line.is_none() {
|
||||
return;
|
||||
}
|
||||
// Our own copies are not part of a recorded frame (the recorder is in diagnostics builds).
|
||||
#[cfg(feature = "diagnostics")]
|
||||
let _ours = crate::replay::record::unrecorded();
|
||||
let scale = (height / 540).max(1);
|
||||
if self.buffers.as_ref().is_none_or(|b| (b.format, b.scale) != (format, scale)) {
|
||||
std::mem::forget(self.buffers.take());
|
||||
self.buffers = Buffers::new(host, format, scale);
|
||||
self.failed = self.buffers.is_none();
|
||||
self.changed = true;
|
||||
}
|
||||
if self.painted != line {
|
||||
self.painted = line.clone();
|
||||
self.changed = true;
|
||||
}
|
||||
let lines = if self.changed { Some(line.as_ref().map_or_else(|| self.lines(), |l| vec![l.clone()])) } else { None };
|
||||
let Some(buffers) = &mut self.buffers else { return };
|
||||
if let Some(lines) = lines {
|
||||
self.changed = false;
|
||||
buffers.write(&lines);
|
||||
}
|
||||
// The whole box in the middle, or of it the first line's part in the corner.
|
||||
let (w, h) = match &line {
|
||||
Some(l) => ((l.len() as u32 * CELL.0 + 2 * RIM) * scale, (CELL.1 + 2 * RIM) * scale),
|
||||
None => size(scale),
|
||||
};
|
||||
let (w, h) = (w.min(width), h.min(height));
|
||||
let (x, y) = if line.is_some() { (0, 0) } else { ((width - w) / 2, (height - h) / 2) };
|
||||
let list = &list.list;
|
||||
// SAFETY: an open list and live resources; the box lies within both.
|
||||
unsafe {
|
||||
if std::mem::take(&mut buffers.fresh) {
|
||||
if std::mem::replace(&mut buffers.used, true) {
|
||||
list.ResourceBarrier(&[transition(&buffers.card, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COPY_DEST)]);
|
||||
}
|
||||
list.CopyResource(&buffers.card, &buffers.uploads[buffers.turn].0);
|
||||
list.ResourceBarrier(&[transition(&buffers.card, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE)]);
|
||||
}
|
||||
let from = D3D12_TEXTURE_COPY_LOCATION {
|
||||
pResource: std::mem::transmute_copy(&buffers.card),
|
||||
Type: D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
|
||||
Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 {
|
||||
PlacedFootprint: D3D12_PLACED_SUBRESOURCE_FOOTPRINT {
|
||||
Offset: 0,
|
||||
Footprint: D3D12_SUBRESOURCE_FOOTPRINT { Format: format, Width: size(scale).0, Height: size(scale).1, Depth: 1, RowPitch: buffers.pitch },
|
||||
},
|
||||
},
|
||||
};
|
||||
let to = D3D12_TEXTURE_COPY_LOCATION {
|
||||
pResource: std::mem::transmute_copy(back),
|
||||
Type: D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
|
||||
Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { SubresourceIndex: 0 },
|
||||
};
|
||||
let part = D3D12_BOX { left: 0, top: 0, front: 0, right: w, bottom: h, back: 1 };
|
||||
list.CopyTextureRegion(&to, x, y, 0, &from, Some(&part));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn every_line_fits_and_every_character_has_a_picture() {
|
||||
let mut menu = Menu { values: ITEMS.iter().map(|_| String::new()).collect(), started: Vec::new(), at: 0, note: String::new(), changed: false, painted: None, buffers: None, failed: false };
|
||||
menu.started = menu.values.clone();
|
||||
for at in 0..ITEMS.len() + ACTIONS.len() {
|
||||
menu.at = at;
|
||||
for line in menu.lines() {
|
||||
assert!(line.len() <= COLUMNS as usize, "{line}");
|
||||
for c in line.bytes() {
|
||||
assert_ne!(glyph(c.to_ascii_uppercase()), glyph(b'#'), "{line}: {}", c as char);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn values_cycle_both_ways() {
|
||||
let mut menu = Menu { values: ITEMS.iter().map(|i| i.values[0].0.to_owned()).collect(), started: Vec::new(), at: 0, note: String::new(), changed: false, painted: None, buffers: None, failed: false };
|
||||
menu.started = menu.values.clone();
|
||||
let n = ITEMS[0].values.len();
|
||||
for _ in 0..n {
|
||||
menu.change(0, 1);
|
||||
}
|
||||
assert_eq!(menu.values[0], ITEMS[0].values[0].0);
|
||||
menu.change(0, -1);
|
||||
assert_eq!(menu.values[0], ITEMS[0].values[n - 1].0);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ use windows::Win32::Graphics::Dxgi::Common::*;
|
||||
use windows_sys::Win32::UI::Input::KeyboardAndMouse::{GetAsyncKeyState, VK_F3};
|
||||
use windows_sys::Win32::UI::WindowsAndMessaging::{GetForegroundWindow, GetWindowThreadProcessId};
|
||||
|
||||
use super::font::{colours, glyph};
|
||||
use super::{Host, HostList, transition};
|
||||
|
||||
/// How often the numbers change.
|
||||
@@ -40,7 +41,7 @@ fn asked() -> bool {
|
||||
}
|
||||
|
||||
/// Whether it is shown now.
|
||||
fn shown() -> &'static AtomicBool {
|
||||
pub(super) fn shown() -> &'static AtomicBool {
|
||||
static SHOWN: OnceLock<AtomicBool> = OnceLock::new();
|
||||
SHOWN.get_or_init(|| AtomicBool::new(asked()))
|
||||
}
|
||||
@@ -59,54 +60,6 @@ fn pressed() -> bool {
|
||||
process == std::process::id()
|
||||
}
|
||||
|
||||
/// Seven rows of five dots, the leftmost the highest bit.
|
||||
#[rustfmt::skip]
|
||||
const fn glyph(c: u8) -> [u8; 7] {
|
||||
match c {
|
||||
b'0' => [0b01110, 0b10001, 0b10011, 0b10101, 0b11001, 0b10001, 0b01110],
|
||||
b'1' => [0b00100, 0b01100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110],
|
||||
b'2' => [0b01110, 0b10001, 0b00001, 0b00110, 0b01000, 0b10000, 0b11111],
|
||||
b'3' => [0b11110, 0b00001, 0b00001, 0b01110, 0b00001, 0b00001, 0b11110],
|
||||
b'4' => [0b00010, 0b00110, 0b01010, 0b10010, 0b11111, 0b00010, 0b00010],
|
||||
b'5' => [0b11111, 0b10000, 0b11110, 0b00001, 0b00001, 0b10001, 0b01110],
|
||||
b'6' => [0b00110, 0b01000, 0b10000, 0b11110, 0b10001, 0b10001, 0b01110],
|
||||
b'7' => [0b11111, 0b00001, 0b00010, 0b00010, 0b00100, 0b00100, 0b00100],
|
||||
b'8' => [0b01110, 0b10001, 0b10001, 0b01110, 0b10001, 0b10001, 0b01110],
|
||||
b'9' => [0b01110, 0b10001, 0b10001, 0b01111, 0b00001, 0b00010, 0b01100],
|
||||
b'A' => [0b00100, 0b01010, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001],
|
||||
b'B' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10001, 0b10001, 0b11110],
|
||||
b'C' => [0b01111, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b01111],
|
||||
b'D' => [0b11110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b11110],
|
||||
b'E' => [0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b11111],
|
||||
b'F' => [0b11111, 0b10000, 0b10000, 0b11110, 0b10000, 0b10000, 0b10000],
|
||||
b'G' => [0b01111, 0b10000, 0b10000, 0b10011, 0b10001, 0b10001, 0b01111],
|
||||
b'H' => [0b10001, 0b10001, 0b10001, 0b11111, 0b10001, 0b10001, 0b10001],
|
||||
b'I' => [0b01110, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b01110],
|
||||
b'J' => [0b00111, 0b00010, 0b00010, 0b00010, 0b00010, 0b10010, 0b01100],
|
||||
b'K' => [0b10001, 0b10010, 0b10100, 0b11000, 0b10100, 0b10010, 0b10001],
|
||||
b'L' => [0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b10000, 0b11111],
|
||||
b'M' => [0b10001, 0b11011, 0b10101, 0b10101, 0b10001, 0b10001, 0b10001],
|
||||
b'N' => [0b10001, 0b11001, 0b11001, 0b10101, 0b10011, 0b10011, 0b10001],
|
||||
b'O' => [0b01110, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110],
|
||||
b'P' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10000, 0b10000, 0b10000],
|
||||
b'Q' => [0b01110, 0b10001, 0b10001, 0b10001, 0b10101, 0b10010, 0b01101],
|
||||
b'R' => [0b11110, 0b10001, 0b10001, 0b11110, 0b10100, 0b10010, 0b10001],
|
||||
b'S' => [0b01111, 0b10000, 0b10000, 0b01110, 0b00001, 0b00001, 0b11110],
|
||||
b'T' => [0b11111, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100, 0b00100],
|
||||
b'U' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01110],
|
||||
b'V' => [0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b01010, 0b00100],
|
||||
b'W' => [0b10001, 0b10001, 0b10001, 0b10101, 0b10101, 0b11011, 0b10001],
|
||||
b'X' => [0b10001, 0b10001, 0b01010, 0b00100, 0b01010, 0b10001, 0b10001],
|
||||
b'Y' => [0b10001, 0b10001, 0b01010, 0b00100, 0b00100, 0b00100, 0b00100],
|
||||
b'Z' => [0b11111, 0b00001, 0b00010, 0b00100, 0b01000, 0b10000, 0b11111],
|
||||
b'.' => [0, 0, 0, 0, 0, 0b01100, 0b01100],
|
||||
b'/' => [0b00001, 0b00010, 0b00010, 0b00100, 0b01000, 0b01000, 0b10000],
|
||||
b'-' => [0, 0, 0, 0b11111, 0, 0, 0],
|
||||
b' ' => [0; 7],
|
||||
_ => [0b11111, 0b10001, 0b10001, 0b10001, 0b10001, 0b10001, 0b11111],
|
||||
}
|
||||
}
|
||||
|
||||
/// The box's size in pixels, a dot being `scale` of them each way.
|
||||
const fn size(scale: u32) -> (u32, u32) {
|
||||
((COLUMNS * CELL.0 + 2 * RIM) * scale, (LINES * CELL.1 + 2 * RIM) * scale)
|
||||
@@ -132,20 +85,6 @@ fn lit(lines: &[String], x: u32, y: u32) -> bool {
|
||||
(glyph(c.to_ascii_uppercase())[(y % CELL.1) as usize] >> (GLYPH.0 - 1 - x % CELL.0)) & 1 != 0
|
||||
}
|
||||
|
||||
/// The bytes of a black and a white pixel of a swap chain's format.
|
||||
fn colours(format: DXGI_FORMAT) -> Option<[&'static [u8]; 2]> {
|
||||
Some(match format {
|
||||
DXGI_FORMAT_R8G8B8A8_UNORM | DXGI_FORMAT_B8G8R8A8_UNORM => [&[0, 0, 0, 0xFF], &[0xFF; 4]],
|
||||
DXGI_FORMAT_R10G10B10A2_UNORM => [&[0, 0, 0, 0xC0], &[0xFF; 4]],
|
||||
// Halves of 0 and 1.
|
||||
DXGI_FORMAT_R16G16B16A16_FLOAT => [
|
||||
&[0, 0, 0, 0, 0, 0, 0, 0x3C],
|
||||
&[0, 0x3C, 0, 0x3C, 0, 0x3C, 0, 0x3C],
|
||||
],
|
||||
_ => return None,
|
||||
})
|
||||
}
|
||||
|
||||
/// The box as rows of `pitch` bytes.
|
||||
fn painted(lines: &[String], scale: u32, colours: [&[u8]; 2], pitch: usize) -> Vec<u8> {
|
||||
let (width, height) = size(scale);
|
||||
|
||||
@@ -43,6 +43,9 @@ mod book;
|
||||
mod heap_marks;
|
||||
#[cfg(windows)]
|
||||
mod host;
|
||||
/// The F1 settings menu is shown (`host/menu.rs`): the title gets no keyboard meanwhile
|
||||
/// (read by the input module).
|
||||
pub static SETTINGS_MENU_OPEN: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);
|
||||
#[cfg(windows)]
|
||||
mod indirect;
|
||||
#[cfg(windows)]
|
||||
|
||||
@@ -259,8 +259,10 @@ struct Calls {
|
||||
optimal: Vec<([u32; 2], u32, Option<[u32; 2]>)>,
|
||||
/// The mode, sizes and preset the last options named.
|
||||
last: Option<(u32, [u32; 2], [u32; 2])>,
|
||||
/// Frame generation: on, and the frame whose simulation began.
|
||||
/// Frame generation: on, the frames for each rendered one last asked of it (0 off), and
|
||||
/// the frame whose simulation began.
|
||||
framegen_on: bool,
|
||||
framegen_times: u32,
|
||||
simulating: Option<u32>,
|
||||
}
|
||||
|
||||
@@ -268,6 +270,7 @@ static CALLS: Mutex<Calls> = Mutex::new(Calls {
|
||||
optimal: Vec::new(),
|
||||
last: None,
|
||||
framegen_on: false,
|
||||
framegen_times: 0,
|
||||
simulating: None,
|
||||
});
|
||||
|
||||
@@ -1450,8 +1453,42 @@ pub(crate) fn present_begins(frame: u64, planes: Planes<'_>) -> Option<Presentin
|
||||
}
|
||||
false
|
||||
};
|
||||
if on != calls.framegen_on {
|
||||
// What is asked right now (the F1 menu changes it while the title runs): off, or the frames
|
||||
// shown for each one rendered. The swap chain stays Streamline's proxy either way.
|
||||
// `VICTORY_FRAMEGEN_CYCLE=<presents>` (a check with nobody at the keys): the amount is asked
|
||||
// anew every that many presents, in turn 2, 4, off and 6, as the settings menu would.
|
||||
static CYCLE: std::sync::OnceLock<u32> = std::sync::OnceLock::new();
|
||||
let every = *CYCLE.get_or_init(|| std::env::var("VICTORY_FRAMEGEN_CYCLE").ok().and_then(|v| v.trim().parse().ok()).unwrap_or(0));
|
||||
if every > 0 {
|
||||
static PRESENTS: AtomicU32 = AtomicU32::new(0);
|
||||
let n = PRESENTS.fetch_add(1, Relaxed);
|
||||
if n % every == 0 {
|
||||
set_framegen([2, 4, 0, 6][(n / every % 4) as usize]);
|
||||
}
|
||||
}
|
||||
let wanted = framegen_wanted();
|
||||
let on = on && wanted != 0;
|
||||
let times = if on { wanted } else { 0 };
|
||||
if on != calls.framegen_on || times != calls.framegen_times {
|
||||
let mut options = abi::DlssgOptions::new(if on { abi::DLSSG_ON } else { abi::DLSSG_OFF });
|
||||
// `VICTORY_FRAMEGEN_X=2..6`: frames shown for each one rendered (2 unless set), no more
|
||||
// than this card and driver generate (the state says how many: 5 on an RTX 50).
|
||||
let mut generated = wanted.max(2) - 1;
|
||||
if on
|
||||
&& generated > 1
|
||||
&& let Some(get_state) = functions.dlssg_get_state
|
||||
{
|
||||
let mut state = abi::DlssgState::default();
|
||||
// SAFETY: a structure to fill, no options.
|
||||
let code = unsafe { get_state(&viewport, &mut state, std::ptr::null()) };
|
||||
let most = if code == 0 { state.num_frames_to_generate_max.max(1) } else { 1 };
|
||||
if generated > most {
|
||||
tracing::warn!(asked = generated + 1, given = most + 1, "DLSS Frame Generation: more frames asked than this card generates");
|
||||
generated = most;
|
||||
}
|
||||
}
|
||||
options.num_frames_to_generate = generated;
|
||||
FG_TIMES.store(generated + 1, Relaxed);
|
||||
options.flags = abi::DLSSG_RETAIN_RESOURCES_WHEN_OFF;
|
||||
options.num_back_buffers = 2;
|
||||
options.color_width = planes.size[0];
|
||||
@@ -1459,9 +1496,20 @@ pub(crate) fn present_begins(frame: u64, planes: Planes<'_>) -> Option<Presentin
|
||||
options.on_error_callback = Some(present_error);
|
||||
// SAFETY: filled options for viewport 0, on the presenting thread.
|
||||
let code = unsafe { set_options(&viewport, &options) };
|
||||
tracing::info!(frame, on, code, result = abi::result_name(code), "DLSS Frame Generation switched");
|
||||
if code == 0 {
|
||||
tracing::info!(frame, on, times = generated + 1, code, result = abi::result_name(code), "DLSS Frame Generation switched");
|
||||
// 39, "warning: out of VRAM": the options are set all the same, with the card's memory
|
||||
// past its budget. Taken as set: asked again at every present (1,828 times in one
|
||||
// run, after the menu's 3X on a full 12 GB card) it showed no generated frame at all.
|
||||
if code == 39 {
|
||||
tracing::warn!(times = generated + 1, "DLSS Frame Generation is on with the card's memory past its budget: frames may come unevenly (the launcher leaves it room when it is on from the start)");
|
||||
}
|
||||
if code == 0 || code == 39 {
|
||||
calls.framegen_on = on;
|
||||
// What was asked (the driver may give fewer): not set again until that changes.
|
||||
calls.framegen_times = times;
|
||||
if !on {
|
||||
FG_PER.store(1, Relaxed);
|
||||
}
|
||||
}
|
||||
}
|
||||
if calls.framegen_on {
|
||||
@@ -1529,6 +1577,49 @@ unsafe extern "C" fn present_error(error: *const i32) {
|
||||
once!(warn, hresult = format_args!("{:#x}", code as u32), "DLSS Frame Generation: a present failed");
|
||||
}
|
||||
|
||||
/// Frames shown for each one rendered with frame generation on, as asked at the start:
|
||||
/// `VICTORY_FRAMEGEN_X=2..6` (2 unless set); 0: ready but off until the settings menu asks.
|
||||
fn framegen_times() -> u32 {
|
||||
static TIMES: std::sync::OnceLock<u32> = std::sync::OnceLock::new();
|
||||
*TIMES.get_or_init(|| {
|
||||
std::env::var("VICTORY_FRAMEGEN_X").ok().and_then(|v| v.trim().parse::<u32>().ok()).map_or(2, |n| if n == 0 { 0 } else { n.clamp(2, 6) })
|
||||
})
|
||||
}
|
||||
|
||||
/// Frames shown for each one rendered, as last given to frame generation.
|
||||
static FG_TIMES: std::sync::atomic::AtomicU32 = std::sync::atomic::AtomicU32::new(2);
|
||||
|
||||
/// What is asked of frame generation now: 0 off, 2..6 frames shown for each one rendered;
|
||||
/// `u32::MAX`: not asked yet (then [`framegen_times`], the start's).
|
||||
static FG_WANTED: AtomicU32 = AtomicU32::new(u32::MAX);
|
||||
/// Frames frame generation showed for the last frame presented (1 while it is off).
|
||||
static FG_PER: AtomicU32 = AtomicU32::new(1);
|
||||
|
||||
fn framegen_wanted() -> u32 {
|
||||
match FG_WANTED.load(Relaxed) {
|
||||
u32::MAX => framegen_times(),
|
||||
n => n,
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether frame generation can be switched and changed while the title runs: it was planned
|
||||
/// at the start, so our swap chain is Streamline's proxy (the F1 menu asks).
|
||||
pub(crate) fn framegen_live() -> bool {
|
||||
FG_READY.load(Acquire) && SWAP_CHAIN_PROXIED.load(Acquire)
|
||||
}
|
||||
|
||||
/// Asks frame generation off (0) or for `times` frames shown for each one rendered (2..6),
|
||||
/// from the next present on.
|
||||
pub(crate) fn set_framegen(times: u32) {
|
||||
FG_WANTED.store(if times == 0 { 0 } else { times.clamp(2, 6) }, Relaxed);
|
||||
tracing::info!(times, "DLSS Frame Generation: asked from the settings menu");
|
||||
}
|
||||
|
||||
/// For the frame-rate texts: frames shown for each one rendered (1 without frame generation).
|
||||
pub(crate) fn shown_per_frame() -> u32 {
|
||||
FG_PER.load(Relaxed).max(1)
|
||||
}
|
||||
|
||||
/// After our swap chain's Present: the frame's last marker, the next
|
||||
/// frame's first, and what frame generation reports.
|
||||
pub(crate) fn present_ends(presenting: Option<Presenting>) {
|
||||
@@ -1553,6 +1644,7 @@ pub(crate) fn present_ends(presenting: Option<Presenting>) {
|
||||
let code = unsafe { get_state(&viewport, &mut state, std::ptr::null()) };
|
||||
spent(T_STATE, asked);
|
||||
if code == 0 {
|
||||
FG_PER.store(state.num_frames_actually_presented.max(1), Relaxed);
|
||||
FG_SHOWN.fetch_add(u64::from(state.num_frames_actually_presented), Relaxed);
|
||||
FG_SHOWN_ALL.fetch_add(u64::from(state.num_frames_actually_presented), Relaxed);
|
||||
let before = FG_STATUS.swap(state.status, Relaxed);
|
||||
@@ -1581,6 +1673,8 @@ pub(crate) fn resizing() {
|
||||
// SAFETY: filled options.
|
||||
unsafe { set_options(&viewport, &options) };
|
||||
calls.framegen_on = false;
|
||||
calls.framegen_times = 0;
|
||||
FG_PER.store(1, Relaxed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1208,6 +1208,10 @@ mod host {
|
||||
}
|
||||
|
||||
fn keys(&mut self) -> Vec<KeyState> {
|
||||
// The F1 settings menu takes the keyboard while it is shown.
|
||||
if victory_gpu::SETTINGS_MENU_OPEN.load(std::sync::atomic::Ordering::Relaxed) {
|
||||
return Vec::new();
|
||||
}
|
||||
let mut down = scripted();
|
||||
if focused() {
|
||||
// Left/right modifier keys only, as devices report them; no
|
||||
|
||||
Reference in new issue
Block a user