vkFX: Effect(ive) approach for
Vulkan API
Tristan Lorach
tlorach@nvidia.com
Intent
NVIDIA cares on encouraging new technologies like Vulkan
help engineers adoption
Give out tools, samples (Open-Source)
Game Engine : baking Shaders and states
CAD/DCC : loading at runtime Shader Effects
Prototyping : experiment on shaders and visual effects
Research : help using Vulkan API
Learn : discover Vulkan
Inspire : share concepts and idea from vkFx
What is ‘vkFx’ ?
Coherent and readable Graphic API’s component Description
Render-states
Shaders (Snippets)
Resources
Maps to Vulkan API (you need to know Vulkan for next slides!)
Simplifies Vulkan usage, while keeping its strength
More Features for higher level of abstraction (Techniques and
Passes)
Available through
Runtime library  to load vkFX files at runtime
Offline compiler  Generating readable C++ ( ‘baking’ effects)
From CgFx to now…
~2003 : Cg and first HLSL shading introduced Effects (CgFX and
HLSLFx)
2014 : nvFx Open-source, as a layer on top of OpenGL and/or
D3D
But overall Interest of ‘Effect’ part was questionable :
no pre-validation of Render-States + Shaders in OpenGL / D3D
2016: DX12 and Vulkan
Pre-Validation Now a First Vulkan’s feature
Could allow better implementation of ‘Effects’
2017 : vkFx pre-release as Open-Source (soon this year)
Check https://github.com/tlorach/vkFX (or contact me)
What can you do with it ?
… Pretty much everything that Vulkan API allows to do…
complex scenes passes
- complex materials and lighting
Techniques and Passes
Effect
file
Shader func’s
Sampler-states
Parameters
Techniques
Passes
states
Texture Samplers
Textures (D3D)
GPU
…
• Validate passes (builds shaders)
• Execute Passes
• Bind shaders, states & resources
Compiler Application
Scene
Shaders
Render
states
Resources
Meshes
Shaders
Render
states
Resources
1
Example : HDR Rendering With Glow
Render
Skybox in HDR
Render The
Scene in HDR
Down-scale the
texture 2x, 4x
Blur texture
Horizontal
Then Vertical
Scene Effect
1
2
3
4
5
6
Material Tech.1
Metal Pass
Material Tech.2
Plastic pass
Scene Graph
More…
RGBA32F
Texture
(HDR)
Compositing:
tone-mapping
And radial Blur
7
RGBA
32F
Texture
Backbuffer
+
23
4
5 677
Example : Compute Post-Processing
Render
Skybox
Render The
Scene
Triggers a
Compute
Kernel
Display result
As a fullscreen
Quad
Scene Effect passes
1
2
3
4
Material Effect 1
Metal Pass
Material Effect 2
Plastic pass
Scene Graph
Other ‘Effects’…
RGBA
Texture
Backbuffer
Fire (Navier-Stokes equations)
Simulation passes
Advect Color
Advect Velocity
Vorticity
Confinement
Emit
(Gaussian ball)
Fire Up-force
Vel. divergence
Comp. pressure
Proj. Velocity
Proj. Vel. edges
Technique
Techniques
passes
1
Volume bound 1
Volume bound 2
Volume depth
2
Volume depth
Smoke Ray-cast
Water Ray-cast
Fire Ray-cast
3
Rasterize result
Rasterize
4
Inside a vkFX file
vkFX file
Sampler-states
Techniques
Passes
VertexInputState
DescriptorSetLayout
Framebuffer
Image (texture…)
Structure decl.
Buffers
(Uniforms, vertex, index…)
DescriptorSet
RenderPass
GraphicsPipeline
(PSO)
Shader Modules
(snippets of code)
GLSL
GLSL-Compute
Later: CUDA (?)
PipelineLayout
PipelineRasterizationState
PipelineColorBlendState
PipelineDepthStencilState
PipelineMultisampleState
PipelineViewportState
Variables
~== Vulkan Objects
vkFx Features
vkFX Effect Integration
Application
vkFX files
…
Shader codeShader code
Techs/passesTechs/passes
Application
vkFX files
Shader codeShader code
Techs/passesTechs/passes
…
compiled
shaders
Vulkan
objects
Vulkan
objects
Offline
Compiler
vkFX
runtime
Pre-
compiled
shaders
Techs/passesStates
Shader codeStates
C++
vkFX
Effects
vkFX
runtime
API Design
Front-End : parser (Bison)
Parses the vkFX file
Does not parse the shader/compute
code inside !
Back-End : the library to build the
effect & Vulkan objects
Used by the Front-End to build data
from vkFx file
Used by the application to drive the
effects and Vulkan Objects
Works on PC
soon on Linux and Android
Front-End
(vkFX parser)
Back-End
(vkFX runtime)
API
Application Offline compiler
Two Ways to Use vkFX
Using Techniques & Passes (== a.k.a Effects)
Take advantage of higher level management of Vulkan objects
Passes will initialize and validate what is needed for them to work
Using vkFx descriptions as a “bag” of Vulkan Objects
Initialize them
Use them directly
vkFx becomes is a simple way to declare Vulkan Objects
vkFX Code Example
Vulkan Objects Declaration: Graphics Pipeline
Note:
PSO (Pipeline-State-Object) Graphics Pipeline
(combination of render-states, including shaders)
Vulkan Objects Declaration : PipelineLayout
Vulkan Objects Declaration : Shaders
Vulkan Objects Declaration : Input State;
Viewport
Vulkan Objects Declaration : Render-States
Technique & Pass Declaration
Technique & Pass : Graphics-Pipeline (PSO)
Technique & Pass : Renderpass
Technique & Pass : Framebuffer target
Technique & Pass : Desc. Set
Technique & Pass : Dynamic States
Note: Custom vkFx variables
• Variables can change at Runtime
• Will flag “dirty” any dependent object
 example: when resizing Windows…
