VideoCommon: Rename Renderer to EFBInterface.

This commit is contained in:
Jordan Woyak 2025-03-11 21:12:06 -05:00
parent de997d616f
commit 5b36c13bfb
28 changed files with 281 additions and 333 deletions

View File

@ -615,14 +615,13 @@
<ClInclude Include="VideoBackends\Software\Clipper.h" />
<ClInclude Include="VideoBackends\Software\CopyRegion.h" />
<ClInclude Include="VideoBackends\Software\EfbCopy.h" />
<ClInclude Include="VideoBackends\Software\EfbInterface.h" />
<ClInclude Include="VideoBackends\Software\NativeVertexFormat.h" />
<ClInclude Include="VideoBackends\Software\Rasterizer.h" />
<ClInclude Include="VideoBackends\Software\SetupUnit.h" />
<ClInclude Include="VideoBackends\Software\SWBoundingBox.h" />
<ClInclude Include="VideoBackends\Software\SWEfbInterface.h" />
<ClInclude Include="VideoBackends\Software\SWGfx.h" />
<ClInclude Include="VideoBackends\Software\SWOGLWindow.h" />
<ClInclude Include="VideoBackends\Software\SWRenderer.h" />
<ClInclude Include="VideoBackends\Software\SWTexture.h" />
<ClInclude Include="VideoBackends\Software\SWVertexLoader.h" />
<ClInclude Include="VideoBackends\Software\Tev.h" />
@ -680,6 +679,7 @@
<ClInclude Include="VideoCommon\CPUCullImpl.h" />
<ClInclude Include="VideoCommon\DataReader.h" />
<ClInclude Include="VideoCommon\DriverDetails.h" />
<ClInclude Include="VideoCommon\EFBInterface.h" />
<ClInclude Include="VideoCommon\Fifo.h" />
<ClInclude Include="VideoCommon\FramebufferManager.h" />
<ClInclude Include="VideoCommon\FramebufferShaderGen.h" />
@ -729,7 +729,6 @@
<ClInclude Include="VideoCommon\PixelShaderManager.h" />
<ClInclude Include="VideoCommon\PostProcessing.h" />
<ClInclude Include="VideoCommon\Present.h" />
<ClInclude Include="VideoCommon\RenderBase.h" />
<ClInclude Include="VideoCommon\RenderState.h" />
<ClInclude Include="VideoCommon\ShaderCache.h" />
<ClInclude Include="VideoCommon\ShaderGenCommon.h" />
@ -1269,14 +1268,13 @@
<ClCompile Include="VideoBackends\OGL\SamplerCache.cpp" />
<ClCompile Include="VideoBackends\Software\Clipper.cpp" />
<ClCompile Include="VideoBackends\Software\EfbCopy.cpp" />
<ClCompile Include="VideoBackends\Software\EfbInterface.cpp" />
<ClCompile Include="VideoBackends\Software\Rasterizer.cpp" />
<ClCompile Include="VideoBackends\Software\SetupUnit.cpp" />
<ClCompile Include="VideoBackends\Software\SWmain.cpp" />
<ClCompile Include="VideoBackends\Software\SWBoundingBox.cpp" />
<ClCompile Include="VideoBackends\Software\SWEfbInterface.cpp" />
<ClCompile Include="VideoBackends\Software\SWGfx.cpp" />
<ClCompile Include="VideoBackends\Software\SWOGLWindow.cpp" />
<ClCompile Include="VideoBackends\Software\SWRenderer.cpp" />
<ClCompile Include="VideoBackends\Software\SWTexture.cpp" />
<ClCompile Include="VideoBackends\Software\SWVertexLoader.cpp" />
<ClCompile Include="VideoBackends\Software\Tev.cpp" />
@ -1324,6 +1322,7 @@
<ClCompile Include="VideoCommon\CPMemory.cpp" />
<ClCompile Include="VideoCommon\CPUCull.cpp" />
<ClCompile Include="VideoCommon\DriverDetails.cpp" />
<ClCompile Include="VideoCommon\EFBInterface.cpp" />
<ClCompile Include="VideoCommon\Fifo.cpp" />
<ClCompile Include="VideoCommon\FramebufferManager.cpp" />
<ClCompile Include="VideoCommon\FramebufferShaderGen.cpp" />
@ -1364,7 +1363,6 @@
<ClCompile Include="VideoCommon\PixelShaderManager.cpp" />
<ClCompile Include="VideoCommon\PostProcessing.cpp" />
<ClCompile Include="VideoCommon\Present.cpp" />
<ClCompile Include="VideoCommon\RenderBase.cpp" />
<ClCompile Include="VideoCommon\RenderState.cpp" />
<ClCompile Include="VideoCommon\ShaderCache.cpp" />
<ClCompile Include="VideoCommon\ShaderGenCommon.cpp" />

