GFD > Texture / Shader (Gfx2)

This file contains textures or shaders and usually has the filename extension 'gtx' or 'gsh'. The file starts with a header, which is followed by one or more blocks. A special block type indicates the end of the file.

The file format is closely tied to the GX2 framework, which is the graphics library of the Wii U.

File Header

OffsetSizeDescription
0x04Magic number (Gfx2)
0x44Header size (always 0x20)
0x84Major version (should be 7)
0xC4Minor version (should be 1)
0x104GPU version (should be 2)
0x144Alignment mode (0 or 1). If enabled, padding blocks are added to align shader and texture data.
0x188Padding

Block

OffsetSizeDescription
0x04Magic number (BLK{)
0x44Header size (always 0x20)
0x84Major version (should be 1)
0xC4Minor version (should be 0)
0x104Block type
0x144Data size
0x188Padding
0x20Data

Block Types

ValueType
1End of file
2Padding (for alignment)
3Vertex shader header
5Vertex shader program
6Pixel shader header
7Pixel shader program
8Geometry shader header
9Geometry shader program
10Geometry shader copy program
11Texture header
12Texture image data
13Texture mipmap data

Texture Blocks

The texture header block contains a GX2Texture structure. The image and mipmap data blocks contain raw texture data, and are stored immediately behind the texture header block that they belong to. The mipmap block is optional.

Shader Blocks

The shader program blocks contain raw shader data and are stored immediately behind the shader header block that they belong to.

The shader header block is a bit complicated. In essence, it contains a GX2VertexShader, GX2PixelShader or GX2GeometryShader structure (depending on the block type). However, these structure contain several pointers, and, for obvious reasons, it is impossible to store raw pointers in a file.

The shader header block is layed out as follows:

Each pointer in a structure is stored as 0xAAABBBBB, where AAA is a tag that specifies the type of offset, and BBBBB is the actual offset (relative to the start of the shader header block body).

The following tags are used:

TagDescription
0xCA7String
0xD06Data

Relocation Info

The relocation info is always stored at the end of the shader header block and makes it possible to convert offsets to pointers without knowing anything about the shader structures.

OffsetSizeDescription
0x04Magic number (}BLK)
0x44Size (always 0x28)
0x84Always 0
0xC4Total size of shader structures and string table
0x104Data pointer to shader structures and string table
0x144Size of string table
0x184Data pointer to string table
0x1C4Must be 0 (updated at runtime)
0x204Number of relocations
0x244Data pointer to relocation table

Relocation Table

The relocation table tells the loader which fields are offsets that need fixing. It contains a list of offsets (with tag) that point to the offsets that should be relocated.