Commit graph

93 commits

Author SHA1 Message Date
jpark37 a8866fe3fa libobs-d3d11: Remove new/delete replacements
MSVC noticed inline is not allowed, and new/delete replacments also
don't belong in a header file. We're also just leaning on
__STDCPP_DEFAULT_NEW_ALIGNMENT__ being 16 for MSVC x64 now.
2024-01-11 04:02:31 -06:00
jpark37 972e24df79 libobs-d3d11: Use OS D3DCompiler_47.dll
OBS needs Windows 10 minimum these days, so the DLL will be there.
2023-11-18 17:17:25 -06:00
Ryan Foster a8f770fdfc libobs-d3d11: Check if device can perform fast clear on init
NVIDIA GPUs in multi-GPU setups cannot safely perform a fast clear until
driver 527.37. Implement a check against the Vendor ID and driver
version of the adapter to determine if the adapter can safely perform a
fast clear.

Co-authored-by: derrod <dennis@obsproject.com>
2023-07-29 16:34:47 -07:00
Richard Stanway e7a3ffdb54 libobs-d3d11: Implement shader cache
Co-Authored-By: derrod <dennis@obsproject.com>
2023-07-22 16:59:31 -07:00
derrod dcc07cfe4e clang-format: Set AllowAllConstructorInitializersOnNextLine to false 2023-07-15 16:14:55 -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
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
Ryan Foster 88ea0bbb56 Revert "libobs-d3d11: Default to Intel IGPU on IGPU+DGPU systems"
This reverts commit c83eaaa51c.
2022-12-30 21:14:15 -08:00
jpark37 d9fe6977a6 libobs-d3d11: Support advanced SDR window preview
Displays more than 8 bpc if monitor is configured to be higher.
2022-11-09 22:35:24 -08: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
jpark37 d9d4b69a59 libobs-d3d11: Add monitor to HDR status cache
Requesting HDR status is surprisingly expensive.
2022-04-14 09:36:09 -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
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
jpark37 83c89d06b5 libobs-d3d11: Log display color space info
Add DXGI_COLOR_SPACE_TYPE and SDR white level when available for HDR
characteristics.

GetPathInfo/IsInternalVideoOutput functions were copied from MS docs.
2022-01-07 15:18:16 -08: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 608cd3867e libobs-d3d11: Use waitable object to avoid stalls
Skip Present if the waitable object says the swap chain isn't ready.
2021-09-15 02:52:12 -07:00
jpark37 00941ffc84 libobs-d3d11: Use ALLOW_TEARING if supported 2021-09-11 01:33:55 -07:00
jpark37 7ce2a60a1d libobs-d3d11: Use FLIP_DISCARD on Windows 11
Windows 11 support for DISCARD swap effect seems to be buggy and slow.
Use FLIP_DISCARD instead. Staying with DISCARD on Windows 10 because of
reports of flickering that hopefully won't happen on Windows 11.

