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.
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.
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.
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.
Enable all of the previously Windows only paths for OpenGL backends that
support encode_texture2
Co-authored-by: Torge Matthies <openglfreak@googlemail.com>
clang expects an empty prototype to explicitly use `void`.
Also silences the warning in `libobs-opengl`, `obsglad`, `caption`,
`mac-syphon` and `obs-x264-test`.
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.
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.
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")
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")
Previously we passed the wrong display and formats/modifiers could not
be queried. This prevented pipewire sources from negotiating texture
sharing on x11.
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.
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
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.
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.
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.
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.
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.