Merge pull request #2098 from SRSaunders/heapquery-fix

Fix heapUsage query for non-unified memory devices
This commit is contained in:
Chip Davis 2023-12-16 14:19:19 -08:00 committed by GitHub
commit 793c7cf34d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 3 deletions

View File

@ -134,7 +134,13 @@ uint64_t mvkGetUsedMemorySize() {
task_vm_info_data_t task_vm_info;
mach_msg_type_number_t task_size = TASK_VM_INFO_COUNT;
if (task_info(mach_task_self(), TASK_VM_INFO, (task_info_t)&task_vm_info, &task_size) == KERN_SUCCESS) {
return task_vm_info.phys_footprint;
#ifdef TASK_VM_INFO_REV3_COUNT // check for rev3 version of task_vm_info
if (task_size >= TASK_VM_INFO_REV3_COUNT) {
return task_vm_info.ledger_tag_graphics_footprint;
}
else
#endif
return task_vm_info.phys_footprint;
}
return 0;
}

View File

@ -1650,12 +1650,17 @@ VkResult MVKPhysicalDevice::getMemoryProperties(VkPhysicalDeviceMemoryProperties
auto* budgetProps = (VkPhysicalDeviceMemoryBudgetPropertiesEXT*)next;
mvkClear(budgetProps->heapBudget, VK_MAX_MEMORY_HEAPS);
mvkClear(budgetProps->heapUsage, VK_MAX_MEMORY_HEAPS);
budgetProps->heapBudget[0] = (VkDeviceSize)getRecommendedMaxWorkingSetSize();
budgetProps->heapUsage[0] = (VkDeviceSize)getCurrentAllocatedSize();
if (!getHasUnifiedMemory()) {
budgetProps->heapBudget[1] = (VkDeviceSize)mvkGetAvailableMemorySize();
budgetProps->heapUsage[1] = (VkDeviceSize)mvkGetUsedMemorySize();
}
budgetProps->heapBudget[0] = (VkDeviceSize)getRecommendedMaxWorkingSetSize();
auto currentAllocatedSize = (VkDeviceSize)getCurrentAllocatedSize();
if (budgetProps->heapUsage[1] > currentAllocatedSize) {
// mapped memory can't be larger than total memory, so ignore and zero-out
budgetProps->heapUsage[1] = 0;
}
budgetProps->heapUsage[0] = currentAllocatedSize - budgetProps->heapUsage[1];
break;
}
default: