2013-09-30 19:37:13 -07:00
|
|
|
/******************************************************************************
|
|
|
|
Copyright (C) 2013 by Hugh Bailey <obs.jim@gmail.com>
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2013-12-02 22:24:38 -07:00
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
2013-09-30 19:37:13 -07:00
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2013-11-26 23:07:27 -07:00
|
|
|
#include <util/AlignedNew.hpp>
|
2015-08-01 14:43:26 -07:00
|
|
|
#include <util/windows/win-version.h>
|
2013-10-01 00:27:14 -07:00
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2016-11-03 06:51:16 -07:00
|
|
|
#include <memory>
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
#include <windows.h>
|
2022-01-06 01:13:57 -08:00
|
|
|
#include <dxgi1_6.h>
|
2018-10-05 03:15:13 -07:00
|
|
|
#include <d3d11_1.h>
|
2013-09-30 19:37:13 -07:00
|
|
|
#include <d3dcompiler.h>
|
|
|
|
|
2013-11-26 23:07:27 -07:00
|
|
|
#include <util/base.h>
|
|
|
|
#include <graphics/matrix4.h>
|
|
|
|
#include <graphics/graphics.h>
|
2014-03-29 17:19:31 -07:00
|
|
|
#include <graphics/device-exports.h>
|
2013-11-26 23:07:27 -07:00
|
|
|
#include <util/windows/ComPtr.hpp>
|
|
|
|
#include <util/windows/HRError.hpp>
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2016-11-25 12:01:31 -08:00
|
|
|
// #define DISASSEMBLE_SHADERS
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
struct shader_var;
|
|
|
|
struct shader_sampler;
|
|
|
|
struct gs_vertex_shader;
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Just to clarify, all structs, and all public. These are exporting only
|
|
|
|
* via encapsulated C bindings, not C++ bindings, so the whole concept of
|
|
|
|
* "public" and "private" does not matter at all for this subproject.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline uint32_t GetWinVer()
|
|
|
|
{
|
2015-08-01 14:43:26 -07:00
|
|
|
struct win_version_info ver;
|
|
|
|
get_win_ver(&ver);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2015-08-01 14:43:26 -07:00
|
|
|
return (ver.major << 8) | ver.minor;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
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-19 15:00:51 -08:00
|
|
|
static inline DXGI_FORMAT ConvertGSTextureFormatResource(gs_color_format format)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
2013-10-04 05:28:36 -07:00
|
|
|
switch (format) {
|
2015-02-09 01:05:01 -08:00
|
|
|
case GS_UNKNOWN:
|
|
|
|
return DXGI_FORMAT_UNKNOWN;
|
2013-09-30 19:37:13 -07:00
|
|
|
case GS_A8:
|
|
|
|
return DXGI_FORMAT_A8_UNORM;
|
|
|
|
case GS_R8:
|
|
|
|
return DXGI_FORMAT_R8_UNORM;
|
|
|
|
case GS_RGBA:
|
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-19 15:00:51 -08:00
|
|
|
return DXGI_FORMAT_R8G8B8A8_TYPELESS;
|
2013-09-30 19:37:13 -07:00
|
|
|
case GS_BGRX:
|
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-19 15:00:51 -08:00
|
|
|
return DXGI_FORMAT_B8G8R8X8_TYPELESS;
|
2013-09-30 19:37:13 -07:00
|
|
|
case GS_BGRA:
|
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-19 15:00:51 -08:00
|
|
|
return DXGI_FORMAT_B8G8R8A8_TYPELESS;
|
2013-09-30 19:37:13 -07:00
|
|
|
case GS_R10G10B10A2:
|
|
|
|
return DXGI_FORMAT_R10G10B10A2_UNORM;
|
|
|
|
case GS_RGBA16:
|
|
|
|
return DXGI_FORMAT_R16G16B16A16_UNORM;
|
|
|
|
case GS_R16:
|
|
|
|
return DXGI_FORMAT_R16_UNORM;
|
|
|
|
case GS_RGBA16F:
|
|
|
|
return DXGI_FORMAT_R16G16B16A16_FLOAT;
|
|
|
|
case GS_RGBA32F:
|
|
|
|
return DXGI_FORMAT_R32G32B32A32_FLOAT;
|
|
|
|
case GS_RG16F:
|
|
|
|
return DXGI_FORMAT_R16G16_FLOAT;
|
|
|
|
case GS_RG32F:
|
|
|
|
return DXGI_FORMAT_R32G32_FLOAT;
|
|
|
|
case GS_R16F:
|
|
|
|
return DXGI_FORMAT_R16_FLOAT;
|
|
|
|
case GS_R32F:
|
|
|
|
return DXGI_FORMAT_R32_FLOAT;
|
|
|
|
case GS_DXT1:
|
|
|
|
return DXGI_FORMAT_BC1_UNORM;
|
|
|
|
case GS_DXT3:
|
|
|
|
return DXGI_FORMAT_BC2_UNORM;
|
|
|
|
case GS_DXT5:
|
|
|
|
return DXGI_FORMAT_BC3_UNORM;
|
2018-10-05 03:15:13 -07:00
|
|
|
case GS_R8G8:
|
|
|
|
return DXGI_FORMAT_R8G8_UNORM;
|
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-19 15:00:51 -08:00
|
|
|
case GS_RGBA_UNORM:
|
|
|
|
return DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
|
case GS_BGRX_UNORM:
|
|
|
|
return DXGI_FORMAT_B8G8R8X8_UNORM;
|
|
|
|
case GS_BGRA_UNORM:
|
|
|
|
return DXGI_FORMAT_B8G8R8A8_UNORM;
|
2022-01-25 02:50:30 -08:00
|
|
|
case GS_RG16:
|
|
|
|
return DXGI_FORMAT_R16G16_UNORM;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
2013-10-24 01:29:06 -07:00
|
|
|
|
|
|
|
return DXGI_FORMAT_UNKNOWN;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
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-19 15:00:51 -08:00
|
|
|
static inline DXGI_FORMAT ConvertGSTextureFormatView(gs_color_format format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case GS_RGBA:
|
|
|
|
return DXGI_FORMAT_R8G8B8A8_UNORM;
|
|
|
|
case GS_BGRX:
|
|
|
|
return DXGI_FORMAT_B8G8R8X8_UNORM;
|
|
|
|
case GS_BGRA:
|
|
|
|
return DXGI_FORMAT_B8G8R8A8_UNORM;
|
|
|
|
default:
|
|
|
|
return ConvertGSTextureFormatResource(format);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline DXGI_FORMAT
|
|
|
|
ConvertGSTextureFormatViewLinear(gs_color_format format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case GS_RGBA:
|
|
|
|
return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
|
|
|
|
case GS_BGRX:
|
|
|
|
return DXGI_FORMAT_B8G8R8X8_UNORM_SRGB;
|
|
|
|
case GS_BGRA:
|
|
|
|
return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
|
|
|
|
default:
|
|
|
|
return ConvertGSTextureFormatResource(format);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-29 00:27:03 -08:00
|
|
|
static inline gs_color_format ConvertDXGITextureFormat(DXGI_FORMAT format)
|
|
|
|
{
|
2015-02-09 01:09:38 -08:00
|
|
|
switch ((unsigned long)format) {
|
2014-12-29 00:27:03 -08:00
|
|
|
case DXGI_FORMAT_A8_UNORM:
|
|
|
|
return GS_A8;
|
|
|
|
case DXGI_FORMAT_R8_UNORM:
|
|
|
|
return GS_R8;
|
2018-10-05 03:15:13 -07:00
|
|
|
case DXGI_FORMAT_R8G8_UNORM:
|
|
|
|
return GS_R8G8;
|
2020-12-17 04:01:08 -08:00
|
|
|
case DXGI_FORMAT_R8G8B8A8_TYPELESS:
|
2014-12-29 00:27:03 -08:00
|
|
|
return GS_RGBA;
|
2020-12-17 04:01:08 -08:00
|
|
|
case DXGI_FORMAT_B8G8R8X8_TYPELESS:
|
2014-12-29 00:27:03 -08:00
|
|
|
return GS_BGRX;
|
2020-12-17 04:01:08 -08:00
|
|
|
case DXGI_FORMAT_B8G8R8A8_TYPELESS:
|
2014-12-29 00:27:03 -08:00
|
|
|
return GS_BGRA;
|
|
|
|
case DXGI_FORMAT_R10G10B10A2_UNORM:
|
|
|
|
return GS_R10G10B10A2;
|
|
|
|
case DXGI_FORMAT_R16G16B16A16_UNORM:
|
|
|
|
return GS_RGBA16;
|
|
|
|
case DXGI_FORMAT_R16_UNORM:
|
|
|
|
return GS_R16;
|
|
|
|
case DXGI_FORMAT_R16G16B16A16_FLOAT:
|
|
|
|
return GS_RGBA16F;
|
|
|
|
case DXGI_FORMAT_R32G32B32A32_FLOAT:
|
|
|
|
return GS_RGBA32F;
|
|
|
|
case DXGI_FORMAT_R16G16_FLOAT:
|
|
|
|
return GS_RG16F;
|
|
|
|
case DXGI_FORMAT_R32G32_FLOAT:
|
|
|
|
return GS_RG32F;
|
|
|
|
case DXGI_FORMAT_R16_FLOAT:
|
|
|
|
return GS_R16F;
|
|
|
|
case DXGI_FORMAT_R32_FLOAT:
|
|
|
|
return GS_R32F;
|
|
|
|
case DXGI_FORMAT_BC1_UNORM:
|
|
|
|
return GS_DXT1;
|
|
|
|
case DXGI_FORMAT_BC2_UNORM:
|
|
|
|
return GS_DXT3;
|
|
|
|
case DXGI_FORMAT_BC3_UNORM:
|
|
|
|
return GS_DXT5;
|
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-19 15:00:51 -08:00
|
|
|
case DXGI_FORMAT_R8G8B8A8_UNORM:
|
|
|
|
return GS_RGBA_UNORM;
|
|
|
|
case DXGI_FORMAT_B8G8R8X8_UNORM:
|
|
|
|
return GS_BGRX_UNORM;
|
|
|
|
case DXGI_FORMAT_B8G8R8A8_UNORM:
|
|
|
|
return GS_BGRA_UNORM;
|
2022-01-25 02:50:30 -08:00
|
|
|
case DXGI_FORMAT_R16G16_UNORM:
|
|
|
|
return GS_RG16;
|
2014-12-29 00:27:03 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return GS_UNKNOWN;
|
|
|
|
}
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
static inline DXGI_FORMAT ConvertGSZStencilFormat(gs_zstencil_format format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
2015-02-09 01:05:01 -08:00
|
|
|
case GS_ZS_NONE:
|
|
|
|
return DXGI_FORMAT_UNKNOWN;
|
2013-09-30 19:37:13 -07:00
|
|
|
case GS_Z16:
|
|
|
|
return DXGI_FORMAT_D16_UNORM;
|
|
|
|
case GS_Z24_S8:
|
|
|
|
return DXGI_FORMAT_D24_UNORM_S8_UINT;
|
|
|
|
case GS_Z32F:
|
|
|
|
return DXGI_FORMAT_D32_FLOAT;
|
|
|
|
case GS_Z32F_S8X24:
|
|
|
|
return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
|
|
|
|
}
|
2013-10-24 01:29:06 -07:00
|
|
|
|
|
|
|
return DXGI_FORMAT_UNKNOWN;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline D3D11_COMPARISON_FUNC ConvertGSDepthTest(gs_depth_test test)
|
|
|
|
{
|
|
|
|
switch (test) {
|
|
|
|
case GS_NEVER:
|
|
|
|
return D3D11_COMPARISON_NEVER;
|
|
|
|
case GS_LESS:
|
|
|
|
return D3D11_COMPARISON_LESS;
|
|
|
|
case GS_LEQUAL:
|
|
|
|
return D3D11_COMPARISON_LESS_EQUAL;
|
|
|
|
case GS_EQUAL:
|
|
|
|
return D3D11_COMPARISON_EQUAL;
|
|
|
|
case GS_GEQUAL:
|
|
|
|
return D3D11_COMPARISON_GREATER_EQUAL;
|
|
|
|
case GS_GREATER:
|
|
|
|
return D3D11_COMPARISON_GREATER;
|
|
|
|
case GS_NOTEQUAL:
|
|
|
|
return D3D11_COMPARISON_NOT_EQUAL;
|
|
|
|
case GS_ALWAYS:
|
|
|
|
return D3D11_COMPARISON_ALWAYS;
|
|
|
|
}
|
2013-10-24 01:29:06 -07:00
|
|
|
|
|
|
|
return D3D11_COMPARISON_NEVER;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
static inline D3D11_STENCIL_OP ConvertGSStencilOp(gs_stencil_op_type op)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
switch (op) {
|
|
|
|
case GS_KEEP:
|
|
|
|
return D3D11_STENCIL_OP_KEEP;
|
|
|
|
case GS_ZERO:
|
|
|
|
return D3D11_STENCIL_OP_ZERO;
|
|
|
|
case GS_REPLACE:
|
|
|
|
return D3D11_STENCIL_OP_REPLACE;
|
|
|
|
case GS_INCR:
|
|
|
|
return D3D11_STENCIL_OP_INCR;
|
|
|
|
case GS_DECR:
|
|
|
|
return D3D11_STENCIL_OP_DECR;
|
|
|
|
case GS_INVERT:
|
|
|
|
return D3D11_STENCIL_OP_INVERT;
|
|
|
|
}
|
2013-10-24 01:29:06 -07:00
|
|
|
|
|
|
|
return D3D11_STENCIL_OP_KEEP;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline D3D11_BLEND ConvertGSBlendType(gs_blend_type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case GS_BLEND_ZERO:
|
|
|
|
return D3D11_BLEND_ZERO;
|
|
|
|
case GS_BLEND_ONE:
|
|
|
|
return D3D11_BLEND_ONE;
|
|
|
|
case GS_BLEND_SRCCOLOR:
|
|
|
|
return D3D11_BLEND_SRC_COLOR;
|
|
|
|
case GS_BLEND_INVSRCCOLOR:
|
|
|
|
return D3D11_BLEND_INV_SRC_COLOR;
|
|
|
|
case GS_BLEND_SRCALPHA:
|
|
|
|
return D3D11_BLEND_SRC_ALPHA;
|
|
|
|
case GS_BLEND_INVSRCALPHA:
|
|
|
|
return D3D11_BLEND_INV_SRC_ALPHA;
|
|
|
|
case GS_BLEND_DSTCOLOR:
|
|
|
|
return D3D11_BLEND_DEST_COLOR;
|
|
|
|
case GS_BLEND_INVDSTCOLOR:
|
|
|
|
return D3D11_BLEND_INV_DEST_COLOR;
|
|
|
|
case GS_BLEND_DSTALPHA:
|
|
|
|
return D3D11_BLEND_DEST_ALPHA;
|
|
|
|
case GS_BLEND_INVDSTALPHA:
|
|
|
|
return D3D11_BLEND_INV_DEST_ALPHA;
|
|
|
|
case GS_BLEND_SRCALPHASAT:
|
|
|
|
return D3D11_BLEND_SRC_ALPHA_SAT;
|
|
|
|
}
|
2013-10-24 01:29:06 -07:00
|
|
|
|
|
|
|
return D3D11_BLEND_ONE;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
2021-10-24 16:18:58 +01:00
|
|
|
static inline D3D11_BLEND_OP ConvertGSBlendOpType(gs_blend_op_type type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case GS_BLEND_OP_ADD:
|
|
|
|
return D3D11_BLEND_OP_ADD;
|
|
|
|
case GS_BLEND_OP_SUBTRACT:
|
|
|
|
return D3D11_BLEND_OP_SUBTRACT;
|
|
|
|
case GS_BLEND_OP_REVERSE_SUBTRACT:
|
|
|
|
return D3D11_BLEND_OP_REV_SUBTRACT;
|
|
|
|
case GS_BLEND_OP_MIN:
|
|
|
|
return D3D11_BLEND_OP_MIN;
|
|
|
|
case GS_BLEND_OP_MAX:
|
|
|
|
return D3D11_BLEND_OP_MAX;
|
|
|
|
}
|
|
|
|
|
|
|
|
return D3D11_BLEND_OP_ADD;
|
|
|
|
}
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
static inline D3D11_CULL_MODE ConvertGSCullMode(gs_cull_mode mode)
|
|
|
|
{
|
|
|
|
switch (mode) {
|
|
|
|
case GS_BACK:
|
|
|
|
return D3D11_CULL_BACK;
|
|
|
|
case GS_FRONT:
|
|
|
|
return D3D11_CULL_FRONT;
|
|
|
|
case GS_NEITHER:
|
|
|
|
return D3D11_CULL_NONE;
|
|
|
|
}
|
2013-10-24 01:29:06 -07:00
|
|
|
|
|
|
|
return D3D11_CULL_BACK;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline D3D11_PRIMITIVE_TOPOLOGY ConvertGSTopology(gs_draw_mode mode)
|
|
|
|
{
|
|
|
|
switch (mode) {
|
|
|
|
case GS_POINTS:
|
|
|
|
return D3D11_PRIMITIVE_TOPOLOGY_POINTLIST;
|
|
|
|
case GS_LINES:
|
|
|
|
return D3D11_PRIMITIVE_TOPOLOGY_LINELIST;
|
|
|
|
case GS_LINESTRIP:
|
|
|
|
return D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP;
|
|
|
|
case GS_TRIS:
|
|
|
|
return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
|
|
|
|
case GS_TRISTRIP:
|
|
|
|
return D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
|
|
|
|
}
|
2013-10-24 01:29:06 -07:00
|
|
|
|
|
|
|
return D3D11_PRIMITIVE_TOPOLOGY_POINTLIST;
|
2013-09-30 19:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* exception-safe RAII wrapper for vertex buffer data (NOTE: not copy-safe) */
|
|
|
|
struct VBDataPtr {
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_vb_data *data;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
inline VBDataPtr(gs_vb_data *data) : data(data) {}
|
|
|
|
inline ~VBDataPtr() { gs_vbdata_destroy(data); }
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
|
|
|
|
2016-11-03 07:37:05 -07:00
|
|
|
enum class gs_type {
|
|
|
|
gs_vertex_buffer,
|
|
|
|
gs_index_buffer,
|
|
|
|
gs_texture_2d,
|
|
|
|
gs_zstencil_buffer,
|
|
|
|
gs_stage_surface,
|
|
|
|
gs_sampler_state,
|
|
|
|
gs_vertex_shader,
|
|
|
|
gs_pixel_shader,
|
|
|
|
gs_duplicator,
|
|
|
|
gs_swap_chain,
|
2019-07-27 13:31:07 -07:00
|
|
|
gs_timer,
|
|
|
|
gs_timer_range,
|
2019-12-15 11:36:24 -08:00
|
|
|
gs_texture_3d,
|
2016-11-03 07:37:05 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct gs_obj {
|
|
|
|
gs_device_t *device;
|
|
|
|
gs_type obj_type;
|
|
|
|
gs_obj *next;
|
|
|
|
gs_obj **prev_next;
|
|
|
|
|
|
|
|
inline gs_obj() : device(nullptr), next(nullptr), prev_next(nullptr) {}
|
|
|
|
|
|
|
|
gs_obj(gs_device_t *device, gs_type type);
|
|
|
|
virtual ~gs_obj();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gs_vertex_buffer : gs_obj {
|
2013-09-30 19:37:13 -07:00
|
|
|
ComPtr<ID3D11Buffer> vertexBuffer;
|
|
|
|
ComPtr<ID3D11Buffer> normalBuffer;
|
|
|
|
ComPtr<ID3D11Buffer> colorBuffer;
|
|
|
|
ComPtr<ID3D11Buffer> tangentBuffer;
|
|
|
|
vector<ComPtr<ID3D11Buffer>> uvBuffers;
|
|
|
|
|
|
|
|
bool dynamic;
|
|
|
|
VBDataPtr vbd;
|
|
|
|
size_t numVerts;
|
|
|
|
vector<size_t> uvSizes;
|
|
|
|
|
|
|
|
void FlushBuffer(ID3D11Buffer *buffer, void *array, size_t elementSize);
|
|
|
|
|
2021-08-11 21:42:58 -07:00
|
|
|
UINT MakeBufferList(gs_vertex_shader *shader, ID3D11Buffer **buffers,
|
|
|
|
uint32_t *strides);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2016-11-03 07:23:19 -07:00
|
|
|
void InitBuffer(const size_t elementSize, const size_t numVerts,
|
2013-09-30 19:37:13 -07:00
|
|
|
void *array, ID3D11Buffer **buffer);
|
|
|
|
|
2016-11-03 07:23:19 -07:00
|
|
|
void BuildBuffers();
|
|
|
|
|
2016-11-03 07:40:15 -07:00
|
|
|
inline void Release()
|
|
|
|
{
|
|
|
|
vertexBuffer.Release();
|
|
|
|
normalBuffer.Release();
|
|
|
|
colorBuffer.Release();
|
|
|
|
tangentBuffer.Release();
|
|
|
|
uvBuffers.clear();
|
|
|
|
}
|
|
|
|
|
2019-02-17 17:22:04 -08:00
|
|
|
void Rebuild();
|
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 07:41:23 -07:00
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_vertex_buffer(gs_device_t *device, struct gs_vb_data *data,
|
2014-08-07 23:42:07 -07:00
|
|
|
uint32_t flags);
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* exception-safe RAII wrapper for index buffer data (NOTE: not copy-safe) */
|
|
|
|
struct DataPtr {
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
inline DataPtr(void *data) : data(data) {}
|
|
|
|
inline ~DataPtr() { bfree(data); }
|
|
|
|
};
|
|
|
|
|
2016-11-03 07:37:05 -07:00
|
|
|
struct gs_index_buffer : gs_obj {
|
2013-09-30 19:37:13 -07:00
|
|
|
ComPtr<ID3D11Buffer> indexBuffer;
|
|
|
|
bool dynamic;
|
|
|
|
gs_index_type type;
|
|
|
|
size_t indexSize;
|
|
|
|
size_t num;
|
|
|
|
DataPtr indices;
|
|
|
|
|
2016-11-03 07:30:22 -07:00
|
|
|
D3D11_BUFFER_DESC bd = {};
|
|
|
|
D3D11_SUBRESOURCE_DATA srd = {};
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
void InitBuffer();
|
|
|
|
|
2019-02-17 17:22:04 -08:00
|
|
|
void Rebuild(ID3D11Device *dev);
|
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 07:41:23 -07:00
|
|
|
|
2016-11-03 07:40:15 -07:00
|
|
|
inline void Release() { indexBuffer.Release(); }
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_index_buffer(gs_device_t *device, enum gs_index_type type,
|
2013-09-30 19:37:13 -07:00
|
|
|
void *indices, size_t num, uint32_t flags);
|
|
|
|
};
|
|
|
|
|
2019-07-27 13:31:07 -07:00
|
|
|
struct gs_timer : gs_obj {
|
|
|
|
ComPtr<ID3D11Query> query_begin;
|
|
|
|
ComPtr<ID3D11Query> query_end;
|
|
|
|
|
|
|
|
void Rebuild(ID3D11Device *dev);
|
|
|
|
|
|
|
|
inline void Release()
|
|
|
|
{
|
|
|
|
query_begin.Release();
|
|
|
|
query_end.Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
gs_timer(gs_device_t *device);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gs_timer_range : gs_obj {
|
|
|
|
ComPtr<ID3D11Query> query_disjoint;
|
|
|
|
|
|
|
|
void Rebuild(ID3D11Device *dev);
|
|
|
|
|
|
|
|
inline void Release() { query_disjoint.Release(); }
|
|
|
|
|
|
|
|
gs_timer_range(gs_device_t *device);
|
|
|
|
};
|
|
|
|
|
2016-11-03 07:37:05 -07:00
|
|
|
struct gs_texture : gs_obj {
|
2013-09-30 19:37:13 -07:00
|
|
|
gs_texture_type type;
|
2013-10-04 08:55:33 -07:00
|
|
|
uint32_t levels;
|
2013-10-16 23:31:18 -07:00
|
|
|
gs_color_format format;
|
2013-10-04 08:55:33 -07:00
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
ComPtr<ID3D11ShaderResourceView> shaderRes;
|
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-19 15:00:51 -08:00
|
|
|
ComPtr<ID3D11ShaderResourceView> shaderResLinear;
|
|
|
|
D3D11_SHADER_RESOURCE_VIEW_DESC viewDesc{};
|
|
|
|
D3D11_SHADER_RESOURCE_VIEW_DESC viewDescLinear{};
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2019-02-17 17:22:04 -08:00
|
|
|
void Rebuild(ID3D11Device *dev);
|
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 07:41:23 -07:00
|
|
|
|
2016-11-03 07:37:05 -07:00
|
|
|
inline gs_texture(gs_texture_type type, uint32_t levels,
|
|
|
|
gs_color_format format)
|
2013-10-16 23:31:18 -07:00
|
|
|
: type(type), levels(levels), format(format)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-11-03 07:37:05 -07:00
|
|
|
inline gs_texture(gs_device *device, gs_type obj_type,
|
|
|
|
gs_texture_type type)
|
|
|
|
: gs_obj(device, obj_type), type(type)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline gs_texture(gs_device *device, gs_type obj_type,
|
|
|
|
gs_texture_type type, uint32_t levels,
|
|
|
|
gs_color_format format)
|
|
|
|
: gs_obj(device, obj_type),
|
|
|
|
type(type),
|
|
|
|
levels(levels),
|
|
|
|
format(format)
|
|
|
|
{
|
|
|
|
}
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct gs_texture_2d : gs_texture {
|
|
|
|
ComPtr<ID3D11Texture2D> texture;
|
|
|
|
ComPtr<ID3D11RenderTargetView> renderTarget[6];
|
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-19 15:00:51 -08:00
|
|
|
ComPtr<ID3D11RenderTargetView> renderTargetLinear[6];
|
2013-09-30 19:37:13 -07:00
|
|
|
ComPtr<IDXGISurface1> gdiSurface;
|
2019-06-22 22:13:45 -07:00
|
|
|
|
2015-02-09 01:02:12 -08:00
|
|
|
uint32_t width = 0, height = 0;
|
2018-10-05 02:38:11 -07:00
|
|
|
uint32_t flags = 0;
|
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-19 15:00:51 -08:00
|
|
|
DXGI_FORMAT dxgiFormatResource = DXGI_FORMAT_UNKNOWN;
|
|
|
|
DXGI_FORMAT dxgiFormatView = DXGI_FORMAT_UNKNOWN;
|
|
|
|
DXGI_FORMAT dxgiFormatViewLinear = DXGI_FORMAT_UNKNOWN;
|
2015-02-09 01:02:12 -08:00
|
|
|
bool isRenderTarget = false;
|
|
|
|
bool isGDICompatible = false;
|
|
|
|
bool isDynamic = false;
|
|
|
|
bool isShared = false;
|
|
|
|
bool genMipmaps = false;
|
2018-10-05 02:38:11 -07:00
|
|
|
uint32_t sharedHandle = GS_INVALID_HANDLE;
|
2019-06-22 22:13:45 -07:00
|
|
|
|
2022-03-02 23:15:02 -08:00
|
|
|
gs_texture_2d *pairedTexture = nullptr;
|
|
|
|
bool twoPlane = false;
|
2018-10-05 03:15:13 -07:00
|
|
|
bool chroma = false;
|
2019-03-03 08:39:18 -08:00
|
|
|
bool acquired = false;
|
2018-10-05 03:15:13 -07:00
|
|
|
|
2016-11-03 07:14:33 -07:00
|
|
|
vector<vector<uint8_t>> data;
|
2016-11-03 07:30:22 -07:00
|
|
|
vector<D3D11_SUBRESOURCE_DATA> srd;
|
|
|
|
D3D11_TEXTURE2D_DESC td = {};
|
2016-11-03 07:14:33 -07:00
|
|
|
|
|
|
|
void InitSRD(vector<D3D11_SUBRESOURCE_DATA> &srd);
|
2019-12-15 11:36:24 -08:00
|
|
|
void InitTexture(const uint8_t *const *data);
|
2013-09-30 19:37:13 -07:00
|
|
|
void InitResourceView();
|
|
|
|
void InitRenderTargets();
|
2019-12-15 11:36:24 -08:00
|
|
|
void BackupTexture(const uint8_t *const *data);
|
2019-03-03 08:41:23 -08:00
|
|
|
void GetSharedHandle(IDXGIResource *dxgi_res);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2016-12-21 15:53:14 -08:00
|
|
|
void RebuildSharedTextureFallback();
|
2019-02-17 17:22:04 -08:00
|
|
|
void Rebuild(ID3D11Device *dev);
|
2022-03-02 23:15:02 -08:00
|
|
|
void RebuildPaired_Y(ID3D11Device *dev);
|
|
|
|
void RebuildPaired_UV(ID3D11Device *dev);
|
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 07:41:23 -07:00
|
|
|
|
2016-11-03 07:40:15 -07:00
|
|
|
inline void Release()
|
|
|
|
{
|
|
|
|
texture.Release();
|
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-19 15:00:51 -08:00
|
|
|
for (ComPtr<ID3D11RenderTargetView> &rt : renderTarget)
|
|
|
|
rt.Release();
|
|
|
|
for (ComPtr<ID3D11RenderTargetView> &rt : renderTargetLinear)
|
2016-11-03 07:40:15 -07:00
|
|
|
rt.Release();
|
|
|
|
gdiSurface.Release();
|
|
|
|
shaderRes.Release();
|
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-19 15:00:51 -08:00
|
|
|
shaderResLinear.Release();
|
2016-11-03 07:40:15 -07:00
|
|
|
}
|
|
|
|
|
2016-11-03 07:37:05 -07:00
|
|
|
inline gs_texture_2d() : gs_texture(GS_TEXTURE_2D, 0, GS_UNKNOWN) {}
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_texture_2d(gs_device_t *device, uint32_t width, uint32_t height,
|
2013-10-04 08:55:33 -07:00
|
|
|
gs_color_format colorFormat, uint32_t levels,
|
2019-12-15 11:36:24 -08:00
|
|
|
const uint8_t *const *data, uint32_t flags,
|
2018-10-05 03:15:13 -07:00
|
|
|
gs_texture_type type, bool gdiCompatible,
|
2022-03-02 23:15:02 -08:00
|
|
|
bool twoPlane = false);
|
2014-10-13 21:41:09 -07:00
|
|
|
|
2018-10-05 03:15:13 -07:00
|
|
|
gs_texture_2d(gs_device_t *device, ID3D11Texture2D *nv12,
|
|
|
|
uint32_t flags);
|
2021-11-12 12:13:41 +13:00
|
|
|
gs_texture_2d(gs_device_t *device, uint32_t handle,
|
|
|
|
bool ntHandle = false);
|
2020-11-22 23:39:59 -08:00
|
|
|
gs_texture_2d(gs_device_t *device, ID3D11Texture2D *obj);
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
|
|
|
|
2019-12-15 11:36:24 -08:00
|
|
|
struct gs_texture_3d : gs_texture {
|
|
|
|
ComPtr<ID3D11Texture3D> texture;
|
|
|
|
|
|
|
|
uint32_t width = 0, height = 0, depth = 0;
|
|
|
|
uint32_t flags = 0;
|
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-19 15:00:51 -08:00
|
|
|
DXGI_FORMAT dxgiFormatResource = DXGI_FORMAT_UNKNOWN;
|
|
|
|
DXGI_FORMAT dxgiFormatView = DXGI_FORMAT_UNKNOWN;
|
|
|
|
DXGI_FORMAT dxgiFormatViewLinear = DXGI_FORMAT_UNKNOWN;
|
2019-12-15 11:36:24 -08:00
|
|
|
bool isDynamic = false;
|
|
|
|
bool isShared = false;
|
|
|
|
bool genMipmaps = false;
|
|
|
|
uint32_t sharedHandle = GS_INVALID_HANDLE;
|
|
|
|
|
|
|
|
bool chroma = false;
|
|
|
|
bool acquired = false;
|
|
|
|
|
|
|
|
vector<vector<uint8_t>> data;
|
|
|
|
vector<D3D11_SUBRESOURCE_DATA> srd;
|
|
|
|
D3D11_TEXTURE3D_DESC td = {};
|
|
|
|
|
|
|
|
void InitSRD(vector<D3D11_SUBRESOURCE_DATA> &srd);
|
|
|
|
void InitTexture(const uint8_t *const *data);
|
|
|
|
void InitResourceView();
|
|
|
|
void BackupTexture(const uint8_t *const *data);
|
|
|
|
void GetSharedHandle(IDXGIResource *dxgi_res);
|
|
|
|
|
|
|
|
void RebuildSharedTextureFallback();
|
|
|
|
void Rebuild(ID3D11Device *dev);
|
|
|
|
void RebuildNV12_Y(ID3D11Device *dev);
|
|
|
|
void RebuildNV12_UV(ID3D11Device *dev);
|
|
|
|
|
|
|
|
inline void Release()
|
|
|
|
{
|
|
|
|
texture.Release();
|
|
|
|
shaderRes.Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline gs_texture_3d() : gs_texture(GS_TEXTURE_3D, 0, GS_UNKNOWN) {}
|
|
|
|
|
|
|
|
gs_texture_3d(gs_device_t *device, uint32_t width, uint32_t height,
|
|
|
|
uint32_t depth, gs_color_format colorFormat,
|
|
|
|
uint32_t levels, const uint8_t *const *data,
|
|
|
|
uint32_t flags);
|
|
|
|
|
|
|
|
gs_texture_3d(gs_device_t *device, uint32_t handle);
|
|
|
|
};
|
|
|
|
|
2016-11-03 07:37:05 -07:00
|
|
|
struct gs_zstencil_buffer : gs_obj {
|
2013-09-30 19:37:13 -07:00
|
|
|
ComPtr<ID3D11Texture2D> texture;
|
|
|
|
ComPtr<ID3D11DepthStencilView> view;
|
|
|
|
|
|
|
|
uint32_t width, height;
|
|
|
|
gs_zstencil_format format;
|
|
|
|
DXGI_FORMAT dxgiFormat;
|
|
|
|
|
2016-11-03 07:30:22 -07:00
|
|
|
D3D11_TEXTURE2D_DESC td = {};
|
|
|
|
D3D11_DEPTH_STENCIL_VIEW_DESC dsvd = {};
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
void InitBuffer();
|
|
|
|
|
2019-02-17 17:22:04 -08:00
|
|
|
void Rebuild(ID3D11Device *dev);
|
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 07:41:23 -07:00
|
|
|
|
2016-11-03 07:40:15 -07:00
|
|
|
inline void Release()
|
|
|
|
{
|
|
|
|
texture.Release();
|
|
|
|
view.Release();
|
|
|
|
}
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
inline gs_zstencil_buffer()
|
|
|
|
: width(0), height(0), dxgiFormat(DXGI_FORMAT_UNKNOWN)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_zstencil_buffer(gs_device_t *device, uint32_t width, uint32_t height,
|
2013-09-30 19:37:13 -07:00
|
|
|
gs_zstencil_format format);
|
|
|
|
};
|
|
|
|
|
2016-11-03 07:37:05 -07:00
|
|
|
struct gs_stage_surface : gs_obj {
|
2013-09-30 19:37:13 -07:00
|
|
|
ComPtr<ID3D11Texture2D> texture;
|
2016-11-03 07:30:22 -07:00
|
|
|
D3D11_TEXTURE2D_DESC td = {};
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
uint32_t width, height;
|
|
|
|
gs_color_format format;
|
|
|
|
DXGI_FORMAT dxgiFormat;
|
|
|
|
|
2019-02-17 17:22:04 -08:00
|
|
|
void Rebuild(ID3D11Device *dev);
|
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 07:41:23 -07:00
|
|
|
|
2016-11-03 07:40:15 -07:00
|
|
|
inline void Release() { texture.Release(); }
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_stage_surface(gs_device_t *device, uint32_t width, uint32_t height,
|
2013-09-30 19:37:13 -07:00
|
|
|
gs_color_format colorFormat);
|
2022-03-02 23:15:02 -08:00
|
|
|
gs_stage_surface(gs_device_t *device, uint32_t width, uint32_t height,
|
|
|
|
bool p010);
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
|
|
|
|
2016-11-03 07:37:05 -07:00
|
|
|
struct gs_sampler_state : gs_obj {
|
2013-09-30 19:37:13 -07:00
|
|
|
ComPtr<ID3D11SamplerState> state;
|
2016-11-03 07:30:22 -07:00
|
|
|
D3D11_SAMPLER_DESC sd = {};
|
2013-09-30 19:37:13 -07:00
|
|
|
gs_sampler_info info;
|
|
|
|
|
2019-02-17 17:22:04 -08:00
|
|
|
void Rebuild(ID3D11Device *dev);
|
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 07:41:23 -07:00
|
|
|
|
2016-11-03 07:40:15 -07:00
|
|
|
inline void Release() { state.Release(); }
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
gs_sampler_state(gs_device_t *device, const gs_sampler_info *info);
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
struct gs_shader_param {
|
2015-02-09 01:13:43 -08:00
|
|
|
string name;
|
|
|
|
gs_shader_param_type type;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2015-02-09 01:13:43 -08:00
|
|
|
uint32_t textureID;
|
2016-06-29 04:15:38 -07:00
|
|
|
struct gs_sampler_state *nextSampler = nullptr;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2015-02-09 01:13:43 -08:00
|
|
|
int arrayCount;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2015-02-09 01:13:43 -08:00
|
|
|
size_t pos;
|
2014-05-02 21:38:05 -07:00
|
|
|
|
2015-02-09 01:13:43 -08:00
|
|
|
vector<uint8_t> curValue;
|
|
|
|
vector<uint8_t> defaultValue;
|
|
|
|
bool changed;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_shader_param(shader_var &var, uint32_t &texCounter);
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ShaderError {
|
|
|
|
ComPtr<ID3D10Blob> errors;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
inline ShaderError(const ComPtr<ID3D10Blob> &errors, HRESULT hr)
|
|
|
|
: errors(errors), hr(hr)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-11-03 07:37:05 -07:00
|
|
|
struct gs_shader : gs_obj {
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_shader_type type;
|
|
|
|
vector<gs_shader_param> params;
|
2015-02-09 01:13:43 -08:00
|
|
|
ComPtr<ID3D11Buffer> constants;
|
|
|
|
size_t constantSize;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2016-11-03 07:30:22 -07:00
|
|
|
D3D11_BUFFER_DESC bd = {};
|
2016-11-03 06:45:08 -07:00
|
|
|
vector<uint8_t> data;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
inline void UpdateParam(vector<uint8_t> &constData,
|
|
|
|
gs_shader_param ¶m, bool &upload);
|
2013-09-30 19:37:13 -07:00
|
|
|
void UploadParams();
|
|
|
|
|
|
|
|
void BuildConstantBuffer();
|
|
|
|
void Compile(const char *shaderStr, const char *file,
|
|
|
|
const char *target, ID3D10Blob **shader);
|
|
|
|
|
2016-11-03 07:37:05 -07:00
|
|
|
inline gs_shader(gs_device_t *device, gs_type obj_type,
|
|
|
|
gs_shader_type type)
|
|
|
|
: gs_obj(device, obj_type), type(type), constantSize(0)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~gs_shader() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ShaderSampler {
|
|
|
|
string name;
|
|
|
|
gs_sampler_state sampler;
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
inline ShaderSampler(const char *name, gs_device_t *device,
|
2013-09-30 19:37:13 -07:00
|
|
|
gs_sampler_info *info)
|
|
|
|
: name(name), sampler(device, info)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gs_vertex_shader : gs_shader {
|
|
|
|
ComPtr<ID3D11VertexShader> shader;
|
|
|
|
ComPtr<ID3D11InputLayout> layout;
|
|
|
|
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_shader_param *world, *viewProj;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2016-11-03 06:45:08 -07:00
|
|
|
vector<D3D11_INPUT_ELEMENT_DESC> layoutData;
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
bool hasNormals;
|
|
|
|
bool hasColors;
|
|
|
|
bool hasTangents;
|
|
|
|
uint32_t nTexUnits;
|
|
|
|
|
2019-02-17 17:22:04 -08:00
|
|
|
void Rebuild(ID3D11Device *dev);
|
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 07:41:23 -07:00
|
|
|
|
2016-11-03 07:40:15 -07:00
|
|
|
inline void Release()
|
|
|
|
{
|
|
|
|
shader.Release();
|
|
|
|
layout.Release();
|
|
|
|
constants.Release();
|
|
|
|
}
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
inline uint32_t NumBuffersExpected() const
|
|
|
|
{
|
|
|
|
uint32_t count = nTexUnits + 1;
|
|
|
|
if (hasNormals)
|
|
|
|
count++;
|
|
|
|
if (hasColors)
|
|
|
|
count++;
|
|
|
|
if (hasTangents)
|
|
|
|
count++;
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GetBuffersExpected(const vector<D3D11_INPUT_ELEMENT_DESC> &inputs);
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_vertex_shader(gs_device_t *device, const char *file,
|
2013-09-30 19:37:13 -07:00
|
|
|
const char *shaderString);
|
|
|
|
};
|
|
|
|
|
2016-11-03 07:37:05 -07:00
|
|
|
struct gs_duplicator : gs_obj {
|
2014-12-29 00:29:55 -08:00
|
|
|
ComPtr<IDXGIOutputDuplication> duplicator;
|
|
|
|
gs_texture_2d *texture;
|
2016-11-03 06:59:56 -07:00
|
|
|
int idx;
|
2018-01-09 22:25:29 +01:00
|
|
|
long refs;
|
|
|
|
bool updated;
|
2016-11-03 06:59:56 -07:00
|
|
|
|
|
|
|
void Start();
|
2014-12-29 00:29:55 -08:00
|
|
|
|
2016-11-03 07:40:15 -07:00
|
|
|
inline void Release() { duplicator.Release(); }
|
|
|
|
|
2014-12-29 00:29:55 -08:00
|
|
|
gs_duplicator(gs_device_t *device, int monitor_idx);
|
|
|
|
~gs_duplicator();
|
|
|
|
};
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
struct gs_pixel_shader : gs_shader {
|
|
|
|
ComPtr<ID3D11PixelShader> shader;
|
2016-11-03 06:51:16 -07:00
|
|
|
vector<unique_ptr<ShaderSampler>> samplers;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2019-02-17 17:22:04 -08:00
|
|
|
void Rebuild(ID3D11Device *dev);
|
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 07:41:23 -07:00
|
|
|
|
2016-11-03 07:40:15 -07:00
|
|
|
inline void Release()
|
|
|
|
{
|
|
|
|
shader.Release();
|
|
|
|
constants.Release();
|
|
|
|
}
|
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
inline void GetSamplerStates(ID3D11SamplerState **states)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < samplers.size(); i++)
|
2016-11-03 06:51:16 -07:00
|
|
|
states[i] = samplers[i]->sampler.state;
|
2013-10-10 12:37:03 -07:00
|
|
|
for (; i < GS_MAX_TEXTURES; i++)
|
2013-09-30 19:37:13 -07:00
|
|
|
states[i] = NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
gs_pixel_shader(gs_device_t *device, const char *file,
|
2013-09-30 19:37:13 -07:00
|
|
|
const char *shaderString);
|
|
|
|
};
|
|
|
|
|
2016-11-03 07:37:05 -07:00
|
|
|
struct gs_swap_chain : gs_obj {
|
2013-09-30 19:37:13 -07:00
|
|
|
HWND hwnd;
|
2016-11-03 07:09:13 -07:00
|
|
|
gs_init_data initData;
|
2016-11-03 07:30:22 -07:00
|
|
|
DXGI_SWAP_CHAIN_DESC swapDesc = {};
|
2022-02-07 23:14:26 -08:00
|
|
|
gs_color_space space;
|
2021-09-11 01:07:39 -07:00
|
|
|
UINT presentFlags = 0;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
gs_texture_2d target;
|
|
|
|
gs_zstencil_buffer zs;
|
|
|
|
ComPtr<IDXGISwapChain> swap;
|
2021-09-14 21:59:54 -07:00
|
|
|
HANDLE hWaitable = NULL;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
void InitTarget(uint32_t cx, uint32_t cy);
|
|
|
|
void InitZStencilBuffer(uint32_t cx, uint32_t cy);
|
2022-02-07 23:14:26 -08:00
|
|
|
void Resize(uint32_t cx, uint32_t cy, gs_color_format format);
|
2016-11-03 07:09:13 -07:00
|
|
|
void Init();
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2019-02-17 17:22:04 -08:00
|
|
|
void Rebuild(ID3D11Device *dev);
|
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 07:41:23 -07:00
|
|
|
|
2016-11-03 07:40:15 -07:00
|
|
|
inline void Release()
|
|
|
|
{
|
|
|
|
target.Release();
|
|
|
|
zs.Release();
|
2021-09-14 21:59:54 -07:00
|
|
|
if (hWaitable) {
|
|
|
|
CloseHandle(hWaitable);
|
|
|
|
hWaitable = NULL;
|
|
|
|
}
|
|
|
|
swap.Clear();
|
2016-11-03 07:40:15 -07:00
|
|
|
}
|
|
|
|
|
2014-09-26 15:25:59 -07:00
|
|
|
gs_swap_chain(gs_device *device, const gs_init_data *data);
|
2021-09-14 21:59:54 -07:00
|
|
|
virtual ~gs_swap_chain();
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct BlendState {
|
|
|
|
bool blendEnabled;
|
2015-03-27 11:18:02 -07:00
|
|
|
gs_blend_type srcFactorC;
|
|
|
|
gs_blend_type destFactorC;
|
|
|
|
gs_blend_type srcFactorA;
|
|
|
|
gs_blend_type destFactorA;
|
2021-10-24 16:18:58 +01:00
|
|
|
gs_blend_op_type op;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
bool redEnabled;
|
|
|
|
bool greenEnabled;
|
|
|
|
bool blueEnabled;
|
|
|
|
bool alphaEnabled;
|
|
|
|
|
|
|
|
inline BlendState()
|
|
|
|
: blendEnabled(true),
|
2015-03-27 11:18:02 -07:00
|
|
|
srcFactorC(GS_BLEND_SRCALPHA),
|
|
|
|
destFactorC(GS_BLEND_INVSRCALPHA),
|
|
|
|
srcFactorA(GS_BLEND_ONE),
|
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-03 03:54:17 -07:00
|
|
|
destFactorA(GS_BLEND_INVSRCALPHA),
|
2021-10-24 16:18:58 +01:00
|
|
|
op(GS_BLEND_OP_ADD),
|
2013-09-30 19:37:13 -07:00
|
|
|
redEnabled(true),
|
|
|
|
greenEnabled(true),
|
|
|
|
blueEnabled(true),
|
|
|
|
alphaEnabled(true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline BlendState(const BlendState &state)
|
|
|
|
{
|
|
|
|
memcpy(this, &state, sizeof(BlendState));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SavedBlendState : BlendState {
|
|
|
|
ComPtr<ID3D11BlendState> state;
|
2016-11-03 07:30:22 -07:00
|
|
|
D3D11_BLEND_DESC bd;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2019-02-17 17:22:04 -08:00
|
|
|
void Rebuild(ID3D11Device *dev);
|
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 07:41:23 -07:00
|
|
|
|
2016-11-03 07:40:15 -07:00
|
|
|
inline void Release() { state.Release(); }
|
|
|
|
|
2016-11-03 07:30:22 -07:00
|
|
|
inline SavedBlendState(const BlendState &val, D3D11_BLEND_DESC &desc)
|
|
|
|
: BlendState(val), bd(desc)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct StencilSide {
|
|
|
|
gs_depth_test test;
|
2014-08-07 23:42:07 -07:00
|
|
|
gs_stencil_op_type fail;
|
|
|
|
gs_stencil_op_type zfail;
|
|
|
|
gs_stencil_op_type zpass;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
inline StencilSide()
|
|
|
|
: test(GS_ALWAYS), fail(GS_KEEP), zfail(GS_KEEP), zpass(GS_KEEP)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ZStencilState {
|
|
|
|
bool depthEnabled;
|
|
|
|
bool depthWriteEnabled;
|
|
|
|
gs_depth_test depthFunc;
|
|
|
|
|
|
|
|
bool stencilEnabled;
|
|
|
|
bool stencilWriteEnabled;
|
|
|
|
StencilSide stencilFront;
|
|
|
|
StencilSide stencilBack;
|
|
|
|
|
|
|
|
inline ZStencilState()
|
|
|
|
: depthEnabled(true),
|
|
|
|
depthWriteEnabled(true),
|
|
|
|
depthFunc(GS_LESS),
|
|
|
|
stencilEnabled(false),
|
|
|
|
stencilWriteEnabled(true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
inline ZStencilState(const ZStencilState &state)
|
|
|
|
{
|
|
|
|
memcpy(this, &state, sizeof(ZStencilState));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SavedZStencilState : ZStencilState {
|
|
|
|
ComPtr<ID3D11DepthStencilState> state;
|
2016-11-03 07:30:22 -07:00
|
|
|
D3D11_DEPTH_STENCIL_DESC dsd;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2019-02-17 17:22:04 -08:00
|
|
|
void Rebuild(ID3D11Device *dev);
|
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 07:41:23 -07:00
|
|
|
|
2016-11-03 07:40:15 -07:00
|
|
|
inline void Release() { state.Release(); }
|
|
|
|
|
2016-11-03 07:30:22 -07:00
|
|
|
inline SavedZStencilState(const ZStencilState &val,
|
|
|
|
D3D11_DEPTH_STENCIL_DESC desc)
|
|
|
|
: ZStencilState(val), dsd(desc)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RasterState {
|
|
|
|
gs_cull_mode cullMode;
|
|
|
|
bool scissorEnabled;
|
|
|
|
|
|
|
|
inline RasterState() : cullMode(GS_BACK), scissorEnabled(false) {}
|
|
|
|
|
|
|
|
inline RasterState(const RasterState &state)
|
|
|
|
{
|
|
|
|
memcpy(this, &state, sizeof(RasterState));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct SavedRasterState : RasterState {
|
|
|
|
ComPtr<ID3D11RasterizerState> state;
|
2016-11-03 07:30:22 -07:00
|
|
|
D3D11_RASTERIZER_DESC rd;
|
2013-09-30 19:37:13 -07:00
|
|
|
|
2019-02-17 17:22:04 -08:00
|
|
|
void Rebuild(ID3D11Device *dev);
|
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 07:41:23 -07:00
|
|
|
|
2016-11-03 07:40:15 -07:00
|
|
|
inline void Release() { state.Release(); }
|
|
|
|
|
2016-11-03 07:30:22 -07:00
|
|
|
inline SavedRasterState(const RasterState &val,
|
|
|
|
D3D11_RASTERIZER_DESC &desc)
|
|
|
|
: RasterState(val), rd(desc)
|
2013-09-30 19:37:13 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mat4float {
|
|
|
|
float mat[16];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct gs_device {
|
|
|
|
ComPtr<IDXGIFactory1> factory;
|
2016-11-03 06:39:24 -07:00
|
|
|
ComPtr<IDXGIAdapter1> adapter;
|
2013-09-30 19:37:13 -07:00
|
|
|
ComPtr<ID3D11Device> device;
|
|
|
|
ComPtr<ID3D11DeviceContext> context;
|
2016-11-03 07:10:58 -07:00
|
|
|
uint32_t adpIdx = 0;
|
2018-10-05 03:15:13 -07:00
|
|
|
bool nv12Supported = false;
|
2022-03-02 23:15:02 -08:00
|
|
|
bool p010Supported = false;
|
2019-06-22 22:13:45 -07:00
|
|
|
|
2015-02-09 01:02:12 -08:00
|
|
|
gs_texture_2d *curRenderTarget = nullptr;
|
|
|
|
gs_zstencil_buffer *curZStencilBuffer = nullptr;
|
|
|
|
int curRenderSide = 0;
|
2022-02-07 23:14:26 -08:00
|
|
|
enum gs_color_space curColorSpace = GS_CS_SRGB;
|
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-19 15:00:51 -08:00
|
|
|
bool curFramebufferSrgb = false;
|
|
|
|
bool curFramebufferInvalidate = false;
|
2013-10-10 12:37:03 -07:00
|
|
|
gs_texture *curTextures[GS_MAX_TEXTURES];
|
|
|
|
gs_sampler_state *curSamplers[GS_MAX_TEXTURES];
|
2015-02-09 01:02:12 -08:00
|
|
|
gs_vertex_buffer *curVertexBuffer = nullptr;
|
|
|
|
gs_index_buffer *curIndexBuffer = nullptr;
|
|
|
|
gs_vertex_shader *curVertexShader = nullptr;
|
|
|
|
gs_pixel_shader *curPixelShader = nullptr;
|
2015-07-30 17:16:24 -07:00
|
|
|
gs_swap_chain *curSwapChain = nullptr;
|
2019-06-22 22:13:45 -07:00
|
|
|
|
2017-05-15 23:35:50 -07:00
|
|
|
gs_vertex_buffer *lastVertexBuffer = nullptr;
|
|
|
|
gs_vertex_shader *lastVertexShader = nullptr;
|
2019-06-22 22:13:45 -07:00
|
|
|
|
2015-02-09 01:02:12 -08:00
|
|
|
bool zstencilStateChanged = true;
|
|
|
|
bool rasterStateChanged = true;
|
|
|
|
bool blendStateChanged = true;
|
2013-09-30 19:37:13 -07:00
|
|
|
ZStencilState zstencilState;
|
|
|
|
RasterState rasterState;
|
|
|
|
BlendState blendState;
|
|
|
|
vector<SavedZStencilState> zstencilStates;
|
|
|
|
vector<SavedRasterState> rasterStates;
|
|
|
|
vector<SavedBlendState> blendStates;
|
2015-02-09 01:02:12 -08:00
|
|
|
ID3D11DepthStencilState *curDepthStencilState = nullptr;
|
|
|
|
ID3D11RasterizerState *curRasterState = nullptr;
|
|
|
|
ID3D11BlendState *curBlendState = nullptr;
|
2013-09-30 19:37:13 -07:00
|
|
|
D3D11_PRIMITIVE_TOPOLOGY curToplogy;
|
2019-06-22 22:13:45 -07:00
|
|
|
|
2015-02-09 01:02:12 -08:00
|
|
|
pD3DCompile d3dCompile = nullptr;
|
2016-11-25 12:01:31 -08:00
|
|
|
#ifdef DISASSEMBLE_SHADERS
|
|
|
|
pD3DDisassemble d3dDisassemble = nullptr;
|
|
|
|
#endif
|
2014-10-03 14:29:47 -07:00
|
|
|
|
2013-09-30 19:37:13 -07:00
|
|
|
gs_rect viewport;
|
|
|
|
|
|
|
|
vector<mat4float> projStack;
|
|
|
|
|
|
|
|
matrix4 curProjMatrix;
|
|
|
|
matrix4 curViewMatrix;
|
|
|
|
matrix4 curViewProjMatrix;
|
|
|
|
|
2019-11-27 16:35:27 -08:00
|
|
|
vector<gs_device_loss> loss_callbacks;
|
2016-11-03 07:37:05 -07:00
|
|
|
gs_obj *first_obj = nullptr;
|
|
|
|
|
2022-04-13 22:24:20 -07:00
|
|
|
vector<std::pair<HMONITOR, bool>> monitor_to_hdr;
|
|
|
|
|
2014-10-03 14:29:47 -07:00
|
|
|
void InitCompiler();
|
2021-03-21 20:37:56 -07:00
|
|
|
void InitFactory();
|
2021-03-21 20:40:23 -07:00
|
|
|
void ReorderAdapters(uint32_t &adapterIdx);
|
2021-03-21 20:37:56 -07:00
|
|
|
void InitAdapter(uint32_t adapterIdx);
|
2016-11-03 06:39:24 -07:00
|
|
|
void InitDevice(uint32_t adapterIdx);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
ID3D11DepthStencilState *AddZStencilState();
|
|
|
|
ID3D11RasterizerState *AddRasterState();
|
|
|
|
ID3D11BlendState *AddBlendState();
|
|
|
|
void UpdateZStencilState();
|
|
|
|
void UpdateRasterState();
|
|
|
|
void UpdateBlendState();
|
|
|
|
|
2017-05-15 23:35:50 -07:00
|
|
|
void LoadVertexBufferData();
|
|
|
|
|
2014-09-25 17:44:05 -07:00
|
|
|
inline void CopyTex(ID3D11Texture2D *dst, uint32_t dst_x,
|
|
|
|
uint32_t dst_y, gs_texture_t *src, uint32_t src_x,
|
|
|
|
uint32_t src_y, uint32_t src_w, uint32_t src_h);
|
2013-09-30 19:37:13 -07:00
|
|
|
|
|
|
|
void UpdateViewProjMatrix();
|
|
|
|
|
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-19 15:00:51 -08:00
|
|
|
void FlushOutputViews();
|
|
|
|
|
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 07:41:23 -07:00
|
|
|
void RebuildDevice();
|
|
|
|
|
2019-03-04 15:40:53 -08:00
|
|
|
bool HasBadNV12Output();
|
2019-03-04 14:06:10 -08:00
|
|
|
|
2015-07-31 23:09:48 -07:00
|
|
|
gs_device(uint32_t adapterIdx);
|
2016-11-03 07:03:02 -07:00
|
|
|
~gs_device();
|
2013-09-30 19:37:13 -07:00
|
|
|
};
|
2019-03-03 08:39:18 -08:00
|
|
|
|
|
|
|
extern "C" EXPORT int device_texture_acquire_sync(gs_texture_t *tex,
|
|
|
|
uint64_t key, uint32_t ms);
|