Slides [1 MB-ppt] - Graphics Hardware

Tiled Polygon Traversal
Using Half-Plane Edge
Functions
Joel McCormack & Bob McNamara
www.compaq.com
What Do You Want To Do?
Partition screen into
rectangular tiles
 Visit all locations in
triangle in one tile before
any in the next tile

www.compaq.com
Why Do You Want To Do That?

Improve frame buffer memory access patterns
DRAM access to open page faster than non-open page
 Staying on open page improves average access time...
 …and improves prefetching of pages into other banks


Improve texture cache access patterns

Staying within limited area increases cache hits by
exploiting 2D spatial coherency of texel accesses
www.compaq.com
Outline
Half-Plane Edge Functions
 Fragment Stamp and Movement
 A Simple Traversal Algorithm
 A Tiling Traversal Algoriththm
 Uses of Tiling and Even Metatiling
 Conclusions

www.compaq.com
Half-Plane Edge Functions
Many rasterizers traverse polygons by surrounding them
with edge functions going from vertex to vertex
 E01(x, y) = (x – x0)(y1 – y0) – (y – y0)(x1 – x0) splits 2D
plane into two halves:

Non-negative on or to right of edge
 Negative to left of edge


If all edge functions at (x, y) have same sign, then (x, y)
is within polygon
www.compaq.com
Triangle Surrounded By Edge
Functions
Non-negative
half-planes have
“shadow” lines
 All three edges
non-negative in
shaded yellow
area

www.compaq.com
Zen and the Art of Polygon Traversal

Scanline traversal like being in the military:
Start exactly right here
 Go exactly to there, then stop
 Repeat


Half-plane traversal more like Zen wandering to
enlightenment:
Where am I?
 Where can I go? Have I reached my limits?
 Okay, how about that away? (For now.)

www.compaq.com
Fragment Stamp: Fragment Sample
Points and Probe Points
 marks sample
point: is fragment
inside object?
  marks probe
point: combine to
determine if more
object to left, right,
above, below?

ORIGIN
RT
LB
RB
www.compaq.com
Fragment Stamp: Which Adjacent
Stamp Positions Are Valid?
Does a stamp segment, e.g. (RB, LB), intersect the
object (and thus indicate valid adjacent position)?
 Probably, if:

ORIGIN
RT
E2
E1
Each edge contains at
least one stamp
segment endpoint
 Object’s bounding
box contains at least
one stamp segment
endpoint

E0
LB
RB
www.compaq.com
Non-Tiling Traversal Example
0. Traverse first
stampline
1. Traverse
stamplines above
2. Traverse
stamplines below
Zen, yeah right.
Looks like goofy
scanline traversal
www.compaq.com
A Non-Tiling Traversal Algorithm
Starting at leftmost vertex...
0. Proceed right as long as valid position
Save first valid up position
 Save first valid down position

1. Jump to saved up, proceed right as long as valid

Save first valid up, repeat 1 until no more up
2. Jump to saved down, proceed right as long as valid

Save first valid down, repeat 2 until no more down
www.compaq.com
Tiling Traversal Observations

Easy to obey top and bottom tile boundaries
Go down from initial scanline until hit tile bottom
 Then do original algorithm starting at Step 1 (go up)


Need new saved state to obey right tile boundary
Original algorithm, but stop at right tile boundary, and
save first right position in next tile over
 Traverse all of object in first tile column
 Then move to saved right position and restart algorithm


Combine both to obey all tile boundaries
www.compaq.com
Tiling Traversal Example
0. Traverse first stampline in tile
½. Traverse stamplines below in
same tile
1. Traverse stamplines above in
tile column
2. Traverse stamplines below in
tile column (then next column)
Let’s see a grubby scanline
algorithm do that!
www.compaq.com
A Tiling Traversal Algorithm
0. Proceed right as long as valid position and in same tile

Save first valid up and down positions
½. Jump to saved down, proceed right in same tile

Save first valid down, repeat ½ while down in same tile
1. Jump to saved up, proceed right in same tile

Save first valid up, repeat 1 until no more up
2. Jump to saved down, proceed right in same tile

Save first valid down, repeat 2 until no more down
3. Jump to saved right (in new tile), go back to Step 0
www.compaq.com
Obvious Uses for Tiling

Optimize frame buffer access patterns
Tile size & dimensions match 2D page in frame buffer
 All positions in object & page visited before new page
 Increases available time to prefetch next page
 Serpentine variation reduces non-prefetchable crossings


Reduce texture cache miss rate
Tile size related to texture cache size
 Tile dimensions long and skinny to minimize texture
fetches that will suffer capacity misses

www.compaq.com
Subset Metatiling
Visit all location in tile before
next tile, and all tiles in metatile
before next metatile
 Requires three additional save
states, though

www.compaq.com
Subset Metatiling Uses

Optimize hierarchical frame buffer caching

Mitsubishi 3D-RAM has two cache levels
Optimize hierarchical texture caches
 Or optimize frame buffer access and texture cache
access simultaneously

www.compaq.com
Non-Subset Metatiling
Tiles not contained by metatiles
 Visit all locations in tile also in metatile before new tile

www.compaq.com
Conclusions
Tiling is easy to add to a half-plane based rasterizer
 Tiling increases frame buffer memory efficiency
 Tiling increases effectiveness of texture cache
 Scanline rasterizers should die a quiet death

www.compaq.com