0
0
mirror of https://github.com/obsproject/obs-studio.git synced 2024-09-20 04:42:18 +02:00
Commit Graph

66 Commits

Author SHA1 Message Date
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
jp9000
951c6892b0 libobs-d3d11: Use linked list for all objects (for rebuilding) 2016-11-03 09:23:21 -07:00
jp9000
ecd5b4ee81 libobs-d3d11: Save all D3D11 object descriptors (for rebuilding) 2016-11-03 09:23:19 -07:00
jp9000
bab77c2afd libobs-d3d11: Store static vertex buffer data (for rebuilding)
Instead of letting vertex buffer data be freed immediately, store it so
it can be used for rebuilding later.  Also, separate the buffer building
to a function.
2016-11-03 09:23:18 -07:00
jp9000
61042e2bc4 libobs-d3d11: Store static textures in RAM (for rebuilding) 2016-11-03 09:23:17 -07:00
jp9000
e4900751c3 libobs-d3d11: Store device adapter index (for rebuilding) 2016-11-03 09:23:16 -07:00
jp9000
6d18ae39c5 libobs-d3d11: Store swap initialization data (for rebuilding) 2016-11-03 09:23:15 -07:00
jp9000
bc0faf9a3c libobs-d3d11: Clear device state before unloading
Unloads all device data and clears all device references.  Probably not
necessary, but it's unknown how D3D11 handles this internally so
probably best to be safe.
2016-11-03 09:23:14 -07:00
jp9000
a5ed61e02e libobs-d3d11: Store index and add "Start" function
This allows restarting the duplicator at a later point in time.
2016-11-03 09:23:13 -07:00
jp9000
7321cc38e8 libobs-d3d11: Store shader samplers as pointers
This allows having them be a part of a linked list later.
2016-11-03 09:23:10 -07:00
jp9000
1ecb1550af libobs-d3d11: Store compiled shader data (for rebuilding) 2016-11-03 09:23:08 -07:00
jp9000
29eea269fc libobs-d3d11: Store dxgi adapter used for device
Keeping a reference is useful, and additionally allows pruning a bit of
duplicated code in the dupicator object.
2016-11-03 09:23:07 -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
eb459e2adc libobs-d3d11: Remove windowless context #error 2015-08-05 01:07:16 -07:00
jp9000
2b62c33c16 libobs-d3d11: Use windowless context
(Non-compiling commit: windowless-context branch)
2015-08-05 01:07:15 -07:00
jp9000
844123164f libobs-d3d11: Add windowless context #error 2015-08-05 01:07:06 -07:00
jp9000
278fd03a66 libobs-d3d11: Use get_win_ver (not GetVersionEx) 2015-08-01 14:51:23 -07:00
jp9000
cedd894fe7 libobs-d3d11: Make sure current swap is valid 2015-07-30 17:16:24 -07:00
jp9000
be52fa26f9 Add gs_blend_function_separate
This allows the ability to separate the blend states of color and alpha.

The default blend state has also changed so that alpha is always added
together to ensure that the destination image always gets an alpha value
that is actually usable after the operation (for render targets).

Old default state:
  color source: GS_BLEND_SRCALPHA, color dest: GS_BLEND_INVSRCALPHA
  alpha source: GS_BLEND_SRCALPHA, alpha dest: GS_BLEND_INVSRCALPHA

New default state:
  color source: GS_BLEND_SRCALPHA, color dest: GS_BLEND_INVSRCALPHA
  alpha source: GS_BLEND_ONE,      alpha dest: GS_BLEND_ONE
2015-03-27 11:18:02 -07:00
jp9000
86563ea1cd libobs-d3d11: Fix vertical alignment
Someone's going to yell at me about this, but fix vertical alignment for
certain member variables in the main header.

For future reference, if you must use vertical alignment, always give it
plenty of space for the type names to grow in case you need to
add/change variables in the future; don't just align to the 'longest'
value, give it an extra 8-16 spaces for potential future variables.
This is done to prevent having to make commits like this in the future
that sort of pollute the history.
2015-02-09 03:56:12 -08:00
jp9000
3af33b26ac libobs-d3d11: Use integer type with switch
DXGI_FORMAT has too many values we don't need/use, so the value for this
switch should be an integer instead of an enum to prevent warnings.
2015-02-09 03:56:11 -08:00
jp9000
7650df5525 libobs-d3d11: Fill out switch enum values
When using an enumeration value with a switch, it needs to be filled out
with all possible values to prevent compiler warnings.  This warning is
used to prevent the developer from unintentionally forgetting to add new
enum values to any switches the enum is used on later on.  Sadly, only
good compilers actually have this warning (mingw).
2015-02-09 03:56:09 -08:00
jp9000
1b2c3a6176 libobs-d3d11: Fix initializer list ordering
Microsoft's compiler doesn't seem to care about warning about things
like initializer list ordering.  Mingw actually reports on this to
prevent potential confusion about ordering.
2015-02-09 03:56:09 -08:00
jp9000
f4406e71f4 libobs-d3d11: Use member initialization
Instead of using initializer lists, use member initialization to clean
up the default values for member variables
2015-02-09 03:56:08 -08:00
jp9000
44b8c24f34 libobs: Add output duplicator support
This adds support for the windows 8+ output duplicator feature which
allows the efficient capturing of a specific monitor connected to the
currently used device.
2015-01-03 02:37:13 -08:00
jp9000
a5447b5fd8 libobs-d3d11: Move DXGI -> GS format conversion
Move the DXGI -> GS format conversion function to d3d11-subsystem.hpp
instead of being exclusively in the d3d11-texture2d.cpp function.
2015-01-03 02:37:12 -08:00
jp9000
caa32cb6d1 Add support for shared textures to graphics API 2014-10-13 21:56:42 -07:00
jp9000
a1b46c0fa5 libobs-d3d11: Don't depend on specific D3DCompiler
I do not want the D3D11 library to depend on a specific compiler
version.  This way, I do not have to distribute D3D Compiler libraries
with the program (proprietary binary blobs).  Any particular version
works because the API for the D3DCompiler function appears to be the
same; the only things that change are other features and additions
mostly (at least as far as I can tell).  Using any version available on
the system should be more than sufficient rather than depending on some
specific D3D compiler version.

If the user doesn't have it, a download of the latest D3D distributables
should be fine, though it should work with the ones that come with
windows 7+ as well.
2014-10-03 14:33:56 -07:00