Hello,
I'm working on an engine called C3DE, it supports Windows and DesktopGL. Recently I've a serious issue with all my shaders for DesktopGL. The compilation from HLSL to GLSL is fine with the Pipeline tool. My code is well generated into XNB. However, when I try to use some of my shaders, it fails with a this message: An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module.
After some debugging, I found a part of the problem
The DrawIndexedPrimitives function will call many functions.
Link(Shader vs, Shader ps) in ShaderProgramCache.cs
GetShaderInfoLog in OpenGL.cs
- And finally
GetShaderInfoLogInternal
This is the last one which causes the crash. The Vertex Program is fine, it's hashkey is normal. However almost all my pixel shader have a negative hashkey and those ones failed to compile.
This is the pixel shader generated by Pipeline
#ifdef GL_ES
precision mediump float;
precision mediump int;
#endif
uniform vec4 ps_uniforms_vec4[4];
const vec4 ps_c4 = vec4(-1.0, 0.0, 1.0, 0.0);
const vec4 ps_c5 = vec4(-1.0, -2.0, -3.0, 0.0);
vec4 ps_r0;
vec4 ps_r1;
vec4 ps_r2;
vec4 ps_r3;
vec4 ps_r4;
#define ps_c0 ps_uniforms_vec4[0]
#define ps_c1 ps_uniforms_vec4[1]
#define ps_c2 ps_uniforms_vec4[2]
#define ps_c3 ps_uniforms_vec4[3]
uniform samplerCube ps_s0;
varying vec4 vTexCoord0;
#define ps_v0 vTexCoord0
#define ps_oC0 gl_FragColor
void main()
{
ps_r0.xy = ps_c4.xy;
ps_r0.x = ps_r0.x + ps_c3.x;
ps_r1.xyz = normalize(ps_v0.xyz);
ps_r1 = textureCube(ps_s0, ps_r1.xyz);
if (-ps_r0.x != ps_r0.x) {
ps_r2 = ps_c4.yyyy;
} else {
if (-ps_c1.x < ps_r0.y) {
ps_r0.z = ps_v1.x * ps_v1.x;
ps_r0.w = ps_c1.y * ps_c1.y;
ps_r0.z = ps_r0.z * ps_r0.w;
ps_r0.w = log2(ps_c0.x);
ps_r0.z = ps_r0.w * ps_r0.z;
ps_r0.z = exp2(ps_r0.z);
ps_r0.z = 1.0 / ps_r0.z;
ps_r3.x = fract(ps_c1.x);
ps_r3.y = ((-ps_r3.x >= 0.0) ? ps_c4.y : ps_c4.z);
ps_r0.y = ((ps_c1.x >= 0.0) ? ps_r0.y : ps_r3.y);
ps_r3.x = -ps_r3.x + ps_c1.x;
ps_r0.y = ps_r0.y + ps_r3.x;
ps_r3.x = ps_c1.y * ps_v1.x;
ps_r0.w = ps_r0.w * ps_r3.x;
ps_r0.w = exp2(ps_r0.w);
ps_r0.w = 1.0 / ps_r0.w;
ps_r3.xyz = ps_r0.yyy + ps_c5.xyz;
ps_r0.z = ((-abs(ps_r3.z) >= 0.0) ? ps_r0.z : ps_c4.z);
ps_r0.z = ((-abs(ps_r3.y) >= 0.0) ? ps_r0.w : ps_r0.z);
ps_r0.w = -ps_c1.z + ps_c1.w;
ps_r0.w = 1.0 / ps_r0.w;
ps_r3.y = ps_c1.w + -ps_v1.x;
ps_r0.w = ps_r0.w * ps_r3.y;
ps_r0.z = ((-abs(ps_r3.x) >= 0.0) ? ps_r0.w : ps_r0.z);
ps_r0.w = clamp(ps_r0.z, 0.0, 1.0);
ps_r0.y = ((-ps_r0.y >= 0.0) ? ps_r0.z : ps_r0.w);
ps_r0.z = -ps_r0.y + ps_c4.z;
ps_r0.yzw = (ps_r0.yyy * ps_r1.xyz) + ps_r0.zzz;
ps_r3.xyz = ps_r0.yzw * ps_c2.xyz;
ps_r3.w = ps_c4.z;
} else {
ps_r3 = ps_c4.yyyy;
}
ps_r4 = (ps_r1.xyzx * ps_c4.zzzy) + ps_c4.yyyz;
ps_r2 = ((-ps_c1.x >= 0.0) ? ps_r4 : ps_r3);
}
ps_oC0 = ((ps_r0.x >= 0.0) ? ps_r2 : ps_r1);
}
The original HLSL shader can be found here. I tried to [change few things] and now it works (https://github.com/demonixis/C3DE/blob/develop/C3DE.Demo/Content/Shaders/SkyboxEffect.fx).
How to reproduce
- Clone the develop branch of C3DE from github
- Open the C3DE.Desktop solution
- Open C3DE.Demos/Content/Shaders/SkyboxEffect.fx and force FOG_ENABLED to
True
- Start the samples and launch the VR demo (don't worry VR is disabled if you don't have a connected compatible headset).
- I recommand you to change references to use the sources of MonoGame.
Thank you.
Hello,
I'm working on an engine called C3DE, it supports Windows and DesktopGL. Recently I've a serious issue with all my shaders for DesktopGL. The compilation from HLSL to GLSL is fine with the Pipeline tool. My code is well generated into XNB. However, when I try to use some of my shaders, it fails with a this message:
An unhandled exception of type 'System.AccessViolationException' occurred in Unknown Module.After some debugging, I found a part of the problem
The
DrawIndexedPrimitivesfunction will call many functions.Link(Shader vs, Shader ps)in ShaderProgramCache.csGetShaderInfoLogin OpenGL.csGetShaderInfoLogInternalThis is the last one which causes the crash. The Vertex Program is fine, it's hashkey is normal. However almost all my pixel shader have a negative hashkey and those ones failed to compile.
This is the pixel shader generated by Pipeline
The original HLSL shader can be found here. I tried to [change few things] and now it works (https://github.com/demonixis/C3DE/blob/develop/C3DE.Demo/Content/Shaders/SkyboxEffect.fx).
How to reproduce
TrueThank you.