Pixel Bender â Building a Domain Specific Language on the ... - Nvidia
Pixel Bender â Building a Domain Specific Language on the ... - Nvidia Pixel Bender â Building a Domain Specific Language on the ... - Nvidia
- Page 2 and 3: Demo • Twirl • Radial blur •
- Page 4 and 5: What’s happening? © 2010 Adobe S
- Page 6 and 7: What’s happening? © 2010 Adobe S
- Page 8 and 9: What’s happening? • 3D system -
- Page 10 and 11: Pixel Bend
- Page 12 and 13: Pixel Bend
- Page 14 and 15: Pixel Bend
- Page 16 and 17: Code walkthrough kernel FadeToBlack
- Page 18 and 19: Code walkthrough kernel FadeToBlack
- Page 20 and 21: Code walkthrough kernel FadeToBlack
- Page 22 and 23: Code walkthrough kernel FadeToBlack
- Page 24 and 25: Code walkthrough kernel FadeToBlack
- Page 26 and 27: GLSL version of fade to black filte
- Page 28 and 29: Pixel Bend
- Page 30 and 31: Per-frame operations - evaluateDepe
- Page 32 and 33: Per-frame operations - evaluateDepe
- Page 34 and 35: Region reasoning Region Reasoning (
- Page 36 and 37: Region reasoning - changed © 2010
- Page 38 and 39: Region reasoning - needed © 2010 A
- Page 40 and 41: Region reasoning • Changed • I
- Page 42 and 43: Region reasoning • Domain
- Page 44 and 45: Compiler architecture © 2010 Adobe
- Page 46 and 47: Challenges • Wide range of hardwa
- Page 48 and 49: What can’t we do • Anything tha
- Page 50: © 2010 Adobe Systems Incorporated.
<str<strong>on</strong>g>Pixel</str<strong>on</strong>g> <str<strong>on</strong>g>Bender</str<strong>on</strong>g> – <str<strong>on</strong>g>Building</str<strong>on</strong>g> a <str<strong>on</strong>g>Domain</str<strong>on</strong>g> <str<strong>on</strong>g>Specific</str<strong>on</strong>g> <str<strong>on</strong>g>Language</str<strong>on</strong>g> <strong>on</strong> <strong>the</strong> GPU<br />
Bob Archer<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
1
Demo<br />
• Twirl<br />
• Radial blur<br />
• Oil paint filter<br />
• Droste<br />
• Fade to black<br />
• Mandelbulb<br />
• Ray tracer<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
2
What’s happening?<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
3
What’s happening?<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
4
What’s happening?<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
5
What’s happening?<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
6
What’s happening?<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
7
What’s happening?<br />
• 3D system – OpenGL + OpenGL Shading <str<strong>on</strong>g>Language</str<strong>on</strong>g><br />
• Ignore all of <strong>the</strong> vertex processing features<br />
• Draw <strong>on</strong>e single polyg<strong>on</strong> – rectangular, <strong>the</strong> size of <strong>the</strong> desired output<br />
• Run a fragment shader that computes <strong>the</strong> desired output<br />
• Fragments become square or rectangular pixels<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
8
Fragment shader programming model<br />
Write a functi<strong>on</strong> that produces a single output<br />
fragment<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
9
<str<strong>on</strong>g>Pixel</str<strong>on</strong>g> <str<strong>on</strong>g>Bender</str<strong>on</strong>g> programming model<br />
Write a functi<strong>on</strong> that produces a single output<br />
fragment pixel<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
10
<str<strong>on</strong>g>Pixel</str<strong>on</strong>g> <str<strong>on</strong>g>Bender</str<strong>on</strong>g> programming model<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
11
<str<strong>on</strong>g>Pixel</str<strong>on</strong>g> <str<strong>on</strong>g>Bender</str<strong>on</strong>g> programming model<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
12
<str<strong>on</strong>g>Pixel</str<strong>on</strong>g> <str<strong>on</strong>g>Bender</str<strong>on</strong>g> programming model<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
13
<str<strong>on</strong>g>Pixel</str<strong>on</strong>g> <str<strong>on</strong>g>Bender</str<strong>on</strong>g> programming model<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
14
Code walkthrough<br />
<br />
kernel FadeToBlack<br />
< namespace : "AIF test";<br />
vendor : "Adobe";<br />
versi<strong>on</strong> : 1;<br />
descripti<strong>on</strong> : "Fade out <strong>the</strong> image";<br />
><br />
{<br />
parameter float fade<br />
<<br />
minValue : 0.0;<br />
maxValue: 1.0;<br />
defaultValue : 1.0;<br />
>;<br />
input image4 src;<br />
output pixel4 dst;<br />
void<br />
evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>()<br />
{<br />
dst = sampleNearest(src,outCoord());<br />
dst.rgb *= fade;<br />
}<br />
}<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.
Code walkthrough<br />
kernel FadeToBlack<br />
{<br />
parameter float fade;<br />
input image4 src;<br />
output pixel4 dst;<br />
}<br />
void evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>()<br />
{<br />
dst = sampleNearest( src, outCoord() );<br />
dst.rgb *= fade;<br />
}<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.
Code walkthrough<br />
kernel FadeToBlack<br />
{<br />
parameter float fade;<br />
input image4 src;<br />
output pixel4 dst;<br />
}<br />
void evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>()<br />
{<br />
dst = sampleNearest( src, outCoord() );<br />
dst.rgb *= fade;<br />
}<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.
Code walkthrough<br />
kernel FadeToBlack<br />
{<br />
parameter float fade;<br />
input image4 src;<br />
output pixel4 dst;<br />
}<br />
void evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>()<br />
{<br />
dst = sampleNearest( src, outCoord() );<br />
dst.rgb *= fade;<br />
}<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.
Code walkthrough<br />
kernel FadeToBlack<br />
{<br />
parameter float fade;<br />
input image4 src;<br />
output pixel4 dst;<br />
}<br />
void evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>()<br />
{<br />
dst = sampleNearest( src, outCoord() );<br />
dst.rgb *= fade;<br />
}<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.
Code walkthrough<br />
kernel FadeToBlack<br />
{<br />
parameter float fade;<br />
input image4 src;<br />
output pixel4 dst;<br />
}<br />
void evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>()<br />
{<br />
dst = sampleNearest( src, outCoord() );<br />
dst.rgb *= fade;<br />
}<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.
Code walkthrough<br />
kernel FadeToBlack<br />
{<br />
parameter float fade;<br />
input image4 src;<br />
output pixel4 dst;<br />
}<br />
void evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>()<br />
{<br />
dst = sampleNearest( src, outCoord() );<br />
dst.rgb *= fade;<br />
}<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.
Code walkthrough<br />
kernel FadeToBlack<br />
{<br />
parameter float fade;<br />
input image4 src;<br />
output pixel4 dst;<br />
}<br />
void evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>()<br />
{<br />
dst = sampleNearest( src, outCoord() );<br />
dst.rgb *= fade;<br />
}<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.
Code walkthrough<br />
kernel FadeToBlack<br />
{<br />
parameter float fade;<br />
input image4 src;<br />
output pixel4 dst;<br />
}<br />
void evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>()<br />
{<br />
dst = sampleNearest( src, outCoord() );<br />
dst.rgb *= fade;<br />
}<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.
Code walkthrough<br />
kernel FadeToBlack<br />
{<br />
parameter float fade;<br />
input image4 src;<br />
output pixel4 dst;<br />
}<br />
void evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>()<br />
{<br />
dst = sampleNearest( src, outCoord() );<br />
dst.rgb *= fade;<br />
}<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.
Code walkthrough<br />
kernel FadeToBlack<br />
{<br />
parameter float fade;<br />
input image4 src;<br />
output pixel4 dst;<br />
}<br />
void evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>()<br />
{<br />
dst = sampleNearest( src, outCoord() );<br />
dst.rgb *= fade;<br />
}<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.
GLSL versi<strong>on</strong> of fade to black filter<br />
#define _PROFILE_TILED<br />
#define _PROFILE_NORMALIZED<br />
uniform vec2 _outOffset;<br />
uniform vec2 _out<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>Extent;<br />
uniform float fade;<br />
uniform sampler2D src_sampler;<br />
uniform vec2 src_offset;<br />
uniform vec2 src_delta;<br />
vec4 temp_dst;<br />
void main(void)<br />
{<br />
temp_dst = texture2D( src_sampler,<br />
( gl_TexCoord[0].xy * _out<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>Extent + _outOffset - src_offset ) * src_delta );<br />
temp_dst.rgb *= fade;<br />
gl_FragData[0] = temp_dst;<br />
}<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
26
GLSL versi<strong>on</strong> of fade to black filter<br />
#define _PROFILE_TILED<br />
#define _PROFILE_NORMALIZED<br />
uniform vec2 _outOffset;<br />
uniform vec2 _out<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>Extent;<br />
uniform float fade;<br />
uniform sampler2D src_sampler;<br />
uniform vec2 src_offset;<br />
uniform vec2 src_delta;<br />
vec4 temp_dst;<br />
void main(void)<br />
{<br />
temp_dst = texture2D( src_sampler,<br />
( gl_TexCoord[0].xy * _out<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>Extent + _outOffset - src_offset ) * src_delta );<br />
temp_dst.rgb *= fade;<br />
gl_FragData[0] = temp_dst;<br />
}<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
27
<str<strong>on</strong>g>Pixel</str<strong>on</strong>g> <str<strong>on</strong>g>Bender</str<strong>on</strong>g><br />
• At first glance, it looks a lot like GLSL, but…<br />
• Has many additi<strong>on</strong>s tuned towards image processing<br />
• N<strong>on</strong>-square pixels<br />
• Image offsets<br />
• Graphs<br />
• Per-frame operati<strong>on</strong>s (as opposed to per-pixel)<br />
• Regi<strong>on</strong> reas<strong>on</strong>ing<br />
• Remove some of <strong>the</strong> 3D boilerplate (but add 2D boilerplate)<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.
Graphs<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
29
Per-frame operati<strong>on</strong>s - evaluateDependents<br />
kernel Twirl<br />
{<br />
parameter float radius_in;<br />
parameter float2 center_in;<br />
parameter float twirl_angle_in;<br />
dependent float radius;<br />
dependent float2 center;<br />
dependent float twirl_angle;<br />
void evaluateDependents()<br />
{<br />
radius = radius_in * 256.0;<br />
center = center_in * 512.0;<br />
twirl_angle = twirl_angle_in * 2.0 * PI;<br />
}<br />
void evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>() ...<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
30
Per-frame operati<strong>on</strong>s - evaluateDependents<br />
kernel Twirl<br />
{<br />
parameter float radius_in;<br />
parameter float2 center_in;<br />
parameter float twirl_angle_in;<br />
dependent float radius;<br />
dependent float2 center;<br />
dependent float twirl_angle;<br />
void evaluateDependents()<br />
{<br />
radius = radius_in * 256.0;<br />
center = center_in * 512.0;<br />
twirl_angle = twirl_angle_in * 2.0 * PI;<br />
}<br />
void evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>() ...<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
31
Per-frame operati<strong>on</strong>s - evaluateDependents<br />
kernel Twirl<br />
{<br />
parameter float radius_in;<br />
parameter float2 center_in;<br />
parameter float twirl_angle_in;<br />
dependent float radius;<br />
dependent float2 center;<br />
dependent float twirl_angle;<br />
void evaluateDependents()<br />
{<br />
radius = radius_in * 256.0;<br />
center = center_in * 512.0;<br />
twirl_angle = twirl_angle_in * 2.0 * PI;<br />
}<br />
void evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>() ...<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
32
Per-frame operati<strong>on</strong>s - evaluateDependents<br />
kernel Twirl<br />
{<br />
parameter float radius_in;<br />
parameter float2 center_in;<br />
parameter float twirl_angle_in;<br />
dependent float radius;<br />
dependent float2 center;<br />
dependent float twirl_angle;<br />
void evaluateDependents()<br />
{<br />
radius = radius_in * 256.0;<br />
center = center_in * 512.0;<br />
twirl_angle = twirl_angle_in * 2.0 * PI;<br />
}<br />
void evaluate<str<strong>on</strong>g>Pixel</str<strong>on</strong>g>() ...<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
33
Regi<strong>on</strong> reas<strong>on</strong>ing<br />
Regi<strong>on</strong> Reas<strong>on</strong>ing<br />
(aka “Reas<strong>on</strong> Regi<strong>on</strong>ing”)<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
34
Regi<strong>on</strong> reas<strong>on</strong>ing - changed<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
35
Regi<strong>on</strong> reas<strong>on</strong>ing - changed<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
36
Regi<strong>on</strong> reas<strong>on</strong>ing - needed<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
37
Regi<strong>on</strong> reas<strong>on</strong>ing - needed<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
38
Regi<strong>on</strong> reas<strong>on</strong>ing - generated<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
39
Regi<strong>on</strong> reas<strong>on</strong>ing<br />
• Changed<br />
• I have changed this input regi<strong>on</strong>, what regi<strong>on</strong> of <strong>the</strong> output has changed?<br />
• Needed<br />
• I want this output regi<strong>on</strong>, what input regi<strong>on</strong>s do you need to have?<br />
• Generated<br />
• What output regi<strong>on</strong> are you going to give me without any o<strong>the</strong>r inputs?<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
40
Regi<strong>on</strong> reas<strong>on</strong>ing<br />
• <str<strong>on</strong>g>Domain</str<strong>on</strong>g> of definiti<strong>on</strong> (DOD) – “what have you got?”<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
41
Regi<strong>on</strong> reas<strong>on</strong>ing<br />
• <str<strong>on</strong>g>Domain</str<strong>on</strong>g> of definiti<strong>on</strong> (DOD) – “what have you got?”<br />
• Regi<strong>on</strong> of interest (ROI) – “what do you want?”<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
42
Regi<strong>on</strong> reas<strong>on</strong>ing<br />
• <str<strong>on</strong>g>Domain</str<strong>on</strong>g> of definiti<strong>on</strong> (DOD) – “what have you got?”<br />
• Regi<strong>on</strong> of interest (ROI) – “what do you want?”<br />
• ROI ∩ DOD “what we’ll actually calculate”<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
43
Compiler architecture<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
44
Adobe applicati<strong>on</strong>s using <str<strong>on</strong>g>Pixel</str<strong>on</strong>g> <str<strong>on</strong>g>Bender</str<strong>on</strong>g><br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.
Challenges<br />
• Wide range of hardware<br />
• Limits <strong>on</strong> instructi<strong>on</strong>s<br />
• Limits <strong>on</strong> instructi<strong>on</strong> counts<br />
• Limits <strong>on</strong> support for e.g. arrays<br />
• Limits <strong>on</strong> image size<br />
• N<strong>on</strong> IEEE float<br />
• Criticism that <strong>the</strong> range of hardware is too wide<br />
• Cross platform<br />
• Cross applicati<strong>on</strong><br />
• Drivers<br />
• Read back speed<br />
• Testing<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
46
Testing<br />
• Programming language – infinite input space<br />
• Automati<strong>on</strong><br />
• Data driven<br />
• Scripts to write tests<br />
• Testing intermediate representati<strong>on</strong>s<br />
• End to end tests<br />
• Fuzz testing<br />
• Test driven development<br />
• Test for errors<br />
• Use <strong>the</strong> documentati<strong>on</strong><br />
• Tools<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
47
What can’t we do<br />
• Anything that doesn’t fit our programming model<br />
• Histogram<br />
• Efficient box blur (and hence gaussian)<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
48
Where to go for informati<strong>on</strong><br />
• http://www.adobe.com/go/pixelbender_toolkit<br />
• http://twitter.com/pixelbender<br />
• http://blogs.adobe.com/kevin.goldsmith<br />
• Search for<br />
• <str<strong>on</strong>g>Pixel</str<strong>on</strong>g> <str<strong>on</strong>g>Bender</str<strong>on</strong>g><br />
• AIF<br />
• Adobe Image Foundati<strong>on</strong><br />
• <str<strong>on</strong>g>Pixel</str<strong>on</strong>g> <str<strong>on</strong>g>Bender</str<strong>on</strong>g> exchange<br />
• Community site for sharing <str<strong>on</strong>g>Pixel</str<strong>on</strong>g> <str<strong>on</strong>g>Bender</str<strong>on</strong>g> filters<br />
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.<br />
49
© 2010 Adobe Systems Incorporated. All Rights Reserved. Adobe C<strong>on</strong>fidential.