mirror of
https://github.com/doitsujin/dxvk.git
synced 2024-12-14 09:23:53 +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:
parent
384a665700
commit
67d03aabd0
@ -31,10 +31,10 @@ namespace dxvk {
|
|||||||
Rc<T> retrieveObject() {
|
Rc<T> retrieveObject() {
|
||||||
std::lock_guard<dxvk::mutex> lock(m_mutex);
|
std::lock_guard<dxvk::mutex> lock(m_mutex);
|
||||||
|
|
||||||
if (m_objectId == 0)
|
if (m_get == m_put)
|
||||||
return nullptr;
|
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) {
|
void returnObject(const Rc<T>& object) {
|
||||||
std::lock_guard<dxvk::mutex> lock(m_mutex);
|
std::lock_guard<dxvk::mutex> lock(m_mutex);
|
||||||
|
|
||||||
if (m_objectId < N)
|
if (m_put - m_get < N)
|
||||||
m_objects.at(m_objectId++) = object;
|
m_objects[(m_put++) % N] = object;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
dxvk::mutex m_mutex;
|
dxvk::mutex m_mutex;
|
||||||
std::array<Rc<T>, N> m_objects;
|
std::array<Rc<T>, N> m_objects;
|
||||||
size_t m_objectId = 0;
|
|
||||||
|
uint64_t m_get = 0;
|
||||||
|
uint64_t m_put = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user