Commit Graph

395 Commits

Author SHA1 Message Date
Sebastian Beckmann
2d5ba21204 libobs-opengl: Treat pixel format 0 in IOSurface as 32BGRA
Per the Apple documentation, when 0 is returned from
IOSurfaceGetPixelFormat, the IOSurface is invalid. Prior to [1] however,
any invalid surfaces were (likely accidentally) treated as 32BGRA.
And as it turns out, any IOSurface received from Syphon does not have
the pixel format set, thus returning 0. Because the pixel format happens
to always be 32BGRA, this was never caught. [1] then slightly refactored
the code, fixing the bug not realizing it ever existed. This lead to
Syphon no longer working.

Treating 0 as 32BGRA appears to be the only way to fix this situation
for now and restore prior behavior. Ideally in the future Syphon
provides valid IOSurfaces. An upstream fix to Syphon-Framework is
already submitted, however even if merged, servers would need to update
to that fixed version before things work again. Therefore, this
workaround is needed on the OBS side.

However, the plan for now is for the Metal renderer to not get this
relaxation. It never had it (so Syphon never worked there, making this
not a regression) and it's marked as experimental. Hopefully, by the
time it's stable and/or default, Syphon will be fixed and servers have
been updated.

[1]: 53ad05db9f
2025-10-23 08:35:52 -04:00
PatTheMav
53ad05db9f libobs-opengl: Clean up macOS code with better error handling
Adds more error handling to macOS code and also updates the code to
use more ObjC-appropriate code styling.

Variable names have been changed to be more expressive and platform-
specific constants are used instead of custom FourCharCodes.
2025-08-20 17:42:32 -04:00
PatTheMav
7e2fd72ddf libobs-opengl: Improve macOS error handling for swapchain code
OpenGL swapchain code has been the subject of obscure crashes on macOS
for quite some time, mainly because updates to the swapchain need to
take place on the main thread (because the operations involve the
NSView instances of the application), which introduces possible race
conditions.

This commit adds more error checking to the related functions and makes
OpenGL-related code use copies of data from the graphics thread
(instead of accessing that data as nested data within a global heap
object) and limit "deep" access to a swap-and-delete update of the
texture pointer for the associated frame buffer object.
2025-08-20 17:42:32 -04:00
Yuri Victorovich
18ee961210 libobs-opengl: Make some includes unconditional
Move 3 headers out from the Linux-specific section.
Without these headers functions like open, close, drmXx aren't found.

* open requires <fcntl.h>
* close requres <unistd.h>
* drmXx requires <xf86drm.h>
2025-07-21 17:06:14 -04:00
Ed Maste
16cb051a57 libobs-opengl: Promote eglCreateImage failure to LOG_ERROR
Xcomposite window capture is currently failing on FreeBSD, in
gl_egl_create_texture_from_pixmap (for currently unknown reasons).
Increase the log level of the existing log for eglCreateImage failure
from LOG_INFO to LOG_ERROR to provide a hint for anyone who encounters
the same issue in the future.
2025-05-15 16:55:44 -04:00
tytan652
1bf84a6901 cmake: Replace Xcb CMake finders with ECM 2025-04-28 13:30:26 -04:00
tytan652
190389ec11 cmake: Replace Wayland CMake finder with ECM 2025-04-28 13:30:26 -04:00
Alex Luccisano
abb8cdf0da libobs, libobs-opengl: Add memory and identification APIs
Add graphics APIs to obtain the GPU driver version and renderer
strings, as well as GDDR memory sizes. The GDDR memory sizes
include the dmem (dedicated memory on the GPU) and smem
(shared CPU memory used by the GPU but resides in the CPU DDR).

The version and renderer strings are needed for identification
purposes, for example enhanced broadcasting used by Twitch, to
associate the GPU used by OBS with the PCIe-based identification
values such as device_id and vendor_id.
2025-04-01 23:18:15 -04:00
Doğukan Korkmaztürk
68ca91b21d libobs,libobs-opengl: Add gs_sync_t
This change adds a new type named gs_sync_t and related functions to X11
and Wayland EGL backends to abstract DRM syncobjs and their various
uses.

