SLIDE 1
Lets Fix OpenGL Adrian Sampson, Cornell Commands Pixels CPU GPU - - PowerPoint PPT Presentation
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 2
SLIDE 3
CPU GPU Display Commands Pixels
SLIDE 4
CPU Display Rendering Pipeline programmable & fixed-function stages
SLIDE 5
vertex positions pixel colors Vertex Shader Fragment Shader C, C++, JavaScript GLSL GLSL CPU
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
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
#1 Shader languages are subsets of supersets of C.
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
Like C #1 Shader languages are subsets of supersets of C. if (bool b = ...) { ... } are allowed. true false Declarations inside conditions
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
#1 Shader languages are subsets of supersets of C. ⇒ Apply work on language extensibility.
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
#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
#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
#3 Massive metaprogramming without hygiene.
SLIDE 17
#3 Massive metaprogramming without hygiene. Übershader
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
⇒ Scale up safe metaprogramming tools to generate thousands of shader variants. #3 Massive metaprogramming without hygiene.
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
#4 Missing general theory for execution rates. vertex fragment geometry tessellation render setup compile
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
#5 Latent types for linear algebra.
b u n n y s p a c e
teapot space
slide space
SLIDE 24
#5 Latent types for linear algebra.
in mat4 bunny_model; in vec4 position; bunny_model * position vec4 position_slide = ;
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
#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
#6 Visual correctness.
SLIDE 28
#6 Visual correctness. 10 months!
SLIDE 29
#6 Visual correctness. ⇒ Apply work on live coding to shorten the debug cycle. ⇒ Apply crowdsourcing to evaluate visual quality.
SLIDE 30
Application “Engine” GPU programming interface portable hardware abstraction
SLIDE 31
Application “Engine” GPU new programming models?
SLIDE 32
https://twitter.com/ID_AA_Carmack/status/851397231320150017
SLIDE 33