Skip to content
Closed
Changes from all commits
Commits
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
46 changes: 46 additions & 0 deletions crates/xcl/src/gpu/tiling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,19 @@ impl Chain {
let l = self.levels[i];
let e = 1usize << self.layout.elem_log2;
let mut out = vec![0u8; l.width * l.height * e];
if self.layout.mode == 0 && self.layout.base_xor == 0 && l.origin == (0, 0) {
// linear: a row's elements are contiguous, so it is copied whole (the elements that
// are all in `src`, as below) – a video plane of 3840×2160 is 2160 copies, not 8 M
let row = l.width * e;
for y in 0..l.height {
let o = self.element_at(&l, 0, y, slice);
let n = src.len().saturating_sub(o).min(row) / e * e;
if n > 0 {
out[y * row..][..n].copy_from_slice(&src[o..o + n]);
}
}
return out;
}
for y in 0..l.height {
for x in 0..l.width {
let o = self.element_at(&l, x, y, slice);
Expand Down Expand Up @@ -513,6 +526,39 @@ mod tests {
}
}

/// Linear levels are copied a row at a time: the same bytes as element by element, for every
/// element size, padded rows, every mip and a source cut short (inside a row and inside an
/// element).
#[test]
fn linear_levels_detile_by_rows_as_by_elements() {
let by_elements = |c: &Chain, src: &[u8], i: usize| {
let l = c.levels[i];
let e = 1usize << c.layout.elem_log2;
let mut out = vec![0u8; l.width * l.height * e];
for y in 0..l.height {
for x in 0..l.width {
let o = c.element_at(&l, x, y, 0);
if let Some(s) = src.get(o..o + e) {
out[(y * l.width + x) * e..][..e].copy_from_slice(s);
}
}
}
out
};
for e in 0..5u32 {
for (w, h, mips) in [(3840u32, 4u32, 1u32), (1920, 3, 1), (77, 13, 4), (1, 1, 1), (300, 200, 9)] {
let c = Chain::new(Layout::new(0, e, PipeConfig { pipes_log2: 0, pkrs_log2: 0 }).unwrap(), w, h, 1, mips);
let full: Vec<u8> = (0..c.slice_bytes).map(|k| (k * 7 + 3) as u8 | 1).collect();
for cut in [full.len(), full.len() / 2 + 1, 5, 0] {
let src = &full[..cut];
for i in 0..c.levels.len() {
assert_eq!(c.detile_level(src, i, 0), by_elements(&c, src, i), "e{e} {w}x{h} level {i} src {cut} B");
}
}
}
}
}

/// The 3D thick modes: every element size and pipe configuration maps a w × h × d block
/// onto its bytes one to one.
#[test]
Expand Down
Loading