<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p><br>
    </p>
    <div class="moz-cite-prefix">On 1/7/19 6:06 PM, Alex Smith wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAD=bm1mwufRNr9FNTpZwoN8UKzBxweQN9J_HtFz-xn62Q2jDkg@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">Hi Samuel,
        <div><br>
        </div>
        <div>Thanks for implementing this - I've been wanting this
          extension for a while so it's good it's finally available.</div>
        <div><br>
        </div>
        <div>This is just reporting the total heap sizes as the budget,
          which is the same info we already get from the basic heap
          properties. The way I'd expected budget to work (and what the
          spec is saying as far as I can see) is that it's an estimate
          of how much is available for the calling app to use in that
          heap at the time of the call, so should account for current
          system-wide usage of the heap by other apps. Shouldn't this be
          something like (heap size - system wide usage of the heap +
          current app usage of the heap)? (+ app usage since the spec
          says budget includes currently allocated device memory)</div>
      </div>
    </blockquote>
    <p>Hi Alex,</p>
    <p>Yes, I was also wondering about that. We can add per-process
      counters for VRAM and GTT heaps, but I don't see how we can be
      accurate for the visible VRAM heap.</p>
    <p>As said in the commit description, that implementation is really
      inacurate. Though if you need something better I can improve.</p>
    <p>Note that I agree with you about the spec.<br>
    </p>
    <blockquote type="cite"
