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:
parent
a4a4f5a822
commit
138dde6c3d
@ -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)
|
||||||
|
@ -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(),
|
||||||
|
@ -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(
|
||||||
|
@ -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);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user