2_ray tracing api overview
TRANSCRIPT
Ray Tracing on the Wizard GPU
Luke Peterson Tobias Hector
3 @PowerVRInsider │ #idc16 facebook.com/imgtec
PowerVR GPU Architecture
PowerVR GR6500 System
Memory
Bus
Vertex Data
Master
Tiling Coprocessor
Compute Data
Master
Pixel Data
Master
Unified Shading Cluster Array
Coarse Grain
Scheduler
Host
CPU
Bus
Core Management
Unit
Control and Register Bus Host CPU Interface
Multi-level Memory
Cache Unit (MCU)
2D Core (TLA)
Pixel Coprocessor
System Memory Interface
(+ System-Level Cache for the whole GPU)
USC USC USC USC
Shared Texture Unit Shared Texture Unit
4 @PowerVRInsider │ #idc16 facebook.com/imgtec
PowerVR Ray Tracing Wizard Architecture
PowerVR GR6500 System
Memory
Bus
Vertex Data
Master
Tiling Coprocessor
Compute Data
Master
Pixel Data
Master
Scene Hierarchy Generator
Unified Shading Cluster Array
Coarse Grain
Scheduler
Host
CPU
Bus
Core Management
Unit
Control and Register Bus Host CPU Interface
Multi-level Memory
Cache Unit (MCU)
2D Core (TLA)
PowerVR Ray Tracing Unit (RTU)
Ray Intersection Processor
Coherency Engine
Ray Data
Master
Frame Accumulator
Cache
Pixel Coprocessor
System Memory Interface
(+ System-Level Cache for the whole GPU)
USC USC USC USC
Shared Texture Unit Shared Texture Unit
www.imgtec.com/idc
Ray tracing is the ability for the shader program for one object to be aware of the
geometry of other objects and trigger additional shaders for those objects.
6 @PowerVRInsider │ #idc16 facebook.com/imgtec
Uses of Ray Tracing
7 @PowerVRInsider │ #idc16 facebook.com/imgtec
Uses of Ray Tracing
8 @PowerVRInsider │ #idc16 facebook.com/imgtec
Uses of Ray Tracing
9 @PowerVRInsider │ #idc16 facebook.com/imgtec
Uses of Ray Tracing
10 @PowerVRInsider │ #idc16 facebook.com/imgtec
Uses of Ray Tracing
11 @PowerVRInsider │ #idc16 facebook.com/imgtec
Uses of Ray Tracing
12 @PowerVRInsider │ #idc16 facebook.com/imgtec
Uses of Ray Tracing
New Ray Tracing API!
14 @PowerVRInsider │ #idc16 facebook.com/imgtec
New Ray Tracing API
• We had OpenRL
• Solid Ray Tracing API
Goodbye OpenRL
15 @PowerVRInsider │ #idc16 facebook.com/imgtec
New Ray Tracing API
• We had OpenRL
• Solid Ray Tracing API
• However
• No integration with other GPU features
• Required reworking to expose new features
Goodbye OpenRL
16 @PowerVRInsider │ #idc16 facebook.com/imgtec
New Ray Tracing API
• We had OpenRL
• Solid Ray Tracing API
• However
• No integration with other GPU features
• Required reworking to expose new features
• So…
Goodbye OpenRL
18 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Tracing in OpenGL ES
• Why OpenGL ES 3.1?
• Already has base features
• Plugs in to existing SW solutions
• Integrates with other GPU features
• Well understood and available
Design Choices
19 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Tracing in OpenGL ES
• Why OpenGL ES 3.1?
• Already has base features
• Plugs in to existing SW solutions
• Integrates with other GPU features
• Well understood and available
• Modern paradigms
• Direct State Access
• App-managed resource lifetimes
• Bindless resources
Design Choices
20 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Tracing in OpenGL ES
• Scene Construction
• Hardware accelerated building
• Re-uses vertex shading
• Output streamed into a hierarchy
• Note: Vertex outputs are in world space
• Ray Traversal
• Emit rays into a scene
• Hardware accelerated traversal
• Shade at intersections
• Accumulate to images
API Overview
Scene Construction
22 @PowerVRInsider │ #idc16 facebook.com/imgtec
Scene Construction
• Scene components
• Equivalent to a “draw call”
• May be multiple “objects”
• Component groups
• Created from number of components
• Represent a scene hierarchy
Scene Components and Component Groups
3
3
2 1
23 @PowerVRInsider │ #idc16 facebook.com/imgtec
Scene Construction
• Building
• Components are descriptions
• Building executes vertex shaders
• Creates a scene hierarchy
• Merging
• Merge component groups together
• Cheaper than rebuilding
• Used to handle different rates of change
Building and Merging
24 @PowerVRInsider │ #idc16 facebook.com/imgtec
Scene Construction
• Rebuild parts of a scene at different rates
Building and Merging Illustration
25 @PowerVRInsider │ #idc16 facebook.com/imgtec
Scene Construction
• Rebuild parts of a scene at different rates
• Static geometry
Building and Merging Illustration
26 @PowerVRInsider │ #idc16 facebook.com/imgtec
Scene Construction
• Rebuild parts of a scene at different rates
• Static geometry
• Dynamic, per-frame
Building and Merging Illustration
27 @PowerVRInsider │ #idc16 facebook.com/imgtec
Scene Construction
• Rebuild parts of a scene at different rates
• Static geometry
• Dynamic, per-frame
• Other levels between the two
Building and Merging Illustration
28 @PowerVRInsider │ #idc16 facebook.com/imgtec
Scene Construction
• Rebuild parts of a scene at different rates
• Static geometry
• Dynamic, per-frame
• Other levels between the two
Building and Merging Illustration
29 @PowerVRInsider │ #idc16 facebook.com/imgtec
Scene Construction
• Rebuild parts of a scene at different rates
• Static geometry
• Dynamic, per-frame
• Other levels between the two
• All traversed as part of the same scene
Building and Merging Illustration
Incoming Ray
Ray Traversal
31 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal Ray Traversal Illustration
Frame
Scene
32 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal Ray Traversal Illustration
Frame
Scene
33 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal Ray Traversal Illustration
Frame
Scene
34 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
• What is a ray?
• A typed data packet
• Built-in values describe traversal
• May contain user-defined values
Ray Emission
raytypeIMG {
highp vec3 gl_OriginIMG,
highp vec3 gl_DirectionIMG,
highp float gl_MaxDistanceIMG,
lowp uint gl_SceneIMG,
bool gl_IsOutgoingIMG,
bool gl_RunPrefixProgramIMG,
highp rayprogramIMG gl_PrefixRayProgramIMG,
bool gl_OcclusionTestIMG,
mediump ivec2 gl_PixelIMG,
mediump uint gl_BounceCountIMG,
bool gl_FlipFacingIMG
};
35 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
• What is a ray?
• A typed data packet
• Built-in values describe traversal
• May contain user-defined values
Ray Emission
raytypeIMG {
highp vec3 gl_OriginIMG,
highp vec3 gl_DirectionIMG,
highp float gl_MaxDistanceIMG,
lowp uint gl_SceneIMG,
bool gl_IsOutgoingIMG,
bool gl_RunPrefixProgramIMG,
highp rayprogramIMG gl_PrefixRayProgramIMG,
bool gl_OcclusionTestIMG,
mediump ivec2 gl_PixelIMG,
mediump uint gl_BounceCountIMG,
bool gl_FlipFacingIMG
};
36 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
• What is it?
• Shader that runs at beginning of traversal
• Runs a user-defined number of invocations
• Purpose
• Setup and emission of primary rays for each invocation
Frame Shader
37 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
#version 310 es
layout(binding = 0) raytypeIMG PrimaryRay {};
layout(max_rays = 1) out;
out PrimaryRay primary;
layout(location = 0) uniform highp vec2 inverseFrameSize;
void main() {
initRayIMG(primary);
primary.gl_OriginIMG = vec3(0.0);
primary.gl_DirectionIMG = vec3((vec2(gl_FrameCoordIMG) * inverseFrameSize - 0.5).xy, -1.0);
primary.gl_PixelIMG = gl_FrameCoordIMG;
emitRayIMG(primary);
}
Frame Shader Example
38 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
#version 310 es
layout(binding = 0) raytypeIMG PrimaryRay {};
layout(max_rays = 1) out;
out PrimaryRay primary;
layout(location = 0) uniform highp vec2 inverseFrameSize;
void main() {
initRayIMG(primary);
primary.gl_OriginIMG = vec3(0.0);
primary.gl_DirectionIMG = vec3((vec2(gl_FrameCoordIMG) * inverseFrameSize - 0.5).xy, -1.0);
primary.gl_PixelIMG = gl_FrameCoordIMG;
emitRayIMG(primary);
}
Frame Shader Example
layout(binding = 0) raytypeIMG PrimaryRay {};
39 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
#version 310 es
layout(binding = 0) raytypeIMG PrimaryRay {};
layout(max_rays = 1) out;
out PrimaryRay primary;
layout(location = 0) uniform highp vec2 inverseFrameSize;
void main() {
initRayIMG(primary);
primary.gl_OriginIMG = vec3(0.0);
primary.gl_DirectionIMG = vec3((vec2(gl_FrameCoordIMG) * inverseFrameSize - 0.5).xy, -1.0);
primary.gl_PixelIMG = gl_FrameCoordIMG;
emitRayIMG(primary);
}
Frame Shader Example
layout(max_rays = 1) out;
40 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
#version 310 es
layout(binding = 0) raytypeIMG PrimaryRay {};
layout(max_rays = 1) out;
out PrimaryRay primary;
layout(location = 0) uniform highp vec2 inverseFrameSize;
void main() {
initRayIMG(primary);
primary.gl_OriginIMG = vec3(0.0);
primary.gl_DirectionIMG = vec3((vec2(gl_FrameCoordIMG) * inverseFrameSize - 0.5).xy, -1.0);
primary.gl_PixelIMG = gl_FrameCoordIMG;
emitRayIMG(primary);
}
Frame Shader Example
out PrimaryRay primary;
41 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
#version 310 es
layout(binding = 0) raytypeIMG PrimaryRay {};
layout(max_rays = 1) out;
out PrimaryRay primary;
layout(location = 0) uniform highp vec2 inverseFrameSize;
void main() {
initRayIMG(primary);
primary.gl_OriginIMG = vec3(0.0);
primary.gl_DirectionIMG = vec3((vec2(gl_FrameCoordIMG) * inverseFrameSize - 0.5).xy, -1.0);
primary.gl_PixelIMG = gl_FrameCoordIMG;
emitRayIMG(primary);
}
Frame Shader Example
primary.gl_OriginIMG = vec3(0.0);
initRayIMG(primary);
primary.gl_DirectionIMG = vec3((vec2(gl_FrameCoordIMG) * inverseFrameSize - 0.5).xy, -1.0);
primary.gl_PixelIMG = gl_FrameCoordIMG;
42 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
#version 310 es
layout(binding = 0) raytypeIMG PrimaryRay {};
layout(max_rays = 1) out;
out PrimaryRay primary;
layout(location = 0) uniform highp vec2 inverseFrameSize;
void main() {
initRayIMG(primary);
primary.gl_OriginIMG = vec3(0.0);
primary.gl_DirectionIMG = vec3((vec2(gl_FrameCoordIMG) * inverseFrameSize - 0.5).xy, -1.0);
primary.gl_PixelIMG = gl_FrameCoordIMG;
emitRayIMG(primary);
}
Frame Shader Example
emitRayIMG(primary);
43 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
• What is it for?
• Shading at ray intersections
• Executes when a ray hits geometry
• Similar to a fragment shader
• Capabilities
• Access incoming rays
• Access intersection result, including vertices
• Initialise and emit rays
• Accumulate to images
Ray Shader
44 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
#version 310 es
layout(binding = 0) raytypeIMG PrimaryRay {};
layout(location = 0, binding = 0, rgba8) uniform lowp accumulateonly image2D accumulationBuffer;
rayInputHandlerIMG(in PrimaryRay primary)
{
void main() {
imageAddIMG(accumulationBuffer, ivec2(primary.gl_PixelIMG), vec4(0.0, 0.5, 1.0, 1.0));
}
}
Ray Shader Example
45 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
#version 310 es
layout(binding = 0) raytypeIMG PrimaryRay {};
layout(location = 0, binding = 0, rgba8) uniform lowp accumulateonly image2D accumulationBuffer;
rayInputHandlerIMG(in PrimaryRay primary)
{
void main() {
imageAddIMG(accumulationBuffer, ivec2(primary.gl_PixelIMG), vec4(0.0, 0.5, 1.0, 1.0));
}
}
Ray Shader Example
rayInputHandlerIMG(in PrimaryRay primary)
46 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
#version 310 es
layout(binding = 0) raytypeIMG PrimaryRay {};
layout(location = 0, binding = 0, rgba8) uniform lowp accumulateonly image2D accumulationBuffer;
rayInputHandlerIMG(in PrimaryRay primary)
{
void main() {
imageAddIMG(accumulationBuffer, ivec2(primary.gl_PixelIMG), vec4(0.0, 0.5, 1.0, 1.0));
}
}
Ray Shader Example
layout(location = 0, binding = 0, rgba8) uniform lowp accumulateonly image2D accumulationBuffer;
47 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
#version 310 es
layout(binding = 0) raytypeIMG PrimaryRay {};
layout(location = 0, binding = 0, rgba8) uniform lowp accumulateonly image2D accumulationBuffer;
rayInputHandlerIMG(in PrimaryRay primary)
{
void main() {
imageAddIMG(accumulationBuffer, ivec2(primary.gl_PixelIMG), vec4(0.0, 0.5, 1.0, 1.0));
}
}
Ray Shader Example
imageAddIMG(accumulationBuffer, ivec2(primary.gl_PixelIMG), vec4(0.0, 0.5, 1.0, 1.0));
48 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
• 1st ray traced image today!
Draw One Triangle
49 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
• 1st ray traced image today!
• It’s a single triangle.
Draw One Triangle
50 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
• 1st ray traced image today!
• It’s a single triangle.
• Woo.
Draw One Triangle
51 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
• Draw a simple triangle
• No lighting
• No complex geometry
• Blue accumulated to image
• Only added once
• This line of code:
Draw One Triangle
imageAddIMG(accumulationBuffer, ivec2(primary.gl_PixelIMG), vec4(0.0, 0.5, 1.0, 1.0));
52 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal
• Bindless Ray Programs
• Semi-arbitrary shader execution
• Separate from ray intersection shading
• Separate to component ray shaders
• Not associated with geometry
• Specialised uses
• Has directly associated resources
Bindless Ray Shaders
53 @PowerVRInsider │ #idc16 facebook.com/imgtec
Ray Traversal Bindless Ray Shader Creation
// Attach a ray program to the program
glAttachShader(myRayProgram, myRayShader);
// Set the program to separable
glProgramParameter(myRayProgram, GL_PROGRAM_SEPARABLE, GL_TRUE);
// Link the program
glLinkProgram(myRayProgram);
// Bind some buffers to it
glRayProgramBufferRangeIMG(myRayProgram, GL_UNIFORM_BUFFER, 0, myUniformBuffer, 0, myUniformBufferSize);
// Create a bindless handle
GLuint64 myRayProgramHandle = glGetRayProgramHandleIMG(myRayProgram);
Default Ray Shaders
55 @PowerVRInsider │ #idc16 facebook.com/imgtec
Default Ray Shaders Default Ray Shader Illustration
Frame
Scene
56 @PowerVRInsider │ #idc16 facebook.com/imgtec
Default Ray Shaders
#version 310 es
layout(binding = 0) raytypeIMG PrimaryRay {};
layout(max_rays = 1) out;
out PrimaryRay primary;
layout(location = 0) uniform highp vec2 inverseFrameSize;
layout(location = 1) uniform highp rayprogramIMG defaultRayShader;
void main() {
initRayIMG(primary);
primary.gl_OriginIMG = vec3(0.0);
primary.gl_DirectionIMG = vec3((vec2(gl_FrameCoordIMG) * inverseFrameSize - 0.5).xy, -1.0);
primary.gl_PixelIMG = gl_FrameCoordIMG;
emitRayIMG(primary, defaultRayShader);
}
Frame Shader Example: Setting a default shader
defaultRayShader
layout(location = 1) uniform highp rayprogramIMG defaultRayShader;
57 @PowerVRInsider │ #idc16 facebook.com/imgtec
Default Ray Shaders
#version 310 es
layout(binding = 0) raytypeIMG PrimaryRay {};
layout(location = 0, binding = 0, rgba8) uniform lowp accumulateonly image2D accumulationBuffer;
rayInputHandlerIMG(in PrimaryRay primary)
{
void main() {
imageAddIMG(accumulationBuffer, ivec2(primary.gl_PixelIMG), vec4(1.0, 0.0, 0.0, 1.0));
}
}
Ray Shader Example: Default
vec4(1.0, 0.0, 0.0, 1.0))
58 @PowerVRInsider │ #idc16 facebook.com/imgtec
Default Ray Shaders
• Accumulates red on miss
• Default shader runs on miss
• Triangle not hit
• Better uses:
• Skyboxes
• World partitions
• Simple light sources
Draw One Triangle – Missed!
59 @PowerVRInsider │ #idc16 facebook.com/imgtec
Default Ray Shaders
• Can obviously do lots more!
• Things like…
More Interesting things
Prefix Ray Shaders
61 @PowerVRInsider │ #idc16 facebook.com/imgtec
Prefix Ray Shaders An illustration
62 @PowerVRInsider │ #idc16 facebook.com/imgtec
Prefix Ray Shaders An illustration
63 @PowerVRInsider │ #idc16 facebook.com/imgtec
Prefix Ray Shaders An illustration
Attach prefix shader
64 @PowerVRInsider │ #idc16 facebook.com/imgtec
Prefix Ray Shaders An illustration
Prefix Shader
Executes
65 @PowerVRInsider │ #idc16 facebook.com/imgtec
Prefix Ray Shaders An illustration
Prefix Shader
Executes
Distance Travelled In Cloud
66 @PowerVRInsider │ #idc16 facebook.com/imgtec
Prefix Ray Shaders An illustration
Intersection Shader
Executes
67 @PowerVRInsider │ #idc16 facebook.com/imgtec
Prefix Ray Shaders
#version 310 es
layout(binding = 0) raytypeIMG PrimaryRay {};
layout(max_rays = 1) out;
out PrimaryRay primary;
layout(location = 0) uniform highp vec2 inverseFrameSize;
layout(location = 1) uniform highp rayprogramIMG prefixRayShader;
void main() {
initRayIMG(primary);
primary.gl_OriginIMG = vec3(0.0);
primary.gl_DirectionIMG = vec3((vec2(gl_FrameCoordIMG) * inverseFrameSize - 0.5).xy, -1.0);
primary.gl_PixelIMG = gl_FrameCoordIMG;
primary.gl_PrefixRayProgramIMG = prefixRayShader;
primary.gl_RunPrefixRayProgramIMG = true;
emitRayIMG(primary);
}
Frame Shader Example: Setting a prefix shader
primary.gl_PrefixRayProgramIMG = prefixRayShader;
layout(location = 1) uniform highp rayprogramIMG prefixRayShader;
primary.gl_RunPrefixRayProgramIMG = true;
68 @PowerVRInsider │ #idc16 facebook.com/imgtec
Prefix Ray Shaders
#version 310 es
layout(binding = 0) raytypeIMG PrimaryRay {};
layout(max_rays = 1) PrimaryRay;
layout(location = 0, binding = 0, rgba8) uniform lowp accumulateonly image2D accumulationBuffer;
rayInputHandlerIMG(inout PrimaryRay primary)
{
void main() {
imageAddIMG(accumulationBuffer, ivec2(primary.gl_PixelIMG), vec4(0.0, 0.5, 0.0, 0.0));
primary.gl_RunPrefixProgramIMG = false;
shadeRayIMG(primary);
}
}
Prefix Ray Shader Example
shadeRayIMG(primary);
vec4(0.0, 0.5, 0.0, 0.0))
inout
layout(max_rays = 1) PrimaryRay;
primary.gl_RunPrefixProgramIMG = false;
69 @PowerVRInsider │ #idc16 facebook.com/imgtec
Prefix Ray Shaders
• Accumulated cyan
• Still running hit shader
• 0.5 Green added in prefix
• 0.5 Green and 1 blue added in hit
• Results in Cyan!
• Better uses:
• Clouds, smoke, water
• Other non-trivial mediums
Draw One Triangle – Prefixed!
Hybrid Ray Shading
71 @PowerVRInsider │ #idc16 facebook.com/imgtec
Hybrid Ray Shading
• TBDR Pipeline Recap
• Ignore most of it for now
• On-chip colour buffer!
Our GPU
Vertex
Processing
Clip, Project
& Cull
Geometry
Data
Tiling
Texture Data Frame Buffer
On-C
hip
Buff
ers
Primitive List
Vertex Data
Syste
m M
em
ory
Raster
*1
HSR & Depth
Test
On-Chip
Depth Buffer
Texture &
ShadeAlpha Test Alpha Blend
On-Chip
Colour Buffer
Tag Buffer
*2
72 @PowerVRInsider │ #idc16 facebook.com/imgtec
Hybrid Ray Shading
• Frame shader can access on-chip colour buffer
• If run at the end of a render
• Access PLS/Framebuffer Fetch as inputs only
Hybrid Pipeline
73 @PowerVRInsider │ #idc16 facebook.com/imgtec
Hybrid Ray Shading
• Rasterizer generates initial data
• Writes out G-Buffer into Pixel Local Storage
• Ray tracing for additional effects
• Shadows
• Reflections
• Etc.
• Post-process as normal
• Use accumulation buffers as input
How do you use hybrid?
74 @PowerVRInsider │ #idc16 facebook.com/imgtec
That’s not everything
• This was just an overview!
• Much more to talk about
• More talks!
• 11:50-12:20
• Real Time Ray Tracing Techniques
• 12:20-12:50
• Global Illumination, Progressive Light Map Baking, Fully Interactive GI
• 12:50-1:20
• Advanced Ray Tracing Techniques
We just scratched the surface
75 @PowerVRInsider │ #idc16 facebook.com/imgtec
Questions?
Get in touch:
• @tobskihectov
Please come and visit us at booth
#1902 in the South Hall to see our
demos and to collect your very own
Vulkan™ Gnome t-shirt!