floooh / sokol-tools

Command line tools for use with sokol headers
MIT License
219 stars 54 forks source link

unexpected compile error #125

Closed danielchasehooper closed 4 months ago

danielchasehooper commented 4 months ago

I'm not sure if this is a legitimate error with an incorrect line number, or what, but I'm getting this error: shader_sokol.glsl:0:0: error: ERROR: shader_sokol.glsl:4: 'non-opaque uniforms outside a block' : not allowed when using GLSL for Vulkan

side note: It seems strange that it has both shader_sokol.glsl:0:0: and shader_sokol.glsl:4:

reproduce with: shdc --ifdef -l glsl330:metal_macos:metal_sim:metal_ios:glsl300es -i shader_sokol.glsl -o shaders_sokol.h

shader_sokol.glsl:

@vs COMMON_VS

in vec3 vPosition;
// <-- this is the line the error is on
void main()
{
    gl_Position = vec4(vPosition, 1.0);
}

@end

@fs MAIN_SHADER_FS

uniform float iTime;
out vec4 finalColor;

void main()
{

    finalColor = vec4(1,0,0, 1);
}

@end

@program MAIN_SHADER COMMON_VS MAIN_SHADER_FS

since sokol-tools doesn't have version numbers heres the hash:

$ shasum -a 256 sokol-shdc 
ae4064824ea079d10cdc5e0aef8e3a11308ef4acc0b64add651194620f5f7037  sokol-shdc
floooh commented 4 months ago

The actual error is this line:

uniform float iTime;

...needs to be inside a uniform block. The line number issue will be fixed in a couple of days when the storage-buffer branch is merged. This had regressed for because sokol-shdc adds a variable number of #define lines at the front of GLSL snippets before they go into the GLSL=>SPIRV pass, and I didn't think of fixing the error- and warnings-line offsets (in the branch this has been rewritten to be more flexible instead of just applying a hardwired offset)