Lets Fix OpenGL Adrian Sampson, Cornell Commands Pixels CPU GPU - - PowerPoint PPT Presentation

let s fix opengl adrian sampson cornell commands pixels
SMART_READER_LITE
LIVE PREVIEW

Lets Fix OpenGL Adrian Sampson, Cornell Commands Pixels CPU GPU - - PowerPoint PPT Presentation

Lets Fix OpenGL Adrian Sampson, Cornell Commands Pixels CPU GPU Display CPU Display Rendering Pipeline programmable & fixed-function stages C, C++, GLSL GLSL JavaScript Vertex Fragment CPU Shader Shader vertex positions


slide-1
SLIDE 1

Let’s Fix OpenGL Adrian Sampson, Cornell

slide-2
SLIDE 2
slide-3
SLIDE 3

CPU GPU Display Commands Pixels

slide-4
SLIDE 4

CPU Display Rendering Pipeline programmable & fixed-function stages

slide-5
SLIDE 5

vertex positions pixel colors Vertex Shader Fragment Shader C, C++, JavaScript GLSL GLSL CPU

slide-6
SLIDE 6

in vec4 fragPos; void main() { gl_FragColor = abs(fragPos); }

Fragment Shader Vertex Shader

in vec4 position; in float dist;

  • ut vec4 fragPos;

void main() { fragPos = position; gl_Position = position + dist; }

slide-7
SLIDE 7

static const char *vertex_shader =
 "in vec4 position; ...";
 static const char *fragment_shader =
 "in vec4 fragPos; ..."; 
 GLuint vshader = glCreateShader(GL_VERTEX_SHADER);
 // ... more boilerplate ...
 glLinkProgram(program); 
 GLuint loc_dist =
 glGetUniformLocation(program, "dist");

CPU “Host Code”

glUseProgram(program); glUniform1f(loc_dist, 4.0);
 // ... assign other "in" parameters ... glDrawArrays(...);

setup render a frame

slide-8
SLIDE 8

#1 Shader languages are subsets of supersets of C.

slide-9
SLIDE 9

Like C++ #1 Shader languages are subsets of supersets of C. struct T { ... } declares a typed named: struct T A. T B.

slide-10
SLIDE 10

Like C #1 Shader languages are subsets of supersets of C. if (bool b = ...) { ... } are allowed. true false Declarations inside conditions

slide-11
SLIDE 11

Correct output. ARM Mali GPU on Android. “It looks like there was indeed an obscure register allocation bug in the driver...” —ARM

from “Bugs can be beautiful," by Alastair Donaldson. https://medium.com/@afd_icl/65b93c5c58f9 c.f. “Metamorphic Testing for (Graphics) Compilers,” by Alastair Donaldson and Andrei Lascu. http://www.doc.ic.ac.uk/~afd/homepages/papers/pdfs/2016/MET.pdf

slide-12
SLIDE 12

#1 Shader languages are subsets of supersets of C. ⇒ Apply work on language extensibility.

slide-13
SLIDE 13

#2 Loose CPU-to-GPU and stage-to-stage coupling.

GLuint loc_dist = glGetAttribLocation(program, "dist");

CPU setup

glUniform1f(loc_dist, 4.0);

CPU render

in float dist;

vertex shader

slide-14
SLIDE 14

#2 Loose CPU-to-GPU and stage-to-stage coupling.

GLuint loc_dist = glGetAttribLocation(program, "dist");

CPU setup

glUniform1f(loc_dist, 4.0);

CPU render

in float dist;

  • ut vec4 fragPos;

vertex shader

fragPos = position; in vec4 fragPos;

fragment shader

slide-15
SLIDE 15

#2 Loose CPU-to-GPU and stage-to-stage coupling. ⇒ Cross-language static analysis for the short term. ⇒ Single-source CPU+GPU languages for the long term.

slide-16
SLIDE 16

#3 Massive metaprogramming without hygiene.

slide-17
SLIDE 17

#3 Massive metaprogramming without hygiene. Übershader

slide-18
SLIDE 18

in bool param; if (param) { ... } glUniform1b(param_loc, true); #ifdef _PARAM ... #endif glShaderSource( "#define _PARAM", "...");

#3 Massive metaprogramming without hygiene. vs.

slide-19
SLIDE 19

⇒ Scale up safe metaprogramming tools
 to generate thousands of shader variants. #3 Massive metaprogramming without hygiene.

slide-20
SLIDE 20

#4 Missing general theory for execution rates.

fragPos = position;

vertex shader fragment shader

gl_FragColor = abs(fragPos);

CPU

float* pos = malloc(...);

interpolation indexing

slide-21
SLIDE 21

#4 Missing general theory for execution rates. vertex fragment geometry tessellation render setup compile

slide-22
SLIDE 22

#4 Missing general theory for execution rates. ⇒ Define a core λGPU to describe programming with rates and a translation from OpenGL.

slide-23
SLIDE 23

#5 Latent types for linear algebra.

b u n n y s p a c e

teapot space

slide space

slide-24
SLIDE 24

#5 Latent types for linear algebra.

in mat4 bunny_model; in vec4 position; bunny_model * position vec4 position_slide = ;

slide-25
SLIDE 25

#5 Latent types for linear algebra.

in mat4 bunny_model; in vec4 position; in vec4 normal; bunny_model * position vec4 position_slide = ; bunny_model * normal; vec4 normal_slide = normal_slide - position_slide normal - position_slide

slide-26
SLIDE 26

#5 Latent types for linear algebra. ⇒ Use a type system to track the space for each vector. ⇒ Synthesize matrix–vector multiplications to declaratively obtain a vector in the right space.

slide-27
SLIDE 27

#6 Visual correctness.

slide-28
SLIDE 28

#6 Visual correctness. 10 months!

slide-29
SLIDE 29

#6 Visual correctness. ⇒ Apply work on live coding to shorten the debug cycle. ⇒ Apply crowdsourcing to evaluate visual quality.

slide-30
SLIDE 30

Application “Engine” GPU programming interface portable hardware abstraction

slide-31
SLIDE 31

Application “Engine” GPU new programming models?

slide-32
SLIDE 32

https://twitter.com/ID_AA_Carmack/status/851397231320150017

slide-33
SLIDE 33

Special thanks to: Kathryn McKinley Todd Mytkowicz Yong He Kayvon Fatahalian Tim Foley Pat Hanrahan