View File

@ -8,8 +8,8 @@
#include "Core/Core.h"
#include "Core/State.h"
#include "Core/System.h"
#include "VideoCommon/EFBInterface.h"
#include "VideoCommon/Present.h"
#include "VideoCommon/RenderBase.h"
#include <AppKit/AppKit.h>
#include <Carbon/Carbon.h>

View File

@ -16,7 +16,6 @@
#include "VideoCommon/AbstractGfx.h"
#include "VideoCommon/AbstractStagingTexture.h"
#include "VideoCommon/AbstractTexture.h"
#include "VideoCommon/RenderBase.h"
namespace DX11
{

View File

@ -14,7 +14,6 @@
#include "VideoCommon/AbstractGfx.h"
#include "VideoCommon/AbstractStagingTexture.h"
#include "VideoCommon/AbstractTexture.h"
#include "VideoCommon/RenderBase.h"
namespace DX12
{

View File

@ -69,7 +69,7 @@ bool VideoBackend::Initialize(const WindowSystemInfo& wsi)
{
return InitializeShared(std::make_unique<NullGfx>(), std::make_unique<VertexManager>(),
std::make_unique<PerfQuery>(), std::make_unique<NullBoundingBox>(),
std::make_unique<NullRenderer>(), std::make_unique<TextureCache>());
std::make_unique<NullEFBInterface>(), std::make_unique<TextureCache>());
}
void VideoBackend::Shutdown()

View File

@ -3,7 +3,6 @@
#include "VideoBackends/Null/NullGfx.h"
#include "VideoBackends/Null/NullBoundingBox.h"
#include "VideoBackends/Null/NullTexture.h"
#include "VideoCommon/AbstractPipeline.h"
@ -92,6 +91,26 @@ NullGfx::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
return std::make_unique<NativeVertexFormat>(vtx_decl);
}
NullRenderer::~NullRenderer() = default;
void NullEFBInterface::ReinterpretPixelData(EFBReinterpretType convtype)
{
}
void NullEFBInterface::PokeColor(u16 x, u16 y, u32 color)
{
}
void NullEFBInterface::PokeDepth(u16 x, u16 y, u32 depth)
{
}
u32 NullEFBInterface::PeekColorInternal(u16 x, u16 y)
{
return 0;
}
u32 NullEFBInterface::PeekDepth(u16 x, u16 y)
{
return 0;
}
} // namespace Null

View File

@ -4,7 +4,7 @@
#pragma once
#include "VideoCommon/AbstractGfx.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/EFBInterface.h"
namespace Null
{
@ -38,16 +38,15 @@ public:
SurfaceInfo GetSurfaceInfo() const override { return {}; }
};
class NullRenderer final : public Renderer
class NullEFBInterface final : public EFBInterfaceBase
{
public:
NullRenderer() {}
~NullRenderer() override;
void ReinterpretPixelData(EFBReinterpretType convtype) override;
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override { return 0; }
void PokeEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override {}
void PokeColor(u16 x, u16 y, u32 color) override;
void PokeDepth(u16 x, u16 y, u32 depth) override;
void ReinterpretPixelData(EFBReinterpretType convtype) override {}
u32 PeekColorInternal(u16 x, u16 y) override;
u32 PeekDepth(u16 x, u16 y) override;
};
} // namespace Null

View File

@ -4,8 +4,6 @@ add_library(videosoftware
CopyRegion.h
EfbCopy.cpp
EfbCopy.h
EfbInterface.cpp
EfbInterface.h
NativeVertexFormat.h
Rasterizer.cpp
Rasterizer.h
@ -14,12 +12,12 @@ add_library(videosoftware
SWmain.cpp
SWBoundingBox.cpp
SWBoundingBox.h
SWEfbInterface.cpp
SWEfbInterface.h
SWGfx.cpp
SWGfx.h
SWOGLWindow.cpp
SWOGLWindow.h
SWRenderer.cpp
SWRenderer.h
SWTexture.cpp
SWTexture.h
SWVertexLoader.cpp

View File

@ -6,13 +6,9 @@
#include <algorithm>
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
#include "Core/HW/Memmap.h"
#include "VideoBackends/Software/EfbInterface.h"
#include "VideoBackends/Software/TextureEncoder.h"
#include "VideoBackends/Software/SWEfbInterface.h"
#include "VideoCommon/BPMemory.h"
#include "VideoCommon/Fifo.h"
#include "VideoCommon/VideoCommon.h"
namespace EfbCopy

View File

@ -10,16 +10,14 @@
#include "Common/Assert.h"
#include "Common/CommonTypes.h"
#include "VideoBackends/Software/EfbInterface.h"
#include "VideoBackends/Software/NativeVertexFormat.h"
#include "VideoBackends/Software/SWEfbInterface.h"
#include "VideoBackends/Software/Tev.h"
#include "VideoCommon/BPFunctions.h"
#include "VideoCommon/BPMemory.h"
#include "VideoCommon/PerfQueryBase.h"
#include "VideoCommon/Statistics.h"
#include "VideoCommon/VideoCommon.h"
#include "VideoCommon/VideoConfig.h"
#include "VideoCommon/XFMemory.h"
namespace Rasterizer
{

View File

@ -1,11 +1,10 @@
// Copyright 2009 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "VideoBackends/Software/EfbInterface.h"
#include "VideoBackends/Software/SWEfbInterface.h"
#include <algorithm>
#include <array>
#include <cstddef>
#include <cstring>
#include <vector>
@ -717,3 +716,35 @@ void IncPerfCounterQuadCount(PerfQueryType type)
++perf_values[type];
}
} // namespace EfbInterface
namespace SW
{
void SWEFBInterface::ReinterpretPixelData(EFBReinterpretType convtype)
{
}
void SWEFBInterface::PokeColor(u16 x, u16 y, u32 color)
{
}
void SWEFBInterface::PokeDepth(u16 x, u16 y, u32 depth)
{
}
u32 SWEFBInterface::PeekColorInternal(u16 x, u16 y)
{
const u32 color = EfbInterface::GetColor(x, y);
// rgba to argb
u32 value = (color >> 8) | (color & 0xff) << 24;
return value;
}
u32 SWEFBInterface::PeekDepth(u16 x, u16 y)
{
return EfbInterface::GetDepth(x, y);
}
} // namespace SW

View File

@ -5,6 +5,7 @@
#include "Common/CommonTypes.h"
#include "Common/MathUtil.h"
#include "VideoCommon/EFBInterface.h"
#include "VideoCommon/PerfQueryBase.h"
namespace EfbInterface
@ -48,9 +49,6 @@ bool ZCompare(u16 x, u16 y, u32 z);
void SetColor(u16 x, u16 y, u8* color);
void SetDepth(u16 x, u16 y, u32 depth);
u32 GetColor(u16 x, u16 y);
u32 GetDepth(u16 x, u16 y);
u8* GetPixelPointer(u16 x, u16 y, bool depth);
void EncodeXFB(u8* xfb_in_ram, u32 memory_stride, const MathUtil::Rectangle<int>& source_rect,
@ -60,3 +58,17 @@ u32 GetPerfQueryResult(PerfQueryType type);
void ResetPerfQuery();
void IncPerfCounterQuadCount(PerfQueryType type);
} // namespace EfbInterface
namespace SW
{
class SWEFBInterface final : public EFBInterfaceBase
{
void ReinterpretPixelData(EFBReinterpretType convtype) override;
void PokeColor(u16 x, u16 y, u32 color) override;
void PokeDepth(u16 x, u16 y, u32 depth) override;
u32 PeekColorInternal(u16 x, u16 y) override;
u32 PeekDepth(u16 x, u16 y) override;
};
} // namespace SW

View File

@ -1,69 +0,0 @@
// Copyright 2009 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "VideoBackends/Software/SWRenderer.h"
#include <string>
#include "Common/CommonTypes.h"
#include "Common/MsgHandler.h"
#include "Core/HW/Memmap.h"
#include "Core/System.h"
#include "VideoBackends/Software/EfbInterface.h"
#include "VideoCommon/PixelEngine.h"
#include "VideoCommon/VideoBackendBase.h"
namespace SW
{
u32 SWRenderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
{
u32 value = 0;
switch (type)
{
case EFBAccessType::PeekZ:
{
value = EfbInterface::GetDepth(x, y);
break;
}
case EFBAccessType::PeekColor:
{
const u32 color = EfbInterface::GetColor(x, y);
// rgba to argb
value = (color >> 8) | (color & 0xff) << 24;
// check what to do with the alpha channel (GX_PokeAlphaRead)
PixelEngine::AlphaReadMode alpha_read_mode =
Core::System::GetInstance().GetPixelEngine().GetAlphaReadMode();
if (alpha_read_mode == PixelEngine::AlphaReadMode::ReadNone)
{
// value is OK as it is
}
else if (alpha_read_mode == PixelEngine::AlphaReadMode::ReadFF)
{
value |= 0xFF000000;
}
else
{
if (alpha_read_mode != PixelEngine::AlphaReadMode::Read00)
{
PanicAlertFmt("Invalid PE alpha read mode: {}", static_cast<u16>(alpha_read_mode));
}
value &= 0x00FFFFFF;
}
break;
}
default:
break;
}
return value;
}
} // namespace SW

View File

@ -1,20 +0,0 @@
// Copyright 2008 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include "Common/CommonTypes.h"
#include "VideoCommon/RenderBase.h"
namespace SW
{
class SWRenderer final : public Renderer
{
public:
u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override;
void PokeEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override {}
void ReinterpretPixelData(EFBReinterpretType convtype) override {}
};
} // namespace SW

View File

@ -14,7 +14,6 @@
#include "VideoBackends/Software/NativeVertexFormat.h"
#include "VideoBackends/Software/Rasterizer.h"
#include "VideoBackends/Software/SWRenderer.h"
#include "VideoBackends/Software/Tev.h"
#include "VideoBackends/Software/TransformUnit.h"

View File

@ -10,23 +10,16 @@
#include "Common/Common.h"
#include "Common/CommonTypes.h"
#include "Common/GL/GLContext.h"
#include "Common/MsgHandler.h"
#include "VideoBackends/Software/Clipper.h"
#include "VideoBackends/Software/EfbInterface.h"
#include "VideoBackends/Software/Rasterizer.h"
#include "VideoBackends/Software/SWBoundingBox.h"
#include "VideoBackends/Software/SWEfbInterface.h"
#include "VideoBackends/Software/SWGfx.h"
#include "VideoBackends/Software/SWOGLWindow.h"
#include "VideoBackends/Software/SWRenderer.h"
#include "VideoBackends/Software/SWTexture.h"
#include "VideoBackends/Software/SWVertexLoader.h"
#include "VideoBackends/Software/TextureCache.h"
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/Present.h"
#include "VideoCommon/TextureCacheBase.h"
#include "VideoCommon/VideoCommon.h"
#include "VideoCommon/VideoConfig.h"
@ -108,7 +101,7 @@ bool VideoSoftware::Initialize(const WindowSystemInfo& wsi)
return InitializeShared(std::make_unique<SWGfx>(std::move(window)),
std::make_unique<SWVertexLoader>(), std::make_unique<PerfQuery>(),
std::make_unique<SWBoundingBox>(), std::make_unique<SWRenderer>(),
std::make_unique<SWBoundingBox>(), std::make_unique<SWEFBInterface>(),
std::make_unique<TextureCache>());
}

View File

@ -7,20 +7,18 @@
#include <cmath>
#include <cstring>
#include "Common/ChunkFile.h"
#include "Common/Assert.h"
#include "Common/CommonTypes.h"
#include "Core/System.h"
#include "VideoBackends/Software/EfbInterface.h"
#include "VideoBackends/Software/SWBoundingBox.h"
#include "VideoBackends/Software/SWEfbInterface.h"
#include "VideoBackends/Software/TextureSampler.h"
#include "VideoCommon/PerfQueryBase.h"
#include "VideoCommon/PixelShaderManager.h"
#include "VideoCommon/Statistics.h"
#include "VideoCommon/VideoCommon.h"
#include "VideoCommon/VideoConfig.h"
#include "VideoCommon/XFMemory.h"
static inline s16 Clamp255(s16 in)

View File

@ -5,12 +5,11 @@
#include "Common/Align.h"
#include "Common/Assert.h"
#include "Common/CommonFuncs.h"
#include "Common/CommonTypes.h"
#include "Common/MsgHandler.h"
#include "Common/Swap.h"
#include "VideoBackends/Software/EfbInterface.h"
#include "VideoBackends/Software/SWEfbInterface.h"
#include "VideoBackends/Software/SWTexture.h"
#include "VideoCommon/BPMemory.h"

View File

@ -9,7 +9,6 @@
#include "VideoCommon/AbstractTexture.h"
#include "VideoCommon/BPFunctions.h"
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/ShaderCache.h"
#include "VideoCommon/VertexManagerBase.h"
#include "VideoCommon/VideoConfig.h"

View File

@ -8,9 +8,9 @@
#include "Core/System.h"
#include "VideoCommon/BoundingBox.h"
#include "VideoCommon/EFBInterface.h"
#include "VideoCommon/Fifo.h"
#include "VideoCommon/Present.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/Statistics.h"
#include "VideoCommon/VertexManagerBase.h"
#include "VideoCommon/VideoBackendBase.h"
@ -102,26 +102,25 @@ void AsyncRequests::HandleEvent(const AsyncRequests::Event& e)
case Event::EFB_POKE_COLOR:
{
INCSTAT(g_stats.this_frame.num_efb_pokes);
g_renderer->PokeEFB(EFBAccessType::PokeColor, e.efb_poke.x, e.efb_poke.y, e.efb_poke.data);
g_efb_interface->PokeColor(e.efb_poke.x, e.efb_poke.y, e.efb_poke.data);
}
break;
case Event::EFB_POKE_Z:
{
INCSTAT(g_stats.this_frame.num_efb_pokes);
g_renderer->PokeEFB(EFBAccessType::PokeZ, e.efb_poke.x, e.efb_poke.y, e.efb_poke.data);
g_efb_interface->PokeDepth(e.efb_poke.x, e.efb_poke.y, e.efb_poke.data);
}
break;
case Event::EFB_PEEK_COLOR:
INCSTAT(g_stats.this_frame.num_efb_peeks);
*e.efb_peek.data =
g_renderer->AccessEFB(EFBAccessType::PeekColor, e.efb_peek.x, e.efb_peek.y, 0);
*e.efb_peek.data = g_efb_interface->PeekColor(e.efb_peek.x, e.efb_peek.y);
break;
case Event::EFB_PEEK_Z:
INCSTAT(g_stats.this_frame.num_efb_peeks);
*e.efb_peek.data = g_renderer->AccessEFB(EFBAccessType::PeekZ, e.efb_peek.x, e.efb_peek.y, 0);
*e.efb_peek.data = g_efb_interface->PeekDepth(e.efb_peek.x, e.efb_peek.y);
break;
case Event::SWAP_EVENT:

View File

@ -15,8 +15,8 @@
#include "VideoCommon/AbstractFramebuffer.h"
#include "VideoCommon/AbstractGfx.h"
#include "VideoCommon/BPMemory.h"
#include "VideoCommon/EFBInterface.h"
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/RenderState.h"
#include "VideoCommon/VertexManagerBase.h"
#include "VideoCommon/VertexShaderManager.h"
@ -369,12 +369,12 @@ void OnPixelFormatChange()
if (new_format == PixelFormat::RGBA6_Z24)
{
g_renderer->ReinterpretPixelData(EFBReinterpretType::RGB8ToRGBA6);
g_efb_interface->ReinterpretPixelData(EFBReinterpretType::RGB8ToRGBA6);
return;
}
else if (new_format == PixelFormat::RGB565_Z16)
{
g_renderer->ReinterpretPixelData(EFBReinterpretType::RGB8ToRGB565);
g_efb_interface->ReinterpretPixelData(EFBReinterpretType::RGB8ToRGB565);
return;
}
}
@ -384,12 +384,12 @@ void OnPixelFormatChange()
{
if (new_format == PixelFormat::RGB8_Z24 || new_format == PixelFormat::Z24)
{
g_renderer->ReinterpretPixelData(EFBReinterpretType::RGBA6ToRGB8);
g_efb_interface->ReinterpretPixelData(EFBReinterpretType::RGBA6ToRGB8);
return;
}
else if (new_format == PixelFormat::RGB565_Z16)
{
g_renderer->ReinterpretPixelData(EFBReinterpretType::RGBA6ToRGB565);
g_efb_interface->ReinterpretPixelData(EFBReinterpretType::RGBA6ToRGB565);
return;
}
}
@ -399,12 +399,12 @@ void OnPixelFormatChange()
{
if (new_format == PixelFormat::RGB8_Z24 || new_format == PixelFormat::Z24)
{
g_renderer->ReinterpretPixelData(EFBReinterpretType::RGB565ToRGB8);
g_efb_interface->ReinterpretPixelData(EFBReinterpretType::RGB565ToRGB8);
return;
}
else if (new_format == PixelFormat::RGBA6_Z24)
{
g_renderer->ReinterpretPixelData(EFBReinterpretType::RGB565ToRGBA6);
g_efb_interface->ReinterpretPixelData(EFBReinterpretType::RGB565ToRGBA6);
return;
}
}

View File

