From 30824d96741cf4557646f47193049439ad10f7df Mon Sep 17 00:00:00 2001 From: thexai <58434170+thexai@users.noreply.github.com> Date: Tue, 14 Jul 2020 19:00:05 +0200 Subject: [PATCH] Removed ALLOW_TEARING flag and disabled multi-thread protection when not needed. --- .../VideoPlayer/DVDCodecs/Video/DXVA.cpp | 18 +++++----- xbmc/rendering/dx/DeviceResources.cpp | 34 +++---------------- xbmc/rendering/dx/DeviceResources.h | 2 -- 3 files changed, 13 insertions(+), 41 deletions(-) diff --git a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp index 812d2f07abd63..acc1b37580c48 100644 --- a/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp +++ b/xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp @@ -306,15 +306,6 @@ bool CContext::CreateContext() featureLevels.size(), D3D11_SDK_VERSION, &pD3DDevice, nullptr, &pD3DDeviceContext); - if (SUCCEEDED(hr)) - { - // enable multi-threaded protection - ComPtr multithread; - hr = pD3DDevice.As(&multithread); - if (SUCCEEDED(hr)) - multithread->SetMultithreadProtected(1); - } - if (FAILED(hr)) { CLog::LogF(LOGWARNING, "unable to create device for decoding, fallback to using app device."); @@ -339,6 +330,15 @@ bool CContext::CreateContext() return false; } + if (FAILED(hr) || !m_sharingAllowed) + { + // enable multi-threaded protection only if is used same d3d11 device for rendering and decoding + ComPtr multithread; + hr = pD3DDevice.As(&multithread); + if (SUCCEEDED(hr)) + multithread->SetMultithreadProtected(1); + } + QueryCaps(); // Some older Ati devices can only open a single decoder at a given time diff --git a/xbmc/rendering/dx/DeviceResources.cpp b/xbmc/rendering/dx/DeviceResources.cpp index 02a5558708bd1..af71d03caa2a3 100644 --- a/xbmc/rendering/dx/DeviceResources.cpp +++ b/xbmc/rendering/dx/DeviceResources.cpp @@ -370,14 +370,8 @@ void DX::DeviceResources::CreateDeviceResources() // Store pointers to the Direct3D 11.1 API device and immediate context. hr = device.As(&m_d3dDevice); CHECK_ERR(); - // To enable multi-threaded access (optional) - ComPtr d3dMultiThread; - hr = m_d3dDevice.As(&d3dMultiThread); CHECK_ERR(); - d3dMultiThread->SetMultithreadProtected(1); - - // Check extended features support + // Check shared textures support CheckNV12SharedTexturesSupport(); - CheckTearingSupport(); #ifdef _DEBUG if (SUCCEEDED(m_d3dDevice.As(&m_d3dDebug))) @@ -566,12 +560,9 @@ void DX::DeviceResources::ResizeBuffers() m_swapChain->GetDesc1(&scDesc); isHdrEnabled ? scDesc.Format = DXGI_FORMAT_R10G10B10A2_UNORM : scDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; - - UINT flags = (windowed ? 0 : DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH) | - (m_allowTearing ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0); - hr = m_swapChain->ResizeBuffers(scDesc.BufferCount, lround(m_outputSize.Width), - lround(m_outputSize.Height), scDesc.Format, flags); + lround(m_outputSize.Height), scDesc.Format, + windowed ? 0 : DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH); if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) { @@ -598,10 +589,7 @@ void DX::DeviceResources::ResizeBuffers() swapChainDesc.SwapEffect = (m_d3dFeatureLevel >= D3D_FEATURE_LEVEL_12_0) ? DXGI_SWAP_EFFECT_FLIP_DISCARD : DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; - - swapChainDesc.Flags = (windowed ? 0 : DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH) | - (m_allowTearing ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0); - + swapChainDesc.Flags = windowed ? 0 : DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_IGNORE; swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Quality = 0; @@ -1066,20 +1054,6 @@ void DX::DeviceResources::CheckNV12SharedTexturesSupport() !!m_NV12SharedTexturesSupport ? " " : " NOT "); } -void DX::DeviceResources::CheckTearingSupport() -{ - if (m_d3dFeatureLevel < D3D_FEATURE_LEVEL_11_1) - return; - - ComPtr factory; - HRESULT hr = CreateDXGIFactory1(IID_PPV_ARGS(&factory)); - BOOL flag = {}; - if (SUCCEEDED(hr)) - hr = factory->CheckFeatureSupport(DXGI_FEATURE_PRESENT_ALLOW_TEARING, &flag, sizeof(flag)); - m_allowTearing = SUCCEEDED(hr) && !!flag; - CLog::LogF(LOGINFO, "feature allow tearing is{}supported", !!m_allowTearing ? " " : " NOT "); -} - #if defined(TARGET_WINDOWS_DESKTOP) // This method is called when the window (WND) is created (or re-created). void DX::DeviceResources::SetWindow(HWND window) diff --git a/xbmc/rendering/dx/DeviceResources.h b/xbmc/rendering/dx/DeviceResources.h index 146d5ba6322b1..1a973badec476 100644 --- a/xbmc/rendering/dx/DeviceResources.h +++ b/xbmc/rendering/dx/DeviceResources.h @@ -126,7 +126,6 @@ namespace DX void OnDeviceRestored(); void HandleOutputChange(const std::function& cmpFunc); bool CreateFactory(); - void CheckTearingSupport(); void CheckNV12SharedTexturesSupport(); HWND m_window{ nullptr }; @@ -168,7 +167,6 @@ namespace DX bool m_stereoEnabled; bool m_bDeviceCreated; bool m_IsHDROutput; - bool m_allowTearing{false}; bool m_NV12SharedTexturesSupport{false}; }; }