Expand description

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;

// 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.

Modules

Documentation for the C API.

Functions for working with surfaces stored in a combined buffer for all array layers and mipmaps.

Functions for swizzling and deswizzling a single mipmap of a surface.

Enums

An enumeration of supported block heights.

Errors than can occur while swizzling or deswizzling.

Functions

Calculates the block height parameter to use for the first mip level if no block height is specified.

Calculates the division of x by d but rounds up rather than truncating.

Calculates the block height parameter for the given mip level.