mesa/src
Axel Davy 90a7573a65 st/nine: Add RAM memory manager for textures
On 32 bits, virtual memory is sometimes too short for apps.
Textures can hold virtual memory 3 ways:
1) MANAGED textures have a RAM copy of any texture
2) SYSTEMMEM is used to have RAM copy of DEFAULT textures
   (to upload them for example)
3) Textures being mapped.

Nine cannot do much for 3). It's up to driver to really unmap textures
when possible on 32 bits to reduce virtual memory usage.

It's not clear whether on Windows anything special is done for
1) and 2). However there is clear indication some efforts have
been done on 3) to really unmap when it makes sense.

My understanding is that other implementations reduce the usage
of 1) by deleting the RAM copy once the texture is uploaded
(Dxvk's behaviour is controlled by evictManagedOnUnlock).

The obvious issue with that approach is whether the texture is
read by the application after some time. In that case,
we have to recreate the RAM backing from the GPU buffer.

And apps DO that. Indeed I found that for example Mass Effect 2
with High Texture mods (one of the crash case fixed by this patch serie),
When the character gets close to an object, a high res texture and replaces
the low res one. The high res one simply has more levels, and the game seems
to optimize reading the high res texture by retrieving the small-resolution
levels from the original low res texture.
In other words during gameplay, the game will randomly read MANAGED textures.
This is expected to be fast as the data is supposed to be in RAM...

Instead of taking that RAM copy eviction approach, this patchset
proposes a different approach: storing in memfd and release the
virtual memory until needed.

Basically instead of using malloc(), we create a memfd file
and map it. When the data doesn't seem to be accessed anymore,
we can unmap the memfd file.
If the data is needed, the memfd file is mapped again.
This trick enables to allocate more than 4GB on 32 bits apps.

The advantage of this approach over the RAM eviction one,
is that the load is much faster and doesn't block the GPU.

Of course we have problems if there's not enough memory to map the
memfd file. But the problem is the same for the RAM eviction approach.

Naturally on 64 bits, we do not use memfd.

Signed-off-by: Axel Davy <davyaxel0@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9377>
2021-03-07 13:13:53 +00:00
..
amd radv: cache pipeline statistics 2021-03-05 17:01:16 +00:00
android_stub egl/android: implement image cleanup callback 2020-12-15 06:05:27 +00:00
broadcom mesa: fix fbo attachment size check for RBs, make it trigger in ES2 2021-03-06 20:29:41 +00:00
compiler nir/algebraic: Apply addition property of equality to the other ordering too 2021-03-04 22:50:53 +00:00
drm-shim drm-shim: report support for timeline semaphores 2021-02-09 21:08:52 +00:00
egl egl: android: use num_planes param in createImageFromDmaBufs() 2021-02-25 16:15:24 +00:00
etnaviv etnaviv, v3d: Fix valgrind include paths. 2020-12-15 19:39:29 +00:00
freedreno ir3: disallow moving memory writes over discard 2021-03-04 11:40:58 +00:00
gallium st/nine: Add RAM memory manager for textures 2021-03-07 13:13:53 +00:00
gbm egl: implement EGL_EXT_protected_surface support 2020-11-02 10:15:47 +01:00
getopt
glx Adjust dylib compatibility versions to match what was set by mesa-18.3's autotools-based builds 2021-02-22 21:27:19 +00:00
gtest
hgl hgl: Major refactor and cleanup 2021-01-09 20:51:35 -06:00
imgui
intel anv: fix MI_PREDICATE_RESULT write 2021-03-05 16:19:20 +00:00
loader loader: Silence a warning at -Og 2021-02-18 20:59:43 +00:00
mapi glapi: keep declspec(thread) msvc-specific 2021-02-24 13:47:30 +00:00
mesa mesa: fix fbo attachment size check for RBs, make it trigger in ES2 2021-03-06 20:29:41 +00:00
microsoft nir: add has_txs flag 2021-02-23 14:04:30 +00:00
nouveau nouveau: add drm-shim support 2021-01-11 22:45:01 +00:00
panfrost pan/bi: Implement fsin/fcos 2021-03-05 15:15:10 +00:00
util util/disk_cache: make MESA_DISK_CACHE_READ_ONLY_FOZ_DBS a relative path 2021-03-04 04:07:46 +00:00
virtio virgl: Add support for querying detailed memory info 2021-03-04 17:14:14 +01:00
vulkan vulkan: Update dispatch table gen for Windows 2021-02-26 04:29:52 +10:00
meson.build nouveau: add drm-shim support 2021-01-11 22:45:01 +00:00
SConscript driconf: drop now unused translation facility 2020-06-22 21:50:12 +00:00