ptitSeb / gl4es

GL4ES is a OpenGL 2.1/1.5 to GL ES 2.0/1.1 translation library, with support for Pandora, ODroid, OrangePI, CHIP, Raspberry PI, Android, Emscripten and AmigaOS4.
http://ptitseb.github.io/gl4es/
MIT License
694 stars 159 forks source link

amigaos4: cube2(sauerbraten) #73

Open kas1e opened 5 years ago

kas1e commented 5 years ago

Hi ptitSeb !

Did you tried to port sauerbraten over gl4es ? It easy to build, but use shaders by itself a lot (which seems autogenerated on fly). I have lots of errors on amigaos4 version (i.e. it starts, show initialisation picture, and then start to throw errors from shaders at me). For example, i have those ones:

GLSL ERROR (VS:default) ERROR: code generation failed Error log: Bad CompositeConstruct Instruction: input/output sie mismatch (input 4, output: 1). 38: OpCompositeConstruct: FloatVector4[1]: tmp38 << tmp32

1: void main(void) 2:{ 3 gl_Position = ftransform(); 4: gl_TexCoord[0] = gl_MultiTexCoord0; 5: gl_FrontColor = gl_Color; 6: }

And those ones:

"sampler2DRect' : Reserved word.

And those ones:

GLSL ERROR (PS: nocolorglsl) ERROR: Code generation failed. Error log: Shader has ero outputs; must have at least one

1: void main() {} 2:

Sure they all looks like errors from warp3d, but just interesting to know if it works for you at all over gl4es.

ptitSeb commented 5 years ago

I haven't tried sauerbraten myslef, but I have seen success report on using gl4es for it on the net. I'll check later to see how it run using latest gl4es on the Pandora.

On thing, the sampler2DRect issue is coming from gl4es (sort of), has this shader tries to use sample2DRect wich is not supported on gl4es yet (but I guess the use of GL_TEXTURE_RECTANGLE can be turned off somewhere).

The 1st error seems Warp3D related, with some problem on Arrays...

I'll check and tell you my findings.

ptitSeb commented 5 years ago

For the array issues, did you tried LIBGL_NOTEXARRAY=1 ?

For the sampler2DRect, I haven't found any occurence in saurbretan? Where does this come from? (note that I used this github mirror: https://github.com/inexorgame/sauerbraten )

Anyway, saurbretan doesn't render correctly on my side, I have a few things to fix on that side.

ptitSeb commented 5 years ago

I have analysed more cube 2. I have fixed an issues with shaders and uniform arrays... But, I also seen that the game use glQueries. It doesn't seems easily parametrable, only by changing code: here is the diff

diff --git a/src/engine/renderva.cpp b/src/engine/renderva.cpp
index fdbfbb7f..cf8be1cf 100644
--- a/src/engine/renderva.cpp
+++ b/src/engine/renderva.cpp
@@ -288,7 +288,7 @@ void clearqueries()
     loopi(MAXQUERYFRAMES) queryframes[i].cleanup();
 }

-VAR(oqfrags, 0, 8, 64);
+VAR(oqfrags, 0, 0/*8*/, 64);
 VAR(oqwait, 0, 1, 1);

 void startquery(occludequery *query)

That disable the glQueries stuffs. Also, the empty fragment shaders is used in the glQueries. I'm not sure I'll ever be able to have this game playable without code changes (glQueries cannot really be emulated, unless you write a complete resteriser with shaders support, so no).

I suggest you use another game for testing.

kas1e commented 5 years ago

But if we disable glQueries in game itself, it still didn't works properly ?

ptitSeb commented 5 years ago

The fragments shaders with empty main will still be built...

I tested on my side, and there are still some strange issues with textures. One of my next goal is to improve traking of used texture in shaders and adding support for sample2DRect and sample3D, and that maybe needed for this game even without queries.

kas1e commented 5 years ago

So, on your side it at least runs already, without throwing those errors ? Or you still have some errors in console (like about sample2DRect), but game still runs ? For me after all errors i have game just exit. And its all feels that all errors come from warp3d..

ptitSeb commented 5 years ago

I don't have any occurence of the sample2DRect error. And I haven't find any occurence of that keyword in the entire sauerbretan sources. And my GLES2 driver accept the empty main for fragment shaders. It runs without any error or message on my side. But it stil does't work correctly (maybe my little GLES2 just run out of memory with textures, because on the "infinite draw distance" due to the lack of queries, I haven't investigated much).

kas1e commented 5 years ago

Ok got it, so, all of this mean there is issues with warp3d which need to be fixed first, before we can made any conclussions about. Once i will be able to run it same as you (i.e will have menu and start any level), then we can see what can be done next ..

Btw, for you for empty mains in fragment shaders , its just continue silencly without problems ? I mean, on your gles2 driver it "eats" fine, just generate nothing ?

kas1e commented 5 years ago

Btw,

I don't have any occurence of the sample2DRect error. And I haven't find any occurence of that keyword in the entire sauerbretan sources.

It is in the data/glsl.cfg, in few places. But i do recheck via glslangvalidator : and it just our warp3d/ogles2 do not support it. Already create BZ about empty fragment shaders, and now will create one abou that sampler2drect.

ptitSeb commented 5 years ago

Sampler2DRect is not supported in gles2, so the error is normal. The support needs to be done inside gl4es

kas1e commented 5 years ago

But you didnt have that error about sampler2Drect ? Or you have, but game still runs ?

More of it, i tryed via glslangvalidator: it also says reserved word.

kas1e commented 5 years ago

I mean you says it runs without error in console on your side, but how it can be then if sampler2Drect not implemented, and even glslangvaludator says reserved word. Maybe my glslangvalidator just old ..

ptitSeb commented 5 years ago

I tried the campaign mode, 1St campaign and 1st level and didn't get the error. But if I had a shader with it, it would have errored like you.

kas1e commented 5 years ago

But if I had a shader with it

Hm.. So you was able somehow to run it wihout shaders at first ? I mean for me, when i run sabre_client, it runs, and then scan all over the shaders (those ones which in data/glsl.cfg ,and others), and bring at me all those errors i have.

http://kas1e.mikendezign.com/aos4/gl4es/games/cube2/cube2_shader_errors.txt

You can see there all errors about which i point out before, and at the end i have lots errors of such kind:

ERROR: An exception occurred during compilation: ERROR: Assertion failed: px != 0, in T* boost::shared_ptr::operator->() const [with T = GPUProg::CGRegisterAlloc], defined in /SDK/local/common/include/boost/shared_ptr.hpp in line 253 ERROR: An exception occurred during compilation: basic_string::_M_construct null not valid

that probably related to boost includes i use .. and something wrong with it.

But anyway i have all the errors right when i only run cube2's binary. All shaders scans right at the running stage .. Maybe you run it somehow different ?

kas1e commented 5 years ago

Btw, i use sauerbraten_2010_07_28_justice_edition_linux.tar.bz2 for tests, what one you use ?

I anyyway found how to run cube2 without its own shaders at all : sauer_clien -f0 So it will use fixed-function path, and no shaders :good for tests.

It then runs, show me menu, i can choice "compaing", "start level 9" (for me it 9 by default there, not 1, probabaly because of different versions we use), then it show me initialisation screen, says "read map packages/base/level9.ogz, start to do loading, and once it hit any md5 config file in which has the command "mdlenvmap 0 0 skybox/morning" , then it stop working. Dunno why maybe related to the amigaos pathes/unix slashes clashes .. But anyway i comment those strings out, and all loads fine to the memory and then says "clearing vertex arrays..." , and then nothing happens again .. No hung, no crash, just nothing.. Maybye it side effect of commented out "mdlenvmap 0 0 skybox/morning" strings, but dunno...

ptitSeb commented 5 years ago

I use latest sources from a github mirror, look at my second post for the address.

kas1e commented 5 years ago

Indeed missed the link, will try now. Hope it not SDL2 only :)

kas1e commented 5 years ago

Uhm, seems they switched to SDL2 .. Your test build also SDL2 based ?

Btw, i do check some youtube videos, and many of them didn't have glQueries support as well , but they works in terms of rendering. I mean trashing you have, probable not because of glQueries, but probabaly as you say because of limited vram you have on your gles2 ..

kas1e commented 5 years ago

I hacked our SDL2 to use gl4es (phew!) and it works for simple test cases. So, then i build latest version of the cube2 from the link above, and on runnin stage once i just do "sauer_client" , i then have error after gl4es initialises fine, etc: "GLSL 1.20 or greater is required!"

Is it our GLES2/Warp3d again lacking something, or you do have the same too, and fixed it somehow ?

ptitSeb commented 5 years ago

You need to use "LIBGL_GL=21" to expose OpenGL 2.1 and make it happy.

kas1e commented 5 years ago

