1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-13 07:08:50 +01:00

[dxvk] Make recycler a ring buffer

Ensures that recycled objects actually get reused soon. Somewhat
important for memory efficiency in descriptor pools.
This commit is contained in:
Philip Rebohle 2022-06-21 19:14:32 +02:00
parent 384a665700
commit 67d03aabd0
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99

View File

@ -31,10 +31,10 @@ namespace dxvk {
Rc<T> retrieveObject() {
std::lock_guard<dxvk::mutex> lock(m_mutex);
if (m_objectId == 0)
if (m_get == m_put)
return nullptr;
return m_objects.at(--m_objectId);
return std::exchange(m_objects[(m_get++) % N], Rc<T>());
}
/**
@ -48,15 +48,17 @@ namespace dxvk {
void returnObject(const Rc<T>& object) {
std::lock_guard<dxvk::mutex> lock(m_mutex);
if (m_objectId < N)
m_objects.at(m_objectId++) = object;
if (m_put - m_get < N)
m_objects[(m_put++) % N] = object;
}
private:
dxvk::mutex m_mutex;
std::array<Rc<T>, N> m_objects;
size_t m_objectId = 0;
dxvk::mutex m_mutex;
std::array<Rc<T>, N> m_objects;
uint64_t m_get = 0;
uint64_t m_put = 0;
};