MacOSX: allow build with homebrew and its emulated MesaGL#66
MacOSX: allow build with homebrew and its emulated MesaGL#66dk wants to merge 0 commit intoPerl-GPU:masterfrom
Conversation
Pull Request Test Coverage Report for Build 20510719765Details
💛 - Coveralls |
|
XQuartz is extremely slow to start, and because of the emulation, there is no hardware acceleration. What benefit does using the emulated Mesa bring for MacOS? |
|
The benefit is binary compatibility with homebrew. This should never be a default build (note the explicit "env WITH_HOMEBREW=1"), but I think that if one insists, for whatever reasons, one should have a possibility to build everything with homebrew only, and not have coredumps because of different versions of shared libraries linked together. ( btw I don't agree that 1-2 seconds for first instance of XQuartz to start is "extremely slow" ) |
|
On my Intel Mac, XQuartz takes 15s or more to start. FreeGLUT (from Homebrew, pulling in XQuartz and Mesa) as used in POGL doesn't get segfaults on my system when the system OpenGL library is also linked in. The change which I saw you make in Prima::OpenGL to disable using the system OpenGL on MacOS has now made it not compile on my machine. That won't be happening for this library. |
|
Hmm that's interesting... so the latest Prima::OpenGL doesn't compile on your setup with homebrew? Could you possible share the setup so I can try to reproduce? Of course you don't see coredumps on OpenGL::Modern, because there is no clash there. On my setup I observed the clash when Prima links with X11 libs from homebrew, and in POGL these in turn pull GLX and after that, GL also from homebrew (and thus, Mesa). Only when OpenGL comes into the picture, these two GL libraries explode. But this aside, you don't want homebrew's Mesa in principle, or ...? |
|
To be clear, Mesa is on the device via Homebrew. I repeat that the latest OpenGL on It would really help if you'd make a CI addition for this that you can show works with GL as you have it locally. It would help Prima-OpenGL quite a lot if you had CI on that, which I'm not currently seeing. |
|
Also, I highly recommend that since you now dep on OGLM, you should use the OpenGL::Modern::Config info I made especially for this purpose. If you're looking to avoid X11 stuff on MacOS, GLFW provides good code to copy for window-opening and widget stuff. |
|
I'm not seeking to get rid of X11, quite the other way as Prima needs X11. But I'll try to look into CI if there is mac-based one provided by github or whoever else... I'll be back in March, will look into that. |
|
Great. By the way, Prima itself is breaking on my Mac device, which I'll take a look at in a while. I did say "if" you want to get rid of X11 for MacOS: I believe that relying on XQuartz in 2026 doesn't make for a good user experience, and it would be worth making Prima do "native" MacOS. |
|
Oh well, native Cocoa for Prima, that's a really painful one ... I don't think will ever have energy for that :( |
|
Pity. There is more prior art to steal from, Qt, which implements a GUI: https://github.com/qt/qtbase By the way, Finally, I really need more information on the segfault you say you're seeing. I can't reproduce it myself; if I could, there might be a better way. Also, I had a weird situation a while ago when P:G:TriD was still in main PDL, where the GNU readline would lose its history if TriD stuff was used. It turned out this was because OpenGL loaded LLVM, which loaded libedit (which is either a fork of, or at least looked at the source of, readline), which had some similar symbols. If OpenGL was loaded before the particular readline function that did history was called, the libedit symbol "won"; if the readline function was called first, it won. In other words, it might be possible to avoid the whole segfault by being canny about symbol management. |
|
Well the segfault and the coredump, they don't bear much of useful info, but the ldd (or rather otool -L) output does. The thing goes like this: Prima uses libX11 and Xft and all other X-related libs, and creates a config how to link with Prima.so if anyone desires - so far so good. OpenGL uses native Mac frameworks and libGL that understands it, but okay so far so good as well. Now POGL tries to link with libGLX using link flags from both Prima and OpenGL, but assuming there is no Mesa and no homebrew's libGLX, it pulls libGLX from the XQuartz distro, and in turn other X-related libs, fontconfig etc.. that's where problem begins. I observed that when f.ex. Prima code wants to use libXft which is linked with fontconfig, the linker brings in libfontconfig from the XQuartz distro, not from homebrew, and of course this explodes. Now I am rereading this and it looks messy, but if you manage to build Prima and POGL and see the otool -L output you'll see what I mean. Btw what kind of a problem you observe with Prima build? You're welcome to submit a bug report... |
|
Btw how do you build OpenGL::Modern with homebrew/freeglut on mac? I'm looking into its Makefile.PL and it is very explicit about if system is darwin, use -framework OpenGL. |
Perl OpenGL (for this context, I'll call that OGL.pm since you're saying POGL as Prima::OpenGL, whereas generally people say POGL and mean "Perl OpenGL" i.e. OGL.pm) on MacOS uses FreeGLUT if available, and Apple GLUT if FreeGLUT isn't available, or if instructed on the command-line. That's at the C linking stage. The From your note above, I would expect that explicitly getting the fontconfig stuff from Homebrew too would obviate the problem you're having. The fact that you don't have any CI at all for Prima:OGL, including for MacOS, doesn't help. You ought to fix that. |
|
I think I see what you mean. I've checked out the latest OGM and there is already a reservation for GLX on Apple, - that So I decided to test it: If I add manually So let's for a time being put aside the native Apple's Metal which would be very nice, but just for this scope let's focus on the pure GLX setup... are you open to the idea to add a switch to Makefile.PL that would support GLEW_APPLE_GLX? It seems to be compiling alright whether it's homebrew or XQuartz. |
|
F.ex.something like this: -- that would work for me. |
|
If you generalised that to env vars of |
|
I'll see if these env vars can be set to have the desired effect, sure. Btw about CI, would you recommend a decent CI setup for mac, preferrably for github actions? |
|
I recommend highly the CI already on this repo. To be clear, I did say "add" a case on the CI on this repo, not make things wholly from scratch. I know how much agony went into making this one, so I'm only asking you to add to it, not make a whole new one. Assuming you're asking in order to make CI on a different repo, then depending on what you are after, you may also benefit from looking at OGL.pm's CI setup, which is quite similar. If you don't want to dep on the actions @zmughal made, then you could copy-paste them, but if it's for your Prima ecosystem, you might benefit from making a devops repo and putting stuff there. |
|
I'm not sure if it's equally useful for graphics/opengl, but for regular testing on Windows and Mac I'm pretty happy with https://github.com/shogo82148/actions-setup-perl as seen at https://github.com/nrdvana/perl-Crypt-SecretBuffer/blob/main/.github/workflows/ci.yml |
|
That action is used by the whole PDL and POGL-o-sphere! Ironic given you mentioned it, but it's just started failing on MacOS and Linux, hopefully that will get sorted soon. Others have reported it: shogo82148/actions-setup-perl#2481 |
|
I couldn't keep this PR to sync my fork, so I'll reopen it under a new number |
As agreed in Perl-GPU#66, here's the next iteration that would allow linking the module with XQuartz libraries. The intended use is this: env: OGLM_ADD_DEFINE: '-DGLEW_APPLE_GLX -I/opt/X11/include' OGLM_ADD_LIBS: '-L/opt/X11/lib -lglut' OGLM_REPLACE_OTHERLDFLAGS: ''
This change comes from Prima::OpenGL that is built with Prima that uses lots of homebrew libraries, and is actually advised to be built on homebrew. The problem comes with the libraries that are implicitly dependant on the native /opt/X11 libraries, and any program that is compiled with both set of Xlibs (and by extention, GL libs), dumps core.
A possibile solution to this is to let OpenGL::Modern to use homebrew libraries, but that comes with a price, native mac gl will not be used, but the slow emulated MesaGL will be used instead.