Yeah, that did the trick ! So, it start the menu now, and once i tried to run any level, it crashes on reading the data, damn :(

Btw, i also has in console output : "libpng warning: iCCP: known incorrect sRGB profile" , did you have that one too ?

Also, how you disable shaders ? I tried -f0 , as in previous version, but that seems didn't help..

Maybe my crashes are shaders related ..

ptitSeb commented 5 years ago

The crash qre probably the shaders with the e;pty fragment shader used for the glQueries stuff. Use "LIBGL_LOGSHADERERROR=1" to have detail on shader faillures.

kas1e commented 5 years ago

Right .. it bring info and about empty shaders, and about one unsupported instruction (OpImageSampleProjImplicitLod), and about shaders which has in the arrays "-" value, i.e about 10 shaders fails to compile because they has somehting like:

uniform vec4 animdata[-30];

And error are:

ERROR: 7:1 '' : array size must be a positive integer

Dunno for what they use negative values in arrays .. But that probably thing we miss also in warp3d.

Strange why i can't disable shaders at all and use fixed pipeline via "-f0", they even in documentation sayys we can do so..

ptitSeb commented 5 years ago

Array with negative size? That's strange. Maybe it's a compilation issue, because that make no sense>

kas1e commented 5 years ago

I just set LIBGL_LOGSHADERERROR 1 , and run sauer_client , so it bring 2 errors about empty arrays, and then about 10 about negative sizes. Original shaders looks like this :

version 120

attribute vec4 vboneweight; attribute vec4 vboneindex; //:uniform animdata uniform vec4 animdata[-30];

    attribute vec4 vvertex;
    uniform mat4 modelmatrix;
    uniform vec4 shadowintensity;
    varying vec4 shadowmapvals;
    void main(void)
    {

    int index = int(vboneindex.x);

        vec4 dqreal = animdata[index];
        vec4 dqdual = animdata[index+1];

    vec4 mpos = vec4((cross(dqreal.xyz, cross(dqreal.xyz, vvertex.xyz) + vvertex.xyz*dqreal.w + dqdual.xyz) + dqdual.xyz*dqreal.w - dqreal.xyz*dqdual.w)*2.0 + vvertex.xyz, vvertex.w);

        gl_Position = modelmatrix * mpos;
        shadowmapvals = vec4(1.0 - gl_Position.z, 1.0, 0.0, shadowintensity.x);
    }

======= ShaderConv Source is:

version 100

precision mediump float; precision mediump int;

attribute vec4 vboneweight; attribute vec4 vboneindex;

    uniform vec4 animdata[-30];

    attribute vec4 vvertex;
    uniform mat4 modelmatrix;
    uniform vec4 shadowintensity;
    varying vec4 shadowmapvals;
    void main(void)
    {

    int index = int(vboneindex.x);

        vec4 dqreal = animdata[index];
        vec4 dqdual = animdata[index+1];

    vec4 mpos = vec4((cross(dqreal.xyz, cross(dqreal.xyz, vvertex.xyz) + vvertex.xyz*dqreal.w + dqdual.xyz) + dqdual.xyz*dqreal.w - dqreal.xyz*dqdual.w)*2.000000 + vvertex.xyz, vvertex.w);

        gl_Position = modelmatrix * mpos;
        shadowmapvals = vec4(1.000000 - gl_Position.z, 1.000000, 0.000000, shadowintensity.x);
    }

======= Compiler message is ERROR: 7:1: '' : array size must be a positive integer ERROR: 29:0: '' : compilation terminated ERROR: 2 compilation errors. No code generated.

ptitSeb commented 5 years ago

I remember having see on the Pandora this array as 192 elements. I say you have signed/unsigned char error or something similar.

kas1e commented 5 years ago

My original compiler's flags was:

CXXFLAGS= -O3 -fomit-frame-pointer -ffast-math -Wall -fsigned-char -fno-exceptions -fno-rtti

So i play a bit with, and when i had -O3, i had that negative arrays, but when i just switch to -O2 (with all other falgs keep the same), then uniform vec4 animdata[-30]; gone, and instead i can see there uniform vec4 animdata[192];

Probably that because my gcc is too old for latest cube2 sources and O3 optimisation (i use 4.4.3).

So, negative arrays gone, but instead i have new errors in the same shaders:

LIBGL: Error while compiling shader 350. Original source is:

version 120

attribute vec4 vboneweight; attribute vec4 vboneindex; //:uniform animdata uniform vec4 animdata[192];

    attribute vec4 vvertex;
    uniform mat4 modelmatrix;
    uniform vec4 shadowintensity;
    varying vec4 shadowmapvals;
    void main(void)
    {

    int index = int(vboneindex.x);

        vec4 dqreal = animdata[index];
        vec4 dqdual = animdata[index+1];

    vec4 mpos = vec4((cross(dqreal.xyz, cross(dqreal.xyz, vvertex.xyz) + vvertex.xyz*dqreal.w + dqdual.xyz) + dqdual.xyz*dqreal.w - dqreal.xyz*dqdual.w)*2.0 + vvertex.xyz, vvertex.w);

        gl_Position = modelmatrix * mpos;
        shadowmapvals = vec4(1.0 - gl_Position.z, 1.0, 0.0, shadowintensity.x);
    }

======= ShaderConv Source is:

version 100

precision mediump float; precision mediump int;

attribute vec4 vboneweight; attribute vec4 vboneindex;

    uniform vec4 animdata[192];

    attribute vec4 vvertex;
    uniform mat4 modelmatrix;
    uniform vec4 shadowintensity;
    varying vec4 shadowmapvals;
    void main(void)
    {

    int index = int(vboneindex.x);

        vec4 dqreal = animdata[index];
        vec4 dqdual = animdata[index+1];

    vec4 mpos = vec4((cross(dqreal.xyz, cross(dqreal.xyz, vvertex.xyz) + vvertex.xyz*dqreal.w + dqdual.xyz) + dqdual.xyz*dqreal.w - dqreal.xyz*dqdual.w)*2.000000 + vvertex.xyz, vvertex.w);

        gl_Position = modelmatrix * mpos;
        shadowmapvals = vec4(1.000000 - gl_Position.z, 1.000000, 0.000000, shadowintensity.x);
    }

======= Compiler message is ERROR: Code generation failed. Error log: INTERNAL ERROR: The following access chain is missing one or more CGVars: 27: OpAccessChain: FloatVector4*: animdata[tmp25] INTERNAL ERROR: Dot instruction's source parameters are missing INTERNAL ERROR: Dot instruction's source parameters are missing INTERNAL ERROR: ExtInstruction is missing parameters INTERNAL ERROR: CompositeExtract instruction's source parameter is incomplete: 28: OpLoad: FloatVector4: tmp28 << animdata[tmp25] Deco LIBGL: End of Error log

Also that one:

LIBGL: Error while compiling shader 351. Original source is:

version 120

attribute vec4 vboneweight; attribute vec4 vboneindex; //:uniform animdata uniform vec4 animdata[192];

    attribute vec4 vvertex;
    uniform mat4 modelmatrix;
    uniform vec4 shadowintensity;
    varying vec4 shadowmapvals;
    void main(void)
    {

    int index = int(vboneindex.x);

        vec4 dqreal = animdata[index] * vboneweight.x;
        vec4 dqdual = animdata[index+1] * vboneweight.x;
        index = int(vboneindex.y);
        dqreal += animdata[index] * vboneweight.y;
        dqdual += animdata[index+1] * vboneweight.y;

        float len = length(dqreal);
        dqreal /= len;
        dqdual /= len;

    vec4 mpos = vec4((cross(dqreal.xyz, cross(dqreal.xyz, vvertex.xyz) + vvertex.xyz*dqreal.w + dqdual.xyz) + dqdual.xyz*dqreal.w - dqreal.xyz*dqdual.w)*2.0 + vvertex.xyz, vvertex.w);

        gl_Position = modelmatrix * mpos;
        shadowmapvals = vec4(1.0 - gl_Position.z, 1.0, 0.0, shadowintensity.x);
    }

======= ShaderConv Source is:

version 100

precision mediump float; precision mediump int;

attribute vec4 vboneweight; attribute vec4 vboneindex;

    uniform vec4 animdata[192];

    attribute vec4 vvertex;
    uniform mat4 modelmatrix;
    uniform vec4 shadowintensity;
    varying vec4 shadowmapvals;
    void main(void)
    {

    int index = int(vboneindex.x);

        vec4 dqreal = animdata[index] * vboneweight.x;
        vec4 dqdual = animdata[index+1] * vboneweight.x;
        index = int(vboneindex.y);
        dqreal += animdata[index] * vboneweight.y;
        dqdual += animdata[index+1] * vboneweight.y;

        float len = length(dqreal);
        dqreal /= len;
        dqdual /= len;

    vec4 mpos = vec4((cross(dqreal.xyz, cross(dqreal.xyz, vvertex.xyz) + vvertex.xyz*dqreal.w + dqdual.xyz) + dqdual.xyz*dqreal.w - dqreal.xyz*dqdual.w)*2.000000 + vvertex.xyz, vvertex.w);

        gl_Position = modelmatrix * mpos;
        shadowmapvals = vec4(1.000000 - gl_Position.z, 1.000000, 0.000000, shadowintensity.x);
    }

======= Compiler message is ERROR: Code generation failed. Error log: INTERNAL ERROR: SOP2 instruction can't have VGPR source or destination registers S_MUL_I32 sDst(SGPR8) src0(LITERAL_CONST) src1(VGPR2) const: 0x10 INTERNAL ERROR: SOP2 instruction can't have VGPR source or destination registers S_MUL_I32 sDst(SGPR8) src0(LITERAL_CONST) src1(VGPR3) const: 0x10 INTERNAL ERROR: SOP2 instruction can't have VGPR source or destination registers S_MUL_I32 sDst(SGPR8) src0(LITERAL_CONST) src1(VGPR2) const: 0x10 INTERNAL ERRO

Seems again warp3d related ? :(

kas1e commented 5 years ago

yeah, can confirm that this is both 2 new issues in our shader's compiler in warp3d.

So at moment i create 4 issues to warp3d, which need to fixed first:

  1. Unsupported opCode OpImageSampleProjImplicitLod
  2. Allow empty fragment shaders
  3. Vertex shader with arrays support issue 1 (that about The following access chain is missing one or more CGVars)
  4. Vertex shader with arrays support issue 2 (that about VGPR const: 0x10)

And probably only after that 4 issues will be fixed, we can come back to this and continue to see what can be done. As of now, it seems that we can't disable shaders completely for latest cube2 (do we?), so the onlyy way to go futher its to fix all shader issues first on our side.

If you doesn't mind, let issue be opened, until progress will be done from our side.

ptitSeb commented 5 years ago

Ok, we can let this ticket open for now.

kas1e commented 5 years ago

just to make you know, Hans already fix 2 issues from 4 : he make it possible to have dummy fragment shader (so empty ones are eats fine), as well as fix one of array's issues (that was some side effect of some optimisation). Remaining are OpImageSampleProjImplicitLod and another arrays related issue. Hope he soon will deal with another 2.

kas1e commented 5 years ago

Hans fixed 3 issues where shaders fail to compiles in cube2 and only remain one are OpImageSampleProjImplicitLod being unimplemented. Hope he can do it more or less fast.

kas1e commented 5 years ago

For me there is anyway the same problem which i has with old version of cube2 i tried to build (that one where i at least can disable shaders, and run it without), so i have this one and there now as well, even over sdl2 and latest sources (that missing OpImageSampleProjImplicitLod , seems didn't make big deal, and all loads without crashes). PRoblem is :

Everything loads , etc, i choiuce leve to load (any level, any other possible map, etc) , and then, all start loads, and once it going to the loading of that "packages/models/mrfixit/hudguns/fist" , everything just stops. Not freezes, not crashes, just stops. As i understand for you all ok in that terms, all starts , you can start play game, just it a bit with messed textures ?

ptitSeb commented 5 years ago

I don't have freeze yes. I can load a level and look around.

kas1e commented 5 years ago

Its not about cube2, but about cube1 , but probabaly creating new ticket not worth of it.

So.. I just build cube1 via gl4es , all builds fine, it runs. But then, something strange happens : it show 30fps (like on minigl), but then, everything veeeeery slow. All movement, etc. Its like 0.5-1fps for real. Did you tried that one ? Source very small ones, builds without changes, etc:

https://sourceforge.net/projects/cube/files/cube/2005_08_29/

But when i do LIBGL_BATCH 1 , it start actually works ! And LIBGL_BATCH 2 make it playable. After that i can see no changes, be it 5, 20, 100 or whatever, i.t. BATCH = 2 is maximum which speed things up.

Through while MiniGL version give 35 fps at begining, gl4es version with LIBGL_BATCH 20 give 22 fps. Maybe there is some other options which may help ?

ptitSeb commented 5 years ago

I tried cube1, but it read the Depth buffer (when you shoot), and because most GLES2 driver wont let you that, I haven't played much with it.

If LIBGL_BATCH=1 or 2 makes a huge difference, hat mean the game use lots of small glDrawArray(...) or glDrawElements(...). I don't remember how it draw things. Again, this one a simple geometry, with very few triangles, with no advanced effect, I don't think minigl can be beaten on simple stuff.

ptitSeb commented 5 years ago

Also, for all those performance questions, did you try the profiling tools that comes with gcc ? Add -pg to you CFLAGS/CXXFLAGS to build a version with profiling enabled. Look here https://www.thegeekstuff.com/2012/08/gprof-tutorial/ for example.