asahi: Copy panfrost's bo cache
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Fri, 17 Jun 2022 02:27:47 +0000 (22:27 -0400)
committerMarge Bot <emma+marge@anholt.net>
Thu, 24 Nov 2022 23:37:48 +0000 (23:37 +0000)
commit04360a270e59a3ac7778eb8744047f165fa64edf
tree2667739b7c857a7514a04b01ab857a981e190937
parent7c8e3963bdaaeb8bd43a9d1d75ade99e3962ffeb
asahi: Copy panfrost's bo cache

Massive performance gains, some fps before/after numbers from glmark2:

   [shading] 1486 -> 2391
   [refract] 87   -> 127
   [terrain] 32   -> 56

...and it's basically for free with enough copy/paste, so thank you to Boris
Brezillon for an excellent Asahi patch, the LRU cache seems to work great on M1
:-p

There are a few minor changes I made from panfrost, notably adjusting the
constants to account for 16KiB pages and switching from pthread_mutex to
simple_mtx to be less weird in Mesa.

For context on the design, the following commits evolved it in Panfrost and
their commit messages may be useful... The logic in this module is the product
of years of mistakes and correcting course :-)

   f06809cdcaf ("panfrost: Evict the BO cache when allocation fails")
   77d04989135 ("panfrost: Fix major flaw in BO cache")
   ee82f9f07e1 ("panfrost: Try to evict unused BOs from the cache")
   2225383af8b ("panfrost: Make sure the BO is 'ready' when picked from the cache")
   9af4aeaaf7c ("panfrost: Don't return imported/exported BOs to the cache")

Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19971>
src/asahi/lib/agx_bo.h
src/asahi/lib/agx_device.c
src/asahi/lib/agx_device.h