floooh / sokol-tools

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

SIGABRT when slang=hlsl5 #123

Closed rsepassi closed 4 months ago

rsepassi commented 4 months ago
# ./sokol-shdc --input shader.glsl --output shader.h --slang hlsl5
The process was killed by SIGABRT: Abort trap: 6

Works fine when slang is glsl300es or metal_macos. The abort is hit on both Linux and Mac. The debug dump didn't show anything immediately obvious to me (i.e. no reported errors).

shader.glsl:

@vs vs

uniform vs_params {
    mat4 proj;
};

in vec2 pos;
in vec2 texuv;

out vec2 uv;

void main() {
    gl_Position = proj * vec4(pos, 0.0, 1.0) - vec4(1.0, 1.0, 0.0, 0.0);
    uv = texuv;
}

@end

@fs fs

uniform utexture2D tex;
@sampler_type smp nonfiltering
uniform sampler smp;
uniform fs_params {
    int alpha_only;
    vec3 color;
    vec2 tex_size;
};

in vec2 uv;

out vec4 pix;

void main() {
    vec2 norm_uv = vec2(uv.x / tex_size.x, 1.0 - uv.y / tex_size.y);
    uvec4 texval = texture(usampler2D(tex, smp), norm_uv);

    if (alpha_only != 0) {
      float alpha = float(texval.r) / 255.0f;
      if (alpha > 0) {
        pix = vec4(color, alpha);
      } else {
        discard;
      }
    } else {
      pix = vec4(texval) / 255.0f;
    }
}

@end

@program sprite vs fs

By the way, love this project and sokol_*. Thank you!

floooh commented 4 months ago

This is currently a known problem when an "internal" SPIRVCross error happens, normally SPIRVCross throws a C++ exception with error information, but without exceptions enabled it just panics without a useful error message when it encounters a problem.

In the storage-buffer branch I'm currently working on I have fixed this problem, but that's not merged yet into main (hopefully 'soon-ish' though). There I have enabled C++ exception and try-catch anything coming out of SPIRVCross and convert the exception into an error message (https://github.com/floooh/sokol-tools/blob/dade247a89c9b1a3e91e8c511d58dd3989d86928/src/shdc/spirvcross.cc#L497-L499).

If possible I would prefer to not cherry-pick this change into master because I changed the entire source code structure in that branch.

PS: let me check what error you're getting, one sec...

This is the SPIRVCross error (I guess you'll need to change the utexture2D into a regular texture2D), or maybe use something else than texture() to load the texture content, maybe textureFetch? I haven't tested this stuff yet though, expect some bumpiness...

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