Skip to content
This repository
Browse code

[win32][added] Shader based HQ scalers for DXVA renderer

  • Loading branch information...
commit 3c31288b4708db2a2c9cc2dbd2b58de30f41290d 1 parent 276abf9
a11599 authored September 01, 2013
60  xbmc/cores/VideoRenderers/WinRenderer.cpp
@@ -445,7 +445,8 @@ bool CWinRenderer::CreateIntermediateRenderTarget()
445 445
   D3DFORMAT format = D3DFMT_X8R8G8B8;
446 446
   DWORD usage = D3DUSAGE_RENDERTARGET;
447 447
 
448  
-  if      (g_Windowing.IsTextureFormatOk(D3DFMT_A2R10G10B10, usage)) format = D3DFMT_A2R10G10B10;
  448
+  if      (m_renderMethod == RENDER_DXVA)                            format = D3DFMT_X8R8G8B8;
  449
+  else if (g_Windowing.IsTextureFormatOk(D3DFMT_A2R10G10B10, usage)) format = D3DFMT_A2R10G10B10;
449 450
   else if (g_Windowing.IsTextureFormatOk(D3DFMT_A2B10G10R10, usage)) format = D3DFMT_A2B10G10R10;
450 451
   else if (g_Windowing.IsTextureFormatOk(D3DFMT_A8R8G8B8, usage))    format = D3DFMT_A8R8G8B8;
451 452
   else if (g_Windowing.IsTextureFormatOk(D3DFMT_A8B8G8R8, usage))    format = D3DFMT_A8B8G8R8;
@@ -525,7 +526,12 @@ void CWinRenderer::SelectPSVideoFilter()
525 526
     bool scaleUp = (int)m_sourceHeight < g_graphicsContext.GetHeight() && (int)m_sourceWidth < g_graphicsContext.GetWidth();
526 527
     bool scaleFps = m_fps < (g_advancedSettings.m_videoAutoScaleMaxFps + 0.01f);
527 528
 
528  
-    if (scaleSD && scaleUp && scaleFps && Supports(VS_SCALINGMETHOD_LANCZOS3_FAST))
  529
+    if (m_renderMethod == RENDER_DXVA)
  530
+    {
  531
+      m_scalingMethod = VS_SCALINGMETHOD_DXVA_HARDWARE;
  532
+      m_bUseHQScaler = false;
  533
+    }
  534
