Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9736 from Techjar/bbox-pixel-quads
VideoCommon: Account for pixel quads in bounding box calculation
  • Loading branch information
lioncash committed May 22, 2021
2 parents 031bef0 + be6b000 commit 77e5d79
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/D3D/D3DRender.cpp
Expand Up @@ -264,12 +264,12 @@ void Renderer::UnbindTexture(const AbstractTexture* texture)
D3D::stateman->ApplyTextures();
}

u16 Renderer::BBoxRead(int index)
u16 Renderer::BBoxReadImpl(int index)
{
return static_cast<u16>(BBox::Get(index));
}

void Renderer::BBoxWrite(int index, u16 value)
void Renderer::BBoxWriteImpl(int index, u16 value)
{
BBox::Set(index, value);
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/D3D/D3DRender.h
Expand Up @@ -61,8 +61,8 @@ class Renderer : public ::Renderer
void SetFullscreen(bool enable_fullscreen) override;
bool IsFullscreen() const override;

u16 BBoxRead(int index) override;
void BBoxWrite(int index, u16 value) override;
u16 BBoxReadImpl(int index) override;
void BBoxWriteImpl(int index, u16 value) override;

void Flush() override;
void WaitForGPUIdle() override;
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/VideoBackends/D3D12/D3D12Renderer.cpp
Expand Up @@ -106,17 +106,17 @@ std::unique_ptr<AbstractPipeline> Renderer::CreatePipeline(const AbstractPipelin
return DXPipeline::Create(config, cache_data, cache_data_length);
}

u16 Renderer::BBoxRead(int index)
u16 Renderer::BBoxReadImpl(int index)
{
return static_cast<u16>(m_bounding_box->Get(index));
}

void Renderer::BBoxWrite(int index, u16 value)
void Renderer::BBoxWriteImpl(int index, u16 value)
{
m_bounding_box->Set(index, value);
}

void Renderer::BBoxFlush()
void Renderer::BBoxFlushImpl()
{
m_bounding_box->Flush();
m_bounding_box->Invalidate();
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/VideoBackends/D3D12/D3D12Renderer.h
Expand Up @@ -47,9 +47,9 @@ class Renderer final : public ::Renderer
const void* cache_data = nullptr,
size_t cache_data_length = 0) override;

u16 BBoxRead(int index) override;
void BBoxWrite(int index, u16 value) override;
void BBoxFlush() override;
u16 BBoxReadImpl(int index) override;
void BBoxWriteImpl(int index, u16 value) override;
void BBoxFlushImpl() override;

void Flush() override;
void WaitForGPUIdle() override;
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/Null/NullRender.h
Expand Up @@ -34,8 +34,8 @@ class Renderer final : public ::Renderer

u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override { return 0; }
void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override {}
u16 BBoxRead(int index) override { return 0; }
void BBoxWrite(int index, u16 value) override {}
u16 BBoxReadImpl(int index) override { return 0; }
void BBoxWriteImpl(int index, u16 value) override {}

void ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable, bool alphaEnable,
bool zEnable, u32 color, u32 z) override
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/OGL/OGLRender.cpp
Expand Up @@ -854,7 +854,7 @@ void Renderer::SetScissorRect(const MathUtil::Rectangle<int>& rc)
glScissor(rc.left, rc.top, rc.GetWidth(), rc.GetHeight());
}

u16 Renderer::BBoxRead(int index)
u16 Renderer::BBoxReadImpl(int index)
{
// swap 2 and 3 for top/bottom
if (index >= 2)
Expand All @@ -870,7 +870,7 @@ u16 Renderer::BBoxRead(int index)
return static_cast<u16>(value);
}

void Renderer::BBoxWrite(int index, u16 value)
void Renderer::BBoxWriteImpl(int index, u16 value)
{
s32 swapped_value = value;
if (index >= 2)
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/OGL/OGLRender.h
Expand Up @@ -126,8 +126,8 @@ class Renderer : public ::Renderer
void BindBackbuffer(const ClearColor& clear_color = {}) override;
void PresentBackbuffer() override;

u16 BBoxRead(int index) override;
void BBoxWrite(int index, u16 value) override;
u16 BBoxReadImpl(int index) override;
void BBoxWriteImpl(int index, u16 value) override;

void BeginUtilityDrawing() override;
void EndUtilityDrawing() override;
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/Software/SWRenderer.cpp
Expand Up @@ -126,12 +126,12 @@ u32 SWRenderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
return value;
}

