Closed OetkenPurveyorOfCode closed 3 months ago
Hmm, yeah, looks like bugs in the sokol-shdc reflection parser code. The padding values are all messed up, and what's also strange is that float, vec2, vec3 arrays shouldn't be allowed at all (only vec4 and mat4).
...hmm, when I try to put a vec3 array into a uniform block I get this (expected) error:
cube-sapp.glsl:0:0: error: uniform block 'vs_params': arrays must be of type vec4[], ivec4[] or mat4[]
...I wonder how the float, vec2 and vec3 arrays actually make it through the shader compiler. Can you paste your complete shader code here?
Do you use the latest version of sokol-shdc?
PS: this was the commit which added those stricter array requirements and error checks (from Jan-2022):
https://github.com/floooh/sokol-tools/commit/54a99d8370ab280173d71d02d4fbe5a0e43fd31a
I thought I was, but maybe I used the wrong download link, I could not find a version info commandline flag for sokol-sdhc.exe.
But when I downloaded sokol-sdhc.exe from https://github.com/floooh/sokol-tools-bin/blob/master/bin/win32/sokol-shdc.exe again I get the correct error message:
cube-sapp.glsl:0:0: error: uniform block 'fs_params': arrays must be of type vec4[], ivec4[] or mat4[]
So I guess it's my bad for downloading an old version and humbly ask for forgiveness.
No problem! The easiest way to get the binaries is to simply clone the repository btw:
git clone --depth=1 https://github.com/floooh/sokol-tools-bin
For example the following in GLSL:
would compile to:
which would then result in the following warning when run in the debugger:
Worse still sometimes this error does not trigger but the uniforms are not all passed correctly:
which compiles to the following header:
But when I set the uniforms and render it, the uniform values are all messed up.
I noticed that when using vec4 arrays, the problem does not occur (my current workaround).
So am I doing something wrong, or is there something wrong in sdhc/sokol when calculating padding and alignment of the data structure, or are uniform arrays of types smaller than vec4 not supported? In that last case I would recommend adding a warning message to either sokol or sdhc.
Here is a full example (I modified cube-sapp.c):
with the following glsl
build with the following batchfile:
Which renders like this (not what I expected):![Screenshot 2024-03-15 002248](https://github.com/floooh/sokol/assets/64617476/5e9b5109-c3c2-44a1-891f-1041bdad7e4a)