nvk: advertize memory heaps and types
authorKarol Herbst <kherbst@redhat.com>
Thu, 19 May 2022 18:29:27 +0000 (20:29 +0200)
committerMarge Bot <emma+marge@anholt.net>
Fri, 4 Aug 2023 21:31:52 +0000 (21:31 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/24326>

src/nouveau/vulkan/nvk_physical_device.c
src/nouveau/vulkan/nvk_physical_device.h
src/nouveau/winsys/nouveau_device.c

index 53e49d4..1d2a0ee 100644 (file)
@@ -176,6 +176,27 @@ nvk_physical_device_try_create(struct nvk_instance *instance,
    device->instance = instance;
    device->dev = ndev;
 
+   device->mem_heaps[0].flags = VK_MEMORY_HEAP_DEVICE_LOCAL_BIT;
+   device->mem_types[0].propertyFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
+   device->mem_types[0].heapIndex = 0;
+
+   if (ndev->vram_size) {
+      device->mem_type_cnt = 2;
+      device->mem_heap_cnt = 2;
+
+      device->mem_heaps[0].size = ndev->vram_size;
+      device->mem_heaps[1].size = ndev->gart_size;
+      device->mem_heaps[1].flags = 0;
+      device->mem_types[1].heapIndex = 1;
+      device->mem_types[1].propertyFlags = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
+   } else {
+      device->mem_type_cnt = 1;
+      device->mem_heap_cnt = 1;
+
+      device->mem_heaps[0].size = ndev->gart_size;
+      device->mem_types[0].propertyFlags |= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
+   }
+
    *device_out = device;
 
    return VK_SUCCESS;
@@ -296,6 +317,18 @@ VKAPI_ATTR void VKAPI_CALL
 nvk_GetPhysicalDeviceMemoryProperties2(VkPhysicalDevice physicalDevice,
    VkPhysicalDeviceMemoryProperties2 *pMemoryProperties)
 {
+   VK_FROM_HANDLE(nvk_physical_device, pdevice, physicalDevice);
+
+   pMemoryProperties->memoryProperties.memoryHeapCount = pdevice->mem_heap_cnt;
+   for (int i = 0; i < pdevice->mem_heap_cnt; i++) {
+      pMemoryProperties->memoryProperties.memoryHeaps[i] = pdevice->mem_heaps[i];
+   }
+
+   pMemoryProperties->memoryProperties.memoryTypeCount = pdevice->mem_type_cnt;
+   for (int i = 0; i < pdevice->mem_type_cnt; i++) {
+      pMemoryProperties->memoryProperties.memoryTypes[i] = pdevice->mem_types[i];
+   }
+
    vk_foreach_struct(ext, pMemoryProperties->pNext)
    {
       switch (ext->sType) {
index 4487b5d..af51307 100644 (file)
@@ -16,6 +16,12 @@ struct nvk_physical_device {
 
    /* Link in nvk_instance::physical_devices */
    struct list_head link;
+
+   // TODO: add mapable VRAM heap if possible
+   VkMemoryHeap mem_heaps[2];
+   VkMemoryType mem_types[2];
+   uint8_t mem_heap_cnt;
+   uint8_t mem_type_cnt;
 };
 
 VK_DEFINE_HANDLE_CASTS(nvk_physical_device,
index 6e5da68..e851ce0 100644 (file)
@@ -8,6 +8,8 @@
 
 #include <stddef.h>
 
+#include "util/os_misc.h"
+
 struct nouveau_ws_device_priv {
    struct nouveau_ws_device base;
    struct nouveau_drm *drm;
@@ -49,7 +51,8 @@ nouveau_ws_device_new(int fd)
    device->base.device_id = device_id;
    device->base.chipset = dev->chipset;
    device->base.vram_size = dev->vram_size;
-   device->base.gart_size = dev->gart_size;
+   os_get_available_system_memory(&device->base.gart_size);
+   device->base.gart_size = MIN2(device->base.gart_size, dev->gart_size);
    device->base.is_integrated = dev->vram_size == 0;
    device->drm = drm;
    device->dev = dev;