DDS File Layout for Textures
Microsoft DirectX 9.0 SDK Update (October 2004)

DDS File Layout for Textures


For simple uncompressed textures, the file should contain DDSD_PITCH and a DDPF_RGB pixel format surface. The pitch value should be DWORD-aligned. In this case, the main image should be (dwPitchOrLinearSize-by-dwHeight) bytes total.

If the file also contains mipmaps, the DDSD_MIPMAPCOUNT, DDSCAPS_MIPMAP, and DDSCAPS_COMPLEX flags should be set, and the dwMipMapCount field should contain the total number of levels defined in the file (for a 256-by-256 image, this field would be 9). The pitch for each mipmap-level image is computed from dwWidth and the pixel format, which is then DWORD-aligned. For example, a 256-by-256 main image, with a pixel format of R8G8B8 (three bytes per pixel) and all mipmap levels, would contain the following:

Texture Size/Type# Bytes
"DDS", 256x256, pitch=768, R8G8B8, 24 bits, mipmapcount = 9, (TEXTURE, PITCH, COMPLEX, MIPMAP, RGB)128
256-by-256 main image196608
128-by-128 mipmap image49152
64-by-64 mipmap image12288
32-by-32 mipmap image3072
16-by-16 mipmap image768
8-by-8 mipmap image192
4-by-4 mipmap image48
2-by-2 mipmap image12
1-by-1 mipmap image4

For simple compressed textures, the file should contain DDSD_LINEARSIZE and a DDPF_FOURCC pixel format surface. In this case, the image should be dwPitchOrLinearSize bytes total. If the file contains mipmaps, the DDSD_MIPMAPCOUNT, DDSCAPS_COMPLEX, DDSCAPS_MIPMAP, and dwMipMapCount fields should be set.

For DXTn compressed formats, the size of each mipmap level image is one-fourth the size of the previous, with a minimum of 8 (DXT1) or 16 (DXT2-5) bytes (this is true only for square textures). For example, a 256-by-256 main image, with a pixel format of DXT1 and all mipmap levels, would contain the following:

Texture Size/Type# Bytes
DDS, 256x256, linearsize = 32768, 128 bytes DXT1, mipmapcount = 9, (TEXTURE, LINEARSIZE, COMPLEX, MIPMAP, FOURCC)128
256-by-256 main image32768
128-by-128 mipmap image8192
64-by-64 mipmap image2048
32-by-32 mipmap image512
16-by-16 mipmap image128
8-by-8 mipmap image32
4-by-4 mipmap image8
2-by-2 mipmap image8
1-by-1 mipmap image8

If mipmaps are generated, all levels down to 1-by-1 are usually written. Some tools may not support partial mipmap chains.

When computing DXTn compressed sizes for non-square textures, the following formula should be used at each mipmap level:

          max(1, width ÷ 4) x max(1, height ÷ 4) x 8(DXT1) or 16(DXT2-5)

A 256-by-64 main image, with a pixel format of DXT1 and all mipmap levels, would contain the following:

Texture Size/Type# Bytes
"DDS ", 256x64, linearsize = 8192, DXT1, mipmapcount = 9, (TEXTURE, LINEARSIZE, COMPLEX, MIPMAP, FOURCC)128 bytes
256-by-64 main image8192
128-by-32 mipmap image2048
64-by-16 mipmap image512
32-by-8 mipmap image128
16-by-4 mipmap image32
8-by-2 mipmap image16
4-by-1 mipmap image8
2-by-1 mipmap image8
1-by-1 mipmap image8


© 2004 Microsoft Corporation. All rights reserved.
Feedback? Please provide us with your comments on this topic.
For more help, visit the DirectX Developer Center.