-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add initial support for wayland to bgfx renderer #11451
Conversation
Now vulkan renderer is working on wayland as well. I am not sure whether this is ready to be merged due to the following:
Nevertheless, it shows that native wayland is possible. |
Blinking seems to be an nvidia specific issue, I do not see this on my amd laptop. |
scripts/src/3rdparty.lua
Outdated
MAME_DIR .. "3rdparty/bgfx/src/glcontext_eagl.mm", | ||
MAME_DIR .. "3rdparty/bgfx/src/glcontext_nsgl.mm", | ||
MAME_DIR .. "3rdparty/bgfx/src/renderer_mtl.mm", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this potentially cause issues for older Apple hardware that has poor Metal support?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, but OpenGL support was dropped from upstream bgfx:
bkaradzic/bgfx@928800f
If the PR is interesting but we want to keep OpenGL on Macs, I can see if the necessary commits can be cherry-picked instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rb6502 how many people are going to want my head if bgfx via OpenGL is no longer possible on macOS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just got done promising Mac users I wouldn't lift the system requirements until January, so I would strongly prefer to hold off on anything that would affect that until then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Particularly as Belegdol says this doesn't actually work that well (which describes the totality of Wayland in my experience, to be fair).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough. Maybe we can leave this PR open in the draft state as a proof-of-concept?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You really should follow the code style of files you’re modifying. Also, why are you casting data pointers through uintptr_t
? That’s only necessary when coercing pointer-to-code to pointer-to-data or vice versa.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dropped the cast. Apologies for the style, I am a C++ newbie at best. The code is more or less a copy-paste from
https://github.com/bkaradzic/bgfx/blob/3101a0d93f024e4278caaab29566647cd3e2bf84/examples/common/entry/entry_sdl.cpp#L53-L64
Do you mind being more specific in terms of what I should fix style-wise?
There are at least two additional points which would be worth clarifying before this is ready for merging
|
I have now pushed an update allowing wayland and X11 to be compiled in simultaneously. XWayland is working as well. The patches needed to achieve this are not merged to upstream bgfx yet, but I am putting these here in case someone is curious and would like to test it themselves. |
I moved the update to the 3rdparty libraries to a separate PR (#11493) for clarity. |
It’s still showing as having all those 3rdparty files changed (1063 files changed). |
Apologies. This is either me failing at github or github not being able to create a pr based on another PR. If I understand correctly, it would work if the b* libs update could be temporarily put in a mamedev branch. |
Apologies if it is a dumb question, but is the code in mame/src/osd/modules/render/drawbgfx.cpp Lines 490 to 528 in 36f5b6e
mame/src/osd/modules/render/drawbgfx.cpp Line 497 in 36f5b6e
If this code is not being used, making the change cleaner would be much simpler. Thanks! |
I rebased onto master, will deal with the dependencies locally. |
@cuavas, is this better style-wise? Also, if |
It’s used by |
src/osd/modules/render/drawbgfx.cpp
Outdated
platform_data.nwh = wmi.info.wl.egl_window; | ||
platform_data.nwh = (void *)create_wl_egl_window(dynamic_cast<sdl_window_info const &>(window).platform_window(), wmi.info.wl.surface); | ||
platform_data.type = bgfx::NativeWindowHandleType::Wayland; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you explicitly casting to void *
? You don’t seem to be casting away CV qualifiers, and you aren’t doing a dynamic cast to the canonical object pointer. You should be able to implicitly convert to void *
if you just want the pointer value to be preserved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implicit conversion seems to be working, will fix it.
src/osd/modules/render/drawbgfx.cpp
Outdated
#if defined(SDLMAME_USE_WAYLAND) | ||
wl_egl_window* create_wl_egl_window(SDL_Window *window, struct wl_surface *surface) | ||
{ | ||
wl_egl_window *win_impl = (wl_egl_window*)SDL_GetWindowData(window, "wl_egl_window"); | ||
if(!win_impl) | ||
{ | ||
int width, height; | ||
SDL_GetWindowSize(window, &width, &height); | ||
if(!surface) | ||
return nullptr; | ||
win_impl = wl_egl_window_create(surface, width, height); | ||
SDL_SetWindowData(window, "wl_egl_window", win_impl); | ||
} | ||
return win_impl; | ||
} | ||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please follow the formatting of the file:
- Space before but not after right-associative unary
*
- Space between flow control keyword and opening parenthesis of controlling expression
Why are you checking surface
after getting the window size? You won’t use the window size if it’s null.
Can wl_egl_window_create
fail?
Unlike the other cases in the switch (wmi.subsystem)
this can fail. However, you aren’t checking for failure and returning false
from video_bgfx::set_platform_data
when that happens.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now.
src/osd/modules/render/drawbgfx.cpp
Outdated
wl_egl_window *win_impl = (wl_egl_window*)SDL_GetWindowData(window, "wl_egl_window"); | ||
if(!win_impl) | ||
{ | ||
int width, height; | ||
SDL_GetWindowSize(window, &width, &height); | ||
struct wl_surface* surface = wmi.info.wl.surface; | ||
if(!surface) | ||
return nullptr; | ||
win_impl = wl_egl_window_create(surface, width, height); | ||
SDL_SetWindowData(window, "wl_egl_window", win_impl); | ||
} | ||
return (void*)win_impl; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is non-trivial copy/pasta – shouldn’t it be factored out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
- do not cast wayland window pointer implicitly - fix whitespace - add error handling - factor out second instance of wayland window creation
I have attempted to implement your feedback to the best of my abilities. Thanks to your hint about multiple windows, it appears that there is an issue with vulkan on wayland whereby second window is not being shown. It is with the opengl renderer strangely enough. I need to investigate further. |
Multiple windows needs to be fixed in bgfx: |
src/osd/modules/render/drawbgfx.cpp
Outdated
wl_egl_window *create_wl_egl_window(SDL_Window *window, struct wl_surface *surface) | ||
{ | ||
if (!surface) | ||
{ | ||
osd_printf_error("Wayland surface missing, aborting\n"); | ||
return nullptr; | ||
} | ||
wl_egl_window *win_impl = (wl_egl_window *)SDL_GetWindowData(window, "wl_egl_window"); | ||
if (!win_impl) | ||
{ | ||
int width, height; | ||
SDL_GetWindowSize(window, &width, &height); | ||
win_impl = wl_egl_window_create(surface, width, height); | ||
if (!win_impl) | ||
{ | ||
osd_printf_error("Creating wayland window failed\n"); | ||
return nullptr; | ||
} | ||
SDL_SetWindowData(window, "wl_egl_window", win_impl); | ||
} | ||
return win_impl; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is off in two places – you’ve bumped two levels for some of the if
statements. The braces should be at the level of the if
statement itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/osd/modules/render/drawbgfx.cpp
Outdated
platform_data.ndt = wmi.info.wl.display; | ||
platform_data.nwh = wmi.info.wl.egl_window; | ||
platform_data.nwh = create_wl_egl_window(dynamic_cast<sdl_window_info const &>(window).platform_window(), wmi.info.wl.surface); | ||
platform_data.type = bgfx::NativeWindowHandleType::Wayland; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because create_wl_egl_window
can fail (unlike the other branches of this switch
statement), you need to check whether it succeeded here, and return false
if it didn’t.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now. Is it also needed for sdlNativeWindowHandle()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be fixed now. Is it also needed for
sdlNativeWindowHandle()
?
It is, but the function would need to be rearranged a bit. I’ll worry about that later.
- more whitespace fixes - more failure handling
0c387e1
to
8d08909
Compare
platform_data.nwh = wmi.info.wl.egl_window; | ||
platform_data.nwh = create_wl_egl_window(dynamic_cast<sdl_window_info const &>(window).platform_window(), wmi.info.wl.surface); | ||
if (!platform_data.nwh) | ||
{ | ||
osd_printf_error("BGFX: Error creating a Wayland window\n"); | ||
return false; | ||
} | ||
platform_data.type = bgfx::NativeWindowHandleType::Wayland; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the rest of the branches in this switch
statement be setting platform_data.type
to bgfx::NativeWindowHandleType::Default
to be explicit? The bgfx examples all seem to be doing it now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
platform_data.type
is supposed initialised to default in bgfx.cpp:
mame/3rdparty/bgfx/src/bgfx.cpp
Line 3425 in e6a7b3c
, type(NativeWindowHandleType::Default) |
The reason why examples are doing it explicitly is because they all go via an intermediate
getNativeWindowHandleType()
function which has to return something for non-Wayland. mame appears to be setting the parameters directly which would suggest setting the window handle to default would be redundant.
@belegdol can this be marked as ready for review now that the bgfx changes have been merged, or are there other things that would hold it up? |
No other things holding up, just wanted to make sure things are merged in the correct order. |
Thanks for merging! |
This is an initial working prototype of wayland working with bgfx renderer. It only works with
-bgfx_backend opengl
due to bkaradzic/bgfx#3143 still needing work. Proper conditionalisation is also required so that X11 or Wayland are included and linked only when required.In order to get to this stage, update to the libraries was required:- bgfx to 3101a0d93f024e4278caaab29566647cd3e2bf84- bx to 198cd120e4941d8aeb677db945ef4291a1ced291- bimg to ec02df824a763b2e2ae31e19c674ba0bc88c0695Libs update moved to #11493 for clarity.
While still hacky, it allows for bgfx in a native Wayland window: