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

Cherry-pick wayland improvements from upstream bgfx #13070

Merged
merged 9 commits into from
Jan 2, 2025

Conversation

belegdol
Copy link
Contributor

As full sync with upstream is not an option at the moment (see #13054 (comment)), cherry-pick recent wayland fixes from upstream bgfx instead.

This uses the API more correctly as well as moves wayland detection to runtime, reducing the build requirements slightly.

mcourteaux and others added 7 commits December 7, 2024 00:22
* Support both X11 and Wayland in the same build.

 - Works for both Vulkan and OpenGL.
 - Remove --with-wayland from genie options.
 - Vulkan loads all three extensions for surface creation instead of only one.
 - Add width and height parameter to GlContext::createSwapChain(), which is needed for EGL to create
   a SwapChain with the given window size.
 - Dirty-fix the example-22-windows to recreate the FrameBuffer by first destroying and then
   recreating to make sure the window is released of its swapchain.
 - Fix dbgText glitch in example-22-windows.
 - Remove old X11-related dependencies for GLFW3.

* Formatting.
* Fix Vulkan swapchain invalidation issue.

* Always clamp render pass to frame buffer size.

* Fix formatting.
Copy link
Member

@cuavas cuavas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to break building on macOS:

Compiling 3rdparty/bgfx/src/renderer_gl.cpp...
../../../../../3rdparty/bgfx/src/renderer_gl.cpp:7148:59: error: too many arguments to function call, expected single argument '_nwh', have 3 arguments
                m_swapChain = s_renderGL->m_glctx.createSwapChain(_nwh, _width, _height);
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       ^~~~~~~~~~~~~~~
In file included from ../../../../../3rdparty/bgfx/src/renderer_gl.cpp:9:
In file included from ../../../../../3rdparty/bgfx/src/renderer_gl.h:1158:
../../../../../3rdparty/bgfx/src/glcontext_nsgl.h:29:16: note: 'createSwapChain' declared here
                SwapChainGL* createSwapChain(void* _nwh);
                             ^
1 error generated.
make[2]: *** [../../../../osx_clang/obj/x64/Release/3rdparty/bgfx/src/renderer_gl.o] Error 1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What’s the rationale for this change? Does SDL always create the Wayland EGL window now? If it does, when did that change happen? Does it raise the minimum SDL requirement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way I understand it, wayland detection is moved from compile-time to run-time with these changes. If SDL is built with Wayland support (SDL_VIDEO_DRIVER_WAYLAND), then the required Wayland library will be dlopened at runtime and things will just work. There is some explanation in the three upstream bgfx PRs, which have prompted me to submit this PR:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that creating wayland EGL window is taken care by glcontext. Quoting bkaradzic/bgfx#3358:

In this PR, the EGL context now creates this wl_egl_window when the NativeWindowHandleType is set to Wayland.

@belegdol
Copy link
Contributor Author

This seems to break building on macOS:

Compiling 3rdparty/bgfx/src/renderer_gl.cpp...
../../../../../3rdparty/bgfx/src/renderer_gl.cpp:7148:59: error: too many arguments to function call, expected single argument '_nwh', have 3 arguments
                m_swapChain = s_renderGL->m_glctx.createSwapChain(_nwh, _width, _height);
                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       ^~~~~~~~~~~~~~~
In file included from ../../../../../3rdparty/bgfx/src/renderer_gl.cpp:9:
In file included from ../../../../../3rdparty/bgfx/src/renderer_gl.h:1158:
../../../../../3rdparty/bgfx/src/glcontext_nsgl.h:29:16: note: 'createSwapChain' declared here
                SwapChainGL* createSwapChain(void* _nwh);
                             ^
1 error generated.
make[2]: *** [../../../../osx_clang/obj/x64/Release/3rdparty/bgfx/src/renderer_gl.o] Error 1

Looks like this is fixed. I do not have access to a mac though so testing would be appreciated - especially the GL renderer.

@cuavas
Copy link
Member

cuavas commented Dec 23, 2024

What’s the prevailing opinion on this? @galibert, @rb6502 do you have thoughts on it?

@rb6502
Copy link
Contributor

rb6502 commented Dec 23, 2024

What’s the prevailing opinion on this? @galibert, @rb6502 do you have thoughts on it?

I'll pull the branch and smoke test it on at least macOS. I believe there's an issue with MAME itself that's causing a lot of the BGFX issues where we're misreporting the width and/or stride and that's why so many drivers segfault during a memcpy().

@rb6502
Copy link
Contributor

rb6502 commented Dec 23, 2024

Never mind, I was on the wrong branch of the branch, whee.

On macOS it works pretty much identically to top of tree. Some shaders work, some don't.

Lots of this diagnostic in Metal mode on some drivers (sexyparo does it, for instance).
AGX: Texture read/write assertion failed: bytes_per_row >= used_bytes_per_row

@cuavas
Copy link
Member

cuavas commented Dec 24, 2024

If we want to merge it, it’s probably better to do it sooner rather than later so Linux users are exposed to it for a while.

@angelosa angelosa merged commit ba6f585 into mamedev:master Jan 2, 2025
5 checks passed
@angelosa
Copy link
Member

angelosa commented Jan 2, 2025

Gonna test it locally.

boamaod pushed a commit to boamaod/mame that referenced this pull request Jan 18, 2025
* Properly support Wayland under EGL and Vulkan. (mamedev#3358)

* Dynamically load libwayland-egl.so.1 when dealing with Wayland to remove dependencies at program startup. (mamedev#3359)

* Cleanup.

* Support both X11 and Wayland in the same build. (mamedev#3360)

* Support both X11 and Wayland in the same build.

 - Works for both Vulkan and OpenGL.
 - Remove --with-wayland from genie options.
 - Vulkan loads all three extensions for surface creation instead of only one.
 - Add width and height parameter to GlContext::createSwapChain(), which is needed for EGL to create
   a SwapChain with the given window size.
 - Dirty-fix the example-22-windows to recreate the FrameBuffer by first destroying and then
   recreating to make sure the window is released of its swapchain.
 - Fix dbgText glitch in example-22-windows.
 - Remove old X11-related dependencies for GLFW3.

* Formatting.

* Adapt to latest bgfx wayland code

* Cleanup.

* Fix Vulkan swapchain invalidation issue. (mamedev#3379)

* Fix Vulkan swapchain invalidation issue.

* Always clamp render pass to frame buffer size.

* Fix formatting.

* Hopefully fix macOS build

* Hopefully fix macOS build, attempt 2

---------

Co-authored-by: Martijn Courteaux <courteauxmartijn@gmail.com>
Co-authored-by: Бранимир Караџић <branimirkaradzic@gmail.com>
@belegdol belegdol deleted the bgfx_wayland_fixes branch January 19, 2025 21:24
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

Successfully merging this pull request may close these issues.

6 participants