Created
September 16, 2025 21:13
-
-
Save reatlat/b3f495b471c327515dafac5ff7421520 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| # --- Detect Steam App ID from environment --- | |
| APPID="${SteamAppId:-${STEAM_COMPAT_APP_ID:-}}" | |
| if [[ -z "${APPID}" ]]; then | |
| echo "[RAMCACHE] ERROR: Steam AppID not found in env (SteamAppId / STEAM_COMPAT_APP_ID)." | |
| echo "Launch this via Steam (it sets the vars), or set APPID= manually." | |
| exit 1 | |
| fi | |
| # --- Detect Steam root (native or Flatpak) --- | |
| STEAM_ROOT="$HOME/.steam/steam" | |
| if [[ ! -d "$STEAM_ROOT" ]]; then | |
| ALT="$HOME/.var/app/com.valvesoftware.Steam/.local/share/Steam" | |
| if [[ -d "$ALT" ]]; then | |
| STEAM_ROOT="$ALT" | |
| fi | |
| fi | |
| if [[ ! -d "$STEAM_ROOT" ]]; then | |
| echo "[RAMCACHE] ERROR: Steam root not found." | |
| exit 1 | |
| fi | |
| # --- Paths to accelerate --- | |
| SHADER_SSD_PERSIST="$STEAM_ROOT/steamapps/shadercache-ssd/$APPID" # persistent storage on SSD | |
| SHADER_LINK_PATH="$STEAM_ROOT/steamapps/shadercache/$APPID" # path Steam/game expects | |
| SHADER_RAM="/dev/shm/steam-ramcache/$APPID/shadercache" # RAM folder | |
| # (optional) accelerate DXVK/VKD3D caches as well: | |
| DXVK_SSD_PERSIST="$STEAM_ROOT/steamapps/compatdata/$APPID/dxvk-cache" | |
| DXVK_LINK_PATH="$STEAM_ROOT/steamapps/compatdata/$APPID/dxvk-cache" | |
| DXVK_RAM="/dev/shm/steam-ramcache/$APPID/dxvk-cache" | |
| VKD3D_SSD_PERSIST="$STEAM_ROOT/steamapps/compatdata/$APPID/vkd3d-cache" | |
| VKD3D_LINK_PATH="$STEAM_ROOT/steamapps/compatdata/$APPID/vkd3d-cache" | |
| VKD3D_RAM="/dev/shm/steam-ramcache/$APPID/vkd3d-cache" | |
| # Enable/disable additional caches | |
| ACCEL_DXVK="${ACCEL_DXVK:-1}" | |
| ACCEL_VKD3D="${ACCEL_VKD3D:-1}" | |
| rsync_safe() { rsync -a --delete --inplace --no-whole-file "$@"; } | |
| prepare_pair() { | |
| local persist="$1" linkpath="$2" ramdir="$3" | |
| # If there is still a normal folder instead of a symlink, move it to persistent storage | |
| if [[ -e "$linkpath" && ! -L "$linkpath" ]]; then | |
| mkdir -p "$(dirname "$persist")" | |
| mkdir -p "$persist" | |
| rsync_safe "$linkpath/" "$persist/" || true | |
| rm -rf "$linkpath" | |
| fi | |
| # Create RAM folder and preload data from persistent storage | |
| mkdir -p "$ramdir" | |
| if [[ -d "$persist" ]]; then | |
| rsync_safe "$persist/" "$ramdir/" || true | |
| fi | |
| # Replace the original path with a symlink to the RAM folder | |
| mkdir -p "$(dirname "$linkpath")" | |
| ln -sfn "$ramdir" "$linkpath" | |
| } | |
| sync_back_pair() { | |
| local persist="$1" linkpath="$2" ramdir="$3" | |
| mkdir -p "$persist" | |
| rsync_safe "$ramdir/" "$persist/" || true | |
| # After exit, remove symlink and restore a normal folder | |
| rm -f "$linkpath" | |
| mkdir -p "$linkpath" | |
| rsync_safe "$persist/" "$linkpath/" || true | |
| } | |
| cleanup() { | |
| echo "[RAMCACHE] Syncing caches back to SSD..." | |
| sync_back_pair "$SHADER_SSD_PERSIST" "$SHADER_LINK_PATH" "$SHADER_RAM" | |
| if [[ "$ACCEL_DXVK" == "1" ]]; then | |
| sync_back_pair "$DXVK_SSD_PERSIST" "$DXVK_LINK_PATH" "$DXVK_RAM" | |
| fi | |
| if [[ "$ACCEL_VKD3D" == "1" ]]; then | |
| sync_back_pair "$VKD3D_SSD_PERSIST" "$VKD3D_LINK_PATH" "$VKD3D_RAM" | |
| fi | |
| echo "[RAMCACHE] Done." | |
| } | |
| trap cleanup EXIT | |
| echo "[RAMCACHE] AppID=$APPID | Steam=$STEAM_ROOT" | |
| echo "[RAMCACHE] Preparing RAM caches..." | |
| prepare_pair "$SHADER_SSD_PERSIST" "$SHADER_LINK_PATH" "$SHADER_RAM" | |
| if [[ "$ACCEL_DXVK" == "1" ]]; then | |
| prepare_pair "$DXVK_SSD_PERSIST" "$DXVK_LINK_PATH" "$DXVK_RAM" | |
| fi | |
| if [[ "$ACCEL_VKD3D" == "1" ]]; then | |
| prepare_pair "$VKD3D_SSD_PERSIST" "$VKD3D_LINK_PATH" "$VKD3D_RAM" | |
| fi | |
| echo "[RAMCACHE] Launching game..." | |
| exec "$@" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steam RAM Cache Launcher
This script allows you to temporarily move Steam shader caches (and optionally Proton’s DXVK/VKD3D caches) into RAM (/dev/shm) while a game is running.
When the game exits, caches are synced back to SSD automatically.
With plenty of RAM (e.g. 32–64 GB), this can reduce shader stutter and improve overall responsiveness in games.
Features
Installation
Save the script to your home directory:
Paste the script contents and save (Ctrl+O, Enter, then Ctrl+X).
Make it executable:
chmod +x ~/bin/steam-ramcacheUsage
In Steam, right-click on a game → Properties → Launch Options.
Enter:
Replace
<USERNAME>with your Linux username.Launch the game.
The script will:
Options
Disable DXVK and VKD3D caching (use only Steam shadercache):
Verifying
Check that the game’s shadercache is a symlink:
Monitor RAM usage:
Troubleshooting
Permission denied → ensure script is executable:
chmod +x ~/bin/steam-ramcache
Steam root not found →
The script checks both:
~/.steam/steam~/.var/app/com.valvesoftware.Steam/.local/share/Steam(Flatpak Steam)rsync not found → install via your package manager.
Low RAM → disable DXVK/VKD3D acceleration with environment variables.
Uninstall / Revert
To stop using the RAM cache for a game, simply remove the script from Launch Options in Steam.
The script restores normal folders after every exit, so nothing permanent is left behind.