Retrieve heap size from MTLDevice on macOS and from free shared system memory on iOS.
This commit is contained in:
parent
6753d90ac4
commit
89e1c92845
@ -842,13 +842,7 @@ void MVKPhysicalDevice::initMemoryProperties() {
|
||||
|
||||
_memoryProperties.memoryHeapCount = 1;
|
||||
_memoryProperties.memoryHeaps[0].flags = (VK_MEMORY_HEAP_DEVICE_LOCAL_BIT);
|
||||
#if MVK_MACOS
|
||||
_memoryProperties.memoryHeaps[0].size = (VkDeviceSize)[_mtlDevice recommendedMaxWorkingSetSize];
|
||||
#else
|
||||
// TODO: determine heap size on iOS where recommenedMaxWorkingSetSize does not exist.
|
||||
_memoryProperties.memoryHeaps[0].size = 0;
|
||||
#endif
|
||||
|
||||
_memoryProperties.memoryHeaps[0].size = (VkDeviceSize)mvkRecommendedMaxWorkingSetSize(_mtlDevice);
|
||||
_memoryProperties.memoryTypes[0].heapIndex = 0;
|
||||
_memoryProperties.memoryTypes[0].propertyFlags = MVK_VK_MEMORY_TYPE_METAL_PRIVATE; // Private storage
|
||||
_memoryProperties.memoryTypes[1].heapIndex = 0;
|
||||
|
@ -99,3 +99,10 @@ MVKOSVersion mvkOSVersion(void);
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark MTLDevice
|
||||
|
||||
/** Returns an approximation of how much memory, in bytes, the device can use with good performance. */
|
||||
uint64_t mvkRecommendedMaxWorkingSetSize(id<MTLDevice> mtlDevice);
|
||||
|
||||
|
||||
|
@ -18,6 +18,10 @@
|
||||
|
||||
|
||||
#include "MVKOSExtensions.h"
|
||||
#include "MVKFoundation.h"
|
||||
|
||||
#import <mach/mach.h>
|
||||
#import <mach/mach_host.h>
|
||||
|
||||
|
||||
static const MVKOSVersion kMVKOSVersionUnknown = 0.0f;
|
||||
@ -99,3 +103,32 @@ MVKOSVersion mvkOSVersion() {
|
||||
|
||||
@end
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark MTLDevice
|
||||
|
||||
uint64_t mvkRecommendedMaxWorkingSetSize(id<MTLDevice> mtlDevice) {
|
||||
|
||||
#if MVK_MACOS
|
||||
if ( [mtlDevice respondsToSelector: @selector(recommendedMaxWorkingSetSize)]) {
|
||||
return mtlDevice.recommendedMaxWorkingSetSize;
|
||||
}
|
||||
#endif
|
||||
#if MVK_IOS
|
||||
// GPU and CPU use shared memory. Estimate the current free memory in the system.
|
||||
mach_port_t host_port;
|
||||
mach_msg_type_number_t host_size;
|
||||
vm_size_t pagesize;
|
||||
host_port = mach_host_self();
|
||||
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
|
||||
host_page_size(host_port, &pagesize);
|
||||
vm_statistics_data_t vm_stat;
|
||||
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&vm_stat, &host_size) == KERN_SUCCESS ) {
|
||||
return vm_stat.free_count * pagesize;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 128 * MEBI; // Conservative minimum for macOS GPU's & iOS shared memory
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user