@ -49,6 +49,8 @@ add_library(videocommon
CPUCullImpl.h
DriverDetails.cpp
DriverDetails.h
EFBInterface.cpp
EFBInterface.h
Fifo.cpp
Fifo.h
FramebufferManager.cpp
@ -134,8 +136,6 @@ add_library(videocommon
PostProcessing.h
Present.cpp
Present.h
RenderBase.cpp
RenderBase.h
RenderState.cpp
RenderState.h
ShaderCache.cpp

View File

@ -0,0 +1,126 @@
// Copyright 2025 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#include "VideoCommon/EFBInterface.h"
#include <algorithm>
#include <cmath>
#include <memory>
#include <fmt/format.h>
#include "Common/MsgHandler.h"
#include "Core/ConfigManager.h"
#include "Core/System.h"
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/PixelEngine.h"
#include "VideoCommon/VideoBackendBase.h"
#include "VideoCommon/VideoCommon.h"
#include "VideoCommon/VideoConfig.h"
std::unique_ptr<EFBInterfaceBase> g_efb_interface;
EFBInterfaceBase::~EFBInterfaceBase() = default;
void HardwareEFBInterface::ReinterpretPixelData(EFBReinterpretType convtype)
{
g_framebuffer_manager->ReinterpretPixelData(convtype);
}
u32 HardwareEFBInterface::PeekColorInternal(u16 x, u16 y)
{
u32 color = g_framebuffer_manager->PeekEFBColor(x, y);
// a little-endian value is expected to be returned
color = ((color & 0xFF00FF00) | ((color >> 16) & 0xFF) | ((color << 16) & 0xFF0000));
if (bpmem.zcontrol.pixel_format == PixelFormat::RGBA6_Z24)
{
color = RGBA8ToRGBA6ToRGBA8(color);
}
else if (bpmem.zcontrol.pixel_format == PixelFormat::RGB565_Z16)
{
color = RGBA8ToRGB565ToRGBA8(color);
}
if (bpmem.zcontrol.pixel_format != PixelFormat::RGBA6_Z24)
{
color |= 0xFF000000;
}
return color;
}
u32 EFBInterfaceBase::PeekColor(u16 x, u16 y)
{
u32 color = PeekColorInternal(x, y);
// check what to do with the alpha channel (GX_PokeAlphaRead)
PixelEngine::AlphaReadMode alpha_read_mode =
Core::System::GetInstance().GetPixelEngine().GetAlphaReadMode();
if (alpha_read_mode == PixelEngine::AlphaReadMode::ReadNone)
{
return color;
}
else if (alpha_read_mode == PixelEngine::AlphaReadMode::ReadFF)
{
return color | 0xFF000000;
}
else
{
if (alpha_read_mode != PixelEngine::AlphaReadMode::Read00)
{
PanicAlertFmt("Invalid PE alpha read mode: {}", static_cast<u16>(alpha_read_mode));
}
return color & 0x00FFFFFF;
}
}
u32 HardwareEFBInterface::PeekDepth(u16 x, u16 y)
{
// Depth buffer is inverted for improved precision near far plane
float depth = g_framebuffer_manager->PeekEFBDepth(x, y);
if (!g_backend_info.bSupportsReversedDepthRange)
depth = 1.0f - depth;
// Convert to 24bit depth
u32 z24depth = std::clamp<u32>(static_cast<u32>(depth * 16777216.0f), 0, 0xFFFFFF);
if (bpmem.zcontrol.pixel_format == PixelFormat::RGB565_Z16)
{
// When in RGB565_Z16 mode, EFB Z peeks return a 16bit value, which is presumably a
// resolved sample from the MSAA buffer.
// Dolphin doesn't currently emulate the 3 sample MSAA mode (and potentially never will)
// it just transparently upgrades the framebuffer to 24bit depth and color and whatever
// level of MSAA and higher Internal Resolution the user has configured.
// This is mostly transparent, unless the game does an EFB read.
// But we can simply convert the 24bit depth on the fly to the 16bit depth the game expects.
return CompressZ16(z24depth, bpmem.zcontrol.zformat);
}
return z24depth;
}
void HardwareEFBInterface::PokeColor(u16 x, u16 y, u32 poke_data)
{
// Convert to expected format (BGRA->RGBA)
// TODO: Check alpha, depending on mode?
const u32 color =
((poke_data & 0xFF00FF00) | ((poke_data >> 16) & 0xFF) | ((poke_data << 16) & 0xFF0000));
g_framebuffer_manager->PokeEFBColor(x, y, color);
}
void HardwareEFBInterface::PokeDepth(u16 x, u16 y, u32 poke_data)
{
// Convert to floating-point depth.
float depth = float(poke_data & 0xFFFFFF) / 16777216.0f;
if (!g_backend_info.bSupportsReversedDepthRange)
depth = 1.0f - depth;
g_framebuffer_manager->PokeEFBDepth(x, y, depth);
}

View File

@ -0,0 +1,40 @@
// Copyright 2025 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include "Common/CommonTypes.h"
enum class EFBReinterpretType;
class EFBInterfaceBase
{
public:
virtual ~EFBInterfaceBase();
virtual void ReinterpretPixelData(EFBReinterpretType convtype) = 0;
virtual void PokeColor(u16 x, u16 y, u32 color) = 0;
virtual void PokeDepth(u16 x, u16 y, u32 depth) = 0;
u32 PeekColor(u16 x, u16 y);
virtual u32 PeekDepth(u16 x, u16 y) = 0;
protected:
virtual u32 PeekColorInternal(u16 x, u16 y) = 0;
};
class HardwareEFBInterface final : public EFBInterfaceBase
{
void ReinterpretPixelData(EFBReinterpretType convtype) override;
void PokeColor(u16 x, u16 y, u32 color) override;
void PokeDepth(u16 x, u16 y, u32 depth) override;
u32 PeekColorInternal(u16 x, u16 y) override;
u32 PeekDepth(u16 x, u16 y) override;
};
extern std::unique_ptr<EFBInterfaceBase> g_efb_interface;

View File

@ -1,134 +0,0 @@
// Copyright 2010 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
// ---------------------------------------------------------------------------------------------
// GC graphics pipeline
// ---------------------------------------------------------------------------------------------
// 3d commands are issued through the fifo. The GPU draws to the 2MB EFB.
// The efb can be copied back into ram in two forms: as textures or as XFB.
// The XFB is the region in RAM that the VI chip scans out to the television.
// So, after all rendering to EFB is done, the image is copied into one of two XFBs in RAM.
// Next frame, that one is scanned out and the other one gets the copy. = double buffering.
// ---------------------------------------------------------------------------------------------
#include "VideoCommon/RenderBase.h"
#include <algorithm>
#include <cmath>
#include <memory>
#include <tuple>
#include <fmt/format.h>
#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
#include "Core/ConfigManager.h"
#include "Core/System.h"
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/PixelEngine.h"
#include "VideoCommon/VideoBackendBase.h"
#include "VideoCommon/VideoCommon.h"
#include "VideoCommon/VideoConfig.h"
std::unique_ptr<Renderer> g_renderer;
Renderer::~Renderer() = default;
void Renderer::ReinterpretPixelData(EFBReinterpretType convtype)
{
g_framebuffer_manager->ReinterpretPixelData(convtype);
}
u32 Renderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
{
if (type == EFBAccessType::PeekColor)
{
u32 color = g_framebuffer_manager->PeekEFBColor(x, y);
// a little-endian value is expected to be returned
color = ((color & 0xFF00FF00) | ((color >> 16) & 0xFF) | ((color << 16) & 0xFF0000));
if (bpmem.zcontrol.pixel_format == PixelFormat::RGBA6_Z24)
{
color = RGBA8ToRGBA6ToRGBA8(color);
}
else if (bpmem.zcontrol.pixel_format == PixelFormat::RGB565_Z16)
{
color = RGBA8ToRGB565ToRGBA8(color);
}
if (bpmem.zcontrol.pixel_format != PixelFormat::RGBA6_Z24)
{
color |= 0xFF000000;
}
// check what to do with the alpha channel (GX_PokeAlphaRead)
PixelEngine::AlphaReadMode alpha_read_mode =
Core::System::GetInstance().GetPixelEngine().GetAlphaReadMode();
if (alpha_read_mode == PixelEngine::AlphaReadMode::ReadNone)
{
return color;
}
else if (alpha_read_mode == PixelEngine::AlphaReadMode::ReadFF)
{
return color | 0xFF000000;
}
else
{
if (alpha_read_mode != PixelEngine::AlphaReadMode::Read00)
{
PanicAlertFmt("Invalid PE alpha read mode: {}", static_cast<u16>(alpha_read_mode));
}
return color & 0x00FFFFFF;
}
}
else // if (type == EFBAccessType::PeekZ)
{
// Depth buffer is inverted for improved precision near far plane
float depth = g_framebuffer_manager->PeekEFBDepth(x, y);
if (!g_backend_info.bSupportsReversedDepthRange)
depth = 1.0f - depth;
// Convert to 24bit depth
u32 z24depth = std::clamp<u32>(static_cast<u32>(depth * 16777216.0f), 0, 0xFFFFFF);
if (bpmem.zcontrol.pixel_format == PixelFormat::RGB565_Z16)
{
// When in RGB565_Z16 mode, EFB Z peeks return a 16bit value, which is presumably a
// resolved sample from the MSAA buffer.
// Dolphin doesn't currently emulate the 3 sample MSAA mode (and potentially never will)
// it just transparently upgrades the framebuffer to 24bit depth and color and whatever
// level of MSAA and higher Internal Resolution the user has configured.
// This is mostly transparent, unless the game does an EFB read.
// But we can simply convert the 24bit depth on the fly to the 16bit depth the game expects.
return CompressZ16(z24depth, bpmem.zcontrol.zformat);
}
return z24depth;
}
}
void Renderer::PokeEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data)
{
if (type == EFBAccessType::PokeColor)
{
// Convert to expected format (BGRA->RGBA)
// TODO: Check alpha, depending on mode?
const u32 color =
((poke_data & 0xFF00FF00) | ((poke_data >> 16) & 0xFF) | ((poke_data << 16) & 0xFF0000));
g_framebuffer_manager->PokeEFBColor(x, y, color);
}
else // if (type == EFBAccessType::PokeZ)
{
// Convert to floating-point depth.
float depth = float(poke_data & 0xFFFFFF) / 16777216.0f;
if (!g_backend_info.bSupportsReversedDepthRange)
depth = 1.0f - depth;
g_framebuffer_manager->PokeEFBDepth(x, y, depth);
}
}

View File

@ -1,28 +0,0 @@
// Copyright 2010 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <memory>
#include "Common/CommonTypes.h"
enum class EFBAccessType;
enum class EFBReinterpretType;
// Renderer really isn't a very good name for this class - it's more like "Misc".
// It used to be a massive mess, but almost everything has been refactored out.
//
// All that's left is a thin abstraction layer for VideoSoftware to intercept EFB accesses.
class Renderer
{
public:
virtual ~Renderer();
virtual void ReinterpretPixelData(EFBReinterpretType convtype);
virtual u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data);
virtual void PokeEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data);
};
extern std::unique_ptr<Renderer> g_renderer;

