AMD FSR 3 frame generation for cards without DLSS frame generation; start notice; F1 preload
- FSR 3 frame generation (AMD FidelityFX 2.x DLLs, never in the repository: VICTORY_FIDELITYFX_DIR or a fidelityfx folder beside victory.exe), 2x at most, with the HUD-less picture so the HUD is not doubled. Series X needs DLSS upscaling. - F1 menu: FRAME GEN TYPE (auto, DLSS, FSR 3); PRELOAD SHADERS; unset rows read NOT SET; save and restart opens its own console window. - A notice at the start (30 s on the picture, and in the console): the GPU, which frame generation runs, and why not (DLSS off, NVIDIA files missing, or the card). - victory preload / --preload; warm keys its work to the program's path. - Logs are named victory-nvidia-...; README: what each card supports, first. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
d12eb1b23d
commit
29d8dbf7d9
12 files changed
+1712
-118
No files matched your search
@@ -1,6 +1,9 @@
|
||||
//! 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
|
||||
//! picked (save, save and restart, preload shaders, reset, close), Esc
|
||||
//! closes. Preloading saves, ends this run and has the launcher make every
|
||||
//! shader before the title starts again (`VICTORY_PRELOAD=1`, `victory
|
||||
//! preload`); it asks for a second Enter first. While it is
|
||||
//! shown the title sees no keyboard (`crate::SETTINGS_MENU_OPEN`, read by the
|
||||
//! input module); a pad still works.
|
||||
//!
|
||||
@@ -35,9 +38,21 @@ 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.
|
||||
/// blank, what the line picked does (`ABOUT`, else blank), a note and the
|
||||
/// repository's link.
|
||||
const ROWS: usize = 20;
|
||||
const LINES: u32 = ROWS as u32 + 5;
|
||||
const LINES: u32 = ROWS as u32 + 9;
|
||||
/// The action that preloads shaders, and what is said of it while it is picked.
|
||||
const PRELOAD: usize = 2;
|
||||
const ABOUT_PRELOAD: [&str; 3] = [
|
||||
"MAKES EVERY SHADER AHEAD, THEN STARTS THE GAME AGAIN.",
|
||||
"TAKES A WHILE: MAYBE A LONG TIME, DEPENDING ON HARDWARE.",
|
||||
"A LATER UPDATE OF THIS BUILD MAY NEED A NEW PRELOAD.",
|
||||
];
|
||||
/// 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.
|
||||
const REPO: &str = "GITHUB.COM/TRUSTNO1-CODER/VICTORY-NVIDIA";
|
||||
const RIM: u32 = 4;
|
||||
const UPLOADS: usize = 4;
|
||||
|
||||
@@ -60,6 +75,8 @@ 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 },
|
||||
// DLSS Frame Generation where it runs (RTX 40 and later), else AMD's FSR 3 (2X only).
|
||||
Item { var: "VICTORY_MENU_FG_TYPE", label: "FRAME GEN TYPE", values: &[("auto", "AUTO"), ("dlss", "DLSS"), ("fsr", "FSR 3 (OLDER CARDS)")], 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_PANEL", label: "STATS PANEL (F3)", values: &[("0", "OFF"), ("1", "ON")], live: true },
|
||||
@@ -87,12 +104,52 @@ const ITEMS: &[Item] = &[
|
||||
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"];
|
||||
const ACTIONS: [&str; 5] =
|
||||
["SAVE AND RESTART NOW", "SAVE FOR NEXT START", "PRELOAD SHADERS (RESTARTS THE GAME)", "RESET ALL TO PLAY DEFAULTS", "CLOSE"];
|
||||
|
||||
fn get(var: &str) -> String {
|
||||
std::env::var(var).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Starts `command_line` in a console window of its own, with that console's input and output.
|
||||
/// (`std::process::Command` always hands its child this process's standard handles: the restarted
|
||||
/// launcher then wrote into the old launcher's pipe and log, not its own window, and kept the old
|
||||
/// launcher waiting on that pipe.)
|
||||
fn new_console(command_line: &str) -> std::io::Result<()> {
|
||||
use windows_sys::Win32::Foundation::CloseHandle;
|
||||
use windows_sys::Win32::System::Threading::{CREATE_NEW_CONSOLE, CreateProcessW, PROCESS_INFORMATION, STARTUPINFOW};
|
||||
let mut line: Vec<u16> = command_line.encode_utf16().chain(Some(0)).collect();
|
||||
// SAFETY: plain structs, zero is their empty value.
|
||||
let mut startup: STARTUPINFOW = unsafe { std::mem::zeroed() };
|
||||
startup.cb = std::mem::size_of::<STARTUPINFOW>() as u32;
|
||||
let mut process: PROCESS_INFORMATION = unsafe { std::mem::zeroed() };
|
||||
// SAFETY: `line` is a writable, terminated UTF-16 string; no handles inherited; this
|
||||
// process's environment and folder.
|
||||
let made = unsafe {
|
||||
CreateProcessW(
|
||||
std::ptr::null(),
|
||||
line.as_mut_ptr(),
|
||||
std::ptr::null(),
|
||||
std::ptr::null(),
|
||||
0,
|
||||
CREATE_NEW_CONSOLE,
|
||||
std::ptr::null(),
|
||||
std::ptr::null(),
|
||||
&startup,
|
||||
&mut process,
|
||||
)
|
||||
};
|
||||
if made == 0 {
|
||||
return Err(std::io::Error::last_os_error());
|
||||
}
|
||||
// SAFETY: the two handles CreateProcessW gave, closed once.
|
||||
unsafe {
|
||||
CloseHandle(process.hThread);
|
||||
CloseHandle(process.hProcess);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
@@ -131,6 +188,17 @@ fn index_of(item: &Item, value: &str) -> Option<usize> {
|
||||
item.values.iter().position(|(v, _)| *v == value)
|
||||
}
|
||||
|
||||
/// What the menu shows for `value`: its label, an unknown value as itself,
|
||||
/// and a value the launcher did not set (a start without play.ps1) as
|
||||
/// "NOT SET" rather than a blank.
|
||||
fn shown_value(item: &Item, value: &str) -> String {
|
||||
match index_of(item, value) {
|
||||
Some(i) => item.values[i].1.to_owned(),
|
||||
None if value.is_empty() => "NOT SET".to_owned(),
|
||||
None => value.to_ascii_uppercase(),
|
||||
}
|
||||
}
|
||||
|
||||
/// 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>> {
|
||||
@@ -294,7 +362,7 @@ impl Menu {
|
||||
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 shown = shown_value(item, value);
|
||||
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 {
|
||||
@@ -306,7 +374,10 @@ impl Menu {
|
||||
out.push(String::new());
|
||||
}
|
||||
out.push(String::new());
|
||||
let about = if self.at == ITEMS.len() + PRELOAD { ABOUT_PRELOAD } else { [""; 3] };
|
||||
out.extend(about.iter().map(|l| (*l).to_owned()));
|
||||
out.push(if self.note.is_empty() { "* = CHANGED: APPLIES AT THE NEXT START UNLESS LIVE".to_owned() } else { self.note.clone() });
|
||||
out.push(REPO.to_owned());
|
||||
out
|
||||
}
|
||||
|
||||
@@ -384,23 +455,18 @@ impl Menu {
|
||||
}
|
||||
|
||||
/// 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;
|
||||
/// `preload`: the launcher makes every shader first (its `-Preload`, for that start alone).
|
||||
fn restart(&mut self, preload: bool) {
|
||||
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");
|
||||
let command = format!("Start-Sleep 3; & '{play}' {args}{}", if preload { " -Preload" } else { "" });
|
||||
match new_console(&format!("powershell.exe -NoProfile -ExecutionPolicy Bypass -Command \"{}\"", command.replace('"', "\\\""))) {
|
||||
Ok(()) => {
|
||||
tracing::info!(command, preload, "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.
|
||||
@@ -443,6 +509,11 @@ impl Menu {
|
||||
if !open {
|
||||
continue;
|
||||
}
|
||||
// Only an Enter right after the first one starts a preload.
|
||||
let confirmed = self.note == CONFIRM_PRELOAD;
|
||||
if confirmed {
|
||||
self.note.clear();
|
||||
}
|
||||
match vk {
|
||||
VK_UP => self.at = (self.at + total - 1) % total,
|
||||
VK_DOWN => self.at = (self.at + 1) % total,
|
||||
@@ -452,13 +523,19 @@ impl Menu {
|
||||
VK_RETURN => match self.at - ITEMS.len() {
|
||||
0 => {
|
||||
if self.save() {
|
||||
self.restart();
|
||||
self.restart(false);
|
||||
}
|
||||
}
|
||||
1 => {
|
||||
self.save();
|
||||
}
|
||||
2 => self.reset(),
|
||||
PRELOAD if !confirmed => self.note = CONFIRM_PRELOAD.to_owned(),
|
||||
PRELOAD => {
|
||||
if self.save() {
|
||||
self.restart(true);
|
||||
}
|
||||
}
|
||||
3 => self.reset(),
|
||||
_ => crate::SETTINGS_MENU_OPEN.store(false, Ordering::Relaxed),
|
||||
},
|
||||
_ => {}
|
||||
@@ -555,6 +632,32 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_link_is_always_right_under_the_note() {
|
||||
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 note in ["", "SAVED"] {
|
||||
menu.note = note.to_owned();
|
||||
for at in 0..ITEMS.len() + ACTIONS.len() {
|
||||
menu.at = at;
|
||||
let lines = menu.lines();
|
||||
assert_eq!(lines.len(), LINES as usize);
|
||||
let n = lines.len();
|
||||
assert!(lines[n - 2].starts_with("* = CHANGED") || lines[n - 2] == note, "{}", lines[n - 2]);
|
||||
assert_eq!(lines[n - 1], REPO);
|
||||
// What a preload costs is said while it is picked, and only then.
|
||||
let about = &lines[n - 5..n - 2];
|
||||
if at == ITEMS.len() + PRELOAD {
|
||||
assert_eq!(about, ABOUT_PRELOAD);
|
||||
} else {
|
||||
assert!(about.iter().all(String::is_empty), "{about:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
assert_eq!(ACTIONS[PRELOAD], "PRELOAD SHADERS (RESTARTS THE GAME)");
|
||||
assert!(CONFIRM_PRELOAD.len() <= COLUMNS as usize);
|
||||
}
|
||||
|
||||
#[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 };
|
||||
|
||||
@@ -62,9 +62,19 @@ fn pressed() -> bool {
|
||||
process == std::process::id()
|
||||
}
|
||||
|
||||
/// A box's characters in a line, and lines.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub(super) struct Shape {
|
||||
columns: u32,
|
||||
lines: u32,
|
||||
}
|
||||
|
||||
/// The numbers panel's box.
|
||||
const PANEL: Shape = Shape { columns: COLUMNS, lines: LINES };
|
||||
|
||||
/// 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)
|
||||
const fn size(shape: Shape, scale: u32) -> (u32, u32) {
|
||||
((shape.columns * CELL.0 + 2 * RIM) * scale, (shape.lines * CELL.1 + 2 * RIM) * scale)
|
||||
}
|
||||
|
||||
/// Pixels to a dot for a picture that high: a 720-line screenshot of it
|
||||
@@ -74,11 +84,11 @@ fn scale(height: u32) -> u32 {
|
||||
}
|
||||
|
||||
/// Whether a dot of the picture of `lines` is white.
|
||||
fn lit(lines: &[String], x: u32, y: u32) -> bool {
|
||||
fn lit(lines: &[String], shape: Shape, 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 {
|
||||
if x % CELL.0 >= GLYPH.0 || y % CELL.1 >= GLYPH.1 || x / CELL.0 >= shape.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 {
|
||||
@@ -88,14 +98,14 @@ fn lit(lines: &[String], x: u32, y: u32) -> bool {
|
||||
}
|
||||
|
||||
/// 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);
|
||||
fn painted(lines: &[String], shape: Shape, scale: u32, colours: [&[u8]; 2], pitch: usize) -> Vec<u8> {
|
||||
let (width, height) = size(shape, 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))];
|
||||
let colour = colours[usize::from(lit(lines, shape, x, y))];
|
||||
for i in 0..scale {
|
||||
let at = top + (x * scale + i) as usize * bytes;
|
||||
out[at..at + bytes].copy_from_slice(colour);
|
||||
@@ -199,6 +209,7 @@ fn text(c: &[f64; COUNTERS], ms: f64, worst: f64, cost: f64, host: &Host) -> Vec
|
||||
|
||||
/// The buffers of a box that size and format.
|
||||
struct Buffers {
|
||||
shape: Shape,
|
||||
format: DXGI_FORMAT,
|
||||
scale: u32,
|
||||
pitch: u32,
|
||||
@@ -214,8 +225,8 @@ struct Buffers {
|
||||
unsafe impl Send for Buffers {}
|
||||
|
||||
impl Buffers {
|
||||
fn new(host: &Host, format: DXGI_FORMAT, scale: u32) -> Option<Buffers> {
|
||||
let (width, height) = size(scale);
|
||||
fn new(host: &Host, shape: Shape, format: DXGI_FORMAT, scale: u32) -> Option<Buffers> {
|
||||
let (width, height) = size(shape, 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<_>>>()?;
|
||||
@@ -240,17 +251,56 @@ impl Buffers {
|
||||
.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 })
|
||||
Some(Buffers { shape, format, scale, pitch, uploads, card: card?, turn: 0, fresh: 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);
|
||||
let picture = painted(lines, self.shape, 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 a second or more ago.
|
||||
unsafe { std::ptr::copy_nonoverlapping(picture.as_ptr(), self.uploads[self.turn].1, picture.len()) };
|
||||
self.fresh = true;
|
||||
}
|
||||
|
||||
/// Records the copy of the box onto `back` (of `width` x `height`, in the
|
||||
/// state to be copied into), its upper left corner at `at`.
|
||||
fn copy(&mut self, list: &ID3D12GraphicsCommandList, back: &ID3D12Resource, at: (u32, u32), (width, height): (u32, u32)) {
|
||||
let (w, h) = size(self.shape, self.scale);
|
||||
if at.0 >= width || at.1 >= height {
|
||||
return;
|
||||
}
|
||||
// SAFETY: an open list and live resources; the box lies within both.
|
||||
unsafe {
|
||||
if std::mem::take(&mut self.fresh) {
|
||||
list.CopyResource(&self.card, &self.uploads[self.turn].0);
|
||||
list.ResourceBarrier(&[transition(&self.card, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE)]);
|
||||
}
|
||||
let from = D3D12_TEXTURE_COPY_LOCATION {
|
||||
pResource: std::mem::transmute_copy(&self.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: self.format,
|
||||
Width: w,
|
||||
Height: h,
|
||||
Depth: 1,
|
||||
RowPitch: self.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.min(width - at.0), bottom: h.min(height - at.1), back: 1 };
|
||||
list.CopyTextureRegion(&to, at.0, at.1, 0, &from, Some(&part));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The panel of a presenter.
|
||||
@@ -341,7 +391,7 @@ impl Panel {
|
||||
if self.buffers.as_ref().is_none_or(|b| (b.format, b.scale) != (format, scale)) {
|
||||
// (What the card may still read stays: a picture's size changes once or twice in a run.)
|
||||
std::mem::forget(self.buffers.take());
|
||||
self.buffers = Buffers::new(host, format, scale);
|
||||
self.buffers = Buffers::new(host, PANEL, format, scale);
|
||||
self.failed = self.buffers.is_none();
|
||||
self.changed = true;
|
||||
}
|
||||
@@ -349,53 +399,71 @@ impl Panel {
|
||||
if std::mem::take(&mut self.changed) {
|
||||
buffers.write(&self.lines);
|
||||
}
|
||||
let (w, h) = size(scale);
|
||||
let list = &list.list;
|
||||
// SAFETY: an open list and live resources; the box lies within both.
|
||||
unsafe {
|
||||
if std::mem::take(&mut buffers.fresh) {
|
||||
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: w,
|
||||
Height: h,
|
||||
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.min(width),
|
||||
bottom: h.min(height),
|
||||
back: 1,
|
||||
};
|
||||
list.CopyTextureRegion(&to, 0, 0, 0, &from, Some(&part));
|
||||
}
|
||||
buffers.copy(&list.list, back, (0, 0), (width, height));
|
||||
self.cost += began.elapsed();
|
||||
}
|
||||
}
|
||||
|
||||
/// How long the start's notice stays.
|
||||
const NOTICE_FOR: Duration = Duration::from_secs(30);
|
||||
/// The longest notice line, in characters.
|
||||
const NOTICE_COLUMNS: u32 = 52;
|
||||
|
||||
/// What this card does for frame generation, said at the top of the picture
|
||||
/// for the first [`NOTICE_FOR`] of a run (`crate::streamline::notice`); in
|
||||
/// every build, nothing without a notice.
|
||||
pub(super) struct Notice {
|
||||
lines: Vec<String>,
|
||||
shape: Shape,
|
||||
since: Option<Instant>,
|
||||
buffers: Option<Buffers>,
|
||||
written: bool,
|
||||
done: bool,
|
||||
}
|
||||
|
||||
impl Notice {
|
||||
pub(super) fn new() -> Notice {
|
||||
let lines: Vec<String> = crate::streamline::notice().into_iter().map(|l| l.to_ascii_uppercase()).collect();
|
||||
let columns = lines.iter().map(|l| l.len() as u32).max().unwrap_or(0).min(NOTICE_COLUMNS);
|
||||
let shape = Shape { columns, lines: lines.len() as u32 };
|
||||
Notice { done: lines.is_empty(), lines, shape, since: None, buffers: None, written: false }
|
||||
}
|
||||
|
||||
/// Records the copy of the notice onto `back` (as [`Panel::draw`]), at
|
||||
/// the top in the middle, while it is due.
|
||||
pub(super) fn draw(&mut self, host: &Host, list: &HostList, back: &ID3D12Resource, (width, height): (u32, u32), format: DXGI_FORMAT) {
|
||||
if self.done {
|
||||
return;
|
||||
}
|
||||
let since = *self.since.get_or_insert_with(Instant::now);
|
||||
if since.elapsed() > NOTICE_FOR {
|
||||
// (Its buffers stay: the card may still read them.)
|
||||
std::mem::forget(self.buffers.take());
|
||||
self.done = true;
|
||||
return;
|
||||
}
|
||||
#[cfg(feature = "diagnostics")]
|
||||
let _ours = crate::replay::record::unrecorded();
|
||||
let scale = scale(height);
|
||||
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, self.shape, format, scale);
|
||||
self.written = false;
|
||||
if self.buffers.is_none() {
|
||||
self.done = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
let Some(buffers) = &mut self.buffers else { return };
|
||||
if !std::mem::replace(&mut self.written, true) {
|
||||
buffers.write(&self.lines);
|
||||
}
|
||||
let (w, _) = size(self.shape, scale);
|
||||
let at = (width.saturating_sub(w) / 2, 24 * scale);
|
||||
buffers.copy(&list.list, back, at, (width, height));
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -426,10 +494,10 @@ mod tests {
|
||||
fn a_box_is_painted() {
|
||||
let lines = vec!["I".to_owned(), " i".to_owned()];
|
||||
for scale in [1, 2, 4] {
|
||||
let (width, height) = size(scale);
|
||||
let (width, height) = size(PANEL, scale);
|
||||
let pitch = (width * 4).next_multiple_of(256) as usize;
|
||||
let colours = colours(DXGI_FORMAT_R10G10B10A2_UNORM).unwrap();
|
||||
let picture = painted(&lines, scale, colours, pitch);
|
||||
let picture = painted(&lines, PANEL, scale, colours, pitch);
|
||||
assert_eq!(picture.len(), pitch * height as usize);
|
||||
let at = |x: u32, y: u32| &picture[y as usize * pitch + x as usize * 4..][..4];
|
||||
// The rim is black, the first letter's top row lit in its middle.
|
||||
|
||||
Reference in new issue
Block a user