lecture 3: sort-everywhere pipeline scheduling and...

63
Visual Computing Systems CMU 15-869, Fall 2014 Lecture 3: Sort-Everywhere Pipeline Scheduling and Geometry Processing

Upload: others

Post on 14-Aug-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

Visual Computing Systems CMU 15-869, Fall 2014

Lecture 3:

Sort-Everywhere Pipeline Scheduling and Geometry Processing

Page 2: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Scheduling a sort-everywhere graphics pipeline !

The following figures follows the design of Pomegranate [Eldridge et al.], but use stage names consistent with modern graphics pipeline.

Page 3: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Starting state: draw commands enqueued for pipeline

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input: three triangles to draw (fragments to be generated for each triangle by rasterization are shown below)

Frag Processing 0

Draw

Draw

Draw

GeometryT1

T2

T3

1 2 3 4

1 2 3 4

1 2 3

Interleaved render target

0 11 0

Draw T1 Draw T2 Draw T3

Frag Processing 1

Assume batch size is 2 for assignment to rasterizers.

Page 4: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Geometry

0 11 0

T1 T2

Draw T3

After geometry processing, first two processed triangles assigned to rast 0

Draw

Draw

Draw

T1

T2

T3

1 2 3 4

1 2 3 4

1 2 3

Frag Processing 1

Interleaved render target

Assume batch size is 2 for assignment to rasterizers.

Page 5: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Geometry

0 11 0

T1 T2

Next

T3

Assign next triangle to rast 1 (round robin policy, batch size = 2) Q. What is the ‘next’ token for?

Draw

Draw

Draw

T1

T2

T3

1 2 3 4

1 2 3 4

1 2 3

Frag Processing 1

Interleaved render target

Page 6: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Geometry

0 11 0

T2 Next

T1,1 T1,2

T3,1 T3,3

T1,3

T1,4

T3,2

Rast 0 and rast 1 can process T1 and T3 simultaneously (Shaded fragments enqueued in frame-buffer unit input queues)

Draw

Draw

Draw

T1

T2

T3

1 2 3 4

1 2 3 4

1 2 3

Frag Processing 1

Interleaved render target

Page 7: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Geometry

0 11 0

T2 Next

T3,1 T3,3

T3,2 T1,2

T1,1

T1,3T1,4

FB 0 and FB 1 can simultaneously process fragments from rast 0 (Notice updates to frame buffer)

Draw

Draw

Draw

T1

T2

T3

1 2 3 4

1 2 3 4

1 2 3

Frag Processing 1

Interleaved render target

Page 8: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Geometry

0 11 0

T2 Next

T3,1 T3,3

T3,2 T1,2

T1,1

T1,3T1,4

Fragments from T3 cannot be processed yet. Why?

Draw

Draw

Draw

T1

T2

T3

1 2 3 4

1 2 3 4

1 2 3

Frag Processing 1

Interleaved render target

Page 9: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Geometry

0 11 0

Next

T3,1 T3,3

T3,2 T1,2

T1,1

T1,3T1,4

Rast 0 processes T2 (Shaded fragments enqueued in frame-buffer unit input queues)

T2,1 T2,2T2,3 T2,4

Draw

Draw

Draw

T1

T2

T3

1 2 3 4

1 2 3 4

1 2 3

Frag Processing 1

Interleaved render target

Page 10: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Geometry

0 11 0

Switch

T3,1 T3,3

T3,2 T1,2

T1,1

T1,3T1,4

Rast 0 broadcasts ‘next’ token to all frame-buffer units

T2,1 T2,2T2,3 T2,4

Draw

Draw

Draw

T1

T2

T3

1 2 3 4

1 2 3 4

1 2 3

Frag Processing 1

Switch

Interleaved render target

Page 11: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Geometry

0 11 0

T3,1 T3,3

T3,2 T1,2

T1,1

T1,3T1,4

FB 0 and FB 1 can simultaneously process fragments from rast 0 (Notice updates to frame buffer)

T2,1

T2,2 T2,3T2,4

Draw

Draw

Draw

T1

T2

T3

1 2 3 4

1 2 3 4

1 2 3

Frag Processing 1

Switch Switch Interleaved render target

Page 12: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Geometry

0 11 0

T3,1 T3,3

T3,2 T1,2

T1,1

T1,3T1,4

Switch token reached: frame-buffer units start processing input from rast 1

T2,1

T2,2 T2,3T2,4

Draw

Draw

Draw

T1

T2

T3

1 2 3 4

1 2 3 4

1 2 3

Frag Processing 1

Interleaved render target

Page 13: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Geometry

0 11 0

T1,2

T1,1

T1,3T1,4 T2,1

T2,2 T2,3T2,4

FB 0 and FB 1 can simultaneously process fragments from rast 1 (Notice updates to frame buffer)

T3,1 T3,2

T3,3

Draw

Draw

Draw

T1

T2

T3

1 2 3 4

1 2 3 4

1 2 3

Frag Processing 1

Interleaved render target

Page 14: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Extending to parallel geometry units

Page 15: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Geometry 0

0 11 0

Draw T1 Draw T2 Draw T3

Geometry 1

Distrib

Draw T4

Draw

Draw

Draw

T1

T2

T3

1 2 3 4

1 2 3 4

Draw T4 1 2

5 6 7

1 2 3 4

5

Frag Processing 1

Starting state: commands enqueued

Interleaved render target

Assume batch size is 2 for assignment to geom units and to rasterizers.

Page 16: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Geometry 0

0 11 0

T1 T2

T3

Geometry 1

Distrib

T4 Next

Draw

Draw

Draw

T1

T2

T3

1 2 3 4

1 2 3 4

Draw T4 1 2

5 6 7

1 2 3 4

5

Frag Processing 1

Distribute triangles to geom units round-robin (batches of 2)

Interleaved render target

Page 17: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2T1,a T1,b

5 6 7

Next

1 2 3 4

5T1,c

Frag Processing 1

Geom 0 and geom 1 process triangles in parallel (Results after T1 processed are shown. Note big triangle T1 broken into multiple work items. [Eldridge et al.])

T2 T3 T4 Next

Interleaved render target

Page 18: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2T1,a T1,b

5 6 7

T2 Next

T3,aT3,b

1 2 3 4

5Next

T4 T1,c

Next

Frag Processing 1

Geom 0 and geom 1 process triangles in parallel (Triangles enqueued in rast input queues. Note big triangles broken into multiple work items. [Eldridge et al.])

Interleaved render target

Page 19: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2T1,a T1,b

5 6 7

T2 Next

T3,aT3,b

1 2 3 4

5Next

T4 T1,c

Switch

Frag Processing 1

Switch

Geom 0 broadcasts ‘next’ token to rasterizers

Interleaved render target

Page 20: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2

5 6 7

Next T3,aT3,b

1 2 3 4

5Next

T4

T1,1 T1,2 T1,3 T1,4

T1,6

T1,5

T1,7 T2,1 T2,2 T2,3 T2,4

Frag Processing 1

Switch Switch

Rast 0 and rast 1 process triangles from geom 0 in parallel (Shaded fragments enqueued in frame-buffer unit input queues)

Interleaved render target

Page 21: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2

5 6 7

T3,aT3,b

1 2 3 4

5Next

T4

T1,1 T1,2 T1,3 T1,4

T1,6

T1,5

T1,7 T2,1 T2,2 T2,3 T2,4

Frag Processing 1

Switch Switch

Rast 0 broadcasts ‘next’ token to FB units (end of geom 0, rast 0)

Switch Switch

Interleaved render target

Page 22: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Frag Processing 0

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2

5 6 7

T3,aT3,b

1 2 3 4

5Next

T4

T1,6 T1,7 T2,1 T2,2 T2,3 T2,4

T1,1

T1,2 T1,3

T1,4 T1,5

Frag Processing 1

Switch Switch

Frame-buffer units process frags from (geom 0, rast 0) in parallel (Notice updates to frame buffer)

Switch Switch

Interleaved render target

Page 23: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2

5 6 7

T3,aT3,b

1 2 3 4

5Next

T4

T1,6 T1,7 T2,1 T2,2 T2,3 T2,4

T1,1

T1,2 T1,3

T1,4 T1,5

Frag Processing 1Frag Processing 0

“End of rast 0” token reached by FB: FB units start processing input from rast 1 (fragments from geom 0, rast 1)

