GPU/Commands

< GPU
Revision as of 05:34, 24 February 2013 by Yellows8 (talk | contribs)

This page describes the structure of the buffer for GX command 1 with the registers at 0x1EF018E0. This buffer is used for GPU commands including OpenGL commands, each 8-byte entry in the buffer is a command. Cmd+0 is the command parameter, and cmd+4 is the command header.

Invalid GPU command parameters can cause the GPU to hang, this then causes the GSP module to hang as well.

Command Header

Bit Description
19-0 Command ID
30-20 Total words following the command, if any.
31 ?

The first word in the parameter data structure is the command parameter value, the rest of the data structure is from the data following the command. The word after the last data structure word is padding when needed for 8-byte alignment, for the following command.

Commands

CommandID Parameter Description
0x000F0010 Value is 0x12345678 This command is always the last command in the buffer.
0x000F0110 Value 0x1 This command is immediately before CmdID 0x000F0010, this is also used elsewhere for beginning rendering of object(s) as well.
0x000F0111 Value 0x1 This command is immediately before CmdID 0x000F0110, however CmdID 0x000F0110 doesn't always follow this command.
0x000F0040 u32, valid values are 0x1 and 0x2, values 0x0 and 0x3 have the same effect as value 0x2. Only bits 1-0 are used. Value 2 = GL_FRONT/GL_CW or GL_BACK/GL_CCW. Value 1 = GL_FRONT/GL_CCW or GL_BACK/GL_CW.
0x000F0041 float This is used to initialize the projection matrix?
0x000F0042 float This is used immediately after CmdID 0x000F0043, for the third parameter for CmdID 0x000F0041.
0x000F0043 float This is used immediately after CmdID 0x000F0041, for the second parameter.
0x000F0044 float This is used immediately after CmdID 0x000F0042, for the fourth parameter for CmdID 0x000F0041.
0x801F004D First word in parameter structure ?
0x0002025E u32, val<<8. This sets the GL rendering mode.
0x000F0068 u32 This is used immediately after CmdID 0x000F0044.
0x000F006E u32 This is used immediately after CmdID 0x000F011E, with the same input parameter value as CmdID 0x000F011E.
0x809F0081 This is used to set the current texture info used for rendering.
0x000F008E u32 color type This command is used immediately after CmdID 0x809F0081, for specifying the texture color type.
0x00020100 u32, value is 0x00E40100 This command is used immediately before CmdID 0x000F0101.
0x000F0101 u32 Color related?
0x00010107 See command set CmdID 0x00010107.
0x00020107 See command set CmdID 0x00010107.
0x00030107 See command set CmdID 0x00030107.
0x000F0116 u32 Unknown, this is used immediately after CmdID 0x000F011D.
0x000F0117 u32 Unknown, normally the input parameter is value 0x2.
0x000F011C Physical address>>3 Normally this address is located in VRAM. This command is used immediately after 0x000F0116.
0x000F011D Physical address>>3 This initializes the framebuffer address used for rendering, this framebuffer is used for the input framebuffer with GX command 3 and 4. This command is used immediately after CmdID 0x000F0117.
0x000F011E u32 This sets the width and height for the framebuffer used for rendering. Therefore this is glViewport() with x=0 and y=0. This is used immediately after CmdID 0x000F011C.
0x826F0200 See command set 0x826F0200.
0x00080126 See command set CmdID 0x00030107.
0x000F0227 u32 This specifies the address of an array containing vertex array indices, and the data-type of the indices, used for rendering primitives.
0x000F0228 u32 total elements in the array to use for rendering. This command is used immediately after CmdID 0x000F0227.
0x803F0232 See command set 0x826F0200.
0x000F02B0 u32, value is 0x7FFF0000 | val. Texture related?
0x801F02BB See command set 0x826F0200.
0x000F02C0 0x80000000 | Type This is used immediately before CmdID 0xXXXF02C1. This type field controls the command parameter buffer type.
0xXXXF02C1 First word in the first entry A list of entries follow this command.

Command Sets

