Skip to content

Commit

Permalink
Some performance improvements:
Browse files Browse the repository at this point in the history
Since GetHDRDisplayStatus() is relativity slow function prefer avoid use it when is posible. Is used cached status isHDROutput() and more fast IsDisplayHDREnabled() method based on GetDesc1 inside ResizeBuffers().

Anterior approach is not causing issues but now is better.

Separate 10bSwapchain flag from HDROutput flag. Some renaming and code styling.

Refactor to avoid if defs
  • Loading branch information
thexai committed Dec 31, 2019
1 parent fae9ab8 commit 5fbc5b6
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 82 deletions.
4 changes: 2 additions & 2 deletions addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -6131,12 +6131,12 @@ msgstr ""

#: addons/skin.estuary/xml/DialogButtonMenu.xml
msgctxt "#13037"
msgid "Toggle Windows HDR On"
msgid "Toggle display HDR on"
msgstr ""

#: addons/skin.estuary/xml/DialogButtonMenu.xml
msgctxt "#13038"
msgid "Toggle Windows HDR Off"
msgid "Toggle display HDR off"
msgstr ""

#empty strings from id 13039 to 13049
Expand Down
5 changes: 3 additions & 2 deletions xbmc/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,10 @@ bool CApplication::Create(const CAppParamParser &params)
CLog::Log(LOGNOTICE, "%s", CWIN32Util::GetResInfoString().c_str());
CLog::Log(LOGNOTICE, "Running with %s rights", (CWIN32Util::IsCurrentUserLocalAdministrator() == TRUE) ? "administrator" : "restricted");
CLog::Log(LOGNOTICE, "Aero is %s", (g_sysinfo.IsAeroDisabled() == true) ? "disabled" : "enabled");
if (CWIN32Util::GetHDRDisplayStatus())
int hDR = CWIN32Util::GetHDRDisplayStatus();
if (hDR > 0)
CLog::Log(LOGNOTICE, "HDR Display capable is detected and Windows HDR switch is %s",
(CWIN32Util::IsDisplayHDREnabled() == true) ? "ON" : "OFF");
(hDR == 2) ? "ON" : "OFF");
else
CLog::Log(LOGNOTICE, "Display is not HDR capable");
#endif
Expand Down
10 changes: 2 additions & 8 deletions xbmc/cores/VideoPlayer/VideoRenderers/HwDecRender/DXVAHD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ do { \
} \
} while(0);

template<typename T>
T from_rational(uint64_t default_factor, AVRational rat)
{
return static_cast<T>(default_factor * rat.num / rat.den);
}

