CppCon 2018: Valentin Galea “Rapid Prototyping of Graphics Shaders in Modern C++”

preview_player
Показать описание


Traditionally it's been hard or downright impossible to have C++ on a GPU: Graphics Shaders are mainly done in GLSL/HLSL (C-like languages) and Compute Shaders only recently run it via CUDA/LLVM complex toolchains. This is not always desirable or available - mobile phones for ex. Turns out code can compile both as valid C++ and shader language with a bit of library writing effort. All you mostly need is equivalent 2D/3D/4D vector and matrix types.

What's the catch then? Swizzling! The shader vector allows addressing of its components both as [0], [1], [2] etc but also as .x, .y, .xyz, .zyx, .xxx and all possible combinations. The talk details how this can be achieved in modern C++, clean and in a generic way, without preprocessor tricks, and overcome language obstacles like template argument deduction with implicit conversions. After all the effort it's possible to prototype complex procedural effects at an interactive rate with full CPU-side debugging. Of course, a dedicated GPU will very quickly outpace this but loses the debugging, and some devices might not always produce correct results due to driver bugs.

As takeaway and showcase of what can be achieved with the C++ techniques presented I'll introduce Signed Distance Field functions modeling and some shaders that use it: Procedural Generated Planet, Volumetric Clouds simulation and some fun experiments: a Vinyl Turntable and an Egg On Bicycle!

Valentin Galea, Splash Damage
Lead Core Tech Programmer

Valentin Galea is a professional video game developer based in London, UK. He currently works at Splash Damage for projects such as the award-winning "Gears of War" franchise on Windows 10 and Xbox One. C++ enthusiast and evangelist, focused on systems, graphics and engine programming. He has 10+ years worth of experience, with past work ranging from MMO projects to mobile and handheld games. When he's not geeking out on games, he collects vinyl records.


*-----*
*-----*
Рекомендации по теме
Комментарии
Автор

Questions at the end: (sorry for not repeating them)

41:56 Are all your shaders using raymarching? How hard will be to interface with something that's using vertex arrays or the depth buffer?
 
42:45 If you look at the generated assembly code, I wonder how much the compiler takes the generated stuff and optimizes it? [...] The question is more for the complicated changes - would you get much more efficient performance with a good arch optimizer or you haven't looked into that?
 
44:04 How about running those unions for swizzling - would it cause any problems for debugging? [...] NOTE: the person talks about issues he has with GLM that's why I joke to use my library
 
45:38 What if you wanted to do texture sampling?
 
46:15 What's the performance on a GPU?
 
47:46 I might be getting myself mixed up with the more complicated shader behavior from GLSL 1 - Was it tricky at any points to make sure that you match the math functions from the shader really closely?

ValentinGalea
Автор

There's pros and cons to running GLSL on the CPU, but it sure has its uses and I am excited to see your approach to teaching C++ about shaders. I have been using GLM for quite some time and think it's great, but I can see how your code would clearly outperform it. Cool stuff.

krytharn
Автор

Great talk but we can't hear the questions from the audience at the end unfortunately.

Max-wkcg