Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
8dd30ab
A write through one view of a page is seen at its other views; page w…
fxceless Nov 25, 2026
a26859f
The first room renders right: byte-copied descriptor records are mirr…
fxceless Nov 25, 2026
9376fd6
Frame rate, processor side: a cheap fingerprint in the descriptor syn…
fxceless Nov 25, 2026
f85101b
Frame rate, second night: a submit thread of the layer's own, a copy …
fxceless Nov 25, 2026
a253706
Frame rate, third session: a frame log and a card meter, the driver w…
fxceless Nov 25, 2026
0b0074e
Copies in place measured and fixed, our threads on the fast cores, an…
fxceless Nov 25, 2026
81e13c9
Integrate fxceless round 2: baseline infra + additive files
Personed Nov 25, 2026
e3d6213
Integrate fxceless round 2: merge overlap files
Personed Nov 25, 2026
e63f09e
indirect: dedupe the bare-cost test module, mesh budget test on recor…
Personed Nov 25, 2026
f0a8aba
gpu: wire the emulated mesh pipeline creation onto the new pipeline a…
Personed Nov 25, 2026
7b25fda
gpu: emulated mesh shaders dispatch on hardware without mesh support
Personed Nov 25, 2026
e2f0601
Merge origin/main into the round-2 integration
Personed Nov 25, 2026
57ccee7
shader: lower tests in their own include (asset policy: lower.rs over…
Personed Nov 25, 2026
8398a5f
gpu: strip trailing whitespace in draw.rs
Personed Nov 25, 2026
af9dc5e
gpu: drop unused CacheKey import in shader cache tests
Personed Nov 25, 2026
ff68f03
gpu: satisfy clippy spacing around mesh pipeline docs
Personed Nov 25, 2026
7b84311
gpu: delink private page_writes from public watch documentation
Personed Nov 25, 2026
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
278 changes: 278 additions & 0 deletions README.md

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions apps/victory/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ enum Command {
/// Worker threads (default: every logical core).
#[arg(long)]
jobs: Option<usize>,
/// Warm the run's shader cache: a file of shader hashes (the 16
/// hex digits a run's log names a shader by, anywhere in a line);
/// the containers with those hashes are translated into the
/// cache and nothing else is done. Set `VICTORY_HOST_WAVE` and
/// `VICTORY_VIEW_LIMIT` to what the run's log says of the host.
#[arg(long)]
warm: Option<PathBuf>,
},
/// Prepare, map and bind a title executable; with --execute, run it.
Run {
Expand Down Expand Up @@ -152,6 +159,7 @@ fn main() -> Result<()> {
pipelines,
list,
jobs,
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()) {
Expand All @@ -161,6 +169,9 @@ fn main() -> Result<()> {
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 {
return translate::warm(paths, &file, jobs);
}
translate::run(paths, validate, pipelines, list, jobs)
}
Command::Run {
Expand Down
81 changes: 81 additions & 0 deletions apps/victory/src/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,87 @@ fn mesh_mode(host: Option<&Host>) -> emit::MeshMode {
}
}

/// `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 warm(paths: Vec<PathBuf>, file: &Path, jobs: Option<usize>) -> Result<()> {
// `--warm all`: every container found, whatever its hash.
let all = file.as_os_str() == "all";
let mut wanted: HashSet<String> = HashSet::new();
if !all {
let text = std::fs::read_to_string(file)?;
for line in text.lines() {
for word in line.split(|c: char| !c.is_ascii_hexdigit()) {
if word.len() == 16 {
wanted.insert(word.to_ascii_lowercase());
}
}
}
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 cfg = victory_core::Config::load()?;
victory_hle::modules::d3d12x::use_shader_cache(cfg.cache_subdir("shaders")?);
let paths = crate::default_paths(paths)?;
let threads = jobs.unwrap_or(4).max(1);
let began = std::time::Instant::now();
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) {
if !entry.file_type().is_file() || entry.metadata().map_or(0, |m| m.len()) > MAX_FILE {
continue;
}
let Ok(data) = std::fs::read(entry.path()) else {
continue;
};
let jobs = sources(&data);
Comment on lines +198 to +206

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Warm-up scans past its deadline

Once VICTORY_WARM_SECONDS expires, warm stops translating but still opens and scans every remaining eligible asset.

Devin left this for you to triage: Scanning remaining assets past the warm deadline wastes startup time but is harmless; small follow-up, out of scope here.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

let next = AtomicUsize::new(0);
std::thread::scope(|s| {
for _ in 0..threads.min(jobs.len()) {
s.spawn(|| {
while let Some(job) = jobs.get(next.fetch_add(1, Ordering::Relaxed)) {
let Some(bytes) = job.bytes() else {
continue;
};
let hash = blake3::hash(&bytes).to_hex()[..16].to_owned();
if limit.is_some_and(|n| began.elapsed().as_secs() >= n) {
counts[3].fetch_add(1, Ordering::Relaxed);
break;
}
if (!all && !wanted.contains(&hash)) || !lock(&done).insert(hash) {
continue;
}
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());
}
let which = match victory_hle::modules::d3d12x::warm_shader(&bytes) {
Ok(true) => 0,
Ok(false) => 1,
Err(_) => 2,
};
counts[which].fetch_add(1, Ordering::Relaxed);
}
});
}
});
}
}
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 { "" };
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,
began.elapsed().as_secs_f64()
);
Ok(())
}

pub fn run(
paths: Vec<PathBuf>,
validate: bool,
Expand Down
163 changes: 118 additions & 45 deletions crates/victory-formats/src/texture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -620,17 +620,7 @@ impl Layout {
row_pitch: usize,
depth_pitch: usize,
) -> Result<(), Error> {
self.walk(
tiled.len(),
mip,
slice,
linear.len(),
row_pitch,
depth_pitch,
|t, l, len| {
linear[l..][..len].copy_from_slice(&tiled[t..][..len]);
},
)
self.walk::<true>(tiled, linear, mip, slice, row_pitch, depth_pitch)
}

/// The reverse of [`Layout::detile`]: linear rows into tiled memory.
Expand All @@ -643,30 +633,19 @@ impl Layout {
row_pitch: usize,
depth_pitch: usize,
) -> Result<(), Error> {
self.walk(
tiled.len(),
mip,
slice,
linear.len(),
row_pitch,
depth_pitch,
|t, l, len| {
tiled[t..][..len].copy_from_slice(&linear[l..][..len]);
},
)
self.walk::<false>(linear, tiled, mip, slice, row_pitch, depth_pitch)
}

/// Visits contiguous runs as (tiled byte offset, linear byte offset, length).
/// Copies contiguous runs in one direction between the two layouts.
#[allow(clippy::too_many_arguments)]
fn walk(
fn walk<const DETILE: bool>(
&self,
tiled_len: usize,
src: &[u8],
dst: &mut [u8],
mip: u32,
slice: u32,
linear_len: usize,
row_pitch: usize,
depth_pitch: usize,
mut copy: impl FnMut(usize, usize, usize),
) -> Result<(), Error> {
let m = self.mips.get(mip as usize).ok_or(Error::Invalid)?;
let depth = m.depth;
Expand All @@ -692,6 +671,11 @@ impl Layout {
.and_then(|(depth_offset, row_offset)| depth_offset.checked_add(row_offset))
.and_then(|offset| offset.checked_add(bytes))
.ok_or(Error::TooSmall)?;
let (tiled_len, linear_len) = if DETILE {
(src.len(), dst.len())
} else {
(dst.len(), src.len())
};
if tiled_len < self.size as usize || linear_len < need || row_pitch < bytes {
return Err(Error::TooSmall);
}
Expand All @@ -714,46 +698,83 @@ impl Layout {
runs.push((first_tiled, first_linear, bytes - first_linear));
}
// A mip can end partway through the last run. Check the other runs
// once so each row can copy them with a compile-time length.
// once so each row can copy them as fixed-size chunks.
let (body, last) = runs.split_at(runs.len().saturating_sub(1));
let run_len = body
.first()
.map(|run| run.2)
.filter(|&len| body.iter().all(|run| run.2 == len));
let chunk_size = body.first().map(|run| run.2).filter(|&size| {
body.iter()
.all(|&(offset, _, len)| len == size && offset.is_multiple_of(size))
});
for z in 0..depth {
let (s, inner) = self.split(first + z);
let base = u64::from(s) * self.slice_size + m.offset;
for y in 0..m.height {
let linear_row = z as usize * depth_pitch + y as usize * row_pitch;
if linear {
let tiled_row = base + u64::from(y) * u64::from(m.pitch) * n as u64;
copy(tiled_row as usize, linear_row, bytes);
copy_run::<DETILE>(src, dst, tiled_row as usize, linear_row, bytes);
} else {
let tiled_row = (base + self.row(m, y, inner)) as usize;
match run_len {
Some(8) => copy_runs::<8>(body, tiled_row, linear_row, &mut copy),
Some(16) => copy_runs::<16>(body, tiled_row, linear_row, &mut copy),
Some(32) => copy_runs::<32>(body, tiled_row, linear_row, &mut copy),
_ => copy_runs::<0>(body, tiled_row, linear_row, &mut copy),
match chunk_size {
Some(8) if tiled_row.is_multiple_of(8) => {
copy_runs::<8, DETILE>(src, dst, body, tiled_row, linear_row)
}
Some(16) if tiled_row.is_multiple_of(16) => {
copy_runs::<16, DETILE>(src, dst, body, tiled_row, linear_row)
}
Some(32) if tiled_row.is_multiple_of(32) => {
copy_runs::<32, DETILE>(src, dst, body, tiled_row, linear_row)
}
_ => copy_runs::<0, DETILE>(src, dst, body, tiled_row, linear_row),
}
copy_runs::<0>(last, tiled_row, linear_row, &mut copy);
copy_runs::<0, DETILE>(src, dst, last, tiled_row, linear_row);
}
}
}
Ok(())
}
}

/// Copy micro-tile runs inline at a known width, or use each run's length for N = 0.
fn copy_runs<const N: usize>(
fn copy_run<const DETILE: bool>(
src: &[u8],
dst: &mut [u8],
tiled: usize,
linear: usize,
len: usize,
) {
let (from, to) = if DETILE {
(tiled, linear)
} else {
(linear, tiled)
};
dst[to..][..len].copy_from_slice(&src[from..][..len]);
}

/// A row of equal runs is contiguous in linear memory. Treat it as a
/// slice of arrays so only the tiled chunk needs a bounds check per copy.
/// Use the byte ranges for irregular runs and the last run of each row.
fn copy_runs<const N: usize, const DETILE: bool>(
src: &[u8],
dst: &mut [u8],
runs: &[(usize, usize, usize)],
tiled_row: usize,
linear_row: usize,
copy: &mut impl FnMut(usize, usize, usize),
) {
for &(tiled, linear, len) in runs {
let len = if N == 0 { len } else { N };
copy(tiled_row + tiled, linear_row + linear, len);
if N == 0 {
for &(tiled, linear, len) in runs {
copy_run::<DETILE>(src, dst, tiled_row + tiled, linear_row + linear, len);
}
} else if DETILE {
let tiled = src.as_chunks::<N>().0;
let linear = dst[linear_row..][..runs.len() * N].as_chunks_mut::<N>().0;
for (out, &(offset, ..)) in linear.iter_mut().zip(runs) {
*out = tiled[(tiled_row + offset) / N];
}
} else {
let tiled = dst.as_chunks_mut::<N>().0;
let linear = src[linear_row..][..runs.len() * N].as_chunks::<N>().0;
for (input, &(offset, ..)) in linear.iter().zip(runs) {
tiled[(tiled_row + offset) / N] = *input;
}
}
}

Expand Down Expand Up @@ -1025,6 +1046,58 @@ mod tests {
}
}

#[test]
fn tiled_chunks_match_element_offsets_with_odd_row_pitches() {
for swizzle in [
Swizzle::SW_256B_S,
Swizzle::SW_256B_D,
Swizzle::SW_4KB_S,
Swizzle::SW_4KB_D,
Swizzle::SW_64KB_S,
Swizzle::SW_64KB_D,
] {
for n in [1, 2, 4, 8, 16] {
let l = Layout::new(&Desc {
depth: 2,
..desc(73, 39, 7, n, swizzle)
})
.unwrap();
let n = n as usize;
let tiled: Vec<_> = (0..l.size)
.map(|i| (i.wrapping_mul(0x9e37_79b9) >> 24) as u8)
.collect();
let mut retiled = vec![0xbb; tiled.len()];
let mut expected_tiled = retiled.clone();
for slice in 0..l.slices {
for (mip, m) in l.mips.iter().enumerate() {
let mip = mip as u32;
let bytes = m.width as usize * n;
let pitch = bytes + 3;
// Keep padding between rows, with exactly the active
// bytes in the last row.
let len = (m.height as usize - 1) * pitch + bytes;
let mut linear = vec![0xcc; len];
let mut expected = linear.clone();
for y in 0..m.height {
for x in 0..m.width {
let src = l.offset(mip, x, y, slice).unwrap() as usize;
let dst = y as usize * pitch + x as usize * n;
expected[dst..][..n].copy_from_slice(&tiled[src..][..n]);
expected_tiled[src..][..n].copy_from_slice(&tiled[src..][..n]);
}
}
l.detile(&tiled, mip, slice, &mut linear, pitch, len)
.unwrap();
assert_eq!(linear, expected, "{swizzle:?} {n} mip {mip} slice {slice}");
l.tile(&mut retiled, mip, slice, &expected, pitch, len)
.unwrap();
}
}
assert_eq!(retiled, expected_tiled, "{swizzle:?} {n}");
}
}
}

/// Hand-checked: in a 64 KiB `D` block of 4-byte elements, x bits go to
/// address bits 2, 3, 6, 9, 11, 13, 15 and y bits to 4, 5, 7, 8, 10, 12,
/// 14; a 4 KiB `S` block of 16-byte elements is 16x16 with y first.
Expand Down
2 changes: 1 addition & 1 deletion crates/victory-gpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ diagnostics = []
workspace = true

[target.'cfg(windows)'.dependencies]
windows-sys = { workspace = true, features = ["Win32_Foundation", "Win32_Security", "Win32_System_Diagnostics_Debug", "Win32_System_Kernel", "Win32_System_LibraryLoader", "Win32_System_Memory", "Win32_System_Performance", "Win32_System_ProcessStatus", "Win32_System_SystemInformation", "Win32_System_Threading"] }
windows-sys = { workspace = true, features = ["Win32_Foundation", "Win32_Security", "Win32_System_Diagnostics_Debug", "Win32_System_EventLog", "Win32_System_Kernel", "Win32_System_LibraryLoader", "Win32_System_Memory", "Win32_System_Performance", "Win32_System_ProcessStatus", "Win32_System_SystemInformation", "Win32_System_Threading"] }
windows = { workspace = true, features = [
"Win32_Graphics_Direct3D",
"Win32_Graphics_Direct3D_Fxc",
Expand Down
18 changes: 17 additions & 1 deletion crates/victory-gpu/src/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,22 @@ fn world_on() -> bool {
*ON.get_or_init(|| std::env::var_os("VICTORY_CAPTURE_WORLD").is_some())
}

/// Every how many world frames a picture is saved with
/// `VICTORY_CAPTURE_WORLD` (`VICTORY_CAPTURE_WORLD_EVERY`, 8 unless said).
///
/// A saved frame is read back at once and written as a PNG inside the
/// present: run 225's frame log has every saved frame of the cell at 371 ms
/// against a usual 136 (the present's own copy and show 137 ms instead of
/// 2, and 123 ms more waiting for the card). At every 8th frame that was
/// the regular dip of every test run, and a fifth of its time. A run that
/// measures speed asks for 64 or more.
fn world_every() -> u64 {
static EVERY: std::sync::OnceLock<u64> = std::sync::OnceLock::new();
*EVERY.get_or_init(|| {
std::env::var("VICTORY_CAPTURE_WORLD_EVERY").ok().and_then(|v| v.trim().parse().ok()).filter(|&n| n > 0).unwrap_or(8)
})
}

/// The first frame that ran 500 draws or more (`VICTORY_CAPTURE_WORLD`).
static WORLD: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(u64::MAX);

Expand Down Expand Up @@ -151,7 +167,7 @@ pub(crate) fn wanted(n: u64) -> bool {
// cutscene (its shots do not fall on the same frame numbers from run to
// run, so single frames cannot be compared between runs).
let first = WORLD.load(std::sync::atomic::Ordering::Relaxed);
let in_world = world_on() && first != u64::MAX && n > first && (n - first).is_multiple_of(8);
let in_world = world_on() && first != u64::MAX && n > first && (n - first).is_multiple_of(world_every());
folder().is_some() && (n.is_power_of_two() || listed(n) || before_world || in_world)
}

Expand Down
Loading
Loading