bryanedds / Nu

Repository hosting the open-source Nu Game Engine and related projects.
MIT License
1.05k stars 151 forks source link

See if we can get our 3D OpenGL implementation to work on AMD. #800

Closed bryanedds closed 2 months ago

bryanedds commented 2 months ago

EDIT: We spent many months trying to get AMD's opengl drivers to work with our renderer once we switched over to bindless textures. Here's where I landed at before giving up -

i have the exact line in shader code where AMD hangs on light mapping
tho that's on drivers where 3D works at all

https://github.com/bryanedds/Nu/blob/536a4028a6eae17d7eac01d58f1c2019293b590f/Nu/Nu.Gaia/Assets/Default/PhysicallyBasedDeferredLightMapping.glsl#L68

it hangs when trying to sample any of the deferred render buffer textures
i concluded that there is an internal synchronization bug inside the amd opengl driver
something internally goes out of order where sampling a deferred geometry buffer later in the pipeline
i tried putting manual synchronization and guards everywhere relevant to no avail
it's either that or there is a case the bindless texture handle being used gets invalidated internally
it must be internal because there is no legal way for a texture handle to become invalid once it has been made resident without the user making it non-resident
so i conlcuded that it's some internal invalid operation or sequence of operations happening in the driver
the reason i think a workaround might even be slightly possible is because maybe there's some other rendering path that could happen to avoid the internal bug or its preconditions
reinux commented 2 months ago

Did some quick tinkering, and on Linux, it is indeed that easy... maybe.

After exporing MESA_LOADER_DRIVER_OVERRIDE=zink, you can then confirm that it's on Zink by doing glxinfo | grep 'renderer string', which will confirm that it's on Zink.

On my AMD machine, it now crashes without an error message here:

Shader.CreateShaderFromStrs() at /home/rei/oden/home/rei/source/nu/Nu/Nu/OpenGL/OpenGL.Shader.fs:line 34
Shader.CreateShaderFromFilePath() at /home/rei/oden/home/rei/source/nu/Nu/Nu/OpenGL/OpenGL.Shader.fs:line 63
Filter.CreateFilterBoxShader()
GlRenderer3d.make()
RendererInline.Nu.RendererProcess.Start()
WorldModule3.World.tryMake.Static()
WorldModule3.World.run.Static()
Program.main()

Sadly, this isn't as far as it was making it before, which was here:

Gl.GetTextureHandleARB() at /home/rei/.config/JetBrains/Rider2024.1/resharper-host/DecompilerCache/decompiler/414ce548b1474721b05451b5df65cc5022d800/8a/8896862c/Gl.cs:line 25,810
Texture.TryCreateTextureHandle() at /home/rei/oden/home/rei/source/nu/Nu/Nu/OpenGL/OpenGL.Texture.fs:line 373
Texture.CreateTextureHandle()
Framebuffer.TryCreateShadowBuffers()
GlRenderer3d.make()
RendererInline.Nu.RendererProcess.Start()
WorldModule3.World.tryMake.Static()
WorldModule3.World.run.Static()
Program.main()

So we can't be sure if it's an improvement or not, or if this is insurmountable again.

Getting Zink working on Windows seems to be a whole other thing, so I'll have to investigate further.

This is probably a good starting point for getting Zink on windows.

bryanedds commented 2 months ago

The only reasonable approach remaining was to rip out bindless texture utilization. But it is done and can be tested on other AMD machines.