Module: Mesa Branch: main Commit: acf6bf88c07e0a1f0283ad1acd0e5f0d2a156535 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=acf6bf88c07e0a1f0283ad1acd0e5f0d2a156535
Author: Lionel Landwerlin <[email protected]> Date: Sat Apr 23 00:13:07 2022 +0300 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 <[email protected]> Reviewed-by: Jordan Justen <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16210> --- src/gallium/drivers/iris/iris_bufmgr.c | 12 ++++++ src/gallium/drivers/iris/iris_bufmgr.h | 3 ++ src/gallium/drivers/iris/iris_screen.c | 67 +++++++++++++++++++++++----------- 3 files changed, 60 insertions(+), 22 deletions(-) diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c index 0fe5e0112a8..e0f54fbca45 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.c +++ b/src/gallium/drivers/iris/iris_bufmgr.c @@ -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; +} diff --git a/src/gallium/drivers/iris/iris_bufmgr.h b/src/gallium/drivers/iris/iris_bufmgr.h index 97701541600..0debf5313bd 100644 --- a/src/gallium/drivers/iris/iris_bufmgr.h +++ b/src/gallium/drivers/iris/iris_bufmgr.h @@ -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 */ diff --git a/src/gallium/drivers/iris/iris_screen.c b/src/gallium/drivers/iris/iris_screen.c index 884f8f667e4..71bec2c1c65 100644 --- a/src/gallium/drivers/iris/iris_screen.c +++ b/src/gallium/drivers/iris/iris_screen.c @@ -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;
