rpcsx-gpu: initial cache implementation

This commit is contained in:
DH 2024-10-09 05:14:46 +03:00
parent 28e1b544e6
commit dd2ed74ff8
8 changed files with 984 additions and 389 deletions

View file

@ -0,0 +1,68 @@
#pragma once
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
namespace rx {
class AddressRange {
std::uint64_t mBeginAddress = -1;
std::uint64_t mEndAddress = 0;
public:
constexpr AddressRange() = default;
[[nodiscard]] static constexpr AddressRange
fromBeginSize(std::uint64_t begin, std::uint64_t size) {
AddressRange result;
result.mBeginAddress = begin;
result.mEndAddress = begin + size;
return result;
}
[[nodiscard]] static constexpr AddressRange fromBeginEnd(std::uint64_t begin,
std::uint64_t end) {
AddressRange result;
result.mBeginAddress = begin;
result.mEndAddress = end;
return result;
}
[[nodiscard]] constexpr bool isValid() const {
return mBeginAddress < mEndAddress;
}
constexpr explicit operator bool() const { return isValid(); }
[[nodiscard]] constexpr bool intersects(AddressRange other) const {
return mBeginAddress < other.mEndAddress &&
mEndAddress > other.mBeginAddress;
}
[[nodiscard]] constexpr bool contains(AddressRange other) const {
return mBeginAddress <= other.mBeginAddress &&
mEndAddress >= other.mEndAddress;
}
[[nodiscard]] constexpr bool contains(std::uint64_t address) const {
return address >= mBeginAddress && address < mEndAddress;
}
[[nodiscard]] constexpr AddressRange merge(AddressRange other) const {
return fromBeginEnd(std::min(mBeginAddress, other.mBeginAddress),
std::max(mEndAddress, other.mEndAddress));
}
[[nodiscard]] constexpr AddressRange intersection(AddressRange other) const {
return fromBeginEnd(std::max(mBeginAddress, other.mBeginAddress),
std::min(mEndAddress, other.mEndAddress));
}
[[nodiscard]] constexpr std::size_t size() const {
return mEndAddress - mBeginAddress;
}
[[nodiscard]] constexpr std::size_t beginAddress() const {
return mBeginAddress;
}
[[nodiscard]] constexpr std::size_t endAddress() const { return mEndAddress; }
constexpr bool operator==(const AddressRange &) const = default;
};
} // namespace rx

View file

@ -1,5 +1,6 @@
#pragma once
#include "rx/AddressRange.hpp"
#include <cassert>
#include <cstdint>
#include <map>
@ -232,6 +233,10 @@ public:
return {it->first, std::next(it)->first, it->second.second};
}
rx::AddressRange range() const {
return rx::AddressRange::fromBeginEnd(beginAddress(), endAddress());
}
std::uint64_t beginAddress() const { return it->first; }
std::uint64_t endAddress() const { return std::next(it)->first; }
std::uint64_t size() const { return endAddress() - beginAddress(); }
@ -307,7 +312,7 @@ public:
}
iterator map(std::uint64_t beginAddress, std::uint64_t endAddress,
PayloadT payload, bool merge = true) {
PayloadT payload, bool merge = true, bool noOverride = false) {
assert(beginAddress < endAddress);
auto [beginIt, beginInserted] =
mAreas.emplace(beginAddress, std::pair{Kind::O, payload});
@ -318,6 +323,10 @@ public:
bool endCollision = false;
bool lastRemovedIsOpen = false;
PayloadT lastRemovedOpenPayload;
if (noOverride && !beginInserted && !endInserted &&
std::next(beginIt) == endIt) {
return beginIt;
}
if (!beginInserted || !endInserted) {
if (!beginInserted) {