13.8 Texture Memory

UP

13.8.1 Memory Organization

Because texturing requires a large amount of random accesses with consistent access time to texture memory, it is impractical to texture directly from DRAM. The approach taken by the Nintendo 64 system is to cache up to 4 KB of an image in an on-chip, high-speed texture memory called TMEM. All primitives are textured using the contents of TMEM. The basic sequence of events needed to texture a primitive is:

  1. Load a texture tile into TMEM.

  2. Describe attributes of the texture tile.

  3. Render primitives that use this tile.

TMEM should indeed be considered a cache from the programmer's point of view. Since each tile must be loaded from DRAM, it makes sense to render as many primitives as possible, using the current tile before loading the next one in order to conserve DRAM bandwidth.

Physically, TMEM is arranged as shown in Figure 13-9. L0-3 are referred to as the low half of TMEM, H0-3 are referred to as the high half of TMEM.

Figure 13-9 Physical TMEM Diagram
[Figure 13-9]

For loading, TMEM is arranged logically, as shown in Figure 13-10.

Figure 13-10 TMEM Loading
[Figure 13-10]

The following table shows the maximum tile sizes that can be stored in the 4KB Texture Memory. Images larger than this will be tiled.

Table 13-8 Maximum tile sizes in TMEM
Texel Type Maximum Texel Count
4-bit(I,IA) 8K
4-bit Color Index 4K(plus 16 palettes)
8-bit(I,IA) 4K
8-bit Color Index 2K(plus 256-entry LUT)
16-bit RGBA 2K
16-bit IA 2K
16-bit YUV 2K Y's, 1K UV pairs
32-bit RGBA 1K

Four-bit textures are stored in TMEM, as shown in Figure 13-11.

Figure 13-11 Four-Bit Texel Layout in TMEM
[Figure 13-11]

Eight-bit textures are stored in TMEM, as shown in Figure 13-12.

Figure 13-12 Eight-Bit Texel Layout in TMEM
[Figure 13-12]

Sixteen-bit textures (except YUV) are stored in TMEM, as shown in Figure 13-13.

Figure 13-13 Sixteen-Bit Texel Layout in TMEM
[Figure 13-13]

Sixteen-bit YUV textures are stored in TMEM, as shown in Figure 13-14. Note that YUV texels must be loaded in pairs. In other words two Y's at a time. Also note that if filtering is enabled, an additional UYVY pair must be loaded per row and SH set accordingly to allow proper filtering of the last UV texel per row.

Figure 13-14 YUV Texel Layout in TMEM
[Figure 13-14]

Thirty-two bit (RGBA) textures are stored in TMEM, as shown in Figure 13-15.

Figure 13-15 Thirty-Two Bit RGBA Texel Layout in TMEM
[Figure 13-15]

For color index (CI) textures, the texture is stored in the lower half of TMEM, and the Texture/Color Look-Up Table (TLUT) is stored in the upper half of TMEM. For 4-bit CI textures, the texels (or indices) addressed in the lower half of TMEM have the 4-bit palette number for the tile prepended to create an 8-bit address into the upper half of TMEM. Since four texels are addressed simultaneously, there must be four (usually identical) TLUTs stored in the upper half of TMEM across the four banks.

For 4-bit CI textures, the palette effectively selects one of sixteen possible tables, each table having sixteen entries. Each table is aligned on 16-word boundaries. Note that there are two choices for the texel type that resides in the TLUT: 16-bit RGBA, or 16-bit IA. The type is selected using the gDPSetTextureLUT() command. This command also configures the TMEM as shown in the following figure. Because of this, CI textures cannot be combined with other texture types in two-cycle mode.

Figure 13-16 TMEM Organization for Four-Bit Color Index Textures
[Figure 13-16]

Eight-bit CI textures do not use the palette number of the tile, since they address the whole 256 TLUT directly. It is possible to use the 8-bit mode for storing index textures that have between 16 and 256 entries.

For example, you could define a texture that had 40 entries, numbered 0-39, and load the TLUT into the upper half of TMEM (word 256). Further suppose that you had another texture with indices 40-69. You could load this texture's 30 entry TLUT into TMEM, starting at word 296.

Assuming that both textures together fit into the lower half of TMEM (2 KB), these textures could be co-resident in TMEM. It is also possible to have CI textures co-resident with other non-CI textures.

In the above example, you are using only the first 70 words of upper TMEM for TLUTs. You could use the remaining 186 words to store a 4-bit I texture, for example. Note that even though you can store CI and other types together in TMEM, you cannot access these types simultaneously in two-cycle mode, because the configuration of the TMEM for CI textures is controlled with a mode bit that must be updated using the gDPSetTextureLUT command, as mentioned previously.

Figure 13-17 TMEM Organization for Eight-Bit CI textures Textures
[Figure 13-17]
UP

13.8.2 Texel Formatting

In the RDP graphics pipeline, most operations are done on 8-bit-per-component RGBA pixels. After looking up the texels, the texture unit converts them into the 32-bit RGBA format. Table 2 describes how each type is converted. The format for beatified descriptions is [MSB:LSB] where MSB is the most significant bit and LSB is the least significant bit. Bit fields are grouped together in braces {} with the most significant field on the left and the least significant field on the right.

Table 13-9 Texel Output Formatting
[Table 13-9]
UP