1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-11-29 01:24:11 +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:
Philip Rebohle 2024-11-08 13:37:03 +01:00
parent 8584fc7722
commit c5bc4d1bac
2 changed files with 31 additions and 16 deletions

View File

@ -489,12 +489,12 @@ namespace dxvk {
for (uint32_t i = 0; i < count; i++) {
auto iter = m_entries.begin();
if (totalSize && totalSize + iter->second.size > size)
if (totalSize && totalSize + iter->first.size > size)
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);
}
@ -504,10 +504,12 @@ namespace dxvk {
void DxvkRelocationList::addResource(
Rc<DxvkPagedResource>&& resource,
DxvkAllocationModes mode,
VkDeviceSize size) {
const DxvkResourceAllocation* allocation,
DxvkAllocationModes mode) {
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;
// 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);
}
}

View File

@ -1,5 +1,6 @@
#pragma once
#include <map>
#include <memory>
#include "dxvk_access.h"
@ -985,6 +986,10 @@ namespace dxvk {
* \brief Relocation entry
*/
struct DxvkRelocationEntry {
DxvkRelocationEntry() = default;
DxvkRelocationEntry(Rc<DxvkPagedResource>&& r, DxvkAllocationModes m)
: resource(std::move(r)), mode(m) { }
/// Resource to relocate
Rc<DxvkPagedResource> resource;
/// Resource to relocate
@ -1023,13 +1028,13 @@ namespace dxvk {
* \brief Adds relocation entry to the list
*
* \param [in] resource Resource to add
* \param [in] allocation Resource storage
* \param [in] mode Allocation mode
* \param [in] size Allocation size
*/
void addResource(
Rc<DxvkPagedResource>&& resource,
DxvkAllocationModes mode,
VkDeviceSize size);
const DxvkResourceAllocation* allocation,
DxvkAllocationModes mode);
/**
* \brief Clears list
@ -1046,14 +1051,22 @@ namespace dxvk {
private:
struct Entry {
DxvkAllocationModes mode = 0u;
VkDeviceSize size = 0u;
struct RelocationOrdering {
bool operator () (const DxvkResourceMemoryInfo& a, const DxvkResourceMemoryInfo& b) const {
// 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;
std::unordered_map<Rc<DxvkPagedResource>,
Entry, RcHash> m_entries;
std::map<
DxvkResourceMemoryInfo,
DxvkRelocationEntry,
RelocationOrdering> m_entries;
};