| 3101 | } |
| 3102 | |
| 3103 | HRESULT CDX11VideoProcessor::ResizeShaderPass(const Tex2D_t& Tex, ID3D11Texture2D* pRenderTarget, const CRect& srcRect, const CRect& dstRect, const int rotation) |
| 3104 | { |
| 3105 | HRESULT hr = S_OK; |
| 3106 | const int w2 = dstRect.Width(); |
| 3107 | const int h2 = dstRect.Height(); |
| 3108 | const int k = m_bInterpolateAt50pct ? 2 : 1; |
| 3109 | |
| 3110 | int w1, h1; |
| 3111 | ID3D11PixelShader* resizerX; |
| 3112 | ID3D11PixelShader* resizerY; |
| 3113 | if (rotation == 90 || rotation == 270) { |
| 3114 | w1 = srcRect.Height(); |
| 3115 | h1 = srcRect.Width(); |
| 3116 | resizerX = (w1 == w2) ? nullptr : (w1 > k * w2) ? m_pShaderDownscaleY.p : m_pShaderUpscaleY.p; // use Y scaling here |
| 3117 | if (resizerX) { |
| 3118 | resizerY = (h1 == h2) ? nullptr : (h1 > k * h2) ? m_pShaderDownscaleY.p : m_pShaderUpscaleY.p; |
| 3119 | } else { |
| 3120 | resizerY = (h1 == h2) ? nullptr : (h1 > k * h2) ? m_pShaderDownscaleX.p : m_pShaderUpscaleX.p; // use X scaling here |
| 3121 | } |
| 3122 | } else { |
| 3123 | w1 = srcRect.Width(); |
| 3124 | h1 = srcRect.Height(); |
| 3125 | resizerX = (w1 == w2) ? nullptr : (w1 > k * w2) ? m_pShaderDownscaleX.p : m_pShaderUpscaleX.p; |
| 3126 | resizerY = (h1 == h2) ? nullptr : (h1 > k * h2) ? m_pShaderDownscaleY.p : m_pShaderUpscaleY.p; |
| 3127 | } |
| 3128 | |
| 3129 | if (resizerX && resizerY) { |
| 3130 | // two pass resize |
| 3131 | |
| 3132 | D3D11_TEXTURE2D_DESC desc; |
| 3133 | pRenderTarget->GetDesc(&desc); |
| 3134 | |
| 3135 | if (resizerX == resizerY) { |
| 3136 | // one pass resize |
| 3137 | hr = TextureResizeShader(Tex, pRenderTarget, srcRect, dstRect, resizerX, rotation, m_bFlip); |
| 3138 | DLogIf(FAILED(hr), L"CDX11VideoProcessor::ResizeShaderPass() : failed with error {}", HR2Str(hr)); |
| 3139 | |
| 3140 | return hr; |
| 3141 | } |
| 3142 | |
| 3143 | // check intermediate texture |
| 3144 | const UINT texWidth = desc.Width; |
| 3145 | const UINT texHeight = h1; |
| 3146 | |
| 3147 | if (m_TexResize.pTexture) { |
| 3148 | if (texWidth != m_TexResize.desc.Width || texHeight != m_TexResize.desc.Height) { |
| 3149 | m_TexResize.Release(); // need new texture |
| 3150 | } |
| 3151 | } |
| 3152 | |
| 3153 | if (!m_TexResize.pTexture) { |
| 3154 | // use only float textures here |
| 3155 | hr = m_TexResize.Create(m_pDevice, DXGI_FORMAT_R16G16B16A16_FLOAT, texWidth, texHeight, Tex2D_DefaultShaderRTarget); |
| 3156 | if (FAILED(hr)) { |
| 3157 | DLog(L"CDX11VideoProcessor::ResizeShaderPass() : m_TexResize.Create() failed with error {}", HR2Str(hr)); |
| 3158 | return hr; |
| 3159 | } |
| 3160 | } |