Switch Switch

Interleaved render target

Page 24: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2

5 6 7

T3,aT3,b

1 2 3 4

5Next

T4

T1,6 T1,7 T2,1 T2,2 T2,3 T2,4

T1,1

T1,2 T1,3

T1,4 T1,5

Frag Processing 1Frag Processing 0

“End of geom 0” token reached by rast units: rast units start processing input from geom 1 (note “end of geom 0, rast 1” token sent to rast input queues)

Switch Switch

Interleaved render target

Page 25: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2

5 6 7

1 2 3 4

5Next

T1,6 T1,7 T2,1 T2,2 T2,3 T2,4

T1,1

T1,2 T1,3

T1,4 T1,5

Frag Processing 1Frag Processing 0

T3,1 T3,2T3,3 T3,4T3,5

Rast 0 processes triangles from geom 1 (Note Rast 1 has work to do, but cannot make progress because its output queues are full)

T4

Switch Switch

Interleaved render target

Page 26: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2

5 6 7

1 2 3 4

5

T1,6 T1,7 T2,1 T2,2 T2,3 T2,4

T1,1

T1,2 T1,3

T1,4 T1,5

Frag Processing 1Frag Processing 0

T3,1 T3,2T3,3 T3,4

Switch Switch T3,5

Rast 0 broadcasts “end of geom 1, rast 0” token to frame-buffer units

T4

Switch Switch

Interleaved render target

Page 27: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2

5 6 7

1 2 3 4

5

T4,1 T1,1

T1,2 T1,3

T1,4 T1,5

Frag Processing 1Frag Processing 0

Switch Switch T3,1 T3,2T3,3 T3,4

Switch Switch

T2,1 T2,2

T2,3 T2,4

T1,6

T1,7

T4,2 T3,5

Frame-buffer units process frags from (geom 0, rast 1) in parallel (Notice updates to frame buffer. Also notice rast 1 can now make progress since space has become available)

Interleaved render target

Page 28: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2

5 6 7

1 2 3 4

5

T4,1 T1,1

T1,2 T1,3

T1,4 T1,5

Frag Processing 1Frag Processing 0

T3,1 T3,2T3,3 T3,4

Switch Switch

T2,1 T2,2

T2,3 T2,4

T1,6

T1,7

T4,2

T3,5

Switch token reached by FB: FB units start processing input from (geom 1, rast 0)

Interleaved render target

Page 29: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2

5 6 7

1 2 3 4

5

T4,1 T1,1

T1,2 T1,3

T1,4 T1,5

Frag Processing 1Frag Processing 0

Switch Switch T2,1 T2,2

T2,3 T2,4

T1,6

T1,7

T4,2

T3,1 T3,2

T3,3 T3,4

T3,5

Frame-buffer units process frags from (geom 1, rast 0) in parallel (Notice updates to frame buffer)

Interleaved render target

Page 30: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2

5 6 7

1 2 3 4

5

T4,1 T1,1

T1,2 T1,3

T1,4 T1,5

Frag Processing 1Frag Processing 0

T2,1 T2,2

T2,3 T2,4

T1,6

T1,7

T4,2

T3,1 T3,2T3,3 T3,4

T3,5

Switch token reached by FB: FB units start processing input from (geom 1, rast 1)

Interleaved render target

Page 31: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Rasterizer 0 Rasterizer 1

Frame-buffer 0 Frame-buffer 1

Input:

Draw

Draw

Draw

Geometry 0T1

T2

T3

1 2 3 4

1 2 3 4

0 11 0

Geometry 1

Distrib

Draw T4 1 2

5 6 7

1 2 3 4

5

T1,1

T1,2 T1,3

T1,4 T1,5

Frag Processing 1Frag Processing 0

T2,1 T2,2

T2,3 T2,4

T1,6

T1,7

T3,1 T3,2

T3,3 T3,4

T3,5

T4,1 T4,2

Frame-buffer units process frags from (geom 1, rast 1) in parallel (Notice updates to frame buffer)

Interleaved render target

Page 32: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Geometry Processing Basics (Focus on design and implementation challenges of tessellation)

Page 33: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Quick review: coordinate spaces

