LWJGL / lwjgl3

LWJGL is a Java library that enables cross-platform access to popular native APIs useful in the development of graphics (OpenGL, Vulkan, bgfx), audio (OpenAL, Opus), parallel computing (OpenCL, CUDA) and XR (OpenVR, LibOVR, OpenXR) applications.
https://www.lwjgl.org
BSD 3-Clause "New" or "Revised" License
4.75k stars 635 forks source link

Add support for Linux RISC-V 64 #890

Closed Glavo closed 10 months ago

Glavo commented 1 year ago

Most of the work has been completed, and both cross compilation and native compilation can work. I have successfully launched Minecraft on Debian RISC-V 64.

image

Currently, the dependent native libraries are all built by me on my own machine. Next, I need to have LWJGL CI build the native libraries for RISC-V.

Progress:

Glavo commented 1 year ago

@Spasi

I'm running into a little trouble.

I disabled the bgfx module for RISC-V 64. However, the nanovg module contains a class (NanoVGBGFX) that depends on bgfx. When the bgfx module is disabled, the class cannot be compiled either (because several invokeXXX methods are missing in org.lwjgl.system.JNI).

I guess this is a known thing since I saw in the template that the class is only generated when the bgfx module is enabled (nanovg_bgfx.kt). But unfortunately, unless I run ant clean first and then turn on offline mode before building, the class always appears.

I know that the generator of LWJGL caches generated classes, so I'm guessing the cause of the problem is that the generator doesn't delete classes that shouldn't be there. But I'm not familiar with the generator, so can you take a look at this problem?

Spasi commented 1 year ago

@Glavo That's correct, the generator is not clever enough to delete previously generated code that is no longer needed. Also, ant clean will only clean directories of currently enabled modules.

I've verified that with a fully clean/reset repo and bgfx disabled in config/build-bindings.xml, the NanoVGBGFX class is not generated and LWJGL builds correctly. Just make sure to not use ant hydrate-kotlinc, that will generate everything again. Use ant compile-templates instead (slow, but necessary in this case).

Glavo commented 1 year ago

@Glavo That's correct, the generator is not clever enough to delete previously generated code that is no longer needed. Also, ant clean will only clean directories of currently enabled modules.

I've verified that with a fully clean/reset repo and bgfx disabled in config/build-bindings.xml, the NanoVGBGFX class is not generated and LWJGL builds correctly. Just make sure to not use ant hydrate-kotlinc, that will generate everything again. Use ant compile-templates instead (slow, but necessary in this case).

I see, thank you.

Slackadays commented 1 year ago

I just spent a few hours working on the same thing, so hopefully I can help progress this PR!

Slackadays commented 1 year ago

There is an issue with compiling this on a VisionFive 2 running the Debian image with OpenJDK 19:

javac: nanovg] /home/user/lwjgl3-riscv/lwjgl3-riscv-existing/modules/lwjgl/nanovg/src/generated/java/org/lwjgl/nanovg/NanoVGBGFX.java:72: error: cannot find symbol
[javac: nanovg]         return invokeCPP(_edgeaa, _viewId, _allocator, __functionAddress);
[javac: nanovg]                ^
[javac: nanovg]   symbol:   method invokeCPP(int,short,long,long)
[javac: nanovg]   location: class NanoVGBGFX
[javac: nanovg] /home/user/lwjgl3-riscv/lwjgl3-riscv-existing/modules/lwjgl/nanovg/src/generated/java/org/lwjgl/nanovg/NanoVGBGFX.java:97: error: cannot find symbol
[javac: nanovg]         invokePCV(_ctx, _viewId, __functionAddress);
[javac: nanovg]         ^
[javac: nanovg]   symbol:   method invokePCV(long,short,long)
[javac: nanovg]   location: class NanoVGBGFX
[javac: nanovg] /home/user/lwjgl3-riscv/lwjgl3-riscv-existing/modules/lwjgl/nanovg/src/generated/java/org/lwjgl/nanovg/NanoVGBGFX.java:158: error: cannot find symbol
[javac: nanovg]         invokeCPV(_view_id, _framebuffer, __functionAddress);
[javac: nanovg]         ^
[javac: nanovg]   symbol:   method invokeCPV(short,long,long)
[javac: nanovg]   location: class NanoVGBGFX
[javac: nanovg] /home/user/lwjgl3-riscv/lwjgl3-riscv-existing/modules/lwjgl/nanovg/src/generated/java/org/lwjgl/nanovg/NanoVGBGFX.java:172: error: cannot find symbol
[javac: nanovg]         invokePCV(_ctx, _id, _width, _height, flags, __functionAddress);
[javac: nanovg]         ^
[javac: nanovg]   symbol:   method invokePCV(long,short,int,int,int,long)
[javac: nanovg]   location: class NanoVGBGFX
[javac: nanovg] 4 errors
[javac: nanovg] 1 warning

Looking in my own lwjgl3 fork, it appears that this symbol does exist as just a function declaration. What differences would cause your version to not make this symbol?

Edit: just do ant clean first

Glavo commented 1 year ago

@Slackadays Hey, the problem you encountered was mentioned in the previous conversation. Here is Spasi's reply to this:

That's correct, the generator is not clever enough to delete previously generated code that is no longer needed. Also, ant clean will only clean directories of currently enabled modules.

I've verified that with a fully clean/reset repo and bgfx disabled in config/build-bindings.xml, the NanoVGBGFX class is not generated and LWJGL builds correctly. Just make sure to not use ant hydrate-kotlinc, that will generate everything again. Use ant compile-templates instead (slow, but necessary in this case).

Slackadays commented 1 year ago

I actually just realized that by trying ant clean right after, so I guess that's on me because I'm used to CMake where it handles this kind of thing properly.

Slackadays commented 1 year ago

One more thing: I'm trying to get the tests working, and it looks like rpmalloc was removed specifically for RISC-V in https://github.com/LWJGL/lwjgl3/pull/890/commits/f2062730c7020e678df266109eaf024626061ee8. However, it seems to compile just fine, so is there a specific reason it was disabled?

Glavo commented 1 year ago

One more thing: I'm trying to get the tests working, and it looks like rpmalloc was removed specifically for RISC-V in f206273. However, it seems to compile just fine, so is there a specific reason it was disabled?

Sorry, I forgot why I did this. I will re-review these temporarily disabled modules when the issues blocking this PR are resolved.

Slackadays commented 1 year ago

It turns out that there was an issue with rpmalloc which prevented it from properly working on RISC-V. I just made a PR at https://github.com/Glavo/lwjgl3/pull/1 that should fix it. Unfortunately, the tests hang at OpenCL probably because the VF2's Imagination drivers are pure junk right now, so that might improve sometime in the future.

Glavo commented 12 months ago

@Spasi There has been no progress on this PR for several months. Can you please take a look at these PRs?

Glavo commented 11 months ago

long wait……

Slackadays commented 11 months ago

@Spasi these PRs let RISC-V become viable for Minecraft and anything else that uses LWJGL

Glavo commented 10 months ago

I'll run some tests right away to see if there are any issues that need to be addressed.

Glavo commented 10 months ago

@Spasi I have successfully built LWJGL on RISC-V platform and it passes all tests. This PR is now pending review.

image

Glavo commented 10 months ago

GitHub Action is working: https://github.com/Glavo/lwjgl3/actions/runs/6803359632

image

Spasi commented 10 months ago

Thank you @Glavo and @Slackadays! The first 3.3.4 snapshot will include riscv64 binaries.

Spasi commented 10 months ago

@SimonIT it's up, I published it before going to bed and updated https://www.lwjgl.org/customize about an hour ago.