Technique & Pass : Vulkan calls
vkCmdBeginRenderPass(…)
calls
 vkCmdEndRenderPass(…) (if needed)
 vkBeginCommandBuffer(…)
calls vkBeginCommandBuffer(…)
vkCmdBindPipeline(…)
vkCmdSetViewport(…)
vkCmdSetScissors(…)
vkCmdBindDescriptorSets(…)
Technique::begin()
Technique::end()
Pass::execute(…)
Pass::execute(…)
Pass::execute(…)
Technique & Pass : RenderMode
Technique & Pass : RenderMode
‘status’ contains the ID of
the PSO (Graphics-
Pipeline)
‘execute’ will pick the right
instance from ‘status’ that
matches the expected
PSO
Scene-Level / Multi-Level Effects
pre/post-processing are Effects, too : Scene-Level Effect
Material on a mesh can be an Effect : Primitive/Material-Level
Scene-level Effects and Material Effects must be consistent
How material works with “Deferred shading” ?
Shadowing of the scene ?
How Material takes lighting defined at Scene level ?
vkFX helps to prepare the combinatorial of Material-Techniques
 Scene-Level techniques
Material-Level shaders/PSO created for the needs of the Parent Scenes
 Generates instances of shaders; States (PSO) and resource update
Metal Pass
PSO Override (b)
Pass 2: Scene
PSO (A)
Combinatorial Of Effects
Pass 1:
Skybox in HDR
Scene Effect
Material Tech.1
FS
1
FS
5
VS
1
IL1
FS
2
FS
3
VS
2
DS
[0]
…
FS
11
DS
[1]
IL2
Metal Pass
PSO Instance (Ab)
Material Tech.1 for
Effect 1 / Pass 2
FS
11
DS
[1]
IL2
FS
5
VS
1
VS
2
DS
[0]
Combinatorial Of Effects
Pass 2: Scene
PSO (A)
Pass 1:
Skybox in HDR
Scene Effect 1
…
Metal Pass
PSO Override (b)
Material Tech.M2
Metal Pass
PSO Override (b)
Material Tech.M1
Metal Pass
PSO Override (b)
Material Tech.M2
Metal Pass
PSO Override (b)
Material Tech.M1
Scene Effect 2
Pass 2: Scene
PSO (B)
Metal Pass
PSO Override (b)
Material Tech.M1
Metal Pass
PSO Override (b)
Material Tech.M2
For Scene Effect 1
For Scene Effect 2
Scope where
This Technique
Can Apply
(combinatorial)
Mixing 2 Levels of Techniques
“VoronoiMaterial” overrides parts of the PSO
Of the Scene-level PSO (“meshTriPSO”)
referenced by the Scene-Pass
 Redefines some snippets of GLSL Code
 Redefines some Parameters
 Generates hybrid PSO from the mix
Offline Compiler
How it works and what does it do
Parses vkFx
Generates C++ source code
generated code is Readable, clean and commented
Generates Spir-V code (+GLSL Stitched code)
Vulkan Objects : code for initialization / Instantiation; destruction
Techniques and Passes : Initialization; execution;
Stitches Snippets of Shaders
Raises Compilation errors on GLSL Stitched shaders
Raises Vulkan Object creation Errors
Offline compiler tries to create objects with Vulkan Debug layers
How To Use
C++ Invocation of vkFx Techniques
1. Choose a Technique, Initialize it
2. Loop in passes and Execute Passes
 vkFx Contributes to Command-buffer feeding (vkCmd…)
 vkFx May start a render-pass or go to the next sub-pass
3. feed the command-buffer with drawcalls etc.
4. Loop to the next Pass, if needed
5. End the Technique (might end the render-pass)
How To Use vkFX: Direct Use Of Components
Near Goals / Future Work
Release it as Open-Source (Github) in a month from now
Check https://github.com/tlorach/vkFX (or contact me)
Consolidate the Parser’s source code
Vulkan objects Validation through Vulkan debug layers
Finalize vkFx runtime library
vkFX to expose NVIDIA extensions
Add a “Simple Effect Mode”
User doesn’t need to precisely define Vulkan components
Compiler build missing parts using default patterns
Thank You
pre-release as Open-Source
Check https://github.com/tlorach/vkFX (or contact me)
Feedback : tlorach@nvidia.com

