floooh / sokol-tools

Command line tools for use with sokol headers
MIT License
229 stars 57 forks source link

[sokol-shdc] `texture(usampler2D(...))` crashes the compiler #124

Closed jakubtomsu closed 5 months ago

jakubtomsu commented 6 months ago

The compiler terminates with exit code -1073740791 when I try to use texture() with a usampler2D. Of course this shouldn't work, but it should print an error instead of crashing. It fails with isampler2D as well. The error could suggest to use texelFetch instead.

This is not a major issue, the error is would be mostly helpful when refactoring or to prevent typos.

Repro:

@vs repro_vs
in vec2 attr_uv;
out vec2 vert_uv;
void main() {
    gl_Position = vec4(attr_uv * 2.0 - 1.0, 0.0, 1.0);
    vert_uv = attr_uv;
}
@end

@fs repro_fs
in vec2 vert_uv;
out vec4 frag_color;
uniform utexture2D tex;
@sampler_type smp nonfiltering
uniform sampler smp;
void main() {
    frag_color = vec4(texture(usampler2D(tex, smp), vert_uv));
}
@end

@program repro repro_vs repro_fs

Some info about my setup:

        OS:      Windows 10 Professional (version: 22H2), build 19045.4291
        CPU:     Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
        RAM:     32681 MiB
floooh commented 6 months ago

This will actually be fixed once the storage-buffer branch goes live (not in the sense that the shader is supported in HLSL, but that there's an actual error message).

It's an old known issue which was caused by C++ exceptions being disabled, SPIRVCross would then panic/crash instead of throwing a C++ excetion. The error message for your shader would then be this, which at least gives a hint what's wrong:

test.glsl:0:0: error: SPIRVCross exception: Sampling non-float textures is not supported in HLSL SM < 6.7.

The error happens down in SPIRVCross and seems to be HLSL specific, the other shader backends can compile the shader.

floooh commented 6 months ago

PS: also see https://github.com/floooh/sokol-tools/issues/123 (I closed this other ticket a bit prematurely even though the fix is currently only in a branch)