Optimize blending in DXVA2 and D3D11VA renderers
This commit is contained in:
parent
c5b7a9c679
commit
c3ce0918b3
3 changed files with 32 additions and 6 deletions
|
|
@ -105,6 +105,9 @@ D3D11VARenderer::~D3D11VARenderer()
|
||||||
|
|
||||||
m_OverlayPixelShader.Reset();
|
m_OverlayPixelShader.Reset();
|
||||||
|
|
||||||
|
m_OverlayBlendState.Reset();
|
||||||
|
m_VideoBlendState.Reset();
|
||||||
|
|
||||||
m_RenderTargetView.Reset();
|
m_RenderTargetView.Reset();
|
||||||
m_SwapChain.Reset();
|
m_SwapChain.Reset();
|
||||||
|
|
||||||
|
|
@ -690,8 +693,10 @@ void D3D11VARenderer::renderOverlay(Overlay::OverlayType type)
|
||||||
m_DeviceContext->PSSetShader(m_OverlayPixelShader.Get(), nullptr, 0);
|
m_DeviceContext->PSSetShader(m_OverlayPixelShader.Get(), nullptr, 0);
|
||||||
m_DeviceContext->PSSetShaderResources(0, 1, overlayTextureResourceView.GetAddressOf());
|
m_DeviceContext->PSSetShaderResources(0, 1, overlayTextureResourceView.GetAddressOf());
|
||||||
|
|
||||||
// Draw the overlay
|
// Draw the overlay with alpha blending
|
||||||
|
m_DeviceContext->OMSetBlendState(m_OverlayBlendState.Get(), nullptr, 0xffffffff);
|
||||||
m_DeviceContext->DrawIndexed(6, 0, 0);
|
m_DeviceContext->DrawIndexed(6, 0, 0);
|
||||||
|
m_DeviceContext->OMSetBlendState(m_VideoBlendState.Get(), nullptr, 0xffffffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
void D3D11VARenderer::bindColorConversion(AVFrame* frame)
|
void D3D11VARenderer::bindColorConversion(AVFrame* frame)
|
||||||
|
|
@ -1379,7 +1384,7 @@ bool D3D11VARenderer::setupRenderingResources()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create our blend state
|
// Create our overlay blend state
|
||||||
{
|
{
|
||||||
D3D11_BLEND_DESC blendDesc = {};
|
D3D11_BLEND_DESC blendDesc = {};
|
||||||
blendDesc.AlphaToCoverageEnable = FALSE;
|
blendDesc.AlphaToCoverageEnable = FALSE;
|
||||||
|
|
@ -1393,10 +1398,26 @@ bool D3D11VARenderer::setupRenderingResources()
|
||||||
blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
|
blendDesc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD;
|
||||||
blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
||||||
|
|
||||||
ComPtr<ID3D11BlendState> blendState;
|
hr = m_Device->CreateBlendState(&blendDesc, &m_OverlayBlendState);
|
||||||
hr = m_Device->CreateBlendState(&blendDesc, &blendState);
|
if (FAILED(hr)) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
"ID3D11Device::CreateBlendState() failed: %x",
|
||||||
|
hr);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create and bind our video blend state
|
||||||
|
{
|
||||||
|
D3D11_BLEND_DESC blendDesc = {};
|
||||||
|
blendDesc.AlphaToCoverageEnable = FALSE;
|
||||||
|
blendDesc.IndependentBlendEnable = FALSE;
|
||||||
|
blendDesc.RenderTarget[0].BlendEnable = FALSE;
|
||||||
|
blendDesc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL;
|
||||||
|
|
||||||
|
hr = m_Device->CreateBlendState(&blendDesc, &m_VideoBlendState);
|
||||||
if (SUCCEEDED(hr)) {
|
if (SUCCEEDED(hr)) {
|
||||||
m_DeviceContext->OMSetBlendState(blendState.Get(), nullptr, 0xffffffff);
|
m_DeviceContext->OMSetBlendState(m_VideoBlendState.Get(), nullptr, 0xffffffff);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,9 @@ private:
|
||||||
Microsoft::WRL::ComPtr<IDXGISwapChain4> m_SwapChain;
|
Microsoft::WRL::ComPtr<IDXGISwapChain4> m_SwapChain;
|
||||||
Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_DeviceContext;
|
Microsoft::WRL::ComPtr<ID3D11DeviceContext1> m_DeviceContext;
|
||||||
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_RenderTargetView;
|
Microsoft::WRL::ComPtr<ID3D11RenderTargetView> m_RenderTargetView;
|
||||||
|
Microsoft::WRL::ComPtr<ID3D11BlendState> m_VideoBlendState;
|
||||||
|
Microsoft::WRL::ComPtr<ID3D11BlendState> m_OverlayBlendState;
|
||||||
|
|
||||||
SupportedFenceType m_FenceType;
|
SupportedFenceType m_FenceType;
|
||||||
SDL_mutex* m_ContextLock;
|
SDL_mutex* m_ContextLock;
|
||||||
bool m_BindDecoderOutputTextures;
|
bool m_BindDecoderOutputTextures;
|
||||||
|
|
|
||||||
|
|
@ -375,7 +375,6 @@ bool DXVA2Renderer::initializeRenderer()
|
||||||
m_Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
m_Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
|
||||||
m_Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
m_Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
|
||||||
|
|
||||||
m_Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
|
|
||||||
m_Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
m_Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
|
||||||
m_Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
m_Device->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
|
||||||
|
|
||||||
|
|
@ -951,7 +950,10 @@ void DXVA2Renderer::renderOverlay(Overlay::OverlayType type)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only enable blending when drawing the overlay
|
||||||
|
m_Device->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
|
||||||
hr = m_Device->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
|
hr = m_Device->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
|
||||||
|
m_Device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION,
|
||||||
"DrawPrimitive() failed: %x",
|
"DrawPrimitive() failed: %x",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue