mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-12-26 04:00:06 +00:00
buffer_cache: Minor style changes
Minor style changes. Mostly done so I avoid editing it while doing other changes.
This commit is contained in:
parent
cf4ee279c6
commit
599274e3f0
@ -40,14 +40,12 @@ public:
|
|||||||
bool is_written = false, bool use_fast_cbuf = false) {
|
bool is_written = false, bool use_fast_cbuf = false) {
|
||||||
std::lock_guard lock{mutex};
|
std::lock_guard lock{mutex};
|
||||||
|
|
||||||
const std::optional<VAddr> cpu_addr_opt =
|
const auto& memory_manager = system.GPU().MemoryManager();
|
||||||
system.GPU().MemoryManager().GpuToCpuAddress(gpu_addr);
|
const std::optional<VAddr> cpu_addr_opt = memory_manager.GpuToCpuAddress(gpu_addr);
|
||||||
|
|
||||||
if (!cpu_addr_opt) {
|
if (!cpu_addr_opt) {
|
||||||
return {GetEmptyBuffer(size), 0};
|
return {GetEmptyBuffer(size), 0};
|
||||||
}
|
}
|
||||||
|
const VAddr cpu_addr = *cpu_addr_opt;
|
||||||
VAddr cpu_addr = *cpu_addr_opt;
|
|
||||||
|
|
||||||
// Cache management is a big overhead, so only cache entries with a given size.
|
// Cache management is a big overhead, so only cache entries with a given size.
|
||||||
// TODO: Figure out which size is the best for given games.
|
// TODO: Figure out which size is the best for given games.
|
||||||
@ -84,9 +82,9 @@ public:
|
|||||||
if (Settings::IsGPULevelHigh() && Settings::values.use_asynchronous_gpu_emulation) {
|
if (Settings::IsGPULevelHigh() && Settings::values.use_asynchronous_gpu_emulation) {
|
||||||
MarkForAsyncFlush(map);
|
MarkForAsyncFlush(map);
|
||||||
}
|
}
|
||||||
if (!map->IsWritten()) {
|
if (!map->is_written) {
|
||||||
map->MarkAsWritten(true);
|
map->is_written = true;
|
||||||
MarkRegionAsWritten(map->GetStart(), map->GetEnd() - 1);
|
MarkRegionAsWritten(map->start, map->end - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,11 +131,11 @@ public:
|
|||||||
std::lock_guard lock{mutex};
|
std::lock_guard lock{mutex};
|
||||||
|
|
||||||
std::vector<MapInterval> objects = GetMapsInRange(addr, size);
|
std::vector<MapInterval> objects = GetMapsInRange(addr, size);
|
||||||
std::sort(objects.begin(), objects.end(), [](const MapInterval& a, const MapInterval& b) {
|
std::sort(
|
||||||
return a->GetModificationTick() < b->GetModificationTick();
|
objects.begin(), objects.end(),
|
||||||
});
|
[](const MapInterval& lhs, const MapInterval& rhs) { return lhs->ticks < rhs->ticks; });
|
||||||
for (auto& object : objects) {
|
for (auto& object : objects) {
|
||||||
if (object->IsModified() && object->IsRegistered()) {
|
if (object->is_modified && object->is_registered) {
|
||||||
mutex.unlock();
|
mutex.unlock();
|
||||||
FlushMap(object);
|
FlushMap(object);
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
@ -150,7 +148,7 @@ public:
|
|||||||
|
|
||||||
const std::vector<MapInterval> objects = GetMapsInRange(addr, size);
|
const std::vector<MapInterval> objects = GetMapsInRange(addr, size);
|
||||||
return std::any_of(objects.cbegin(), objects.cend(), [](const MapInterval& map) {
|
return std::any_of(objects.cbegin(), objects.cend(), [](const MapInterval& map) {
|
||||||
return map->IsModified() && map->IsRegistered();
|
return map->is_modified && map->is_registered;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,7 +158,7 @@ public:
|
|||||||
|
|
||||||
std::vector<MapInterval> objects = GetMapsInRange(addr, size);
|
std::vector<MapInterval> objects = GetMapsInRange(addr, size);
|
||||||
for (auto& object : objects) {
|
for (auto& object : objects) {
|
||||||
if (object->IsRegistered()) {
|
if (object->is_registered) {
|
||||||
Unregister(object);
|
Unregister(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,9 +168,9 @@ public:
|
|||||||
std::lock_guard lock{mutex};
|
std::lock_guard lock{mutex};
|
||||||
|
|
||||||
for (const auto& object : GetMapsInRange(addr, size)) {
|
for (const auto& object : GetMapsInRange(addr, size)) {
|
||||||
if (object->IsMemoryMarked() && object->IsRegistered()) {
|
if (object->is_memory_marked && object->is_registered) {
|
||||||
UnmarkMemory(object);
|
UnmarkMemory(object);
|
||||||
object->SetSyncPending(true);
|
object->is_sync_pending = true;
|
||||||
marked_for_unregister.emplace_back(object);
|
marked_for_unregister.emplace_back(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,8 +180,8 @@ public:
|
|||||||
std::lock_guard lock{mutex};
|
std::lock_guard lock{mutex};
|
||||||
|
|
||||||
for (const auto& object : marked_for_unregister) {
|
for (const auto& object : marked_for_unregister) {
|
||||||
if (object->IsRegistered()) {
|
if (object->is_registered) {
|
||||||
object->SetSyncPending(false);
|
object->is_sync_pending = false;
|
||||||
Unregister(object);
|
Unregister(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -194,7 +192,7 @@ public:
|
|||||||
if (uncommitted_flushes) {
|
if (uncommitted_flushes) {
|
||||||
auto commit_list = std::make_shared<std::list<MapInterval>>();
|
auto commit_list = std::make_shared<std::list<MapInterval>>();
|
||||||
for (auto& map : *uncommitted_flushes) {
|
for (auto& map : *uncommitted_flushes) {
|
||||||
if (map->IsRegistered() && map->IsModified()) {
|
if (map->is_registered && map->is_modified) {
|
||||||
// TODO(Blinkhawk): Implement backend asynchronous flushing
|
// TODO(Blinkhawk): Implement backend asynchronous flushing
|
||||||
// AsyncFlushMap(map)
|
// AsyncFlushMap(map)
|
||||||
commit_list->push_back(map);
|
commit_list->push_back(map);
|
||||||
@ -229,7 +227,7 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (MapInterval& map : *flush_list) {
|
for (MapInterval& map : *flush_list) {
|
||||||
if (map->IsRegistered()) {
|
if (map->is_registered) {
|
||||||
// TODO(Blinkhawk): Replace this for reading the asynchronous flush
|
// TODO(Blinkhawk): Replace this for reading the asynchronous flush
|
||||||
FlushMap(map);
|
FlushMap(map);
|
||||||
}
|
}
|
||||||
@ -266,45 +264,45 @@ protected:
|
|||||||
|
|
||||||
/// Register an object into the cache
|
/// Register an object into the cache
|
||||||
void Register(const MapInterval& new_map, bool inherit_written = false) {
|
void Register(const MapInterval& new_map, bool inherit_written = false) {
|
||||||
const VAddr cpu_addr = new_map->GetStart();
|
const VAddr cpu_addr = new_map->start;
|
||||||
if (!cpu_addr) {
|
if (!cpu_addr) {
|
||||||
LOG_CRITICAL(HW_GPU, "Failed to register buffer with unmapped gpu_address 0x{:016x}",
|
LOG_CRITICAL(HW_GPU, "Failed to register buffer with unmapped gpu_address 0x{:016x}",
|
||||||
new_map->GetGpuAddress());
|
new_map->gpu_addr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const std::size_t size = new_map->GetEnd() - new_map->GetStart();
|
const std::size_t size = new_map->end - new_map->start;
|
||||||
new_map->MarkAsRegistered(true);
|
new_map->is_registered = true;
|
||||||
const IntervalType interval{new_map->GetStart(), new_map->GetEnd()};
|
const IntervalType interval{new_map->start, new_map->end};
|
||||||
mapped_addresses.insert({interval, new_map});
|
mapped_addresses.insert({interval, new_map});
|
||||||
rasterizer.UpdatePagesCachedCount(cpu_addr, size, 1);
|
rasterizer.UpdatePagesCachedCount(cpu_addr, size, 1);
|
||||||
new_map->SetMemoryMarked(true);
|
new_map->is_memory_marked = true;
|
||||||
if (inherit_written) {
|
if (inherit_written) {
|
||||||
MarkRegionAsWritten(new_map->GetStart(), new_map->GetEnd() - 1);
|
MarkRegionAsWritten(new_map->start, new_map->end - 1);
|
||||||
new_map->MarkAsWritten(true);
|
new_map->is_written = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnmarkMemory(const MapInterval& map) {
|
void UnmarkMemory(const MapInterval& map) {
|
||||||
if (!map->IsMemoryMarked()) {
|
if (!map->is_memory_marked) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const std::size_t size = map->GetEnd() - map->GetStart();
|
const std::size_t size = map->end - map->start;
|
||||||
rasterizer.UpdatePagesCachedCount(map->GetStart(), size, -1);
|
rasterizer.UpdatePagesCachedCount(map->start, size, -1);
|
||||||
map->SetMemoryMarked(false);
|
map->is_memory_marked = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unregisters an object from the cache
|
/// Unregisters an object from the cache
|
||||||
void Unregister(const MapInterval& map) {
|
void Unregister(const MapInterval& map) {
|
||||||
UnmarkMemory(map);
|
UnmarkMemory(map);
|
||||||
map->MarkAsRegistered(false);
|
map->is_registered = false;
|
||||||
if (map->IsSyncPending()) {
|
if (map->is_sync_pending) {
|
||||||
|
map->is_sync_pending = false;
|
||||||
marked_for_unregister.remove(map);
|
marked_for_unregister.remove(map);
|
||||||
map->SetSyncPending(false);
|
|
||||||
}
|
}
|
||||||
if (map->IsWritten()) {
|
if (map->is_written) {
|
||||||
UnmarkRegionAsWritten(map->GetStart(), map->GetEnd() - 1);
|
UnmarkRegionAsWritten(map->start, map->end - 1);
|
||||||
}
|
}
|
||||||
const IntervalType delete_interval{map->GetStart(), map->GetEnd()};
|
const IntervalType delete_interval{map->start, map->end};
|
||||||
mapped_addresses.erase(delete_interval);
|
mapped_addresses.erase(delete_interval);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,10 +343,10 @@ private:
|
|||||||
bool modified_inheritance = false;
|
bool modified_inheritance = false;
|
||||||
// Calculate new buffer parameters
|
// Calculate new buffer parameters
|
||||||
for (auto& overlap : overlaps) {
|
for (auto& overlap : overlaps) {
|
||||||
new_start = std::min(overlap->GetStart(), new_start);
|
new_start = std::min(overlap->start, new_start);
|
||||||
new_end = std::max(overlap->GetEnd(), new_end);
|
new_end = std::max(overlap->end, new_end);
|
||||||
write_inheritance |= overlap->IsWritten();
|
write_inheritance |= overlap->is_written;
|
||||||
modified_inheritance |= overlap->IsModified();
|
modified_inheritance |= overlap->is_modified;
|
||||||
}
|
}
|
||||||
GPUVAddr new_gpu_addr = gpu_addr + new_start - cpu_addr;
|
GPUVAddr new_gpu_addr = gpu_addr + new_start - cpu_addr;
|
||||||
for (auto& overlap : overlaps) {
|
for (auto& overlap : overlaps) {
|
||||||
@ -372,7 +370,7 @@ private:
|
|||||||
IntervalSet interval_set{};
|
IntervalSet interval_set{};
|
||||||
interval_set.add(base_interval);
|
interval_set.add(base_interval);
|
||||||
for (auto& overlap : overlaps) {
|
for (auto& overlap : overlaps) {
|
||||||
const IntervalType subtract{overlap->GetStart(), overlap->GetEnd()};
|
const IntervalType subtract{overlap->start, overlap->end};
|
||||||
interval_set.subtract(subtract);
|
interval_set.subtract(subtract);
|
||||||
}
|
}
|
||||||
for (auto& interval : interval_set) {
|
for (auto& interval : interval_set) {
|
||||||
@ -406,11 +404,11 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FlushMap(MapInterval map) {
|
void FlushMap(MapInterval map) {
|
||||||
std::size_t size = map->GetEnd() - map->GetStart();
|
std::size_t size = map->end - map->start;
|
||||||
OwnerBuffer block = blocks[map->GetStart() >> block_page_bits];
|
OwnerBuffer block = blocks[map->start >> block_page_bits];
|
||||||
staging_buffer.resize(size);
|
staging_buffer.resize(size);
|
||||||
DownloadBlockData(block, block->GetOffset(map->GetStart()), size, staging_buffer.data());
|
DownloadBlockData(block, block->GetOffset(map->start), size, staging_buffer.data());
|
||||||
system.Memory().WriteBlockUnsafe(map->GetStart(), staging_buffer.data(), size);
|
system.Memory().WriteBlockUnsafe(map->start, staging_buffer.data(), size);
|
||||||
map->MarkAsModified(false, 0);
|
map->MarkAsModified(false, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -515,7 +513,7 @@ private:
|
|||||||
} else {
|
} else {
|
||||||
written_pages[page_start] = 1;
|
written_pages[page_start] = 1;
|
||||||
}
|
}
|
||||||
page_start++;
|
++page_start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -531,7 +529,7 @@ private:
|
|||||||
written_pages.erase(it);
|
written_pages.erase(it);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
page_start++;
|
++page_start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -542,7 +540,7 @@ private:
|
|||||||
if (written_pages.count(page_start) > 0) {
|
if (written_pages.count(page_start) > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
page_start++;
|
++page_start;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -585,7 +583,7 @@ private:
|
|||||||
std::vector<u8> staging_buffer;
|
std::vector<u8> staging_buffer;
|
||||||
std::list<MapInterval> marked_for_unregister;
|
std::list<MapInterval> marked_for_unregister;
|
||||||
|
|
||||||
std::shared_ptr<std::unordered_set<MapInterval>> uncommitted_flushes{};
|
std::shared_ptr<std::unordered_set<MapInterval>> uncommitted_flushes;
|
||||||
std::list<std::shared_ptr<std::list<MapInterval>>> committed_flushes;
|
std::list<std::shared_ptr<std::list<MapInterval>>> committed_flushes;
|
||||||
|
|
||||||
std::recursive_mutex mutex;
|
std::recursive_mutex mutex;
|
||||||
|
@ -9,99 +9,37 @@
|
|||||||
|
|
||||||
namespace VideoCommon {
|
namespace VideoCommon {
|
||||||
|
|
||||||
class MapIntervalBase {
|
struct MapIntervalBase {
|
||||||
public:
|
constexpr explicit MapIntervalBase(VAddr start, VAddr end, GPUVAddr gpu_addr) noexcept
|
||||||
MapIntervalBase(const VAddr start, const VAddr end, const GPUVAddr gpu_addr)
|
|
||||||
: start{start}, end{end}, gpu_addr{gpu_addr} {}
|
: start{start}, end{end}, gpu_addr{gpu_addr} {}
|
||||||
|
|
||||||
void SetCpuAddress(VAddr new_cpu_addr) {
|
constexpr bool IsInside(const VAddr other_start, const VAddr other_end) const noexcept {
|
||||||
cpu_addr = new_cpu_addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
VAddr GetCpuAddress() const {
|
|
||||||
return cpu_addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
GPUVAddr GetGpuAddress() const {
|
|
||||||
return gpu_addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsInside(const VAddr other_start, const VAddr other_end) const {
|
|
||||||
return (start <= other_start && other_end <= end);
|
return (start <= other_start && other_end <= end);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const MapIntervalBase& rhs) const {
|
constexpr void MarkAsModified(bool is_modified_, u64 ticks_) noexcept {
|
||||||
return std::tie(start, end) == std::tie(rhs.start, rhs.end);
|
is_modified = is_modified_;
|
||||||
|
ticks = ticks_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const MapIntervalBase& rhs) const {
|
constexpr bool operator==(const MapIntervalBase& rhs) const noexcept {
|
||||||
|
return start == rhs.start && end == rhs.end;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr bool operator!=(const MapIntervalBase& rhs) const noexcept {
|
||||||
return !operator==(rhs);
|
return !operator==(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MarkAsRegistered(const bool registered) {
|
|
||||||
is_registered = registered;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsRegistered() const {
|
|
||||||
return is_registered;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetMemoryMarked(bool is_memory_marked_) {
|
|
||||||
is_memory_marked = is_memory_marked_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsMemoryMarked() const {
|
|
||||||
return is_memory_marked;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SetSyncPending(bool is_sync_pending_) {
|
|
||||||
is_sync_pending = is_sync_pending_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsSyncPending() const {
|
|
||||||
return is_sync_pending;
|
|
||||||
}
|
|
||||||
|
|
||||||
VAddr GetStart() const {
|
|
||||||
return start;
|
|
||||||
}
|
|
||||||
|
|
||||||
VAddr GetEnd() const {
|
|
||||||
return end;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MarkAsModified(const bool is_modified_, const u64 tick) {
|
|
||||||
is_modified = is_modified_;
|
|
||||||
ticks = tick;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsModified() const {
|
|
||||||
return is_modified;
|
|
||||||
}
|
|
||||||
|
|
||||||
u64 GetModificationTick() const {
|
|
||||||
return ticks;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MarkAsWritten(const bool is_written_) {
|
|
||||||
is_written = is_written_;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsWritten() const {
|
|
||||||
return is_written;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
VAddr start;
|
VAddr start;
|
||||||
VAddr end;
|
VAddr end;
|
||||||
GPUVAddr gpu_addr;
|
GPUVAddr gpu_addr;
|
||||||
VAddr cpu_addr{};
|
VAddr cpu_addr = 0;
|
||||||
bool is_written{};
|
u64 ticks = 0;
|
||||||
bool is_modified{};
|
bool is_written = false;
|
||||||
bool is_registered{};
|
bool is_modified = false;
|
||||||
bool is_memory_marked{};
|
bool is_registered = false;
|
||||||
bool is_sync_pending{};
|
bool is_memory_marked = false;
|
||||||
u64 ticks{};
|
bool is_sync_pending = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace VideoCommon
|
} // namespace VideoCommon
|
||||||
|
Loading…
Reference in New Issue
Block a user