gl4es icon indicating copy to clipboard operation
gl4es copied to clipboard

OpenMW shaders fail to compile when enabling an extension

Open AbduSharif opened this issue 2 years ago • 21 comments

Some openmw shaders fail to compile with this error:

[05:39:47.691 W] VERTEX glCompileShader "18 objects_vertex.glsl" FAILED
[05:39:47.691 W] VERTEX Shader "18 objects_vertex.glsl" infolog:
[05:39:47.691 W] 0:4: P0001: Extension directive must occur before any non-preprocessor tokens
[05:39:47.691 W] 0:5: P0001: Extension directive must occur before any non-preprocessor tokens
[05:39:48.019 W] glLinkProgram 0x7b48d9d800"" FAILED
[05:39:48.020 W] Program "" infolog:
[05:39:48.020 W] Link failed because of invalid vertex shader.

The shaders haven't met any new changes that could result in this error, and previous nightlies of gl4es (before at least a few months ago) didn't cause such error.

Edit: See below for more details, Also Sisah's example in custom shaders that didn't compile

AbduSharif avatar Dec 15 '22 03:12 AbduSharif

The OpenMW shaders are here: https://github.com/OpenMW/openmw/tree/master/files/shaders

AbduSharif avatar Dec 15 '22 04:12 AbduSharif

It's most likely this commit: https://github.com/ptitSeb/gl4es/commit/c2fecee44d582b5e0aab30f9c85f42d3ae6a3268

AbduSharif avatar Dec 15 '22 11:12 AbduSharif

Yes, I have supposedly fixed an issue with extension that was not preperly handled. Seems like it's still not properly handled. I'll have a look at this.

ptitSeb avatar Dec 15 '22 11:12 ptitSeb

I think the issue is because the #extension keyword is preceded by some space. I need to check and fix that.

ptitSeb avatar Jan 02 '23 13:01 ptitSeb

Mmmm, on second thought, both extension should be disabled, as they are not supported on gl4es. Can you get the transformed shader?

PS: you can use LIBGL_LOGSHADERERROR=1 to get the shader before and after transformation by shaderconv.

ptitSeb avatar Jan 02 '23 13:01 ptitSeb

Where to get that on Android? I don't have a rooted device.

AbduSharif avatar Jan 03 '23 01:01 AbduSharif

Maybe I can help, run openmw under linux using gl4es (with mali gpu driver) I got some errors like:

Compiler message is
0:71: L0002: Function 'mw_modelToClip' not defined
LIBGL: End of Error log
[12:34:17.485 W] VERTEX glCompileShader "14 objects_vertex.glsl" FAILED
[12:34:17.485 W] VERTEX Shader "14 objects_vertex.glsl" infolog:
[12:34:17.485 W] 0:71: L0002: Function 'mw_modelToClip' not defined
LIBGL: Error while compiling shader 10. Original source is:

Full log: openmw-malig610-blob.log

ChisBread avatar Jan 07 '23 12:01 ChisBread

GL4ES doesn't support the shader liking OpenMW does, but this version of the shaders should work fine with GL4ES, so we can see the problem this particular issue is about better: shaders.zip

Extract the shaders folder to replace the one in the OpenMW resources folder.

AbduSharif avatar Jan 07 '23 15:01 AbduSharif

GL4ES doesn't support the shader liking OpenMW does, but this version of the shaders should work fine with GL4ES, so we can see the problem this particular issue is about better: shaders.zip

Extract the shaders folder to replace the one in the OpenMW resources folder.

I built openmw with these shaders. When I pressed F3 to show fps the game crashed.

amazingfate avatar Jan 08 '23 16:01 amazingfate

Do not build OpenMW with it, just replacing the shaders folder from OpenMW's resources folder with the one from the archive is fine, and btw this is for GL4ES only if your game doesn't work with default OpenMW shaders.

Btw I forgot to add an include in water fragment for water shader to work properly with refraction and reflections, updated:

shaders.zip

AbduSharif avatar Jan 08 '23 17:01 AbduSharif

Do not build OpenMW with it, just replacing the shaders folder from OpenMW's resources folder with the one from the archive is fine, and btw this is for GL4ES only if your game doesn't work with default OpenMW shaders.

Btw I forgot to add an include in water fragment for water shader to work properly, updated:

shaders.zip

I tried these shaders. Game got stuck when I press F3. And openmw process consumed 100% cpu in top. I'm using mali g610 gpu on a rk3588 SBC.

amazingfate avatar Jan 09 '23 01:01 amazingfate

They work fine on Android, not getting stuck or weird CPU usage.

AbduSharif avatar Jan 09 '23 05:01 AbduSharif

Is it possibly this commit the source of the shader compilation failure? https://github.com/ptitSeb/gl4es/commit/3d0d2bd20de16fb3422950ed084e4e8d732deea6

Will try reverting it in a fork.

AbduSharif avatar Jan 11 '23 21:01 AbduSharif

I would say it's the commit about #extension handling

ptitSeb avatar Jan 11 '23 22:01 ptitSeb

Ok, I'm reverted that 3d0d2bd20de16fb3422950ed084e4e8d732deea6, and d80c40bc1d6f13bf6991ad182813c7f867d107c2 and c2fecee44d582b5e0aab30f9c85f42d3ae6a3268 and started builds for each revert to test which one is it.

Reverting the last two was tricky because the recent commits touch almost the same files (also I was using gitlab's UI because I don't have a PC with me).

AbduSharif avatar Jan 11 '23 22:01 AbduSharif

Apologies, none of those are actually the main cause, I started a build with just fresh gl4es (no changes to gl4es other than building it for Android), and everything works fine so far.

AbduSharif avatar Jan 11 '23 23:01 AbduSharif

The reason why the shader compilation fail happened was the changes made by Sisah to this file (see gitblame or the commot history of the file): https://github.com/Sisah2/gl4es/commits/master/src/gl/shaderconv.c

Those changes by Sisah made using post processing shaders easier for OpenMW on Android where shaders didn't have to be edited to fix this error (and other extensions where added too): 0:60: S0012: Global variable initializer must be a constant expression

It used to work fine when I using those changes in a fork of mine, but the recent gl4es change apparently made it not work anymore.

AbduSharif avatar Jan 11 '23 23:01 AbduSharif

There is still issue with enabling extensions with #extension something : enable in custom shaders

Sisah2 avatar Mar 10 '23 20:03 Sisah2

For example this code dont compile, but if i enabled this extension in shadwrconv itself it just work

#version 120

#extension GL_EXT_shader_non_constant_global_initializers : enable

float a = 2.0; float b = 2.0; float color = a / b;

void main() { gl_FragData[0].x = color; }

Sisah2 avatar Mar 10 '23 21:03 Sisah2

Now if i do just this i get crash while starting game https://github.com/Sisah2/gl4es/commit/18f957d9d15909b6060c749e0099bee344b4651c (also changed GetLine to gl4es_getLine) Dont understand why :( ptitSeb any idea? There will be also issue that it put it on wrong line, but that crash now is confusing.

Sisah2 avatar Mar 11 '23 08:03 Sisah2

If the shader fail to compile, it may crash.

But I suppose shaderconv is still confused with the #extension string. There is some code in it to handle that, but it's obviously wrong, and it might even get things to crash. I need to take some time to properly fix this.

ptitSeb avatar Mar 11 '23 09:03 ptitSeb