Title: Tiled Polygon Traversal Using Half-Plane Edge Functions
1Tiled Polygon Traversal Using Half-Plane Edge
Functions
- Joel McCormack Bob McNamara
2What Do You Want To Do?
- Partition screen into rectangular tiles
- Visit all locations in triangle in one tile
before any in the next tile
3Why 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
4Outline
- Half-Plane Edge Functions
- Fragment Stamp and Movement
- A Simple Traversal Algorithm
- A Tiling Traversal Algoriththm
- Uses of Tiling and Even Metatiling
- Conclusions
5Half-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
6Triangle Surrounded By Edge Functions
- Non-negative half-planes have shadow lines
- All three edges non-negative in shaded yellow area
7Zen 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.)
8Fragment 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?
9Fragment 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
- Each edge contains at least one stamp segment
endpoint - Objects bounding box contains at least one stamp
segment endpoint
10Non-Tiling Traversal Example
- 0. Traverse first stampline
1. Traverse stamplines above
2. Traverse stamplines below
Zen, yeah right. Looks like goofy scanline
traversal
11A 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
12Tiling 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
13Tiling 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)
Lets see a grubby scanline algorithm do that!
14A 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
15Obvious 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
16Subset Metatiling
- Visit all location in tile before next tile, and
all tiles in metatile before next metatile - Requires three additional save states, though
17Subset 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
18Non-Subset Metatiling
- Tiles not contained by metatiles
- Visit all locations in tile also in metatile
before new tile
19Conclusions
- 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