glDrawElements()
Command Index CommandID Parameter Description
0 0x00020229 u32, val<<8. Unknown, val is 0 or 1.
1-2 0x00020253 Same as CmdID 0x00020229. Unknown
3 0x0002025E u32, val<<8. This sets the GL rendering mode.
4 0x0004025E Value 0 ?
5 0x000F025F Value 1 ?
6 0x00010253 Value 0 ?
7 0x000F0227 u32 This specifies the indices data-type, and the indices array address.
8 0x000F0228 u32 This specifies the number of elements in the array to use for rendering.
9 0x00010245 Value 0 ?
10 0x000F022F Value 1 ?
11 0x00010245 Value 1 ?
12 0x000F0231 Value 1 ?
13 0x000F0111 Value 1 ?
14 0x00020229 Value 0 ?
15 0x00020253 Value 0 ?
16 0x0002025E Value 0 ?
17 0x000C02BA Value 0x7FFF0000 ?
CmdID 0x826F0200
Command Index CommandID Parameter Description
0 0x826F0200 This sets the addresses for the GL arrays.
1 0x801F02BB ?
2 0x803F0232 Unknown, this command is used multiple times for specifying each parameter-buffer entry.
CmdID 0x00030107
Command Index CommandID Parameter Description
0 0x00030107 glAlphaFunc() parameters.
1 0x00080126 type<<24

This command set is used for disabling alpha testing, and for glAlphaFunc(). The GL AlphaFunction used here is normally GL_ALWAYS.

CmdID 0x00010107
Command Index CommandID Parameter Description
0 0x00010107 Same format as CmdID 0x00030107.
1 0x00080126 type<<24
0 0x00020107 Same value as CmdID 0x00030107.

This is used for glAlphaFunc().

Parameter format for CmdIDs 0x00030107, 0x00020107, and 0x00010107

Bit Description
0 0 = disable GL_ALPHA_TEST, 1 = enable GL_ALPHA_TEST.
3-1 Unused?
7-4 Alpha function
11-8 ?
12 ?
31-13 Unused

Alpha function values

Value GL AlphaFunction
0 GL_NEVER
1 GL_ALWAYS
2 GL_EQUAL
3 GL_NOTEQUAL
4 GL_LESS
5 GL_LEQUAL
6 GL_GREATER
7 GL_GEQUAL

Alpha types for CmdID 0x00080126

Type GL AlphaFunction
0 GL_NEVER
1 GL_ALWAYS
2 GL_GREATER/GL_GEQUAL
3 The remaining GL alpha functions.

GL mode values for CmdID 0x0002025E

Value Description
0 ?
1 GL_TRIANGLE_STRIP
2 GL_TRIANGLE_FAN
3 GL_TRIANGLES
4 Unknown, this seems to have the same effect as value 0.

Parameter value format for CmdID 0x000F0227

Bit Description
30-0 Indices array address, relative to VRAM physical address 0x18000000. Thus, when this relative address is 0x08XXXXXX, the array is located in FCRAM.
31 1 = indices data-type GL_UNSIGNED_SHORT, 0 = GL_UNSIGNED_BYTE.

Parameter value format for CmdID 0x000F011E

Bit Description
11-0 Framebuffer width
23-12 Framebuffer height - 1
24 Must be set
31-25 Unused?

Normally the width and height is set to the same dimensions used with GX command 3 and 4.

Texture info parameter structure for CmdID 0x809F0081

Index Word Description
0 ?
1 The low u16 is the texture image width, and the high u16 is the texture image height.
2 Texture parameters, initialized by glTexParameter().
3 ?
4 Texture data physical address >> 3. This is normally located in VRAM.
5-9 ?

Texture parameters