We're also not using ALLOW_TEARING because it seems to break after an
OBS cycle of minimize/restore on both Windows 10 and 11. The swap chain
displays a stale image. Not sure if ALLOW_TEARING would be beneficial
even if it was working.
2021-09-10 20:19:24 -07:00
jpark37 5457524f5a libobs-d3d11: Avoid vector usage
Allocations need global heap lock, which is bad.
2021-08-15 00:12:14 -07:00
Lin c83eaaa51c libobs-d3d11: Default to Intel IGPU on IGPU+DGPU systems
On systems that have both Intel iGPU and Intel dGPU at the same time,
default/prioritize running OBS the iGPU instead to improve performance.
The user can still choose the dGPU if they change the adapter index, but
the adapter index will now be the second value instead of the first
value. (-Jim)
2021-03-21 22:45:08 -07:00
Lin 1e106c8bb8 libobs-d3d11: Split InitFactory to InitAdapter
Splits off the adapter initialization to its own function so we can
modify what happens in between those actions. (-Jim)
2021-03-21 22:45:08 -07: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
jpark37 c72b5de23e libobs-d3d11: Support typeless textures
In the future, we may share or wrap typeless textures to support SRGB
and non-SRGB views.
2021-01-11 14:18:12 -08: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 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
jpark37 ed91c4e3bc libobs-d3d11: Don't allow volume render targets
Unlikely to be necessary. Disable for simplicity.
2020-01-01 12:40:03 -08:00
jpark37 8f6984e345 libobs: Add support for volume textures
Also fix some mip calculations along the way.
2019-12-15 14:38:26 -08: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 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 52eb536b04 libobs-d3d11: Check for bad NV12 output on all devices
Just to be safe, check for bad output on all devices.
2019-03-04 15:40:53 -08:00
jp9000 b4c35fab75 libobs-d3d11: Perform actual test for NV12 driver bug
Performs a test on a texture to determine if NV12 textures are
functioning correctly.  Older NVIDIA drivers appear to have a bug where
they will output their UV channel data on to the Y channel when copying
from the GPU.  This test on startup determines whether that bug is
occurring, and if so, disables NV12 texture support.
2019-03-04 14:06:10 -08:00
jp9000 8f3ea18276 libobs-d3d11: Use discrete function to get shared handle
Allows us to reacquire the shared handle if the texture is rebuilt.
2019-03-03 08:41:23 -08:00
jp9000 492f50ee87 libobs-d3d11: Set acquired bool when texture acquired
This is used when the device needs to be rebuilt.  Ensures that the
texture doesn't get locked again if the texture is rebuilt.
2019-03-03 08:39:47 -08:00
jp9000 925f72c8c3 libobs-d3d11: Fix rebuild of NV12 textures
When NV12 textures were added, driver crashes and their rebuild process
was not taken in to consideration.  This fixes that by adding explicit
NV12 rebuild functions.
2019-02-17 17:42:48 -08:00
jp9000 e09c63914e libobs-d3d11: Don't inline rebuild funcs
Inlining these functions is pretty pointless.
2019-02-17 17:42:48 -08: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
Wouter 65f81105f5 libobs-d3d11: Allow multiple display captures of same monitor
This commit fixes a bug that occurs on Windows 8+ when two or more
"Display Capture" sources are active that are configured to capture the
same monitor.  Only one display capture would show, while all subsequent
display captures would display nothing.

Closes jp9000/obs-studio#1142
2018-01-09 19:49:54 -08:00
jp9000 ea6efc9514 libobs-d3d11: Only load vertex buffer before drawing
Fixes a bug where loading vertex shaders could cause error messages
about mismatching vertex buffer data to appear because the vertex shader
would try to reload the previously used vertex buffer.
2017-05-15 23:57:53 -07:00
jp9000 8cc5f8de55 libobs-d3d11: Don't crash if unable to rebuild shared texture
When rebuilding the graphics subsystem, it's possible a shared texture
may no longer be available.  In this case, just soft fail and allow the
texture to be rebuilt rather than crash the entire program over it.
2016-12-21 16:09:12 -08:00
jp9000 d2bb7157c2 libobs-d3d11: Add optional macro to log shader disassembly 2016-11-25 12:01:31 -08:00
jp9000 8e8834f109 libobs-d3d11: Rebuild device and assets if device removed/reset
Due to an NVIDIA driver bug with the Windows 10 Anniversary Update,
there are an increasingly large number of reports of "Device Removed"
errors and TDRs.  When this happens, OBS stops outputting all data
because all graphics functions are failing, and it appears to just
"freeze up" for users.

To temporarily alleviate this issue while waiting for it to be fixed,
the D3D subsystem can be rebuilt when that happens, all assets can be
reloaded to ensure that it can continue functioning (with a minor hiccup
in playback).

To allow rebuilding the entire D3D subsystem, all objects that contain
D3D references must be part of a linked list (with a few exceptions) so
we can quickly traverse them all whenever needed, and all data for those
resources (static resources primarily, such as shaders, textures, index
buffers, vertex buffers) must be stored in RAM so they can be recreated
whenever needed.

Then if D3D reports a "device removed" or "device reset" error, all D3D
references must first be fully released with no stray references; the
linked list must be fully traversed until all references are released.
Then, the linked list must once again be traversed again, and all those
D3D objects must be recreated with the same data and descriptors (which
are now saved in each object).  Finally, all states need to be reset.

After that's complete, the device is able to continue functioning almost
as it was before, although the output to recording/stream may get a few
green frames due to texture data being reset.

This will temporarily alleviate the "Device Removed" issue while waiting
for a fix from NVIDIA.
2016-11-03 09:23:24 -07:00
jp9000 5eb0c4ec83 libobs-d3d11: Add Release funtions to all GS objects
Releases references for each graphics object.
2016-11-03 09:23:23 -07:00
jp9000 54737c9c68 libobs-d3d11: Remove unused function 2016-11-03 09:23:22 -07:00