12.4 TX - Texture Engine

The Texture Engine takes s/w, t/w, 1/w, and LOD values for a pixel and fetches the onboard texture memory (TMEM: special memory of texture built-in RDP) for the four nearest texels to the screen pixel. The game application can manipulate TX states such as texture image types and formats, how and where to load texture images, and texture sampling attributes.

Figure 12-5 TX State and Input/Output
[Figure 12-5]

UP


12.4.1 Texture Tiles

TX treats the 4 KB on-chip texture memory (TMEM) as general-purpose texture memory. The texture memory is divided into four simultaneous accessible banks, giving output of four texels per clock.

The game application can load various sizes of texture with different formats anywhere in the 4 KB texture map. There are eight texture tile descriptors that describe the location of texture images within the TMEM, the format of this texture, and the sampling parameters. Therefore, you can load many texture maps in the TMEM at one time, but there are only eight tiles that are accessible at any time.

Figure 12-6 Tile Descriptors and TMEM
[Figure 12-6\

Note: There are some restrictions, depending on texel size and 64-bit alignment within the texture memory. Please see Section 13.11.2 "Alignment" for additional information.

UP


12.4.2 Multiple Tile Textures

Given the eight texture tiles, you can use two-cycle pipeline mode to cycle TX twice and access eight texels (four from each of two tiles). This functionality, coupled with the use of up to eight texture tiles, allows the TX to perform mipmapping and detailed textures.

Furthermore, there are no explicit restrictions requiring power of two tile-sized decrements for mipmaps. Multi-tile texture map sizes are all independently programmable. Therefore, using these tiles and the color combiner block (please see Section 12.6, "CC - Color Combiner", arithmetic logic can result in many special effects. For example, sliding two different frequency band tiles across a polygon surface while combining them with a blue polygon can give a nice ocean wave effect.

UP


12.4.3 Texture Image Types and Format

Table 12-10 shows the valid combinations of data types and pixel/texel sizes for the Color and Texture images. For RGBA types, the 16-bit format is 5/5/5/1, and the 32-bit format is 8/8/8/8.

The Intensity Alpha type (IA) replicates the I value on the RGB channels and places the A value on the A channel. The IA 16-bit format is 8/8, the 8-bit format is 4/4, and the 4-bit format is 3/1.

Table 12-10 Texture Format and Sizes
Type4b8b16b32b
RGBA

XX
YUV

X
Color IndexXX

IAXXX
IXX

UP


12.4.4 Texture Loading

Several steps are necessary to load a texture map into the TMEM. You must block-load the texture map itself and set up the attributes for this tile. There are GBI macros that simplify all these steps into a single macro.

There are two ways of loading textures: block or tile mode. Block mode assumes that the texture map is a contiguous block of texels that represents the whole texture map. Tile mode can lift a subrectangle out of a larger image. The following tables list block and tile mode texture-loading GBI commands respectively.

Table 12-11 gsDPLoadTextureTile(timg,fmt,siz,width,height,uls,ult,lrs,lrt,pal,cms,cmt,masks,maskt,shifts,shiftt)
Table 12-12 gsDPLoadTextureTile_4b(pkt,timg,fmt,width,height,uls,ult,lrs,lrt,pal,cms,cmt,masks,maskt,shifts,shiftt)
ParameterValues
timgTexture DRAM address
fmtG_IM_FMT_RGBA
G_IM_FMT_YUV
G_IM_FMT_CI
G_IM_FMT_I
G_IM_FMT_IA
sizG_IM_SIZ_4b
G_IM_SIZ_8b
G_IM_SIZ_16b
G_IM_SIZ_32b
width, heightTexture tile width and height in texel space
palTLUT palette
cms, cmtclamping/mirroring for s/t axis
G_TX_NOMIRROR
G_TX_MIRROR
G_TX_WRAP
G_TX_CLAMP
masks, masktBit mask for wrapping
G_TX_NOMASK or a number: A wrapping bit mask is represented by (1<<number) - 1.
shifts, shifttShifts applied to s/t coordinate of each pixel.
This is how you "sample" the lower levels of mipmap.
G_TX_NOLOD or a number: (s or t coord >> number) = s/t to sample other mipmap levels.
ulsupper left s index of the tile within the texture image
ultupper left t
lrslower right s
lrtlower right t

UP


12.4.5 Color-Indexed Textures

These are some restrictions on the size and placement of CI texture maps within the TMEM. The TMEM is actually partitioned into two halves. Four texels are sampled from the first bank and fed into the second bank for texture/color/index table lookup (TLUT).

Figure 12-7 CI TMEM Partition
[Figure 12-7]

Four texels from the texture images are sent from first half banks to the second half banks. The second half banks contain color index palettes. Each color map entry is replicated 4 times for four simultaneous bank lookups. Therefore, 8-bit CI textures all require 2 KB (256 x 64 bits per entry) second half banks to hold the TLUT, while 4-bit CI texture can have up to 16 separate TLUTs.

Note: TLUT must reside on the second half of TMEM; while CI texture cannot reside on the second half of TMEM. Non-CI texture can actually reside on the second half of TMEM in unused TLUT palette/entries.x

Table 12-13 gsLoadTLUT(count,tmemaddr,dramaddr)
ParameterValues
countNumber of entries in the TLUT. For example, a 4-bit texel TLUT would have 16 entries.
tmemaddrWhere the TLUT goes in TMEM
dramaddrWhere the TLUT is in DRAM

UP


12.4.6 Texture-Sampling Modes

Software can enable and disable TX to perform the following sampling modes:

  1. perspective correction
  2. detail or sharp textures
  3. LOD (mipmap) or bilinear textures
  4. RGBA or IA TLUT type
Table 12-14 gsDPSetTexturePersp(mode)
ParameterValues
modeG_TP_NONE
G_TP_PERSP

Table 12-15 gsDPSetTextureDetail(mode)
ParameterValues
modeG_TD_CLAMP
G_TD_SHARPEN
G_TD_DETAIL

Table 12-16 gsDPSetTextureLOD(mode)
ParameterValues
modeG_TL_TILE
G_TL_LOD

Table 12-17 gsDPSetTextureLUT(type)
ParameterValues
typeG_TT_NONE
G_TT_RGBA16
G_TT_1A16

UP


12.4.7 Synchronization

With TMEM and tile descriptor states, TX also requires explicit synchronization to render primitives with the proper attribute state. Texture loads after primitive rendering must be preceded by a gsDPLoadSync(), and tile descriptor attribute changes should be preceded by a gsDPTileSync().

Note: If you use the high-level programming macros gsDPLoadTexture* or gsDPLoadTexture*_4b, then you don't need to worry about load and tile syncs. They are embedded in the macro.

UP