Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,49 @@ Tested on one machine: Windows 11, Intel i7-14700KF, NVIDIA RTX 4070 12 GB,

### Newest (2026-11-25, later the same day)

**Update, 2026-11-25 afternoon: what a frame is made of, measured, and two
changes that hold.** First rooms, about 3,850 draws a frame: 104 ms a frame
(9.6 frames a second) with the set below, from about 120 ms in the
morning. Still far from the console's 33 ms.
- How the title paces itself (new meters in `fence.rs` and
`console_insn.rs`): it never asks for an event. Each frame begins with
one small submission and a signal, and a title thread then waits for
that fence value by reading it in memory with `monitorx` / `mwaitx`
(AMD-only: about 280,000 emulated exceptions a second on an Intel
processor, all from this wait). The value is set when the layer has
finished the whole frame before. So a frame is the time the layer needs
for one frame's burst of submissions plus about 20 ms of the title's
own; putting presents behind the line, or giving the title's threads
more processors, changes nothing (both measured).
- Two walls stand side by side and both are full: the layer's submit
thread (about 95 ms of a 120 ms frame in the morning) and the card
(about 102 ms busy, by a timestamp pair around every host list:
`cardmeter.rs`). Taking time off one alone moved the frame by 0 to 7 %.
- `VICTORY_JOIN_PARTS=1` (off by default): the title's lists wait for
memory values, which cut its ~15 submissions a frame into ~29 parts;
parts that follow one another now go to the host as one submission
(9 a frame), the same lists in the same order. About 6 %.
- `VICTORY_BACK_OWN_VIEW=1` (off by default): what shaders wrote goes
back into title view memory through a view of the layer's own, so the
copy that wrote it is not read in again. About 9 % (submit thread 93 ->
81 ms a frame, 104 -> 80 MB a frame checked). A CORRECTION: an earlier
run seemed to show washed-out frames with this switch; the same frames
turn up in about 6 of 21 runs with no switch at all (cause not known),
and `VICTORY_BACK_OWN_CHECK=1` counted 0 stores gone astray in 1.36
million.
- Where the card's time goes now (`VICTORY_CARD_METER_PIPELINES=1`, a
table by pipeline): no pass is large. About 82 ms of the title's lists
are spread over ~3,400 pipeline bindings a frame; ~2,400 of the
indirect commands still get a clamp pass of the layer's with draw
windows on (960 are compute dispatches; about 1,000 are mesh records
the title keeps scattered through a 100 MB argument buffer, which a
window of records at one step cannot serve).
- Measured and found to give nothing (switches left in, off):
`VICTORY_REFRESH_ONCE`, `VICTORY_ASYNC_PRESENT`, `VICTORY_VIEW_KNOWN`,
`VICTORY_SPREAD`, `VICTORY_QUEUE2=3`, `VICTORY_WINDOW_JUMP`. Each has an
`=alt` form (twenty seconds on, twenty off, each change said in the
log) so that one run measures both in the same scene.

