Add build flag to control ram available to Vulkan.

--args anv_use_max_ram=true

Also rename enable_external_fd to anv_enable_external_fd.

Change-Id: I05015421a8777c08913dc52d3abdcaecedab6a14
Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/mesa/+/463874
Reviewed-by: John Bauman <jbauman@google.com>
diff --git a/src/intel/vulkan/BUILD.gn b/src/intel/vulkan/BUILD.gn
index d91a347..25b46ee 100644
--- a/src/intel/vulkan/BUILD.gn
+++ b/src/intel/vulkan/BUILD.gn
@@ -23,15 +23,20 @@
 
 declare_args() {
   # TODO(fxbug.dev/67565) - remove once external FD extensions fully supported
-  enable_external_fd = false
+  anv_enable_external_fd = false
+  # Give maximum possible memory to Vulkan heap
+  anv_use_max_ram = false
 }
 
 config("vulkan_internal_config") {
   defines = [ "ANV_MAGMA=1" ]
 
-  if (!enable_external_fd) {
+  if (!anv_enable_external_fd) {
     defines += [ "DISABLE_EXTERNAL_FD=1" ]
   }
+  if (anv_use_max_ram) {
+    defines += [ "ANV_AVAILABLE_RAM_FRACTION=1.0" ]
+  }
 
   include_dirs = [
     ".",
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index ea1caba..d760d2e 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -123,10 +123,14 @@
     * or less, we use at most half.  If they have more than 4GiB, we use 3/4.
     */
    uint64_t available_ram;
+#if defined(ANV_AVAILABLE_RAM_FRACTION)
+   available_ram = (double) total_ram * ANV_AVAILABLE_RAM_FRACTION;
+#else
    if (total_ram <= 4ull * 1024ull * 1024ull * 1024ull)
       available_ram = total_ram / 2;
    else
       available_ram = total_ram * 3 / 4;
+#endif
 
    /* We also want to leave some padding for things we allocate in the driver,
     * so don't go over 3/4 of the GTT either.