mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-11-03 15:40:00 +00:00
Garbage Collection: Adress Feedback.
This commit is contained in:
parent
ba82bb359b
commit
ff48f06fb9
4 changed files with 23 additions and 17 deletions
|
@ -29,11 +29,11 @@ public:
|
||||||
~LeastRecentlyUsedCache() = default;
|
~LeastRecentlyUsedCache() = default;
|
||||||
|
|
||||||
size_t Insert(ObjectType obj, TickType tick) {
|
size_t Insert(ObjectType obj, TickType tick) {
|
||||||
const auto new_id = build();
|
const auto new_id = Build();
|
||||||
auto& item = item_pool[new_id];
|
auto& item = item_pool[new_id];
|
||||||
item.obj = obj;
|
item.obj = obj;
|
||||||
item.tick = tick;
|
item.tick = tick;
|
||||||
attach(item);
|
Attach(item);
|
||||||
return new_id;
|
return new_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,13 +46,13 @@ public:
|
||||||
if (&item == last_item) {
|
if (&item == last_item) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
detach(item);
|
Detach(item);
|
||||||
attach(item);
|
Attach(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Free(size_t id) {
|
void Free(size_t id) {
|
||||||
auto& item = item_pool[id];
|
auto& item = item_pool[id];
|
||||||
detach(item);
|
Detach(item);
|
||||||
item.prev = nullptr;
|
item.prev = nullptr;
|
||||||
item.next = nullptr;
|
item.next = nullptr;
|
||||||
free_items.push_back(id);
|
free_items.push_back(id);
|
||||||
|
@ -80,11 +80,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t build() {
|
size_t Build() {
|
||||||
if (free_items.empty()) {
|
if (free_items.empty()) {
|
||||||
const size_t item_id = item_pool.size();
|
const size_t item_id = item_pool.size();
|
||||||
item_pool.emplace_back();
|
auto& item = item_pool.emplace_back();
|
||||||
auto& item = item_pool[item_id];
|
|
||||||
item.next = nullptr;
|
item.next = nullptr;
|
||||||
item.prev = nullptr;
|
item.prev = nullptr;
|
||||||
return item_id;
|
return item_id;
|
||||||
|
@ -97,7 +96,7 @@ private:
|
||||||
return item_id;
|
return item_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
void attach(Item& item) {
|
void Attach(Item& item) {
|
||||||
if (!first_item) {
|
if (!first_item) {
|
||||||
first_item = &item;
|
first_item = &item;
|
||||||
}
|
}
|
||||||
|
@ -111,7 +110,7 @@ private:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void detach(Item& item) {
|
void Detach(Item& item) {
|
||||||
if (item.prev) {
|
if (item.prev) {
|
||||||
item.prev->next = item.next;
|
item.prev->next = item.next;
|
||||||
}
|
}
|
||||||
|
@ -134,8 +133,8 @@ private:
|
||||||
|
|
||||||
std::deque<Item> item_pool;
|
std::deque<Item> item_pool;
|
||||||
std::deque<size_t> free_items;
|
std::deque<size_t> free_items;
|
||||||
Item* first_item;
|
Item* first_item{};
|
||||||
Item* last_item;
|
Item* last_item{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
|
|
@ -297,7 +297,13 @@ public:
|
||||||
return words.size_bytes;
|
return words.size_bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t lru_id;
|
size_t getLRUID() const noexcept {
|
||||||
|
return lru_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setLRUID(size_t lru_id_) {
|
||||||
|
lru_id = lru_id_;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
template <Type type>
|
template <Type type>
|
||||||
|
@ -597,6 +603,7 @@ private:
|
||||||
Words words;
|
Words words;
|
||||||
BufferFlagBits flags{};
|
BufferFlagBits flags{};
|
||||||
int stream_score = 0;
|
int stream_score = 0;
|
||||||
|
size_t lru_id = SIZE_MAX;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace VideoCommon
|
} // namespace VideoCommon
|
||||||
|
|
|
@ -1539,10 +1539,10 @@ void BufferCache<P>::ChangeRegister(BufferId buffer_id) {
|
||||||
const auto size = buffer.SizeBytes();
|
const auto size = buffer.SizeBytes();
|
||||||
if (insert) {
|
if (insert) {
|
||||||
total_used_memory += Common::AlignUp(size, 1024);
|
total_used_memory += Common::AlignUp(size, 1024);
|
||||||
buffer.lru_id = lru_cache.Insert(buffer_id, frame_tick);
|
buffer.setLRUID(lru_cache.Insert(buffer_id, frame_tick));
|
||||||
} else {
|
} else {
|
||||||
total_used_memory -= Common::AlignUp(size, 1024);
|
total_used_memory -= Common::AlignUp(size, 1024);
|
||||||
lru_cache.Free(buffer.lru_id);
|
lru_cache.Free(buffer.getLRUID());
|
||||||
}
|
}
|
||||||
const VAddr cpu_addr_begin = buffer.CpuAddr();
|
const VAddr cpu_addr_begin = buffer.CpuAddr();
|
||||||
const VAddr cpu_addr_end = cpu_addr_begin + size;
|
const VAddr cpu_addr_end = cpu_addr_begin + size;
|
||||||
|
@ -1560,7 +1560,7 @@ void BufferCache<P>::ChangeRegister(BufferId buffer_id) {
|
||||||
template <class P>
|
template <class P>
|
||||||
void BufferCache<P>::TouchBuffer(Buffer& buffer, BufferId buffer_id) noexcept {
|
void BufferCache<P>::TouchBuffer(Buffer& buffer, BufferId buffer_id) noexcept {
|
||||||
if (buffer_id != NULL_BUFFER_ID) {
|
if (buffer_id != NULL_BUFFER_ID) {
|
||||||
lru_cache.Touch(buffer.lru_id, frame_tick);
|
lru_cache.Touch(buffer.getLRUID(), frame_tick);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ struct ImageBase {
|
||||||
VAddr cpu_addr_end = 0;
|
VAddr cpu_addr_end = 0;
|
||||||
|
|
||||||
u64 modification_tick = 0;
|
u64 modification_tick = 0;
|
||||||
size_t lru_index = ~0;
|
size_t lru_index = SIZE_MAX;
|
||||||
|
|
||||||
std::array<u32, MAX_MIP_LEVELS> mip_level_offsets{};
|
std::array<u32, MAX_MIP_LEVELS> mip_level_offsets{};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue