19
www.compaq.com Tiled Polygon Tiled Polygon Traversal Using Traversal Using Half-Plane Edge Half-Plane Edge Functions Functions Joel McCormack & Bob McNamara Joel McCormack & Bob McNamara

Www.compaq.com Tiled Polygon Traversal Using Half-Plane Edge Functions Joel McCormack & Bob McNamara

Embed Size (px)

Citation preview

www.compaq.com

Tiled Polygon Tiled Polygon Traversal Using Half-Traversal Using Half-Plane Edge FunctionsPlane Edge Functions

Joel McCormack & Bob Joel McCormack & Bob McNamaraMcNamara

www.compaq.com

What Do You Want To Do?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 Why Do You Want To Do That?That?

Improve frame buffer memory access patternsDRAM 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 patternsStaying within limited area increases cache hits by exploiting 2D spatial coherency of texel accesses

www.compaq.com

OutlineOutlineHalf-Plane Edge FunctionsFragment Stamp and MovementA Simple Traversal AlgorithmA Tiling Traversal AlgoriththmUses of Tiling and Even MetatilingConclusions

www.compaq.com

Half-Plane Edge FunctionsHalf-Plane Edge FunctionsMany 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 edgeNegative 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 Triangle Surrounded By Edge FunctionsEdge 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 Zen and the Art of Polygon TraversalTraversal

Scanline traversal like being in the military:

Start exactly right hereGo exactly to there, then stopRepeat

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 Fragment Stamp: Fragment Sample Points and Probe Sample Points and Probe PointsPoints

marks sample point: is fragment inside object?

marks probe point: combine to determine if more object to left, right, above, below?

ORIGIN

LB

RT

RB

www.compaq.com

Fragment Stamp: Which Fragment Stamp: Which Adjacent Stamp Positions Adjacent Stamp Positions Are Valid?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

Object’s bounding box contains at least one stamp segment endpoint

E0

E1

E2

ORIGIN

LB

RT

RB

www.compaq.com

Non-Tiling Traversal Non-Tiling Traversal ExampleExample

0. Traverse first stampline

1. Traverse stamplines above2. Traverse stamplines belowZen, yeah

right. Looks like goofy scanline traversal

www.compaq.com

A Non-Tiling Traversal A Non-Tiling Traversal AlgorithmAlgorithm

Starting at leftmost vertex...0. Proceed right as long as valid position

Save first valid up positionSave first valid down position

1. Jump to saved up, proceed right as long as valid

Save first valid up, repeat 1 until no more up2. 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 Tiling Traversal ObservationsObservations

Easy to obey top and bottom tile boundariesGo down from initial scanline until hit tile bottomThen do original algorithm starting at Step 1 (go up)

Need new saved state to obey right tile boundaryOriginal algorithm, but stop at right tile boundary, and save first right position in next tile over

Traverse all of object in first tile columnThen move to saved right position and restart algorithm

Combine both to obey all tile boundaries

www.compaq.com

Tiling Traversal ExampleTiling Traversal Example0. 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 AlgorithmA Tiling Traversal Algorithm0. 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 tileSave first valid up, repeat 1 until no more up

2. Jump to saved down, proceed right in same tileSave 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 TilingObvious Uses for TilingOptimize 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 pageSerpentine variation reduces non-prefetchable crossings

Reduce texture cache miss rateTile size related to texture cache sizeTile dimensions long and skinny to minimize texture fetches that will suffer capacity misses

www.compaq.com

Subset MetatilingSubset MetatilingVisit 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 UsesSubset Metatiling UsesOptimize hierarchical frame buffer caching

Mitsubishi 3D-RAM has two cache levelsOptimize hierarchical texture cachesOr optimize frame buffer access and texture cache access simultaneously

www.compaq.com

Non-Subset MetatilingNon-Subset MetatilingTiles not contained by metatilesVisit all locations in tile also in metatile before new tile

www.compaq.com

ConclusionsConclusionsTiling 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