panfrost: limit maximum texture size

We don't want huge textures to take up large amounts of system memory.

On a system with 1GB of RAM, this would limit us to 256 MB, which is the
same memory usage as a texture of 8192 x 8192 with 4 bytes per
component, which is what we currently limit max texture size to anyway.

The goal here is really to allow using larger textures on systems with
more memory, but that bit comes in a later patch in this series.

Acked-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/32866>
This commit is contained in:
Erik Faye-Lund 2025-01-16 13:17:27 +01:00 committed by Marge Bot
parent c205777cb6
commit 3a5c606d20

View file

@ -706,6 +706,25 @@ panfrost_resource_set_damage_region(struct pipe_screen *screen,
}
}
static bool
panfrost_can_create_resource(struct pipe_screen *screen,
const struct pipe_resource *template)
{
struct panfrost_resource tmp;
tmp.base = *template;
panfrost_resource_setup(screen, &tmp, DRM_FORMAT_MOD_INVALID, template->format);
uint64_t system_memory;
if (!os_get_total_physical_memory(&system_memory))
return false;
/* Limit maximum texture size to a quarter of the system memory, to avoid
* allocating huge textures on systems with little memory.
*/
return tmp.image.layout.data_size <= system_memory / 4;
}
struct pipe_resource *
panfrost_resource_create_with_modifier(struct pipe_screen *screen,
const struct pipe_resource *template,
@ -1937,6 +1956,7 @@ static const struct u_transfer_vtbl transfer_vtbl = {
void
panfrost_resource_screen_init(struct pipe_screen *pscreen)
{
pscreen->can_create_resource = panfrost_can_create_resource;
pscreen->resource_create_with_modifiers =
panfrost_resource_create_with_modifiers;
pscreen->resource_create = u_transfer_helper_resource_create;