Closed TheNosiriN closed 2 years ago
Just to show that I have compiled a similar compute shader before. This is the same compute shader but with few things changed and it compiles:
#version 460
layout(local_size_x = 1, local_size_y = 1) in;
layout(binding = 0, r32f) uniform image2D colordepthTex;
layout(binding = 1, rgba32f) uniform image2D uvTex;
layout(push_constant) uniform Camera {
vec2 frame_size;
mat4 projection;
mat4 view;
};
layout(std430, binding = 0) buffer Positions {
vec3 pos_buffer[];
};
vec3 rayDirection(float fieldOfView, vec2 size, vec2 fragCoord) {
vec2 xy = fragCoord - size / 2.0;
float z = size.y / tan(radians(fieldOfView) / 2.0);
return normalize(vec3(xy, -z));
}
vec2 rayBox(vec3 origin, vec3 direction, vec3 cMin, vec3 cMax) {
vec3 tMin = (cMin - origin) / direction;
vec3 tMax = (cMax - origin) / direction;
vec3 t1 = min(tMin, tMax);
vec3 t2 = max(tMin, tMax);
float tNear = max(max(t1.x, t1.y), t1.z);
float tFar = min(min(t2.x, t2.y), t2.z);
return vec2(tNear, tFar);
}
#define R frame_size
void main() {
vec2 C = vec2(gl_GlobalInvocationID.xy);
vec2 uv = (C - R/2.) - min(R.x, R.y);
vec3 dir = normalize(vec3(uv,1.0));//rayDirection(35.0, frame_size, vec2(C));
vec3 worldDir = ((view) * vec4(dir, 0.0)).xyz;// * .5+.5;
vec3 normal;
float dp = rayBox(vec3(0.0), vec3(0.0), vec3(1.0), vec3(1.0)).y;
// imageStore(colordepthTex, ivec2(C), vec4(1.0));
imageStore(uvTex, ivec2(C), vec4(dp));
}
This is the output GLSL:
#version 330 es
layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, std430) buffer Positions
{
vec3 pos_buffer[];
} _143;
layout(std140) uniform Camera
{
vec2 frame_size;
mat4 projection;
mat4 view;
} _80;
layout(binding = 1, rgba32f) uniform writeonly highp image2D uvTex;
layout(binding = 0, r32f) uniform readonly writeonly highp image2D colordepthTex;
vec2 rayBox(vec3 origin, vec3 direction, vec3 cMin, vec3 cMax)
{
vec3 tMin = (cMin - origin) / direction;
vec3 tMax = (cMax - origin) / direction;
vec3 t1 = min(tMin, tMax);
vec3 t2 = max(tMin, tMax);
float tNear = max(max(t1.x, t1.y), t1.z);
float tFar = min(min(t2.x, t2.y), t2.z);
return vec2(tNear, tFar);
}
void main()
{
vec2 C = vec2(gl_GlobalInvocationID.xy);
vec2 uv = (C - (_80.frame_size / vec2(2.0))) - vec2(min(_80.frame_size.x, _80.frame_size.y));
vec3 dir = normalize(vec3(uv, 1.0));
vec3 worldDir = (_80.view * vec4(dir, 0.0)).xyz;
vec3 param = vec3(0.0);
vec3 param_1 = vec3(0.0);
vec3 param_2 = vec3(1.0);
vec3 param_3 = vec3(1.0);
float dp = rayBox(param, param_1, param_2, param_3).y;
imageStore(uvTex, ivec2(C), vec4(dp));
}
Are you sure you're not hitting any ABI issues with mismatched headers and such? Every time this has come up that has been the cause. Does it reproduce with the standalone CLI?
I didn't even think about using the CLI.
I wrote SPIRV binary to a file the tried it using the CLI on release build and it compiles the shader just fine.
So it's a problem on my end. I downloaded the August 30 build again, rebuilt it completely using the release setting from cmake, copied the headers and built libraries, but it still crashes.
I tried something else, I commented out the GlslangToSpv
(Vulkan GLSL compiler code) part of my code, then I loaded in the spirv binary file that I had already generated using that code then used the spirv_cross::CompilerGLSL
on it and it compiled successfully.
But the weird part is that its only when I comment out the code that generates SPIRV binary that it works for any shader now.
Are you trying to link against a pre-built library that was built with a different toolchain?
No. I am building the project using cmake with release config, then I copy the libraries that built straight to my project for linking.
I tried something else. I tried using google's shaderc for the SPIRV compilation part but I also get the same result, it crashes when I use the spirv compiler but it doesn't crash when I comment it out and just read from the previous .spv file
Is it that I can't use a glsl to spirv compiler and spirv cross in the same program? Do you think I should make them seperate programs then output a temporary binary file to pass around?
After a couple hours of frustration, I tried using the C api library and I found out that everything works just fine with it. I think I'm going to continue with it.
Hi, I've been using SPIRV for quite some time now and it was working perfectly fine. I make a shader in Vulkan GLSL then generate ESSL 3.3 (OpenGL ES shading language) from the SPIRV binary, it has been working without problems until I made this compute shader:
I am using the August 30th codebase and using release libraries. The shader makes the SPIRV cross compiler crash at random times, I would insert a new function then it crashes, I would comment out a line and it would crash, random little things would make it crash. Currently the shader above crashes the GLSL compiler.
After running it with WinDbg, I see this call site at the crash point:
I am able to see the values of the data members of the spirv_cross::CompilerGLSL object at the crash point but I don't know how to export it to show here so I will take screenshots of it if needed.
This is the code where I am invoking compile. It's nothing advanced so I think this is sufficient.
The size printed is 1173 so the binary is not empty. I do not believe it is a bug that makes it crash with that compute shader, the shader is fairly simple, it might even problem on my end but I do not know where to start to fix this.
Edit: the above compute shader compiles successfully on CompilerHLSL with shader model 6.6