Hacker News front pageAgentlien12 min readintermediate
Anatomy of a Texture
Summary
A practical deep‑dive into modern texture memory layout: block‑compression (BC7), swizzle ordering (Morton/Z‑order), mip‑map hierarchies, and concrete debugging tricks for cross‑platform texture conversion.
- BC7 stores texels in 4×4 blocks (16 bytes per block), turning a 32‑bit RGBA texel into ~1 byte and improving cache locality.
- Swizzle patterns (e.g., Morton/Z‑order) reorder texels to keep spatially adjacent texels close in memory; different platforms may use different swizzles, requiring full re‑ordering on conversion.
- Mip‑maps are a hierarchy of down‑sampled textures (each level half the width/height) that must be laid out and addressed correctly for each level.
- Debugging compressed textures is hard; replace each 16‑byte block with known 32‑bit values (e.g., coordinates) or all‑zero blocks to create visual markers that survive compression.
Incorrect address calculations or swizzle mismatches produce garbled textures that are hard to diagnose, especially when dealing with compressed formats that hide raw data. Understanding the layout lets engineers write reliable cross‑platform asset pipelines and faster debugging tools.
6/10