Image credit: http://www.songho.ca/opengl/gl_projectionmatrix.html

Camera-space 3D view frustum: - Camera at origin - Camera looking down -Z axis - All triangles intersecting with

this volume will be drawn. All triangles outside the region will be discarded prior to rasterization (they are off-screen)

Canonical clip-space view frustum: - (-1,-1,-1) to (1,1,1) in euclidian 3D space - (-w,-w,-w, *) to (w,w,w, *) in

homogeneous 3D space

Clipping example: triangle extends beyond view volume. Clipped to form two triangles entirely within volume.

- Modeling transform: compute vertex positions in world-space (“object-to-world” transform) - View transform: compute vertex position in camera-space (“world-to-camera” transform) - Projection transform: compute vertex position in homogeneous clip space (“camera-to-clip” transform)

Page 34: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Per vertex operations: application-specified vertex shader outputs vertex positions in clip space

Vertex Processing

Rasterization (Fragment Generation)

(x,y,z,w)

Vertex positions emitted by vertex processing (or the geometry shader, if enabled) are represented in homogeneous, clip-space coordinates. !Homogeneous vertex v = (x,  y,  z,  w)    !Vertex position in euclidian space: (x/w,  y/w,  z/w)    !Vertex is within the canonical clip-space view frustum if: !-­‐w  ≤  x  ≤  w  -­‐w  ≤  y  ≤  w  -­‐w  ≤  z  ≤  w

Page 35: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Fixed-function, per-primitive operations

Given triangle’s input vertices (with positions in homogeneous clip space):

1. “Assemble” (a.k.a. group) vertices into primitives 2. Discard primitive if it is entirely outside the view frustum 3. Clip primitive against view frustum (if clipping is necessary) 4. For each resulting primitive

- Divide homogeneous x,y,z coordinates by w (coordinates now in [-1,1] range)

- Apply viewport transform to compute screen position of vertex (coordinates now in the range [0,screen_width])

- Discard back-facing primitives [optional, depends on rasterizer configuration]

Page 36: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Assembling vertices into primitives

How to assemble vertices into primitives is pipeline state (specified as an argument to the pipeline’s draw command)

Notice: vertices are processed independently, but get grouped into primitives (this is a “join” in fork-join parallelism terminology)

Page 37: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Clipping

▪ May generate new vertices/primitives, or eliminate vertices/primitives ▪ Data-dependent computation - Variable amount of work per primitive - Variable control flow per primitive

Page 38: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Why clipping?▪ Avoid downstream processing that will not contribute to

image (rasterization, fragment processing)

▪ Establish invariants for emitted primitives - Can safely divide vertex clip space xyz coordinates by w after clipping - Bounds vertex positions (allowing system to perform subsequent

rasterization operations using lower precision arithmetic)

Page 39: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Guard-band clipping▪ Idea: clip against wider X-Y plane clip bounds than canonical view volume

▪ Significantly reduces number of triangles that must undergo clipping -- reduces variance in per-primitive clipping work

▪ Cost is that primitives no longer guaranteed to be fully on screen - Rasterizer must not generate off-screen fragments - Increased precision required during rasterization

[RealityEngine, Akeley 93]

Page 40: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Back-face culling▪ Sign of triangle area indicates if triangle is facing toward or away

from camera ▪ Pipeline may discard primitive as a result of this test

- For closed meshes, eliminates ~ 1/2 of triangles (these triangles would be occluded by other triangles anyway)

Page 41: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

GPU Tessellation Pipeline

Page 42: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Graphics pipeline support for tessellation

[Tatarchuk 2007]

Image credit: 3D Guru (from NVIDIA)

No tessellation Tessellated surfaces with displacement mapping

Page 43: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Image credit: Unigine Engine, copyright Unigine Corp.

Low detail

No tessellation

Page 44: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Image credit: Unigine Engine, copyright Unigine Corp.

Tessellated surfaces with displacement mapping

Page 45: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Modern GPU tessellation▪ Motivations:

- Reduce footprint (do not store high-resolution triangles in memory)

- For animated surfaces: reduce CPU-GPU bandwidth (do not transfer high resolution mesh over PCIe bus to GPU each frame)

- Animate/skin/compute physics using course resolution mesh, but render high resolution mesh

