Difference between revisions of "GTX\GSH (File Format)"

From MK8
Jump to navigation Jump to search
Line 147: Line 147:
  
 
{| class="wikitable"
 
{| class="wikitable"
! Offset
+
! Offset !! Size !! Description
! Size
 
! Description
 
 
|-
 
|-
| 0x00
+
| 0x00 || 4 || '''Dimension'''. Maps to '''GX2SurfaceDim''' (line 849 [http://pastebin.com/DCrP1w9x here]). Indicates the "shape" of a given surface or texture.
| 4
 
| '''Dimension'''. Indicates the "shape" of a given surface or texture (see line 849 [http://pastebin.com/DCrP1w9x here]).
 
 
|-
 
|-
| 0x04
+
| 0x04 || 4 || '''Texture width'''. Width of the texture in pixels.
| 4
 
| '''Texture Width'''. Width of the texture in pixels.
 
 
|-
 
|-
| 0x08
+
| 0x08 || 4 || '''Texture height'''. Height of the texture in pixels.
| 4
 
| '''Texture Height'''. Height of the texture in pixels.
 
 
|-
 
|-
| 0x0C
+
| 0x0C || 4 || '''Depth'''.
| 4
 
| '''Depth'''.
 
 
|-
 
|-
| 0x10
+
| 0x10 || 4 || '''Number of mipmaps'''.
| 4
 
| '''Number of Mipmaps'''.
 
 
|-
 
|-
| 0x14
+
| 0x14 || 4 || '''Texture format'''. Maps to '''GX2SurfaceFormat''' (line 589 [http://pastebin.com/DCrP1w9x here] for explanation and format values).
| 4
 
| '''Texture Format'''. Go to line 589 on [http://pastebin.com/DCrP1w9x this page] for explanation and format values.
 
 
|-
 
|-
| 0x18
+
| 0x18 || 4 || '''AA mode'''. Maps to '''GX2AAMode''' (line 865 [http://pastebin.com/DCrP1w9x here]). Indicates the AA mode (number of samples) for the surface.
| 4
 
| '''AA Mode'''. Indicates the AA mode (number of samples) for the surface (see line 865 [http://pastebin.com/DCrP1w9x here]).
 
 
|-
 
|-
| 0x1C
+
| 0x1C || 4 || '''Usage'''. Maps to '''GX2SurfaceUse''' (line 823 [http://pastebin.com/DCrP1w9x here]). Indicates how the given surface may be used.
| 4
 
| '''Usage'''. Indicates how the given surface may be used (see line 823 [http://pastebin.com/DCrP1w9x here]).
 
 
|-
 
|-
| 0x20
+
| 0x20 || 4 || '''Data length'''. Length of texture data in bytes.
| 4
 
| '''Data Length'''. Length of texture data in bytes.
 
 
|-
 
|-
| 0x24
+
| 0x24 || 4 || '''Data pointer'''. Set at runtime.
| 4
 
| '''Data Pointer?'''
 
 
|-
 
|-
| 0x28
+
| 0x28 || 4 || '''Mipmaps data length'''. Length of mipmaps data in bytes.
| 4
 
| '''Mipmaps Data Length'''. Length of mipmaps data in bytes.
 
 
|-
 
|-
| 0x2C
+
| 0x2C || 4 || '''Mipmaps pointer'''. Set at runtime.
| 4
 
| '''Mipmaps Pointer?'''
 
 
|-
 
|-
| 0x30
+
| 0x30 || 4 || '''Tile mode'''. Maps to '''GX2TileMode''' (line 795 [http://pastebin.com/DCrP1w9x here]). Indicates the desired tiling mode for the surface.
| 4
 
| '''Tile Mode'''. Indicates the desired tiling mode for the surface (see line 795 [http://pastebin.com/DCrP1w9x here]).
 
 
|-
 
|-
| 0x34
+
| 0x34 || 4 || '''Swizzle value'''.
| 4
 
| '''Swizzle Value'''.
 
 
|-
 
|-
| 0x38
+
| 0x38 || 4 || '''Alignment'''. Always 512 * bytes per pixel.
| 4
 
| '''Alignment'''. Always 512 * bytes per pixel.
 
 
|-
 
|-
| 0x3C
+
| 0x3C || 4 || '''Pitch'''.
| 4
 
| '''Pitch'''.
 
 
|-
 
|-
| 0x40
+
| 0x40 || 0x38 || '''Mipmap offsets'''. An array of 13 offsets for each mipmap, relative to the start of the mipmap data.
| 0x38
 
| '''Mip Offset'''. Offset for each mipmap
 
 
|-
 
|-
| 0x78
+
| 0x78 || 4 || '''Number of mipmaps''' (again).
| 4
 
| '''Number of Mipmaps'''. Again...
 
 
|-
 
|-
| 0x7C
+
| 0x7C || 4 || '''First slice'''. Always 0.
| 4
 
| Unknown. Always 0.
 
 
|-
 
|-
| 0x80
+
| 0x80 || 4 || '''Number of slices'''. Always 1.
| 4
 
| Unknown. Always 1.
 
 
|-
 
|-
| 0x84
+
| 0x84 || 4 || '''GX2CompSel'''.
| 4
 
| Unknown. Always 0x00010203. (Is this some kind of a pattern? 00->01->02->03)
 
 
|-
 
|-
| 0x88
+
| 0x88 || 0x14 || '''Texture registers'''. Array of 5 unsigned integers with unknown purpose.
| 0x14
 
| Unknown.
 
 
|}
 
|}
  

Revision as of 19:08, 2 June 2017

GTX and GSH files are used in various Wii U games, including Mario Kart 8. GSH stands for GX2 SHader and GTX stands for GX2 TeXture.

Header

Every GTX/GSH file begins with an 0x20 byte Gfx2 header.

Offset Size Description
0x00 4 "Gfx2" File identifier, ASCII string.
0x04 4 Size of header in bytes. Must be the real size (0x20), or header (and hence file) is unreadable.
0x08 4 Major version number. Must be 0x07, or header is unreadable.
0x0C 4 Minor version number. Must be 0x01.
0x10 4 GPU version for which this file is designed for.
0x14 4 Align mode.
0x18 4 Reserved, Always 0x00.
0x1C 4 Reserved, Always 0x00.
0x20 End of Gfx2 header.

Data Blocks

After the header comes some data blocks, data blocks contain a 0x20 byte BLK{ block header followed by data specified by the block type.

Block Header

Offset Size Description
0x00 4 "BLK{" Header of the block, ASCII string.
0x04 4 Size of block header in bytes.
0x08 4 Major version number. Must be 0x01 or header is unreadable.
0x0C 4 Minor version number. Must be 0x00.
0x10 4 Block type, it determines the type of the following data.
0x14 4 Size of the following data. In bytes, always 0x9C if the block type is 0x0B.
0x18 4 A unique identifier for this block, allowing it to be referenced by other blocks
0x1C 4 An incrementing index for each instance of a given type.

Block types

Type Description
0x00 Not actually a valid Block type.
0x01 Follows this block header the end of the file.
0x02 Follows this block header padding. (Used to align following data)
0x03 Follows this block header Vertex shader header.
0x05 Follows this block header Vertex shader program.
0x06 Follows this block header Pixel shader header.
0x07 Follows this block header Pixel shader program.
0x08 Follows this block header Geometry shader header.
0x09 Follows this block header Geometry shader program.
0x0A Same as 0x09? (Duplicate?)
0x0B Follows this block header the Image header.
0x0C Follows this block header the swizzled image data.
0x0D Follows this block header the swizzled mipmaps data.
0x0E Follows this block header Compute shader header.
0x0F Follows this block header Compute shader program.
0x10 Treated like a 0x02 block, users can do what they want with this block.

Image info

The image info directly follows the block header that has a block type 0x0B, and should exactly have a size of 0x9C:

Offset Size Description
0x00 4 Dimension. Maps to GX2SurfaceDim (line 849 here). Indicates the "shape" of a given surface or texture.
0x04 4 Texture width. Width of the texture in pixels.
0x08 4 Texture height. Height of the texture in pixels.
0x0C 4 Depth.
0x10 4 Number of mipmaps.
0x14 4 Texture format. Maps to GX2SurfaceFormat (line 589 here for explanation and format values).
0x18 4 AA mode. Maps to GX2AAMode (line 865 here). Indicates the AA mode (number of samples) for the surface.
0x1C 4 Usage. Maps to GX2SurfaceUse (line 823 here). Indicates how the given surface may be used.
0x20 4 Data length. Length of texture data in bytes.
0x24 4 Data pointer. Set at runtime.
0x28 4 Mipmaps data length. Length of mipmaps data in bytes.
0x2C 4 Mipmaps pointer. Set at runtime.
0x30 4 Tile mode. Maps to GX2TileMode (line 795 here). Indicates the desired tiling mode for the surface.
0x34 4 Swizzle value.
0x38 4 Alignment. Always 512 * bytes per pixel.
0x3C 4 Pitch.
0x40 0x38 Mipmap offsets. An array of 13 offsets for each mipmap, relative to the start of the mipmap data.
0x78 4 Number of mipmaps (again).
0x7C 4 First slice. Always 0.
0x80 4 Number of slices. Always 1.
0x84 4 GX2CompSel.
0x88 0x14 Texture registers. Array of 5 unsigned integers with unknown purpose.

Swizzling

This code can swizzle image and mipmap data. Call swizzle() by giving it the width, height, format (in hex), tileMode, swizzle value, pitch and the swizzled data. If you're swizzling then set do_swizzle to True. If you're deswizzling then set do_swizzle to False.

Tools

The following tools can handle GTX/GSH files: