1
0
mirror of https://github.com/EduApps-CDG/OpenDX synced 2024-12-30 09:45:37 +01:00

[dxvk] Prefer VRAM allocation over dedicated sysmem allocation

May in some cases improve performance when under memory pressure:
If a dedicated allocation is preferred, but the alloaction fails,
try to allocate memory from an already allocated chunk instead
of falling back to system memory right away.
This commit is contained in:
Philip Rebohle 2019-06-20 10:32:00 +02:00
parent a4a4f5a822
commit 138dde6c3d
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
4 changed files with 19 additions and 11 deletions

View File

@ -91,10 +91,8 @@ namespace dxvk {
float priority = isGpuWritable ? 1.0f : 0.5f; float priority = isGpuWritable ? 1.0f : 0.5f;
// Ask driver whether we should be using a dedicated allocation // Ask driver whether we should be using a dedicated allocation
bool useDedicated = dedicatedRequirements.prefersDedicatedAllocation;
handle.memory = m_memAlloc->alloc(&memReq.memoryRequirements, handle.memory = m_memAlloc->alloc(&memReq.memoryRequirements,
useDedicated ? &dedMemoryAllocInfo : nullptr, m_memFlags, priority); dedicatedRequirements, dedMemoryAllocInfo, m_memFlags, priority);
if (vkd->vkBindBufferMemory(vkd->device(), handle.buffer, if (vkd->vkBindBufferMemory(vkd->device(), handle.buffer,
handle.memory.memory(), handle.memory.offset()) != VK_SUCCESS) handle.memory.memory(), handle.memory.offset()) != VK_SUCCESS)

View File

@ -98,10 +98,8 @@ namespace dxvk {
float priority = isGpuWritable ? 1.0f : 0.5f; float priority = isGpuWritable ? 1.0f : 0.5f;
// Ask driver whether we should be using a dedicated allocation // Ask driver whether we should be using a dedicated allocation
bool useDedicated = dedicatedRequirements.prefersDedicatedAllocation;
m_memory = memAlloc.alloc(&memReq.memoryRequirements, m_memory = memAlloc.alloc(&memReq.memoryRequirements,
useDedicated ? &dedMemoryAllocInfo : nullptr, memFlags, priority); dedicatedRequirements, dedMemoryAllocInfo, memFlags, priority);
// Try to bind the allocated memory slice to the image // Try to bind the allocated memory slice to the image
if (m_vkd->vkBindImageMemory(m_vkd->device(), if (m_vkd->vkBindImageMemory(m_vkd->device(),

View File

@ -181,18 +181,28 @@ namespace dxvk {
DxvkMemory DxvkMemoryAllocator::alloc( DxvkMemory DxvkMemoryAllocator::alloc(
const VkMemoryRequirements* req, const VkMemoryRequirements* req,
const VkMemoryDedicatedAllocateInfoKHR* dedAllocInfo, const VkMemoryDedicatedRequirements& dedAllocReq,
const VkMemoryDedicatedAllocateInfoKHR& dedAllocInfo,
VkMemoryPropertyFlags flags, VkMemoryPropertyFlags flags,
float priority) { float priority) {
std::lock_guard<std::mutex> lock(m_mutex); std::lock_guard<std::mutex> lock(m_mutex);
// Try to allocate from a memory type which supports the given flags exactly
auto dedAllocPtr = dedAllocReq.prefersDedicatedAllocation ? &dedAllocInfo : nullptr;
DxvkMemory result = this->tryAlloc(req, dedAllocPtr, flags, priority);
// If the first attempt failed, try ignoring the dedicated allocation
if (!result && dedAllocPtr && !dedAllocReq.requiresDedicatedAllocation) {
result = this->tryAlloc(req, nullptr, flags, priority);
dedAllocPtr = nullptr;
}
// If that still didn't work, probe slower memory types as well
VkMemoryPropertyFlags optFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT VkMemoryPropertyFlags optFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
| VK_MEMORY_PROPERTY_HOST_CACHED_BIT; | VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
DxvkMemory result = this->tryAlloc(req, dedAllocInfo, flags, priority);
if (!result && (flags & optFlags)) if (!result && (flags & optFlags))
result = this->tryAlloc(req, dedAllocInfo, flags & ~optFlags, priority); result = this->tryAlloc(req, dedAllocPtr, flags & ~optFlags, priority);
if (!result) { if (!result) {
Logger::err(str::format( Logger::err(str::format(

View File

@ -239,6 +239,7 @@ namespace dxvk {
* \brief Allocates device memory * \brief Allocates device memory
* *
* \param [in] req Memory requirements * \param [in] req Memory requirements
* \param [in] dedAllocReq Dedicated allocation requirements
* \param [in] dedAllocInfo Dedicated allocation info * \param [in] dedAllocInfo Dedicated allocation info
* \param [in] flags Memory type flags * \param [in] flags Memory type flags
* \param [in] priority Device-local memory priority * \param [in] priority Device-local memory priority
@ -246,7 +247,8 @@ namespace dxvk {
*/ */
DxvkMemory alloc( DxvkMemory alloc(
const VkMemoryRequirements* req, const VkMemoryRequirements* req,
const VkMemoryDedicatedAllocateInfoKHR* dedAllocInfo, const VkMemoryDedicatedRequirements& dedAllocReq,
const VkMemoryDedicatedAllocateInfoKHR& dedAllocInfo,
VkMemoryPropertyFlags flags, VkMemoryPropertyFlags flags,
float priority); float priority);