cite="mid:CAD=bm1mwufRNr9FNTpZwoN8UKzBxweQN9J_HtFz-xn62Q2jDkg@mail.gmail.com">
      <div dir="ltr">
        <div><br>
        </div>
        <div>Alex</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr">On Mon, 7 Jan 2019 at 16:35, Samuel Pitoiset <<a
            href="mailto:samuel.pitoiset@gmail.com" target="_blank"
            moz-do-not-send="true">samuel.pitoiset@gmail.com</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">A
          simple Vulkan extension that allows apps to query size and<br>
          usage of all exposed memory heaps.<br>
          <br>
          The different usage values are not really accurate because<br>
          they are per drm-fd, but they should be close enough.<br>
          <br>
          Signed-off-by: Samuel Pitoiset <<a
            href="mailto:samuel.pitoiset@gmail.com" target="_blank"
            moz-do-not-send="true">samuel.pitoiset@gmail.com</a>><br>
          ---<br>
           src/amd/vulkan/radv_device.c      | 44
          +++++++++++++++++++++++++++++++<br>
           src/amd/vulkan/radv_extensions.py |  1 +<br>
           2 files changed, 45 insertions(+)<br>
          <br>
          diff --git a/src/amd/vulkan/radv_device.c
          b/src/amd/vulkan/radv_device.c<br>
          index cef3a430555..32eaeb3b226 100644<br>
          --- a/src/amd/vulkan/radv_device.c<br>
          +++ b/src/amd/vulkan/radv_device.c<br>
          @@ -1352,12 +1352,56 @@ void
          radv_GetPhysicalDeviceMemoryProperties(<br>
                  *pMemoryProperties =
          physical_device->memory_properties;<br>
           }<br>
          <br>
          +static void<br>
          +radv_get_memory_budget_properties(VkPhysicalDevice
          physicalDevice,<br>
          +                               
           VkPhysicalDeviceMemoryBudgetPropertiesEXT *memoryBudget)<br>
          +{<br>
          +       RADV_FROM_HANDLE(radv_physical_device, device,
          physicalDevice);<br>
          +       VkPhysicalDeviceMemoryProperties *memory_properties =
          &device->memory_properties;<br>
          +       uint64_t visible_vram_size =
          radv_get_visible_vram_size(device);<br>
          +       uint64_t vram_size = radv_get_vram_size(device);<br>
          +       uint64_t gtt_size = device->rad_info.gart_size;<br>
          +<br>
          +       if (vram_size) {<br>
          +             
           memoryBudget->heapBudget[RADV_MEM_HEAP_VRAM] = vram_size;<br>
          +               memoryBudget->heapUsage[RADV_MEM_HEAP_VRAM]
          =<br>
          +                     
           device->ws->query_value(device->ws,
          RADEON_VRAM_USAGE);<br>
          +       }<br>
          +<br>
          +       if (visible_vram_size) {<br>
          +             
           memoryBudget->heapBudget[RADV_MEM_HEAP_VRAM_CPU_ACCESS] =
          visible_vram_size;<br>
          +             
           memoryBudget->heapUsage[RADV_MEM_HEAP_VRAM_CPU_ACCESS] =<br>
          +                     
           device->ws->query_value(device->ws,
          RADEON_VRAM_VIS_USAGE);<br>
          +       }<br>
          +<br>
          +       if (gtt_size) {<br>
          +               memoryBudget->heapBudget[RADV_MEM_HEAP_GTT]
          = gtt_size;<br>
          +               memoryBudget->heapUsage[RADV_MEM_HEAP_GTT]
          =<br>
          +                     
           device->ws->query_value(device->ws,
          RADEON_GTT_USAGE);<br>
          +       }<br>
          +<br>
          +       /* The heapBudget and heapUsage values must be zero
          for array elements<br>
          +        * greater than or equal to<br>
          +        * VkPhysicalDeviceMemoryProperties::memoryHeapCount.<br>
          +        */<br>
          +       for (uint32_t i =
          memory_properties->memoryHeapCount; i <
          VK_MAX_MEMORY_HEAPS; i++) {<br>
          +               memoryBudget->heapBudget[i] = 0;<br>
          +               memoryBudget->heapUsage[i] = 0;<br>
          +       }<br>
          +}<br>
          +<br>
           void radv_GetPhysicalDeviceMemoryProperties2(<br>
                  VkPhysicalDevice                           
          physicalDevice,<br>
                  VkPhysicalDeviceMemoryProperties2KHR     
           *pMemoryProperties)<br>
           {<br>
                  radv_GetPhysicalDeviceMemoryProperties(physicalDevice,<br>
                                                       
           &pMemoryProperties->memoryProperties);<br>
          +<br>
          +       VkPhysicalDeviceMemoryBudgetPropertiesEXT
          *memory_budget =<br>
          +               vk_find_struct(pMemoryProperties->pNext,<br>
          +                             
          PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT);<br>
          +       if (memory_budget)<br>
          +             
           radv_get_memory_budget_properties(physicalDevice,
          memory_budget);<br>
           }<br>
          <br>
           VkResult radv_GetMemoryHostPointerPropertiesEXT(<br>
          diff --git a/src/amd/vulkan/radv_extensions.py
          b/src/amd/vulkan/radv_extensions.py<br>
          index 9952bb9c1c6..491ed9d94c3 100644<br>
          --- a/src/amd/vulkan/radv_extensions.py<br>
          +++ b/src/amd/vulkan/radv_extensions.py<br>
          @@ -105,6 +105,7 @@ EXTENSIONS = [<br>
               Extension('VK_EXT_external_memory_dma_buf',           1,
          True),<br>
               Extension('VK_EXT_external_memory_host',              1,
          'device->rad_info.has_userptr'),<br>
               Extension('VK_EXT_global_priority',                   1,
          'device->rad_info.has_ctx_priority'),<br>
          +    Extension('VK_EXT_memory_budget',                     1,
          True),<br>
               Extension('VK_EXT_pci_bus_info',                      2,
          True),<br>
               Extension('VK_EXT_sampler_filter_minmax',             1,
          'device->rad_info.chip_class >= CIK'),<br>
               Extension('VK_EXT_scalar_block_layout',               1,
          'device->rad_info.chip_class >= CIK'),<br>
          -- <br>
          2.20.1<br>
          <br>
          _______________________________________________<br>
          mesa-dev mailing list<br>
          <a href="mailto:mesa-dev@lists.freedesktop.org"
            target="_blank" moz-do-not-send="true">mesa-dev@lists.freedesktop.org</a><br>
          <a
            href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev"
            rel="noreferrer" target="_blank" moz-do-not-send="true">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
        </blockquote>
      </div>
    </blockquote>
  </body>
</html>