Commit graph

125 commits

Author SHA1 Message Date
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 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
Ryan Foster e5d5df879c libobs: Add function to check fast clear capability 2023-07-29 16:34:47 -07:00
Lain 106c7aa61f Update copyrights/names 2023-05-20 01:31:18 -07:00
jpark37 7bfde66578 libobs-d3d11: Support color spaces for duplicator
Need this plumbing to make decisions about duplicator colors.
2023-02-19 11:40:32 -08:00
Jan Beich c082c4a74d libobs/graphics: Enable DMABUF on FreeBSD and DragonFly
Required under Wayland (wlrobs) on FreeBSD and DragonFly. DMABUF was
already partially exposed after c50c625555.
2023-01-24 11:50:13 -05: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
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
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
jpark37 fee3703f40 libobs/graphics, libobs-d3d11: Add P010 support 2022-03-20 17:22:13 -07:00
columbarius 4cda05f270 libobs/graphics: Add Linux-only gs_query_dmabuf_* functions
When sharing DMA-BUFs it is required the announce the underlying
hardware capabilities via supported modifiers.

Add new device_query_dmabuf_capabilities vfunc to gs_exports and connect it
to the egl implementation stubs in the supported render platforms. Add a new
public method gs_query_dmabuf_capabilities() that calls the vfunc above.

Add new device_query_dmabuf_modifiers vfunc to gs_exports and connect it
to the egl implementation in the supported render platforms. Add a new
public method gs_query_dmabuf_modifiers() that calls the vfunc above.
2021-12-22 14:27:53 -03:00
jw0z96 33a6d2a5fd libobs: Expose blending operation types 2021-12-20 09:06:38 -08:00
VodBox c8e417057a libobs, libobs-d3d11: Add support for NT Handle shared textures
Adds support for using shared textures that were made with the
D3D11_RESOURCE_MISC_SHARED_NTHANDLE flag.

This increases the minimum required Windows version to Windows 8 or the
Platform Update for Windows 7. As official support is only for Win 8+
this does not change official support.
2021-11-20 16:34:28 +13:00
jpark37 3c45ae2e9d libobs, libobs-opengl: Consistent near/far undef 2021-10-10 19:12:45 -07:00
Tommy Vercetti e1cf7c0e4b libobs: Fix near and far redefinition on MSVC 2021-09-11 15:50:06 -07:00
Kurt Kartaltepe 705a47b0e4 libobs, libobs-opengl: add drm format param
This adds the drmbuf format as a parameter separate from the obs texture
format that will be used. drmbuf's may have a variety of formats that we
need to pass correctly to get a usable texture which may correspond to
multi-platform texture formats.
2021-03-29 17:00:31 -03:00
jpark37 c03320cfc2 libobs: Add function to count GPU adapters
Only implemented for D3D11 for now.
2021-03-12 20:59:31 -08:00
Georges Basile Stavracas Neto f7a55f45fd libobs/graphics: Add Linux-only gs_texture_create_from_dmabuf()
DMA-BUF is a widespread Linux buffer sharing mechanism. It is what's
commonly used zero-copy screen sharing by Wayland compositors.

Add a new 'device_texture_create_from_dmabuf' vfunc to gs_exports,
and stub implementations to libobs-opengl. Add a new public method
gs_texture_create_from_dmabuf() that calls this vfunc.
2021-02-13 19:13:54 -03:00
jpark37 2b652cc763 libobs: gs_duplicator_get_monitor_index
Helper function to find DXGI output index of HMONITOR.
2021-01-26 17:11:04 -08:00
jpark37 66259560e0 libobs: Add dormant SRGB format support
GS_RGBA, GS_BGRX, and GS_BGRA now use TYPELESS DXGI formats, so we can
alias them between UNORM and UNORM_SRGB as necessary. GS_RGBA_UNORM,
GS_BGRX_UNORM, and GS_BGRA_UNORM have been added to support straight
UNORM types, which Windows requires for sharing textures from D3D9 and
OpenGL. The D3D path aliases via views, and GL aliases via
GL_EXT_texture_sRGB_decode/GL_FRAMEBUFFER_SRGB.

A significant amount of code has changed in the D3D/GL backends, but the
concepts are simple. On the D3D side, we need separate SRVs and RTVs to
support nonlinear/linear reads and writes. On the GL side, we need to
set the proper GL parameters to emulate the same.

Add gs_enable_framebuffer_srgb/gs_framebuffer_srgb_enabled to set/get
the framebuffer as SRGB or not.