Signed-off-by: Doğukan Korkmaztürk <dkorkmazturk@nvidia.com>
2025-02-05 16:20:15 -05:00
tytan652
a0e4e37341 libobs-opengl: Avoid trying to allocate 0 byte on Linux
Some checks failed
Push / Format 🔍 (push) Has been cancelled
Push / Build 🧱 (push) Has been cancelled
Push / Validate Compatibility 🕵️ (push) Has been cancelled
Push / Validate Services 🕵️ (push) Has been cancelled
Push / Update Documentation 📖 (push) Has been cancelled
Push / Deploy Documentation to Cloudflare ☁️ (push) Has been cancelled
Push / Create Sparkle Appcast 🎙️ (arm64) (push) Has been cancelled
Push / Create Sparkle Appcast 🎙️ (x86_64) (push) Has been cancelled
Push / merge-appcasts (push) Has been cancelled
Push / Windows Signing ✍️ (push) Has been cancelled
Push / Create Release 🛫 (push) Has been cancelled
2024-12-20 16:23:10 -05:00
Ryan Foster
a1fbf1015f clang-format: Increase column limit from 80 to 120 2024-10-04 18:19:27 -04:00
PatTheMav
6c590805e8 cmake: Update supported CMake version range to 3.28 and 3.30 2024-09-13 14:42:32 -04:00
tytan652
26d275223a libobs-opengl: Relax texture format copy check
SRGB and non-SRGB formats are compatible for copy.
2024-09-12 15:35:46 -04:00
tytan652
31385006d5 Remove legacy_check CMake macro
The macro was not removed in 72428ccd97
waiting for submodules to be be updated to a commit where their legacy
code path is removed.
2024-09-11 13:24:39 -04:00
tytan652
72428ccd97 Remove CMake legacy code path
Except submodules and legacy_check macro since the former depend on it.
2024-08-28 13:53:25 -04:00
PatTheMav
b8cfacaec3 Update formatting of CMake files 2024-08-14 12:07:47 -04:00
Norihiro Kamae
5dd97b3688 libobs-opengl: Remove unused static-inline function 2024-08-07 17:27:49 -04:00
Kurt Kartaltepe
7912d06b65 libobs-opengl: Disable NV12/P010 on Windows
These formats are used for texture encoding but the OpenGL texture
encoding pipeline is not supported on Windows. This can also cause
failure to initialize on Windows so it's better to disable the formats.
2024-07-22 18:07:03 -04:00
PatTheMav
eee912b8ba libobs-opengl: Add Linux-specific changes for CMake build framework 3.0 2024-04-13 23:48:38 -04:00
Kurt Kartaltepe
d2e50c8c38 libobs-opengl: Specify display attributes
This is functionally a no-op, but works around a driver bug that
prevents use of eglQueryDisplayAttribEXT. This makes us more likely to
not trigger the driver bug and that gs_enum_adapters works correctly.
2024-02-03 17:23:01 -06:00
Kurt Kartaltepe
3e49e89611 libobs,libobs-opengl,libobs-d3d11: Add opengl gs_enum_adapters
This adds gs_enum_adapters and gs_get_adapter_count to the opengl
backend and promotes these to multiplatform graphics functions.

However we need to make an internal device change, device_enum_adapters
must pass in the current device on opengl to ensure that adapter #0 is
the display adapter. We do this to avoid changes to plugins already
checking against obs_video_info.adapter which is always 0 and expected
to be the device OBS was initialized on.

The actual implementation reports the dri render node (or /Software).
This allows plugins to query non-video features of the adapters like
VA-API/NVENC/etc or other cross device functionality. `/Software` is
chosen to avoid opening random files in the current directory if its
passed along as a file path like the regular dri render nodes.
2024-01-27 17:51:33 -06:00
Kurt Kartaltepe
34950f7fb2 libobs-opengl: Enable imported dmabufs for rendering
For now just tag all imported images with GS_RENDER, this may not work
for some images that were produced by some hardware other than the GPU
render engines. But since we don't import VA-API decoded frames we
probably won't run into this. And we need this to render into VA-API
frames destined for encoding.
2024-01-26 20:01:58 -05:00
Kurt Kartaltepe
02c90207fc libobs,libobs-opengl: enable GPU encoding for OpenGL
Enable all of the previously Windows only paths for OpenGL backends that
support encode_texture2

Co-authored-by: Torge Matthies <openglfreak@googlemail.com>
2024-01-26 20:01:58 -05:00
PatTheMav
f7d6593a25 libobs-opengl: Update CMake formatting with manual format choices 2023-12-19 17:59:44 -05:00
Ryan Foster
fc693f9c3d libobs: Update CMake minimum to 3.22
Since Ubuntu 22.04 is now our minimum supported Ubuntu version, and it
has CMake 3.22, let's make CMake 3.22 the minimum CMake version.
2023-08-05 16:45:46 -07:00
jpark37
0934e73902 libobs-opengl: Support mad/uint2/uint3/uint4 2023-07-29 16:41:31 -07:00
PatTheMav
3ca56fee84 libobs: Silence clang warnings for empty prototypes without void
clang expects an empty prototype to explicitly use `void`.