u16 SWRenderer::BBoxRead(int index)
u16 SWRenderer::BBoxReadImpl(int index)
{
return BoundingBox::GetCoordinate(static_cast<BoundingBox::Coordinate>(index));
}

void SWRenderer::BBoxWrite(int index, u16 value)
void SWRenderer::BBoxWriteImpl(int index, u16 value)
{
BoundingBox::SetCoordinate(static_cast<BoundingBox::Coordinate>(index), value);
}
Expand Down
4 changes: 2 additions & 2 deletions Source/Core/VideoBackends/Software/SWRenderer.h
Expand Up @@ -39,8 +39,8 @@ class SWRenderer final : public Renderer

u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override;
void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override {}
u16 BBoxRead(int index) override;
void BBoxWrite(int index, u16 value) override;
u16 BBoxReadImpl(int index) override;
void BBoxWriteImpl(int index, u16 value) override;

void RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc,
const AbstractTexture* source_texture,
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/VideoBackends/Vulkan/VKRenderer.cpp
Expand Up @@ -131,17 +131,17 @@ void Renderer::SetPipeline(const AbstractPipeline* pipeline)
StateTracker::GetInstance()->SetPipeline(static_cast<const VKPipeline*>(pipeline));
}

u16 Renderer::BBoxRead(int index)
u16 Renderer::BBoxReadImpl(int index)
{
return static_cast<u16>(m_bounding_box->Get(index));
}

void Renderer::BBoxWrite(int index, u16 value)
void Renderer::BBoxWriteImpl(int index, u16 value)
{
m_bounding_box->Set(index, value);
}

void Renderer::BBoxFlush()
void Renderer::BBoxFlushImpl()
{
m_bounding_box->Flush();
m_bounding_box->Invalidate();
Expand Down
6 changes: 3 additions & 3 deletions Source/Core/VideoBackends/Vulkan/VKRenderer.h
Expand Up @@ -54,9 +54,9 @@ class Renderer : public ::Renderer

SwapChain* GetSwapChain() const { return m_swap_chain.get(); }
BoundingBox* GetBoundingBox() const { return m_bounding_box.get(); }
u16 BBoxRead(int index) override;
void BBoxWrite(int index, u16 value) override;
void BBoxFlush() override;
u16 BBoxReadImpl(int index) override;
void BBoxWriteImpl(int index, u16 value) override;
void BBoxFlushImpl() override;

void Flush() override;
void WaitForGPUIdle() override;
Expand Down
26 changes: 26 additions & 0 deletions Source/Core/VideoCommon/RenderBase.cpp
Expand Up @@ -185,6 +185,32 @@ void Renderer::ReinterpretPixelData(EFBReinterpretType convtype)
g_framebuffer_manager->ReinterpretPixelData(convtype);
}

u16 Renderer::BBoxRead(int index)
{
u16 value = BBoxReadImpl(index);

// The GC/Wii GPU rasterizes in 2x2 pixel groups, so bounding box values will be rounded to the
// extents of these groups, rather than the exact pixel.
// This would have been handled in the pixel shader, but all attempts to do so did not work on
// OpenGL/NVIDIA, due to presumably mystical driver behavior with atomics.
if (index == 0 || index == 2)
value &= ~1;
else
value |= 1;

return value;
}

void Renderer::BBoxWrite(int index, u16 value)
{
BBoxWriteImpl(index, value);
}

void Renderer::BBoxFlush()
{
BBoxFlushImpl();
}

u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
{
if (type == EFBAccessType::PeekColor)
Expand Down
10 changes: 7 additions & 3 deletions Source/Core/VideoCommon/RenderBase.h
Expand Up @@ -211,9 +211,9 @@ class Renderer
virtual u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data);
virtual void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points);

virtual u16 BBoxRead(int index) = 0;
virtual void BBoxWrite(int index, u16 value) = 0;
virtual void BBoxFlush() {}
u16 BBoxRead(int index);
void BBoxWrite(int index, u16 value);
void BBoxFlush();

virtual void Flush() {}
virtual void WaitForGPUIdle() {}
Expand Down Expand Up @@ -301,6 +301,10 @@ class Renderer
// Should be called with the ImGui lock held.
void DrawImGui();

virtual u16 BBoxReadImpl(int index) = 0;
virtual void BBoxWriteImpl(int index, u16 value) = 0;
virtual void BBoxFlushImpl() {}

AbstractFramebuffer* m_current_framebuffer = nullptr;
const AbstractPipeline* m_current_pipeline = nullptr;

Expand Down

0 comments on commit 77e5d79

Please sign in to comment.