Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
03175e5
Document PL Plus development scope and release gates
Matartos Nov 28, 2026
393b013
Add read-only upstream metadata and merge-conflict audit
Matartos Nov 28, 2026
c67be65
fix(policy): move lowering tests out of lower.rs to stay under the 64…
claude Nov 28, 2026
b9363cb
Merge remote-tracking branch 'origin/claude/practical-euler-95ngzp' i…
claude Nov 28, 2026
f03a1a8
Merge remote-tracking branch 'origin/ampere-sm86-perf-exp1' into clau…
claude Nov 28, 2026
96f0acb
chore: keep pl-plus-dev files off the Kemerd port branch
claude Nov 28, 2026
970bcbc
perf(texture): VICTORY_STAGING_NO_ZERO, staging pieces not zeroed twi…
claude Nov 28, 2026
19b484b
docs: Kemerd rt-test-11 audit (sampler table already present, staging…
claude Nov 28, 2026
a376dd7
perf(pipeline): VICTORY_PIPELINE_WAIT_BACKLOG, no draw wait past n qu…
claude Nov 28, 2026
fbdb2ae
docs: Kemerd audit, pipeline wait switches
claude Nov 28, 2026
6d39c94
Files: the title's synchronous read-only opens of its package past th…
Kemerd Nov 28, 2026
22ccd83
docs: Kemerd audit, files read through the system cache
claude Nov 28, 2026
595b8cc
Card copies: a title buffer copy finds the copies it touches by where…
Kemerd Nov 27, 2026
8fff3e8
Textures: a guarded texture nothing wrote is read whole at most once …
Kemerd Nov 27, 2026
a5f964a
Streaming: the reviewers' findings (the parts for the switches ported…
Kemerd Nov 28, 2026
578e47a
docs: Kemerd audit, copy finder, look once, review fixes, authorship …
claude Nov 28, 2026
1d0e418
docs: Kemerd audit, original commits and their authors
claude Nov 28, 2026
b19e19b
Textures: a buffer staged for one upload of the pass is read by threa…
Kemerd Nov 27, 2026
4162a3d
Streaming: the reviewers' findings for the read-ahead
Kemerd Nov 28, 2026
c0a72b4
docs: Kemerd audit, texture read-ahead
claude Nov 28, 2026
84be0ad
docs: Kemerd audit, read-ahead source correction
claude Nov 28, 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
15 changes: 14 additions & 1 deletion crates/victory-gpu/src/draw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3995,7 +3995,20 @@ impl State {
let memory = if again.is_none() && heap_recheck() { crate::texture::staged_memory(resource) } else { None };
memory.map(|(at, len)| (at, len, crate::texture::fingerprint(at, len)))
});
rest(6, || crate::texture::unstage(resource));
let staged = rest(6, || crate::texture::unstage(resource));
// Read by threads of ours from here, after the fingerprint for
// the later look ([`crate::texture::ahead::read_ahead`]): not a
// bake's, not one taken ahead, not one looked at again by
// mapped bytes alone.
if let Some(staging) = staged
&& crate::texture::ahead::read_ahead()
&& ahead.is_none()
&& sync.is_none()
&& !baking
&& memory.is_some()
{
crate::texture::ahead::read_soon(staging);
}
SPENT.fetch_add(bytes, Ordering::Relaxed);
since_asked += bytes;
if first_upload || (room && since_asked >= 32 << 20) {
Expand Down
11 changes: 9 additions & 2 deletions crates/victory-gpu/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10357,6 +10357,8 @@ impl Meter {
modes.join(", ")
);
}
crate::texture::look_once_line(frames);
crate::texture::ahead::read_ahead_line(frames);
let [through, left, filled, short] =
[0, 1, 2, 3].map(|i| crate::texture::UNLOCKED[i].swap(0, Ordering::Relaxed) as f64 / frames);
if through + left + filled > 0.0 {
Expand Down Expand Up @@ -10474,6 +10476,7 @@ impl Meter {
crate::draw::HEAP_TEXTURE_BYTES.load(Ordering::Relaxed) >> 20
);
}
crate::texture::staging_zeros_line();
let served = crate::descriptor::host::SERVED.each_ref().map(|n| n.swap(0, Ordering::Relaxed));
if served[0] + served[3] > 0 {
tracing::info!(
Expand Down Expand Up @@ -10644,7 +10647,8 @@ impl Meter {
tracing::info!(
"host copies in the card's memory: {} copies {} MB, their bytes from before {} MB; per frame: \
{:.1} MB sent up in {:.0} ranges, {:.0} pieces compared on the card, {:.0} of them fetched \
({:.1} MB) with {:.1} more waits for the card ({:.1} ms)",
({:.1} MB) with {:.1} more waits for the card ({:.1} ms); title buffer copies done on the CPU \
looked for among them {:.1} times ({:.2} ms), {:.1} copies found (VICTORY_SEND_COPIED_FIND)",
card[7],
card[8] >> 20,
card[9] >> 20,
Expand All @@ -10654,7 +10658,10 @@ impl Meter {
per_frame(3),
per_frame(4) / 1e6,
per_frame(5),
per_frame(6) / 1e3
per_frame(6) / 1e3,
per_frame(10),
per_frame(11) / 1e6,
per_frame(12)
);
}
let [raw_srv, raw_uav] = crate::descriptor::host::raw_view_counts();
Expand Down
45 changes: 45 additions & 0 deletions crates/victory-gpu/src/pipeline/make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,46 @@ fn shared_budget() -> bool {
*ON.get_or_init(|| std::env::var_os("VICTORY_PIPELINE_WAIT_SHARED").is_none_or(|v| v != "0"))
}

/// `VICTORY_PIPELINE_WAIT_BACKLOG=n` (read once, unset by default): past
/// `n` pipelines queued, a draw's pipeline is not waited for at all and the
/// draw is dropped at once, as it is when the budget runs out; it is drawn
/// again in a later frame. Unset, every draw waits as before.
///
/// With more queued than the workers can make within the budget, the
/// pipeline asked for here will not arrive in time, and waiting only costs
/// the frame (Kemerd/VIctory-NVIDIA-RT rt-test-11, 0549d44c, GPL-3.0: a run
/// spent the whole 500 ms in every frame for two minutes while 470 were
/// queued; another sat at 3 fps with 600 queued). Only graphics: passes over
/// the screen keep their own budget, and a dispatch is never dropped here
/// (it waits unless `VICTORY_PIPELINE_COMPUTE_WAIT=0`, and not by this rule
/// even then). docs/KEMERD-AUDIT.md.
fn backlog() -> Option<u64> {
static MOST: OnceLock<Option<u64>> = OnceLock::new();
*MOST.get_or_init(|| {
let most = std::env::var("VICTORY_PIPELINE_WAIT_BACKLOG").ok().and_then(|v| v.trim().parse::<u64>().ok());
if let Some(most) = most {
tracing::info!(most, "host pipelines are not waited for while more than this many are queued");
}
most
})
}

/// Whether a draw's wait is left out for the backlog ([`backlog`]): more
/// than `most` queued.
fn over_backlog(most: Option<u64>, queued: u64) -> bool {
most.is_some_and(|most| queued > most)
}

/// Waits for `p` while frame `frame` has budget left.
fn wait(p: &Pending, frame: u64) {
let screen = p.screen && screens_first();
let budget = if screen { screen_budget() } else { wait_budget() };
if budget.is_zero() {
return;
}
if !screen && p.graphics.is_some() && over_backlog(backlog(), WAITING.load(Ordering::Relaxed)) {
return;
}
// The frame the budget belongs to, and what was waited of it (or is
// taken by a thread waiting now); of the passes over the screen too.
static SPENT: [Mutex<(u64, Duration)>; 2] = [const { Mutex::new((u64::MAX, Duration::ZERO)) }; 2];
Expand Down Expand Up @@ -829,6 +862,18 @@ fn drained() {

#[cfg(test)]
mod tests {
/// [`super::over_backlog`]: unset never skips; set, only more queued than
/// asked skips.
#[test]
fn a_wait_is_left_out_only_past_the_backlog() {
use super::over_backlog;
assert!(!over_backlog(None, u64::MAX));
assert!(!over_backlog(Some(64), 0));
assert!(!over_backlog(Some(64), 64));
assert!(over_backlog(Some(64), 65));
assert!(over_backlog(Some(0), 1));
}

use super::*;

#[test]
Expand Down
59 changes: 46 additions & 13 deletions crates/victory-gpu/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,9 +653,33 @@ impl Drop for StagingPiece {
}
}

/// `bytes` of upload memory, all zeros: the buffer it lies in, where in
/// that buffer, and its mapping. `None`: not pooled.
pub(crate) fn staging(host: &crate::host::Host, bytes: u64) -> Option<(StagingPiece, ID3D12Resource, u64, *mut u8)> {
/// Whether a staging piece the detiling is known to write whole may be
/// handed out as it is, its zeros left to the detiling or to a fill where
/// a copy from it is recorded (`VICTORY_STAGING_NO_ZERO=1`, off by
/// default; see `crate::texture::Staging::zero_if_unwritten`). Without it
/// every piece cut from a part of a block used before is zero-filled when
/// it is handed out, and the detiling then writes the same bytes again:
/// upload memory written twice per texture byte, on the thread that makes
/// the staging buffer. It saves thread time of the texture pass and bytes
/// written, not frame time: judge it by microseconds per upload.
///
/// Ported from Kemerd/VIctory-NVIDIA-RT `rt-test-11`
/// (0549d44c330bf0a1f808f8b012d8e22168dfad91), GPL-3.0; docs/KEMERD-AUDIT.md.
pub(crate) fn no_zero() -> bool {
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
*ON.get_or_init(|| std::env::var_os("VICTORY_STAGING_NO_ZERO").is_some_and(|v| v == "1"))
}

/// `bytes` of upload memory: the buffer it lies in, where in that buffer,
/// its mapping, and whether the piece was used before. All zeros, unless
/// `leave` and it was used before ([`no_zero`]): then it holds what it held,
/// and the caller sees to every byte a copy reads from it. `None`: not
/// pooled.
pub(crate) fn staging(
host: &crate::host::Host,
bytes: u64,
leave: bool,
) -> Option<(StagingPiece, ID3D12Resource, u64, *mut u8, bool)> {
if !on() {
return None;
}
Expand All @@ -676,13 +700,13 @@ pub(crate) fn staging(host: &crate::host::Host, bytes: u64) -> Option<(StagingPi
let owned = StagingPiece(piece);
// SAFETY: the piece lies in the block's mapping.
let data = unsafe { memory.1.add(piece.start as usize) };
if again {
if again && !leave {
// What is not detiled into it (an unmapped texture) uploads zeros,
// as from a buffer of its own.
// SAFETY: the piece is ours alone.
unsafe { std::ptr::write_bytes(data, 0, bytes as usize) };
}
Some((owned, memory.0, piece.start, data))
Some((owned, memory.0, piece.start, data, again))
}

/// An object the host texture holds and releases when it goes: its piece
Expand Down Expand Up @@ -1615,12 +1639,12 @@ mod tests {
let stop = std::sync::atomic::AtomicBool::new(false);
let mut ms = Vec::new();
let mut keep = Vec::new();
keep.extend(staging(host, 64 << 10));
keep.extend(staging(host, 64 << 10, false));
std::thread::scope(|s| {
s.spawn(|| {
let mut held = std::collections::VecDeque::new();
while !stop.load(Ordering::Relaxed) {
held.extend(staging(host, 8 << 20));
held.extend(staging(host, 8 << 20, false));
if held.len() > 64 {
held.pop_front();
}
Expand All @@ -1629,7 +1653,7 @@ mod tests {
std::thread::sleep(std::time::Duration::from_millis(100));
for _ in 0..1000 {
let began = std::time::Instant::now();
keep.extend(staging(host, 64 << 10));
keep.extend(staging(host, 64 << 10, false));
ms.push(began.elapsed().as_secs_f64() * 1e3);
}
stop.store(true, Ordering::Relaxed);
Expand Down Expand Up @@ -1710,16 +1734,16 @@ mod tests {
for t in 0..8u8 {
s.spawn(move || {
// 8 of 8 MiB a thread: 64 MiB each, so new blocks are made.
let pieces: Vec<_> = (0..8).filter_map(|_| staging(host, BYTES as u64)).collect();
let pieces: Vec<_> = (0..8).filter_map(|_| staging(host, BYTES as u64, false)).collect();
assert_eq!(pieces.len(), 8);
for (_, _, _, data) in &pieces {
for (_, _, _, data, _) in &pieces {
// SAFETY: the piece's mapping, ours alone.
unsafe {
assert!(looked(*data).all(|b| b == 0), "a piece is not zeros");
std::ptr::write_bytes(*data, t + 1, BYTES);
}
}
for (_, _, _, data) in &pieces {
for (_, _, _, data, _) in &pieces {
assert!(looked(*data).all(|b| b == t + 1), "another thread wrote this piece");
}
});
Expand Down Expand Up @@ -1754,13 +1778,22 @@ mod tests {
assert_eq!(resting(), before + 1);
// SAFETY: the piece's mapping, 4096 bytes of it ours.
unsafe {
let (piece, _, at, data) = staging(host, 4096).unwrap();
let (piece, _, at, data, _) = staging(host, 4096, false).unwrap();
assert!(at.is_multiple_of(512));
std::ptr::write_bytes(data, 0xAB, 4096);
drop(piece);
lock(&STAGING).rested(u64::MAX);
let (_piece, _, _, data) = staging(host, 4096).unwrap();
let (piece, _, _, data, again) = staging(host, 4096, false).unwrap();
assert!(again);
assert!((0..4096).all(|i| *data.add(i) == 0));
// Left as it was (`VICTORY_STAGING_NO_ZERO`): what it held, and
// said to have been used before.
std::ptr::write_bytes(data, 0xCD, 4096);
drop(piece);
lock(&STAGING).rested(u64::MAX);
let (_piece, _, _, data, again) = staging(host, 4096, true).unwrap();
assert!(again);
assert!((0..4096).all(|i| *data.add(i) == 0xCD));
// SAFETY: plain query.
assert!(host.device.GetDeviceRemovedReason().is_ok());
}
Expand Down
Loading
Loading