aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBas Nieuwenhuizen <[email protected]>2018-08-17 14:35:59 +0200
committerChia-I Wu <[email protected]>2019-03-11 10:01:33 -0700
commit7be2e1fc371979bd308d037cc8e45656b32b4bfd (patch)
tree6c4030ecc18284211829a2be5a1683e44c9d03c1 /src
parent462b693d943b8ba4cf80db9bc5238819ca798012 (diff)
turnip: Cargo cult the Intel heap size functionality.
Diffstat (limited to 'src')
-rw-r--r--src/freedreno/vulkan/tu_device.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/freedreno/vulkan/tu_device.c b/src/freedreno/vulkan/tu_device.c
index cbcc7977544..54385fefd23 100644
--- a/src/freedreno/vulkan/tu_device.c
+++ b/src/freedreno/vulkan/tu_device.c
@@ -34,6 +34,7 @@
#include <fcntl.h>
#include <stdbool.h>
#include <string.h>
+#include <sys/sysinfo.h>
#include <unistd.h>
#include <xf86drm.h>
@@ -875,11 +876,23 @@ tu_GetPhysicalDeviceQueueFamilyProperties2(
}
static uint64_t
-tu_get_system_memory_size()
+tu_get_system_heap_size()
{
- uint64_t pages = sysconf(_SC_PHYS_PAGES);
- uint64_t page_size = sysconf(_SC_PAGE_SIZE);
- return pages * page_size;
+ struct sysinfo info;
+ sysinfo(&info);
+
+ uint64_t total_ram = (uint64_t)info.totalram * (uint64_t)info.mem_unit;
+
+ /* We don't want to burn too much ram with the GPU. If the user has 4GiB
+ * or less, we use at most half. If they have more than 4GiB, we use 3/4.
+ */
+ uint64_t available_ram;
+ if (total_ram <= 4ull * 1024ull * 1024ull * 1024ull)
+ available_ram = total_ram / 2;
+ else
+ available_ram = total_ram * 3 / 4;
+
+ return available_ram;
}
void
@@ -888,7 +901,7 @@ tu_GetPhysicalDeviceMemoryProperties(
VkPhysicalDeviceMemoryProperties *pMemoryProperties)
{
pMemoryProperties->memoryHeapCount = 1;
- pMemoryProperties->memoryHeaps[0].size = tu_get_system_memory_size();
+ pMemoryProperties->memoryHeaps[0].size = tu_get_system_heap_size();
pMemoryProperties->memoryHeaps[0].flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
pMemoryProperties->memoryTypeCount = 1;