Skip to content

Commit

Permalink
Removed ALLOW_TEARING flag and disabled multi-thread protection when …
Browse files Browse the repository at this point in the history
…not needed.
  • Loading branch information
thexai committed Jul 14, 2020
1 parent 0844dc8 commit 30824d9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 41 deletions.
18 changes: 9 additions & 9 deletions xbmc/cores/VideoPlayer/DVDCodecs/Video/DXVA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,6 @@ bool CContext::CreateContext()
featureLevels.size(), D3D11_SDK_VERSION, &pD3DDevice, nullptr,
&pD3DDeviceContext);

if (SUCCEEDED(hr))
{
// enable multi-threaded protection
ComPtr<ID3D11Multithread> 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.");
Expand All @@ -339,6 +330,15 @@ bool CContext::CreateContext()
return false;
}

if (FAILED(hr) || !m_sharingAllowed)

This comment has been minimized.

Copy link
@afedchin

afedchin Jul 15, 2020

please check that video bookmarks and taking screenshot work well without protection. I'm not sure that we can safety disable protection.

This comment has been minimized.

Copy link
@thexai

thexai Jul 15, 2020

Author Owner

Quick test now bookmarks and screenshot and no issues. I will be pending in case it fails in other systems.

{
// enable multi-threaded protection only if is used same d3d11 device for rendering and decoding
ComPtr<ID3D11Multithread> 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
Expand Down
34 changes: 4 additions & 30 deletions xbmc/rendering/dx/DeviceResources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ID3D11Multithread> 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)))
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down Expand Up @@ -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<IDXGIFactory5> 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)
Expand Down
2 changes: 0 additions & 2 deletions xbmc/rendering/dx/DeviceResources.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ namespace DX
void OnDeviceRestored();
void HandleOutputChange(const std::function<bool(DXGI_OUTPUT_DESC)>& cmpFunc);
bool CreateFactory();
void CheckTearingSupport();
void CheckNV12SharedTexturesSupport();

HWND m_window{ nullptr };
Expand Down Expand Up @@ -168,7 +167,6 @@ namespace DX
bool m_stereoEnabled;
bool m_bDeviceCreated;
bool m_IsHDROutput;
bool m_allowTearing{false};
bool m_NV12SharedTexturesSupport{false};
};
}

0 comments on commit 30824d9

Please sign in to comment.