VICTORY_SPANS_QUICK=1, VICTORY_SYNC_FINE=1: the heaps' records' round spared the spans' lock, in finer jobs

Ported from Belobug/VIctory-Belobug-AMD a284ca7 (its per-job timing and
timeline phases are left out; both switches are on by default there and
off here).

VICTORY_SPANS_QUICK=1: a slot written with no placed texture view leaves
the heap's spans of placed views (and their lock) alone when the slot is
not in them (HostHeap::spanned, a bit per slot that may be there). Every
record the round of the heaps' records mirrors went by that one lock,
from its six threads, with the title's threads and the texture passes:
there, 4 of the 16 ms a frame the submitting thread waited for the round
were its threads waiting on that lock (run city4). What is done is the
same: forgetting a slot that is not there does nothing.

VICTORY_SYNC_FINE=1: the round gives its threads 2 pages and 64 records a
job instead of 8 and 256: a round for a submission finds a dozen pages,
which were two jobs on two of six threads while the submission waited.

Neither changes what is mirrored. Off by default. The frame line "writes
of view slots per frame (VICTORY_SPANS_QUICK=1)" counts writes that left
the spans alone and those under their lock, and the job size; the heaps'
records line's "ms waited for" shows the gain.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
readmet3xt-labandClaude Opus 5.5 committed 2026-11-27 01:11:03 +05:30
1 parent 769fe52887
commit 96dfd9bb89
2 files changed
+121 -7

No files matched your search

+46 -6
View File
@@ -330,6 +330,7 @@ pub(crate) fn sync_heaps() {
let mut short = 0u64;
let mut wait: Vec<u32> = Vec::new();
let frame = crate::frame::current();
let (pages_a_job, records_a_job) = sync_jobs();
let heaps = SHADER_HEAPS.read().unwrap_or_else(|e| e.into_inner());
for &(start, end, at) in heaps.iter() {
// SAFETY: registered heaps are live (removed when dropped).
@@ -347,8 +348,8 @@ pub(crate) fn sync_heaps() {
// since: a shader may pick them by index.
let before = host.copied_before(frame);
let of_tables = std::sync::atomic::AtomicU64::new(0);
crate::land::each_view(true, before.len().div_ceil(SYNC_AT_A_TIME), &|n| {
for &index in before.chunks(SYNC_AT_A_TIME).nth(n).unwrap_or_default() {
crate::land::each_view(true, before.len().div_ceil(records_a_job), &|n| {
for &index in before.chunks(records_a_job).nth(n).unwrap_or_default() {
if host.copied_tabled(index, frame) {
of_tables.fetch_add(1, Relaxed);
} else {
@@ -380,13 +381,13 @@ pub(crate) fn sync_heaps() {
let copied = host.copied_begin(step as usize);
let samplers = heap.samplers();
let in_place = sync_in_place() && step == 32 && crate::safecopy::on();
let found: Vec<std::sync::Mutex<SyncPart>> = parts.chunks(SYNC_PAGES).map(|_| Default::default()).collect();
let found: Vec<std::sync::Mutex<SyncPart>> = parts.chunks(pages_a_job).map(|_| Default::default()).collect();
crate::land::each_view(true, found.len(), &|n| {
let mut out = SyncPart::default();
let mut page_bytes: Vec<u8> = Vec::new();
let mut changed: Vec<u32> = Vec::new();
let mut bits: Vec<u64> = Vec::new();
for &(from, to) in parts.chunks(SYNC_PAGES).nth(n).unwrap_or_default() {
for &(from, to) in parts.chunks(pages_a_job).nth(n).unwrap_or_default() {
let slots = changed_slots(from, to, start as usize, step, mirrored_count);
// A record that straddles the range's ends is left
// to the range that holds its first byte.
@@ -500,8 +501,8 @@ pub(crate) fn sync_heaps() {
}
spent[1] += since(began);
let began = std::time::Instant::now();
crate::land::each_view(true, make.len().div_ceil(SYNC_AT_A_TIME), &|n| {
for &index in make.chunks(SYNC_AT_A_TIME).nth(n).unwrap_or_default() {
crate::land::each_view(true, make.len().div_ceil(records_a_job), &|n| {
for &index in make.chunks(records_a_job).nth(n).unwrap_or_default() {
host.mirror(index, start + u64::from(index) * step, false);
}
});
@@ -582,6 +583,35 @@ const SYNC_PAGES: usize = 8;
#[cfg(windows)]
const SYNC_AT_A_TIME: usize = 256;
/// With `VICTORY_SYNC_FINE=1`: pages and records [`sync_heaps`] gives a thread
/// at a time.
#[cfg(windows)]
const SYNC_PAGES_FINE: usize = 2;
#[cfg(windows)]
const SYNC_AT_A_TIME_FINE: usize = 64;
/// Pages and records [`sync_heaps`] gives a thread at a time
/// (`VICTORY_SYNC_FINE=1`: [`SYNC_PAGES_FINE`] and [`SYNC_AT_A_TIME_FINE`];
/// off by default: [`SYNC_PAGES`] and [`SYNC_AT_A_TIME`], as before).
///
/// Ported from Belobug/VIctory-Belobug-AMD a284ca7: a round for a submission
/// finds a dozen pages or so; by eight a job that was two jobs, on two of the
/// six threads, while the submission waited for the round (2 to 3.4 ms at a
/// time, their run city4).
#[cfg(windows)]
fn sync_jobs() -> (usize, usize) {
#[cfg(feature = "diagnostics")]
if let Some(fine) = crate::ab::pick("VICTORY_SYNC_FINE") {
return if fine { (SYNC_PAGES_FINE, SYNC_AT_A_TIME_FINE) } else { (SYNC_PAGES, SYNC_AT_A_TIME) };
}
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
if *ON.get_or_init(|| std::env::var_os("VICTORY_SYNC_FINE").is_some_and(|v| v != "0")) {
(SYNC_PAGES_FINE, SYNC_AT_A_TIME_FINE)
} else {
(SYNC_PAGES, SYNC_AT_A_TIME)
}
}
/// Since the last frame line, of [`sync_heaps`]: changed pages of placed
/// shader-visible heaps looked at, slots on them, slots whose record was
/// not the one last seen and was mirrored, the microseconds it took; then
@@ -614,6 +644,16 @@ pub(crate) fn sync_line(frames: f64) {
let split = [0, 1, 2, 3, 4].map(|i| SYNC_SPLIT[i].swap(0, std::sync::atomic::Ordering::Relaxed) as f64);
let kinds = [0, 1, 2, 3, 4].map(|i| SYNCED_KINDS[i].swap(0, std::sync::atomic::Ordering::Relaxed) as f64 / frames);
let short = SYNC_SHORT.swap(0, std::sync::atomic::Ordering::Relaxed);
let quick = [0, 1].map(|i| host::SPANS_QUICK[i].swap(0, std::sync::atomic::Ordering::Relaxed) as f64 / frames);
if quick[0] > 0.0 || sync_jobs().0 == SYNC_PAGES_FINE {
tracing::info!(
"writes of view slots per frame (VICTORY_SPANS_QUICK=1): {:.0} leaving the placed views' spans alone, {:.0} under \
their lock; the heaps' records in jobs of {} pages (VICTORY_SYNC_FINE)",
quick[0],
quick[1],
sync_jobs().0
);
}
if pages == 0 {
return;
}