Vertex Shader

Tessellator

Domain Shader

Geometry Shader

Hull Shader

Note: D3D11 Stage Naming (not canonical stage names)

[Moreton 01]

▪ Design: - Hybrid programmable / non-programmable

implementation using three new pipeline stages - Supports only parametric surfaces:

surface must support direct evaluation of position(u,v)

Page 46: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Pipeline tessellation requires parametric surfaces

u

v

(1,0)(0,0)

(1,1)(0,1)

(u,v)

f(u,v)=(x,y,z)

(u,v)

Image credit: http://csis.pace.edu/~marchese/CG/Lect10/cg_10.htm

3D surface position is a function of 2D parametric coordinate (u,v) Below: [0,1]2 parametric domain

Page 47: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Example parametric surfaces

Bicubic patch, defined by 16 control points (quadrilateral domain)

PN Triangles, 3 vertices + 3 normals (defines bezier patch on triangular domain)

See “Approximating Catmull-Clark Subdivision Surfaces With Bicubic

Patches”, Loop et al. 2008

See “Curved PN Triangles”, Vlachos et al. 2008

Page 48: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Three-stage tessellation pipeline▪ Stage 1: hull shader

- Programmable stage

- Input: one “surface patch” primitive: grouped vertices after traditional vertex processing

- Output: new “patch” primitive - Tessellation factor for each edge of

parametric domain - Control points for parametric surface

(computed from input primitive vertices)

Vertex Shader

Tessellator

Domain Shader

Geometry Shader

Hull Shader

Note: D3D11 Stage Naming (not canonical stage names)

Patch control points

Edge tess factors

Coarse primitive (with adjacency)

Page 49: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

7

2

43

Hull shader produces edge tessellation ratesBased on estimate of parametric surface position (e.g, larger surfaces on screen yield higher tessellation rates)

u

v

Page 50: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

7

2

43

Stage 2: fixed-function tessellation stage

[Moreton 01]

Input: edge tessellation constraints for a patch Output: (almost) uniform mesh topology meeting constraints

Page 51: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

Stage 3: domain shader (“fine vertex” shader)Input: control points (from hull shader) and stream of parametric vertex locations (u,v) from tessellator Output: position of vertex at parametric coordinate: position(u,v)

Page 52: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Modern GPU tessellation pipeline▪ Hull shader (programmable)

- Coarse primitive granularity - Data-parallel across coarse primitives - Large working set per invocation

(typically a primitive + one-ring)

▪ Tessellator (fixed-function) - Surface agnostic, fixed-function hardware implementation - Irregular control flow

▪ Domain shader (programmable) - Fine-mesh-vertex granularity - Data-parallel (preserves shader programming model) - Direct evaluation of surface at specified domain coordinate

Vertex Shader

Tessellator

Domain Shader

Geometry Shader

Hull Shader

Note: D3D11 Stage Naming (not canonical stage names)

Patch control points

Edge tess factors

Coarse primitive (with adjacency)

Fine vertex coord: (u,v)

Fine vertices

Page 53: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

Parallel tessellation challenge: avoid cracks!

2

1

21 (parametric domain)

Hull shader must carefully compute edge tess factors to avoid cracks (See suggested readings on website)

Page 54: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Modern GPU tessellation summary▪ Enables adaptive level-of-detail, high-resolution meshes in games

▪ Heterogeneous abstraction: co-design of algorithm and hardware - Retain flexibility: surface type is programmable, but it must be parametric - Minimize new complexity: extension of existing shader programming model - Retain performance:

- Parallelism: data-parallel evaluation of fine vertex positions - Fixed-function HW algorithm for generating points (not data parallel algorithm)

▪ Implementation challenges - Application developer: avoiding cracks (requires consistent edge rate evaluation,

this is tricky in floating point math) - GPU implementor: managing large data amplification... while maintaining

parallelism, locality, and order

Page 55: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Parallel Scheduling of Data Amplification

Page 56: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Geometry amplification

▪ Examples of one-to-many stage behavior during geometry processing in the graphics pipeline

- Clipping amplifies geometry (clipping can result in multiple output primitives)

- Tessellation: pipeline permits thousands of vertices to be generated from a single base primitive (challenging to maintain highly parallel execution)

