<div dir="auto"><div><div class="gmail_extra"><div class="gmail_quote">18 mar 2017 05:24 "Jason Ekstrand" <<a href="mailto:jason@jlekstrand.net">jason@jlekstrand.net</a>> napisał(a):<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Instead of just advertising the aperture size, we do something more<br>
intelligent.  On systems with a full 48-bit PPGTT, we can address 100%<br>
of the available system RAM from the GPU.  In order to keep clients from<br>
burning 100% of your available RAM for graphics resources, we have a<br>
nice little heuristic (which has received exactly zero tuning) to keep<br>
things under a reasonable level of control.<br>
<br>
Cc: Alex Smith <<a href="mailto:asmith@feralinteractive.com">asmith@feralinteractive.com</a>><br>
---<br>
 src/intel/vulkan/anv_device.c  | 61 ++++++++++++++++++++++++++++++<wbr>+++---------<br>
 src/intel/vulkan/anv_gem.c     | 16 +++++++++++<br>
 src/intel/vulkan/anv_private.h | 13 ++++++++-<br>
 3 files changed, 76 insertions(+), 14 deletions(-)<br>
<br>
diff --git a/src/intel/vulkan/anv_device.<wbr>c b/src/intel/vulkan/anv_device.<wbr>c<br>
index 8994e70..fd71a23 100644<br>
--- a/src/intel/vulkan/anv_device.<wbr>c<br>
+++ b/src/intel/vulkan/anv_device.<wbr>c<br>
@@ -25,6 +25,7 @@<br>
 #include <stdbool.h><br>
 #include <string.h><br>
 #include <sys/mman.h><br>
+#include <sys/sysinfo.h><br>
 #include <unistd.h><br>
 #include <fcntl.h><br>
 #include <xf86drm.h><br>
@@ -53,6 +54,48 @@ compiler_perf_log(void *data, const char *fmt, ...)<br>
    va_end(args);<br>
 }<br>
<br>
+static VkResult<br>
+anv_compute_heap_size(int fd, uint64_t *heap_size)<br>
+{<br>
+   uint64_t gtt_size;<br>
+   if (anv_gem_get_context_param(fd, 0, I915_CONTEXT_PARAM_GTT_SIZE,<br>
+                                 &gtt_size) == -1) {<br>
+      /* If, for whatever reason, we can't actually get the GTT size from the<br>
+       * kernel (too old?) fall back to the aperture size.<br>
+       */<br>
+      anv_perf_warn("Failed to get I915_CONTEXT_PARAM_GTT_SIZE: %m");<br>
+<br>
+      if (anv_gem_get_aperture(fd, &gtt_size) == -1) {<br>
+         return vk_errorf(VK_ERROR_<wbr>INITIALIZATION_FAILED,<br>
+                          "failed to get aperture size: %m");<br>
+      }<br>
+   }<br>
+<br>
+   /* Query the total ram from the system */<br>
+   struct sysinfo info;<br>
+   sysinfo(&info);<br>
+<br>
+   uint64_t total_ram = (uint64_t)info.totalram * (uint64_t)info.mem_unit;<br>
+<br>
+   /* We don't want to burn too much ram with the GPU.  If the user has 4GiB<br>
+    * or less, we use at most half.  If they have more than 4GiB, we use 3/4.<br>
+    */<br>
+   uint64_t available_ram;<br>
+   if (total_ram < 4ull * 1024ull * 1024ull * 1024ull)<br>
+      available_ram = total_ram / 2;<br>
+   else<br>
+      available_ram = total_ram * 3 / 4;<br></blockquote></div></div></div><div dir="auto"><br></div><div dir="auto">This will result in 3/4 in case of exactly 4GB of RAM present. Did you mean to use <= instead of <?</div><div dir="auto"><br></div><div dir="auto">Regards,</div><div dir="auto">Gustaw</div></div>