Add gs_linear_srgb_active/gs_set_linear_srgb to instruct sources that
they should render as SRGB. Legacy sources can ignore this setting
without regression.

Update obs_source_draw to use linear SRGB as needed.

Update render_filter_tex to use linear SRGB as needed.

Add gs_effect_set_texture_srgb next to gs_effect_set_texture to set
texture with SRGB view instead.

Add SRGB helpers for vec4 struct.

Create GDI-compatible textures without SRGB support. Doesn't seem to
work with SRGB formats.
2021-01-21 07:42:13 -08:00
ckelsel 9e07c42d74 libobs: Fix gs_duplicator_get_texture function check 2021-01-11 11:16:02 -08:00
PatTheMav 61ea6e0247
libobs: Add texture sharing support for macOS/OpenGL 2020-12-18 17:44:03 +01:00
jpark37 2d547cf669 libobs: Allow wrapping D3D11 object with gs_texture_t
This can be useful for reading from textures provided by middleware.
2020-11-24 14:39:56 -08:00
jpark37 cd6f56d0ea libobs: Fix potential truncation warnings 2020-05-21 10:02:03 -07:00
jp9000 b31c166814 Revert "graphics: libobs-d3d11: Use DXGI_SWAP_EFFECT_FLIP_DISCARD on Windows 10"
This reverts commit 4da73445c3.

This is being reverted because apparently it causes flickering displays
for some people.  Bad drivers or something?  Not sure.  Very annoying.
2020-03-11 09:35:47 -07:00
jpark37 f27f858ab3 libobs: Support device loss registration
Complex external systems using the D3D11 device may need to perform
their own device loss handling, the upcoming Windows Graphics Capture
support for example.
2020-02-22 21:02:33 -08:00
Jim 3e01fdf3e5
Merge pull request #2116 from jpark37/begin-frame
libobs: Add gs_begin_frame for duplicators
2019-10-15 22:23:34 -07:00
jpark37 ade65df2aa libobs: Add gs_begin_frame for duplicators
We really shouldn't be resetting duplicator state as part of gs_flush.
gs_begin_scene is not ideal because it is called twice per frame, and
only after duplicators have been ticked. Even though it makes no
user-facing difference, it makes more logical sense to reset at the top
of the frame than the bottom.
2019-10-10 21:06:01 -07:00
jpark37 4da73445c3 graphics: libobs-d3d11: Use DXGI_SWAP_EFFECT_FLIP_DISCARD on Windows 10
This is supposed to eliminate a copy by DWM with extra benefits for
borderless fullsceen, which should help the fullscreen projector.
2019-09-06 19:39:42 -07:00
jp9000 09fc41cc06 libobs: Use correct pointer
This is not supposed to pass the graphics context pointer -- it's
supposed to pass the device pointer held by the graphics context object.
2019-08-30 00:36:27 -07:00
jp9000 bf41fd5a6b libobs: Add graphics API to get graphics object pointer 2019-08-29 12:43:10 -07:00
jpark37 0e12d8189c libobs: Add GPU timestamp query support
This change only wraps the functionality. I have rough code to exercise
the the query functionality, but that part is not really clean enough to
submit.
2019-07-27 13:31:07 -07:00
jp9000 f53df7da64 clang-format: Apply formatting
Code submissions have continually suffered from formatting
inconsistencies that constantly have to be addressed.  Using
clang-format simplifies this by making code formatting more consistent,
and allows automation of the code formatting so that maintainers can
focus more on the code itself instead of code formatting.
2019-06-23 23:49:10 -07:00
James Park ba21fb947e libobs: Fix various alpha issues
There are cases where alpha is multiplied unnecessarily. This change
attempts to use premultiplied alpha blending for composition.

To keep this change simple, The filter chain will continue to use
straight alpha. Otherwise, every source would need to modified to output
premultiplied, and every filter modified for premultiplied input.

"DrawAlphaDivide" shader techniques have been added to convert from
premultiplied alpha to straight alpha for final output. "DrawMatrix"
techniques ignore alpha, so they do not appear to need changing.

One remaining issue is that scale effects are set up here to use the
same shader logic for both scale filters (straight alpha - incorrectly),
and output composition (premultiplied alpha - correctly). A fix could be
made to add additional shaders for straight alpha, but the "real" fix
may be to eliminate the straight alpha path at some point.

For graphics, SrcBlendAlpha and DestBlendAlpha were both ONE, and could
combine together to form alpha values greater than one. This is not as
noticeable of a problem for UNORM targets because the channels are
clamped, but it will likely become a problem in more situations if FLOAT
targets are used.