- Geometry shader: output up to 1024 floats worth of vertices per input primitive

Page 57: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Thought experimentCommand Processor

Geometry Amplifier

. . .. . . Rasterizer

Geometry Amplifier

T2

Geometry Amplifier

Geometry Amplifier

T1T4T3

T6T5

T8T7

Assume round-robin distribution of eight primitives to geometry pipelines, one rasterizer unit.

Page 58: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Consider case of large amplification when processing T1

Command Processor

Geometry Amplifier

. . .. . . Rasterizer

Geometry Amplifier

T2

T3,1T3,2T4,1

T1,1T1,2T1,3T1,4T1,5T1,6

Geometry Amplifier

Geometry Amplifier

T4,2T4,3T4,4

T5,1T6,1T6,2T6,3T6,4T6,5

T7,1T7,2T7,3T8,1T8,2T8,3

Result: one geometry unit (the one producing outputs from T1) is feeding the entire downstream pipeline - Serialization of geometry processing: other geometry units are stalled because their output queues

are full (they cannot be drained until all work from T1 is completed) - Underutilization of rest of chip: unlikely that one geometry producer is fast enough to produce

pipeline work at a rate that fills resources of rest of GPU.

Notice: output from T1 processing fills output queue

Page 59: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Thought experiment: (class homework) design a scheduling strategy for this case

Command Processor

Geometry Amplifier

. . .. . . Rasterizer

Geometry Amplifier

T2

T3,1T3,2T4,1

T1,1T1,2T1,3T1,4T1,5T1,6

Geometry Amplifier

Geometry Amplifier

T4,2T4,3T4,4

T5,1T6,1T6,2T6,3T6,4T6,5

T7,1T7,2T7,3T8,1T8,2T8,3

1. Design a solution that is performant when the expected amount of data amplification is low? 2. Design a solution this is performant when the expected amount of data amplification is high 3. What about a solution that works well for both? The ideal solution always executes with maximum parallelism (no stalls), and with maximal locality (units read and write to fixed size, on-chip inter-stage buffers), and (of course) preserves order.

Page 60: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Implementation 1: fixed on-chip storageCommand Processor

Geometry Amplifier

. . .. . . Rasterizer

Geometry Amplifier

Geometry Amplifier

Geometry Amplifier

Approach 1: make on-chip buffers big enough to handle common cases, but tolerate stalls - Run fast for low amplification (never move output queue data off chip) - Run very slow under high amplification (serialization of processing due to blocked units). Bad

performance cliff.

Small, on-chip buffers

Page 61: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Command Processor

Geometry Amplifier

. . .. . . Rasterizer

Geometry Amplifier

Geometry Amplifier

Geometry Amplifier

Implementation 2: worst-case allocation

Approach 2: never block geometry unit: allocate worst-case space in off-chip buffers (stored in DRAM) - Run slower for low amplification (data goes off chip then read back in by rasterizers) - No performance cliff for high amplification (still maximum parallelism, data still goes off chip) - What is overall worst-case buffer allocation if the four geometry units above are Direct3D 11

geometry shaders?

. . . . . . . . . . . .

Large, in-memory buffers

Page 62: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Command Processor

Geometry Amplifier

. . .. . . Rasterizer

Geometry Amplifier

Geometry Amplifier

Geometry Amplifier

Implementation 3: hybrid

Hybrid approach: allocate output buffers on chip, but spill to off-chip, worst-case size buffers under high amplification - Run fast for low amplification (high parallelism, no memory traffic) - Less of performance cliff for high amplification (high parallelism, but incurs more memory traffic)

Off-chip (spill) buffers

. . . . . . . . . . . .

On-chip buffers

Page 63: Lecture 3: Sort-Everywhere Pipeline Scheduling and ...graphics.cs.cmu.edu/.../03_geometry_slides.pdf · Sort-Everywhere Pipeline Scheduling and Geometry Processing . CMU 15-869, Fall

CMU 15-869, Fall 2014

Readings▪ A. R. Smith, A Pixel is Not a Little Square, a Pixel is Not a Little Square,

a Pixel is Not a Little Square! (and a Voxel is Not a Little Cube) Microsoft Technical Memo, 1995 (to prep for next class)