View File

@ -13,7 +13,6 @@
#include "Common/ChunkFile.h"
#include "Common/CommonTypes.h"
#include "Common/Event.h"
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
@ -46,18 +45,16 @@
#include "VideoCommon/BoundingBox.h"
#include "VideoCommon/CPMemory.h"
#include "VideoCommon/CommandProcessor.h"
#include "VideoCommon/EFBInterface.h"
#include "VideoCommon/Fifo.h"
#include "VideoCommon/FrameDumper.h"
#include "VideoCommon/FramebufferManager.h"
#include "VideoCommon/GeometryShaderManager.h"
#include "VideoCommon/GraphicsModSystem/Runtime/GraphicsModManager.h"
#include "VideoCommon/IndexGenerator.h"
#include "VideoCommon/OnScreenDisplay.h"
#include "VideoCommon/OpcodeDecoding.h"
#include "VideoCommon/PixelEngine.h"
#include "VideoCommon/PixelShaderManager.h"
#include "VideoCommon/Present.h"
#include "VideoCommon/RenderBase.h"
#include "VideoCommon/TMEM.h"
#include "VideoCommon/TextureCacheBase.h"
#include "VideoCommon/VertexLoaderManager.h"
@ -325,11 +322,11 @@ bool VideoBackendBase::InitializeShared(std::unique_ptr<AbstractGfx> gfx,
std::unique_ptr<PerfQueryBase> perf_query,
std::unique_ptr<BoundingBox> bounding_box)
{
// All hardware backends use the default RendererBase and TextureCacheBase.
// All hardware backends use the default EFBInterface and TextureCacheBase.
// Only Null and Software backends override them
return InitializeShared(std::move(gfx), std::move(vertex_manager), std::move(perf_query),
std::move(bounding_box), std::make_unique<Renderer>(),
std::move(bounding_box), std::make_unique<HardwareEFBInterface>(),
std::make_unique<TextureCacheBase>());
}
@ -337,7 +334,7 @@ bool VideoBackendBase::InitializeShared(std::unique_ptr<AbstractGfx> gfx,
std::unique_ptr<VertexManagerBase> vertex_manager,
std::unique_ptr<PerfQueryBase> perf_query,
std::unique_ptr<BoundingBox> bounding_box,
std::unique_ptr<Renderer> renderer,
std::unique_ptr<EFBInterfaceBase> efb_interface,
std::unique_ptr<TextureCacheBase> texture_cache)
{
memset(reinterpret_cast<u8*>(&g_main_cp_state), 0, sizeof(g_main_cp_state));
@ -352,9 +349,9 @@ bool VideoBackendBase::InitializeShared(std::unique_ptr<AbstractGfx> gfx,
g_perf_query = std::move(perf_query);
g_bounding_box = std::move(bounding_box);
// Null and Software Backends supply their own derived Renderer and Texture Cache
// Null and Software Backends supply their own derived EFBInterface and TextureCache
g_texture_cache = std::move(texture_cache);
g_renderer = std::move(renderer);
g_efb_interface = std::move(efb_interface);
g_presenter = std::make_unique<VideoCommon::Presenter>();
g_frame_dumper = std::make_unique<FrameDumper>();
@ -418,7 +415,7 @@ void VideoBackendBase::ShutdownShared()
g_framebuffer_manager.reset();
g_shader_cache.reset();
g_vertex_manager.reset();
g_renderer.reset();
g_efb_interface.reset();
g_widescreen.reset();
g_presenter.reset();
g_gfx.reset();

View File

@ -20,9 +20,9 @@ class PointerWrap;
class AbstractGfx;
class BoundingBox;
class Renderer;
class TextureCacheBase;
class VertexManagerBase;
class EFBInterfaceBase;
enum class FieldType
{
@ -80,12 +80,12 @@ protected:
std::unique_ptr<PerfQueryBase> perf_query,
std::unique_ptr<BoundingBox> bounding_box);
// For software and null backends. Allows overriding the default Renderer and Texture Cache
// For software and null backends. Allows overriding the default EFBInterface and TextureCache
bool InitializeShared(std::unique_ptr<AbstractGfx> gfx,
std::unique_ptr<VertexManagerBase> vertex_manager,
std::unique_ptr<PerfQueryBase> perf_query,
std::unique_ptr<BoundingBox> bounding_box,
std::unique_ptr<Renderer> renderer,
std::unique_ptr<EFBInterfaceBase> efb_interface,
std::unique_ptr<TextureCacheBase> texture_cache);
void ShutdownShared();