Open geekley opened 1 month ago
It is mostly just a game of words but godot doesn't use GLSL ES 3.0. It uses it's own language: Godot shading language... Which is yeah very similar to glsl
Anyway effectively godot doesn't have any "useful" pragmas and uses it only for disabling preprocessor so I agree that throwing error isn't a good approach.
@dustdfg Yes, but GDShader is based on GLSL ES 3.0, and it's been decided that the preprocessor behavior should aim to be GLSL-compatible where possible: https://github.com/godotengine/godot/issues/96253#issuecomment-2333734897
I brought up this Issue in the 2024-09-03 Rendering Meeting, these are the key points:
- Aim for glsl-like behavior, so that shaders can be ported over very easily [...]
And this is also the behavior in C preprocessor (GCC).
Tested versions
System information
Godot v4.3.stable (77dcf97d8) - Freedesktop SDK 23.08 (Flatpak runtime) - X11 - Vulkan (Forward+) - integrated Intel(R) HD Graphics 5500 (BDW GT2) - Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz (4 Threads)
Issue description
The GLSL ES 3.00 spec says on page 15:
I believe the whole point of
#pragma
is to allow forward-compatibility, by letting any unrecognized instructions be ignored. So I believe showing an error like "Invalid pragma directive" defeats the whole purpose, no? Invalid pragma lines should be ignored like how it is in the spec.In fact, both C and GLSL preprocessors don't complain at all if you add a custom pragma.
The spec also says:
So, I think it would also be beneficial to add something similar for mandatory directives that should raise error if unrecognized. For example, you could exceptionally raise the error if it starts with
#pragma required
:Note that both C and GLSL preprocessors leave the entire
#pragma
lines (after joining line continuations) in their output as well (unlike other directives such as#define
, etc. which are stripped out). Presumably, this could be to allow the compilation after the preprocessor to be affected by pragmas as well. So the ignoring behavior should be implemented in both the preprocessor and the lexer/parser after it, to account for potential usages that may extend beyond the preprocessor.Steps to reproduce
Of course, the error should still show for recognized pragma lines that are malformed:
Minimal reproduction project (MRP)
N/A