gpu: fuse ask_once, batch journal nothing_new, use AVX2 word_runs in Shadow::take, and cache non-watched view textures
This commit is contained in:
1 parent
3a4ce453cd
commit
3f3e525d55
4 files changed
+342
-120
No files matched your search
@@ -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
|
||||
/// the copy.
|
||||
#[inline]
|
||||
@@ -4216,6 +4236,12 @@ impl Shadow {
|
||||
/// nothing, and knows it without asking anything
|
||||
/// (`crate::watch::nothing_new`). `false` if it would have to ask.
|
||||
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() {
|
||||
return true;
|
||||
}
|
||||
@@ -4235,7 +4261,7 @@ impl Shadow {
|
||||
}
|
||||
let copied = self.copied.lock().unwrap_or_else(|e| e.into_inner());
|
||||
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")]
|
||||
if same {
|
||||
use crate::copystat::{C, add};
|
||||
@@ -4255,11 +4281,15 @@ impl Shadow {
|
||||
/// [`Shadow::update`] of `[from, to)` (inside the buffer) where no
|
||||
/// shader writes.
|
||||
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) {
|
||||
// (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;
|
||||
self.watched.store(if guarded { GUARDED } else { 1 }, Ordering::Relaxed);
|
||||
let guarded = prev == GUARDED || crate::watch::guarded(from, to);
|
||||
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);
|
||||
self.refresh_check(from, to);
|
||||
#[cfg(feature = "diagnostics")]
|
||||
@@ -4393,8 +4423,14 @@ impl Shadow {
|
||||
if let Some((first, known)) = run {
|
||||
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 = self.take_all(runs);
|
||||
let bytes = if runs.is_empty() {
|
||||
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() {
|
||||
// All of the range is in the copy as of this asking.
|
||||
let ranged = &mut copied.1;
|
||||
@@ -4532,6 +4568,7 @@ impl Shadow {
|
||||
};
|
||||
let whole = !known && card.before.get().is_none();
|
||||
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.resize(PAGE, 0);
|
||||
let mut at = from;
|
||||
@@ -4546,24 +4583,37 @@ impl Shadow {
|
||||
// refresh lie apart.
|
||||
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 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 {
|
||||
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 {
|
||||
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() {
|
||||
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;
|
||||
}
|
||||
});
|
||||
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
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user