1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-20 10:54:16 +01:00

[dxvk] Add global resource map to memory allocator

This commit is contained in:
Philip Rebohle 2024-10-18 00:32:22 +02:00 committed by Philip Rebohle
parent 8e94a8bcc6
commit 9a8406f28a
4 changed files with 45 additions and 2 deletions

View File

@ -17,6 +17,8 @@ namespace dxvk {
m_shaderStages (util::shaderStages(createInfo.stages)),
m_sharingMode (device->getSharingMode()),
m_info (createInfo) {
m_allocator->registerResource(this);
// Create and assign actual buffer resource
assignStorage(allocateStorage());
}
@ -34,6 +36,8 @@ namespace dxvk {
m_shaderStages (util::shaderStages(createInfo.stages)),
m_sharingMode (device->getSharingMode()),
m_info (createInfo) {
m_allocator->registerResource(this);
DxvkAllocationInfo allocationInfo = { };
allocationInfo.resourceCookie = cookie();
@ -48,7 +52,7 @@ namespace dxvk {
DxvkBuffer::~DxvkBuffer() {
m_allocator->unregisterResource(this);
}

View File

@ -14,6 +14,8 @@ namespace dxvk {
m_properties (memFlags),
m_shaderStages (util::shaderStages(createInfo.stages)),
m_info (createInfo) {
m_allocator->registerResource(this);
copyFormatList(createInfo.viewFormatCount, createInfo.viewFormats);
// Always enable depth-stencil attachment usage for depth-stencil
@ -44,6 +46,8 @@ namespace dxvk {
m_properties (memFlags),
m_shaderStages (util::shaderStages(createInfo.stages)),
m_info (createInfo) {
m_allocator->registerResource(this);
copyFormatList(createInfo.viewFormatCount, createInfo.viewFormats);
// Create backing storage for existing image resource
@ -56,7 +60,7 @@ namespace dxvk {
DxvkImage::~DxvkImage() {
m_allocator->unregisterResource(this);
}

View File

@ -1848,6 +1848,20 @@ namespace dxvk {
}
void DxvkMemoryAllocator::registerResource(
DxvkPagedResource* resource) {
std::lock_guard lock(m_resourceMutex);
m_resourceMap.emplace(resource->cookie(), resource);
}
void DxvkMemoryAllocator::unregisterResource(
DxvkPagedResource* resource) {
std::lock_guard lock(m_resourceMutex);
m_resourceMap.erase(resource->cookie());
}
VkDeviceAddress DxvkMemoryAllocator::getBufferDeviceAddress(VkBuffer buffer) const {
auto vk = m_device->vkd();

View File

@ -16,6 +16,7 @@ namespace dxvk {
class DxvkSparsePageTable;
class DxvkSharedAllocationCache;
class DxvkResourceAllocation;
class DxvkPagedResource;
/**
* \brief Memory stats
@ -1117,6 +1118,22 @@ namespace dxvk {
const VkImageCreateInfo& createInfo,
VkMemoryRequirements2& memoryRequirements) const;
/**
* \brief Registers a paged resource with cookie
*
* Useful when the allocator needs to track resources.
* \param [in] resource Resource to add
*/
void registerResource(
DxvkPagedResource* resource);
/**
* \brief Unregisters a paged resource
* \param [in] resource Resource to remove
*/
void unregisterResource(
DxvkPagedResource* resource);
/**
* \brief Performs clean-up tasks
*
@ -1153,6 +1170,10 @@ namespace dxvk {
high_resolution_clock::time_point m_taskDeadline = { };
std::array<DxvkMemoryStats, VK_MAX_MEMORY_HEAPS> m_adapterHeapStats = { };
alignas(CACHE_LINE_SIZE)
dxvk::mutex m_resourceMutex;
std::unordered_map<uint64_t, DxvkPagedResource*> m_resourceMap;
DxvkDeviceMemory allocateDeviceMemory(
DxvkMemoryType& type,
VkDeviceSize size,