summaryrefslogtreecommitdiff
path: root/Source/Core/VideoBackends/Software
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2021-10-08 22:24:38 +0200
committerGitHub <noreply@github.com>2021-10-08 22:24:38 +0200
commitff1cb5a1c08d5a4a2a0449b8b23a4977ccc20f8a (patch)
treea584d167e0c71c08d4d885f60aa071f5a577692e /Source/Core/VideoBackends/Software
parentd90b30ca251146c478759190d9b206f38c3b70d3 (diff)
parent1161af80594c403233e3d21589af004ee2d75594 (diff)
Merge pull request #9803 from Techjar/bbox-videocommon
VideoCommon: Abstract bounding box
Diffstat (limited to 'Source/Core/VideoBackends/Software')
-rw-r--r--Source/Core/VideoBackends/Software/CMakeLists.txt2
-rw-r--r--Source/Core/VideoBackends/Software/SWBoundingBox.cpp66
-rw-r--r--Source/Core/VideoBackends/Software/SWBoundingBox.h43
-rw-r--r--Source/Core/VideoBackends/Software/SWRenderer.cpp11
-rw-r--r--Source/Core/VideoBackends/Software/SWRenderer.h6
-rw-r--r--Source/Core/VideoBackends/Software/SWVertexLoader.cpp4
-rw-r--r--Source/Core/VideoBackends/Software/SWmain.cpp1
-rw-r--r--Source/Core/VideoBackends/Software/Tev.cpp4
8 files changed, 125 insertions, 12 deletions
diff --git a/Source/Core/VideoBackends/Software/CMakeLists.txt b/Source/Core/VideoBackends/Software/CMakeLists.txt
index 9d188f434b..983cd3df3f 100644
--- a/Source/Core/VideoBackends/Software/CMakeLists.txt
+++ b/Source/Core/VideoBackends/Software/CMakeLists.txt
@@ -14,6 +14,8 @@ add_library(videosoftware
SetupUnit.cpp
SetupUnit.h
SWmain.cpp
+ SWBoundingBox.cpp
+ SWBoundingBox.h
SWOGLWindow.cpp
SWOGLWindow.h
SWRenderer.cpp
diff --git a/Source/Core/VideoBackends/Software/SWBoundingBox.cpp b/Source/Core/VideoBackends/Software/SWBoundingBox.cpp
new file mode 100644
index 0000000000..96d38517b8
--- /dev/null
+++ b/Source/Core/VideoBackends/Software/SWBoundingBox.cpp
@@ -0,0 +1,66 @@
+// Copyright 2021 Dolphin Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#include "VideoBackends/Software/SWBoundingBox.h"
+
+#include <algorithm>
+#include <array>
+
+#include "Common/CommonTypes.h"
+
+namespace BBoxManager
+{
+namespace
+{
+// Current bounding box coordinates.
+std::array<u16, 4> s_coordinates{};
+} // Anonymous namespace
+
+u16 GetCoordinate(Coordinate coordinate)
+{
+ return s_coordinates[static_cast<u32>(coordinate)];
+}
+
+void SetCoordinate(Coordinate coordinate, u16 value)
+{
+ s_coordinates[static_cast<u32>(coordinate)] = value;
+}
+
+void Update(u16 left, u16 right, u16 top, u16 bottom)
+{
+ const u16 new_left = std::min(left, GetCoordinate(Coordinate::Left));
+ const u16 new_right = std::max(right, GetCoordinate(Coordinate::Right));
+ const u16 new_top = std::min(top, GetCoordinate(Coordinate::Top));
+ const u16 new_bottom = std::max(bottom, GetCoordinate(Coordinate::Bottom));
+
+ SetCoordinate(Coordinate::Left, new_left);
+ SetCoordinate(Coordinate::Right, new_right);
+ SetCoordinate(Coordinate::Top, new_top);
+ SetCoordinate(Coordinate::Bottom, new_bottom);
+}
+
+} // namespace BBoxManager
+
+namespace SW
+{
+std::vector<BBoxType> SWBoundingBox::Read(u32 index, u32 length)
+{
+ std::vector<BBoxType> values(length);
+
+ for (u32 i = 0; i < length; i++)
+ {
+ values[i] = BBoxManager::GetCoordinate(static_cast<BBoxManager::Coordinate>(index + i));
+ }
+
+ return values;
+}
+
+void SWBoundingBox::Write(u32 index, const std::vector<BBoxType>& values)
+{
+ for (size_t i = 0; i < values.size(); i++)
+ {
+ BBoxManager::SetCoordinate(static_cast<BBoxManager::Coordinate>(index + i), values[i]);
+ }
+}
+
+} // namespace SW
diff --git a/Source/Core/VideoBackends/Software/SWBoundingBox.h b/Source/Core/VideoBackends/Software/SWBoundingBox.h
new file mode 100644
index 0000000000..116d85bdf1
--- /dev/null
+++ b/Source/Core/VideoBackends/Software/SWBoundingBox.h
@@ -0,0 +1,43 @@
+// Copyright 2021 Dolphin Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include "Common/CommonTypes.h"
+
+#include "VideoCommon/BoundingBox.h"
+
+namespace BBoxManager
+{
+// Indicates a coordinate of the bounding box.
+enum class Coordinate
+{
+ Left, // The X coordinate of the left side of the bounding box.
+ Right, // The X coordinate of the right side of the bounding box.
+ Top, // The Y coordinate of the top of the bounding box.
+ Bottom, // The Y coordinate of the bottom of the bounding box.
+};
+
+// Gets a particular coordinate for the bounding box.
+u16 GetCoordinate(Coordinate coordinate);
+
+// Sets a particular coordinate for the bounding box.
+void SetCoordinate(Coordinate coordinate, u16 value);
+
+// Updates all bounding box coordinates.
+void Update(u16 left, u16 right, u16 top, u16 bottom);
+} // namespace BBoxManager
+
+namespace SW
+{
+class SWBoundingBox final : public BoundingBox
+{
+public:
+ bool Initialize() override { return true; }
+
+protected:
+ std::vector<BBoxType> Read(u32 index, u32 length) override;
+ void Write(u32 index, const std::vector<BBoxType>& values) override;
+};
+
+} // namespace SW
diff --git a/Source/Core/VideoBackends/Software/SWRenderer.cpp b/Source/Core/VideoBackends/Software/SWRenderer.cpp
index d66609ad3a..84fe951fcd 100644
--- a/Source/Core/VideoBackends/Software/SWRenderer.cpp
+++ b/Source/Core/VideoBackends/Software/SWRenderer.cpp
@@ -12,13 +12,13 @@
#include "VideoBackends/Software/EfbCopy.h"
#include "VideoBackends/Software/EfbInterface.h"
+#include "VideoBackends/Software/SWBoundingBox.h"
#include "VideoBackends/Software/SWOGLWindow.h"
#include "VideoBackends/Software/SWTexture.h"
#include "VideoCommon/AbstractPipeline.h"
#include "VideoCommon/AbstractShader.h"
#include "VideoCommon/AbstractTexture.h"
-#include "VideoCommon/BoundingBox.h"
#include "VideoCommon/NativeVertexFormat.h"
#include "VideoCommon/VideoBackendBase.h"
#include "VideoCommon/VideoCommon.h"
@@ -141,14 +141,9 @@ u32 SWRenderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
return value;
}
-u16 SWRenderer::BBoxReadImpl(int index)
+std::unique_ptr<BoundingBox> SWRenderer::CreateBoundingBox() const
{
- return BoundingBox::GetCoordinate(static_cast<BoundingBox::Coordinate>(index));
-}
-
-void SWRenderer::BBoxWriteImpl(int index, u16 value)
-{
- BoundingBox::SetCoordinate(static_cast<BoundingBox::Coordinate>(index), value);
+ return std::make_unique<SWBoundingBox>();
}
void SWRenderer::ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable, bool alphaEnable,
diff --git a/Source/Core/VideoBackends/Software/SWRenderer.h b/Source/Core/VideoBackends/Software/SWRenderer.h
index b3c624b0d0..dcedc1934d 100644
--- a/Source/Core/VideoBackends/Software/SWRenderer.h
+++ b/Source/Core/VideoBackends/Software/SWRenderer.h
@@ -10,6 +10,7 @@
#include "VideoCommon/RenderBase.h"
+class BoundingBox;
class SWOGLWindow;
namespace SW
@@ -43,8 +44,6 @@ public:
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 BBoxReadImpl(int index) override;
- void BBoxWriteImpl(int index, u16 value) override;
void RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc,
const AbstractTexture* source_texture,
@@ -59,6 +58,9 @@ public:
const AbstractTexture* src_texture,
const MathUtil::Rectangle<int>& src_rect) override;
+protected:
+ std::unique_ptr<BoundingBox> CreateBoundingBox() const override;
+
private:
std::unique_ptr<SWOGLWindow> m_window;
};
diff --git a/Source/Core/VideoBackends/Software/SWVertexLoader.cpp b/Source/Core/VideoBackends/Software/SWVertexLoader.cpp
index 22d6f016f1..5c0362b2c5 100644
--- a/Source/Core/VideoBackends/Software/SWVertexLoader.cpp
+++ b/Source/Core/VideoBackends/Software/SWVertexLoader.cpp
@@ -53,6 +53,10 @@ void SWVertexLoader::DrawCurrentBatch(u32 base_index, u32 num_indices, u32 base_
break;
}
+ // Flush bounding box here because software overrides the base function
+ if (g_renderer->IsBBoxEnabled())
+ g_renderer->BBoxFlush();
+
m_setup_unit.Init(primitiveType);
// set all states with are stored within video sw
diff --git a/Source/Core/VideoBackends/Software/SWmain.cpp b/Source/Core/VideoBackends/Software/SWmain.cpp
index 7d8be7f1aa..a0aa8e03c1 100644
--- a/Source/Core/VideoBackends/Software/SWmain.cpp
+++ b/Source/Core/VideoBackends/Software/SWmain.cpp
@@ -83,6 +83,7 @@ void VideoSoftware::InitBackendInfo()
g_Config.backend_info.bSupportsLogicOp = true;
g_Config.backend_info.bSupportsShaderBinaries = false;
g_Config.backend_info.bSupportsPipelineCacheData = false;
+ g_Config.backend_info.bSupportsBBox = true;
// aamodes
g_Config.backend_info.AAModes = {1};
diff --git a/Source/Core/VideoBackends/Software/Tev.cpp b/Source/Core/VideoBackends/Software/Tev.cpp
index f8af6325db..1da39f6ca7 100644
--- a/Source/Core/VideoBackends/Software/Tev.cpp
+++ b/Source/Core/VideoBackends/Software/Tev.cpp
@@ -11,9 +11,9 @@
#include "Common/CommonTypes.h"
#include "VideoBackends/Software/DebugUtil.h"
#include "VideoBackends/Software/EfbInterface.h"
+#include "VideoBackends/Software/SWBoundingBox.h"
#include "VideoBackends/Software/TextureSampler.h"
-#include "VideoCommon/BoundingBox.h"
#include "VideoCommon/PerfQueryBase.h"
#include "VideoCommon/PixelShaderManager.h"
#include "VideoCommon/Statistics.h"
@@ -839,7 +839,7 @@ void Tev::Draw()
// 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.
- BoundingBox::Update(static_cast<u16>(Position[0] & ~1), static_cast<u16>(Position[0] | 1),
+ BBoxManager::Update(static_cast<u16>(Position[0] & ~1), static_cast<u16>(Position[0] | 1),
static_cast<u16>(Position[1] & ~1), static_cast<u16>(Position[1] | 1));
#if ALLOW_TEV_DUMPS