Hacker News new | ask | show | jobs
by nice_byte 3352 days ago
I don't think I fully understand the point about metaprogramming facilities. Sure, it would be nice to have compile-time ifs that get eliminated from the generated code if the condition isn't met. But I don't think this necessarily solves the problem of "combinatoric explosion" of different shader variants - you still have to generate a separate chunk of code for each possible combination of compile-time conditions. Unless a corresponding change is proposed at the level of shader bytecode (SPIR-V), which probably leads to opening a can of worms.
1 comments

Im fairly certain shaders can and do eliminate compile time if statements, you can observer this by seeing which uniforms are defined (for example in WebGL).
You mean if we write

if (some_constant_expression) { //...code... }

and some_constant_expression evaluates to false, the entire code block will be stripped from the result?

That may be true, but it's not standardized behavior, is it?

True for many compilers for many years. Its a way to integrate 'conditional compilation' into the normal program flow. It can make the code easier (or harder) to read. Use judiciously.