zaps166 / NFSIISE

Need For Speed™ II SE - Cross-platform wrapper with 3D acceleration and TCP protocol!
MIT License
534 stars 42 forks source link

gles2 renderer - GLSL shader compilation error (aarch64 Linux / Panfrost) #112

Closed porschemad911 closed 4 months ago

porschemad911 commented 4 months ago

First off, thank you so much for this excellent Linux port of NFS II SE!

I have been attempting to get the GLES renderer working on a couple of devices running JELOS. Both devices are runnning mainline Linux 6.7.5 aarch64 kernels and Mesa 24.1.0 with Panfrost GPU drivers compiled with OpenGL ES 1 and 2 support included and 32-bit libs built. One has a RockChip RK3326 SOC with a Mali G31 GPU, and the other has an Amlogic S922X SOC with a Mali G52 GPU. Both devices support OpenGL ES 3.1 and OpenGL 3.1 according to Panfrost Mesa driver docs.

The OpenGL 1 and 2 renderers work fine and the game runs well. But the GLES render is producing the following error:

RK3326:/roms/ports/nfs2se # MESA_GLSL=dump ./nfs2se
Need For Speed II SE
  Wrapper v1.3.0
  Game    v1.1.2-cpp_r5
  OpenGL  ES 2
Mesa: info: GLSL source for vertex shader 1:
Mesa: info: precision mediump float;attribute vec4 aPosition;attribute vec4 aTexCoord;attribute vec4 aColor;attribute float aFog;varying vec4 vTexCoord;varying vec4 vColor;varying float vFog;uniform mat4 uMatrix;void main(){vTexCoord = aTexCoord;vColor = aColor;vFog = aFog;gl_Position = uMatrix * aPosition;}
Mesa: info: GLSL shader 1 failed to compile.
Mesa: info: GLSL shader 1 info log:
Mesa: info: 0:1(1): error: syntax error, unexpected NEW_IDENTIFIER

0:1(1): error: syntax error, unexpected NEW_IDENTIFIER

Aborted

It seems to be crashing in /src/Glide2x/OpenGL2.c

porschemad911 commented 4 months ago

I have tried different values in the MESA_GLES_VERSION_OVERRIDE and MESA_GLSL_VERSION_OVERRIDE environment variables as workarounds but with no luck. Is there a particular version number of GLSL I should try?

zaps166 commented 4 months ago

It can't compile GLES shader, hmm. I remember same on R-Pi, but this works on Android. If OpenGL1 works correctly, use it, GL1 is best here.

porschemad911 commented 4 months ago

Thank you for that information, good to know that OpenGL 1 is the preferred renderer.

zaps166 commented 4 months ago

:facepalm: It's my bug :rofl:

zaps166 commented 4 months ago

Fixed, however if OpenGL 1 is working there - use it.

porschemad911 commented 4 months ago

Brilliant thank you, I'll give it a test!

zaps166 commented 4 months ago

Also I generally improved OpenGL performance, maybe it'll run faster now!

porschemad911 commented 4 months ago

@zaps166 was able to compile at commit 06c357106827eee5f9845a749aa3d4869cb34cc9 in a docker container, and the gles2 renderer is now working on the Panfrost devices. Thank you for the fix!

zaps166 commented 4 months ago

After some changes, GL(ES)2 is now default renderer.

porschemad911 commented 4 months ago

I see you have been busy!

Earlier in the week I was attempting to re-compile for arm32v7 / armhf at commit 7d144a070547260a27a71d5cb6a5dd7af38188f3. Compilation was fine, but at runtime on my devices all 3 renderers would crash with error:

Application closed with a signal: 7 /storage/roms/ports Need For Speed II SE.sh: line 46: 14104 Bus error $GAMEDIR/nfs2se

Will try my luck again at HEAD :-)

zaps166 commented 4 months ago

Bus error is caused by alignment error, probably floating point numbers. I hope it'll work on current master :slightly_smiling_face: It's working on R-Pi 4 and Android :smile:

porschemad911 commented 4 months ago

No luck unfortunately. When running ./compile_nfs cpp at commit 52c9f50faa7addfa46c1db77ad7e4213184f2974 I get quite a few warnings similar to the following:

Compiling C code... DInput.c:586:27: warning: incompatible pointer types assigning to 'uint32_t (*)(struct DirectInputEffect **, const DIEFFECT *, uint32_t)' (aka 'unsigned int (*)(struct DirectInputEffect **, const DIEFFECT *, unsigned int)') from 'void (void *)' [-Wincompatible-pointer-types]
        dinputEff->SetParameters = WRAP_NAME(SetParameters);

Then same runtime errors as in https://github.com/zaps166/NFSIISE/issues/112#issuecomment-1984568566

This is in an Ubuntu Focal Docker Container (arm32v7 / armhf):

john@john-desktop:~/workspace/sdl2$ docker ps
CONTAINER ID   IMAGE                  COMMAND       CREATED      STATUS          PORTS     NAMES
139df2187727   arm32v7/ubuntu:focal   "/bin/bash"   3 days ago   Up 31 minutes             flamboyant_sinoussi

Dependency versions: SDL2 2.26.2, clang 1:10.0-50 and lld 1:10.0-50

Maybe I'm doing something wrong, although it is fine at commits prior to the switch to lld. How are you compiling for R-Pi 4?

zaps166 commented 4 months ago

I get quite a few warnings similar to the following:

Because I don't use cast, in C it can compile :smile: However I don't have these warnings. Maybe different compiler version? I see Clang 10, I use newer Clang.

How are you compiling for R-Pi 4?

32-bit Arch Linux, ./compile_nfs cpp. It runs normally there.

Bus error

I copy floating-point data to aligned stack and use VFP there, so it shouldn't happen.


Could you try ./compile_nfs cpp debug ?

edemirkan commented 4 months ago

Let me know if I would need to move this another issue but just adding here as I also test with porschemad911's binaries - but on another device using the same OS. In my case I'm getting the bus error in run time, after 30-40 secs while in a race. Would that still be related Clang version used for compilation?

'/storage/.nfs2se' -> '/roms/ports/nfs2se/conf/.nfs2se'
Need For Speed II SE
  Wrapper v1.3.0
  Game    v1.1.2-cpp_r5
  OpenGL  ES 2
Application closed with a signal: 7
/storage/roms/ports/Need For Speed II SE.sh: line 59:  3391 Bus error               $GAMEDIR/nfs2se
Failed to restart oga_events.service: Unit oga_events.service not found.
zaps166 commented 4 months ago

You use old version, check current master branch.