CProcessorHD::CProcessorHD()
{
DX::Windowing()->Register(this);
Expand Down Expand Up @@ -514,7 +508,7 @@ bool CProcessorHD::Render(CRect src, CRect dst, ID3D11Resource* target, CRenderB
? DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709
: DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709;

if (DX::DeviceResources::Get()->Is10BitSwapchain())
if (DX::DeviceResources::Get()->IsHDROutput())
{
if ((views[2]->color_transfer == AVCOL_TRC_SMPTE2084 ||
views[2]->color_transfer == AVCOL_TRC_ARIB_STD_B67) &&
Expand All @@ -538,7 +532,7 @@ bool CProcessorHD::Render(CRect src, CRect dst, ID3D11Resource* target, CRenderB
// makes target available for processing in shaders
videoCtx1->VideoProcessorSetOutputShaderUsage(m_pVideoProcessor.Get(), 1);

if (DX::DeviceResources::Get()->Is10BitSwapchain() && m_bSupportHDR10 &&
if (DX::DeviceResources::Get()->IsHDROutput() && m_bSupportHDR10 &&
views[2]->color_transfer == AVCOL_TRC_SMPTE2084 && views[2]->primaries == AVCOL_PRI_BT2020)
{
ComPtr<ID3D11VideoContext2> videoCtx2;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ bool COutputShader::Create(bool useLUT, bool useDithering, int ditherDepth, bool
{
m_useLut = useLUT;
m_ditherDepth = ditherDepth;
m_toneMapping = toneMapping && !DX::DeviceResources::Get()->Is10BitSwapchain();
m_toneMapping = toneMapping && !DX::DeviceResources::Get()->IsHDROutput();

CWinShader::CreateVertexBuffer(4, sizeof(Vertex));

Expand Down
47 changes: 19 additions & 28 deletions xbmc/cores/VideoPlayer/VideoRenderers/windows/RendererBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

#include "DVDCodecs/Video/DVDVideoCodec.h"
#include "DVDCodecs/Video/DXVA.h"
#include "platform/win32/WIN32Util.h"
#include "Process/VideoBuffer.h"
#include "VideoRenderers/BaseRenderer.h"
#include "VideoRenderers/RenderFlags.h"
Expand Down Expand Up @@ -131,13 +130,10 @@ CRendererBase::CRendererBase(CVideoSettings& videoSettings)

CRendererBase::~CRendererBase()
{
if (DX::DeviceResources::Get()->Is10BitSwapchain())
if (DX::DeviceResources::Get()->IsHDROutput())
{
if (CWIN32Util::IsDisplayHDREnabled())
{
CLog::LogF(LOGDEBUG, "Restoring SDR rendering");
DX::DeviceResources::Get()->SetColorSpace1(DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709);
}
CLog::LogF(LOGDEBUG, "Restoring SDR rendering");
DX::DeviceResources::Get()->SetHdrColorSpace(DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709);
}
Flush(false);
}
Expand Down Expand Up @@ -171,7 +167,7 @@ bool CRendererBase::Configure(const VideoPicture& picture, float fps, unsigned o
m_fps = fps;
m_renderOrientation = orientation;

if (DX::DeviceResources::Get()->Is10BitSwapchain())
if (DX::DeviceResources::Get()->IsHDROutput())
{
m_lastHdr10 = {};
m_isHdrEnabled = false;
Expand Down Expand Up @@ -214,7 +210,7 @@ void CRendererBase::Render(CD3DTexture& target, const CRect& sourceRect, const C
return;
}

if (DX::DeviceResources::Get()->Is10BitSwapchain())
if (DX::DeviceResources::Get()->IsHDROutput())
{
// HDR10
if (buf->color_transfer == AVCOL_TRC_SMPTE2084 && buf->primaries == AVCOL_PRI_BT2020)
Expand All @@ -233,14 +229,11 @@ void CRendererBase::Render(CD3DTexture& target, const CRect& sourceRect, const C
else
{
// Sets HDR10 metadata and enables HDR10 color space (switch to HDR rendering)
if (CWIN32Util::IsDisplayHDREnabled())
{
DX::DeviceResources::Get()->SetHdrMetaData(hdr10);
CLog::LogF(LOGNOTICE, "Switching to HDR rendering");
DX::DeviceResources::Get()->SetColorSpace1(DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020);
m_isHdrEnabled = true;
m_lastHdr10 = hdr10;
}
DX::DeviceResources::Get()->SetHdrMetaData(hdr10);
CLog::LogF(LOGNOTICE, "Switching to HDR rendering");
DX::DeviceResources::Get()->SetHdrColorSpace(DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020);
m_isHdrEnabled = true;
m_lastHdr10 = hdr10;
}
m_iCntMetaData = 0;
}
Expand All @@ -249,13 +242,10 @@ void CRendererBase::Render(CD3DTexture& target, const CRect& sourceRect, const C
{
if (!m_isHlgEnabled)
{
if (CWIN32Util::IsDisplayHDREnabled())
{
// Switch to HLG rendering (internally converts HLG to HDR10)
CLog::LogF(LOGNOTICE, "Switching to HLG rendering");
DX::DeviceResources::Get()->SetColorSpace1(DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020);
m_isHlgEnabled = true;
}
// Switch to HLG rendering (internally converts HLG to HDR10)
CLog::LogF(LOGNOTICE, "Switching to HLG rendering");
DX::DeviceResources::Get()->SetHdrColorSpace(DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020);
m_isHlgEnabled = true;
}
}
// Rec. 2020
Expand All @@ -265,7 +255,7 @@ void CRendererBase::Render(CD3DTexture& target, const CRect& sourceRect, const C
{
// Switch to Rec.2020 rendering
CLog::LogF(LOGNOTICE, "Switching to Rec.2020 rendering");
DX::DeviceResources::Get()->SetColorSpace1(DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020);
DX::DeviceResources::Get()->SetHdrColorSpace(DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020);
m_isRec2020Enabled = true;
}
}
Expand All @@ -278,7 +268,7 @@ void CRendererBase::Render(CD3DTexture& target, const CRect& sourceRect, const C
{
// If more than 60 frames are received without HDR10 metadata switch to SDR rendering
CLog::LogF(LOGNOTICE, "Switching to SDR rendering");
DX::DeviceResources::Get()->SetColorSpace1(DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709);
DX::DeviceResources::Get()->SetHdrColorSpace(DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709);
m_isHdrEnabled = false;
m_iCntMetaData = 0;
}
Expand All @@ -287,7 +277,7 @@ void CRendererBase::Render(CD3DTexture& target, const CRect& sourceRect, const C
{
// Switch to SDR rendering
CLog::LogF(LOGNOTICE, "Switching to SDR rendering");
DX::DeviceResources::Get()->SetColorSpace1(DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709);
DX::DeviceResources::Get()->SetHdrColorSpace(DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709);
m_isHlgEnabled = false;
m_isRec2020Enabled = false;
}
Expand Down Expand Up @@ -491,7 +481,8 @@ void CRendererBase::CheckVideoParameters()
CRenderBuffer* buf = m_renderBuffers[m_iBufferIndex];

bool toneMap = false;
if (m_videoSettings.m_ToneMapMethod != VS_TONEMAPMETHOD_OFF)
if (m_videoSettings.m_ToneMapMethod != VS_TONEMAPMETHOD_OFF &&
!DX::DeviceResources::Get()->IsHDROutput())
{
if (buf->hasLightMetadata || buf->hasDisplayMetadata && buf->displayMetadata.has_luminance)
toneMap = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@ CRect CRendererDXVA::ApplyTransforms(const CRect& destRect) const
bool CRendererDXVA::UseToneMapping() const
{
// use mapping only if processor doesn't support HDR10
// and is not 10 bit swapchain (HDR to SDR conversion)
return !m_processor->HasHDR10Support() && !DX::DeviceResources::Get()->Is10BitSwapchain() &&
__super::UseToneMapping();
return !m_processor->HasHDR10Support() && __super::UseToneMapping();
}

void CRendererDXVA::FillBuffersSet(CRenderBuffer* (&buffers)[8])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ void CRendererShaders::UpdateVideoFilters()

AVColorPrimaries dstPrimaries = AVCOL_PRI_BT709;

if (DX::DeviceResources::Get()->Is10BitSwapchain())
if (DX::DeviceResources::Get()->IsHDROutput() &&
(m_srcPrimaries == AVCOL_PRI_BT709 || m_srcPrimaries == AVCOL_PRI_BT2020))
dstPrimaries = m_srcPrimaries;

if (!m_colorShader->Create(m_format, dstPrimaries, m_srcPrimaries))
Expand Down
15 changes: 2 additions & 13 deletions xbmc/guilib/guiinfo/SystemGUIInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
#if defined(TARGET_DARWIN_OSX)
#include "platform/darwin/osx/smc.h"
#endif
#if defined(TARGET_WINDOWS)
#include "platform/win32/WIN32Util.h"
#endif
#include "powermanagement/PowerManager.h"
#include "profiles/ProfileManager.h"
#include "settings/AdvancedSettings.h"
Expand Down Expand Up @@ -574,18 +571,10 @@ bool CSystemGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int context
value = CServiceBroker::GetSettingsComponent()->GetAdvancedSettings()->m_showExitButton;
return true;
case SYSTEM_IS_HDR_DISPLAY_OFF:
#if defined(TARGET_WINDOWS)
value = (1 == CWIN32Util::GetHDRDisplayStatus());
#else
value = false;
#endif
value = (1 == CServiceBroker::GetWinSystem()->GetHDRDisplayStatus());
return true;
case SYSTEM_IS_HDR_DISPLAY_ON:
#if defined(TARGET_WINDOWS)
value = (2 == CWIN32Util::GetHDRDisplayStatus());
#else
value = false;
#endif
value = (2 == CServiceBroker::GetWinSystem()->GetHDRDisplayStatus());
return true;
case SYSTEM_HAS_LOGINSCREEN:
value = CServiceBroker::GetSettingsComponent()->GetProfileManager()->UsingLoginScreen();
Expand Down
7 changes: 1 addition & 6 deletions xbmc/interfaces/builtins/GUIBuiltins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#include "input/WindowTranslator.h"
#include "input/actions/ActionTranslator.h"
#include "messaging/ApplicationMessenger.h"
#if defined(TARGET_WINDOWS)
#include "platform/win32/WIN32Util.h"
#endif
#include "settings/AdvancedSettings.h"
#include "settings/SettingsComponent.h"
#include "utils/AlarmClock.h"
Expand Down Expand Up @@ -383,10 +380,8 @@ static int ToggleDirty(const std::vector<std::string>&)
*/
static int ToggleDisplayHDR(const std::vector<std::string>&)
{
#if defined(TARGET_WINDOWS)
CWIN32Util::ToggleWindowsHDR();
CServiceBroker::GetWinSystem()->ToggleDisplayHDR();
CApplicationMessenger::GetInstance().SendMsg(TMSG_RESTARTAPP);
#endif
return 0;
}

Expand Down
8 changes: 0 additions & 8 deletions xbmc/platform/win32/WIN32Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1377,11 +1377,3 @@ int CWIN32Util::GetHDRDisplayStatus()

return status;
}

bool CWIN32Util::IsDisplayHDREnabled()
{
if (GetHDRDisplayStatus() == 2)
return true;

return false;
}
2 changes: 0 additions & 2 deletions xbmc/platform/win32/WIN32Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ class CWIN32Util
static std::string WUSysMsg(DWORD dwError);
static bool SetThreadLocalLocale(bool enable = true);

// HDR display support
static void ToggleWindowsHDR();
static int GetHDRDisplayStatus();
static bool IsDisplayHDREnabled();
};
55 changes: 50 additions & 5 deletions xbmc/rendering/dx/DeviceResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "windowing/GraphicContext.h"
#include "messaging/ApplicationMessenger.h"
#include "platform/win32/CharsetConverter.h"
#include "platform/win32/WIN32Util.h"
#include "ServiceBroker.h"
#include "settings/AdvancedSettings.h"
#include "settings/SettingsComponent.h"
Expand Down Expand Up @@ -517,7 +516,7 @@ void DX::DeviceResources::ResizeBuffers()
bool bHWStereoEnabled = RENDER_STEREO_MODE_HARDWAREBASED ==
CServiceBroker::GetWinSystem()->GetGfxContext().GetStereoMode();
bool windowed = true;
bool isHdrEnabled = CWIN32Util::IsDisplayHDREnabled();
bool isHdrEnabled = false;
HRESULT hr = E_FAIL;
DXGI_SWAP_CHAIN_DESC1 scDesc = { 0 };

Expand All @@ -532,6 +531,7 @@ void DX::DeviceResources::ResizeBuffers()

// check if swapchain needs to be recreated
m_swapChain->GetDesc1(&scDesc);
isHdrEnabled = IsDisplayHDREnabled();

if ((scDesc.Stereo == TRUE) != bHWStereoEnabled || (m_Is10bSwapchain != isHdrEnabled))
{
Expand Down Expand Up @@ -630,13 +630,25 @@ void DX::DeviceResources::ResizeBuffers()

if (swapChainDesc.Format == DXGI_FORMAT_R10G10B10A2_UNORM)
{
std::string txOutput;
m_Is10bSwapchain = true;
CLog::LogF(LOGNOTICE, "10 bit swapchain is used.");
if (isHdrEnabled)
{
m_IsHDROutput = true;
txOutput = "HDR";
}
else
{
m_IsHDROutput = false;
txOutput = "SDR";
}
CLog::LogF(LOGNOTICE, "10 bit swapchain is used with {0:s} output", txOutput);
}
else
{
m_Is10bSwapchain = false;
CLog::LogF(LOGNOTICE, "8 bit swapchain is used.");
m_IsHDROutput = false;
CLog::LogF(LOGNOTICE, "8 bit swapchain is used with SDR output");
}

hr = swapChain.As(&m_swapChain); CHECK_ERR();
Expand All @@ -648,6 +660,8 @@ void DX::DeviceResources::ResizeBuffers()
hr = m_d3dDevice.As(&dxgiDevice); CHECK_ERR();
dxgiDevice->SetMaximumFrameLatency(1);
}

CLog::LogF(LOGDEBUG, "end resize buffers.");
}

// These resources need to be recreated every time the window size is changed.
Expand Down Expand Up @@ -1233,7 +1247,7 @@ void DX::DeviceResources::SetHdrMetaData(DXGI_HDR_METADATA_HDR10& hdr10) const
}
}

void DX::DeviceResources::SetColorSpace1(const DXGI_COLOR_SPACE_TYPE colorSpace) const
void DX::DeviceResources::SetHdrColorSpace(const DXGI_COLOR_SPACE_TYPE colorSpace) const
{
ComPtr<IDXGISwapChain3> swapChain3;

Expand Down Expand Up @@ -1268,3 +1282,34 @@ void DX::DeviceResources::SetColorSpace1(const DXGI_COLOR_SPACE_TYPE colorSpace)
}
}
}

bool DX::DeviceResources::IsDisplayHDREnabled() const
{
ComPtr<IDXGIOutput> pOutput;
ComPtr<IDXGIOutput6> pOutput6;
DXGI_OUTPUT_DESC1 od = {};

if (m_swapChain == nullptr)
return false;

if (SUCCEEDED(m_swapChain->GetContainingOutput(pOutput.GetAddressOf())))
{
if (SUCCEEDED(pOutput.As(&pOutput6)))
{
if (SUCCEEDED(pOutput6->GetDesc1(&od)))
{
CLog::LogF(LOGDEBUG, "DXGI GetDesc1 success");
if (od.ColorSpace == DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020)
{
return true;
}
}
else
{
CLog::LogF(LOGERROR, "DXGI GetDesc1 failed");
}
}
}

return false;
}
Loading

0 comments on commit 5fbc5b6

Please sign in to comment.