Much faster framebuffer matching (no more ToString every time there's more than 1 candidate, etc).

This commit is contained in:
Henrik Rydgård committed 2022-08-31 14:23:56 +02:00
1 parent 67d6549afd
commit a8a9fb4206
3 files changed
+57 -13

No files matched your search

+41 -1
View File
@@ -3,10 +3,12 @@
#include <vector>
// Insert-only small-set implementation. Performs no allocation unless MaxFastSize is exceeded.
// Can also be used as a small vector, then use push_back (or push_in_place) instead of insert.
// Duplicates are thus allowed if you use that, but not if you exclusively use insert.
template <class T, int MaxFastSize>
struct TinySet {
~TinySet() { delete slowLookup_; }
inline void insert(T t) {
inline void insert(const T &t) {
// Fast linear scan.
for (int i = 0; i < fastCount; i++) {
if (fastLookup_[i] == t)
@@ -20,6 +22,27 @@ struct TinySet {
// Fall back to slow path.
insertSlow(t);
}
inline void push_back(const T &t) {
if (fastCount < MaxFastSize) {
fastLookup_[fastCount++] = t;
return;
}
if (!slowLookup_) {
slowLookup_ = new std::vector<T>();
}
slowLookup_->push_back(t);
}
inline T *add_back() {
if (fastCount < MaxFastSize) {
return &fastLookup_[fastCount++];
}
if (!slowLookup_) {
slowLookup_ = new std::vector<T>();
}
T t;
slowLookup_->push_back(t);
return slowLookup_->back();
}
bool contains(T t) const {
for (int i = 0; i < fastCount; i++) {
if (fastLookup_[i] == t)
@@ -52,6 +75,23 @@ struct TinySet {
slowLookup_ = nullptr;
fastCount = 0;
}
bool empty() const {
return fastCount == 0;
}
size_t size() const {
if (fastCount <= MaxFastSize) {
return fastCount;
} else {
return slowLookup_->size() + MaxFastSize;
}
}
const T &operator[] (size_t index) const {
if (index < MaxFastSize) {
return fastLookup_[index];
} else {
return (*slowLookup_)[index - MaxFastSize];
}
}
private:
void insertSlow(T t) {
+16 -8
View File
@@ -21,6 +21,7 @@
#include "Common/GPU/thin3d.h"
#include "Common/GPU/OpenGL/GLFeatures.h"
#include "Common/Data/Collections/TinySet.h"
#include "Common/Data/Convert/ColorConv.h"
#include "Common/Data/Text/I18n.h"
#include "Common/Math/lin/matrix4x4.h"
@@ -1677,7 +1678,7 @@ bool FramebufferManagerCommon::FindTransferFramebuffer(u32 basePtr, int stride_p
int x_bytes = x_pixels * bpp;
int w_bytes = w_pixels * bpp;
std::vector<BlockTransferRect> candidates;
TinySet<BlockTransferRect, 4> candidates;
// We work entirely in bytes when we do the matching, because games don't consistently use bpps that match
// that of their buffers. Then after matching we try to map the copy to the simplest operation that does
@@ -1752,20 +1753,27 @@ bool FramebufferManagerCommon::FindTransferFramebuffer(u32 basePtr, int stride_p
candidates.push_back(candidate);
}
const BlockTransferRect *best = nullptr;
// Sort candidates by just recency for now, we might add other.
std::sort(candidates.begin(), candidates.end());
for (size_t i = 0; i < candidates.size(); i++) {
const BlockTransferRect *candidate = &candidates[i];
if (!best || candidate->vfb->colorBindSeq > best->vfb->colorBindSeq) {
best = candidate;
}
}
if (candidates.size() > 1) {
std::string log;
for (auto &candidate : candidates) {
log += " - " + candidate.ToString() + "\n";
if (Reporting::ShouldLogNTimes("mulblock", 5)) {
std::string log;
for (size_t i = 0; i < candidates.size(); i++) {
log += " - " + candidates[i].ToString() + "\n";
}
WARN_LOG(G3D, "Multiple framebuffer candidates for %08x/%d/%d %d,%d %dx%d (dest = %d):\n%s", basePtr, stride_pixels, bpp, x_pixels, y, w_pixels, h, (int)destination, log.c_str());
}
WARN_LOG_N_TIMES(mulblock, 5, G3D, "Multiple framebuffer candidates for %08x/%d/%d %d,%d %dx%d (dest = %d):\n%s", basePtr, stride_pixels, bpp, x_pixels, y, w_pixels, h, (int)destination, log.c_str());
}
if (!candidates.empty()) {
// Pick the last candidate.
*rect = candidates.back();
*rect = *best;
return true;
} else {
if (Memory::IsVRAMAddress(basePtr) && destination && h >= 128) {
-4
View File
@@ -245,10 +245,6 @@ struct BlockTransferRect {
int x_pixels() const {
return x_bytes / BufferFormatBytesPerPixel(vfb->fb_format);
}
bool operator < (const BlockTransferRect &other) const {
return vfb->colorBindSeq < other.vfb->colorBindSeq;
}
};
namespace Draw {