cancel
Showing results for
Search instead for
Did you mean:

# OpenGL & Vulkan

Adept I

## Integer input with a function reqires floating point crashes GLSL compiler

I'm a Minecraft Java Edition's Optifine shader pack developer, and when I was helping others testing why a shader pack crash the whole game, I found the crash is caused by giving integer input to a function that reqires floating point.

Below is the crash related code. This only happens after 22.7.1, 22.5.2 works well.

``````struct ComplexFloat {
float r;
float i;
};
ComplexFloat ComplexAdd(ComplexFloat a, ComplexFloat b) {
return ComplexFloat(a.r + b.r, a.i + b.i);
}
ComplexFloat ComplexSub(float a, ComplexFloat b) {
return ComplexFloat(a - b.r, -b.i);
}
ComplexFloat ComplexMul(ComplexFloat a, ComplexFloat b) {
return ComplexFloat(a.r * b.r - a.i * b.i, a.i * b.r + a.r * b.i);
}
ComplexFloat ComplexLog(ComplexFloat z) {
//return ComplexFloat(log(sqrt(z.r * z.r + z.i * z.i)), atan(z.i, z.r));
return ComplexFloat(0.5 * log(z.r * z.r + z.i * z.i), atan(z.i, z.r));
}
ComplexFloat ComplexSqrt(ComplexFloat z) {
ComplexFloat ret;
float modulus = sqrt(z.r * z.r + z.i * z.i);
ret.r =             sqrt(max((modulus + z.r) * 0.5, 0.0));
ret.i = sign(z.i) * sqrt(max((modulus - z.r) * 0.5, 0.0));
return ret;
}

ComplexFloat ComplexArcsin(ComplexFloat z) {
// The 1 in ComplexSub(1, ComplexMul(z, z)) causes crash
z = ComplexLog(ComplexAdd(ComplexFloat(-z.i, z.r), ComplexSqrt(ComplexSub(1, ComplexMul(z, z)))));
return ComplexFloat(z.i, -z.r);
}``````

Crash log of JVM is too large so I wont upload a whole one, tho I will provide the core information I think that approves this is a GLSL compiler crash

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)

J 25077 org.lwjgl.opengl.GL20C.glCompileShader(I)V (0 bytes) @ 0x000002cdf91ba5e9 [0x000002cdf91ba5a0+0x0000000000000049]

J 25076 c1 org.lwjgl.opengl.GL20.glCompileShader(I)V (5 bytes) @ 0x000002cdf22a526c [0x000002cdf22a5220+0x000000000000004c]

Besides that, I noticed another issue with driver version above 22.7.1 that may difficult to reproduce : imageStore() does not truely write to certain images somethimes with Optifine randomly. In the same shader program, images that unable to write are same on different devices, but not same in different shader programs.

1 Solution
Big Boss

Could you please check the issue with the latest driver (Adrenalin 23.7.1 ) and let us know if the issue has been resolved?

Thanks.

11 Replies
Big Boss

Thank you for reporting it. I have whitelisted you and moved the post to the AMD OpenGL forum.

Please provide the setup information. I will report the issue to the OpenGL team.

Thanks.

I'v recieved crash reports from some people with different devices, looks like this is not related to setup but any AMD graphics card with driver above version 22.7.1 (including it) will suffer this issue.

Big Boss

Thanks for the above information. I have reported the issue to the OpenGL team. I will let you know once I get any feedback/update on this.

Thanks.

Big Boss

Just FYI, a bug ticket has been created to track this issue.

Thanks.

Big Boss

Here is the feedback from the OpenGL team:

`1. GLSL ES doesn't support implicit conversion, which means the function call param list with types should exactly match its declaration.2. But there's a chance to support this: enabling GL_EXT_shader_implicit_conversions extension in shader with version >= 310.It would be better to let the developers change their shader (enabling the ext with version >= 310) rather than we relax this core restriction in driver/compiler.Ref: OpenGL-Registry/EXT_shader_implicit_conversions.txt at main · KhronosGroup/OpenGL-Registry · GitHub https://registry.khronos.org/OpenGL/index_es.php#specs32 For imageStore() issue, we can't find helpful information through the description. It would be better to have a demo app that reproduces the issue. `

Thanks.

According to feedback, it looks like the new version of driver does not crash with integer to float implicit cast in function calls, thanks for your work (before the fix, we expect a log feedback tells us there is an invalid implicit cast, but not the game crash). I'll try finding someone to test with details of the imageStore issue as soon as possible.

Hi @dipak ,

This is a link to the example shader that can cause imageStore() issue:

https://1drv.ms/u/s!AkdRZmvQYMLMhzm7HFvn4veyj0z9?e=ki2vMj

Useage: Minecraft: Java Edition 1.17 or higher (1.19.2 is best) with Optifine installed, and load the shader provided in game settings.

Expected: game rendered correctly

What we get:

If we are using driver before 22.7.1, everything looks fine.

If we are using driver from 22.7.1 to the version before 23.2.1, we will get a black screen. This is caused by in this shader pack, shaders/composite5.csh cannot write to colorimg5 using imageStore(). RenderDoc shows that the image does not get changed at all.

If we are using driver 23.2.1, the game screen even freezes and cannot react anymore.

Big Boss

Thanks for sharing the above information. I will pass it on to the OpenGL team.

Big Boss

Could you please check the issue with the latest driver (Adrenalin 23.7.1 ) and let us know if the issue has been resolved?

Thanks.

Confirmed fixed, thank you and the whole team for your work!

Big Boss

Thanks for the confirmation.