summaryrefslogtreecommitdiff
path: root/Source/Core/VideoCommon/BPFunctions.cpp
diff options
context:
space:
mode:
authorJosJuice <josjuice@gmail.com>2023-08-21 16:12:49 +0200
committerJosJuice <josjuice@gmail.com>2023-08-22 13:19:49 +0200
commit6e88c44d5dd041a75912f000cce631316a6b72fd (patch)
tree1dd45e8e95fea99439efb682cf1f6f21d9cee16d /Source/Core/VideoCommon/BPFunctions.cpp
parented7894924c79be09863ade3aa4622423dd434691 (diff)
Move SmallVector to Common
We had one implementation of this type of data structure in Arm64Emitter and one in VideoCommon. This moves the Arm64Emitter implementation to its own file and adds begin and end functions to it, so that VideoCommon can use it. You may notice that the license header for the new file is CC0. I wrote the Arm64Emitter implementation of SmallVector, so this should be no problem.
Diffstat (limited to 'Source/Core/VideoCommon/BPFunctions.cpp')
-rw-r--r--Source/Core/VideoCommon/BPFunctions.cpp24
1 files changed, 3 insertions, 21 deletions
diff --git a/Source/Core/VideoCommon/BPFunctions.cpp b/Source/Core/VideoCommon/BPFunctions.cpp
index ad9898b27e..6f9948a68e 100644
--- a/Source/Core/VideoCommon/BPFunctions.cpp
+++ b/Source/Core/VideoCommon/BPFunctions.cpp
@@ -10,6 +10,7 @@
#include "Common/Assert.h"
#include "Common/CommonTypes.h"
#include "Common/Logging/Log.h"
+#include "Common/SmallVector.h"
#include "VideoCommon/AbstractFramebuffer.h"
#include "VideoCommon/AbstractGfx.h"
@@ -76,26 +77,7 @@ bool ScissorResult::IsWorse(const ScissorRect& lhs, const ScissorRect& rhs) cons
namespace
{
-// Dynamically sized small array of ScissorRanges (used as an heap-less alternative to std::vector
-// to reduce allocation overhead)
-struct RangeList
-{
- static constexpr u32 MAX_RANGES = 9;
-
- u32 m_num_ranges = 0;
- std::array<ScissorRange, MAX_RANGES> m_ranges{};
-
- void AddRange(int offset, int start, int end)
- {
- DEBUG_ASSERT(m_num_ranges < MAX_RANGES);
- m_ranges[m_num_ranges] = ScissorRange(offset, start, end);
- m_num_ranges++;
- }
- auto begin() const { return m_ranges.begin(); }
- auto end() const { return m_ranges.begin() + m_num_ranges; }
-
- u32 size() { return m_num_ranges; }
-};
+using RangeList = Common::SmallVector<ScissorRange, 9>;
static RangeList ComputeScissorRanges(int start, int end, int offset, int efb_dim)
{
@@ -108,7 +90,7 @@ static RangeList ComputeScissorRanges(int start, int end, int offset, int efb_di
int new_end = std::clamp(end - new_off + 1, 0, efb_dim);
if (new_start < new_end)
{
- ranges.AddRange(new_off, new_start, new_end);
+ ranges.emplace_back(new_off, new_start, new_end);
}
}