mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-02-27 04:54:15 +01:00
[dxvk] Order allocations to relocate by offset
Potentially improves the situation where a chunk cannot be relocated in its entirely by freeing up a larger block of memory at the end of the chunk, which may be enough to service a subsequent defrag attempt of a different chunk.
This commit is contained in:
parent
8584fc7722
commit
c5bc4d1bac
@ -489,12 +489,12 @@ namespace dxvk {
|
|||||||
for (uint32_t i = 0; i < count; i++) {
|
for (uint32_t i = 0; i < count; i++) {
|
||||||
auto iter = m_entries.begin();
|
auto iter = m_entries.begin();
|
||||||
|
|
||||||
if (totalSize && totalSize + iter->second.size > size)
|
if (totalSize && totalSize + iter->first.size > size)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
totalSize += iter->second.size;
|
totalSize += iter->first.size;
|
||||||
|
|
||||||
result.push_back({ iter->first, iter->second.mode });
|
result.push_back(std::move(iter->second));
|
||||||
m_entries.erase(iter);
|
m_entries.erase(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,10 +504,12 @@ namespace dxvk {
|
|||||||
|
|
||||||
void DxvkRelocationList::addResource(
|
void DxvkRelocationList::addResource(
|
||||||
Rc<DxvkPagedResource>&& resource,
|
Rc<DxvkPagedResource>&& resource,
|
||||||
DxvkAllocationModes mode,
|
const DxvkResourceAllocation* allocation,
|
||||||
VkDeviceSize size) {
|
DxvkAllocationModes mode) {
|
||||||
std::lock_guard lock(m_mutex);
|
std::lock_guard lock(m_mutex);
|
||||||
m_entries.emplace(std::move(resource), Entry { mode, size });
|
m_entries.emplace(std::piecewise_construct,
|
||||||
|
std::forward_as_tuple(allocation->getMemoryInfo()),
|
||||||
|
std::forward_as_tuple(std::move(resource), mode));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2175,7 +2177,7 @@ namespace dxvk {
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Acquired the resource, add it to the relocation list.
|
// Acquired the resource, add it to the relocation list.
|
||||||
m_relocations.addResource(std::move(resource), mode, a->m_size);
|
m_relocations.addResource(std::move(resource), a, mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "dxvk_access.h"
|
#include "dxvk_access.h"
|
||||||
@ -985,6 +986,10 @@ namespace dxvk {
|
|||||||
* \brief Relocation entry
|
* \brief Relocation entry
|
||||||
*/
|
*/
|
||||||
struct DxvkRelocationEntry {
|
struct DxvkRelocationEntry {
|
||||||
|
DxvkRelocationEntry() = default;
|
||||||
|
DxvkRelocationEntry(Rc<DxvkPagedResource>&& r, DxvkAllocationModes m)
|
||||||
|
: resource(std::move(r)), mode(m) { }
|
||||||
|
|
||||||
/// Resource to relocate
|
/// Resource to relocate
|
||||||
Rc<DxvkPagedResource> resource;
|
Rc<DxvkPagedResource> resource;
|
||||||
/// Resource to relocate
|
/// Resource to relocate
|
||||||
@ -1023,13 +1028,13 @@ namespace dxvk {
|
|||||||
* \brief Adds relocation entry to the list
|
* \brief Adds relocation entry to the list
|
||||||
*
|
*
|
||||||
* \param [in] resource Resource to add
|
* \param [in] resource Resource to add
|
||||||
|
* \param [in] allocation Resource storage
|
||||||
* \param [in] mode Allocation mode
|
* \param [in] mode Allocation mode
|
||||||
* \param [in] size Allocation size
|
|
||||||
*/
|
*/
|
||||||
void addResource(
|
void addResource(
|
||||||
Rc<DxvkPagedResource>&& resource,
|
Rc<DxvkPagedResource>&& resource,
|
||||||
DxvkAllocationModes mode,
|
const DxvkResourceAllocation* allocation,
|
||||||
VkDeviceSize size);
|
DxvkAllocationModes mode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Clears list
|
* \brief Clears list
|
||||||
@ -1046,14 +1051,22 @@ namespace dxvk {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
struct Entry {
|
struct RelocationOrdering {
|
||||||
DxvkAllocationModes mode = 0u;
|
bool operator () (const DxvkResourceMemoryInfo& a, const DxvkResourceMemoryInfo& b) const {
|
||||||
VkDeviceSize size = 0u;
|
// Keep chunks together, then order by offset in order to increase
|
||||||
|
// the likelihood of freeing up a contiguous block of memory.
|
||||||
|
if (a.memory < b.memory) return true;
|
||||||
|
if (a.memory > b.memory) return false;
|
||||||
|
return a.offset > b.offset;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
dxvk::mutex m_mutex;
|
dxvk::mutex m_mutex;
|
||||||
std::unordered_map<Rc<DxvkPagedResource>,
|
|
||||||
Entry, RcHash> m_entries;
|
std::map<
|
||||||
|
DxvkResourceMemoryInfo,
|
||||||
|
DxvkRelocationEntry,
|
||||||
|
RelocationOrdering> m_entries;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user