| 2449 | } |
| 2450 | |
| 2451 | HRESULT CDX9VideoProcessor::ResizeShaderPass(IDirect3DTexture9* pTexture, IDirect3DSurface9* pRenderTarget, const CRect& srcRect, const CRect& dstRect) |
| 2452 | { |
| 2453 | HRESULT hr = S_OK; |
| 2454 | const int w2 = dstRect.Width(); |
| 2455 | const int h2 = dstRect.Height(); |
| 2456 | const int k = m_bInterpolateAt50pct ? 2 : 1; |
| 2457 | |
| 2458 | int w1, h1; |
| 2459 | IDirect3DPixelShader9* resizerX; |
| 2460 | IDirect3DPixelShader9* resizerY; |
| 2461 | if (m_iRotation == 90 || m_iRotation == 270) { |
| 2462 | w1 = srcRect.Height(); |
| 2463 | h1 = srcRect.Width(); |
| 2464 | resizerX = (w1 == w2) ? nullptr : (w1 > k * w2) ? m_pShaderDownscaleY.p : m_pShaderUpscaleY.p; // use Y scaling here |
| 2465 | if (resizerX) { |
| 2466 | resizerY = (h1 == h2) ? nullptr : (h1 > k * h2) ? m_pShaderDownscaleY.p : m_pShaderUpscaleY.p; |
| 2467 | } else { |
| 2468 | resizerY = (h1 == h2) ? nullptr : (h1 > k * h2) ? m_pShaderDownscaleX.p : m_pShaderUpscaleX.p; // use X scaling here |
| 2469 | } |
| 2470 | } else { |
| 2471 | w1 = srcRect.Width(); |
| 2472 | h1 = srcRect.Height(); |
| 2473 | resizerX = (w1 == w2) ? nullptr : (w1 > k * w2) ? m_pShaderDownscaleX.p : m_pShaderUpscaleX.p; |
| 2474 | resizerY = (h1 == h2) ? nullptr : (h1 > k * h2) ? m_pShaderDownscaleY.p : m_pShaderUpscaleY.p; |
| 2475 | } |
| 2476 | |
| 2477 | if (resizerX && resizerY) { |
| 2478 | // two pass resize |
| 2479 | |
| 2480 | D3DSURFACE_DESC desc; |
| 2481 | pRenderTarget->GetDesc(&desc); |
| 2482 | |
| 2483 | if (resizerX == resizerY) { |
| 2484 | // one pass resize |
| 2485 | hr = m_pD3DDevEx->SetRenderTarget(0, pRenderTarget); |
| 2486 | hr = TextureResizeShader(pTexture, srcRect, dstRect, resizerX, m_iRotation, m_bFlip); |
| 2487 | DLogIf(FAILED(hr), L"CDX9VideoProcessor::ResizeShaderPass() : failed with error {}", HR2Str(hr)); |
| 2488 | |
| 2489 | return hr; |
| 2490 | } |
| 2491 | |
| 2492 | // check intermediate texture |
| 2493 | const UINT texWidth = desc.Width; |
| 2494 | const UINT texHeight = h1; |
| 2495 | |
| 2496 | if (m_TexResize.pTexture) { |
| 2497 | if (texWidth != m_TexResize.Width || texHeight != m_TexResize.Height) { |
| 2498 | m_TexResize.Release(); // need new texture |
| 2499 | } |
| 2500 | } |
| 2501 | |
| 2502 | if (!m_TexResize.pTexture) { |
| 2503 | // use only float textures here |
| 2504 | hr = m_TexResize.Create(m_pD3DDevEx, D3DFMT_A16B16G16R16F,texWidth, texHeight, D3DUSAGE_RENDERTARGET); |
| 2505 | if (FAILED(hr)) { |
| 2506 | DLog(L"CDX9VideoProcessor::ProcessTex() : m_TexResize.Create() failed with error {}", HR2Str(hr)); |
| 2507 | return TextureCopyRect(pTexture, srcRect, dstRect, D3DTEXF_LINEAR, m_iRotation, m_bFlip); |
| 2508 | } |