Open geekley opened 3 months ago
In fact, why is this form even allowed at all?
Because it's comfortable to declare and define, as you stated. And it's indeed a syntax sugar. Changing it back to require a size will cause a huge compatibility breakage for the user shaders.
int[] d = {2}, e = {3, 4}; // Gives ERROR: Array size mismatch
This may be a subject to fix.
then I suggest instead telling the expected count in the error message
Will be fixed in https://github.com/godotengine/godot/pull/93822
I guess an array of nothings is also nothing. Still, there's no reason to allow it.
I've fixed it in https://github.com/godotengine/godot/pull/95276, interesting that It's still a valid GLSL code.
Thanks, @Chaosus . I have several questions about shader arrays.
So, are arrays in GDShader always more like structs containing just the data, and statically known size (implied, not stored in a field at runtime)? Instead of more like a pointer to data + length field with dynamic size?
Because since .length()
"method" exists, I'd assume it's most useful for the latter, meaning that implementation could be possible on size-less declarations like int[]
, also allowing it on return values, parameters, etc. so you could have e.g. functions that deal with sizes dynamically (similar to languages like C# and Java).
But since it's not supported (I think) then does that mean arrays can never have dynamic sizes? I guess this makes sense if you can't dynamically allocate like malloc/new. Or am I wrong and can it have dynamic size somehow (just an example) on something like void my_func(int size, float[size] array) {...}
(I can't remember if C allows something like this)?
Or perhaps "semi-dynamic" values like:
void my_func(int size) {
float[size] array = {...}; // somehow initialize all to zero or whatever
}
Also, what could be the max for arrays roughly speaking? I.e. something closer to e.g. 255 or to MAX_INT32? Is it related to stack size? GPU-dependent? How does that work?
@akien-mga @Chaosus I believe one of the bugs in the checklist is still unresolved, with no PR for it. Can you reopen?
Local variables of implied array size allowing non-arrays indirectly
You shouldn't be able to do this:
bool[] a = function_returning_non_array_bool();
Or was this fixed too?
Tested versions
Reproducible in:
In Godot 3, some constructs are not allowed, so it seems to only have the
const
function issue. So, partially reproducible in:System information
Godot v4.2.2.stable (15073afe3) - 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 Shader code below should give errors of various types, but it's being parsed as valid.
Problems:
const
qualifier before return typebuggy.gdshader
Steps to reproduce
Simply create a Shader file with the code above and note it shows no errors in Godot's Shader code editor. I did not make any tests whatsoever involving Visual Shader, I don't know if it's applicable.
Minimal reproduction project (MRP)
N/A
I was told to report the bug by @Chaosus on devel chat.