+    else if (scaleSD && scaleUp && scaleFps && Supports(VS_SCALINGMETHOD_LANCZOS3_FAST))
529 535
     {
530 536
       m_scalingMethod = VS_SCALINGMETHOD_LANCZOS3_FAST;
531 537
       m_bUseHQScaler = true;
@@ -573,6 +579,10 @@ void CWinRenderer::UpdatePSVideoFilter()
573 579
 
574 580
   SAFE_DELETE(m_colorShader);
575 581
 
  582
+  // When using DXVA, we are already setup at this point, color shader is not needed
  583
+  if (m_renderMethod == RENDER_DXVA)
  584
+    return;
  585
+
576 586
   if (m_bUseHQScaler)
577 587
   {
578 588
     m_colorShader = new CYUV2RGBShader();
@@ -618,14 +628,11 @@ void CWinRenderer::UpdateVideoFilter()
618 628
     break;
619 629
 
620 630
   case RENDER_PS:
  631
+  case RENDER_DXVA:
621 632
     SelectPSVideoFilter();
622 633
     UpdatePSVideoFilter();
623 634
     break;
624 635
 
625  
-  case RENDER_DXVA:
626  
-    // Everything already setup, nothing to do.
627  
-    break;
628  
-
629 636
   default:
630 637
     return;
631 638
   }
@@ -635,6 +642,9 @@ void CWinRenderer::Render(DWORD flags)
635 642
 {
636 643
   if (m_renderMethod == RENDER_DXVA)
637 644
   {
  645
+    UpdateVideoFilter();
  646
+    if (m_bUseHQScaler)
  647
+      g_Windowing.FlushGPU();
638 648
     CWinRenderer::RenderProcessor(flags);
639 649
     return;
640 650
   }
@@ -918,19 +928,38 @@ void CWinRenderer::RenderProcessor(DWORD flags)
918 928
 {
919 929
   CSingleLock lock(g_graphicsContext);
920 930
   HRESULT hr;
  931
+  CRect destRect;
  932
+
  933
+  if (m_bUseHQScaler)
  934
+  {
  935
+    destRect.y1 = 0.0f;
  936
+    destRect.y2 = m_sourceHeight;
  937
+    destRect.x1 = 0.0f;
  938
+    destRect.x2 = m_sourceWidth;
  939
+  }
  940
+  else
  941
+    destRect = m_destRect;
921 942
 
922 943
   DXVABuffer *image = (DXVABuffer*)m_VideoBuffers[m_iYV12RenderBuffer];
923 944
 
924 945
   IDirect3DSurface9* target;
925  
-  if(FAILED(hr = g_Windowing.Get3DDevice()->GetRenderTarget(0, &target)))
  946
+  if (m_bUseHQScaler)
  947
+    m_IntermediateTarget.GetSurfaceLevel(0, &target);
  948
+  else
926 949
   {
927  
-    CLog::Log(LOGERROR, "CWinRenderer::RenderSurface - failed to get render target. %s", CRenderSystemDX::GetErrorDescription(hr).c_str());
928  
-    return;
  950
+    if(FAILED(hr = g_Windowing.Get3DDevice()->GetRenderTarget(0, &target)))
  951
+    {
  952
+      CLog::Log(LOGERROR, "CWinRenderer::RenderSurface - failed to get render target. %s", CRenderSystemDX::GetErrorDescription(hr).c_str());
  953
+      return;
  954
+    }
929 955
   }
930 956
 
931  
-  m_processor.Render(m_sourceRect, g_graphicsContext.StereoCorrection(m_destRect), target, image->id, flags);
  957
+  m_processor.Render(m_sourceRect, g_graphicsContext.StereoCorrection(destRect), target, image->id, flags);
932 958
 
933 959
   target->Release();
  960
+
  961
+  if (m_bUseHQScaler)
  962
+    Stage2();
934 963
 }
935 964
 
936 965
 bool CWinRenderer::RenderCapture(CRenderCapture* capture)
@@ -1068,17 +1097,14 @@ bool CWinRenderer::Supports(ERENDERFEATURE feature)
1068 1097
 
1069 1098
 bool CWinRenderer::Supports(ESCALINGMETHOD method)
1070 1099
 {
1071  
-  if (m_renderMethod == RENDER_DXVA)
  1100
+  if (m_renderMethod == RENDER_PS || m_renderMethod == RENDER_DXVA)
1072 1101
   {
1073  
-    if(method == VS_SCALINGMETHOD_DXVA_HARDWARE)
  1102
+    if(m_renderMethod == RENDER_DXVA && method == VS_SCALINGMETHOD_DXVA_HARDWARE)
1074 1103
       return true;
1075  
-    return false;
1076  
-  }
1077  
-  else if(m_renderMethod == RENDER_PS)
1078  
-  {
  1104
+
1079 1105
     if(m_deviceCaps.PixelShaderVersion >= D3DPS_VERSION(2, 0)
1080 1106
     && (   method == VS_SCALINGMETHOD_AUTO
1081  
-        || method == VS_SCALINGMETHOD_LINEAR))
  1107
+       || (method == VS_SCALINGMETHOD_LINEAR && m_renderMethod == RENDER_PS) ))
1082 1108
         return true;
1083 1109
 
1084 1110
     if(m_deviceCaps.PixelShaderVersion >= D3DPS_VERSION(3, 0))
12  xbmc/rendering/dx/RenderSystemDX.cpp
@@ -1043,5 +1043,17 @@ bool CRenderSystemDX::SupportsStereo(RENDER_STEREO_MODE mode) const
1043 1043
   }
1044 1044
 }
1045 1045
 
  1046
+void CRenderSystemDX::FlushGPU()
  1047
+{
  1048
+  IDirect3DQuery9* pEvent = NULL;
  1049
+
  1050
+  m_pD3DDevice->CreateQuery(D3DQUERYTYPE_EVENT, &pEvent);
  1051
+  if (pEvent != NULL)
  1052
+  {
  1053
+    pEvent->Issue(D3DISSUE_END);
  1054
+    while (S_FALSE == pEvent->GetData(NULL, 0, D3DGETDATA_FLUSH))
  1055
+      Sleep(1);
  1056
+  }
  1057
+}
1046 1058
 
1047 1059
 #endif
2  xbmc/rendering/dx/RenderSystemDX.h
@@ -78,6 +78,8 @@ class CRenderSystemDX : public CRenderSystemBase
78 78
 
79 79
   virtual void Project(float &x, float &y, float &z);
80 80
 
  81
+  void FlushGPU();
  82
+
81 83
   LPDIRECT3DDEVICE9 Get3DDevice() { return m_pD3DDevice; }
82 84
   int GetBackbufferCount() const { return m_D3DPP.BackBufferCount; }
83 85
 

0 notes on commit 3c31288

Please sign in to comment.
Something went wrong with that request. Please try again.