Also silences the warning in `libobs-opengl`, `obsglad`, `caption`,
`mac-syphon` and `obs-x264-test`.
2023-06-16 14:12:58 -04:00
PatTheMav
f8e00d6071 clang-format: Update formatting of all ObjC and ObjC++ files 2023-06-11 14:56:45 +02:00
Lain
106c7aa61f Update copyrights/names 2023-05-20 01:31:18 -07:00
PatTheMav
349372b3b3 cmake: Add changes for CMake build framework 3.0
New code path only taken if OBS_CMAKE_VERSION is set to 3.0.0 or
greater, old functionality remains unchanged.
2023-03-26 18:20:38 -04:00
PatTheMav
41a10b05fd libobs-opengl: Refactor macOS implementation
Replaces macros with actual code and uses more platform-specific code.
As an added benefit this improves debugging and code navigation in
Xcode.
2023-02-18 15:22:33 -08:00
PatTheMav
2f4b611fd7 libobs-opengl: Fix non-exhaustive switch statement 2023-02-18 15:22:33 -08:00
PatTheMav
27ba216271 libobs-opengl: Fix projector crash with external macOS displays
When an external display is disconnected with a fullscreen projector
attached to it, Qt will trigger a resize of the window twice, which
makes the renderer queue 2 resize event blocks.

At the time when those blocks are run, Qt's window destructor will have
reset all pointers, and the block directly accesses pointers within
structures identified by pointers, which are invalid by that point.

This commit makes a block return early if the associated window has
been destroyed already and also explicitly checks for valid pointers
after.
2023-02-15 16:34:21 +01:00
Kurt Kartaltepe
041fee0484 libobs-opengl: Accelerate dmabuf import
Previously we would actually initialize a texture memory that would then
also have to be deleted when we bound the EGLImage to the texture during
dmabuf import.

Instead simply do not create the dummy texture memory. One odd thing is
that we must still query the texture to ensure its initialized or
binding the EGLImage will not work. So we leave the TEXTURE_MAX_LEVEL
check.

This makes screencapture up to 100x faster on discrete intel cards and
likely has some performance benefit for amd/integrated cards. Without
this dmabufs are actually slower than shared memory for these intel
cards.
2023-02-12 19:07:05 -03:00
Barnabás Pőcze
8e96d47cd3 libobs-opengl: Close display when destroying X11/EGL platform
Currently, the X11 display may be leaked when the X11/EGL
platform is destroyed. Fix that by calling XCloseDisplay()
to free it.

Fixes: 2fd8a6df55 ("libobs-opengl: Introduce the X11/EGL winsys")
2023-01-25 13:56:50 -05:00
Barnabás Pőcze
dee7ef8512 libobs-opengl: Do not close X11 platform display on error
The platform display is not owned by libobs, it should not
be closed. Doing so results in heap use-after-frees when
Qt components try to use it while trying to show
a message box about the failure:

  info: Initializing OpenGL...
  error: Failed to initialize EGL: EGL_BAD_ACCESS
  error: Failed to create context!
  error: device_create (GL) failed
  error: Failed to initialize video.  Your GPU may not be supported, or your graphics drivers may need to be updated.
  =================================================================
  ==2320345==ERROR: AddressSanitizer: heap-use-after-free on address 0x621000018668 at pc 0x7fcb75e20d6e bp 0x7ffe88d0e910 sp 0x7ffe88d0e900
  READ of size 8 at 0x621000018668 thread T0
      0 0x7fcb75e20d6d in XInternAtom /.../libx11/src/IntAtom.c:175
      1 0x7fcb6bf5edfd in Kvantum::ThemeConfig::getCompositeSpec()
      2 0x7fcb6bf0eb19 in Kvantum::Style::setSurfaceFormat(QWidget*) const
      3 0x7fcb6bf11bae in Kvantum::Style::styleHint(QStyle::StyleHint, QStyleOption const*, QWidget const*, QStyleHintReturn*) const
      4 0x5585cbce70b8 in OBSIgnoreWheelProxyStyle::styleHint(QStyle::StyleHint, QStyleOption const*, QWidget const*, QStyleHintReturn*) const /.../obs-studio/UI/obs-proxy-style.cpp:88
      5 0x7fcb85826515  (/usr/lib/libQt6Widgets.so.6+0x226515)
      6 0x7fcb859dbf1d  (/usr/lib/libQt6Widgets.so.6+0x3dbf1d)
      7 0x7fcb859dc5f0 in QMessageBox::QMessageBox(...)
      8 0x7fcb859dc6b1  (/usr/lib/libQt6Widgets.so.6+0x3dc6b1)
      9 0x5585cbd2fb31 in OBSErrorBoxva /.../obs-studio/UI/qt-wrappers.cpp:48
      10 0x5585cbd2fd34 in OBSErrorBox(QWidget*, char const*, ...) /.../obs-studio/UI/qt-wrappers.cpp:55
      11 0x5585cbcc3f36 in run_program /.../obs-studio/UI/obs-app.cpp:2475
      12 0x5585cbcc52b4 in main /.../obs-studio/UI/obs-app.cpp:3358
      13 0x7fcb82e3c28f  (/usr/lib/libc.so.6+0x2328f)
      14 0x7fcb82e3c349 in __libc_start_main
      15 0x5585cbbd2f54 in _start

