floooh / sokol-tools

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

sdhc crash #104

Closed danielchasehooper closed 5 months ago

danielchasehooper commented 11 months ago

running this command crashes sokol-shdc -l metal_macos -i crash.glsl -o shaderssdg.h

crash.glsl contains this

@vs layer_vs
void main(void) {
   gl_Position =  vec4(1);
}
@end

@fs layer_fs
uniform texture2D textures[12];
uniform sampler smp;

out vec4 FragColor;

void main(void) {
   FragColor = texture(sampler2D(textures[0 ], smp), vec2(1));
}
@end

@program layer layer_vs layer_fs

looks like there is an error for it, but in release builds the error message isn't shown, which seems wrong.

in spirv_cross_error_handling.hpp line 48

inline void
report_and_abort(const std::string &msg)
{
#ifdef NDEBUG
    (void)msg;
#else
    fprintf(stderr, "There was a compiler error: %s\n", msg.c_str());
#endif
    fflush(stderr);
    abort();
}
floooh commented 11 months ago

Yes this is a known issue which I need to take care of, see: https://github.com/KhronosGroup/SPIRV-Cross/issues/2177, there was basically an internal SPIRVCross error, but the error message isn't properly routed with C++ exceptions disabled.

(the issue in your code is however almost certainly the texture array, even if SPIRVCross would support this, sokol-gfx definitely won't, you'll need to use different texture uniforms, or alternatively a 2D-array-texture)

floooh commented 5 months ago

FYI I just fixed this in the storage-buffer branch, SPIRVCross now generates C++ exceptions which are caught and converted into a regular error message (for instance with your test shader it looks like this:

/Users/floh/projects/sokol-tools/test/issue_104.glsl:0:0: error: SPIRVCross exception: MSL 2.0 or greater is required for arrays of textures.

I'll close the ticket right away even though the fix won't land in master until the storage-buffer branch is merged.