iris: use new kernel uAPI to compute video memory

v2: Use os_get_available_system_memory() when kernel memory region
    uAPI is not available (Lionel)

Cc: 22.1 <mesa-stable>
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16210>
This commit is contained in:
Lionel Landwerlin 2022-04-23 00:13:07 +03:00 committed by Marge Bot
parent 763744aa8b
commit acf6bf88c0
3 changed files with 60 additions and 22 deletions

View file

@ -2585,3 +2585,15 @@ iris_bufmgr_get_border_color_pool(struct iris_bufmgr *bufmgr)
{
return &bufmgr->border_color_pool;
}
uint64_t
iris_bufmgr_vram_size(struct iris_bufmgr *bufmgr)
{
return bufmgr->vram.size;
}
uint64_t
iris_bufmgr_sram_size(struct iris_bufmgr *bufmgr)
{
return bufmgr->sys.size;
}

View file

@ -599,4 +599,7 @@ void iris_destroy_border_color_pool(struct iris_border_color_pool *pool);
uint32_t iris_upload_border_color(struct iris_border_color_pool *pool,
union pipe_color_union *color);
uint64_t iris_bufmgr_vram_size(struct iris_bufmgr *bufmgr);
uint64_t iris_bufmgr_sram_size(struct iris_bufmgr *bufmgr);
#endif /* IRIS_BUFMGR_H */

View file

@ -142,6 +142,49 @@ iris_get_name(struct pipe_screen *pscreen)
return buf;
}
static int
iris_get_video_memory(struct iris_screen *screen)
{
uint64_t vram = iris_bufmgr_vram_size(screen->bufmgr);
uint64_t sram = iris_bufmgr_sram_size(screen->bufmgr);
uint64_t osmem;
if (vram) {
return vram / (1024 * 1024);
} else if (sram) {
return sram / (1024 * 1024);
} else if (os_get_available_system_memory(&osmem)) {
return osmem / (1024 * 1024);
} else {
/* This is the old code path, it get the GGTT size from the kernel
* (which should always be 4Gb on Gfx8+).
*
* We should probably never end up here. This is just a fallback to get
* some kind of value in case os_get_available_system_memory fails.
*/
const struct intel_device_info *devinfo = &screen->devinfo;
/* Once a batch uses more than 75% of the maximum mappable size, we
* assume that there's some fragmentation, and we start doing extra
* flushing, etc. That's the big cliff apps will care about.
*/
const unsigned gpu_mappable_megabytes =
(devinfo->aperture_bytes * 3 / 4) / (1024 * 1024);
const long system_memory_pages = sysconf(_SC_PHYS_PAGES);
const long system_page_size = sysconf(_SC_PAGE_SIZE);
if (system_memory_pages <= 0 || system_page_size <= 0)
return -1;
const uint64_t system_memory_bytes =
(uint64_t) system_memory_pages * (uint64_t) system_page_size;
const unsigned system_memory_megabytes =
(unsigned) (system_memory_bytes / (1024 * 1024));
return MIN2(system_memory_megabytes, gpu_mappable_megabytes);
}
}
static int
iris_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
{
@ -320,28 +363,8 @@ iris_get_param(struct pipe_screen *pscreen, enum pipe_cap param)
return 0x8086;
case PIPE_CAP_DEVICE_ID:
return screen->pci_id;
case PIPE_CAP_VIDEO_MEMORY: {
/* Once a batch uses more than 75% of the maximum mappable size, we
* assume that there's some fragmentation, and we start doing extra
* flushing, etc. That's the big cliff apps will care about.
*/
const unsigned gpu_mappable_megabytes =
(devinfo->aperture_bytes * 3 / 4) / (1024 * 1024);
const long system_memory_pages = sysconf(_SC_PHYS_PAGES);
const long system_page_size = sysconf(_SC_PAGE_SIZE);
if (system_memory_pages <= 0 || system_page_size <= 0)
return -1;
const uint64_t system_memory_bytes =
(uint64_t) system_memory_pages * (uint64_t) system_page_size;
const unsigned system_memory_megabytes =
(unsigned) (system_memory_bytes / (1024 * 1024));
return MIN2(system_memory_megabytes, gpu_mappable_megabytes);
}
case PIPE_CAP_VIDEO_MEMORY:
return iris_get_video_memory(screen);
case PIPE_CAP_MAX_SHADER_PATCH_VARYINGS:
case PIPE_CAP_MAX_VARYINGS:
return 32;