Fixes: 137966e01f ("libobs-opengl: Try to use the platform display if available")
2023-01-25 13:56:50 -05:00
Kurt Kartaltepe
4216991413 libobs-opengl: Fixup dmabuf queries on X11
Previously we passed the wrong display and formats/modifiers could not
be queried. This prevented pipewire sources from negotiating texture
sharing on x11.
2023-01-24 16:28:51 -03:00
tytan652
c648222332 libobs,libobs-opengl,obs-ffmpeg-mux: Calm deprecation warnings on *nix
Calm libobs-opengl deprecation warnings on macOS.

Calm FFmpeg deprecation warning with LIBAVFORMAT_VERSION_MAJOR < 59.
2023-01-19 13:08:46 -05:00
tytan652
107b2a8f27 libobs-d3d11,libobs-opengl,plugins: Remove unneeded cast in switches
Those casts were usually used to workaround switch warnings.
2023-01-16 11:52:26 +01:00
tytan652
cf5c68b773 UI,libobs,libobs-opengl,obs-ffmpeg: Remove unneeded cast in switches
Those casts were usually used to workaround switch warnings.

Also adds default to OBS frontend event switches that had this
workaround.
2023-01-16 11:52:26 +01:00
Kurt Kartaltepe
599b017881 libobs-opengl: Drop gl pointers on device_leave_context
Mac was already dropping a most of these when leaving contexts,
this patch brings the same drops to linux and also drops vertex/index
buffers that were noticed as leaking across contexts and resulting in
invalid bindings by later draws. Especially with the new spacing labels.
2023-01-14 15:33:18 -08:00
jpark37
37cc894333 libobs-opengl: Support l10r IOSurface 2022-11-09 22:34:50 -08:00
PatTheMav
9650109748 libobs-opengl: Disable deprecation warnings on macOS
We are aware of OpenGL having been deprecated on macOS since
Mac OS X 10.14, so silence the deprecation warnings the "official" way.
2022-09-17 16:29:51 -07:00
Kurt Kartaltepe
674bd3f821 libobs-opengl: Use a simple 24bit framebuffer
When using EGL the mesa+nvidia stack are unable to offload 32bit
framebuffers despite having this capability on GLX. In practice the X11
server does not support alpha windows so we dont need the alpha
component in our framebuffer. We previously had alpha specified in our
framebuffer since we do alpha texturing but testing shows this isnt
required for mesa/intel or nvidia drivers and we must pick a 24bit
config for users to enable render offloading for mixed gpu systems.

fixes #6984
2022-08-30 15:28:45 -03:00
jpark37
2c7ef7d682 libobs-opengl: Fix Mac projector color space
Use sRGB instead of native display color space for correctness.
2022-08-24 05:08:26 -07:00
Kurt Kartaltepe
7f3ea4e00c libobs-opengl: Check window creation for errors
Without this we get somewhat misleading errors from later in the
swapchain creation when this fails. This is currently happening for
users attempting to use multi-gpu with prime offloading on nvidia.
2022-08-09 13:55:45 -03:00
jpark37
4fe6803fe4 libobs: Prevent D3D11 projectors from tearing
Some users stream projectors, so don't let them tear. Use the waitable
object to check the flip queue, and only flip if there's space.

Metal and Vulkan can probably perform similar flip throttling once OBS
starts using them.
2022-08-06 16:16:20 -07:00
PatTheMav
4edb034790 libobs-opengl: Fix error message for invalid IOSurface buffers
Syphon relies on global IOSurfaces which are not officially supported
by macOS anymore. While the core functionality is still available,
`IOSurfaceGetPixelFormat` will not return a valid pixel format.
2022-07-31 12:21:35 +02:00
Developer-Ecosystem-Engineering
9ed5062e59 mac-capture: Add support for improved window capture in macOS 12.3
Add a new capture plugin called General Capture that allows for capture
of an entire desktop, a single window, or all windows of an application
2022-07-24 13:59:09 +02:00
tytan652
057e433bdb libobs-opengl: Replace OBS_UNUSED with UNUSED_PARAMETER
OBS_UNUSED is not portable to MSVC.
2022-07-20 08:22:08 +02:00