From 76f9b7eaced6850152d0a7a1ac5ee7902533bf45 Mon Sep 17 00:00:00 2001 From: KOPRajs Date: Tue, 14 May 2024 12:00:24 +0200 Subject: [PATCH] Set correct destination rectangle size for the last pass --- .../cores/RetroPlayer/shaders/gl/ShaderGL.cpp | 20 +++++++++---------- xbmc/cores/RetroPlayer/shaders/gl/ShaderGL.h | 5 ++++- .../RetroPlayer/shaders/gl/ShaderPresetGL.cpp | 4 ++-- .../RetroPlayer/shaders/windows/ShaderDX.cpp | 17 ++++++++-------- .../RetroPlayer/shaders/windows/ShaderDX.h | 5 ++++- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/xbmc/cores/RetroPlayer/shaders/gl/ShaderGL.cpp b/xbmc/cores/RetroPlayer/shaders/gl/ShaderGL.cpp index 153d336ed84d0..76926f33da9af 100644 --- a/xbmc/cores/RetroPlayer/shaders/gl/ShaderGL.cpp +++ b/xbmc/cores/RetroPlayer/shaders/gl/ShaderGL.cpp @@ -153,10 +153,8 @@ void CShaderGL::SetShaderParameters() } } -void CShaderGL::PrepareParameters(CPoint* dest, bool isLastPass, uint64_t frameCount) +void CShaderGL::PrepareParameters(CPoint dest[4], bool isLastPass, uint64_t frameCount) { - UpdateInputBuffer(frameCount); - if (!isLastPass) { // bottom left x,y @@ -171,6 +169,9 @@ void CShaderGL::PrepareParameters(CPoint* dest, bool isLastPass, uint64_t frameC // top left x,y m_VertexCoords[3][0] = -m_outputSize.x / 2; m_VertexCoords[3][1] = m_outputSize.y / 2; + + // Set destination rectangle size + m_destSize = m_outputSize; } else // last pass { @@ -186,6 +187,9 @@ void CShaderGL::PrepareParameters(CPoint* dest, bool isLastPass, uint64_t frameC // top left x,y m_VertexCoords[3][0] = dest[0].x - m_outputSize.x / 2; m_VertexCoords[3][1] = dest[0].y - m_outputSize.y / 2; + + // Set destination rectangle size for the last pass + m_destSize = {dest[2].x - dest[0].x, dest[2].y - dest[0].y}; } // bottom left z, tu, tv, r, g, b @@ -195,7 +199,6 @@ void CShaderGL::PrepareParameters(CPoint* dest, bool isLastPass, uint64_t frameC m_colors[0][0] = 0.0f; m_colors[0][1] = 0.0f; m_colors[0][2] = 0.0f; - // bottom right z, tu, tv, r, g, b m_VertexCoords[1][2] = 0; m_TexCoords[1][0] = 1.0f; @@ -203,7 +206,6 @@ void CShaderGL::PrepareParameters(CPoint* dest, bool isLastPass, uint64_t frameC m_colors[1][0] = 0.0f; m_colors[1][1] = 0.0f; m_colors[1][2] = 0.0f; - // top right z, tu, tv, r, g, b m_VertexCoords[2][2] = 0; m_TexCoords[2][0] = 1.0f; @@ -211,7 +213,6 @@ void CShaderGL::PrepareParameters(CPoint* dest, bool isLastPass, uint64_t frameC m_colors[2][0] = 0.0f; m_colors[2][1] = 0.0f; m_colors[2][2] = 0.0f; - // top left z, tu, tv, r, g, b m_VertexCoords[3][2] = 0; m_TexCoords[3][0] = 0.0f; @@ -226,6 +227,8 @@ void CShaderGL::PrepareParameters(CPoint* dest, bool isLastPass, uint64_t frameC m_indices[1][0] = 1; m_indices[1][1] = 2; m_indices[1][2] = 3; + + UpdateInputBuffer(frameCount); } void CShaderGL::UpdateMVP() @@ -273,12 +276,9 @@ CShaderGL::uniformInputs CShaderGL::GetInputData(uint64_t frameCount) frameCount %= m_frameCountMod; uniformInputs input = { - // Resolution of texture passed to the shader {m_inputSize}, // video_size {m_inputTextureSize}, // texture_size - // As per the spec, this is the viewport resolution (not the - // output res of each shader) - {m_viewportSize}, // output_size + {m_destSize}, // output_size // Current frame count that can be modulo'ed static_cast(frameCount), // frame_count // Time always flows forward diff --git a/xbmc/cores/RetroPlayer/shaders/gl/ShaderGL.h b/xbmc/cores/RetroPlayer/shaders/gl/ShaderGL.h index 447a93bdf65b2..b175023f155de 100644 --- a/xbmc/cores/RetroPlayer/shaders/gl/ShaderGL.h +++ b/xbmc/cores/RetroPlayer/shaders/gl/ShaderGL.h @@ -83,9 +83,12 @@ class CShaderGL : public IShader // Resolution of the texture that holds the input float2 m_inputTextureSize; - // Resolution of the output of the shader + // Resolution of the output viewport of the shader float2 m_outputSize; + // Resolution of the destination rectangle of the shader + float2 m_destSize; + // Resolution of the viewport/window float2 m_viewportSize; diff --git a/xbmc/cores/RetroPlayer/shaders/gl/ShaderPresetGL.cpp b/xbmc/cores/RetroPlayer/shaders/gl/ShaderPresetGL.cpp index 77e19f4aa6f6b..02d14845d19ba 100644 --- a/xbmc/cores/RetroPlayer/shaders/gl/ShaderPresetGL.cpp +++ b/xbmc/cores/RetroPlayer/shaders/gl/ShaderPresetGL.cpp @@ -330,7 +330,7 @@ bool CShaderPresetGL::CreateShaderTextures() prevTextureSize = textureSize; } - // The last shader pass is supposed to output at full (viewport) resolution + // The last shader pass is supposed to output at full resolution m_pShaders[numPasses - 1]->SetSizes(prevSize, prevTextureSize, m_outputSize); // Update MVPs @@ -416,7 +416,7 @@ void CShaderPresetGL::DisposeShaders() m_bPresetNeedsUpdate = true; } -void CShaderPresetGL::PrepareParameters(const IShaderTexture* texture, const CPoint* dest) +void CShaderPresetGL::PrepareParameters(const IShaderTexture* texture, const CPoint dest[]) { if (m_dest[0] != dest[0] || m_dest[1] != dest[1] || m_dest[2] != dest[2] || m_dest[3] != dest[3] || texture->GetWidth() != m_outputSize.x || diff --git a/xbmc/cores/RetroPlayer/shaders/windows/ShaderDX.cpp b/xbmc/cores/RetroPlayer/shaders/windows/ShaderDX.cpp index 1f9864ffa56ec..7ffb323964867 100644 --- a/xbmc/cores/RetroPlayer/shaders/windows/ShaderDX.cpp +++ b/xbmc/cores/RetroPlayer/shaders/windows/ShaderDX.cpp @@ -111,8 +111,6 @@ void CShaderDX::SetShaderParameters(CD3DTexture& sourceTexture) void CShaderDX::PrepareParameters(CPoint dest[4], bool isLastPass, uint64_t frameCount) { - UpdateInputBuffer(frameCount); - CUSTOMVERTEX* v; LockVertexBuffer(reinterpret_cast(&v)); @@ -130,6 +128,9 @@ void CShaderDX::PrepareParameters(CPoint dest[4], bool isLastPass, uint64_t fram // bottom left v[3].x = -m_outputSize.x / 2; v[3].y = m_outputSize.y / 2; + + // Set destination rectangle size + m_destSize = m_outputSize; } else // last pass { @@ -145,6 +146,9 @@ void CShaderDX::PrepareParameters(CPoint dest[4], bool isLastPass, uint64_t fram // bottom left v[3].x = dest[3].x - m_outputSize.x / 2; v[3].y = dest[3].y - m_outputSize.y / 2; + + // Set destination rectangle size for the last pass + m_destSize = {dest[2].x - dest[0].x, dest[2].y - dest[0].y}; } // top left @@ -165,6 +169,8 @@ void CShaderDX::PrepareParameters(CPoint dest[4], bool isLastPass, uint64_t fram v[3].tv = 1; UnlockVertexBuffer(); + + UpdateInputBuffer(frameCount); } bool CShaderDX::CreateVertexBuffer(unsigned vertCount, unsigned vertSize) @@ -235,14 +241,9 @@ CShaderDX::cbInput CShaderDX::GetInputData(uint64_t frameCount) frameCount %= m_frameCountMod; cbInput input = { - // Resution of texture passed to the shader {m_inputSize.ToDXVector()}, // video_size - // Shaders don't (and shouldn't) know about _actual_ texture - // size, because D3D gives them correct texture coordinates {m_inputTextureSize.ToDXVector()}, // texture_size - // As per the spec, this is the viewport resolution (not the - // output res of each shader - {m_viewportSize.ToDXVector()}, // output_size + {m_destSize.ToDXVector()}, // output_size // Current frame count that can be modulo'ed {static_cast(frameCount)}, // frame_count // Time always flows forward diff --git a/xbmc/cores/RetroPlayer/shaders/windows/ShaderDX.h b/xbmc/cores/RetroPlayer/shaders/windows/ShaderDX.h index 85828d2f810f3..e6731305a2d1a 100644 --- a/xbmc/cores/RetroPlayer/shaders/windows/ShaderDX.h +++ b/xbmc/cores/RetroPlayer/shaders/windows/ShaderDX.h @@ -95,9 +95,12 @@ class CShaderDX : public CWinShader, public IShader // Resolution of the texture that holds the input float2 m_inputTextureSize; - // Resolution of the output of the shader + // Resolution of the output viewport of the shader float2 m_outputSize; + // Resolution of the destination rectangle of the shader + float2 m_destSize; + // Resolution of the viewport/window float2 m_viewportSize;