Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e4dbd89cd3 | ||
|
|
5d65b5d333 | ||
|
|
3f3e525d55 |
No files matched your search
@@ -17,7 +17,7 @@ A performance- and low-memory-tuned fork of [VIctory-NVIDIA](https://github.com/
|
|||||||
- **6 GB / 4 GB VRAM support (`VICTORY_TEXTURE_DROP_MIPS`):** Drops top texture mip levels (`1` = Half for 6 GB GPUs, `2` = Quarter for 4 GB GPUs) to keep VRAM comfortably under budget. Toggleable in the **F1** menu (`TEXTURE SCALE (VRAM)`).
|
- **6 GB / 4 GB VRAM support (`VICTORY_TEXTURE_DROP_MIPS`):** Drops top texture mip levels (`1` = Half for 6 GB GPUs, `2` = Quarter for 4 GB GPUs) to keep VRAM comfortably under budget. Toggleable in the **F1** menu (`TEXTURE SCALE (VRAM)`).
|
||||||
- **16 GB RAM stability & OOM recovery:** Caps idle upload/list pools automatically on `<= 32 GB` hosts, drains idle pools under critical commit pressure, and retries `E_OUTOFMEMORY` in command-list preludes instead of crashing.
|
- **16 GB RAM stability & OOM recovery:** Caps idle upload/list pools automatically on `<= 32 GB` hosts, drains idle pools under critical commit pressure, and retries `E_OUTOFMEMORY` in command-list preludes instead of crashing.
|
||||||
- **Custom windowed output sizes (`VICTORY_OUTPUT`):** True `1280x720` and `1664x936` output patching that works cleanly alongside DLSS and FSR 3 Frame Generation. Toggleable in **F1** (`OUTPUT SIZE (WINDOW)`).
|
- **Custom windowed output sizes (`VICTORY_OUTPUT`):** True `1280x720` and `1664x936` output patching that works cleanly alongside DLSS and FSR 3 Frame Generation. Toggleable in **F1** (`OUTPUT SIZE (WINDOW)`).
|
||||||
- **CPU submit-thread optimizations:** Lock-free `watch::AHEAD_KEPT` + binary-searched `ahead_contains`, `RwLock<Guards>` shared-read fast path, lock-free `Shadow::pending_len` & `Card::before`, merged `copied`/`ranged` lock, incremental `HeapRanges` spans, zero-alloc `HostList::prelude()` fast path, and reused `Batch` scratch buffers.
|
- **CPU submit-thread & refresh optimizations:** Fused single-pass write-watch `ask_once` with guarded-view skip, chunked `JOURNAL`-batched `nothing_new` filtering, AVX2 `word_runs` in `Shadow::take`, cached non-watched view-texture checks with zero-alloc `writes_since`, `AddressHash` on `Deferred::textures`, `has_gpu_write` fast-skip, deduplicated `card_before` root bindings, `Batch::last_ahead` 1-entry cache, lock-free `watch::AHEAD_KEPT` + binary-searched `ahead_contains`, `RwLock<Guards>` shared-read fast path, incremental `HeapRanges` spans, and zero-alloc `HostList::prelude()` fast path.
|
||||||
- **DLSS Super Resolution + AMD FSR 3 / DLSS Frame Generation:** Full F1 settings menu, F3 stats panel, HUD-less FSR 3 2X Frame Generation for RTX 20/30 and non-NVIDIA DX12 GPUs, and DLSS FG (2x–6x) for RTX 40/50.
|
- **DLSS Super Resolution + AMD FSR 3 / DLSS Frame Generation:** Full F1 settings menu, F3 stats panel, HUD-less FSR 3 2X Frame Generation for RTX 20/30 and non-NVIDIA DX12 GPUs, and DLSS FG (2x–6x) for RTX 40/50.
|
||||||
- **Portable 6 GB / 16 GB launcher (`scripts/play-6gb.ps1`):** Pre-configured with verified settings (`VICTORY_FAST_CORES=0` for hybrid P+E CPUs, `VICTORY_PORT_CONSTANTS=1`, aligned `SLOT_EVICT` thresholds, `VICTORY_PIPELINE_WAIT_MS=50`, and ReBAR GPU windows).
|
- **Portable 6 GB / 16 GB launcher (`scripts/play-6gb.ps1`):** Pre-configured with verified settings (`VICTORY_FAST_CORES=0` for hybrid P+E CPUs, `VICTORY_PORT_CONSTANTS=1`, aligned `SLOT_EVICT` thresholds, `VICTORY_PIPELINE_WAIT_MS=50`, and ReBAR GPU windows).
|
||||||
|
|
||||||
@@ -133,13 +133,14 @@ All numbers below were measured on the same Windows 11 gaming laptop (**Intel Co
|
|||||||
| Metric | Before (Stock `VIctory-NVIDIA` on 6 GB / 16 GB) | After (This Fork + Tuned Preset) | Change |
|
| Metric | Before (Stock `VIctory-NVIDIA` on 6 GB / 16 GB) | After (This Fork + Tuned Preset) | Change |
|
||||||
| :--- | :---: | :---: | :---: |
|
| :--- | :---: | :---: | :---: |
|
||||||
| **Shader-warm frame stall** | `1.9 fps` (`520 ms` pipeline wait stalls) | `0` stalls (`VICTORY_PIPELINE_WAIT_MS=50`) | **Eliminated** |
|
| **Shader-warm frame stall** | `1.9 fps` (`520 ms` pipeline wait stalls) | `0` stalls (`VICTORY_PIPELINE_WAIT_MS=50`) | **Eliminated** |
|
||||||
| **CPU `preparing` per frame** | `94.2 ms` | **`45.0 ms`** *(720p)* / **`53.7 ms`** *(1080p)* | **−52% (2.1× faster)** |
|
| **CPU `preparing` per frame** | `94.2 ms` | **`43.5–44.2 ms`** *(1080p)* / **`45.0 ms`** *(720p)* | **−54% (2.17× faster)** |
|
||||||
| **GPU idle bubbles (waiting on CPU)** | `24.2 ms` *(with `FAST_CORES=2`)* | **`8.4 ms`** *(1080p)* / **`16.7 ms`** *(720p)* | **GPU 97–99% busy** |
|
| **Texture refresh CPU time (all threads)** | `33.4 ms` (`6.6 ms` watch/guards) | **`17.8 ms`** (`1.7–2.3 ms` watch/guards) | **−47% (−65% watch)** |
|
||||||
| **Standard open-world scene (~6k draws, real FPS)** | `8.5 fps` real (`117.8 ms`) | **`10.1–10.4 fps` real** *(720p)* / **`9.0–9.8 fps`** *(sharp 1080p + all visuals)* | **+19% to +22% real** |
|
| **GPU idle bubbles (waiting on CPU)** | `24.2 ms` *(with `FAST_CORES=2`)* | **`4.4–8.5 ms`** *(1080p)* | **GPU 95–99% busy** |
|
||||||
| **Heavy open-world scene (~11k draws, real FPS)** | `4.8 fps` real (`208 ms`) | **`7.3 fps` real** *(720p)* / **`6.0 fps` real** *(sharp 1080p)* | **+25% to +52% real** |
|
| **Standard open-world scene (~6k draws, real FPS)** | `8.5 fps` real (`117.8 ms`) | **`9.5–9.9 fps` real** *(sharp 1080p + all visuals)* / **`10.1–10.4 fps`** *(720p)* | **+15% to +22% real** |
|
||||||
| **With FSR 3 2X Frame Gen (HUD-less)** | `17.0 fps` displayed (`8.5` base) | **`18.0–19.6 fps`** *(sharp 1080p, 96/96 HUD-less)* | **+15% + cleaner pacing** |
|
| **Heavy open-world scene (~11k draws, real FPS)** | `4.8 fps` real (`208 ms`) | **`6.5–6.7 fps` real** *(sharp 1080p)* / **`7.3 fps` real** *(720p)* | **+35% to +52% real** |
|
||||||
| **VRAM usage (6 GB card, 5.2 GiB DXGI budget)** | `5,291 MiB` peak *(hitting `no room` stalls)* | **`4,604–4,872 MiB` avg** | **Up to −687 MiB VRAM** |
|
| **With FSR 3 2X Frame Gen (HUD-less)** | `17.0 fps` displayed (`8.5` base) | **`19.0–19.8 fps`** *(sharp 1080p, 100/100 HUD-less)* | **+16% + cleaner pacing** |
|
||||||
| **System RAM (16 GB host)** | `16,513 MiB` private commit | **`14,703–14,900 MiB`** private / **`5.1–6.4 GiB`** working set | **−1.6 to −1.8 GiB RAM** |
|
| **VRAM usage (6 GB card, 5.2 GiB DXGI budget)** | `5,291 MiB` peak *(hitting `no room` stalls)* | **`4,604–4,965 MiB` avg** | **Up to −687 MiB VRAM** |
|
||||||
|
| **System RAM (16 GB host)** | `16,513 MiB` private commit | **`14,703–14,900 MiB`** private / **`4.1–5.1 GiB`** working set | **−1.6 to −1.8 GiB RAM** |
|
||||||
| **Texture eviction `sweep()` overhead** | `8.0 ms/frame` *(when `ROOM% > SLOT_EVICT%`)* | **`0.3 ms/frame`** *(aligned `85% / 92%`)* | **26× faster** |
|
| **Texture eviction `sweep()` overhead** | `8.0 ms/frame` *(when `ROOM% > SLOT_EVICT%`)* | **`0.3 ms/frame`** *(aligned `85% / 92%`)* | **26× faster** |
|
||||||
|
|
||||||
> **Hybrid CPU note (`i5-12450HX` 4P + 4E):** Switching `VICTORY_FAST_CORES=2` → `0` alone lifted real FPS from **`8.9 → 10.1 fps`** (**+13.5%**, peak `10.4`) on ~6k-draw views and **`6.3 → 7.3 fps`** (**+16%**) on heavy ~11k-draw views, while cutting CPU `preparing` from `59.4 → 45.0 ms` with zero visual loss. Unlocking a 30 W-capped laptop GPU up to its full 65 W Performance Mode adds further real-FPS headroom on top of these numbers.
|
> **Hybrid CPU note (`i5-12450HX` 4P + 4E):** Switching `VICTORY_FAST_CORES=2` → `0` alone lifted real FPS from **`8.9 → 10.1 fps`** (**+13.5%**, peak `10.4`) on ~6k-draw views and **`6.3 → 7.3 fps`** (**+16%**) on heavy ~11k-draw views, while cutting CPU `preparing` from `59.4 → 45.0 ms` with zero visual loss. Unlocking a 30 W-capped laptop GPU up to its full 65 W Performance Mode adds further real-FPS headroom on top of these numbers.
|
||||||
|
|||||||
+156
-43
@@ -2716,7 +2716,10 @@ struct Deferred {
|
|||||||
/// wrote title memory (source, bytes): its host address.
|
/// wrote title memory (source, bytes): its host address.
|
||||||
filled: std::collections::HashMap<(usize, usize), u64, std::hash::BuildHasherDefault<AddressHash>>,
|
filled: std::collections::HashMap<(usize, usize), u64, std::hash::BuildHasherDefault<AddressHash>>,
|
||||||
/// Textures whose contents the list brings up to date.
|
/// Textures whose contents the list brings up to date.
|
||||||
textures: std::collections::HashSet<usize>,
|
textures: std::collections::HashSet<usize, std::hash::BuildHasherDefault<AddressHash>>,
|
||||||
|
/// Whether `copies` contains at least one `Step::GpuWrite` (lets
|
||||||
|
/// `declared_writes` skip lists that only record refreshes/copies).
|
||||||
|
has_gpu_write: bool,
|
||||||
/// Bottom-of-pipe writes, done once the list has run: address, what,
|
/// Bottom-of-pipe writes, done once the list has run: address, what,
|
||||||
/// bytes.
|
/// bytes.
|
||||||
writes: Vec<(usize, crate::queue::Written, usize)>,
|
writes: Vec<(usize, crate::queue::Written, usize)>,
|
||||||
@@ -4329,7 +4332,11 @@ fn declared_writes(runs: &[&HostList]) -> Vec<Declared> {
|
|||||||
let mut places: ByCopy<usize> = ByCopy::default();
|
let mut places: ByCopy<usize> = ByCopy::default();
|
||||||
let mut seen = std::collections::HashSet::<(usize, usize, usize), std::hash::BuildHasherDefault<AddressHash>>::default();
|
let mut seen = std::collections::HashSet::<(usize, usize, usize), std::hash::BuildHasherDefault<AddressHash>>::default();
|
||||||
for list in runs {
|
for list in runs {
|
||||||
for step in &list.deferred().copies {
|
let deferred = list.deferred();
|
||||||
|
if !deferred.has_gpu_write {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
for step in &deferred.copies {
|
||||||
if let Step::GpuWrite(shadow, address, len) = step {
|
if let Step::GpuWrite(shadow, address, len) = step {
|
||||||
let key = std::sync::Arc::as_ptr(shadow) as usize;
|
let key = std::sync::Arc::as_ptr(shadow) as usize;
|
||||||
if !seen.insert((key, *address, *len)) {
|
if !seen.insert((key, *address, *len)) {
|
||||||
@@ -5023,16 +5030,27 @@ impl Host {
|
|||||||
list.SetComputeRootSignature(&work.root);
|
list.SetComputeRootSignature(&work.root);
|
||||||
list.SetPipelineState(&work.pso);
|
list.SetPipelineState(&work.pso);
|
||||||
list.SetComputeRootUnorderedAccessView(3, work.differs.0.GetGPUVirtualAddress());
|
list.SetComputeRootUnorderedAccessView(3, work.differs.0.GetGPUVirtualAddress());
|
||||||
|
let mut last_shadow = 0usize;
|
||||||
|
let mut last_size = 0u32;
|
||||||
|
let mut passes = 0u64;
|
||||||
for r in plan.ranges.iter().filter(|r| r.compared) {
|
for r in plan.ranges.iter().filter(|r| r.compared) {
|
||||||
let (Some((_, Some(before), _)), size) = (r.shadow.card_sides(), r.shadow.card_hash_size()) else {
|
let key = Arc::as_ptr(&r.shadow) as usize;
|
||||||
continue;
|
if key != last_shadow {
|
||||||
};
|
let (Some((_, Some(before), _)), size) = (r.shadow.card_sides(), r.shadow.card_hash_size()) else {
|
||||||
list.SetComputeRootShaderResourceView(1, r.shadow.buffer.GetGPUVirtualAddress());
|
continue;
|
||||||
list.SetComputeRootUnorderedAccessView(2, before.GetGPUVirtualAddress());
|
};
|
||||||
|
list.SetComputeRootShaderResourceView(1, r.shadow.buffer.GetGPUVirtualAddress());
|
||||||
|
list.SetComputeRootUnorderedAccessView(2, before.GetGPUVirtualAddress());
|
||||||
|
last_shadow = key;
|
||||||
|
last_size = size as u32;
|
||||||
|
}
|
||||||
// (What is only looked at keeps its hashes: what
|
// (What is only looked at keeps its hashes: what
|
||||||
// changed there is the next declared range's to land.)
|
// changed there is the next declared range's to land.)
|
||||||
card_pass(list, &r.span, size as u32, r.at, if flown && !r.picked { 2 } else { 1 });
|
card_pass(list, &r.span, last_size, r.at, if flown && !r.picked { 2 } else { 1 });
|
||||||
CARD_PASSES[2].fetch_add(1, Ordering::Relaxed);
|
passes += 1;
|
||||||
|
}
|
||||||
|
if passes != 0 {
|
||||||
|
CARD_PASSES[2].fetch_add(passes, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
list.Close()?;
|
list.Close()?;
|
||||||
list.cast()
|
list.cast()
|
||||||
@@ -7718,6 +7736,7 @@ impl HostList {
|
|||||||
let mut deferred = self.deferred();
|
let mut deferred = self.deferred();
|
||||||
let key = (std::sync::Arc::as_ptr(shadow) as usize, address, len);
|
let key = (std::sync::Arc::as_ptr(shadow) as usize, address, len);
|
||||||
if deferred.gpu_written.insert(key) || !declare_once() {
|
if deferred.gpu_written.insert(key) || !declare_once() {
|
||||||
|
deferred.has_gpu_write = true;
|
||||||
deferred.copies.push(Step::GpuWrite(shadow.clone(), address, len));
|
deferred.copies.push(Step::GpuWrite(shadow.clone(), address, len));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8584,6 +8603,9 @@ struct Batch {
|
|||||||
/// Copies (by address) brought up to date ahead of the steps, and the
|
/// Copies (by address) brought up to date ahead of the steps, and the
|
||||||
/// range (from, to) ([`Batch::refresh_ahead`]).
|
/// range (from, to) ([`Batch::refresh_ahead`]).
|
||||||
ahead: ByCopy<(usize, usize)>,
|
ahead: ByCopy<(usize, usize)>,
|
||||||
|
/// One-entry cache of the last hit in `ahead` (`(key, from, to)`), avoiding
|
||||||
|
/// repeated HashMap lookups for consecutive refreshes on the same buffer.
|
||||||
|
last_ahead: (usize, usize, usize),
|
||||||
/// `ahead` holds everything the submission refreshes
|
/// `ahead` holds everything the submission refreshes
|
||||||
/// ([`Batch::refresh_front`]).
|
/// ([`Batch::refresh_front`]).
|
||||||
front: bool,
|
front: bool,
|
||||||
@@ -8853,6 +8875,7 @@ impl Batch {
|
|||||||
self.placed.clear();
|
self.placed.clear();
|
||||||
self.fills.clear();
|
self.fills.clear();
|
||||||
self.ahead.clear();
|
self.ahead.clear();
|
||||||
|
self.last_ahead = (0, 0, 0);
|
||||||
self.front = false;
|
self.front = false;
|
||||||
self.spans.clear();
|
self.spans.clear();
|
||||||
self.spans_at.clear();
|
self.spans_at.clear();
|
||||||
@@ -8917,8 +8940,15 @@ impl Batch {
|
|||||||
}
|
}
|
||||||
let end = address + len;
|
let end = address + len;
|
||||||
let key = std::sync::Arc::as_ptr(shadow) as usize;
|
let key = std::sync::Arc::as_ptr(shadow) as usize;
|
||||||
if self.ahead.get(&key).is_some_and(|&(from, to)| from <= address && end <= to) {
|
if self.last_ahead.0 == key && key != 0 {
|
||||||
return;
|
if self.last_ahead.1 <= address && end <= self.last_ahead.2 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else if let Some(&(from, to)) = self.ahead.get(&key) {
|
||||||
|
self.last_ahead = (key, from, to);
|
||||||
|
if from <= address && end <= to {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
match self.index.get(&key) {
|
match self.index.get(&key) {
|
||||||
Some(&at) => {
|
Some(&at) => {
|
||||||
@@ -8938,7 +8968,11 @@ impl Batch {
|
|||||||
// From here on it is refreshed around what the shaders write. (What
|
// From here on it is refreshed around what the shaders write. (What
|
||||||
// is in front of all the steps was, up to here.)
|
// is in front of all the steps was, up to here.)
|
||||||
if !self.front {
|
if !self.front {
|
||||||
self.ahead.remove(&(std::sync::Arc::as_ptr(shadow) as usize));
|
let key = std::sync::Arc::as_ptr(shadow) as usize;
|
||||||
|
self.ahead.remove(&key);
|
||||||
|
if self.last_ahead.0 == key {
|
||||||
|
self.last_ahead = (0, 0, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
let Some(at) = self.index.remove(&(std::sync::Arc::as_ptr(shadow) as usize)) else {
|
let Some(at) = self.index.remove(&(std::sync::Arc::as_ptr(shadow) as usize)) else {
|
||||||
return;
|
return;
|
||||||
@@ -8981,6 +9015,7 @@ impl Batch {
|
|||||||
fn title_written(&mut self) {
|
fn title_written(&mut self) {
|
||||||
self.flush();
|
self.flush();
|
||||||
self.ahead.clear();
|
self.ahead.clear();
|
||||||
|
self.last_ahead = (0, 0, 0);
|
||||||
self.textures.clear();
|
self.textures.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -9039,32 +9074,71 @@ impl Batch {
|
|||||||
// Those known to copy nothing are said so here, unless they are very
|
// Those known to copy nothing are said so here, unless they are very
|
||||||
// many: then beside the others.
|
// many: then beside the others.
|
||||||
const FEW: usize = 256;
|
const FEW: usize = 256;
|
||||||
let mut spans = spans;
|
const CHUNK: usize = 64;
|
||||||
let many = spans.len() > FEW;
|
let spans = std::sync::Arc::new(spans);
|
||||||
if !many {
|
let dirty: Vec<usize> = if spans.len() <= FEW {
|
||||||
let all = spans.len();
|
let j = crate::watch::read_journal();
|
||||||
spans.retain(|(shadow, from, to)| !shadow.nothing_new(*from, *to - *from));
|
let mut keep = Vec::with_capacity(spans.len());
|
||||||
FLUSHES[2].fetch_add((all - spans.len()) as u64, Ordering::Relaxed);
|
for (i, (shadow, from, to)) in spans.iter().enumerate() {
|
||||||
}
|
if !shadow.nothing_new_in(&j, *from, *to - *from) {
|
||||||
let ahead = spans.len() > 1 && !crate::watch::kept_active();
|
keep.push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
FLUSHES[2].fetch_add((spans.len() - keep.len()) as u64, Ordering::Relaxed);
|
||||||
|
keep
|
||||||
|
} else {
|
||||||
|
let flags: std::sync::Arc<Vec<std::sync::atomic::AtomicBool>> = std::sync::Arc::new(
|
||||||
|
(0..spans.len()).map(|_| std::sync::atomic::AtomicBool::new(false)).collect(),
|
||||||
|
);
|
||||||
|
let chunks = spans.len().div_ceil(CHUNK);
|
||||||
|
let spans_ref = spans.clone();
|
||||||
|
let flags_ref = flags.clone();
|
||||||
|
crate::shadow::wide_each(chunks, move |c| {
|
||||||
|
let start = c * CHUNK;
|
||||||
|
let end = (start + CHUNK).min(spans_ref.len());
|
||||||
|
let j = crate::watch::read_journal();
|
||||||
|
let mut skipped = 0u64;
|
||||||
|
for i in start..end {
|
||||||
|
let (shadow, from, to) = &spans_ref[i];
|
||||||
|
if shadow.nothing_new_in(&j, *from, *to - *from) {
|
||||||
|
skipped += 1;
|
||||||
|
} else {
|
||||||
|
flags_ref[i].store(true, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if skipped != 0 {
|
||||||
|
FLUSHES[2].fetch_add(skipped, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
flags
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter_map(|(i, f)| f.load(Ordering::Relaxed).then_some(i))
|
||||||
|
.collect()
|
||||||
|
};
|
||||||
|
let ahead = dirty.len() > 1 && !crate::watch::kept_active();
|
||||||
if ahead {
|
if ahead {
|
||||||
let ranges: Vec<(usize, usize)> = spans.iter().filter(|r| r.0.asked_ahead()).map(|r| (r.1, r.2)).collect();
|
let ranges: Vec<(usize, usize)> = dirty
|
||||||
|
.iter()
|
||||||
|
.map(|&i| &spans[i])
|
||||||
|
.filter(|r| r.0.asked_ahead())
|
||||||
|
.map(|r| (r.1, r.2))
|
||||||
|
.collect();
|
||||||
crate::watch::ask_ahead(&ranges);
|
crate::watch::ask_ahead(&ranges);
|
||||||
}
|
}
|
||||||
FLUSHES[3].fetch_add(spans.len() as u64, Ordering::Relaxed);
|
FLUSHES[3].fetch_add(spans.len() as u64, Ordering::Relaxed);
|
||||||
crate::shadow::wide_each(spans.len() + due.len(), move |i| {
|
let work = dirty.len() + due.len();
|
||||||
// The textures first: they are the longer pieces.
|
if work > 0 {
|
||||||
let Some(i) = i.checked_sub(due.len()) else {
|
crate::shadow::wide_each(work, move |i| {
|
||||||
due[i].refresh();
|
// The textures first: they are the longer pieces.
|
||||||
return;
|
let Some(i) = i.checked_sub(due.len()) else {
|
||||||
};
|
due[i].refresh();
|
||||||
let (shadow, from, to) = &spans[i];
|
return;
|
||||||
if many && shadow.nothing_new(*from, *to - *from) {
|
};
|
||||||
FLUSHES[2].fetch_add(1, Ordering::Relaxed);
|
let (shadow, from, to) = &spans[dirty[i]];
|
||||||
return;
|
Self::update(shadow, *from, *to);
|
||||||
}
|
});
|
||||||
Self::update(shadow, *from, *to);
|
}
|
||||||
});
|
|
||||||
if ahead {
|
if ahead {
|
||||||
crate::watch::ask_ahead_done();
|
crate::watch::ask_ahead_done();
|
||||||
}
|
}
|
||||||
@@ -9185,13 +9259,19 @@ impl Batch {
|
|||||||
// and any thread woken. (Thousands of them, the heap's buffer views
|
// and any thread woken. (Thousands of them, the heap's buffer views
|
||||||
// once a frame: on the threads, below.)
|
// once a frame: on the threads, below.)
|
||||||
const FEW: usize = 256;
|
const FEW: usize = 256;
|
||||||
|
const CHUNK: usize = 64;
|
||||||
let light = crate::watch::light();
|
let light = crate::watch::light();
|
||||||
if light && self.refreshes.len() <= FEW {
|
if light && self.refreshes.len() <= FEW {
|
||||||
let started = std::time::Instant::now();
|
let started = std::time::Instant::now();
|
||||||
let all = self.refreshes.len();
|
let all = self.refreshes.len();
|
||||||
self.refreshes.retain(|(shadow, from, to)| !shadow.nothing_new(*from, *to - *from));
|
let j = crate::watch::read_journal();
|
||||||
|
self.refreshes.retain(|(shadow, from, to)| !shadow.nothing_new_in(&j, *from, *to - *from));
|
||||||
|
drop(j);
|
||||||
PREPARING[0].fetch_add(started.elapsed().as_micros() as u64, Ordering::Relaxed);
|
PREPARING[0].fetch_add(started.elapsed().as_micros() as u64, Ordering::Relaxed);
|
||||||
FLUSHES[2].fetch_add((all - self.refreshes.len()) as u64, Ordering::Relaxed);
|
FLUSHES[2].fetch_add((all - self.refreshes.len()) as u64, Ordering::Relaxed);
|
||||||
|
if self.refreshes.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// One write-watch asking for the copies that lie close together,
|
// One write-watch asking for the copies that lie close together,
|
||||||
// not one per copy.
|
// not one per copy.
|
||||||
@@ -9215,16 +9295,49 @@ impl Batch {
|
|||||||
let before = PREPARING[0].load(Ordering::Relaxed);
|
let before = PREPARING[0].load(Ordering::Relaxed);
|
||||||
FLUSHES[3].fetch_add(self.refreshes.len() as u64, Ordering::Relaxed);
|
FLUSHES[3].fetch_add(self.refreshes.len() as u64, Ordering::Relaxed);
|
||||||
if light {
|
if light {
|
||||||
// A number to a free thread, not a job to each copy.
|
|
||||||
let refreshes = std::mem::take(&mut self.refreshes);
|
let refreshes = std::mem::take(&mut self.refreshes);
|
||||||
crate::shadow::wide_each(refreshes.len(), move |i| {
|
if refreshes.len() > FEW {
|
||||||
let (shadow, from, to) = &refreshes[i];
|
let refreshes = std::sync::Arc::new(refreshes);
|
||||||
if refreshes.len() > FEW && shadow.nothing_new(*from, *to - *from) {
|
let flags: std::sync::Arc<Vec<std::sync::atomic::AtomicBool>> = std::sync::Arc::new(
|
||||||
FLUSHES[2].fetch_add(1, Ordering::Relaxed);
|
(0..refreshes.len()).map(|_| std::sync::atomic::AtomicBool::new(false)).collect(),
|
||||||
return;
|
);
|
||||||
|
let chunks = refreshes.len().div_ceil(CHUNK);
|
||||||
|
let r_ref = refreshes.clone();
|
||||||
|
let f_ref = flags.clone();
|
||||||
|
crate::shadow::wide_each(chunks, move |c| {
|
||||||
|
let start = c * CHUNK;
|
||||||
|
let end = (start + CHUNK).min(r_ref.len());
|
||||||
|
let j = crate::watch::read_journal();
|
||||||
|
let mut skipped = 0u64;
|
||||||
|
for i in start..end {
|
||||||
|
let (shadow, from, to) = &r_ref[i];
|
||||||
|
if shadow.nothing_new_in(&j, *from, *to - *from) {
|
||||||
|
skipped += 1;
|
||||||
|
} else {
|
||||||
|
f_ref[i].store(true, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if skipped != 0 {
|
||||||
|
FLUSHES[2].fetch_add(skipped, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
let dirty: Vec<usize> = flags
|
||||||
|
.iter()
|
||||||
|
.enumerate()
|
||||||
|
.filter_map(|(i, f)| f.load(Ordering::Relaxed).then_some(i))
|
||||||
|
.collect();
|
||||||
|
if !dirty.is_empty() {
|
||||||
|
crate::shadow::wide_each(dirty.len(), move |i| {
|
||||||
|
let (shadow, from, to) = &refreshes[dirty[i]];
|
||||||
|
Self::update(shadow, *from, *to);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Self::update(shadow, *from, *to);
|
} else {
|
||||||
});
|
crate::shadow::wide_each(refreshes.len(), move |i| {
|
||||||
|
let (shadow, from, to) = &refreshes[i];
|
||||||
|
Self::update(shadow, *from, *to);
|
||||||
|
});
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
let jobs: Vec<Box<dyn FnOnce() + Send>> = self
|
let jobs: Vec<Box<dyn FnOnce() + Send>> = self
|
||||||
.refreshes
|
.refreshes
|
||||||
|
|||||||
@@ -3912,6 +3912,26 @@ impl Shadow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// [`Shadow::changed`] for multiple offset ranges under a single `kept` lock.
|
||||||
|
fn changed_runs(&self, runs: impl Iterator<Item = (usize, usize)>) {
|
||||||
|
if !keeps() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let mut runs = runs.filter(|r| r.0 < r.1).peekable();
|
||||||
|
if runs.peek().is_none() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let mut kept = self.kept.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
|
if kept.0.is_empty() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (from, to) in runs {
|
||||||
|
for piece in self.pieces(from, to) {
|
||||||
|
kept.0[piece] = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether shaders of a submission not yet copied back may be writing
|
/// Whether shaders of a submission not yet copied back may be writing
|
||||||
/// the copy.
|
/// the copy.
|
||||||
#[inline]
|
#[inline]
|
||||||
@@ -4216,6 +4236,12 @@ impl Shadow {
|
|||||||
/// nothing, and knows it without asking anything
|
/// nothing, and knows it without asking anything
|
||||||
/// (`crate::watch::nothing_new`). `false` if it would have to ask.
|
/// (`crate::watch::nothing_new`). `false` if it would have to ask.
|
||||||
pub(crate) fn nothing_new(&self, address: usize, len: usize) -> bool {
|
pub(crate) fn nothing_new(&self, address: usize, len: usize) -> bool {
|
||||||
|
let j = crate::watch::read_journal();
|
||||||
|
self.nothing_new_in(&j, address, len)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// [`Shadow::nothing_new`] using an already-held write-watch journal read guard.
|
||||||
|
pub(crate) fn nothing_new_in(&self, j: &crate::watch::JournalGuard, address: usize, len: usize) -> bool {
|
||||||
if self.place.is_some() {
|
if self.place.is_some() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -4235,7 +4261,7 @@ impl Shadow {
|
|||||||
}
|
}
|
||||||
let copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
let copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
||||||
let ranged = Self::ranged_in(&copied.1, from, to);
|
let ranged = Self::ranged_in(&copied.1, from, to);
|
||||||
let same = crate::watch::nothing_new(from, to, start / PAGE, &copied.0, ranged);
|
let same = crate::watch::nothing_new_in(j, from, to, start / PAGE, &copied.0, ranged);
|
||||||
#[cfg(feature = "diagnostics")]
|
#[cfg(feature = "diagnostics")]
|
||||||
if same {
|
if same {
|
||||||
use crate::copystat::{C, add};
|
use crate::copystat::{C, add};
|
||||||
@@ -4255,11 +4281,15 @@ impl Shadow {
|
|||||||
/// [`Shadow::update`] of `[from, to)` (inside the buffer) where no
|
/// [`Shadow::update`] of `[from, to)` (inside the buffer) where no
|
||||||
/// shader writes.
|
/// shader writes.
|
||||||
fn update_free(&self, from: usize, to: usize) -> usize {
|
fn update_free(&self, from: usize, to: usize) -> usize {
|
||||||
if self.watched.load(Ordering::Relaxed) != NOT_WATCHED {
|
let prev = self.watched.load(Ordering::Relaxed);
|
||||||
|
if prev != NOT_WATCHED {
|
||||||
if let Some((now, written)) = crate::watch::writes(from, to, true) {
|
if let Some((now, written)) = crate::watch::writes(from, to, true) {
|
||||||
// (A range whose blocks rest after a write has no guard now.)
|
// (A range whose blocks rest after a write has no guard now.)
|
||||||
let guarded = crate::watch::guarded(from, to) || self.watched.load(Ordering::Relaxed) == GUARDED;
|
let guarded = prev == GUARDED || crate::watch::guarded(from, to);
|
||||||
self.watched.store(if guarded { GUARDED } else { 1 }, Ordering::Relaxed);
|
let next = if guarded { GUARDED } else { 1 };
|
||||||
|
if next != prev {
|
||||||
|
self.watched.store(next, Ordering::Relaxed);
|
||||||
|
}
|
||||||
let copied = self.copy_stale(from, to, now, &written);
|
let copied = self.copy_stale(from, to, now, &written);
|
||||||
self.refresh_check(from, to);
|
self.refresh_check(from, to);
|
||||||
#[cfg(feature = "diagnostics")]
|
#[cfg(feature = "diagnostics")]
|
||||||
@@ -4393,8 +4423,14 @@ impl Shadow {
|
|||||||
if let Some((first, known)) = run {
|
if let Some((first, known)) = run {
|
||||||
runs.push(((first * PAGE).max(from), ((last + 1) * PAGE).min(to), known));
|
runs.push(((first * PAGE).max(from), ((last + 1) * PAGE).min(to), known));
|
||||||
}
|
}
|
||||||
let runs = by_parts(runs, &again_at, &crate::watch::parts_written(&again_at));
|
let bytes = if runs.is_empty() {
|
||||||
let bytes = self.take_all(runs);
|
0
|
||||||
|
} else if again_at.is_empty() {
|
||||||
|
self.take_all(runs)
|
||||||
|
} else {
|
||||||
|
let runs = by_parts(runs, &again_at, &crate::watch::parts_written(&again_at));
|
||||||
|
self.take_all(runs)
|
||||||
|
};
|
||||||
if crate::watch::light() {
|
if crate::watch::light() {
|
||||||
// All of the range is in the copy as of this asking.
|
// All of the range is in the copy as of this asking.
|
||||||
let ranged = &mut copied.1;
|
let ranged = &mut copied.1;
|
||||||
@@ -4532,6 +4568,7 @@ impl Shadow {
|
|||||||
};
|
};
|
||||||
let whole = !known && card.before.get().is_none();
|
let whole = !known && card.before.get().is_none();
|
||||||
let start = self.start as usize;
|
let start = self.start as usize;
|
||||||
|
let (mut send0, mut send1, mut send2, mut send3) = (0u64, 0u64, 0u64, 0u64);
|
||||||
TITLE.with_borrow_mut(|title| {
|
TITLE.with_borrow_mut(|title| {
|
||||||
title.resize(PAGE, 0);
|
title.resize(PAGE, 0);
|
||||||
let mut at = from;
|
let mut at = from;
|
||||||
@@ -4546,24 +4583,37 @@ impl Shadow {
|
|||||||
// refresh lie apart.
|
// refresh lie apart.
|
||||||
let held = unsafe { std::slice::from_raw_parts_mut(self.data.add(at - start), n) };
|
let held = unsafe { std::slice::from_raw_parts_mut(self.data.add(at - start), n) };
|
||||||
let was = crate::host::upcheck::on().then(|| held.to_vec());
|
let was = crate::host::upcheck::on().then(|| held.to_vec());
|
||||||
let runs = if whole { vec![(0, n)] } else { dword_runs(at, held, title, 0) };
|
let runs = if whole { vec![(0, n)] } else { word_runs(at, held, title) };
|
||||||
|
let mut page_bytes = 0u64;
|
||||||
for &(a, len) in &runs {
|
for &(a, len) in &runs {
|
||||||
held[a..a + len].copy_from_slice(&title[a..a + len]);
|
held[a..a + len].copy_from_slice(&title[a..a + len]);
|
||||||
self.changed(at - start + a, at - start + a + len);
|
page_bytes += len as u64;
|
||||||
|
}
|
||||||
|
if !runs.is_empty() {
|
||||||
|
self.changed_runs(runs.iter().map(|&(a, len)| (at - start + a, at - start + a + len)));
|
||||||
|
self.card_changed_runs(runs.iter().map(|&(a, len)| (at - start + a, at - start + a + len)));
|
||||||
}
|
}
|
||||||
self.card_changed_runs(runs.iter().map(|&(a, len)| (at - start + a, at - start + a + len)));
|
|
||||||
if let Some(was) = was {
|
if let Some(was) = was {
|
||||||
crate::host::upcheck::note(self.id, at - start, &was, held);
|
crate::host::upcheck::note(self.id, at - start, &was, held);
|
||||||
}
|
}
|
||||||
SEND[0].fetch_add(n as u64, Ordering::Relaxed);
|
send0 += n as u64;
|
||||||
if runs.is_empty() {
|
if runs.is_empty() {
|
||||||
SEND[1].fetch_add(n as u64, Ordering::Relaxed);
|
send1 += n as u64;
|
||||||
|
} else {
|
||||||
|
send2 += page_bytes;
|
||||||
|
send3 += runs.len() as u64;
|
||||||
}
|
}
|
||||||
SEND[2].fetch_add(runs.iter().map(|r| r.1 as u64).sum(), Ordering::Relaxed);
|
|
||||||
SEND[3].fetch_add(runs.len() as u64, Ordering::Relaxed);
|
|
||||||
at += n;
|
at += n;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
SEND[0].fetch_add(send0, Ordering::Relaxed);
|
||||||
|
if send1 != 0 {
|
||||||
|
SEND[1].fetch_add(send1, Ordering::Relaxed);
|
||||||
|
}
|
||||||
|
if send2 != 0 {
|
||||||
|
SEND[2].fetch_add(send2, Ordering::Relaxed);
|
||||||
|
SEND[3].fetch_add(send3, Ordering::Relaxed);
|
||||||
|
}
|
||||||
to - from
|
to - from
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -110,6 +110,10 @@ struct Last {
|
|||||||
/// first checks, and after the hash found a change the guard had not
|
/// first checks, and after the hash found a change the guard had not
|
||||||
/// seen ([`hot_textures`]). 0: not checked under the guard yet.
|
/// seen ([`hot_textures`]). 0: not checked under the guard yet.
|
||||||
hot_until: u64,
|
hot_until: u64,
|
||||||
|
/// Cached negative result from write-watch (`writes(..., false)` returned
|
||||||
|
/// `None` or the range is already guarded view memory), avoiding a
|
||||||
|
/// guaranteed-failing `GetWriteWatch` syscall on every refresh.
|
||||||
|
not_watched: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Frames a guarded texture is hashed at every check from its first check,
|
/// Frames a guarded texture is hashed at every check from its first check,
|
||||||
@@ -1449,20 +1453,26 @@ impl Staging {
|
|||||||
if alone && !exact && last.hash.is_some() {
|
if alone && !exact && last.hash.is_some() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if !alone && let Some((now, written)) = waited(1, || crate::watch::writes(start, start + size, false)) {
|
if !alone && !last.not_watched {
|
||||||
if !exact && last.asked != 0 && written.iter().all(|&(_, w)| w <= last.asked) {
|
if crate::watch::guarded(start, start + size) {
|
||||||
return 0;
|
last.not_watched = true;
|
||||||
|
} else if let Some((now, changed)) = waited(1, || crate::watch::writes_since(start, start + size, false, last.asked)) {
|
||||||
|
if !exact && !changed {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
last.asked = now;
|
||||||
|
// Read through the copy, which stands unmapped pages: memory of
|
||||||
|
// big pools is too slow to ask page by page.
|
||||||
|
with_read(size, |read| {
|
||||||
|
crate::host::copy_mapped(read.as_mut_ptr(), self.memory, size, false);
|
||||||
|
self.detile(read);
|
||||||
|
});
|
||||||
|
#[cfg(feature = "diagnostics")]
|
||||||
|
crate::copystat::add(crate::copystat::C::TexWatched, size as u64);
|
||||||
|
return size;
|
||||||
|
} else {
|
||||||
|
last.not_watched = true;
|
||||||
}
|
}
|
||||||
last.asked = now;
|
|
||||||
// Read through the copy, which stands unmapped pages: memory of
|
|
||||||
// big pools is too slow to ask page by page.
|
|
||||||
with_read(size, |read| {
|
|
||||||
crate::host::copy_mapped(read.as_mut_ptr(), self.memory, size, false);
|
|
||||||
self.detile(read);
|
|
||||||
});
|
|
||||||
#[cfg(feature = "diagnostics")]
|
|
||||||
crate::copystat::add(crate::copystat::C::TexWatched, size as u64);
|
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
// View memory has no write-watch, and a texture there was hashed
|
// View memory has no write-watch, and a texture there was hashed
|
||||||
// whole at every check: 229 MB and 51 ms a frame in a gameplay view
|
// whole at every check: 229 MB and 51 ms a frame in a gameplay view
|
||||||
@@ -1479,10 +1489,10 @@ impl Staging {
|
|||||||
let mut blind = false;
|
let mut blind = false;
|
||||||
if !alone
|
if !alone
|
||||||
&& *GUARD.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_GUARD").is_none_or(|v| v != "0"))
|
&& *GUARD.get_or_init(|| std::env::var_os("VICTORY_TEXTURE_GUARD").is_none_or(|v| v != "0"))
|
||||||
&& let Some((now, written)) = waited(1, || crate::watch::writes(start, start + size, true))
|
&& let Some((now, changed)) = waited(1, || crate::watch::writes_since(start, start + size, true, last.asked))
|
||||||
{
|
{
|
||||||
const HASH_EVERY: u64 = 8;
|
const HASH_EVERY: u64 = 8;
|
||||||
let unwritten = last.asked != 0 && written.iter().all(|&(_, w)| w <= last.asked);
|
let unwritten = !changed;
|
||||||
last.asked = now;
|
last.asked = now;
|
||||||
let frame = crate::frame::current();
|
let frame = crate::frame::current();
|
||||||
let turn = frame
|
let turn = frame
|
||||||
|
|||||||
+145
-61
@@ -164,6 +164,14 @@ fn journal_mut() -> std::sync::RwLockWriteGuard<'static, Journal> {
|
|||||||
waited(2, || JOURNAL.write().unwrap_or_else(|e| e.into_inner()))
|
waited(2, || JOURNAL.write().unwrap_or_else(|e| e.into_inner()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Shared read guard over the write-watch journal so a batch of `nothing_new`
|
||||||
|
/// checks can acquire the lock once instead of per buffer.
|
||||||
|
pub(crate) struct JournalGuard(std::sync::RwLockReadGuard<'static, Journal>);
|
||||||
|
|
||||||
|
pub(crate) fn read_journal() -> JournalGuard {
|
||||||
|
JournalGuard(journal())
|
||||||
|
}
|
||||||
|
|
||||||
/// Since the last line: waits and nanoseconds of waiting, of all threads, for
|
/// Since the last line: waits and nanoseconds of waiting, of all threads, for
|
||||||
/// the ranges held ([`ASKING`]), the journal to read it, the journal to note
|
/// the ranges held ([`ASKING`]), the journal to read it, the journal to note
|
||||||
/// in it, and the guards (faults of the title's among them).
|
/// in it, and the guards (faults of the title's among them).
|
||||||
@@ -367,17 +375,33 @@ pub(crate) fn ask_ahead(ranges: &[(usize, usize)]) {
|
|||||||
if kept_active() {
|
if kept_active() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
let skip_guarded = light();
|
||||||
let mut pieces: Vec<(usize, usize)> = ranges
|
let mut pieces: Vec<(usize, usize)> = ranges
|
||||||
.iter()
|
.iter()
|
||||||
// Not view memory known by its bits: the kernel would refuse the
|
// Not view memory known by its bits or guarded read-only: the kernel
|
||||||
// asking (and, asked together with others, theirs).
|
// would refuse the asking (and, asked together with others, theirs).
|
||||||
.filter(|r| r.0 < r.1 && !published(r.0, r.1))
|
.filter(|r| r.0 < r.1 && !published(r.0, r.1))
|
||||||
.map(|&(start, end)| (start / PAGE, end.div_ceil(PAGE)))
|
.map(|&(start, end)| (start / PAGE, end.div_ceil(PAGE)))
|
||||||
|
.filter(|&(first, last)| !(skip_guarded && PROTECTED.any(first, last)))
|
||||||
.collect();
|
.collect();
|
||||||
if pieces.len() < 2 {
|
if pieces.len() < 2 {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
pieces.sort_unstable();
|
pieces.sort_unstable();
|
||||||
|
// Collapse duplicate or fully-contained page spans before asking.
|
||||||
|
let mut write = 0usize;
|
||||||
|
for read in 1..pieces.len() {
|
||||||
|
let (a, b) = pieces[read];
|
||||||
|
if a >= pieces[write].0 && b <= pieces[write].1 {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
write += 1;
|
||||||
|
pieces[write] = (a, b);
|
||||||
|
}
|
||||||
|
pieces.truncate(write + 1);
|
||||||
|
if pieces.len() < 2 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let _all = Asking::hold_all();
|
let _all = Asking::hold_all();
|
||||||
let (mut asked, mut written) = (Vec::new(), Vec::new());
|
let (mut asked, mut written) = (Vec::new(), Vec::new());
|
||||||
let mut i = 0;
|
let mut i = 0;
|
||||||
@@ -392,7 +416,7 @@ pub(crate) fn ask_ahead(ranges: &[(usize, usize)]) {
|
|||||||
last = last.max(pieces[k].1);
|
last = last.max(pieces[k].1);
|
||||||
k += 1;
|
k += 1;
|
||||||
}
|
}
|
||||||
ask_run(&pieces[i..k], &mut asked, &mut written);
|
ask_run(&pieces[i..k], &mut asked, &mut written, false);
|
||||||
i = k;
|
i = k;
|
||||||
}
|
}
|
||||||
sort_merge_ahead(&mut asked);
|
sort_merge_ahead(&mut asked);
|
||||||
@@ -578,63 +602,63 @@ pub(crate) fn once() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// With [`once`]: asks about `ranges` (everything a submission's lists
|
/// With [`once`]: asks about `ranges` (everything a submission's lists
|
||||||
/// refresh) as [`ask_ahead`] does, and lets that asking stand until
|
/// refresh) in a single pass (merged runs and isolated ranges together) and
|
||||||
/// [`ask_once_end`].
|
/// lets that asking stand until [`ask_once_end`].
|
||||||
pub(crate) fn ask_once(ranges: &[(usize, usize)]) {
|
pub(crate) fn ask_once(ranges: &[(usize, usize)]) {
|
||||||
if !once() {
|
if !once() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ask_once_end();
|
ask_once_end();
|
||||||
ask_ahead(ranges);
|
let skip_guarded = light();
|
||||||
ask_rest(ranges);
|
let mut pieces: Vec<(usize, usize)> = ranges
|
||||||
}
|
.iter()
|
||||||
|
.filter(|r| r.0 < r.1 && !published(r.0, r.1))
|
||||||
/// [`ask_once`] after its [`ask_ahead`]: what that left to `writes`, and the
|
.map(|&(start, end)| (start / PAGE, end.div_ceil(PAGE)))
|
||||||
/// asking stands.
|
.filter(|&(first, last)| !(skip_guarded && PROTECTED.any(first, last)))
|
||||||
fn ask_rest(ranges: &[(usize, usize)]) {
|
.collect();
|
||||||
let _all = Asking::hold_all();
|
if pieces.is_empty() {
|
||||||
let mut ahead = {
|
return;
|
||||||
let mut j = journal_mut();
|
}
|
||||||
std::mem::take(&mut j.ahead)
|
pieces.sort_unstable();
|
||||||
};
|
// Collapse exact duplicates and fully-contained page spans in O(N).
|
||||||
// `ask_ahead` leaves a range that lies alone to `writes`, which asks
|
let mut write = 0usize;
|
||||||
// once per flush: with one asking for the submission that was every
|
for read in 1..pieces.len() {
|
||||||
// such range asked again at each of its 70 flushes (run 76: 2,300
|
let (a, b) = pieces[read];
|
||||||
// askings a frame with the switch on, as without it). They are asked
|
if a >= pieces[write].0 && b <= pieces[write].1 {
|
||||||
// here, once; what is not write-watched stays with `writes`.
|
|
||||||
let mut written = Vec::new();
|
|
||||||
let mut extra = Vec::new();
|
|
||||||
for &(start, end) in ranges {
|
|
||||||
if start >= end || published(start, end) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let (first, last) = (start / PAGE, end.div_ceil(PAGE));
|
write += 1;
|
||||||
if !ahead_contains(&ahead, first, last)
|
pieces[write] = (a, b);
|
||||||
&& !extra.iter().any(|&(a, b)| a <= first && last <= b)
|
}
|
||||||
&& let Some(pages) = kernel_written(first, last)
|
pieces.truncate(write + 1);
|
||||||
|
let _all = Asking::hold_all();
|
||||||
|
let (mut asked, mut written) = (Vec::new(), Vec::new());
|
||||||
|
let mut i = 0;
|
||||||
|
while i < pieces.len() {
|
||||||
|
let first = pieces[i].0;
|
||||||
|
let mut last = pieces[i].1;
|
||||||
|
let mut k = i + 1;
|
||||||
|
while k < pieces.len()
|
||||||
|
&& pieces[k].0 <= last + AHEAD_GAP
|
||||||
|
&& last.max(pieces[k].1) - first <= AHEAD_MAX
|
||||||
{
|
{
|
||||||
written.extend(pages);
|
last = last.max(pieces[k].1);
|
||||||
extra.push((first, last));
|
k += 1;
|
||||||
}
|
}
|
||||||
|
ask_run(&pieces[i..k], &mut asked, &mut written, true);
|
||||||
|
i = k;
|
||||||
}
|
}
|
||||||
if !extra.is_empty() {
|
sort_merge_ahead(&mut asked);
|
||||||
ahead.extend(extra);
|
|
||||||
sort_merge_ahead(&mut ahead);
|
|
||||||
}
|
|
||||||
note_hot(&written);
|
note_hot(&written);
|
||||||
let mut j = journal_mut();
|
let mut j = journal_mut();
|
||||||
// A number of its own, and the one this asking stands under: between
|
|
||||||
// the two parts another thread may have asked about a range of the
|
|
||||||
// second, copied it, and the title written it since. Under the first
|
|
||||||
// part's number that write was older than the copy, and never copied.
|
|
||||||
let now = next_asking();
|
let now = next_asking();
|
||||||
j.ahead_asked = now;
|
j.ahead_asked = now;
|
||||||
for (page, parts) in written {
|
for (page, parts) in written {
|
||||||
j.note(page, parts, now);
|
j.note(page, parts, now);
|
||||||
}
|
}
|
||||||
let kept = !ahead.is_empty();
|
let kept = !asked.is_empty();
|
||||||
j.kept = kept;
|
j.kept = kept;
|
||||||
j.ahead = ahead;
|
j.ahead = asked;
|
||||||
AHEAD_KEPT.store(kept, std::sync::atomic::Ordering::Release);
|
AHEAD_KEPT.store(kept, std::sync::atomic::Ordering::Release);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -686,10 +710,11 @@ fn elsewhere(at: usize, len: usize) -> Vec<(usize, Vec<usize>)> {
|
|||||||
|
|
||||||
/// One kernel asking for `pieces` (page ranges in order); by halves if it
|
/// One kernel asking for `pieces` (page ranges in order); by halves if it
|
||||||
/// fails, as a run across two reservations or into memory that is not
|
/// fails, as a run across two reservations or into memory that is not
|
||||||
/// write-watched does. A piece alone is left to [`writes`]. Adds what was
|
/// write-watched does. When `ask_single` is false, a piece alone is left to
|
||||||
/// asked to `asked` and the pages found written to `written`.
|
/// [`writes`]. Adds what was asked to `asked` and the pages found written to
|
||||||
fn ask_run(pieces: &[(usize, usize)], asked: &mut Vec<(usize, usize)>, written: &mut Vec<(usize, u16)>) {
|
/// `written`.
|
||||||
if pieces.len() < 2 {
|
fn ask_run(pieces: &[(usize, usize)], asked: &mut Vec<(usize, usize)>, written: &mut Vec<(usize, u16)>, ask_single: bool) {
|
||||||
|
if pieces.is_empty() || (!ask_single && pieces.len() < 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let first = pieces[0].0;
|
let first = pieces[0].0;
|
||||||
@@ -699,9 +724,12 @@ fn ask_run(pieces: &[(usize, usize)], asked: &mut Vec<(usize, usize)>, written:
|
|||||||
asked.push((first, last));
|
asked.push((first, last));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if pieces.len() < 2 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
let (a, b) = pieces.split_at(pieces.len() / 2);
|
let (a, b) = pieces.split_at(pieces.len() / 2);
|
||||||
ask_run(a, asked, written);
|
ask_run(a, asked, written, ask_single);
|
||||||
ask_run(b, asked, written);
|
ask_run(b, asked, written, ask_single);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// What [`writes`] would say of `[start, end)` from the journal alone, if
|
/// What [`writes`] would say of `[start, end)` from the journal alone, if
|
||||||
@@ -729,7 +757,13 @@ pub(crate) fn writes(start: usize, end: usize, guarded: bool) -> Option<(u64, Ve
|
|||||||
materialize(start, end.saturating_sub(start));
|
materialize(start, end.saturating_sub(start));
|
||||||
}
|
}
|
||||||
let (first, last) = (start / PAGE, end.div_ceil(PAGE));
|
let (first, last) = (start / PAGE, end.div_ceil(PAGE));
|
||||||
let of = |j: &Journal| -> Vec<(usize, u64)> { j.written.range(first..last).map(|(&p, &w)| (p, w)).collect() };
|
let of = |j: &Journal| -> Vec<(usize, u64)> {
|
||||||
|
if first + 1 == last {
|
||||||
|
j.written.get(&first).map(|&w| vec![(first, w)]).unwrap_or_default()
|
||||||
|
} else {
|
||||||
|
j.written.range(first..last).map(|(&p, &w)| (p, w)).collect()
|
||||||
|
}
|
||||||
|
};
|
||||||
// Asked ahead with the submission's other ranges: the journal has it.
|
// Asked ahead with the submission's other ranges: the journal has it.
|
||||||
let ahead = |j: &Journal| ahead_contains(&j.ahead, first, last).then(|| (j.ahead_asked, of(j)));
|
let ahead = |j: &Journal| ahead_contains(&j.ahead, first, last).then(|| (j.ahead_asked, of(j)));
|
||||||
if let Some(known) = ahead(&journal()) {
|
if let Some(known) = ahead(&journal()) {
|
||||||
@@ -800,29 +834,79 @@ pub(crate) fn writes(start: usize, end: usize, guarded: bool) -> Option<(u64, Ve
|
|||||||
Some(answer)
|
Some(answer)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Like [`writes`], but returns `(asking, changed_since)` without allocating a
|
||||||
|
/// per-page vector on the hot fast paths (`ahead` or `published`).
|
||||||
|
pub(crate) fn writes_since(start: usize, end: usize, guarded: bool, since: u64) -> Option<(u64, bool)> {
|
||||||
|
if guarded && soft().is_none() {
|
||||||
|
materialize(start, end.saturating_sub(start));
|
||||||
|
}
|
||||||
|
let (first, last) = (start / PAGE, end.div_ceil(PAGE));
|
||||||
|
let newer = |j: &Journal| -> bool {
|
||||||
|
if since == 0 {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if first + 1 == last {
|
||||||
|
j.written.get(&first).is_some_and(|&w| w > since)
|
||||||
|
} else {
|
||||||
|
j.written.range(first..last).any(|(_, &w)| w > since)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
{
|
||||||
|
let j = journal();
|
||||||
|
if ahead_contains(&j.ahead, first, last) {
|
||||||
|
return Some((j.ahead_asked, newer(&j)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if guarded && published(start, end) {
|
||||||
|
#[cfg(feature = "diagnostics")]
|
||||||
|
{
|
||||||
|
tally(2, 1);
|
||||||
|
crate::faultbook::note(crate::faultbook::What::Known, first, last, 0);
|
||||||
|
}
|
||||||
|
let j = journal();
|
||||||
|
return Some((next_asking(), newer(&j)));
|
||||||
|
}
|
||||||
|
let (now, written) = writes(start, end, guarded)?;
|
||||||
|
let changed = since == 0 || written.iter().any(|&(_, w)| w > since);
|
||||||
|
Some((now, changed))
|
||||||
|
}
|
||||||
|
|
||||||
/// Whether nothing of `[start, end)` was written that a copy with the notes
|
/// Whether nothing of `[start, end)` was written that a copy with the notes
|
||||||
/// `copied` (the asking after which each page from page `base` on was taken)
|
/// `copied` (the asking after which each page from page `base` on was taken)
|
||||||
/// and `ranged` (the asking after which a range that holds this one was
|
/// and `ranged` (the asking after which a range that holds this one was
|
||||||
/// taken whole, or 0) does not hold, as [`writes`] would answer with nothing
|
/// taken whole, or 0) does not hold, as [`writes`] would answer with nothing
|
||||||
/// asked: the submission's asking covers the range, or its blocks are known
|
/// asked: the submission's asking covers the range, or its blocks are known
|
||||||
/// by their bits. `false` if something would have to be asked.
|
/// by their bits. `false` if something would have to be asked.
|
||||||
pub(crate) fn nothing_new(start: usize, end: usize, base: usize, copied: &[u64], ranged: u64) -> bool {
|
pub(crate) fn nothing_new_in(j: &JournalGuard, start: usize, end: usize, base: usize, copied: &[u64], ranged: u64) -> bool {
|
||||||
let (first, last) = (start / PAGE, end.div_ceil(PAGE));
|
let (first, last) = (start / PAGE, end.div_ceil(PAGE));
|
||||||
// The bits first, then the journal, as in `writes`.
|
let covered = {
|
||||||
let known = published(start, end);
|
#[cfg(feature = "diagnostics")]
|
||||||
#[cfg(feature = "diagnostics")]
|
{
|
||||||
if known {
|
let known = published(start, end);
|
||||||
crate::faultbook::note(crate::faultbook::What::Known, first, last, 1);
|
if known {
|
||||||
}
|
crate::faultbook::note(crate::faultbook::What::Known, first, last, 1);
|
||||||
let j = journal();
|
}
|
||||||
if !known && !ahead_contains(&j.ahead, first, last) {
|
known || ahead_contains(&j.0.ahead, first, last)
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "diagnostics"))]
|
||||||
|
{
|
||||||
|
ahead_contains(&j.0.ahead, first, last) || published(start, end)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if !covered {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
let Some(taken) = first.checked_sub(base).and_then(|from| copied.get(from..last - base)) else {
|
let Some(taken) = first.checked_sub(base).and_then(|from| copied.get(from..last - base)) else {
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
(ranged != 0 || taken.iter().all(|&at| at != 0))
|
if ranged == 0 && taken.iter().any(|&at| at == 0) {
|
||||||
&& j.written.range(first..last).all(|(&page, &write)| write <= taken[page - first].max(ranged))
|
return false;
|
||||||
|
}
|
||||||
|
if first + 1 == last {
|
||||||
|
j.0.written.get(&first).is_none_or(|&write| write <= taken[0].max(ranged))
|
||||||
|
} else {
|
||||||
|
j.0.written.range(first..last).all(|(&page, &write)| write <= taken[page - first].max(ranged))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Tracked {
|
impl Tracked {
|
||||||
@@ -3750,7 +3834,7 @@ mod tests {
|
|||||||
let (copied, _) = writes(p, p + 4 * PAGE, false).expect("watched");
|
let (copied, _) = writes(p, p + 4 * PAGE, false).expect("watched");
|
||||||
// SAFETY: committed pages of ours.
|
// SAFETY: committed pages of ours.
|
||||||
unsafe { ((p + PAGE) as *mut u8).write_volatile(1) };
|
unsafe { ((p + PAGE) as *mut u8).write_volatile(1) };
|
||||||
ask_rest(&ranges);
|
ask_once(&ranges);
|
||||||
let last = journal().written.get(&(p / PAGE + 1)).copied();
|
let last = journal().written.get(&(p / PAGE + 1)).copied();
|
||||||
ask_once_end();
|
ask_once_end();
|
||||||
assert!(last.is_some_and(|last| last > copied), "{last:?} is not after {copied}");
|
assert!(last.is_some_and(|last| last > copied), "{last:?} is not after {copied}");
|
||||||
|
|||||||
Reference in new issue
Block a user