Formats: test texture layouts against addrlib's own sizes and addresses
The layouts follow AMD's addrlib, but the tests only checked them against themselves (every element on its own address) and a few hand-worked offsets. Two tests now pin them to addrlib itself (Mesa src/amd/addrlib at ed09d38, Navi 21 settings): - layouts_match_addrlib: 21 descriptions over every mode Layout::offset addresses (linear, 256 B, 4 KiB and 64 KiB S and D; 1-16 byte elements, block compression, arrays, mip tails, 2D and 3D), each with addrlib's surface size, first tail mip and a hash of the address of every element. - deep_volumes_keep_their_chain_in_each_slabs_tail: a 16x16x64 volume whose chain is all in the tail (addrlib's mipChainInTail), with explicit addresses: each 16-slice slab has its own tail block, and mip 1's 32 slices span two of them. Over a wider sweep (about 20,000 descriptions, every mip count for volumes up to 256 deep) main matches addrlib exactly in size, tail and every address compared. A tail-entry rule that also requires a mip's depth to fit one slab changes 5,456 of 14,780 volume layouts (5,087 grow, by up to 5x) and moves their addresses; both tests fail with it. Co-Authored-By: Claude Opus 5.5 <[email protected]> (cherry picked from commit f078008b112343b6e68c8ca72b884073064320c1)
This commit is contained in:
1 parent
e394a216f9
commit
8780871ff7
1 file changed
+122
@@ -1183,6 +1183,128 @@ mod tests {
|
||||
assert_eq!(l.mips[0].offset, 8192 + 16384);
|
||||
}
|
||||
|
||||
/// A volume deeper than its block keeps its whole chain in the tail when
|
||||
/// every mip's width and height fit it (addrlib's `mipChainInTail`): each
|
||||
/// depth slab has its own tail block, holding that slab's slices of
|
||||
/// every mip. 16x16x64 in 64 KiB `S` blocks of 32x32x16 is four slabs
|
||||
/// of one block; mip 1's 32 slices span the first two. Addresses from
|
||||
/// addrlib, as in [`layouts_match_addrlib`].
|
||||
#[test]
|
||||
fn deep_volumes_keep_their_chain_in_each_slabs_tail() {
|
||||
let l = Layout::new(&Desc {
|
||||
dimension: Dimension::Tex3d,
|
||||
depth: 64,
|
||||
..desc(16, 16, 4, 4, Swizzle::SW_64KB_S)
|
||||
})
|
||||
.unwrap();
|
||||
assert_eq!(l.block, [32, 32, 16]);
|
||||
assert_eq!((l.first_tail_mip, l.size), (0, 4 * 65536));
|
||||
for (mip, x, y, z, address) in [
|
||||
(0, 0, 0, 0, 32768),
|
||||
(0, 0, 0, 15, 42128),
|
||||
(0, 0, 0, 16, 65536 + 32768),
|
||||
(0, 15, 15, 63, 3 * 65536 + 49148),
|
||||
(1, 0, 0, 0, 16384),
|
||||
(1, 0, 0, 16, 65536 + 16384),
|
||||
(1, 0, 0, 31, 65536 + 25744),
|
||||
(2, 0, 0, 0, 4096),
|
||||
(3, 1, 1, 7, 3740),
|
||||
] {
|
||||
let at = l.offset(mip, x, y, z);
|
||||
assert_eq!(at, Ok(address), "mip {mip} ({x},{y},{z})");
|
||||
}
|
||||
}
|
||||
|
||||
/// Layouts as AMD's addrlib computes them (Mesa `src/amd/addrlib` at ed09d38,
|
||||
/// `Addr2ComputeSurfaceInfo` and `Addr2ComputeSurfaceAddrFromCoord`,
|
||||
/// Navi 21 settings, no pipe-bank XOR): its surface size, its first mip
|
||||
/// in the tail (`mipChainInTail` is 0; linear has no tail) and an
|
||||
/// FNV-1a hash of the address of every element (mips in order, then
|
||||
/// slices, rows and columns; 8 little-endian bytes each). Element sizes
|
||||
/// 1-16 bytes, block compression, arrays, mip tails and deep volumes, in
|
||||
/// every mode [`Layout::offset`] addresses.
|
||||
#[test]
|
||||
fn layouts_match_addrlib() {
|
||||
use Dimension::{Tex1d, Tex2d, Tex3d};
|
||||
#[rustfmt::skip]
|
||||
let cases = [
|
||||
// mode, dimension, element bytes, texels per element side,
|
||||
// [width, height, depth or array], mips,
|
||||
// (size, first tail mip, hash)
|
||||
(Swizzle::SW_256B_S, Tex2d, 1, 1, [83, 31, 1], 6,
|
||||
(5120, 6, 0x435e_9cad_96ff_dd81)),
|
||||
(Swizzle::SW_256B_D, Tex2d, 16, 4, [109, 71, 1], 6,
|
||||
(13824, 6, 0xbc2b_b84f_c528_7cb3)),
|
||||
(Swizzle::SW_4KB_S, Tex2d, 8, 1, [250, 175, 1], 8,
|
||||
(495616, 4, 0x1e87_7240_4dcd_c56e)),
|
||||
(Swizzle::SW_4KB_S, Tex2d, 16, 1, [70, 70, 3], 4,
|
||||
(479232, 4, 0xf948_6d1d_511c_d75c)),
|
||||
(Swizzle::SW_4KB_D, Tex2d, 1, 1, [33, 17, 1], 6,
|
||||
(8192, 1, 0xaae1_0e3f_15a1_892e)),
|
||||
(Swizzle::SW_64KB_S, Tex2d, 2, 1, [40, 9, 1], 3,
|
||||
(65536, 0, 0xf7a3_7fe6_41c2_d565)),
|
||||
(Swizzle::SW_64KB_S, Tex2d, 4, 1, [100, 60, 6], 7,
|
||||
(786432, 1, 0xe6b7_50a0_b65e_09a3)),
|
||||
(Swizzle::SW_64KB_S, Tex2d, 8, 1, [65, 33, 1], 7,
|
||||
(131072, 1, 0xdf0a_7ddb_9b93_41ee)),
|
||||
(Swizzle::SW_64KB_D, Tex2d, 16, 4, [256, 256, 1], 9,
|
||||
(131072, 1, 0xe569_7630_03d8_3e28)),
|
||||
(Swizzle::SW_64KB_D, Tex2d, 4, 1, [100, 60, 1], 7,
|
||||
(131072, 1, 0xb1db_1641_adaf_77a6)),
|
||||
(Swizzle::SW_64KB_D, Tex2d, 1, 1, [255, 129, 2], 8,
|
||||
(262144, 1, 0xd706_42f5_9a01_5115)),
|
||||
(Swizzle::LINEAR, Tex2d, 4, 1, [30, 20, 1], 5,
|
||||
(10240, 5, 0x819a_9c12_81e6_40f2)),
|
||||
(Swizzle::LINEAR, Tex2d, 2, 1, [17, 9, 3], 5,
|
||||
(15360, 5, 0xbf1a_74f1_7803_df62)),
|
||||
(Swizzle::LINEAR, Tex1d, 4, 1, [1000, 1, 1], 10,
|
||||
(9216, 10, 0xd37e_f9ac_a5de_cab4)),
|
||||
(Swizzle::SW_4KB_S, Tex3d, 4, 1, [64, 32, 16], 7,
|
||||
(188416, 3, 0xf06b_d42a_7183_90e6)),
|
||||
(Swizzle::SW_4KB_S, Tex3d, 4, 1, [4, 4, 16], 5,
|
||||
(8192, 0, 0xbf87_001b_ad72_d375)),
|
||||
(Swizzle::SW_4KB_S, Tex3d, 1, 1, [1, 1, 17], 2,
|
||||
(8192, 0, 0xcdf4_4ee3_33e5_e03d)),
|
||||
(Swizzle::SW_64KB_S, Tex3d, 4, 1, [16, 16, 64], 4,
|
||||
(262144, 0, 0x5d1a_a7af_c371_e8e5)),
|
||||
(Swizzle::SW_64KB_S, Tex3d, 1, 1, [8, 8, 128], 4,
|
||||
(262144, 0, 0x8fec_f010_6542_6225)),
|
||||
(Swizzle::SW_64KB_S, Tex3d, 16, 1, [33, 17, 40], 6,
|
||||
(1966080, 3, 0xec9c_fd44_b89c_2fd5)),
|
||||
(Swizzle::LINEAR, Tex3d, 4, 1, [9, 7, 5], 3,
|
||||
(16640, 3, 0x6d5b_351d_4a3d_7b5a)),
|
||||
];
|
||||
for (swizzle, dimension, element_bytes, block, extent, mips, expected) in cases {
|
||||
let [width, height, depth] = extent;
|
||||
let d = Desc {
|
||||
dimension,
|
||||
width,
|
||||
height,
|
||||
depth,
|
||||
mips,
|
||||
element_bytes,
|
||||
block,
|
||||
samples: 1,
|
||||
swizzle,
|
||||
};
|
||||
let l = Layout::new(&d).unwrap();
|
||||
let mut h = 0xcbf2_9ce4_8422_2325u64;
|
||||
for (mip, m) in (0..).zip(&l.mips) {
|
||||
let slices = if dimension == Tex3d { m.depth } else { depth };
|
||||
for z in 0..slices {
|
||||
for y in 0..m.height {
|
||||
for x in 0..m.width {
|
||||
for byte in l.offset(mip, x, y, z).unwrap().to_le_bytes() {
|
||||
h = (h ^ u64::from(byte)).wrapping_mul(0x100_0000_01b3);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assert_eq!((l.size, l.first_tail_mip, h), expected, "{d:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn depth_stencil_is_two_planes() {
|
||||
let t = Texture::new(&TextureDesc {
|
||||
|
||||
Reference in new issue
Block a user