turnip: keep track of memory heap usage, size and flags
Signed-off-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com> Reviewed-by: Eric Anholt <eric@anholt.net> Reviewed-by: Hyunjun Ko <zzoon@igalia.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8524>
This commit is contained in:
parent
182fb988c8
commit
4342dec09a
|
@ -889,7 +889,7 @@ tu_GetPhysicalDeviceQueueFamilyProperties2(
|
|||
}
|
||||
}
|
||||
|
||||
static uint64_t
|
||||
uint64_t
|
||||
tu_get_system_heap_size()
|
||||
{
|
||||
struct sysinfo info;
|
||||
|
@ -913,11 +913,12 @@ void
|
|||
tu_GetPhysicalDeviceMemoryProperties2(VkPhysicalDevice pdev,
|
||||
VkPhysicalDeviceMemoryProperties2 *props2)
|
||||
{
|
||||
VkPhysicalDeviceMemoryProperties *props = &props2->memoryProperties;
|
||||
TU_FROM_HANDLE(tu_physical_device, physical_device, pdev);
|
||||
|
||||
VkPhysicalDeviceMemoryProperties *props = &props2->memoryProperties;
|
||||
props->memoryHeapCount = 1;
|
||||
props->memoryHeaps[0].size = tu_get_system_heap_size();
|
||||
props->memoryHeaps[0].flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
|
||||
props->memoryHeaps[0].size = physical_device->heap.size;
|
||||
props->memoryHeaps[0].flags = physical_device->heap.flags;
|
||||
|
||||
props->memoryTypeCount = 1;
|
||||
props->memoryTypes[0].propertyFlags =
|
||||
|
@ -1428,6 +1429,11 @@ tu_AllocateMemory(VkDevice _device,
|
|||
return VK_SUCCESS;
|
||||
}
|
||||
|
||||
struct tu_memory_heap *mem_heap = &device->physical_device->heap;
|
||||
uint64_t mem_heap_used = p_atomic_read(&mem_heap->used);
|
||||
if (mem_heap_used > mem_heap->size)
|
||||
return vk_error(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY);
|
||||
|
||||
mem = vk_object_alloc(&device->vk, pAllocator, sizeof(*mem),
|
||||
VK_OBJECT_TYPE_DEVICE_MEMORY);
|
||||
if (mem == NULL)
|
||||
|
@ -1460,6 +1466,17 @@ tu_AllocateMemory(VkDevice _device,
|
|||
tu_bo_init_new(device, &mem->bo, pAllocateInfo->allocationSize, false);
|
||||
}
|
||||
|
||||
|
||||
if (result == VK_SUCCESS) {
|
||||
mem_heap_used = p_atomic_add_return(&mem_heap->used, mem->bo.size);
|
||||
if (mem_heap_used > mem_heap->size) {
|
||||
p_atomic_add(&mem_heap->used, -mem->bo.size);
|
||||
tu_bo_finish(device, &mem->bo);
|
||||
result = vk_errorf(device->instance, VK_ERROR_OUT_OF_DEVICE_MEMORY,
|
||||
"Out of heap memory");
|
||||
}
|
||||
}
|
||||
|
||||
if (result != VK_SUCCESS) {
|
||||
vk_object_free(&device->vk, pAllocator, mem);
|
||||
return result;
|
||||
|
@ -1481,6 +1498,7 @@ tu_FreeMemory(VkDevice _device,
|
|||
if (mem == NULL)
|
||||
return;
|
||||
|
||||
p_atomic_add(&device->physical_device->heap.used, -mem->bo.size);
|
||||
tu_bo_finish(device, &mem->bo);
|
||||
vk_object_free(&device->vk, pAllocator, mem);
|
||||
}
|
||||
|
|
|
@ -393,6 +393,10 @@ tu_drm_device_init(struct tu_physical_device *device,
|
|||
goto fail;
|
||||
}
|
||||
|
||||
device->heap.size = tu_get_system_heap_size();
|
||||
device->heap.used = 0u;
|
||||
device->heap.flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
|
||||
|
||||
return tu_physical_device_init(device, instance);
|
||||
|
||||
fail:
|
||||
|
|
|
@ -242,6 +242,10 @@ tu_enumerate_devices(struct tu_instance *instance)
|
|||
device->gmem_size = info.gmem_sizebytes;
|
||||
device->gmem_base = gmem_iova;
|
||||
|
||||
device->heap.size = tu_get_system_heap_size();
|
||||
device->heap.used = 0u;
|
||||
device->heap.flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
|
||||
|
||||
if (tu_physical_device_init(device, instance) != VK_SUCCESS)
|
||||
goto fail;
|
||||
|
||||
|
|
|
@ -174,6 +174,23 @@ __tu_finishme(const char *file, int line, const char *format, ...)
|
|||
tu_finishme("stub %s", __func__); \
|
||||
} while (0)
|
||||
|
||||
struct tu_memory_heap {
|
||||
/* Standard bits passed on to the client */
|
||||
VkDeviceSize size;
|
||||
VkMemoryHeapFlags flags;
|
||||
|
||||
/** Copied from ANV:
|
||||
*
|
||||
* Driver-internal book-keeping.
|
||||
*
|
||||
* Align it to 64 bits to make atomic operations faster on 32 bit platforms.
|
||||
*/
|
||||
VkDeviceSize used __attribute__ ((aligned (8)));
|
||||
};
|
||||
|
||||
uint64_t
|
||||
tu_get_system_heap_size(void);
|
||||
|
||||
struct tu_physical_device
|
||||
{
|
||||
struct vk_physical_device vk;
|
||||
|
@ -203,6 +220,8 @@ struct tu_physical_device
|
|||
* the pipeline cache defined by apps.
|
||||
*/
|
||||
struct disk_cache *disk_cache;
|
||||
|
||||
struct tu_memory_heap heap;
|
||||
};
|
||||
|
||||
enum tu_debug_flags
|
||||
|
|
Loading…
Reference in New Issue