**Update, the same night: the first room now renders right on the test
machine** (walls, textures, people, lamps), at 190 to 450 ms a frame (2 to 5
frames a second): the picture work has caught up, the frame rate has not.
Expand Down
10 changes: 8 additions & 2 deletions apps/victory/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,17 @@ fn main() -> Result<()> {
warm,
} => {
// `VICTORY_VIEW_LIMIT=<null slot>`: translate as on a host whose view heap is capped
if let Some(n) = std::env::var("VICTORY_VIEW_LIMIT").ok().and_then(|v| v.parse().ok()) {
if let Some(n) = std::env::var("VICTORY_VIEW_LIMIT")
.ok()
.and_then(|v| v.parse().ok())
{
victory_shader::emit::set_view_heap_limit(n);
}
// `VICTORY_HOST_WAVE=32`: translate as for a GPU whose waves are at most 32 lanes
if let Some(n) = std::env::var("VICTORY_HOST_WAVE").ok().and_then(|v| v.parse().ok()) {
if let Some(n) = std::env::var("VICTORY_HOST_WAVE")
.ok()
.and_then(|v| v.parse().ok())
{
victory_shader::emit::set_host_max_wave(n);
}
if let Some(file) = warm {
Expand Down
36 changes: 30 additions & 6 deletions apps/victory/src/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,17 @@ pub fn warm(paths: Vec<PathBuf>, file: &Path, jobs: Option<usize>) -> Result<()>
}
}
}
anyhow::ensure!(!wanted.is_empty(), "no 16-digit shader hash in {}", file.display());
anyhow::ensure!(
!wanted.is_empty(),
"no 16-digit shader hash in {}",
file.display()
);
}
// `VICTORY_WARM_SECONDS=<n>`: stop taking new shaders after n seconds
// (what is done stays in the cache; the next warm-up goes on from there).
let limit = std::env::var("VICTORY_WARM_SECONDS").ok().and_then(|v| v.trim().parse::<u64>().ok());
let limit = std::env::var("VICTORY_WARM_SECONDS")
.ok()
.and_then(|v| v.trim().parse::<u64>().ok());
let cfg = victory_core::Config::load()?;
victory_hle::modules::d3d12x::use_shader_cache(cfg.cache_subdir("shaders")?);
let paths = crate::default_paths(paths)?;
Expand All @@ -196,7 +202,10 @@ pub fn warm(paths: Vec<PathBuf>, file: &Path, jobs: Option<usize>) -> Result<()>
let done = Mutex::new(HashSet::new());
let counts = [const { AtomicUsize::new(0) }; 5];
for root in &paths {
for entry in walkdir::WalkDir::new(root).into_iter().filter_map(Result::ok) {
for entry in walkdir::WalkDir::new(root)
.into_iter()
.filter_map(Result::ok)
{
// Past the deadline the workers break out at once: walking and
// opening the rest of the assets would only scan for nothing.
if limit.is_some_and(|n| began.elapsed().as_secs() >= n) {
Expand Down Expand Up @@ -227,7 +236,10 @@ pub fn warm(paths: Vec<PathBuf>, file: &Path, jobs: Option<usize>) -> Result<()>
}
let n = counts[4].fetch_add(1, Ordering::Relaxed) + 1;
if n.is_multiple_of(1000) {
println!("warm-up {n} shaders so far, {:.0} s", began.elapsed().as_secs_f64());
println!(
"warm-up {n} shaders so far, {:.0} s",
began.elapsed().as_secs_f64()
);
}
let which = match victory_hle::modules::d3d12x::warm_shader(&bytes) {
Ok(true) => 0,
Expand All @@ -242,8 +254,16 @@ pub fn warm(paths: Vec<PathBuf>, file: &Path, jobs: Option<usize>) -> Result<()>
}
}
let [translated, there, failed] = [0, 1, 2].map(|i| counts[i].load(Ordering::Relaxed));
let asked = if all { "all".to_owned() } else { wanted.len().to_string() };
let stopped = if counts[3].load(Ordering::Relaxed) > 0 { " (stopped at the time limit)" } else { "" };
let asked = if all {
"all".to_owned()
} else {
wanted.len().to_string()
};
let stopped = if counts[3].load(Ordering::Relaxed) > 0 {
" (stopped at the time limit)"
} else {
""
};
println!(
"warm-up {asked} hashes asked, {} found: {translated} translated now, {there} in the cache already, {failed} do not translate; {:.1} s on {threads} threads{stopped}",
translated + there + failed,
Expand All @@ -252,6 +272,10 @@ pub fn warm(paths: Vec<PathBuf>, file: &Path, jobs: Option<usize>) -> Result<()>
Ok(())
}

/// `translate --warm <file>`: the containers whose hash the file names are
/// translated into the run's shader cache, on `jobs` threads; nothing is
/// made on the GPU. A run of the title then finds them there instead of
/// translating each at its first use.
pub fn run(
paths: Vec<PathBuf>,
validate: bool,
Expand Down
59 changes: 48 additions & 11 deletions crates/victory-formats/src/xma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ fn next_frame(data: &[u8], start: usize, end: usize) -> Option<usize> {
let mut end = end;
if end.is_multiple_of(PACKET_BITS) || (last && end / PACKET_BITS == index) {
// The next frame begins in the next packet of this stream.
let next = (end - 1) / PACKET_BITS + 1 + packet(data, (end - 1) / PACKET_BITS)?.skip as usize;
let next =
(end - 1) / PACKET_BITS + 1 + packet(data, (end - 1) / PACKET_BITS)?.skip as usize;
let header = packet(data, next)?;
end = next * PACKET_BITS + HEADER_BITS + header.first_frame_bit as usize;
}
Expand Down Expand Up @@ -248,10 +249,20 @@ fn codes() -> &'static Codes {
scale: pairs(&SCALE, -60),
scale_rl: pairs(&SCALE_RL, 0),
coef: [
Vlc::new(COEF0_SYMS.iter().zip(COEF0_LENS).map(|(&s, l)| (s as i32, l))),
Vlc::new(
COEF0_SYMS
.iter()
.zip(COEF0_LENS)
.map(|(&s, l)| (s as i32, l)),
),
pairs(&COEF1, 0),
],
vec4: Vlc::new(VEC4_SYMS.iter().zip(VEC4_LENS).map(|(&s, l)| (s as i32 - 1, l))),
vec4: Vlc::new(
VEC4_SYMS
.iter()
.zip(VEC4_LENS)
.map(|(&s, l)| (s as i32 - 1, l)),
),
vec2: pairs(&VEC2, -1),
vec1: pairs(&VEC1, 0),
}
Expand Down Expand Up @@ -757,7 +768,11 @@ impl Decoder {
ch.scale_factors = target;
if ch.reuse_sf {
let from = ch.saved_scale_factors[ch.scale_factor_idx];
for (sf, &offset) in ch.saved_scale_factors[target].iter_mut().zip(&sf_offsets).take(self.num_bands) {
for (sf, &offset) in ch.saved_scale_factors[target]
.iter_mut()
.zip(&sf_offsets)
.take(self.num_bands)
{
*sf = from[offset];
}
}
Expand Down Expand Up @@ -890,7 +905,11 @@ impl Decoder {
}
quant += 31;
}
quant_step += if negative { -(quant + step) } else { quant + step };
quant_step += if negative {
-(quant + step)
} else {
quant + step
};
}
if self.channels_for_cur_subframe == 1 {
self.ch[self.channel_indexes[0]].quant_step = quant_step;
Expand Down Expand Up @@ -933,13 +952,21 @@ impl Decoder {
let sf = ch.saved_scale_factors[ch.scale_factors];
for band in 0..self.num_bands {
let end = sfb[band + 1].min(subframe_len);
let exp = ch.quant_step - (ch.max_scale_factor - sf[band]) * ch.scale_factor_step;
let exp =
ch.quant_step - (ch.max_scale_factor - sf[band]) * ch.scale_factor_step;
let quant = 10f32.powf(exp as f32 / 20.0);
for (t, &c) in tmp[sfb[band]..end].iter_mut().zip(&ch.coeffs[sfb[band]..end]) {
for (t, &c) in tmp[sfb[band]..end]
.iter_mut()
.zip(&ch.coeffs[sfb[band]..end])
{
*t = c * quant;
}
}
imdct_half(&tmp[..subframe_len], &mut ch.out[at..at + subframe_len], scale);
imdct_half(
&tmp[..subframe_len],
&mut ch.out[at..at + subframe_len],
scale,
);
}
} else {
for i in 0..self.channels_for_cur_subframe {
Expand All @@ -956,7 +983,10 @@ impl Decoder {
start += (winlen - subframe_len) / 2;
winlen = subframe_len;
}
window_overlap(&mut ch.out[start..start + winlen], &windows()[log2(winlen) as usize - 7]);
window_overlap(
&mut ch.out[start..start + winlen],
&windows()[log2(winlen) as usize - 7],
);
ch.prev_block_len = subframe_len;
}

Expand Down Expand Up @@ -1057,7 +1087,9 @@ mod tests {
-(input
.iter()
.enumerate()
.map(|(k, &x)| x as f64 * (std::f64::consts::PI / n as f64 * t * (k as f64 + 0.5)).cos())
.map(|(k, &x)| {
x as f64 * (std::f64::consts::PI / n as f64 * t * (k as f64 + 0.5)).cos()
})
.sum::<f64>() as f32)
})
.collect()
Expand Down Expand Up @@ -1109,7 +1141,12 @@ mod tests {
}
}
for i in n..5 * n {
assert!((out[i] - signal[i]).abs() < 1e-3, "{i}: {} vs {}", out[i], signal[i]);
assert!(
(out[i] - signal[i]).abs() < 1e-3,
"{i}: {} vs {}",
out[i],
signal[i]
);
}
}

Expand Down
Loading
Loading