#cpu #unofficial #swizzling #x1

tegra_swizzle

Unofficial CPU implementation for Tegra X1 swizzling

3 releases (breaking)

0.3.0 Jul 25, 2022
0.2.0 Feb 3, 2022
0.1.0 Nov 17, 2021

#476 in Rust patterns

36 downloads per month
Used in nutexb

MIT license

95KB
2K SLoC

tegra_swizzle

tegra_swizzle is an unofficial CPU implementation for Tegra X1 surface swizzling. The library provides functions for converting between the Tegra X1's optimized memory layout and standard row-major ordering.

C FFI

See the ffi module in the docs for documentation.


lib.rs:

tegra_swizzle

tegra_swizzle is an unofficial CPU implementation for Tegra X1 surface swizzling.

Getting Started

Swizzled texture data is often stored in a single buffer containing all arrays and mipmaps. This memory layout can be deswizzled all at once using [surface::deswizzle_surface].

use tegra_swizzle::surface::{BlockDim, deswizzle_surface};
use std::num::NonZeroUsize;
# let swizzled_surface = vec![0u8; 10];

// 16x16 BC7 cube map with 5 mipmaps.
let surface = deswizzle_surface(
16,
16,
1,
&swizzled_surface,
BlockDim::block_4x4(),
None,
16,
5,
6,
);

// 128x128 R8G8B8A8 2D texture with no mipmaps.
let surface = deswizzle_surface(
128,
128,
1,
&swizzled_surface,
BlockDim::uncompressed(),
None,
4,
1,
1,
);

// 16x16x16 R8G8B8A8 3D texture with no mipmaps.
let surface = deswizzle_surface(
16,
16,
16,
&swizzled_surface,
BlockDim::uncompressed(),
None,
4,
1,
1,
);

Block Linear Swizzling

The [surface::swizzle_surface] and [surface::deswizzle_surface] functions implement safe and efficient swizzling for the Tegra X1's block linear format.

Block linear arranges bytes of a texture surface into a 2D grid of blocks where blocks are arranged linearly in row-major order. The swizzled surface size is padded to integral dimensions in blocks, so swizzled surfaces may be larger than the corresponding data in row-major order.

Groups of 512 bytes form GOBs ("group of bytes") where each GOB is 64x8 bytes. The block_height parameter determines how many GOBs stack vertically to form a block.

Limitations

Array layer counts other than 1 or 6 and 3D textures with depth values other than 16 are not well tested, so swizzling may not work as intended. These limitations should hopefully be fixed in a future release.

Dependencies

~115KB