This change switches DestBlendAlpha to INVSRCALPHA. The blending
behavior of stacked transparents is preserved without overflowing the
alpha channel.

obs-transitions: Use premultiplied alpha blend, and simplify shaders
because both inputs and outputs use premultiplied alpha now.

Fixes https://obsproject.com/mantis/view.php?id=1108
2019-05-08 20:26:52 -07:00
jp9000 f109d1c2bf Revert "libobs: libobs-d3d11: obs-filters: No excess alpha"
This reverts commit d91bd327d7, which
broke alpha with sources, scenes, and filter, causing them all to become
opaque unintentionally.
2019-04-25 08:36:41 -07:00
James Park 8bafa51d3b libobs: Fix GS_UNSIGNED_LONG definition
GS_UNSIGNED_LONG is defined as sizeof(long) in some places, making it 8
outside of Windows instead of 4 as it should be.

Fixes https://obsproject.com/mantis/view.php?id=1444
2019-04-21 21:25:35 -07:00
Jim f1399b6d18
Merge pull request #1765 from jpark37/blend-alpha
libobs: libobs-d3d11: Fix blend alpha overflow
2019-04-14 00:22:20 -07:00
James Park 2996a6c06b libobs/graphics: Support debug markers
Add support for debug markers via D3DPERF API and KHR_debug. This makes
it easier to understand RenderDoc captures.

D3DPERF is preferred to ID3DUserDefinedAnnotation because it supports
colors. d3d9.lib is now linked in to support this.

This feature is disabled by default, and is controlled by
GS_USE_DEBUG_MARKERS.

From: obsproject/obs-studio#1799
2019-04-08 02:05:37 -07:00
James Park d91bd327d7 libobs: libobs-d3d11: obs-filters: No excess alpha
Currently SrcBlendAlpha and DestBlendAlpha are both ONE, and can
combine together to form two. This is not a noticeable problem for
UNORM targets because the channels are clamped, but it will likely
become a problem if FLOAT targets are more widely used.

This change switches DestBlendAlpha to INVSRCALPHA, and starts
backgrounds as opaque black instead of transparent black. The blending
behavior of stacked transparents is preserved without overflowing the
alpha channel.
2019-04-07 18:16:56 -07:00
jp9000 93fc61fa82 libobs/graphics: Add NV12 texture support 2019-02-07 17:00:46 -08:00
jp9000 b64d7d71d0 libobs/graphics: Add texture sharing functions 2019-02-07 17:00:46 -08:00
jp9000 b56c33a260 libobs/util: Add THREAD_LOCAL macro
Adds a thread local storage macro to declare thread local storage
independent of platform.
2018-01-03 17:04:02 -08:00
jp9000 c111fa68b8 libobs: Add vertex/index buffer "direct" flush functions
(Note: This commit also modifies libobs-d3d11 and libobs-opengl)

Allows the ability to flush data directly without having to use the
buffer's internal data.

Allows the caller to manage his/her own vertex/index buffer data if
desired, working around the design flaw of having to rely on a
vertex/index buffer's internal data.
2017-11-27 03:00:20 -08:00
jp9000 a46f0b4808 libobs: Add option to duplicate vertex/index buffer data
Prevents from having to pass ownership of buffer data from caller when
using gs_vertexbuffer_create() or gs_indexbuffer_create() (which is a
design flaw).
2017-11-27 02:45:33 -08:00
jp9000 0bc0db1207 libobs/graphics: Add gs_draw_sprite_subregion function
Allows rendering only a subregion of a specific sprite.
2016-09-19 07:03:57 -07:00
jp9000 4dc0024198 libobs/graphics: Add ability to set shader texture sampler
(Note: This also modifies libobs-d3d11 and libobs-opengl)

Allows overriding the sampler for a specific shader parameter.
2016-06-29 04:15:38 -07:00
jp9000 9f63554e69 libobs: Add gs_create_texture_file_data function
Allows loading the file to memory first so the graphics subsystem
doesn't necessarily have to be locked when loading image files.
2016-01-23 07:17:48 -08:00
jp9000 46feac7f8f libobs/graphics: Allow gs_render_sprite use without texture
Allows gs_render_sprite to be used without a texture as long as cx/cy
are set.  There's no reason why it shouldn't be able to do this.
2016-01-23 07:17:45 -08:00
jp9000 0be0eedc81 libobs/graphics: Allow NULL *_destroy parameters
Passing null pointer values to the destroy functions should be
considered legal and simply ignored.
2015-10-22 17:37:59 -07:00