Bit Description GL parameter name
0 Normally this is value 0.
1 0 = GL_NEAREST, 1 = GL_LINEAR. GL_TEXTURE_MAG_FILTER
2 1 = GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, or GL_LINEAR_MIPMAP_LINEAR. Value zero otherwise. GL_TEXTURE_MIN_FILTER
3 Unused? ?
7-4 2 = texture color type 0xC, 0 otherwise.(Enable/disable texture data compression?)
11-8 0 = GL_CLAMP_TO_EDGE, 1=unknown, 2=GL_REPEAT, 3=unknown. GL_TEXTURE_WRAP_S
15-12 Same values as GL_TEXTURE_WRAP_S. GL_TEXTURE_WRAP_T
24 1 = GL_NEAREST_MIPMAP_LINEAR, or GL_LINEAR_MIPMAP_LINEAR. Value zero otherwise. GL_TEXTURE_MIN_FILTER
27-25 Unused?
30-28 When some flag=1: value1=GL_TEXTURE_2D, value0 when the input parameter is not GL_TEXTURE_2D. When some flag=0: 0=GL_TEXTURE_2D, 1-4=unknown. ?
31 Unused? ?

Texture color type parameter values for CmdID 0x000F008E

Value Description GL Format GL Data Type
0x0 RGBA8888 GL_RGBA GL_UNSIGNED_BYTE
0x1 RGB888 GL_RGB GL_UNSIGNED_BYTE
0x2 RGBA5551 GL_RGBA GL_UNSIGNED_SHORT_5_5_5_1
0x3 RGB565 GL_RGB GL_UNSIGNED_SHORT_5_6_5
0x4 RGBA4444 GL_RGBA GL_UNSIGNED_SHORT_4_4_4_4
0x5 GL_LUMINANCE_ALPHA GL_UNSIGNED_BYTE
0x6 ? ? GL_UNSIGNED_BYTE
0x7 GL_LUMINANCE GL_UNSIGNED_BYTE
0x8 GL_ALPHA GL_UNSIGNED_BYTE
0x9 ? GL_LUMINANCE_ALPHA ?
0xA ? GL_LUMINANCE
0xB ? GL_ALPHA
0xC Compression related? ?
0xD ? ?

Parameter structure for CmdID 0x826F0200

Index Word Description
0x0 Base physical address >> 3, normally located in VRAM.
0x1 Physical address, relative to the base address. When writing each entry: value |= entval << (index * 4).
0x2 Value is: (0xF0000000 + (val<<28)) | (((0xFF<<totalentries) & 0xFF)<<16).
0x3-0x26 12 entries, each entry is 3 words.

Entry structure

Index Word Description
0 Physical address, relative to the base address.
1 Entry index
2 Value is: 0x10000000 | (arraytype<<16).

When the entry is unused, the entry data is all-zero.

Entry array types
Type Description
0x2 ?
0x3 Normals array
0x4 Texture coordinates array
0xC Vertex array

Parameter structure for CmdID 0x801F02BB

Index Word Description
0-1 u64, every 4-bits is a value from some array.

Parameter structure for CmdID 0x803F0232

Index Word Description
0 Entry index + total CmdID 0x826F0200 parameter-buffer entries.
1 ?
2 ?
3 ?

Each parameter buffer for CmdID 0x803F0232 is an entry loaded from an array.

Entries for CmdID 0xXXXF02C1

Index Word Description
0 float
1 float
2 float

Color Entry

Index Word Description
0 float Red component
1 float Blue component
2 float Green component
3 float Alpha?
4 float
5 float

Vertex Entry

Index Word Description
0 float X coordinate
1 float Y coordinate
2 float Z coordinate

Type 0x14 is used for specifying vertices, however the vertex array can be used for specifying vertices as well.

Types for CmdID 0x000F02C0

Value Entries per chunk Description
0x00 4 Related to model-view matrix translation?
0x04 4 Unknown, this is used immediately after type 0x00.
0x08 One color entry via two CmdID 0xXXXF02C1 entries. Sets the color.
0x0A 4 Texture coordinates
0x0B 3 ?
0x0C, 0x0D 3 Related to type 0x0A?
0x0E 4 Related to type 0x0A?
0x14 <=30 Geometry vertices
0x4C 4 ?
0x50, 0x53, and 0x56 1 ?
0x51, 0x54, and 0x57 1 ?
0x52, 0x55, and 0x58 1 ?
0x59 1 Unknown, the entry data is floats converted from s32s.
0x5A 2 Color related?
0x5C 1 ?