vkFX: Effect(ive) approach for Vulkan API

  • 1.
    vkFX: Effect(ive) approachfor Vulkan API Tristan Lorach tlorach@nvidia.com
  • 2.
    Intent NVIDIA cares onencouraging new technologies like Vulkan help engineers adoption Give out tools, samples (Open-Source) Game Engine : baking Shaders and states CAD/DCC : loading at runtime Shader Effects Prototyping : experiment on shaders and visual effects Research : help using Vulkan API Learn : discover Vulkan Inspire : share concepts and idea from vkFx
  • 3.
    What is ‘vkFx’? Coherent and readable Graphic API’s component Description Render-states Shaders (Snippets) Resources Maps to Vulkan API (you need to know Vulkan for next slides!) Simplifies Vulkan usage, while keeping its strength More Features for higher level of abstraction (Techniques and Passes) Available through Runtime library  to load vkFX files at runtime Offline compiler  Generating readable C++ ( ‘baking’ effects)
  • 4.
    From CgFx tonow… ~2003 : Cg and first HLSL shading introduced Effects (CgFX and HLSLFx) 2014 : nvFx Open-source, as a layer on top of OpenGL and/or D3D But overall Interest of ‘Effect’ part was questionable : no pre-validation of Render-States + Shaders in OpenGL / D3D 2016: DX12 and Vulkan Pre-Validation Now a First Vulkan’s feature Could allow better implementation of ‘Effects’ 2017 : vkFx pre-release as Open-Source (soon this year) Check https://github.com/tlorach/vkFX (or contact me)
  • 5.
    What can youdo with it ? … Pretty much everything that Vulkan API allows to do… complex scenes passes - complex materials and lighting
  • 6.
    Techniques and Passes Effect file Shaderfunc’s Sampler-states Parameters Techniques Passes states Texture Samplers Textures (D3D) GPU … • Validate passes (builds shaders) • Execute Passes • Bind shaders, states & resources Compiler Application Scene Shaders Render states Resources Meshes Shaders Render states Resources
  • 7.
    1 Example : HDRRendering With Glow Render Skybox in HDR Render The Scene in HDR Down-scale the texture 2x, 4x Blur texture Horizontal Then Vertical Scene Effect 1 2 3 4 5 6 Material Tech.1 Metal Pass Material Tech.2 Plastic pass Scene Graph More… RGBA32F Texture (HDR) Compositing: tone-mapping And radial Blur 7 RGBA 32F Texture Backbuffer + 23 4 5 677
  • 8.
    Example : ComputePost-Processing Render Skybox Render The Scene Triggers a Compute Kernel Display result As a fullscreen Quad Scene Effect passes 1 2 3 4 Material Effect 1 Metal Pass Material Effect 2 Plastic pass Scene Graph Other ‘Effects’… RGBA Texture Backbuffer
  • 9.
    Fire (Navier-Stokes equations) Simulationpasses Advect Color Advect Velocity Vorticity Confinement Emit (Gaussian ball) Fire Up-force Vel. divergence Comp. pressure Proj. Velocity Proj. Vel. edges Technique Techniques passes 1 Volume bound 1 Volume bound 2 Volume depth 2 Volume depth Smoke Ray-cast Water Ray-cast Fire Ray-cast 3 Rasterize result Rasterize 4
  • 10.
    Inside a vkFXfile vkFX file Sampler-states Techniques Passes VertexInputState DescriptorSetLayout Framebuffer Image (texture…) Structure decl. Buffers (Uniforms, vertex, index…) DescriptorSet RenderPass GraphicsPipeline (PSO) Shader Modules (snippets of code) GLSL GLSL-Compute Later: CUDA (?) PipelineLayout PipelineRasterizationState PipelineColorBlendState PipelineDepthStencilState PipelineMultisampleState PipelineViewportState Variables ~== Vulkan Objects vkFx Features
  • 11.
    vkFX Effect Integration Application vkFXfiles … Shader codeShader code Techs/passesTechs/passes Application vkFX files Shader codeShader code Techs/passesTechs/passes … compiled shaders Vulkan objects Vulkan objects Offline Compiler vkFX runtime Pre- compiled shaders Techs/passesStates Shader codeStates C++ vkFX Effects vkFX runtime
  • 12.
    API Design Front-End :parser (Bison) Parses the vkFX file Does not parse the shader/compute code inside ! Back-End : the library to build the effect & Vulkan objects Used by the Front-End to build data from vkFx file Used by the application to drive the effects and Vulkan Objects Works on PC soon on Linux and Android Front-End (vkFX parser) Back-End (vkFX runtime) API Application Offline compiler
  • 13.
    Two Ways toUse vkFX Using Techniques & Passes (== a.k.a Effects) Take advantage of higher level management of Vulkan objects Passes will initialize and validate what is needed for them to work Using vkFx descriptions as a “bag” of Vulkan Objects Initialize them Use them directly vkFx becomes is a simple way to declare Vulkan Objects
  • 14.
  • 15.
    Vulkan Objects Declaration:Graphics Pipeline Note: PSO (Pipeline-State-Object) Graphics Pipeline (combination of render-states, including shaders)
  • 16.
  • 17.
  • 18.
    Vulkan Objects Declaration: Input State; Viewport
  • 19.
  • 20.
    Technique & PassDeclaration
  • 21.
    Technique & Pass: Graphics-Pipeline (PSO)
  • 22.
    Technique & Pass: Renderpass
  • 23.
    Technique & Pass: Framebuffer target
  • 24.
    Technique & Pass: Desc. Set
  • 25.
    Technique & Pass: Dynamic States Note: Custom vkFx variables • Variables can change at Runtime • Will flag “dirty” any dependent object  example: when resizing Windows…
  • 26.
    Technique & Pass: Vulkan calls vkCmdBeginRenderPass(…) calls  vkCmdEndRenderPass(…) (if needed)  vkBeginCommandBuffer(…) calls vkBeginCommandBuffer(…) vkCmdBindPipeline(…) vkCmdSetViewport(…) vkCmdSetScissors(…) vkCmdBindDescriptorSets(…) Technique::begin() Technique::end() Pass::execute(…) Pass::execute(…) Pass::execute(…)
  • 27.
    Technique & Pass: RenderMode
  • 28.
    Technique & Pass: RenderMode ‘status’ contains the ID of the PSO (Graphics- Pipeline) ‘execute’ will pick the right instance from ‘status’ that matches the expected PSO
  • 29.
    Scene-Level / Multi-LevelEffects pre/post-processing are Effects, too : Scene-Level Effect Material on a mesh can be an Effect : Primitive/Material-Level Scene-level Effects and Material Effects must be consistent How material works with “Deferred shading” ? Shadowing of the scene ? How Material takes lighting defined at Scene level ? vkFX helps to prepare the combinatorial of Material-Techniques  Scene-Level techniques Material-Level shaders/PSO created for the needs of the Parent Scenes  Generates instances of shaders; States (PSO) and resource update
  • 30.
    Metal Pass PSO Override(b) Pass 2: Scene PSO (A) Combinatorial Of Effects Pass 1: Skybox in HDR Scene Effect Material Tech.1 FS 1 FS 5 VS 1 IL1 FS 2 FS 3 VS 2 DS [0] … FS 11 DS [1] IL2 Metal Pass PSO Instance (Ab) Material Tech.1 for Effect 1 / Pass 2 FS 11 DS [1] IL2 FS 5 VS 1 VS 2 DS [0]
  • 31.
    Combinatorial Of Effects Pass2: Scene PSO (A) Pass 1: Skybox in HDR Scene Effect 1 … Metal Pass PSO Override (b) Material Tech.M2 Metal Pass PSO Override (b) Material Tech.M1 Metal Pass PSO Override (b) Material Tech.M2 Metal Pass PSO Override (b) Material Tech.M1 Scene Effect 2 Pass 2: Scene PSO (B) Metal Pass PSO Override (b) Material Tech.M1 Metal Pass PSO Override (b) Material Tech.M2 For Scene Effect 1 For Scene Effect 2
  • 32.
    Scope where This Technique CanApply (combinatorial) Mixing 2 Levels of Techniques “VoronoiMaterial” overrides parts of the PSO Of the Scene-level PSO (“meshTriPSO”) referenced by the Scene-Pass  Redefines some snippets of GLSL Code  Redefines some Parameters  Generates hybrid PSO from the mix
  • 33.
    Offline Compiler How itworks and what does it do Parses vkFx Generates C++ source code generated code is Readable, clean and commented Generates Spir-V code (+GLSL Stitched code) Vulkan Objects : code for initialization / Instantiation; destruction Techniques and Passes : Initialization; execution; Stitches Snippets of Shaders Raises Compilation errors on GLSL Stitched shaders Raises Vulkan Object creation Errors Offline compiler tries to create objects with Vulkan Debug layers
  • 34.
    How To Use C++Invocation of vkFx Techniques 1. Choose a Technique, Initialize it 2. Loop in passes and Execute Passes  vkFx Contributes to Command-buffer feeding (vkCmd…)  vkFx May start a render-pass or go to the next sub-pass 3. feed the command-buffer with drawcalls etc. 4. Loop to the next Pass, if needed 5. End the Technique (might end the render-pass)
  • 35.
    How To UsevkFX: Direct Use Of Components
  • 36.
    Near Goals /Future Work Release it as Open-Source (Github) in a month from now Check https://github.com/tlorach/vkFX (or contact me) Consolidate the Parser’s source code Vulkan objects Validation through Vulkan debug layers Finalize vkFx runtime library vkFX to expose NVIDIA extensions Add a “Simple Effect Mode” User doesn’t need to precisely define Vulkan components Compiler build missing parts using default patterns
  • 37.
    Thank You pre-release asOpen-Source Check https://github.com/tlorach/vkFX (or contact me) Feedback : tlorach@nvidia.com

Editor's Notes

  • #10 ~2500 C++ lines of code saved More code on vkFx file More flexibility outside of the C++ compiled part