<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><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">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">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">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div>