Skip to content

Commit

Permalink
[WinRenderer] Fix HQ scallers, to avoid unnecessary scaling at Stage1…
Browse files Browse the repository at this point in the history
… (with DXVA processor and color shader). This also fixes HQ scallers for TAB/SBS modes.
  • Loading branch information
Anton Fedchin committed Oct 23, 2015
1 parent 3caf72f commit 4b12412
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 53 deletions.
70 changes: 40 additions & 30 deletions xbmc/cores/VideoRenderers/VideoShaders/WinVideoFilter.cpp
Expand Up @@ -20,16 +20,17 @@

#ifdef HAS_DX

#include <DirectXPackedVector.h>
#include "WinVideoFilter.h"
#include "windowing/WindowingFactory.h"
#include "../../../utils/log.h"
#include "../../../FileSystem/File.h"
#include <map>
#include "ConvolutionKernels.h"
#include "YUV2RGBShader.h"
#include "win32/WIN32Util.h"
#include <DirectXPackedVector.h>
#include "FileSystem/File.h"
#include "guilib/GraphicContext.h"
#include "Util.h"
#include "utils/log.h"
#include "win32/WIN32Util.h"
#include "windowing/WindowingFactory.h"
#include "YUV2RGBShader.h"
#include <map>

using namespace DirectX::PackedVector;

Expand Down Expand Up @@ -844,48 +845,57 @@ void CConvolutionShaderSeparable::SetShaderParameters(CD3DTexture &sourceTexture

void CConvolutionShaderSeparable::SetStepParams(UINT iPass)
{
float viewPortWidth = 0.0f, viewPortHeight = 0.0f;
CD3D11_VIEWPORT viewPort(.0f, .0f, .0f, .0f);
ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context();

if (iPass == 0)
{
// store old RT
pContext->OMGetRenderTargets(1, &m_oldRenderTarget, nullptr);
viewPortWidth = (float)m_IntermediateTarget.GetWidth();
viewPortHeight = (float)m_IntermediateTarget.GetHeight();

// setting new RT
ID3D11RenderTargetView* newRT = m_IntermediateTarget.GetRenderTarget();
pContext->OMSetRenderTargets(1, &newRT, nullptr);
// new viewport
viewPort = CD3D11_VIEWPORT(0.0f, 0.0f,
static_cast<float>(m_IntermediateTarget.GetWidth()),
static_cast<float>(m_IntermediateTarget.GetHeight()));
// reset scissor
g_Windowing.ResetScissors();
}
else if (iPass == 1)
{
// get dimention of old render target
ID3D11Resource* rtResource = nullptr;
m_oldRenderTarget->GetResource(&rtResource);
ID3D11Texture2D* rtTexture = nullptr;
HRESULT hr = rtResource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&rtTexture));

if (S_OK == hr && rtTexture)
if (m_oldRenderTarget)
{
D3D11_TEXTURE2D_DESC rtDescr = {};
rtTexture->GetDesc(&rtDescr);
viewPortWidth = static_cast<float>(rtDescr.Width);
viewPortHeight = static_cast<float>(rtDescr.Height);
// get dimention of old render target
ID3D11Resource* rtResource = nullptr;
m_oldRenderTarget->GetResource(&rtResource);
ID3D11Texture2D* rtTexture = nullptr;
if (SUCCEEDED(rtResource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&rtTexture))))
{
D3D11_TEXTURE2D_DESC rtDescr = {};
rtTexture->GetDesc(&rtDescr);
viewPort = CD3D11_VIEWPORT(0.0f, 0.0f,
static_cast<float>(rtDescr.Width),
static_cast<float>(rtDescr.Height));
}
SAFE_RELEASE(rtTexture);
SAFE_RELEASE(rtResource);
}
else
{
// current RT is null so try to restore viewport
CRect winViewPort;
g_Windowing.GetViewPort(winViewPort);
viewPort = CD3D11_VIEWPORT(winViewPort.x1, winViewPort.y1, winViewPort.Width(), winViewPort.Height());
}

SAFE_RELEASE(rtTexture);
SAFE_RELEASE(rtResource);

pContext->OMSetRenderTargets(1, &m_oldRenderTarget, nullptr);
SAFE_RELEASE(m_oldRenderTarget);

// at the second pass m_IntermediateTarget is a source of data
m_effect.SetTexture("g_Texture", m_IntermediateTarget);
// restore scissor
g_Windowing.SetScissors(g_graphicsContext.StereoCorrection(g_graphicsContext.GetScissors()));
}

// setting view port to the full size of the current render target
CD3D11_VIEWPORT viewPort(0.0f, 0.0f, viewPortWidth, viewPortHeight);
// seting view port
pContext->RSSetViewports(1, &viewPort);
// pass viewport dimention to the shaders
m_effect.SetFloatArray("g_viewPort", &viewPort.Width, 2);
Expand Down
30 changes: 7 additions & 23 deletions xbmc/cores/VideoRenderers/WinRenderer.cpp
Expand Up @@ -815,7 +815,6 @@ void CWinRenderer::RenderPS()
void CWinRenderer::Stage1()
{
ID3D11DeviceContext* pContext = g_Windowing.Get3D11Context();
g_Windowing.ResetScissors();

// Store current render target and depth view.
ID3D11RenderTargetView *oldRT = nullptr; ID3D11DepthStencilView* oldDS = nullptr;
Expand Down Expand Up @@ -846,13 +845,11 @@ void CWinRenderer::Stage1()
// Switch the render target to the temporary destination
pContext->OMSetRenderTargets(1, &newRT, nullptr);

CRect srcRect(0.0f, 0.0f, static_cast<float>(m_sourceWidth), static_cast<float>(m_sourceHeight));

m_colorShader->Render(srcRect, srcRect,
CRect srcRect(0.0f, 0.0f, m_sourceRect.Width(), m_sourceRect.Height());
m_colorShader->Render(m_sourceRect, srcRect,
CMediaSettings::GetInstance().GetCurrentVideoSettings().m_Contrast,
CMediaSettings::GetInstance().GetCurrentVideoSettings().m_Brightness,
m_iFlags, (YUVBuffer*)m_VideoBuffers[m_iYV12RenderBuffer]);

// Restore our view port.
g_Windowing.RestoreViewPort();
}
Expand All @@ -865,22 +862,8 @@ void CWinRenderer::Stage1()

void CWinRenderer::Stage2()
{
g_Windowing.ResetScissors();

CRect sourceRect;

// fixup stereo+dxva+hq scaling issue
if (m_renderMethod == RENDER_DXVA)
{
sourceRect.y1 = 0.0f;
sourceRect.y2 = static_cast<float>(m_sourceHeight);
sourceRect.x1 = 0.0f;
sourceRect.x2 = static_cast<float>(m_sourceWidth);
}
else
sourceRect = m_sourceRect;

m_scalerShader->Render(m_IntermediateTarget, m_sourceWidth, m_sourceHeight, m_destWidth, m_destHeight, sourceRect, g_graphicsContext.StereoCorrection(m_destRect));
CRect srcRect(0.0f, 0.0f, m_sourceRect.Width(), m_sourceRect.Height());
m_scalerShader->Render(m_IntermediateTarget, m_sourceWidth, m_sourceHeight, m_destWidth, m_destHeight, srcRect, g_graphicsContext.StereoCorrection(m_destRect));
}

void CWinRenderer::RenderProcessor(DWORD flags)
Expand All @@ -890,10 +873,11 @@ void CWinRenderer::RenderProcessor(DWORD flags)

if (m_bUseHQScaler)
{
// no need to scale, so destination has same dimention (width/height) as source
destRect.y1 = 0.0f;
destRect.y2 = static_cast<float>(m_sourceHeight);
destRect.y2 = m_sourceRect.Height();
destRect.x1 = 0.0f;
destRect.x2 = static_cast<float>(m_sourceWidth);
destRect.x2 = m_sourceRect.Width();
}
else
destRect = g_graphicsContext.StereoCorrection(m_destRect);
Expand Down

0 comments on commit 4b12412

Please sign in to comment.