Closed hadronized closed 8 years ago
You may also consider Solution 4 – do nothing and work on something else.
I don’t understand the hate: text-based GLSL shaders are great, they’re cross-platform and cross-engine, you can copy whole chunks of them around, you can debug them directly using RenderDoc and have access to the original source code that you know and understand, instead of some generated intermediate code.
Interesting idea. The problem with string shaders is the fact they’re opaque at compilation and that static analysis is performed at runtime. I’m not sure whether I truly want that to happen without a compile-time pass to check the correctness of the code.
I'm with Sam on this one. Shader compilation happening at run-time is actually a blessing rather than a curse: you can write tools that let you live-edit your shader without rebuilding/restarting the engine. Especially for demoscene prods where you typically spend a lot of time tweakig shaders, it is a much bigger productivity win than having the guarantee that shaders build without running the engine.
I kinda disagree with that in the sense that tweaking shaders is not about changing code, it’s about changing values passed in as uniforms.
I really meant tweaking shaders as in modifying the source code (changing uniform values is not tweaking a shader). I am very surprised you don't do that all the time. How do you write new effects?
I write the shader code as GLSL and run / restart the program when I tweak the shader. Which can be tedious, that’s true, but it’s not that much compared to visual tweaks.
@phaazon IMHO if you can tweak your shaders by changing uniforms rather than changing the code, then they are very simple and they don’t actually need the compile-time verification you strive for.
Good point. :)
Ok, so, I’ll just leave the shaders as plain String
. There’s already pragma injection in the OpenGL backends (#version 330 core
for instance). The rest is YOLO.
Problem
We’re exposing the shader source code as
String
. I hate that. It’s opaque, it lives at runtime, it doesn’t scale (no cross-language support when writting shaders, no modules/libs). We have to find a way out of that situationSolution 1 – EDSL via macros
Writing an EDSL would solve that in the most elegant way. The idea is to have a set of types, functions and macros to help creating shader stages directly in rust. Such work is partially implemented in the lsl branch.
Advantages
Drawbacks
Solution 2 – DSL
We can have a DSL written in a language of our own. We would load it, parse it, compile it and turn it into a graphics executable at runtime. Exactly like we already do with GLSL.
Advantages
Drawbacks
String
, so as opaque as the current ;Solution 3 – EDSL via compiler plugins
From the reading of this, it should be possible to use the compiler plugins power of rustc to create directly the EDSL in rustc itself.
Advantages
Drawbacks
Which one to choose?