A write through one view of a page is seen at its other views; page writes counted; levels on demand (off); warm-up; card memory numbers
Memory sync: - The guard over every view of a physical page (code by myokex, victory-amd c6dc4d8, after pull request #115 by Spexivus, its correction by joroyt and a part of VIctory #1122 by tightfall): the title shows one page at several addresses and a copy was guarded at one only. 0.8 to 1.0 million writes through another view in a five-minute run on the test machine. VICTORY_VIEW_GUARD=0 turns it off. - Kernel reads into title memory are read beside and copied in (Joshua Odom, 10ea38e). - Writes of the storage layer into physical pages are counted where the title has the pages mapped and can open the guards there (VICTORY_PAGE_WRITES, off: counted only). Failed page-destination reads are retried. Card memory: - Levels on demand, off unless VICTORY_LEVELS_ON_DEMAND=1: a texture the title fills takes card memory for the levels the title holds; held levels get memory only while the card has room and are asked for again. Its test runs on the software adapter; not run on a card yet. - Refused texture slots are held back so a pass reaches the slots behind them; room can be kept for card copies of title buffers (off). Tools: translate --warm all; the shader cache is keyed on the translator's source; counters for copy-back races, page writes and the copies the texture sweep never lets go; a walls trace. Game runs of these changes on an RTX 4070: five five-minute runs without a device loss or a failed request. This merged tree was built; its test suites were run on the tree the changes come from (gpu 129, hle 97). Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
1 parent
310c6eb6c1
commit
8dd30ab472
25 files changed
+4218
-240
No files matched your search
@@ -594,9 +594,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.
|
||||
@@ -609,22 +607,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;
|
||||
@@ -650,6 +645,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);
|
||||
}
|
||||
@@ -672,12 +672,12 @@ 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;
|
||||
@@ -685,16 +685,22 @@ impl Layout {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -702,16 +708,47 @@ impl Layout {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -968,6 +1005,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.
|
||||
|
||||
Reference in new issue
Block a user