Programming Guide

Programming Guide

This page is intended to contain more higher-level explanation of concepts and features provided by the 3DS GPU. For more detailed register-level information check GPU/Internal Registers.

Geometry Pipeline #

Fixed Vertex Attributes #

If a certain vertex attribute is constant for the duration of a draw call, instead of specifying a vertex array with repeated contents or changing the shader to use a uniform, fixed vertex attributes can be used. They let you specify a fixed value, which will be assumed by the attribute for all vertices of the batch.

To use a fixed attribute, set the bit corresponding to the attribute in GPUREG_ATTRIBBUFFERS_FORMAT_HIGH and ensure that no vertex arrays are configured for the attribute. (Any configured arrays will override the fixed value, regardless of the bit setting.) Even if a vertex array isn’t being used for the attribute it still needs to be counted in the number of active attributes specified in the same register.

To specify the actual value of the fixed attribute, write the attribute index to GPUREG_FIXEDATTRIB_INDEX followed by writes with packed a float24 4-tuple to the 3 GPUREG_FIXEDATTRIB_DATA registers. The value is always specified as a float 4-component vector, the configured type is ignored.

Immediate-Mode Vertex Submission #

Instead of using vertex arrays to supply vertex data, drawing can be done by directly writing vertex data to a register. This allows vertex data to be inlined directly in the command buffer. Since this is restricted to 4-component float data, it is more useful for small draws like UI elements or debug displays, to avoid using an unreasonable amount of memory and processing time appending the vertices to the command buffer.

To use this feature, configure the number of attributes per vertex in GPUREG_VSH_NUM_ATTR. (All settings in the registers related to the vertex loader are ignored.) Then setup the GPU and shaders the same as if doing a regular draw call with GPUREG_DRAWARRAYS or GPUREG_DRAWELEMENTS, but instead of writing to either register, write the value 0xF to GPUREG_FIXEDATTRIB_INDEX and then follow by repeatedly writing vertex data to GPUREG_FIXEDATTRIB_DATA.

Each set of writes to the 3 data registers specifies one attribute and all attributes (as configured in GPUREG_VSH_NUM_ATTR) need to be written, in order, to specify a vertex. Drawing happens automatically as vertices are specified. After finishing specifying vertices, follow with the same writes used after a draw arrays/elements.

When drawing using triangle strips or fans, GPUREG_RESTART_PRIMITIVE should be used to end the previous strip before (or while) drawing.

Drawing elements #

The 3DS GPU is capable of drawing vertex + index arrays, triggered by GPUREG_DRAWELEMENTS. A set of commands commonly used by the standard GL implementation to accomplish this is as follows:

Command IndexRegisterDescription
0GPUREG_GEOSTAGE_CONFIGSet whether drawing triangle elements
1-2GPUREG_GEOSTAGE_CONFIG2Set whether drawing triangle elements
3GPUREG_PRIMITIVE_CONFIGSet primitive mode
4GPUREG_PRIMITIVE_CONFIGSet number of output map registers
5GPUREG_RESTART_PRIMITIVETrigger reset
6GPUREG_GEOSTAGE_CONFIG2Set function indicator to 0
7GPUREG_INDEXBUFFER_CONFIGSet offset and type
8GPUREG_NUMVERTICESSet vertex count
9GPUREG_START_DRAW_FUNC0Set mode to drawing
10GPUREG_DRAWELEMENTSTrigger draw
11GPUREG_START_DRAW_FUNC0Set mode to configuration
12GPUREG_VTX_FUNCTrigger post-vertex cache clear
13GPUREG_FRAMEBUFFER_FLUSHFlush framebuffer
14GPUREG_GEOSTAGE_CONFIGClear drawing triangle elements
15GPUREG_GEOSTAGE_CONFIG2Clear drawing triangle elements
16GPUREG_PRIMITIVE_CONFIGClear primitive mode
17GPUREG_VSH_ENTRYPOINTClear entry point

Category:GPU