You can sign up to get a daily email of our articles, see the Mailing List page.
Script to clean out Mesa shader caches
Grogan Jun 22, 2023
Since somewhere in proton_experimental_7, Proton has been changing the location of the mesa_shader_cache to the individual appid directories where the Wine prefixes are stored.

This is very messy (and quite frankly irresponsible) as the objects are invalidated every time there's a change to Mesa (even new build of same version) and/or a change to LLVM will cause Mesa to plunk down new subdirectories and start repopulating them. I don't think anything prunes them (size only applies to each cache, for 32 or 64 bit) at least not with the fossilize format.

I've been using a script to nuke this stuff for some time now, but I just made it interactive to share with others

This is for Mesa, I don't know where, or how this stuff is handled for Nvidia these days. The script is pretty simple ideas, easy to change it to do whatever you want.

This should be able to find the real path to compatdata to set for the COMPATDATA variable using the ~/.steam/root symlink but if that isn't the case for everyone (I think so, but...) it can be edited.

The real location may be somewhere like $HOME/.local/share/steam/steamapps/compatdata through a symlink, %HOME/.steam/root/steamapps/compatdata

Or, for containerized installations... who bloody knows. I'm also sorry that I don't personally know where this is on the Steam Deck. I think (from a reddit thread):

/home/deck/.local/share/Steam/steamapps/compatdata/

and if so, that S in steam would be case sensitive.

It's also possible your user's main mesa_shader_cache is not in $HOME/.cache if your distributor or somebody has set a variable for it to be elsewhere. Verify all paths and edit accordingly.

Should be able to easily copy and paste from the code tag, save it as a filename, and give it the executable bit (e.g. "chmod 755 filename" or right click and find checkboxes in your file manager etc.)

Run it as your user (I don't mean to insult anyone's intelligence but don't run this as root)

#! /bin/bash

### Clean out ~/.cache/mesa_shader_cache(_sf) and radv_builtin shaders
### Clean out the mesa_shader_cache(_sf) directories from Steam's compatdata
### Note that the fossilize cache (MESA_DISK_CACHE_SINGLE_FILE=1) isn't used by default,
### so we cover the mesa_shader_cache_sf case with a wildcard

# System specific path, you may need to edit below if the following doesn't lead
# to the real path correctly

cd "$HOME"/.steam/root/steamapps/compatdata || exit 1
COMPATDATA=$(pwd -P)

find "$COMPATDATA" -name 'mesa_shader_cache*' -exec du -sh '{}' \;
find "$HOME"/.cache -name 'mesa_shader_cache*' -exec du -sh '{}' \;

echo "Look at all the CRUD that is accumulating..."

while true; do
read -p "Do you wish to clean it out? (y/n) " yn
case $yn in 
        [yY] ) echo Nuking...;
                break;;
        [nN] ) echo Aborting...;
                exit 0;;
        * ) echo "Enter y or n, silly!";;
esac
done

find "$COMPATDATA" -name 'mesa_shader_cache*' -exec rm -rvf '{}' \;
rm -vf "$HOME"/.cache/radv_builtin_shaders32
rm -vf "$HOME"/.cache/radv_builtin_shaders64
rm -rvf "$HOME"/.cache/mesa_shader_cache*


Oops, forum code formatting tag doesn't seem to preserve tab indents. That doesn't really break it, but it's a sin, so I changed it to spaces in the post, but here's a text file anyway:

http://www.mikeserv.org/files/cleanshadercaches.txt

You might be surprised at how much of it there is. This script will first show that to you and you can just take a look. If you say n the script will exit and do nothing more, if you say y it will continue on with the removal commands below. Verbose, if there is anything to do, silent if not (-f doesn't emit error output). Remove the f if you don't like that.

Moreover, don't say y and nuke your shader caches for no reason (i.e. wait until there's been a mesa update in your distro), as disconnected directories in there are only taking up space and inodes for now. Things have gotten a lot better now with dxvk's shader pipeline library method (in many cases it's hardly noticeable), and vkd3d-proton's similar mechanism, but still, I'm not fond of losing my cached shaders.

I just did a mesa build before bed this morning (chasing commits) and only tested the one relevant game so I didn't have much yet, but this is how it rolls:

[grogan@getstuffed mesabuild]$ ./cleanshadercaches
5.3M /storage3/shit/steam/steamapps/compatdata/0/pfx/mesa_shader_cache_sf
44M /storage3/shit/steam/steamapps/compatdata/397540/pfx/mesa_shader_cache_sf
4.7M /home/grogan/.cache/mesa_shader_cache_sf
Look at all the CRUD that is accumulating...
Do you wish to clean it out? (y/n) y
Nuking...
removed '/storage3/shit/steam/steamapps/compatdata/0/pfx/mesa_shader_cache_sf/f29e7c363fad35083e8d7322333c62074a1ccdb2/POLARIS10/index'
removed '/storage3/shit/steam/steamapps/compatdata/0/pfx/mesa_shader_cache_sf/f29e7c363fad35083e8d7322333c62074a1ccdb2/POLARIS10/foz_cache.foz'
removed '/storage3/shit/steam/steamapps/compatdata/0/pfx/mesa_shader_cache_sf/f29e7c363fad35083e8d7322333c62074a1ccdb2/POLARIS10/foz_cache_idx.foz'
removed directory '/storage3/shit/steam/steamapps/compatdata/0/pfx/mesa_shader_cache_sf/f29e7c363fad35083e8d7322333c62074a1ccdb2/POLARIS10'
removed directory '/storage3/shit/steam/steamapps/compatdata/0/pfx/mesa_shader_cache_sf/f29e7c363fad35083e8d7322333c62074a1ccdb2'
... lengthy output snipped ...
[grogan@getstuffed mesabuild]$


Last edited by Grogan on 22 June 2023 at 11:09 pm UTC
Grogan Jun 22, 2023
I should also say that I don't use Valve's shader pre-cache mechanism with the uploading and downloading etc, that would be independent, stored in steamapps/shadercache

(I hate that, but it would make good sense on the Steam Deck)
kokoko3k Jun 23, 2023
I fail to understand what the issue is.
Grogan Jun 23, 2023
Quoting: kokoko3kI fail to understand what the issue is.

Cleaning up garbage that accumulates. For discerning users that care.
While you're here, please consider supporting GamingOnLinux on:

Reward Tiers: Patreon. Plain Donations: PayPal.

This ensures all of our main content remains totally free for everyone! Patreon supporters can also remove all adverts and sponsors! Supporting us helps bring good, fresh content. Without your continued support, we simply could not continue!

You can find even more ways to support us on this dedicated page any time. If you already are, thank you!
Login / Register


Or login with...
Sign in with Steam Sign in with Google
Social logins require cookies to stay logged in.