dolphin/Source/Core/VideoBackends/D3D12/D3D12SwapChain.cpp

Failed to ignore revisions in .git-blame-ignore-revs.

80 lines
2.3 KiB
C++
Raw Normal View History

2019-03-28 10:35:46 +00:00
// Copyright 2019 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
2019-03-28 10:35:46 +00:00
#include "VideoBackends/D3D12/D3D12SwapChain.h"
2021-12-10 02:22:16 +00:00
#include "Common/Assert.h"
#include "VideoBackends/D3D12/DX12Context.h"
#include "VideoBackends/D3D12/DX12Texture.h"
2019-03-28 10:35:46 +00:00
namespace DX12
{
SwapChain::SwapChain(const WindowSystemInfo& wsi, IDXGIFactory* dxgi_factory,
2019-03-28 10:35:46 +00:00
ID3D12CommandQueue* d3d_command_queue)
: D3DCommon::SwapChain(wsi, dxgi_factory, d3d_command_queue)
{
}
SwapChain::~SwapChain() = default;
std::unique_ptr<SwapChain> SwapChain::Create(const WindowSystemInfo& wsi)
{
std::unique_ptr<SwapChain> swap_chain = std::make_unique<SwapChain>(
wsi, g_dx_context->GetDXGIFactory(), g_dx_context->GetCommandQueue());
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 (!swap_chain->CreateSwapChain(WantsStereo(), WantsHDR()))
2019-03-28 10:35:46 +00:00
return nullptr;
return swap_chain;
}
bool SwapChain::CreateSwapChainBuffers()
{
for (u32 i = 0; i < SWAP_CHAIN_BUFFER_COUNT; i++)
{
ComPtr<ID3D12Resource> resource;
HRESULT hr = m_swap_chain->GetBuffer(i, IID_PPV_ARGS(&resource));
ASSERT_MSG(VIDEO, SUCCEEDED(hr), "Failed to get swap chain buffer {}: {}", i, DX12HRWrap(hr));
2019-03-28 10:35:46 +00:00
BufferResources buffer;
buffer.texture = DXTexture::CreateAdopted(resource.Get());
ASSERT_MSG(VIDEO, buffer.texture != nullptr, "Failed to create swap chain buffer texture");
2019-03-28 10:35:46 +00:00
if (!buffer.texture)
return false;
buffer.framebuffer = DXFramebuffer::Create(buffer.texture.get(), nullptr, {});
ASSERT_MSG(VIDEO, buffer.framebuffer != nullptr,
"Failed to create swap chain buffer framebuffer");
2019-03-28 10:35:46 +00:00
if (!buffer.framebuffer)
return false;
m_buffers.push_back(std::move(buffer));
}
m_current_buffer = 0;
return true;
}
void SwapChain::DestroySwapChainBuffers()
{
// Swap chain textures must be released before it can be resized, therefore we need to destroy all
// of them immediately, and not place them onto the deferred desturction queue.
for (BufferResources& res : m_buffers)
{
res.framebuffer.reset();
res.texture->DestroyResource();
res.texture.release();
}
m_buffers.clear();
}
bool SwapChain::Present()
{
if (!D3DCommon::SwapChain::Present())
return false;
m_current_buffer = (m_current_buffer + 1) % SWAP_CHAIN_BUFFER_COUNT;
return true;
}
} // namespace DX12