2019-03-09 13:31:35 +00:00
|
|
|
// Copyright 2019 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2019-03-09 13:31:35 +00:00
|
|
|
|
|
|
|
#include "VideoBackends/D3DCommon/SwapChain.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
#include "Common/Assert.h"
|
|
|
|
#include "Common/CommonFuncs.h"
|
2021-12-12 21:50:18 +00:00
|
|
|
#include "Common/HRWrap.h"
|
2019-03-09 13:31:35 +00:00
|
|
|
#include "Common/Logging/Log.h"
|
|
|
|
#include "Common/MsgHandler.h"
|
2021-12-12 21:50:18 +00:00
|
|
|
|
2019-03-09 13:31:35 +00:00
|
|
|
#include "VideoCommon/VideoConfig.h"
|
|
|
|
|
|
|
|
static bool IsTearingSupported(IDXGIFactory2* dxgi_factory)
|
|
|
|
{
|
|
|
|
Microsoft::WRL::ComPtr<IDXGIFactory5> factory5;
|
|
|
|
if (FAILED(dxgi_factory->QueryInterface(IID_PPV_ARGS(&factory5))))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
UINT allow_tearing = 0;
|
|
|
|
return SUCCEEDED(factory5->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &allow_tearing,
|
|
|
|
sizeof(allow_tearing))) &&
|
|
|
|
allow_tearing != 0;
|
|
|
|
}
|
|
|
|
|
2019-05-12 04:42:16 +00:00
|
|
|
static bool GetFullscreenState(IDXGISwapChain* swap_chain)
|
2019-03-09 13:31:35 +00:00
|
|
|
{
|
|
|
|
BOOL fs = FALSE;
|
|
|
|
return SUCCEEDED(swap_chain->GetFullscreenState(&fs, nullptr)) && fs;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace D3DCommon
|
|
|
|
{
|
2019-05-12 04:42:16 +00:00
|
|
|
SwapChain::SwapChain(const WindowSystemInfo& wsi, IDXGIFactory* dxgi_factory, IUnknown* d3d_device)
|
|
|
|
: m_wsi(wsi), m_dxgi_factory(dxgi_factory), m_d3d_device(d3d_device)
|
2019-03-09 13:31:35 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SwapChain::~SwapChain()
|
|
|
|
{
|
|
|
|
// Can't destroy swap chain while it's fullscreen.
|
|
|
|
if (m_swap_chain && GetFullscreenState(m_swap_chain.Get()))
|
|
|
|
m_swap_chain->SetFullscreenState(FALSE, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SwapChain::WantsStereo()
|
|
|
|
{
|
|
|
|
return g_ActiveConfig.stereo_mode == StereoMode::QuadBuffer;
|
|
|
|
}
|
|
|
|
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 08:48:05 +00:00
|
|
|
bool SwapChain::WantsHDR()
|
|
|
|
{
|
|
|
|
return g_ActiveConfig.bHDR;
|
|
|
|
}
|
|
|
|
|
2019-03-09 13:31:35 +00:00
|
|
|
u32 SwapChain::GetSwapChainFlags() const
|
|
|
|
{
|
|
|
|
// This flag is necessary if we want to use a flip-model swapchain without locking the framerate
|
|
|
|
return m_allow_tearing_supported ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0;
|
|
|
|
}
|
|
|
|
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 08:48:05 +00:00
|
|
|
bool SwapChain::CreateSwapChain(bool stereo, bool hdr)
|
2019-03-09 13:31:35 +00:00
|
|
|
{
|
|
|
|
RECT client_rc;
|
|
|
|
if (GetClientRect(static_cast<HWND>(m_wsi.render_surface), &client_rc))
|
|
|
|
{
|
|
|
|
m_width = client_rc.right - client_rc.left;
|
|
|
|
m_height = client_rc.bottom - client_rc.top;
|
|
|
|
}
|
|
|
|
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 08:48:05 +00:00
|
|
|
m_stereo = false;
|
|
|
|
m_hdr = false;
|
|
|
|
|
2019-05-12 04:42:16 +00:00
|
|
|
// Try using the Win8 version if available.
|
|
|
|
Microsoft::WRL::ComPtr<IDXGIFactory2> dxgi_factory2;
|
|
|
|
HRESULT hr = m_dxgi_factory.As(&dxgi_factory2);
|
|
|
|
if (SUCCEEDED(hr))
|
2019-03-09 13:31:35 +00:00
|
|
|
{
|
2019-05-12 04:42:16 +00:00
|
|
|
m_allow_tearing_supported = IsTearingSupported(dxgi_factory2.Get());
|
|
|
|
|
|
|
|
DXGI_SWAP_CHAIN_DESC1 swap_chain_desc = {};
|
|
|
|
swap_chain_desc.Width = m_width;
|
|
|
|
swap_chain_desc.Height = m_height;
|
|
|
|
swap_chain_desc.BufferCount = SWAP_CHAIN_BUFFER_COUNT;
|
|
|
|
swap_chain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
|
|
|
swap_chain_desc.SampleDesc.Count = 1;
|
|
|
|
swap_chain_desc.SampleDesc.Quality = 0;
|
|
|
|
swap_chain_desc.Format = GetDXGIFormatForAbstractFormat(m_texture_format, false);
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 08:48:05 +00:00
|
|
|
|
2019-05-12 04:42:16 +00:00
|
|
|
swap_chain_desc.Scaling = DXGI_SCALING_STRETCH;
|
|
|
|
swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
|
|
|
|
swap_chain_desc.Stereo = stereo;
|
|
|
|
swap_chain_desc.Flags = GetSwapChainFlags();
|
|
|
|
|
|
|
|
Microsoft::WRL::ComPtr<IDXGISwapChain1> swap_chain1;
|
|
|
|
hr = dxgi_factory2->CreateSwapChainForHwnd(m_d3d_device.Get(),
|
|
|
|
static_cast<HWND>(m_wsi.render_surface),
|
|
|
|
&swap_chain_desc, nullptr, nullptr, &swap_chain1);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
// Flip-model discard swapchains aren't supported on Windows 8, so here we fall back to
|
|
|
|
// a sequential swapchain
|
|
|
|
swap_chain_desc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
|
|
|
|
hr = dxgi_factory2->CreateSwapChainForHwnd(m_d3d_device.Get(),
|
|
|
|
static_cast<HWND>(m_wsi.render_surface),
|
|
|
|
&swap_chain_desc, nullptr, nullptr, &swap_chain1);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_swap_chain = swap_chain1;
|
2019-03-09 13:31:35 +00:00
|
|
|
}
|
|
|
|
|
2019-05-12 04:42:16 +00:00
|
|
|
// Flip-model swapchains aren't supported on Windows 7, so here we fall back to a legacy
|
|
|
|
// BitBlt-model swapchain. Note that this won't work for DX12, but systems which don't
|
|
|
|
// support the newer DXGI interface aren't going to support DX12 anyway.
|
2019-03-09 13:31:35 +00:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 08:48:05 +00:00
|
|
|
hdr = false;
|
|
|
|
|
2019-05-12 04:42:16 +00:00
|
|
|
DXGI_SWAP_CHAIN_DESC desc = {};
|
|
|
|
desc.BufferDesc.Width = m_width;
|
|
|
|
desc.BufferDesc.Height = m_height;
|
|
|
|
desc.BufferDesc.Format = GetDXGIFormatForAbstractFormat(m_texture_format, false);
|
|
|
|
desc.SampleDesc.Count = 1;
|
|
|
|
desc.SampleDesc.Quality = 0;
|
|
|
|
desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
|
|
|
desc.BufferCount = SWAP_CHAIN_BUFFER_COUNT;
|
|
|
|
desc.OutputWindow = static_cast<HWND>(m_wsi.render_surface);
|
|
|
|
desc.Windowed = TRUE;
|
|
|
|
desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
|
|
|
desc.Flags = 0;
|
|
|
|
|
|
|
|
m_allow_tearing_supported = false;
|
|
|
|
hr = m_dxgi_factory->CreateSwapChain(m_d3d_device.Get(), &desc, &m_swap_chain);
|
2019-03-09 13:31:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-12-12 21:50:18 +00:00
|
|
|
PanicAlertFmt("Failed to create swap chain: {}", Common::HRWrap(hr));
|
2019-03-09 13:31:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We handle fullscreen ourselves.
|
|
|
|
hr = m_dxgi_factory->MakeWindowAssociation(static_cast<HWND>(m_wsi.render_surface),
|
|
|
|
DXGI_MWA_NO_WINDOW_CHANGES | DXGI_MWA_NO_ALT_ENTER);
|
|
|
|
if (FAILED(hr))
|
2021-12-12 21:50:18 +00:00
|
|
|
WARN_LOG_FMT(VIDEO, "MakeWindowAssociation() failed: {}", Common::HRWrap(hr));
|
2019-03-09 13:31:35 +00:00
|
|
|
|
|
|
|
m_stereo = stereo;
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 08:48:05 +00:00
|
|
|
|
|
|
|
if (hdr)
|
|
|
|
{
|
|
|
|
// Only try to activate HDR here, to avoid failing when creating the swapchain
|
|
|
|
// (we can't know if the format is supported upfront)
|
|
|
|
Microsoft::WRL::ComPtr<IDXGISwapChain4> swap_chain4;
|
|
|
|
hr = m_swap_chain->QueryInterface(IID_PPV_ARGS(&swap_chain4));
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
UINT color_space_support = 0;
|
|
|
|
// Note that this should succeed even if HDR is not currently engaged on the monitor,
|
|
|
|
// but it should display fine nonetheless.
|
|
|
|
// We need to check for DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020 as checking for
|
|
|
|
// scRGB always returns false (DX bug).
|
|
|
|
hr = swap_chain4->CheckColorSpaceSupport(DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020,
|
|
|
|
&color_space_support);
|
|
|
|
if (SUCCEEDED(hr) && (color_space_support & DXGI_SWAP_CHAIN_COLOR_SPACE_SUPPORT_FLAG_PRESENT))
|
|
|
|
{
|
|
|
|
hr = swap_chain4->ResizeBuffers(SWAP_CHAIN_BUFFER_COUNT, 0, 0,
|
|
|
|
GetDXGIFormatForAbstractFormat(m_texture_format_hdr, false),
|
|
|
|
GetSwapChainFlags());
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
hr = swap_chain4->SetColorSpace1(DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
m_hdr = hdr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-09 13:31:35 +00:00
|
|
|
if (!CreateSwapChainBuffers())
|
|
|
|
{
|
2020-12-02 18:17:27 +00:00
|
|
|
PanicAlertFmt("Failed to create swap chain buffers");
|
2019-03-09 13:31:35 +00:00
|
|
|
DestroySwapChainBuffers();
|
|
|
|
m_swap_chain.Reset();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwapChain::DestroySwapChain()
|
|
|
|
{
|
|
|
|
DestroySwapChainBuffers();
|
|
|
|
|
|
|
|
// Can't destroy swap chain while it's fullscreen.
|
|
|
|
if (m_swap_chain && GetFullscreenState(m_swap_chain.Get()))
|
|
|
|
m_swap_chain->SetFullscreenState(FALSE, nullptr);
|
|
|
|
|
|
|
|
m_swap_chain.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SwapChain::ResizeSwapChain()
|
|
|
|
{
|
|
|
|
DestroySwapChainBuffers();
|
|
|
|
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 08:48:05 +00:00
|
|
|
// The swap chain fills up the size of the window if no size is specified
|
|
|
|
HRESULT hr = m_swap_chain->ResizeBuffers(SWAP_CHAIN_BUFFER_COUNT, 0, 0, DXGI_FORMAT_UNKNOWN,
|
2019-03-09 13:31:35 +00:00
|
|
|
GetSwapChainFlags());
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 08:48:05 +00:00
|
|
|
|
2019-03-09 13:31:35 +00:00
|
|
|
if (FAILED(hr))
|
2021-12-12 21:50:18 +00:00
|
|
|
WARN_LOG_FMT(VIDEO, "ResizeBuffers() failed: {}", Common::HRWrap(hr));
|
2019-03-09 13:31:35 +00:00
|
|
|
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 08:48:05 +00:00
|
|
|
Microsoft::WRL::ComPtr<IDXGISwapChain4> swap_chain4;
|
|
|
|
hr = m_swap_chain->QueryInterface(IID_PPV_ARGS(&swap_chain4));
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
hr = swap_chain4->SetColorSpace1(m_hdr ? DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709 :
|
|
|
|
DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709);
|
|
|
|
|
2019-05-12 04:42:16 +00:00
|
|
|
DXGI_SWAP_CHAIN_DESC desc;
|
|
|
|
if (SUCCEEDED(m_swap_chain->GetDesc(&desc)))
|
2019-03-09 13:31:35 +00:00
|
|
|
{
|
2019-05-12 04:42:16 +00:00
|
|
|
m_width = desc.BufferDesc.Width;
|
|
|
|
m_height = desc.BufferDesc.Height;
|
2019-03-09 13:31:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return CreateSwapChainBuffers();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwapChain::SetStereo(bool stereo)
|
|
|
|
{
|
|
|
|
if (m_stereo == stereo)
|
|
|
|
return;
|
|
|
|
|
|
|
|
DestroySwapChain();
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 08:48:05 +00:00
|
|
|
// Do not try to re-activate HDR here if it had already failed
|
|
|
|
if (!CreateSwapChain(stereo, m_hdr))
|
2019-03-09 13:31:35 +00:00
|
|
|
{
|
2020-12-02 18:17:27 +00:00
|
|
|
PanicAlertFmt("Failed to switch swap chain stereo mode");
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 08:48:05 +00:00
|
|
|
CreateSwapChain(false, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwapChain::SetHDR(bool hdr)
|
|
|
|
{
|
|
|
|
if (m_hdr == hdr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// NOTE: as an optimization here we could just call "ResizeSwapChain()"
|
|
|
|
// by adding some code to check if we could change the format to HDR.
|
|
|
|
|
|
|
|
DestroySwapChain();
|
|
|
|
// Do not try to re-activate stereo mode here if it had already failed
|
|
|
|
if (!CreateSwapChain(m_stereo, hdr))
|
|
|
|
{
|
|
|
|
PanicAlertFmt("Failed to switch swap chain SDR/HDR mode");
|
|
|
|
CreateSwapChain(false, false);
|
2019-03-09 13:31:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SwapChain::GetFullscreen() const
|
|
|
|
{
|
|
|
|
return GetFullscreenState(m_swap_chain.Get());
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwapChain::SetFullscreen(bool request)
|
|
|
|
{
|
|
|
|
m_swap_chain->SetFullscreenState(request, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SwapChain::CheckForFullscreenChange()
|
|
|
|
{
|
|
|
|
if (m_fullscreen_request != m_has_fullscreen)
|
|
|
|
{
|
|
|
|
HRESULT hr = m_swap_chain->SetFullscreenState(m_fullscreen_request, nullptr);
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
{
|
|
|
|
m_has_fullscreen = m_fullscreen_request;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const bool new_fullscreen_state = GetFullscreenState(m_swap_chain.Get());
|
|
|
|
if (new_fullscreen_state != m_has_fullscreen)
|
|
|
|
{
|
|
|
|
m_has_fullscreen = new_fullscreen_state;
|
|
|
|
m_fullscreen_request = new_fullscreen_state;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SwapChain::Present()
|
|
|
|
{
|
|
|
|
// When using sync interval 0, it is recommended to always pass the tearing flag when it is
|
|
|
|
// supported, even when presenting in windowed mode. However, this flag cannot be used if the app
|
|
|
|
// is in fullscreen mode as a result of calling SetFullscreenState.
|
|
|
|
UINT present_flags = 0;
|
|
|
|
if (m_allow_tearing_supported && !g_ActiveConfig.bVSyncActive && !m_has_fullscreen)
|
|
|
|
present_flags |= DXGI_PRESENT_ALLOW_TEARING;
|
|
|
|
|
|
|
|
HRESULT hr = m_swap_chain->Present(static_cast<UINT>(g_ActiveConfig.bVSyncActive), present_flags);
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2021-12-12 21:50:18 +00:00
|
|
|
WARN_LOG_FMT(VIDEO, "Swap chain present failed: {}", Common::HRWrap(hr));
|
2019-03-09 13:31:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool SwapChain::ChangeSurface(void* native_handle)
|
|
|
|
{
|
|
|
|
DestroySwapChain();
|
|
|
|
m_wsi.render_surface = native_handle;
|
Video: implement color correction to match the NTSC and PAL color spaces (and gamma) that GC and Wii targeted.
To further increase the accuracy of the post process phase, I've added (scRGB) HDR support, which is necessary
to fully display the PAL and NTSC-J color spaces, and also to improve the quality of post process texture samplings and
do them in linear space instead of gamma space (which is very important when playing at low resolutions).
For SDR, the quality is also slightly increased, at least if any post process runs, as the buffer is now
R10G10B10A2 (on Vulkan, DX11 and DX12) if supported; previously it was R8G8B8A8 but the alpha bits were wasted.
Gamma correction is arguably the most important thing as Dolphin on Windows outputted in "sRGB" (implicitly)
as that's what Windows expects by default, though sRGB gamma is very different from the gamma commonly used
by video standards dating to the pre HDR era (roughly gamma 2.35).
Additionally, the addition of HDR support (which is pretty straight forward and minimal), added support for
our own custom AutoHDR shaders, which would allow us to achieve decent looking HDR in Dolphin games without
having to use SpecialK or Windows 11 AutoHDR. Both of which don't necessarily play nice with older games
with strongly different and simpler lighting. HDR should also be supported in Linux.
Development of my own AutoHDR shader is almost complete and will come next.
This has been carefully tested and there should be no regression in any of the different features that Dolphin
offers, like multisampling, stereo rendering, other post processes, etc etc.
Fixes: https://bugs.dolphin-emu.org/issues/8941
Co-authored-by: EndlesslyFlowering <EndlesslyFlowering@protonmail.com>
Co-authored-by: Dogway <lin_ares@hotmail.com>
2023-06-10 08:48:05 +00:00
|
|
|
// We only keep the swap chain settings (HDR/Stereo) that had successfully applied beofre
|
|
|
|
return CreateSwapChain(m_stereo, m_hdr);
|
2019-03-09 13:31:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace D3DCommon
|