Commit graph

377 commits

Author SHA1 Message Date
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
Norihiro Kamae af3890a4a9 libobs: Cleanup unused-parameters
- Add OBS_UNUSED to unused function parameters
- Remove unnecessary UNUSED_PARAMETER
Also update libobs-opengl/
2022-07-19 11:01:00 -04:00
Kurt Kartaltepe 4163940137 libobs-opengl: Change log level for texture_from_pixmap
This function is expected to fail fairly often as it is the tool for
checking if windows are mapped and have a valid pixmap in the linux
capture plugin. So reduce this error to a debug message to avoid
spamming release builds.
2022-07-10 11:24:40 +10:00
Norihiro Kamae f4854dccb4 libobs-opengl: Remove unnecessary call to retrieve screen number
The code to retrieve the screen number was originally implemented for
GLX but not necessary for EGL.
2022-06-08 08:55:03 -03:00
Norihiro Kamae 6c39b023ad libobs-opengl: Remove unused code 2022-06-08 08:55:03 -03:00
Georges Basile Stavracas Neto ca2d02c2ce Drop GLX renderer
"They must often change, who would be constant in happiness or wisdom"

 - Confucius
2022-05-24 14:31:48 -03:00
Kurt Kartaltepe d78b27961c libobs-opengl: Add create_texture_from_pixmap for EGL
create_texture_from_pixmap is only implemented for X11/EGL where it will
bind the provided X11 pixmap to a texture with glEGLImageTargetTexture2DOES
2022-05-15 09:08:53 -03:00
mvji c6029ac658 libobs-opengl: Fix compiler warning
Fix unused parameter warning.
2022-04-23 16:12:45 -07:00
Kurt Kartaltepe 855572ed7c libobs-opengl: Disable vsync during present
Brings X11 EGL in line with Wayland. This prevents you from recording at
a higher fps than the monitor where an OBS preview is being displayed.
2022-04-23 00:57:42 -03:00
Kurt Kartaltepe f695b14edc libobs-opengl: Use gl helpers in create_dmabuf_image
This replaces direct OpenGL calls to error handling helpers. Previously
this would cause errors to be misattributed to the next OpenGL functions
called.

Fixes DMA-BUF importing returning a texture on failure on KDE+NVIDIA.
2022-04-11 23:18:00 -03:00
jpark37 eccde48926 libobs/graphics: Add gs_is_monitor_hdr
Only Windows is implemented for now. Mac/Linux return false for now.
2022-03-23 22:35:26 -07:00
jpark37 abddfead2f libobs/graphics: Add color space support 2022-03-23 22:35:26 -07:00
PatTheMav 1fd7770548
libobs: Update CMakeLists.txt for libobs and associated libraries
Also updates libobs-opengl, libobs-d3d11, libobs-winrt
2022-03-16 23:11:08 +01:00
jpark37 63db2265dc libobs, libobs-d3d11, libobs-opengl: Add GS_RG16
This format will be useful for P010 chroma in the future.
2022-01-29 15:12:00 -08:00
Richard Stanway a3c97dfad2 libobs-opengl: Miscellaneous static analysis fixes
Detected by PVS Studio.
2022-01-15 23:02:38 +00:00
jp9000 8ed8301452 libobs-opengl: Fix border color support on GL textures 2022-01-12 06:35:16 -08:00
jp9000 9bd9513e94 Revert "libobs-opengl: Use PBO in device_stage_texture on macOS"
This reverts commit 76f7a0c1c0.

Unfortunately, the performance issue is still present with PBOs even on
Monterey. During the 27.2 beta, macOS users even on Monterey have been
reporting a performance regression, and when the profiler data for those
users was looked at, major performance loss was noted in the
stage_output_texture function. This commit was the only probable cause.
2022-01-01 18:38:33 -08:00
Richard Stanway 7f2dfd53a9 libobs-opengl: Use correct size for PIXELFORMATDESCRIPTOR
Issue detected by PVS Studio.
2021-12-30 22:53:22 +01:00
Georges Basile Stavracas Neto e1f01554f7 libobs-opengl: Swap order of out parameters
The usual pattern of function signature is "array / n_elements",
but query_dmabuf_formats() does not follow it. Apply this order
to query_dmabuf_formats().
2021-12-30 18:41:04 -03:00