Skip to content

Commit

Permalink
Set correct destination rectangle size for the last pass
Browse files Browse the repository at this point in the history
  • Loading branch information
KOPRajs authored and garbear committed May 28, 2024
1 parent 6aa1722 commit 76f9b7e
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
20 changes: 10 additions & 10 deletions xbmc/cores/RetroPlayer/shaders/gl/ShaderGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
{
Expand All @@ -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
Expand All @@ -195,23 +199,20 @@ 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;
m_TexCoords[1][1] = 1.0f;
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;
m_TexCoords[2][1] = 0.0f;
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;
Expand All @@ -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()
Expand Down Expand Up @@ -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<GLint>(frameCount), // frame_count
// Time always flows forward
Expand Down
5 changes: 4 additions & 1 deletion xbmc/cores/RetroPlayer/shaders/gl/ShaderGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions xbmc/cores/RetroPlayer/shaders/gl/ShaderPresetGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ||
Expand Down
17 changes: 9 additions & 8 deletions xbmc/cores/RetroPlayer/shaders/windows/ShaderDX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void**>(&v));

Expand All @@ -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
{
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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<float>(frameCount)}, // frame_count
// Time always flows forward
Expand Down
5 changes: 4 additions & 1 deletion xbmc/cores/RetroPlayer/shaders/windows/ShaderDX.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 76f9b7e

Please sign in to comment.