Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mac M1 arm64 support #4

Open
Protoxy22 opened this issue Sep 29, 2021 · 7 comments
Open

Mac M1 arm64 support #4

Protoxy22 opened this issue Sep 29, 2021 · 7 comments

Comments

@Protoxy22
Copy link

Protoxy22 commented Sep 29, 2021

Hello, I would like to setup a development environment with kool on my M1 Macbook.
I started to change the lwjgl version from 3.2.4 to 3.3.0 which is compatible with arm64 architectures.

In Dependencies.kt -> lwjglVersion = 3.3.0-SNAPSHOT
And I select the good natives in it natives-macos-arm64.
Note: Add this repository url (https://oss.sonatype.org/content/repositories/snapshots)

I am now looking for physx-jni, to be able to build arm natives, but there is lot of stuff on the cmake.
Is it possible for you to do add the compiling process for arm64 architectures on mac ?
If you don't have a macos arm64, I can build it for you on XCode or look for the Github Workflow.

Thanks in advance !
And great work here.

@Protoxy22 Protoxy22 changed the title Mac M1 arm64 Mac M1 arm64 support Sep 29, 2021
@fabmax
Copy link
Collaborator

fabmax commented Sep 29, 2021

It should be possible to compile the PhysX code for M1 (see e.g. this issue for the original PhysX code). Unfortunately I don't have an M1 Mac so it's a bit difficult for me to test and, unfortunately, I'm a bit busy lately so I'm not sure when / if I'm able to do that in the near future.

You might be able to adopt the commit, linked in the issue, and compile physx-jni for arm64 yourself.

@Protoxy22
Copy link
Author

Hello, if you are interested on my work trying to port to the M1 architecture

I built the repo physx-jni for macos-arm64 and linked the native to kool project.
I had to:

  • add jvmArgs("-XstartOnFirstThread") to run the demo
  • add glfwWindowHint(139266, 3), glfwWindowHint(139267, 3) to allow OpenGL core profile instead of compatibility profile (OpenGL 3.3) and up to 4.1
  • glsl shaders version 300 es is not supported
21:47:13.209|f:1 E/ShaderManager: Vertex shader compilation failed:
ERROR: 0:1: '' :  version '300' is not supported
ERROR: 0:1: '' : syntax error: #version
ERROR: 0:2: '' :  #version required and missing.
ERROR: 0:13: '0' : syntax error: integers in layouts require GLSL 140 or later

So I replaced to #version 330 for testing purposes with hope that is the same syntax than 300 es. Now I get no errors.

Except the last one which stuck me, maybe you can help me.
For all of the demo scenes I got this error that is maybe the first OpenGL call for render:

21:50:10.417|f:79 D/RgbeDecoder: Converted RGBe to linear: https://kool.blob.core.windows.net/kool-demo/hdri/shanghai_bund_1k.rgbe.png
FATAL ERROR in native method: Thread[main,5,main]: No context is current or a function that is not available in the current context was called. The JVM will abort execution.
	at org.lwjgl.opengl.GL43C.glCopyImageSubData(Native Method)
	at org.lwjgl.opengl.GL43.glCopyImageSubData(GL43.java:677)
	at de.fabmax.kool.platform.gl.OffscreenPassCubeGl.copyToTextures(OffscreenPassCubeGl.kt:57)
	at de.fabmax.kool.platform.gl.OffscreenPassCubeGl.draw(OffscreenPassCubeGl.kt:35)
	at de.fabmax.kool.pipeline.OffscreenPassCubeImpl.draw(OffscreenPassCubeImpl.kt:13)
	at de.fabmax.kool.platform.gl.GlRenderBackend.drawOffscreen(GlRenderBackend.kt:184)
	at de.fabmax.kool.platform.gl.GlRenderBackend.doOffscreenPasses(GlRenderBackend.kt:164)
	at de.fabmax.kool.platform.gl.GlRenderBackend.drawFrame(GlRenderBackend.kt:123)
	at de.fabmax.kool.platform.Lwjgl3Context.run(Lwjgl3Context.kt:124)
	at de.fabmax.kool.demo.Demo.<init>(Demo.kt:99)
	at de.fabmax.kool.demo.DemoKt.demo(Demo.kt:39)
	at de.fabmax.kool.demo.DemoKt.demo$default(Demo.kt:25)
	at de.fabmax.kool.demo.MainKt.main(Main.kt:25)
	at de.fabmax.kool.demo.MainKt.main(Main.kt)

Full logs here: https://pastebin.com/7YSgE4hq

@Protoxy22 Protoxy22 reopened this Jun 13, 2022
@fabmax
Copy link
Collaborator

fabmax commented Jun 14, 2022

Hmm, you usually get the "no context is current" error message when a gl function is called from a different thread than the one that was used to initialize OpenGL. However, there's the second part of the message saying that a functions is not available and I assume that is the case here.

You mentioned that you use OpenGL core up to version 4.1 but the function which is used here is actually OpenGL 4.3 (org.lwjgl.opengl.GL43.glCopyImageSubData). It should be possible to replace glCopyImageSubData with copyTexSubImage2D, which should work fine. You can take a look at the js version of OffscreenPassCubeImpl, which does it that way.

@Protoxy22
Copy link
Author

Protoxy22 commented Jun 14, 2022

Ok thank you for your comment.

I switched all the GL43 calls (OffscreenPass2dGl/OffscreenPassCubeGl with GL_TEXTURE_CUBE_MAP instead)
to that

//glCopyImageSubData(glColorTexs[0], GL_TEXTURE_2D, mipLevel, 0, 0, 0, target.texture, GL_TEXTURE_2D, mipLevel, 0, 0, 0, width, height, 1)
GL11.glBindTexture(GL_TEXTURE_2D, target.texture)
GL11C.glCopyTexSubImage2D(GL_TEXTURE_2D, mipLevel, 0, 0, 0, 0, width, height)

AND

//glTexStorage2D(GL_TEXTURE_2D, mipLevels, intFormat, width, height)
GL31.glRenderbufferStorage(GL_TEXTURE_2D, intFormat, width, height)

Now I get no more errors in the console, and the screen is like that for all demos

image

So I think for the moment there is no possibilities for me to find a way since I don't know what to check.
I know you don't have access to an arm64 computer, so you can't really help. At least I have tried

Thank you very much for your game engine

@Protoxy22
Copy link
Author

Protoxy22 commented Jul 10, 2022

As OpenGL has been deprecated by Apple I tested with Vulkan with some of the tweakings I explained above.

Almost all demos doesn't work because of this error:

Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 5, Size: 5
	at java.util.ArrayList.rangeCheck(ArrayList.java:659)
	at java.util.ArrayList.get(ArrayList.java:435)
	at de.fabmax.kool.platform.vk.CommandBuffers.nextCommandBuffer(CommandBuffers.kt:32)
	at de.fabmax.kool.platform.vk.VkRenderBackend$KoolVkScene.makeCommandBuffers(VkRenderBackend.kt:255)
	at de.fabmax.kool.platform.vk.VkRenderBackend$KoolVkScene.renderAll(VkRenderBackend.kt:206)
	at de.fabmax.kool.platform.vk.VkRenderBackend$KoolVkScene.onDrawFrame(VkRenderBackend.kt:156)
	at de.fabmax.kool.platform.vk.RenderLoop.drawFrame(RenderLoop.kt:72)
	at de.fabmax.kool.platform.vk.VkRenderBackend.drawFrame(VkRenderBackend.kt:106)
	at de.fabmax.kool.platform.Lwjgl3Context.run(Lwjgl3Context.kt:124)
	at de.fabmax.kool.demo.Demo.<init>(Demo.kt:99)
	at de.fabmax.kool.demo.DemoKt.demo(Demo.kt:39)
	at de.fabmax.kool.demo.DemoKt.demo$default(Demo.kt:25)
	at de.fabmax.kool.demo.MainKt.main(Main.kt:27)
	at de.fabmax.kool.demo.MainKt.main(Main.kt)

But luckily ksl-test works great ! 120 FPS on a Macbook Pro M1
It uses MolkenVK (given by lwjgl libs)

image

I replaced shader = pbrShader {} in helloworld demo by KslBlinnPhongShader and it didn't crash

@fabmax
Copy link
Collaborator

fabmax commented Jul 10, 2022

Good to know! The Vulkan backend is pretty experimental and definitely needs some more work... But cool that it works at least a little on M1

@fabmax
Copy link
Collaborator

fabmax commented Aug 2, 2022

@Protoxy22 I just pushed a small update to the Vulkan backend which should fix the IndexOutOfBoundsException

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants