mirror of
https://git.triforceproject.com/triforce/source
synced 2026-11-22 17:19:58 -04:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e6f2f248f2 | ||
|
|
70c210cee1 | ||
|
|
043db52c62 | ||
|
|
6c7117635c | ||
|
|
b0e46adb48 | ||
|
|
fb26495475 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -18,6 +18,8 @@ gamefile/
|
||||
|
||||
# ---- build output and caches ----
|
||||
build/
|
||||
# (but launcher/Logic/Build/ is source: git on Windows ignores case, so build/ hid it and v0.5.2 was committed without it)
|
||||
!launcher/Logic/Build/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
*.o
|
||||
|
||||
@@ -952,6 +952,15 @@ public partial class MainWindow : Window
|
||||
clock.Stop();
|
||||
elapsed.Stop();
|
||||
runner = null;
|
||||
// ((Triforce, 11-18) a Cancel first, whatever the run said: Runner.Cancel asks the game's shader preparation to stop
|
||||
// and it ends well, so make_game.py goes on to its @@done. Taken as done, a Cancel in "Preparing shaders" said "Your
|
||||
// game is ready", made the shortcuts and freed the build's files, where it went back to the files, as before)
|
||||
if (failure == "cancelled")
|
||||
{
|
||||
SetStep(0);
|
||||
ShowPage(FilesPage);
|
||||
return;
|
||||
}
|
||||
if (finished.Length > 0)
|
||||
{
|
||||
foreach (var (id, r) in rows)
|
||||
@@ -964,12 +973,6 @@ public partial class MainWindow : Window
|
||||
ShowReady();
|
||||
return;
|
||||
}
|
||||
if (failure == "cancelled")
|
||||
{
|
||||
SetStep(0);
|
||||
ShowPage(FilesPage);
|
||||
return;
|
||||
}
|
||||
if (current != null && rows.TryGetValue(current, out var row)) row.Stopped();
|
||||
ShowProblem(failure ?? "The build tools stopped without saying why.", tools: failure?.Contains("antivirus", StringComparison.OrdinalIgnoreCase) == true);
|
||||
}
|
||||
@@ -1231,7 +1234,7 @@ public partial class MainWindow : Window
|
||||
void CloseWindow(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (runner != null && MessageBox.Show(this, T(S.CloseQuestion), "Hookshot", MessageBoxButton.YesNo) != MessageBoxResult.Yes) return;
|
||||
runner?.Cancel();
|
||||
runner?.Cancel().Wait(); // (the app ends with the window: a shader preparation asked to stop is waited for, or killed)
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,12 @@ sealed class Runner
|
||||
this.ngxSdk = ngxSdk;
|
||||
}
|
||||
|
||||
static ProcessStartInfo Info(Tools tools, IEnumerable<string> args, int? workers = null, string? ngxSdk = null)
|
||||
/// (Triforce, 11-18) The event this run's game opens while it prepares its shaders (gpu/vk/vk_main.cpp PrepareStopWatch),
|
||||
/// named for this run alone: a Cancel here never stops another builder's preparation
|
||||
readonly string stopEvent = @"Local\TriforcePrepareStop." + Guid.NewGuid().ToString("N");
|
||||
|
||||
static ProcessStartInfo Info(Tools tools, IEnumerable<string> args, int? workers = null, string? ngxSdk = null,
|
||||
string? stopEvent = null)
|
||||
{
|
||||
var si = new ProcessStartInfo(tools.Python)
|
||||
{
|
||||
@@ -98,6 +103,9 @@ sealed class Runner
|
||||
// (NVIDIA DLSS: only when ticked. Without it, one set on the PC is not passed on either: a build is with DLSS only when asked)
|
||||
if (ngxSdk != null) si.Environment["HOOKSHOT_NGX_SDK"] = ngxSdk;
|
||||
else si.Environment.Remove("HOOKSHOT_NGX_SDK");
|
||||
// (not a HOOKSHOT_ name: make_game.py's game_env keeps it for the game)
|
||||
if (stopEvent != null) si.Environment["TRIFORCE_PREPARE_STOP"] = stopEvent;
|
||||
else si.Environment.Remove("TRIFORCE_PREPARE_STOP");
|
||||
// (the folder's own compiler, headers and libraries, when it has them: nothing of the PC's but Windows' own)
|
||||
var sets = new[] { ("EMSDK", "emsdk"), ("RX_CPM", "cpm"), ("WGPU_NATIVE", "wgpu-native") };
|
||||
foreach (var (name, folder) in sets)
|
||||
@@ -118,11 +126,16 @@ sealed class Runner
|
||||
{
|
||||
try
|
||||
{
|
||||
using var p = Process.Start(Info(tools, args, workers, ngxSdk))!;
|
||||
using var p = Process.Start(Info(tools, args, workers, ngxSdk, stopEvent))!;
|
||||
process = p;
|
||||
p.ErrorDataReceived += (_, e) => { if (e.Data != null) Line?.Invoke(e.Data); };
|
||||
p.BeginErrorReadLine();
|
||||
try { p.PriorityClass = ProcessPriorityClass.BelowNormal; } catch (Exception) { }
|
||||
// (Triforce, 11-22, the performance audit's OS-57, after Source A's) The build tools run at normal priority;
|
||||
// below normal, as every build was before, only with HOOKSHOT_LOW_PRIORITY=1. Source A's reason, a report
|
||||
// it did not measure: below normal, Windows kept the steps that are one process (the read, the lift) on a
|
||||
// hybrid Intel CPU's efficiency cores while the performance cores idled.
|
||||
if (Environment.GetEnvironmentVariable("HOOKSHOT_LOW_PRIORITY") == "1")
|
||||
try { p.PriorityClass = ProcessPriorityClass.BelowNormal; } catch (Exception) { }
|
||||
while (p.StandardOutput.ReadLine() is { } line)
|
||||
{
|
||||
if (line.StartsWith("@@error ")) error = line[8..];
|
||||
@@ -138,10 +151,26 @@ sealed class Runner
|
||||
});
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
/// (Triforce, 11-18) The game's --prepare-shaders run, when that is the step under way, is asked to stop first (the event
|
||||
/// gpu/vk/vk_main.cpp PrepareStopWatch waits on): it ends its driver's part cleanly and keeps what it made, where a kill
|
||||
/// used one of that part's three tries and left shaders out for good. Killed as before when it has not ended in 30 s,
|
||||
/// and at once when no preparation is under way. The wait is not on the caller's thread
|
||||
public Task Cancel()
|
||||
{
|
||||
cancelled = true;
|
||||
try { process?.Kill(entireProcessTree: true); } catch (Exception) { }
|
||||
var p = process;
|
||||
var asked = false;
|
||||
try
|
||||
{
|
||||
if (EventWaitHandle.TryOpenExisting(stopEvent, out var stop))
|
||||
using (stop) asked = stop.Set();
|
||||
}
|
||||
catch (Exception) { }
|
||||
return Task.Run(() =>
|
||||
{
|
||||
try { if (asked && p != null && p.WaitForExit(30000)) return; } catch (Exception) { }
|
||||
try { p?.Kill(entireProcessTree: true); } catch (Exception) { }
|
||||
});
|
||||
}
|
||||
|
||||
/// Is this the supported game and version? The answer in plain words.
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#!/bin/sh
|
||||
# The Hookshot AppImage: the builder window (builder/linux/hookshot_builder.py) with everything it builds the game with -
|
||||
# Python and the tools, clang and lld, a glibc 2.35 sysroot, FFmpeg, SDL2 and the Vulkan back end, built already.
|
||||
# Hookshot.AppImage the builder window (Play is in the window, once a game is built)
|
||||
# Hookshot.AppImage the launcher window (Play is in the window, once a game is built)
|
||||
# Hookshot.AppImage --classic the classic builder window instead
|
||||
# Hookshot.AppImage --play start the game the builder saved, without opening the window
|
||||
# Hookshot.AppImage --play <folder> start the game in that folder
|
||||
# Hookshot.AppImage <folder> the same
|
||||
@@ -35,4 +36,20 @@ fi
|
||||
if [ -n "${1:-}" ] && [ -d "$1" ]; then
|
||||
exec "$HOOKSHOT_TOOLS/builder/linux/hookshot-launch" "$1"
|
||||
fi
|
||||
# The window: the Triforce launcher (usr/bin/triforce-launcher, a WebKitGTK window). It exits 4 when this system has no
|
||||
# WebKitGTK 4.1 (e.g. some Steam Deck images), and the classic builder window opens instead; --classic or
|
||||
# TRIFORCE_CLASSIC=1 always opens the classic one.
|
||||
LAUNCHER="$HERE/usr/bin/triforce-launcher"
|
||||
if [ "${1:-}" = "--classic" ]; then
|
||||
shift
|
||||
TRIFORCE_CLASSIC=1
|
||||
fi
|
||||
if [ "${TRIFORCE_CLASSIC:-0}" != "1" ] && [ -x "$LAUNCHER" ]; then
|
||||
# (WebKitGTK's GPU path breaks on NVIDIA's driver and under gamescope; its plain path is fine for a launcher)
|
||||
export WEBKIT_DISABLE_DMABUF_RENDERER="${WEBKIT_DISABLE_DMABUF_RENDERER:-1}"
|
||||
export TRIFORCE_APPRUN="$HERE/AppRun"
|
||||
"$LAUNCHER" "$@"
|
||||
code=$?
|
||||
[ "$code" -ne 4 ] && exit "$code"
|
||||
fi
|
||||
exec "$PY" -I "$HOOKSHOT_TOOLS/builder/linux/hookshot_builder.py" "$@"
|
||||
|
||||
@@ -17,6 +17,15 @@ CREATE_NO_WINDOW = 0x08000000
|
||||
BELOW_NORMAL_PRIORITY_CLASS = 0x00004000
|
||||
|
||||
|
||||
def build_priority(env=None):
|
||||
"""(Triforce, 11-22, the performance audit's OS-57, after Source A's) The priority class the build tools are started
|
||||
with, as a creation flag: none (normal priority), and below normal, as every build was before, only with
|
||||
HOOKSHOT_LOW_PRIORITY=1. Source A's reason, a report it did not measure: below normal, Windows kept the steps that are
|
||||
one process (the read, the lift) on a hybrid Intel CPU's efficiency cores while the performance cores idled."""
|
||||
env = os.environ if env is None else env
|
||||
return BELOW_NORMAL_PRIORITY_CLASS if env.get("HOOKSHOT_LOW_PRIORITY") == "1" else 0
|
||||
|
||||
|
||||
# ---------------- the build tools (Runner.cs: Tools) ----------------
|
||||
|
||||
class Tools:
|
||||
@@ -96,7 +105,7 @@ class Runner:
|
||||
p = subprocess.Popen(build_command(self.tools, self.args), cwd=self.tools.root,
|
||||
env=build_env(self.tools, self.workers, self.ngx_sdk), stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE, stdin=subprocess.DEVNULL,
|
||||
creationflags=CREATE_NO_WINDOW | BELOW_NORMAL_PRIORITY_CLASS)
|
||||
creationflags=CREATE_NO_WINDOW | build_priority())
|
||||
except OSError as e:
|
||||
self.on_finished("The build tools could not start: %s" % e)
|
||||
return
|
||||
|
||||
@@ -109,8 +109,7 @@ second game.
|
||||
pipeline compiles share it, and extra helper threads have lowered fps before. Thread counts are measured, never
|
||||
raised by default (`HOS_VCORES`, `RX_VK_CAPTURE_THREADS`, `HOS_THREAD_TIMES=<seconds>`, the `HOS_SAMPLE` profiler
|
||||
with `scripts/prof.py`). The one exception, by the owner's choice (2026-11-15): the Replay helper threads row is
|
||||
Automatic unless set, which is none on every PC since 2026-11-17 (the helper threads slowed the game's own threads in the
|
||||
owner's play); a count set on the row keeps its threads only where trials in play measure the
|
||||
Automatic unless set, none with four cores or fewer, and its threads are kept only where trials in play measure the
|
||||
frames shorter, or, without a trial, where the replay is plainly the frame's limit by a margin over the GPU's time
|
||||
(the rule in `gpu/vk/replay_threads.h`, fitted to the owner's logs; a trial that finds them slower holds it).
|
||||
|
||||
@@ -264,6 +263,6 @@ dump, the runtime made game-neutral, the stage-1 tools checked on MKW's dump as
|
||||
repeat with a delay that keeps ~45 fps. The MKW session's mirror page skip fired 0 times here and was removed.
|
||||
Not an instrument's doing: with nothing attached, photographed from outside the window (37 s, ~2200 photographs): 16 with `RX_VK_FRAMEGEN=0`, none at the user's 4x. With
|
||||
`RX_VK_SUBMIT_DELAY_US`: 7 at 300, 0 at 1000; a repeat at 1000 with shots still had 7 events against 50-60. So it is a race with the game's threads: less overlap, fewer. The delay is a test, not a fix.
|
||||
- The builder's first full build: 43 minutes at below-normal priority, 0 failures; the folder starts from a double click and reaches the title at 60 fps.
|
||||
- The builder's first full build: 43 minutes at below-normal priority (the builders' start then; since the performance audit's OS-57 normal, below normal with `HOOKSHOT_LOW_PRIORITY=1`), 0 failures; the folder starts from a double click and reaches the title at 60 fps.
|
||||
- Render conditions here gate single lights and read reports earlier in the same stream, so they cannot be read at record time.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Hookshot (oot-recomp)
|
||||
|
||||
**Hookshot** is the port's name (as Skybound is TOTKPort's and BlueShell is mkw-recomp's); the maintainer's repository
|
||||
folder stays `oot-recomp`. The game builds as `hookshot.exe` + `hookshot_vk.dll` (`hookshot` + `hookshot_vk.so` on Linux).
|
||||
folder stays `oot-recomp`. The game builds as `Triforce.exe` + `triforce_vk.dll` (`triforce` + `triforce_vk.so` on Linux).
|
||||
|
||||
A static recompilation of the Switch 2 *The Legend of Zelda: Ocarina of Time* remake to native x86-64 Windows and Linux:
|
||||
the game's code lifted to C (NotRexed's a64-kit, Rexcomp's AArch64 kit), the Horizon OS and NVN2 implemented
|
||||
@@ -79,18 +79,42 @@ screen. It costs some GPU time on cards that cull quickly, so it is off unless s
|
||||
| `HOS_WINDOW_SIZE=<w>x<h>` | The window's size in pixels (1280x720 by default, wider for an ultrawide picture; 64 to 16384 a side) |
|
||||
| `HOS_WINDOW_NOACTIVATE` (set) | The window opens behind the others and does not take the focus (Windows) |
|
||||
| `HOS_FULLSCREEN=1` | Starts in fullscreen; the Insert menu's Fullscreen row is then left alone |
|
||||
| `HOS_ALT_MENU=1` | (Triforce, 11-22, after Casual Gamer's #dev-fixes post) A lone Alt is left to Windows, as before: it enters the menu loop on the window's thread, which during the start-up screen is the one waiting for the shaders, and the screen froze until a key was pressed. By default the window, which has no menu bar, answers that command itself (`host/display.c` `keymenu_dropped`, `tests/test_alt_menu.py`); Alt+Space's system menu, Alt+Enter, F10 and Alt+F4 are as they were |
|
||||
| `HOS_AUDIO=0` | No sound device is opened (the mixer still runs); `scripts/run-vk.ps1` sets it unless `-Sound` |
|
||||
| `HOS_AUDIO_EFFECTS=0` | The game's plain reverb, delay and biquad filter effects on its mixes and its splitter destinations' biquad filters are accepted and left out, as before they were emulated (the sound unfiltered and at full level: the "Volcano eruption audio bugged" ticket); the I3DL2 reverb still runs. By default they run on the mix buffers in the order the game added them (`host/nn_audio.c` "mix effects"; `tests/test_audio_mix_effects.py`) |
|
||||
| `HOS_LANGUAGE=<code>` | The game's language for this run, a code from `language.txt` |
|
||||
| `HOS_OUTPUT_RES=<0..3>`, `HOS_HANDHELD=1`, `HOS_ASPECT=<ratio>` | Over the options file: the output resolution (0 2048x1152, 1 2560x1440, 2 3840x2160, 3 1920x1080), the handheld profile, a picture wider than 16:9 (2.3889 for 3440x1440; the Ultrawide row's 21:9 is 2.3704, 64:27, and its 32:9 3.5556) |
|
||||
| `HOS_DYNRES=0`, `HOS_REALTIME_STEP=0`, `HOS_TEXT_SPEED=<0..3>` | Over the options file: Resolution 100% (non-zero: Auto), Game speed Per frame (1: Real time), Text speed |
|
||||
| `RX_VK_FIRST_START_AUTO=1`, `RX_VK_FIRST_START_AUTO=<MB>` | (Triforce, 11-22, the performance audit's PRESENT-46, after Source A's; off by default) A first start sized to the card: with no options file, `RX_VK_LOW_SPEC` not asked and `HOS_DYNRES` not set, a weak card starts with the Render resolution row at 50% in place of Auto, or at 33% for an integrated GPU beside 4 processor threads or fewer (`gpu/vk/first_start.h`, `gpu/vk/vk_menu.cpp` `menu_first_start`, called from `mkwvk_init` once the device is made). Weak is Source A's tier 1: an integrated GPU (a handheld's is one; the `SteamDeck` variable is not read, it took desktops for handhelds), a card without mesh shaders, or 4.5 GB of video memory or less. Only that row is set: the upscaler, the textures and the output stay, and nothing is saved, so each start chooses again until the player saves options. A number over 1 plays a card of that many MB (the lab: `=4096` on a large card). Not set or `=0`: as before. Off until the owner decides what a first start on a weak card gets; unmeasured (Source A states no gain and tried it on one RTX 4070 Ti). One `menu: first start:` line says the choice |
|
||||
| `HOS_STEP_STEADY=0` | (Triforce, on by default since the lab's A/B; `=0` the mean of the last five as before) The game's real-time step kept steady, after NX2navi's steady step (`host/step_steady.h`, `host/nn_vi.c` `realtime_step`): the mean of the last 12 present intervals without their longest and shortest in place of the mean of the last five (`HOS_REALTIME_WINDOW`), the paced period itself where that mean is within 3% of it, and what the display showed and the game was not given repaid at a 64th a frame, 10% of the step at most (a quarter second owed at most). A cap the game holds steps it by the period exactly, and a hitch is paid back over most of a second instead of in the next five frames (a 50 ms frame at 240: 200 frames of at most 10% more, where the mean of five gave five steps of 13 ms). Game time still follows the clock |
|
||||
| `RX_VK_FRAMEGEN=0`, `RX_VK_FRAMEGEN_MULT=<2..8>`, `RX_VK_PACE=0`, `RX_VK_UPSCALE=<0..2>` | No frame generation whatever the menu says; over the options file: its multiplier, frame pacing, the upscaling filter |
|
||||
| `RX_VK_FG_KEEP=1` | (Triforce, 11-21, the performance audit's PRESENT-18) Frame generation's images are kept once made, as before. The default lets them go after 120 presents in a row with frame generation off (about two seconds at 60, so a row stepped through keeps them): the built-in interpolation's frames and made-frame sets, which stayed in VRAM until a resize after it was turned off or left for NVIDIA's own, and AMD FSR 4 frame generation's four images of the picture without the HUD once that row is left. The display thread is drained and the GPU idle first; they are made again at the next frame that needs them. The log says how many MB went (`gpu/vk/framegen_idle.h`, `vk_framegen.cpp` `framegen_idle`) |
|
||||
| `RX_VK_CAPTURE_TABLES=0` | (Triforce, 11-21, the upscaler audit's UPS-02) The stored draws' two tables as `std::unordered_map`, emptied and filled every frame, as before. While NVIDIA DLSS, AMD FSR 4 or AMD FSR 3.1 upscales, every plain draw into the scene stores its positions and is drawn again into the motion vectors; the count of a model's draws and the frame before's draws by their key took a node from the heap for every stored draw every frame (about 1,400 of each in the owner's log, whose status line said 0.65 ms of CPU a frame for the stored draws in all). The default keeps their memory from frame to frame, so a frame the size of the one before takes nothing from the heap, and gives the next frame's list of draws its room at once. The status line's `ms CPU a frame` is the measure (`gpu/vk/capture_tables.h`, `vk_temporal.cpp` `capture_motion`). Not built or run in the game when it was written |
|
||||
| `RX_VK_REDRAW_STATE=0` | (Triforce, 11-21, the upscaler audit's UPS-03) Every stored draw drawn again into the motion vectors sets the primitive topology, the primitive restart and its index buffer before it draws, as before. The default sets each only where the draw's differs from what the pass has set so far (its first draw sets all three): about 900 draws a frame are drawn again in the owner's log, nearly all of them triangle lists without restart, so two commands a draw are left out, and the index buffer's where two draws in a row bind the same one at the same offset (`gpu/vk/redraw_state.h`, `vk_temporal.cpp` `capture_motion`). Not built or run in the game when it was written |
|
||||
| `RX_VK_DLSS_MODE_SLACK=0` | (Triforce, 11-22, the performance audit's PRESENT-38) DLSS's quality mode found strictly, as before: a render size is a mode's only inside the range NGX answers. Not set: a size outside a range by a rounding (a 64th of the range's largest size, 2 pixels at least: `gpu/vk/dlss_checks.h` `mode_for`) is that mode's, so the Render resolution row's 33% at 2560x1440 (854x480, NGX's is 853x480) draws with DLSS and not the game's own upscale; and the feature there is is let go only once a mode took the new size. The lab's `dlssstrict` phases switch it within a run |
|
||||
| `RX_VK_DLSS_MODEL_SETTLE=<frames>` | (Triforce, 11-21, the performance audit's PRESENT-37) The DLSS model row steps K, M, L, NVIDIA's default and applies live: going from K to L made a feature for M on the way, tens of ms each, and NGX keeps a released feature's video memory for some seconds. A new preset is taken once the row has held it for `<frames>` frames, 30 when not set; the feature already made draws on meanwhile, and with no feature the row's preset is taken at once. `0`: at once, as before (`gpu/vk/dlss_checks.h` `PresetSettle`, `vk_dlss.cpp` `prepare`) |
|
||||
| `RX_VK_DLSS_CNN_VRAM=1` | (Triforce, 11-22, the performance audit's PRESENT-36, after Source A's and Source B's; off by default) On a card with less than 7 GB of video memory the DLSS model row's K (the default) asks NGX for preset E, NVIDIA's last CNN model, and the row reads "CNN (E)" (`gpu/vk/upscaler_rows.h` `cnn_for_vram`, `gpu/vk/vk_dlss.cpp` `wanted_preset`, `dlss_cnn_vram`). M, L and NVIDIA's default stay as chosen, `RX_VK_DLSS_PRESET` goes over it, and cards of 7 GB and more are not touched. Source A measured it on a 6 GB laptop RTX 3050 (1080p, DLSS Performance, one run a preset): 15.75 to 14.20 ms of GPU a frame, NGX's own memory 85 to 58 MB. Off here, as in Source B: preset E ghosts more on grass and thin objects at the smallest render sizes and NVIDIA marks it deprecated, so the picture is the owner's to look at first. A DLSS runtime without E falls back to NVIDIA's default; `RX_VK_DLSS_LOG=1` shows the preset NGX took. One `vk: NVIDIA DLSS: ... MB of video memory: the K row draws with preset E` line says it is in use; `RX_VK_TEST_CARD_MB=6144` plays a 6 GB card |
|
||||
| `RX_VK_DLSS_FEATURE_MAX=1` | (Triforce, 11-21, the upscaler audit's UPS-01) NVIDIA DLSS's feature made for the largest render size its quality mode allows, whatever the Render resolution row says, as before. NGX answers that largest size as the output's own, so at a fixed share the feature was made for 2.25 times the pixels it was ever given at Quality (4 at Performance, 9 at Ultra Performance), and the chain's colour, depth and motion images with it; the owner's log has DLSS's own video memory at 1069 MB for such a feature with preset M, where NVIDIA's table has 456 MB at 4K, and NVIDIA's guide says the cost of presets L and M follows the size the feature is initialized for. The default makes a fixed share's feature for its own render size; the row's Auto (the game's dynamic resolution), and any run in which the render size is seen changing under one output, make it for the mode's whole range as before (one feature made again when that is first seen). DLAA's is the output's either way. The `feature N made` line says which, and the status line's `its own ... MB` and `its images ... MB` are the measure (`gpu/vk/dlss_feature.h`, `vk_dlss.cpp` `prepare`). Not built or run in the game when it was written |
|
||||
| `RX_VK_DLSS_PREWARM=1` | (Triforce, 11-22, the performance audit's PRESENT-32, after Source A's: its first step; off by default) NVIDIA DLSS at the output's size takes the scaled quality mode whose range holds that size, and only NVIDIA DLAA the one-size mode (`gpu/vk/dlss_checks.h` `dlaa_feature`, `gpu/vk/vk_dlss.cpp` `prepare`). With the Render resolution row at Auto the game starts at the output's size and lowers it some frames later: before, a one-size feature and then a second one made in play (Source A's save load-in: 119 ms, then 29.5 ms 17 frames on); with the switch one feature, for its mode's whole range. Off by default because DLSS at full size then draws with the scaled mode's network, not DLAA's: a picture to compare first. The rest of the entry is not built: making the feature, the chain's images and a first evaluation ahead in a light frame (a title or loading screen) needs the first gameplay upscale's sizes and colour kind before it has happened, which only a run with DLSS can settle. `tests/test_dlss_prewarm.py` runs the decisions over a load-in |
|
||||
| `RX_VK_FRAMEGEN_REFRESH=1` | (Triforce, 11-21, the upscaler audit's UPS-05; off unless set) The Frame generation row's 2x to 8x make no more frames for each of the game's than the display's refreshes that fall in one frame of the game: the game's recent frame time over the display's period, rounded up, a tenth of a refresh forgiven, never more than the row's number and never fewer than the game's own frame. Without it the row's number is made whatever the display shows: the owner's log has 5x on a 165 Hz display with the game near 66 frames a second, 331 frames a second presented, each present call 2.2 to 3.0 ms (0.03 ms without frame generation) and the display thread's line `0 frames shown on time, 1655 late`. Auto and AMD FSR's row are not touched. A `vk: frame interpolation: N frame(s) for each of the game's` line says each change (`gpu/vk/framegen_refresh.h`, `vk_framegen.cpp` `framegen_record`). Not built or run in the game when it was written |
|
||||
| `RX_VK_FRAMEGEN=0`, `RX_VK_FRAMEGEN_MULT=<0..9>`, `RX_VK_PACE=0`, `RX_VK_UPSCALE=<0..2>` | No frame generation whatever the menu says; over the options file: the Frame generation row's value (0 Off, 1 Auto, 2 to 8 the multiplier, 9 AMD FSR frame generation: a lab run's pin for each generator; `gpu/vk/framegen_rows.h` `env_row`), frame pacing, the upscaling filter |
|
||||
| `RX_VK_FG_OWN_MOTION=0` | (Triforce, FG-4) Frame generation's motion the camera's alone, as before, for comparing. Without it, while NVIDIA DLSS or AMD FSR 4 upscale, the depth and motion frame generation takes (AMD's, NVIDIA DLSS frame generation, FSR 3.1's interpolation) are made from the upscaler chain's frame, with what moves by itself drawn into the motion (`gpu/vk/vk_temporal.cpp` `fg_inputs_from_chain`, `gpu/vk/vk_fsr3_inputs.cpp` `chain_motion`): also where the gameplay network does not translate on the card and the upscaler draws it in its place (RDNA 3), where they were never made before and AMD's frame generation made no frame |
|
||||
| `RX_VK_DLSSG_OWN_MOTION=1` | (Triforce, 11-22) NVIDIA DLSS frame generation is given the upscaler chain's motion, as before (`RX_VK_FG_OWN_MOTION` above). By default it is given the camera's alone, from FSR's inputs: with the chain's the owner's flicker of the whole picture while the camera moved came back on 11-22, with frame generation at 2x and DLSS at 50%, and it stayed with the upscaler audit's commits set back; with `RX_VK_FG_OWN_MOTION=0` it was gone. DLSS frame generation finds what moves by itself with its own optical flow. AMD's frame generation and FSR 3.1's interpolation keep the chain's (`gpu/vk/fg_motion.h`, `vk_fsr3_inputs.cpp` `chain_motion`). Not built when it was written: the same as the run with `RX_VK_FG_OWN_MOTION=0`, for DLSS frame generation alone |
|
||||
| `RX_VK_DLSSG_CLIP=0` | (Triforce, 11-20) NVIDIA DLSS frame generation is given the game's own camera matrices, as before, for comparing. Without it they are in the clip space of the depth it is given (FSR's copy, 1 at the near plane): the game's clip z runs from -1 at the near plane to 1 at the far one, and with its matrices that depth read as a clip z put what is far next to the camera, which showed as a flicker of the whole picture while the camera moved (`gpu/vk/dlss_math.h` `depth_clip_projection`, `gpu/vk/vk_dlssg.cpp` `frame`) |
|
||||
| `RX_VK_FG_HUDLESS=0` | (Triforce, FG-2) No picture without the HUD is taken for AMD's frame generation, so its library makes no frame (the game's frame alone): a test. Without it the gameplay upscale's output is taken before the HUD is drawn into it, sRGB-encoded as the game's last pass encodes it, and given as `HUDLessColor` (`gpu/vk/vk_framegen.cpp` `framegen_hudless_note`, `hudless_for`); a present without it shows the game's frame alone; with HDR Native or RenoDX's RGBA16F scene AMD's library is not asked and the renderer's own makes the frame, as at 2x |
|
||||
| `RX_VK_FRAMEGEN_FINE=0` | Frame generation's own made frames (Auto, 2x to 8x) the old way: a vector per 16x16 pixels in steps of 4 pixels, a blend of four of them per pixel, a pixel alike in both frames taken as still. Without it, a vector per 8x8 pixels to a fraction of a pixel, settled among its neighbours, and one motion per pixel (`gpu/vk/vk_framegen.cpp` `fine_vectors`, `shaders/fg_fine_*.comp`), which keeps moving straight lines straight and thin lines drawn (`tests/test_framegen_lines.py` measures both) |
|
||||
| `RX_VK_PACE_SMOOTH=0` | (Triforce, on by default since the lab's A/B; `=0` off) The Frame pacing row on the plain present too, without frame generation: with the row on, a picture of the game's that comes sooner than seven eighths of the recent interval after the last one waits for that, its blit on the queue and the queue's lock let go; a late one goes at once, and none waits more than 50 ms (`gpu/vk/present_smooth.h`, after NX2navi's `pace_smooth`). Without it the row spaces only frame generation's frames, as before. With `RX_VK_PRESENT_THREAD=0` the present is on the game's presenting thread, so a wait also holds that thread's next frame: what that does to the rate under the cap is for a measurement before it is on. A `vk: frame pacing` line every 1200 pictures says how many waited and how long |
|
||||
| `RX_VK_PRESENT_THREAD=1` | (off by default since the lab showed no gain) (Triforce, on by default; `=0` as before) The game's presents go out from a present thread of their own (`gpu/vk/present_thread.h`, after NX2navi's present thread): the presenting thread records and submits the blit as before (the frame fence, the swapchain's image, the overlays, the bug capture's copy and the frame log's: the same commands in the same order on the queue), then hands the pacing's wait (`RX_VK_PACE_SMOOTH`) and the present call to that thread and goes on to its next frame; the next present waits first until the one handed over is out, so one is in hand at most. Not with frame generation, NVIDIA DLSS frame generation or AMD Anti-Lag 2 (presents and stages of their own); NVIDIA Reflex's present markers carry their frame's id. The `vk: a frame's present` line every 120 presents says how many went out from it, the presenting thread's time in the present and how much of it was the wait for the present before, and the pacing's wait and the present call (on whichever thread); the stall line's present is the presenting thread's, with that wait named |
|
||||
| `RX_VK_REFLEX_LIMIT=1` | (Triforce, off by default) With the NVIDIA Reflex row on and no frame generation, Reflex's sleep holds the Game frame rate cap (the sleep mode's minimum interval) where each frame starts, in place of the game's own wait, as the Reflex frame limit row does with DLSS frame generation: one wait a frame, timed by the driver (`gpu/vk/vk_reflex.cpp` `reflex_pace`, the rule `gpu/vk/dlssg_pace.h`'s; after NX2navi's `low_latency`). The game's own wait holds a movie, a frame RivaTuner holds, a window that showed nothing for 200 ms, and the rest of the run once over half of 60 frames came sooner than three quarters of the period, or when the driver refuses the interval. `vk: NVIDIA Reflex: frame limit:` lines say who holds it; the Full overlay's Frame limit line says NVIDIA Reflex after the rate. The Reflex frame limit row's text does not cover this switch yet |
|
||||
| `HOS_PACE_HANDOFF=0` | The game's own wait paces every frame, whatever the Reflex frame limit row says and whether RivaTuner Statistics Server runs: the renderer is never asked whether another limiter holds a frame, and RivaTuner gets no limit from the game (`host/nn_vi.c` `pace_handed`, `gpu/vk/vk_pace.cpp`) |
|
||||
| `HOS_FPS_STEADY=0`, `=1`, `=2` | (Triforce, off by default: the Steady frame rate row, over it) 1 any rate, 2 steps of the display's refresh: the game's frames paced to a period this PC holds in the scene, never shorter than the Game frame rate cap's (`host/pace_steady.h`, `host/nn_vi.c` `steady_period`). The rate is chosen by probes (`pace_steady_probed`): 32 frames at the cap, unpaced, the last 24 of them measured, at the start, 2 s after a load, at least every 12 s, and when a quarter of the last 64 frames ran late (2 s after the last probe at the soonest, twice that each time a probe changes nothing, up to 12 s); the rate becomes the first the last three probes' 90th percentile fits in with 2% to spare where that is slower, or the first it fits in with 5% to spare where that is faster. A frame paced slower does more work (the lab's Market: 11.6 ms unpaced, 15.5 ms paced at 55 fps), so the frames' own measure as they run chased the rate down; frames late now only bring a probe on, and the rate is never under what a probe shows the PC holds. `HOS_FPS_STEADY_PROBE=0`: no probes, the rule below as before. Without probes: what a frame took is its present interval less the longest of the pacing's waits in it (the acquire's, on the presenting thread or another, and the present's hold), and what it needed the interval less all of them (OoT's main thread and Presentation Thread take turns; where the waits add up to the whole interval, the longest: `pace_steady_measure`); a quarter of the last 64 frames that took more than the period lowers it at once to the first rate their 90th percentile fits in with 2% to spare, and once it has held 3 s since a raise (6 s since a lowering, doubled for each lowering within 30 s of a raise, up to 120 s, and back to 6 s at a load) it rises to the fastest rate the 90th percentile of what the last 512 frames needed fits in with 5% to spare (one rate at a time where the game acquires on another thread). A frame that took over 2.5 times the median of the last 64 (hitches among them), a present interval over 250 ms, and the frames of the 2 s after such a load (the scene is not its measure yet) are left out; the first lowering after a load waits for 128 frames of the new scene and takes their 90th percentile. The acquire's wait starts the frames a period apart (the steady step then gives the game the period as its time step) and the present holds each picture of the game's to the period after the last, less a 64th of it (`gpu/vk/present_smooth.h` `present_smooth_paced_at`, with or without the Frame pacing row; not with frame generation). Another limiter holding the frames (RivaTuner, Reflex) puts the cap back while it does. `vi: steady frame rate:` lines at each change say what the frames needed, and every 5 s what the rule was given (what the frames took and needed at p50 and p90, the present interval's p50, the waits a frame by kind, the frames kept and left out by reason, how many of the last 64 kept were late, and the probes and what the last three took unpaced); the `vk: frame pacing` line counts the present's holds |
|
||||
| `RX_VK_ACQUIRE_FENCE=0` | (Triforce, on by default; `=0` as before) The swapchain's image waited for on the CPU, not on the replay's queue (`gpu/vk/vk_replay.cpp` `present_image`, `image_free`): the acquire signals a fence, the present waits for it, at most 250 ms, before it records anything for the image, and the blit's submit waits for nothing. AMD's Windows driver returns from the acquire at once, the image not yet free: with the window covered (Alt+Tab, another window or OBS in front) the blit's wait for the acquire held the queue, every later submit queued behind it, and the game froze for as long as the cover. An image not free in time is held (`vk: swapchain image ... held`): no frame is shown, the game goes on, and the next presents look at it again without waiting until it is back. The wait counts as the pacing's in the present line. With DLSS frame generation the acquire's semaphore as before |
|
||||
| `RX_VK_SURFACE_RECOVER=0` | (Triforce, 11-22, the performance audit's PRESENT-45, after Source A's; on by default) A lost window surface is not handled, as before: after `VK_ERROR_SURFACE_LOST_KHR` (a display driver reset, a monitor change, a remote session) every acquire fails without a word and the picture stays frozen until a restart. Not set, an acquire, a present or a swapchain's creation that answers it lets go of what hangs on the surface, in order: the present thread's present out, the device idle, the overlays' views, the images' semaphores, the swapchain, then the surface (`gpu/vk/vk_main.cpp` `invalidate_lost_surface`); and the next present's `create_swapchain` first makes a surface for the window again with the startup's calls (`open_window_surface`), only while the window has a size (a minimized window waits), one try each 250 ms at most, with the presents' own queue chosen again for it. A loss seen on the present thread is only noted there and handled by the next present. Nothing changes while no surface is lost (every new statement is behind that result or a missing surface, and the startup's own code is as it was), nor while NVIDIA DLSS frame generation runs (the swapchain is Streamline's). `vk: the window's surface is lost` and `... is made again` lines say it. Never seen on a real driver here, and the window's path is not in the scripted (headless) runs: `tests/test_present_surface_lost.py` runs the code against a model of a driver that loses its surface at each call |
|
||||
| `RX_VK_REFLEX_LIMIT=1` | (Triforce, off by default) With the NVIDIA Reflex row on and no frame generation, Reflex's sleep holds the Game frame rate cap (the sleep mode's minimum interval) where each frame starts, in place of the game's own wait; and with DLSS frame generation, Streamline's Reflex holds it the same way (`gpu/vk/vk_dlssg.cpp` `pace`; options_version 7: the Reflex frame limit row is gone, and this is its only switch until that path has been played on an RTX 40/50 card; `vk: dlssg: frame limit:` lines say who holds it): one wait a frame, timed by the driver (`gpu/vk/vk_reflex.cpp` `reflex_pace`, the rule `gpu/vk/dlssg_pace.h`'s; after NX2navi's `low_latency`). The game's own wait holds a movie, a frame RivaTuner holds, a window that showed nothing for 200 ms, and the rest of the run once over half of 60 frames came sooner than three quarters of the period, or when the driver refuses the interval. `vk: NVIDIA Reflex: frame limit:` lines say who holds it; the Full overlay's Frame limit line says NVIDIA Reflex after the rate. |
|
||||
| `HOS_PACE_HANDOFF=0` | The game's own wait paces every frame, with DLSS frame generation's Reflex too and whether RivaTuner Statistics Server runs: the renderer is never asked whether another limiter holds a frame, and RivaTuner gets no limit from the game (`host/nn_vi.c` `pace_handed`, `gpu/vk/vk_pace.cpp`) |
|
||||
| `HOS_MEM_QUERY_USED=0` | (Triforce, 11-19) `nn::os::QueryMemoryInfo` answers the memory in use as the program and the system's part only, as before. By default it is the program, the heap and every page the game mapped beyond it, at most the total, as Horizon answers (`host/hos_mem.c` `query_used`): the game's resource cache sizes what it may still take from it, and without it kept every area it ever loaded (12.5 GB of its 9809 MB after four areas). Needs the census on (`HOS_MEM_CENSUS`). `HOS_MEM_QUERY_SLACK_MB=<MB>` (1024 by default): that much less of the game's pages answered as in use, room for its cache beyond a Switch's (our game needs ~3.2 GB of regions at a save load where a Switch leaves ~2.8; with 0 it evicted in every scene) |
|
||||
| `HOS_OBJ_CACHE=<n>` | (Triforce) The per-thread cache that finds a guest nn::os object (mutex, event, condition variable ...) by its address (`host/nn_os_sync.c` `obj_lookup_cached`, `tests/test_obj_cache_size.py`): by default 16,384 entries, four ways to a 64-byte set picked by murmur3's finalizer, the oldest way replaced; 256 KB a thread, allocated at its first lookup. The direct-mapped cache missed at nearly every step of the game's walk over some 4,000 mutexes 0x80 apart. n: 256 to 65,536 entries (down to a power of two); `0`: the direct-mapped 4,096 entries, as before. Every 10 s the log's `sync: object cache` line counts the lookups and misses |
|
||||
| `HOS_NO_OBJ_CACHE=1` | No per-thread object cache at all (either kind): every nn::os call looks its object up in the shared table |
|
||||
| `HOS_GUEST_MEMFD=0`, `=1` | (Linux) The guest window as a memfd's, its pages handed to the GPU as dma-bufs (udmabuf), where `/dev/udmabuf` can be opened: amdgpu checks every page of a host-pointer import again at each submission, 15-45 ms a submission in Kokiri. (Triforce, 11-21) Also where udmabuf's `size_limit_mb` cannot be read (Flatpak and other sandboxes hide `/sys/module`): its default, 64 MB, is assumed and the log says so; only a limit that reads 0 keeps the window anonymous. The log's `mem: the guest window is a memfd's` line. `=0`: anonymous memory, host-pointer imports; `=1`: the memfd all the same |
|
||||
| `HOS_MEM_TRACE=1` | (Triforce, lab) Logs every address region and page call of the game with its size and caller (`memtrace:` lines; a region's with its call stack) and every `QueryMemoryInfo` answer |
|
||||
| `RX_VK_WB_EXCL_CLIP=0` | (Triforce, 11-22; on by default with `RX_VK_CAP_ONLY_GPU=1`) A written binding is copied back to guest memory whole at the submission's end, as in 0.6.0. By default the parts of it in memory the capture leaves out (heap memory between the game's pools inside an imported chunk) are not: the collection does not stamp the CPU's writes there, so the mirror's bytes there are stale, and the write-back diff copied them over the game's newer ones. A pointer table's bare entry (its 64-byte head marked written, `gpu/vk/vk_draw.cpp`) did so over a heap block 0x18 past its base: the 0.6.0 crashes at area changes in guest 0x803b44e0 (a block header of 0x9ed00000001 or 0x1aa88000013fe), 0x80a30a00 and 0x80a31030 (`gpu/vk/wb_excl_clip.h`, `gpu/vk/vk_memory.cpp` `gpu_buffer_bind`; `tests/test_wb_excl_clip.py`). The first 20 clipped write-backs are logged (`vk: write-back of ... not copied back`) |
|
||||
| `HOS_FPS_STEADY=0`, `=1`, `=2` | (Triforce, off by default: the Frame pacing row's two Steady values, over them) 1 any rate, 2 steps of the display's refresh: the game's frames paced to a period this PC holds in the scene, never shorter than the Game frame rate cap's (`host/pace_steady.h`, `host/nn_vi.c` `steady_period`). The rate is chosen by probes (`pace_steady_probed`): 32 frames at the cap, unpaced, the last 24 of them measured, at the start, 2 s after a load, at least every 12 s, and when a quarter of the last 64 frames ran late (2 s after the last probe at the soonest, twice that each time a probe changes nothing, up to 12 s); the rate becomes the first the last three probes' 90th percentile fits in with 2% to spare where that is slower, or the first it fits in with 5% to spare where that is faster. A frame paced slower does more work (the lab's Market: 11.6 ms unpaced, 15.5 ms paced at 55 fps), so the frames' own measure as they run chased the rate down; frames late now only bring a probe on, and the rate is never under what a probe shows the PC holds. `HOS_FPS_STEADY_PROBE=0`: no probes, the rule below as before. Without probes: what a frame took is its present interval less the longest of the pacing's waits in it (the acquire's, on the presenting thread or another, and the present's hold), and what it needed the interval less all of them (OoT's main thread and Presentation Thread take turns; where the waits add up to the whole interval, the longest: `pace_steady_measure`); a quarter of the last 64 frames that took more than the period lowers it at once to the first rate their 90th percentile fits in with 2% to spare, and once it has held 3 s since a raise (6 s since a lowering, doubled for each lowering within 30 s of a raise, up to 120 s, and back to 6 s at a load) it rises to the fastest rate the 90th percentile of what the last 512 frames needed fits in with 5% to spare (one rate at a time where the game acquires on another thread). A frame that took over 2.5 times the median of the last 64 (hitches among them), a present interval over 250 ms, and the frames of the 2 s after such a load (the scene is not its measure yet) are left out; the first lowering after a load waits for 128 frames of the new scene and takes their 90th percentile. The acquire's wait starts the frames a period apart (the steady step then gives the game the period as its time step) and the present holds each picture of the game's to the period after the last, less a 64th of it (`gpu/vk/present_smooth.h` `present_smooth_paced_at`, with or without the Frame pacing row; not with frame generation). Another limiter holding the frames (RivaTuner, Reflex) puts the cap back while it does. `vi: steady frame rate:` lines at each change say what the frames needed, and every 5 s what the rule was given (what the frames took and needed at p50 and p90, the present interval's p50, the waits a frame by kind, the frames kept and left out by reason, how many of the last 64 kept were late, and the probes and what the last three took unpaced); the `vk: frame pacing` line counts the present's holds |
|
||||
| `HOS_FPS_STEADY_PROBE=0` | (Triforce, with `HOS_FPS_STEADY` or the Steady frame rate row) No unpaced probes: the rate by the frames' own measure as they run, as before test31 (`host/pace_steady.h` `pace_steady_probed`, `host/nn_vi.c` `steady_period`); the frames' work grows when they are paced slower, and that rule slides down |
|
||||
| `HOS_PACE_SPIN=0`, `HOS_PACE_SPIN=<microseconds>` | (Triforce) The game's own frame wait on the high-resolution timer for the whole wait, as before, which wakes up to about 0.5 ms after the frame's time. By default the timer takes the wait up to 0.6 ms before the frame's time and the rest is yielded away on the clock, so the frame starts on its time (`host/pace_wait.h`, `host/nn_vi.c` `pace_sleep`); a number is another margin. Every 5 s in which frames waited a `vi: frame waits` line says how long after their time the waits ended, on average and at most |
|
||||
| `HOS_RTSS=0` | RivaTuner Statistics Server is left out entirely: nothing of it is read or loaded and its profile is not touched; a line `triforce_rtss_profile.txt` holds from a run that did not close is only reported in the log (`gpu/vk/rtss_limit.cpp`, *The options file* below) |
|
||||
@@ -142,11 +166,17 @@ case-sensitive, and an unknown one is ignored.
|
||||
| `HOS_THREAD_TIMES=<seconds>` | Every interval, the threads that used over 5% of a core |
|
||||
| `HOS_FPS_LOG` (set), `HOS_PRESENT_TRACE=<csv>` | The game's frame limiter, VRR flags and nominal rate every 300 presents; a CSV line per game present |
|
||||
| `RX_VK_FRAME_LOG=<csv>` | A CSV line per present: frame, seconds, frame time in ms |
|
||||
| `RX_VK_FRAME_TRACE=1` | A line a frame in `triforce_frames.csv` beside the game (the lab's scenarios keep it as `frames.csv`): present to present, the waits for shaders and pipelines, the uploads, and the replay's parts (`memsync_ms` ... `tex_lookup_ms`: the draws' parts are sampled and summed over every thread that records). (Triforce, wp20, `gpu/vk/frame_trace.h`) Then each frame split as the stall line splits a long one: `replay_ms` (the submits and the present phase), `present_ms`, `dispatch_ms`, `qsubmit_ms`, `par_wait_ms` (the replay thread's waits for its helpers' segments), `outside_ms` (the frame less the replay and the present: the game's own update), `game_wait_ms` (the game's fence waits), `captures_ms` (the captures at its submits), `wb_wait_ms` and `wb_held_ms` (the waits for write-backs, and their part after the writer's recording was done: `RX_VK_WB_WAIT_REC`), `qs_bg_ms` (the queue submits beside a background import). `python -I scripts/frame_rank.py <run folder or csv>` ranks what made the frames over the 99th percentile and over 1.5x the median by these, per window (the Market, the tour's stays, the loads) |
|
||||
| `RX_VK_WB_WAIT_REC=1` | (Triforce, off by default; the handoff's §12.9, `gpu/vk/wb_rec_wait.h`) A wait for a write-back still on the GPU (a capture's late pages on the game's submitting thread, a read or binding of a page put off) ends once the recording its submission was finished in is done on the GPU, not when the submissions' timeline reaches it: that timeline is held below any submission stopped at an event wait, and the lab's Market had 20-46 ms waits of the game's thread with the GPU 4 submissions behind. Whatever the switch, the wait for the recording comes first and the rest is counted: the stall line's `N of them X ms after their writer's recording was done`, the `late:` line's `ms of the wait after the recording that finished it was done`, the frame trace's `wb_held_ms`. Off: the captures' late-page wait orders something not known yet (`RX_VK_LATE_NEW`), so it is tried with the lab's flicker count first |
|
||||
| `RX_VK_FRAME_TRACE=1` | A line a frame in `triforce_frames.csv` beside the game (the lab's scenarios keep it as `frames.csv`): present to present, the waits for shaders and pipelines, the uploads, and the replay's parts (`memsync_ms` ... `tex_lookup_ms`: the draws' parts are sampled and summed over every thread that records). (Triforce, wp20, `gpu/vk/frame_trace.h`) Then each frame split as the stall line splits a long one: `replay_ms` (the submits and the present phase), `present_ms`, `dispatch_ms`, `qsubmit_ms`, `par_wait_ms` (the replay thread's waits for its helpers' segments), `outside_ms` (the frame less the replay and the present: the game's own update), `game_wait_ms` (the game's fence waits), `captures_ms` (the captures at its submits), `wb_wait_ms` and `wb_held_ms` (the waits for write-backs, and their part after the writer's recording was done: `RX_VK_WB_WAIT_REC`), `qs_bg_ms` (the queue submits beside a background import), `gpu_waits_ms` ((Triforce, 11-22, the performance audit's SYNC-27) every thread's time in calls that block on the GPU, `RX_VK_GPU_WAITS` below). `python -I scripts/frame_rank.py <run folder or csv>` ranks what made the frames over the 99th percentile and over 1.5x the median by these, per window (the Market, the tour's stays, the loads) |
|
||||
| `RX_VK_SETTLE_GATE=1`, `=2` | (Triforce, 11-22, off by default; the performance audit's SYNC-29, after Source A's; `gpu/vk/settle_gate.h`) A CPU read that lets the stopped queues whose waits are met go on (the readback's look, which `RX_VK_RB_SETTLE=1` turns on, and the two looks made for a range a texture may be in) takes the order's lock whenever a queue is stopped, and that lock is held through whole replays and presents. With the gate a site looks only while a queue is stopped **and** the CPU has signalled an event since the last finished look, or a stopped queue waits on an event whose value is read from guest memory; any other met wait was met by a signal in the stream, and the thread that replayed it looked before it let the lock go. `1`: the readback's look; `2`: the texture sites' too (new ground: those looks order the exposure meter's readback, so `2` needs the lab's flicker count). Unset or `0`: every look as before. The `RX_VK_LAB_AB` knobs `settlegate` and `texgate` are `1` and `2` in their phases (`rbsettle+settlegate` is the pair the audit asks for). The 3000-readback line and the texture catch-ups' 300-call line count the looks made and skipped |
|
||||
| `RX_VK_READBACK_LATE=<rule>[,<rule>]`, `RX_VK_LOG_READBACK_RANGES=1` | (Triforce, 11-22, the performance audit's SYNC-19, after Source A's; `gpu/vk/readback_late.h`) Ranges the CPU reads back **without** the wait for their write-back, from what guest memory holds (the last write-back made): a rule is a size in hex (`3980`: every range of 0x3980 bytes, the culling camera block Source A reads late by default) or `newest` (a range whose writer is the newest submission handed out: the game cannot have waited for it). **Unset: no rule**, every readback waits as before, until the lab has run it where the waits are long (a handheld, an AMD iGPU, a weak discrete card); `=0`: none either. The `RX_VK_LAB_AB` knob `rblate` is `3980` in its phases. A late read hands the game the frame before's values, and when the CPU resets a range read late the pending write-back lands over its reset (the exposure meter's flashes): `newest` can catch that meter, so it is never a default. `RX_VK_LOG_READBACK_RANGES=1`: with every 3000-readback line, the 12 ranges that waited longest (readbacks, waits, ms, how often their writer was the newest submission, how often read late), to find such ranges on other hardware; nothing is noted without it |
|
||||
| `RX_VK_WB_WAIT_REC=1`, `=2` | (Triforce, off by default; the handoff's §12.9, `gpu/vk/wb_rec_wait.h`) A wait for a write-back still on the GPU (a capture's late pages on the game's submitting thread, a read or binding of a page put off) ends once the recording its submission was finished in is done on the GPU, not when the submissions' timeline reaches it: that timeline is held below any submission stopped at an event wait, and the lab's Market had 20-46 ms waits of the game's thread with the GPU 4 submissions behind. Whatever the switch, the wait for the recording comes first and the rest is counted: the stall line's `N of them X ms after their writer's recording was done`, the `late:` line's `ms of the wait after the recording that finished it was done`, the frame trace's `wb_held_ms`. Off: the captures' late-page wait orders something not known yet (`RX_VK_LATE_NEW`), so it is tried with the lab's flicker count first. (Triforce, 11-22, the performance audit's SYNC-122, after Source B's) The reads' side: a readback whose write-back is not recorded yet waited on the submissions' timeline with no bound and no second look; it is counted now (the 3000-readback line's second line), and the stall line names the held part by caller (takes, reads, binds, readbacks). The variable is a mode: `1` as above, and such a readback waits in 1 ms slices, looks its writer's recording up between them and ends with it; `2` is the check, where no wait ends earlier and the readback's slices count the part after the recording was done (what `1` would not have waited); unset, `0` or any other text: off, one wait as before. The check of the pages a later write-back changes (the audit's SYNC-101) is not built. `RX_VK_TL_REC=1` and the lab knob `tlrec` ended a capture's wait at a submission's first part, before its burst's write-backs were recorded: they now end it at the recording the submission was finished in, as `=1` here does; `RX_VK_TL_REC=2` keeps the old lookup |
|
||||
| `RX_VK_LATE_INLINE=1` | (Triforce, 11-22, the performance audit's MEM-80, after Source B's; `gpu/vk/late_inline.h`; **off unless set**, not yet run in the game) A late page (one the CPU wrote while a submission still on the GPU writes it back) is waited for and taken again by default (`RX_VK_LATE_QUEUE`: at the queue's next submit). `RX_VK_LATE_NEW=1` (knob `latenew`) turns four no-wait rules on, each of which brought brightness steps back at the Castle Town save. This turns on the partial rule alone (knob `lateinline`): a page only part of which a submission on the GPU writes back has its other parts synced from the capture, no wait; pages of pools with no mirror, texture storage, pages written back whole and pages whose write-backs' ranges are not known are waited for as by default. The partial rule, here and under `RX_VK_LATE_NEW`, now asks which ranges are still on the GPU against the progress the capture read before its copies, not a second read at the take: a write-back done between the two counts as in flight, and its range is not synced from the older copy. `RX_VK_LOG_LATE` shows the pages waited for |
|
||||
| `RX_VK_PASS_TIMING=1` or `2` | GPU time per pass (2: per program too), logged every 600 presents |
|
||||
| `RX_VK_SLOW_LOG=<ms>` | The replay's times for each frame that took longer than this |
|
||||
| `RX_VK_STALL_LOG=<ms>` or `0` | On in every run (`gpu/vk/stall_watch.h`): every 600 of the game's frames a `vk: frame times` line (the longest frame and how many were over 33, 50, 100 and 250 ms, present to present and in the replay's own time), and for each frame of 50 ms or more a `vk: stall` line of where its time went: the replay's phases, memory sync's parts, the waits for write-backs still on the GPU (how far ahead, and whether behind a present's blit), the waits for shaders or pipelines, the uploads, the pools imported where they were bound, the GPU behind, the present (its image, fence, call and Reflex's sleep), the game's fence waits, the rest, and a pool's trial in guest memory if one is under way (`RX_VK_DEMOTE_QUICK`); and the new textures left for the next frame and whether the frame's picture was held (`RX_VK_HOLD_MS`), whose holds the 600-frame line counts too. At most 3 stall lines a second and 1500 a session. `<ms>`: the stall line's threshold; `0`: neither line |
|
||||
| `RX_VK_LOCK_CENSUS=1` | (Triforce, 11-22, the performance audit's THREAD-68, after Source B's; off unless set) The lock census: who holds the lock a thread waits for. A lock that is busy when a thread comes for it notes the waiter, the thread that held it and how long the wait was, and every 10 s a thread of the census's own logs the 12 pairs that waited longest, as `vk: lock census: <waiter> <- <holder> (<lock>) x ms/s (n/s, y us each)`. Counted: `replay_mu`, `sync_order_mu`, `held_mu`, and in `vk_memory.cpp` `pools_mu`, `sync_mu` and `cap_mu`. Threads are named by their descriptions (the game's threads and the renderer's own have them). Off, each lock is taken exactly as before; on, a free lock is one try and a store, and only a busy one reads the clock. The holder is read without the lock, so one that lets go at that moment can be misnamed. With `RX_VK_LAB_AB` naming a knob `lockcensus` it counts only in that knob's phases. Only the counting of Source B's is here, not its sampling of the holders' stacks (`gpu/vk/lock_census.h`) |
|
||||
| `HOS_STALL_HOST=0` | (Triforce, 11-22, the performance audit's OS-51, after Source B's; on whenever the stall line is) The stall line names a long frame's time on the replay's side and calls the rest outside the replay and the present. A present that comes `RX_VK_STALL_LOG`'s threshold (50 ms) or more after the last one also logs the host's part of that frame, a `vi: stall, the host's part` line: the game's file reads, writes, flushes and save commits (how many, MB, their time and the longest one), the discards, zero-fills and decommits of memory it let go and the give-back's passes, the waits for a virtual core summed over the game's threads, the process's page faults (soft and hard together) and its CPU time in the kernel and in its own code. Causes that did not happen are left out; `none of the host's causes` rules them out. At most 3 lines a second and 1500 in a session, as the stall line. It costs a clock read before and after each counted call and two system calls a present. `0`: none of it; so with `RX_VK_STALL_LOG=0` (`host/stall_host.h`, `host/mkw_glue.c` `hos_stall_host_presented`) |
|
||||
| `RX_VK_SLOW_TAKE_MS=<ms>` or `0` | (Triforce, 20 by default) A submit-time capture take that long or longer (`gpu/vk/vk_memory.cpp` `take_capture`): a `vk: slow capture take` line with where its time went (the marks and late pages, the pools lock, the retires, the stamps, the texture shadow, the buffer kept or given back), the first 200 of them. A Linux RTX 4090 near the Market stuttered with `memory sync [capture taken 30 to 110 ms]` while the 600-take average said 1.3 ms. `0`: none |
|
||||
| `HOS_PGO=<file>` | In a run of an `RX_PGO=gen` build: `<file>.reset` clears the counters, `<file>.dump` writes them to `<file>`. It is read before `hookshot_env.txt`, so set it in the environment |
|
||||
|
||||
### The GPU
|
||||
@@ -155,51 +185,108 @@ case-sensitive, and an unknown one is ignored.
|
||||
|---|---|
|
||||
| `RX_VK_VALIDATION` (set) | The Khronos validation layer |
|
||||
| `RX_VK_CHECKPOINTS=0` | No NVIDIA checkpoints (on by default; after a lost device they name the draw it stopped at). (Triforce) The boundaries between a frame's work have markers too: the write-back diff pass, each recording's start, uploads and end, the present's blit and its menu (`gpu/vk/checkpoint_kinds.h`); the report reads the two stages' last markers together, says what followed the last one reached, and logs the switches, the queue's timeline and the mirrors' piece binds the submits wait for. (P4) Each marking thread numbers its own markers in a ring of its own (15 of 4096; threads after the 15th share a 16th), no atomic shared by the recording threads; the report names a marker's ring and reads the markers around it in that ring |
|
||||
| `RX_VK_HANG_DUMP=<file>` or `0` | The hang watch (Windows) is on in every run: once no frame was shown for `RX_VK_HANG_SEC` seconds (20) with the game's window in front, the top of every thread's stack goes into the log and the whole stacks into `triforce_hang.txt` in the game folder, once a stall and at most three times a run. `<file>`: that file instead, and every second counts whatever window is in front. `0`: no watch |
|
||||
| `RX_VK_HANG_DUMP=<file>` or `0` | The hang watch (Windows) is on in every run: once no frame was shown for `RX_VK_HANG_SEC` seconds (20) with the game's window in front, the top of every thread's stack goes into the log and the whole stacks into `triforce_hang.txt` in the game folder, once a stall and at most three times a run. `<file>`: that file instead, and every second counts whatever window is in front. `0`: no watch (Triforce) The same report can be asked for at any time: put a file named `triforce_hang.txt.now` in the game folder (the report's name with `.now`); within a second the watch takes it away and writes every thread's stack, for a game that goes on showing frames and gets nowhere (a loading screen that never ends). |
|
||||
| `RX_VK_NOOPT` (set) | Pipelines built without the driver's optimisations |
|
||||
| `RX_VK_MESH_OPT=1` or `=0` | (Triforce) Task and mesh pipelines on AMD. Unset: built without the driver's optimizer on AMD's own drivers (it hung the GPU minutes into Kokiri on an RX 6600) and with it on RADV (without it, the foliage culling's task programs timed out the GPU's ring at the save load on a Steam Deck); the driver's part is made once more on RADV with mesh shaders. `=1`: with the optimizer everywhere. `=0`: without it on every AMD driver, RADV too, as before |
|
||||
| `RX_VK_GPU_CLOCK=0`, `=peak`, `=standard` | (Triforce, Linux) The Steam Deck's GPU held at amdgpu's peak stable power state while the game runs (`gpu/vk/vk_gpu_clock.cpp`): the Deck's automatic clock dropped while the frame waited on the CPU or a readback, and the GPU work after it ran slow (Kokiri handheld on a Deck OLED: 11.1 to 16.2 fps at the same 15 W; up to 4 W more where the APU was under its cap, so shorter battery life). Unset: only on the Deck's APU, and only while `power_dpm_force_performance_level` is `auto` (a level set by hand is left alone). The render node VK_EXT_physical_device_drm names is opened and the state set on an amdgpu context of the renderer's own (no root); the kernel gives the level back at the process's end, a crash too. The log's `vk: GPU clock:` line says what was done (AMD only). `=0`: nothing opened; `=peak` (or `=1`), `=standard`: that state on any AMD GPU, whatever the level |
|
||||
| `HOS_HALF_RATE_SHADING=1` | (Triforce, Linux) Keeps `RADV_FORCE_VRS_CONFIG_FILE`, which Steam's Game Mode gives every game (its Half Rate Shading). By default it is dropped before Vulkan loads when it names a file that exists: while it does, RADV on RDNA 2 and newer puts a forced shading rate into every pipeline's key, whatever the file holds, so the pipelines prepared in Desktop Mode or by the builder all compiled again (over 25 minutes to the title on a Deck). The slider then does nothing for this game, little loss: RADV keeps fragment programs that read their position at full rate, and nearly all of this game's do. `RADV_FORCE_VRS` is left alone. The log's boot: line says what was done. Can be set in `triforce_env.txt` |
|
||||
| `RX_VK_COMPUTE_PIN=all`, `lanes` or `shared` | (Triforce, the performance audit's PIPE-52, after Source A's and Source B's) Which compute programs' pipelines ask for subgroups of 32 lanes (`gpu/vk/compute_pin.h`, `gpu/vk/vk_draw.cpp` `pin_compute`). `all`, the default on every driver but Mesa's Intel one: every compute program, as before. `lanes`, the default on Mesa's Intel driver: only the programs that can tell how many lanes run beside them (a vote, a lane mask, the lane's index, a shuffle, FSWZADD, a matrix multiply, a barrier of Subgroup scope in the module, or shared memory in a workgroup of 32 invocations or fewer); the rest get the driver's choice, which Mesa's Intel compiler builds in a fraction of the time and memory (Source A, an Iris Xe: 0.8-1 GB over 23-25 s pinned, at most 300 MB unpinned). `shared`: as `lanes`, and any shared memory pins, whatever the workgroup. The log has `vk: compute programs held to 32 lanes: ...` where it is not `all` by default, and the pinned and free counts after the precompile. An unpinned program that did need 32 lanes computes wrongly: `=all` is the old pipelines. Not run on an Intel GPU here |
|
||||
| `RX_VK_FALLBACK_PHI_LIMIT=<n>` | (Triforce, the performance audit's PIPE-56, after Source A's) On Mesa's RADV for GCN 1 to 4 GPUs (HD 7000 to RX 500: RADV without 16-bit storage input and output) and on Mesa's Intel driver only: a mesh-fallback program with a compute stage of more than `<n>` `OpPhi` instructions is not handed to the driver; it is left out as a program the driver refused is, with a log line (8 at most), and its draws are not drawn (`gpu/vk/fallback_size_policy.h`, `gpu/vk/vk_draw.cpp` `fallback_compute_pipelines`). Unset: 50,000 on GCN (Source A: RADV for GFX6-8 had not built a 79,947-phi stage after 45-90 s and was killed at 25 GB), 20,000 on Mesa's Intel driver. `0`: no limit. No other driver has a limit, whatever is set. Not run on either driver here |
|
||||
| `RX_VK_FALLBACK_CALL_LIMIT=<n>` | (Triforce, PIPE-56) The same for a stage's `OpFunctionCall` instructions. Unset: 200 on Mesa's Intel driver (Source A, an Iris Xe: a 251-call stage unfinished after 27 minutes at 14 GB), none on RADV for GCN. `0`: no limit |
|
||||
| `RX_VK_NO_SPILLING_RATE=1` | (Triforce, the performance audit's PIPE-55, after Source A's; Linux build only) The Linux build sets `shader_spilling_rate=2` in its environment before the Vulkan instance is made (`gpu/vk/mesa_spilling.h`, `gpu/vk/vk_main.cpp` `create_instance`), unless the player has set that variable. Only Mesa's Intel shader compiler reads it: a program whose registers do not fit is built in fewer, larger steps (Source A, an Iris Xe: one compute program not built after 20 minutes and 13 GB, 32 s and 1.7 GB at rate 2). `=1` sets nothing, so the driver keeps its own rate. On Mesa's Intel driver the log has `vk: Mesa's Intel compiler spills at rate ...`. The Windows build sets nothing: under Proton, add `shader_spilling_rate=2` to the launch options. Not run on an Intel GPU here |
|
||||
| `RX_VK_DRIVER_FAULTS=0` or `2` | (Triforce, 11-22, the performance audit's PIPE-57, after Source A's; `gpu/vk/driver_faults.h`) On AMD's own Windows driver only (`VK_DRIVER_ID_AMD_PROPRIETARY`), unless `0`: a program whose pipeline build faulted inside the driver is not asked of the driver again this run, and its key is appended to `triforce_driver_faults.txt` beside the executable (one line: vendor, driver version, program) by the fault's handler, before a fault during the start's shader work restarts the game, so the next start with that driver skips it instead of faulting again (`vk: driver faults: N programs ... kept out of it`; delete the file to try them again, another driver version ignores its lines). And one build of a program is inside the driver at a time: a second waits outside it, a probe of the caches is told a compile is required. `2`: on every driver (the lab's); `0`: nowhere. On other drivers nothing of it runs (`gpu/vk/vk_draw.cpp` `fault_quarantine`, `build_graphics`, `guarded_graphics`) |
|
||||
| `RX_VK_PASS_BARRIER=game` or `full` | The barrier a draw pass starts with (`gpu/vk/pass_barrier.h`). `game`: a pass right after another, with nothing recorded between (no barrier of the game's, no copy, clear, uniform update or dispatch), waits for the earlier work in its fragment stages only, so its vertex, task and mesh work may overlap the earlier pass's fragments; a pass the replay itself split off for a hazard (`a pass of its own` in the log) and `RX_VK_BARRIER_EVERY_DRAW`'s keep a full one. (Triforce, P4) "Nothing recorded between" is the command buffer's own count (`RX_VK_BARRIER_CONTEXT`), so beside the Replay helper threads too. `full`: a full barrier at every pass start, as before. Unset: `game` with NVIDIA's driver, `full` on every other card. The log's `vk: pass barriers:` line says which, and the frame statistics' `pass starts ordered in their fragment stages only` how many a frame |
|
||||
| `RX_VK_SPLIT_BARRIER=pass` or `full` | (Triforce) A long submission goes to the GPU in parts of 120 draws and dispatches (`RX_VK_CHUNK`); `gpu/vk/barrier_rules.h`. `pass`: a pass open at a part's split goes on in the next part, begun again with the same targets behind a barrier of its attachments' outputs alone and with what its draws sampled and wrote, so the GPU does not drain between two draws of one of the game's passes; where the part's end records anything (its uniform updates, its write-backs) or an event's write is held, the full barriers as before. A parallel replay's segments are not split into parts: each begins and ends with a full barrier, so nothing goes on across a segment's edge. `full`: a full barrier at each part's end and the next one's start, as before. Unset: `pass` with NVIDIA's driver, `full` on every other card. The log's `vk: a submission's parts:` lines say which and, every 3,600 splits, how many went on in their pass and how many of those parts had uploads (whose own full barriers order them after the part before all the same) |
|
||||
| `RX_VK_CHUNK=<n>` | (Triforce, 11-22, the performance audit's SYNC-66, after Source B's; `gpu/vk/barrier_rules.h` `part_draws`) How many draws and dispatches a part of a long submission has in a serial replay: the GPU starts on the first part while the rest is recorded, and each split costs a queue submit, two full barriers and the part's bookkeeping (about 27 a frame at 120). Unset: the driver's default, **120 on every driver** until the lab has measured one (Source B cuts at 128 where the GPU idles while the CPU records and at 4096 on desktop drivers); `0`: whole submissions, never split; `120`: today's size whatever a later default says. The size was read once into a static: now the `RX_VK_LAB_AB` knob `chunk:<n>` changes it in its phases while the variable is unset (`RX_VK_LAB_AB=chunk:480,chunk:240` with `RX_VK_PARALLEL=0`). The log's first `vk: a submission's parts:` line says the size in force and the driver's default |
|
||||
| `RX_VK_SPLIT_BARRIER=pass` or `full` | (Triforce) A long submission goes to the GPU in parts of 120 draws and dispatches (`RX_VK_CHUNK`); `gpu/vk/barrier_rules.h`. `pass`: a pass open at a part's split goes on in the next part, begun again with the same targets behind a barrier of its attachments' outputs alone and with what its draws sampled and wrote, so the GPU does not drain between two draws of one of the game's passes; where the part's end records anything (its uniform updates, its write-backs) or an event's write is held, the full barriers as before. A parallel replay's segments are not split into parts: each begins and ends with a full barrier, so nothing goes on across a segment's edge. `full`: a full barrier at each part's end and the next one's start, as before. Unset: `full` on every card ((Triforce, 11-22, SYNC-66) this row said `pass` with NVIDIA's driver; `pass` has been off unless set since 11-16, when the lab's Market showed no gain from it: `barrier_rules.h` `split_in_pass`). The log's `vk: a submission's parts:` lines say which and, every 3,600 splits, how many went on in their pass and how many of those parts had uploads (whose own full barriers order them after the part before all the same) |
|
||||
| `RX_VK_GPU_WAITS=0` | (Triforce, 11-22, the performance audit's SYNC-27; on by default; not yet run in the game) The host's calls that block on the GPU are made without being timed, as before. By default each is timed where it is wrapped (`gpu/vk/vk_work.h`, `gpu/vk/gpu_wait_kinds.h`) and summed by kind: `vkWaitForFences` and `vkWaitSemaphores` with a timeout above 0 (fences, timelines), `vkQueueWaitIdle` and `vkDeviceWaitIdle` (idle), `vkGetQueryPoolResults` with the wait bit (queries). Polls count nothing, a wait inside a wait counts once, and the low-latency sleep's wait is left out as pacing. After each 120-present line the log has `vk: host waits for the GPU: ... ms a frame (fences, timelines, idle, queries; all threads)`, which counts what that line's "GPU-bound wait" (the recording slots' waits alone) does not, and the frame trace has `gpu_waits_ms`. The cost is two clock reads a blocking wait. The `RX_VK_LAB_AB` knob `nogpuwaits` turns the count off in its phases |
|
||||
| `RX_VK_ORDER_WAKE=1` | (Triforce, 11-22, the performance audit's SYNC-59; off unless set; not yet run in the game) A queue stopped at a wait for an event goes on when a submit finds the wait met. A signal of the CPU's (`nvnEventSignal`) wakes no one: the stop waits for the order thread's next `Sleep(1)`, or a game thread's wait yields up to 3 ms and then forces it. With the switch (`gpu/vk/vk_replay.cpp` `sync_watch`, `event_signal_queued`) the order thread waits on an auto-reset event, 1 ms at most, which the signal sets while a queue is stopped: one `SetEvent`, no lock and no replay on the signalling thread. And a game thread's wait for stopped work that sees a signal pending lets the queues whose waits are met go on first, as `sync_settle` does; nothing is forced. The order line counts the wakes and those that let work on: under about one a second, leave it off. The `RX_VK_LAB_AB` knob `orderwake` turns it on in its phases |
|
||||
| `RX_VK_RELEASE_QUEUE=1` | (Triforce, 11-22, the performance audit's MEM-85, after Source B's idea; `gpu/vk/release_queue.h`; **off unless set**, not yet run in the game) Without the replay thread (`RX_VK_ASYNC` unset), a texture or program the game finalizes is let go by its own thread: held for the replaying thread only while a queue is stopped at a wait (PR 430), otherwise after `sync_drain` and the replay's lock, which a replay holds through whole submissions. With this on, every such release goes to a list the replaying thread applies at the start of the next submission's replay or present when no queue is stopped (after the stopped work otherwise, as PR 430's); a texture's release counts the game's writes from the write generation of its call, so writes after the call are still uploaded. The `RX_VK_ASYNC` job path is not changed. The `RX_VK_LAB_AB` knob `relq` turns it on in its phases. On in every run, a count: every 600 releases a `vk: releases` line when one of them waited 0.5 ms or more for the replay or its order (how many, the time in all, the longest) or went to the list. Not built: the entry's `rel_wait_ms` column in frames.csv |
|
||||
| `RX_VK_UB_BATCH=1` or `2` | (Triforce, 11-22, the performance audit's SYNC-21; off unless set; not yet run in the game) A recording's uniform updates are written into guest memory at its end between two full barriers, one `vkCmdUpdateBuffer` an update (about 80 a frame) and nothing between two updates of the same bytes. `=1` (`gpu/vk/ub_batch.h`, `gpu/vk/vk_replay.cpp` `flush_ub_batched`): each update's bytes go into the recording's stream (256 bytes at least) and each run of updates into one buffer is one `vkCmdCopyBuffer` of many regions; a run ends where an update would write bytes the run already wrote, or where the destination buffer changes, and the next starts behind a full barrier, so overlapping updates reach memory in the stream's order. A piece that is not 4-byte aligned becomes a region too (it was a CPU write at record time); with the stream full a piece is written as before. `=2`: written as before, the overlaps counted (by guest address). Both log a line every 600 flushes: updates, runs ended by an overlap and by another buffer, copies and regions. Look at the counts first: a barrier at every run end costs GPU time if they are common. The `RX_VK_LAB_AB` knob `ubbatch` is `=1` in its phases |
|
||||
| `RX_VK_SPLIT_BEFORE_DRAW=0` or `1` | (Triforce, the performance audit's REPLAY-14, after Source A's) A part of a long submission (and a helper thread's segment) ends only right before a plain draw that will draw (`NOP_DRAW`, `_IDX`, `_INDIRECT`; rendering on, no rasterizer discard), not after any draw or dispatch (`gpu/vk/barrier_rules.h` `split_before_draw`, `cut_ok`; `gpu/vk/vk_replay.cpp`). On by default on Intel's GPUs only: on an Arc B580 a command buffer that begins with mesh draws drew its later plain draws as exploded triangles (Source A: 40 shard frames of 1,121, then 0 of 1,101). `=0` off, `=1` on with any GPU. A run of mesh draws or dispatches is then not cut, so a part can be longer than `RX_VK_CHUNK`. Not run on an Intel GPU here |
|
||||
| `RX_VK_SPLIT_UBFLUSH=0` or `1` | (Triforce, REPLAY-14) Whether a part's end writes the submission's uniform updates so far into the game's memory (`split_ub_flush`). On by default, as before, except on Intel's GPUs without mirrors of the game's pools (integrated ones), where only the submission's last part writes them, as an unsplit submission does: written at each part's end they reach the memory later parts' other reads and the game's CPU see (Source A: white blocks in 1 run of 3 on a Meteor Lake iGPU, then 0 of 3). `=0` off, `=1` on with any GPU. The log's `vk: a submission's parts: ended only right before a plain draw ...` line says both |
|
||||
| `RX_VK_EVENT_BARRIER=late` or `full` | (Triforce) An event signal in the game's command stream (`gpu/vk/barrier_rules.h`). `late`: nothing is recorded at the signal and its pass goes on (the word's buffer is bound there, as before); the event's word is written right after the next full barrier on its command buffer (the game's next barrier, a dispatch's or pass start's), so after all the work before the signal, and a recording's end writes what is still held behind a full barrier before its write-backs copy the words to the game's memory; a wait the replay finds met for an event whose write is held gets a full barrier first. The game sees the word at that barrier rather than at the signal. `full`: the pass ended, a full barrier and the write at each signal, as before. Unset: with the pass barriers' game mode (`RX_VK_PASS_BARRIER`: NVIDIA's driver). Not with the parallel replay. The `vk: event signals:` line says which |
|
||||
| `RX_VK_TAIL_EARLY=1` or `=0` | (Triforce, on by default since options_version 6; over the Debug tab's Start next frame early row, `tail_early=0` to turn it off; read at the start; after NX2navi's `tail_early`) The early tail (`gpu/vk/tail_early.h`, `gpu/vk/vk_replay.cpp`): the replay cuts a frame's recording at the gameplay upscale's dispatch (the game's network, or DLSS, DLAA, FSR in its place) and records the rest, the upscaler and the interface, as one command buffer; its event signals are held. At the recording's end a tail that wrote no binding (its inline uniform updates aside), bound no guest memory itself, ran no program of the game's that reaches guest memory through the page table or a texel buffer, and wrote no texture back has its event words written in its upload command buffer, after the scene's write-backs and ahead of its own commands: OoT's present poll then sees its frame's event while the GPU still runs the tail. Any other tail has the words written at its end, as before. Also with the parallel replay (its segments end at that dispatch) and with the lazy write-back. Not with `RX_VK_BENCH` or a frame dump. A `vk: the early tail` line at the start says on, and every 1200 tails how many went early and why the others did not. Not yet run in the game |
|
||||
| `RX_VK_DISPATCH_BARRIER=game` | (Triforce) Off unless set, not yet run in the game: a dispatch right after another, nothing recorded between, records no full barrier of its own (not an indirect one, nor a program a stand-in may take over), as NX2navi's `barrier_game` does; the game's own barriers order its dispatches. Only the game shows whether that is always so (a one-frame band or flicker where it is not): a switch for the lab. A `vk: RX_VK_DISPATCH_BARRIER=game:` line every 20,000 dispatches it left without one. (wp14, P4) It no longer stands aside while the Replay helper threads record (most frames at the Market, so the lab's earlier run of it measured little): "nothing recorded between" is the command buffer's own count of its commands (`gpu/vk/cmd_work.h`, `RX_VK_BARRIER_CONTEXT`), a segment being a command buffer of its own |
|
||||
| `RX_VK_BARRIER_CONTEXT=0` | (Triforce, P4; after NX2navi's per-context barrier state) What the barrier rules ask, "was anything recorded into this command buffer since its last full barrier, its last pass's end, its last dispatch", is answered by each command buffer's own count of its commands (`gpu/vk/cmd_work.h`), where one count of every thread's commands served before (an atomic add on every command by every recording thread). So the rules hold while the Replay helper threads record: the left-out repeats of a full barrier, `RX_VK_PASS_BARRIER`'s pass starts and `RX_VK_DISPATCH_BARRIER`. A command buffer's begin starts its state afresh; each segment begins and ends with a full barrier, so no rule relaxes across a segment's edge. `RX_VK_SPLIT_BARRIER` asks also whether anything went to the queue between two parts (every submit is counted). The rules' defaults are as they were. `0`: the one count, and the rules standing aside while the helper threads record, as before. The `vk: barrier state:` line at the start says which; the frame statistics' `full barriers recorded, ... left out` and `pass starts ordered in their fragment stages only` show the difference |
|
||||
| `RX_VK_BATCH_IDLE=1` | (Triforce, 11-22, off by default; the performance audit's SYNC-09, after Source A's; `gpu/vk/barrier_rules.h` `batch_idle`) With held submits (`RX_VK_BATCH`, the row below: on by default with Mesa's RADV only), a submit that joins the held batch sends it at once when the GPU has finished every batch sent; while the GPU is busy, submits still group. A held batch otherwise waits for a wait, a present, the 2 ms poll or the cap of 32 with the GPU idle beside it. Source A has this on wherever batching is, and off where guest memory stayed host-pointer imports (each submit there pays amdgpu's page check); here it is **off unless set on every driver** until a Linux RADV machine has run it, and no guard for host-pointer imports is built. Nothing changes without held submits (NVIDIA, AMD's and Intel's Windows drivers). The 120-present `vk: batched submits:` line counts its flushes as `idle` |
|
||||
| `RX_VK_BATCH=parts`, `1` or `0` | Held submits (`gpu/vk/vk_replay.cpp` `batch_way`). `1` (the default with Mesa's RADV): every submit held until something needs the GPU's results or the queue's order. (Triforce) `parts`, off unless set: only a whole submission's recordings are held, and only while the game's submit is being replayed; a part goes at once with those held before it, as do 4 held (`RX_VK_BATCH_MAX`), and the held go when the replay of the game's submit returns. Neither changes the command buffers or their order on the queue. `0`: each submit at once (the default elsewhere). The `vk: batched submits` lines say which and how many command buffers went in each queue call |
|
||||
| `RX_VK_FOLIAGE_SHADOW_CULL=<layer>[f]` | Off unless set, not yet run in the game: the draws of mesh programs into the sun's shadow cascades (depth only, square, wider than 768) from that layer of the cascades on (0 to 2; NX2navi's is 1) that cull neither face are drawn with their back faces culled (the front ones with `f`, as `1f`): the foliage's double-sided cards draw half their fragments there (`gpu/vk/foliage_shadow.h`). Not the same picture: a card facing away from the sun casts no shadow in those cascades. The log says `vk: RX_VK_FOLIAGE_SHADOW_CULL` at the start and names the first draws it culled (`vk: foliage shadow cull:`) |
|
||||
| `RX_VK_PEND_HELD=0` | (Triforce, on by default) A flush for a fence wait or a progress poll looks at a flag before the queue's lock (`dev.present_mu`) and returns when nothing is held (always, with batching off): it took the lock to find nothing, behind a present or a late page's fix waiting on the GPU. A held submit's recording is made known to the waiters only once it is held with the flag raised, so a waiter that finds it flushes it (before, it could flush nothing and wait for the held signal until the next poll, present or cap); a recordings' wait whose recording the recordings' timeline has passed returns without a flush. The batched submits' line counts the looks that found nothing held. `=0`: the lock every time and the registration first, as before; `RX_VK_LAB_AB=nopendheld` the same in its phases (`tests/test_flush_nothing_held.py`) |
|
||||
| `RX_VK_IMPORT_HIGH=<percent>` or `0`, `RX_VK_IMPORT_LOW=<percent>` | The idle imports' valve (`gpu/vk/vk_memory.cpp` `imports_give_back`): past `HIGH` percent (85) of the system heap's budget, the imported pools bound least lately, idle for 600 submissions and without a mirror, are given back down to `LOW` percent (75; 10 to 95). On by default where that budget is under 12 GB (on Windows only with the memory handling on); `RX_VK_IMPORT_HIGH=85` turns it on at any budget, `=0` off altogether. Setting either keeps the whole budget as the measure (no cap, below) |
|
||||
| `RX_VK_IMPORT_CAP_MB=<n>` or `0` | (Triforce, the performance audit's MEM-22, after Source A's) What the valve above measures the heap against, where that is less than the budget (`gpu/vk/import_budget.h`). Unset: 4,500 MB with Mesa's RADV at a budget of 12 GB or more, where the valve was off and live imports piled up for the session (Source A, an RX 9070 XT with 32 GB: 221 live imports and 7.4 GB after two hours against 50-64 and 2.3-2.7 GB capped); no cap on any other driver or at a smaller budget. `<n>`: that cap on any driver and budget, which turns the valve on. `0`: no cap, RADV's behaviour before. A pass against the cap gives back 1 GB at most. Not run on RADV here |
|
||||
| `RX_VK_FOLIAGE_SHADOW_CULL=<layer>[f]` | (Triforce, after NX2navi's 754ded9) On from layer 1 unless set (`off`: as the game draws them): the draws of mesh programs into the sun's shadow cascades (depth only, square, wider than 768) from that layer of the cascades on (0 to 2; NX2navi's is 1) that cull neither face are drawn with their back faces culled (the front ones with `f`, as `1f`): the foliage's double-sided cards draw half their fragments there (`gpu/vk/foliage_shadow.h`). Not quite the same picture: a lone card facing away from the sun casts no shadow in the middle and far cascades (where cards stand in pairs or clumps the others cover it; the near cascade is drawn as the game asks). The log says `vk: RX_VK_FOLIAGE_SHADOW_CULL` at the start and names the first draws it culled (`vk: foliage shadow cull:`) |
|
||||
| `RX_VK_FOLIAGE_SHADOW_VRS=<layer>` | (Triforce, after NX2navi's 754ded9) On from layer 2 unless set (`off`: the extension not asked for, no pipeline changed): the same draws of native mesh programs, from that layer of the cascades on, shade one fragment per 2 x 2 pixels (`VK_KHR_fragment_shading_rate`, where the device has `pipelineFragmentShadingRate` and native mesh shaders; elsewhere nothing changes): the leaves' alpha test runs a quarter as often, depth still per texel. The rate is dynamic state only in the pipelines of native mesh programs with no colour target and a depth one (and in their two shader libraries, keyed apart), which the driver builds again once: on such a device the driver's part of the preparation makes those libraries too (and the `RX_VK_LIB_CHECK` sample asks for them), once more at the first start after the update, before the game (the other libraries come back from the cache), and the light precompile builds each depth-only pipeline of a native mesh program once more; their keys, the program cache and every other pipeline stay as they were. The log says `vk: the far shadow cascades' foliage at 2 x 2:` at the start and names the first draws (`vk: foliage shadow 2 x 2:`) |
|
||||
| `RX_VK_FOG_CULL=1` | (Triforce, after NX2navi's 0379b00) Off unless set: the volumetric fog's first compute pass skips, as the game does, the froxels behind a coarse depth table of the frame before and writes them as empty, which the fog's history smears into dark trails beside near objects (worst at the screen edges, in foggy places such as the Lost Woods and Kokiri Forest). By default those froxels are computed too: the comparison is made never true in that one module, found by its shape in the SPIR-V (`gpu/vk/spv_fog.h`: a block of five image writes, four of (0,0,0,1) and last 1/255, and the one branch to it an ordered greater-than decides). It is applied where the module is made (`make_module`), outside the translation stamp: the program cache's records stay as they were translated, so nothing is translated again, and only that one compute pipeline is new to the driver's caches. With the precompile keeping none (`RX_VK_PRECOMPILE_KEEP`, less RAM), its record of the compute programs built has the patch and the matcher's version in its key (`gpu/vk/vk_draw.cpp` kFogPatch times `spv_fog::kMatcher`, raised whenever the matcher finds modules it did not: a record written by the matcher before 11-17's, which patched none of Triforce's fog modules, is built again), so the first start with the patch, or with a new matcher, builds the listed compute programs once more before the game (every one but the fog's a cache hit, the fog's compiled into the play cache, `mkw_vk_pipelines_play.bin`, or the main one where there is none, and saved before the record says built) rather than compiling the fog's at its first dispatch; with `RX_VK_FOG_CULL=1` that key is the one it was. A little more GPU time in the fog's pass. The log says `vk: fog: module <crc>, the volumetric fog's first pass:` and what was done (also for a near miss: the exit found but not its comparison) |
|
||||
| `RX_VK_FIFO` (set), `RX_VK_IMMEDIATE` (set) | The swapchain's present mode for one run, over the Insert menu's VSync row: FIFO, as with vsync forced by a driver; immediate, where the surface lists it. Unset, the row decides (`gpu/vk/present_mode.h`): On is mailbox where the driver has it (immediate on Windows where it has none, FIFO elsewhere), Off immediate wherever the surface lists it |
|
||||
| `RX_VK_SKIP_PROG=<prefix>,...` | Leaves out the draws of these programs (default `53509044401d78d2`; `-` leaves out none) |
|
||||
| `RX_VK_PIPE_SKIP=0`, `1` or `2` | Default/`1`: wait for shader translation; a pending pipeline can be skipped only for attachment-only draws whose targets hold an earlier frame. `0`: wait for every pipeline too. `2`: restore the old skip for untranslated draws with persistent targets; this can omit writes before the shader is known. Translated memory-writing draws still wait |
|
||||
| `RX_VK_TRANSLATE_WAIT_MS=<ms>` | (Triforce, 11-22, the performance audit's PIPE-30, after Source A's; `gpu/vk/translate_wait.h`) Off by default: a draw whose program is still translating waits for it, as before. Set (1 to 100, digits only; 8 to try): a draw into targets that hold an earlier frame, of a program whose key's translated variants write no memory (noted at each new pipeline and at the precompile's loads), waits at most that many ms a frame in all, the translation hurried but not run on the draw's thread, then is left out; a spent budget leaves the next one out at once. A key never translated, one with a variant that writes memory, and a draw into new targets wait as before; `RX_VK_PIPE_SKIP=0` and `=2` keep their meaning. The log says how many waited and were left out (`vk: programs still translating, so far: ...`). More draws left out, mostly in load frames: for a lab to weigh (`gpu/vk/vk_draw.cpp` `draw`, `translate_note`) |
|
||||
| `RX_VK_PIPE_DEPTH_BUDGET=1` | (Triforce, 11-22, the performance audit's PIPE-29, after Source B's; `gpu/vk/pipe_wait.h` `depth_budget`, `choose`) Off by default on every driver, Intel's too (the entry would have it on for Intel's Windows driver: that waits for the owner's word). Set: a depth-tested draw into a pass drawn once whose shaders write no memory, outside a samples-passed count and not into targets kept from an earlier frame (the item icon capture's), waits for its pipeline from the frame's wait pool (`RX_VK_PIPE_FRAME_WAIT_MS`, 50 ms) and is then left out; that pipeline is then left out at once until it is built (the list emptied every 600 presents). The first 16 left out are named, and a line counts them (`vk: depth-tested draws into passes drawn once, so far: ...`). A render into a new depth target left out can stay missing until it is drawn again: the trade Source B made for an Arc B580's 11-13 s freezes (`gpu/vk/vk_draw.cpp` `draw`, `pipe_depth_budget`) |
|
||||
| `RX_VK_PIPE_FRAME_WAIT_MS=<ms>`, `RX_VK_PIPE_ONESHOT_BUDGET=1`, `RX_VK_PIPE_SKIP_NEW=0` | A draw whose pipeline is not ready (`gpu/vk/pipe_wait.h`, NX2navi's rules). A full-screen draw (at most 6 vertices over half the pass or more: a lighting, fog or tone mapping pass) into targets that hold an earlier frame is left out only where the hold of the last picture takes its frame (`RX_VK_HOLD_PIPELINES`); where it cannot (at its bound, resting after one, or off) the draw waits for its pipeline up to this many ms a frame in all (50, at most 500), then 40 ms more, and is left out after both; its job goes to the front of the workers' queue meanwhile. `0`: left out, as before. `RX_VK_PIPE_ONESHOT_BUDGET=1` (off; NX2navi has it on): draws into targets drawn once and draws whose shaders write memory wait from the same budget and are left out once it is spent, instead of waiting until their pipeline is made. `RX_VK_PIPE_SKIP_NEW=0`: a pass whose colour target is drawn for the first time is kept by its depth target alone, as before (by default its draws wait, as for any target drawn once: the game's item icon capture). The log's `vk: pipelines not ready` line counts them |
|
||||
| `RX_VK_PIPE_FAST_WORKERS=0`, `RX_VK_PIPE_LINK_MS=<ms>` | A pipeline whose stage libraries were cold has those libraries built by a worker first and is linked from them, ready with that link, and its whole optimised build follows as a job of its own (`gpu/vk/pipe_wait.h` `libs_first`, NX2navi's `pipe_fast_workers`); a draw that waits for it runs the libraries and the link, not the whole build. `0`: the whole build first and the cold libraries after it, as before. `RX_VK_PIPE_LINK_MS=<ms>` (0 by default, at most 100; NX2navi's 6): the links made on the draws' threads in a frame take at most this long; a new pipeline after that is linked by a worker, its draws left out or waited for meanwhile (needs the fast pipeline link and the first switch on) |
|
||||
| `RX_VK_PRECOMPILE=0` or `1` | The shader preparation before the title off or on (on in builds made with `RX_RELEASE=1`, as the builders' are) |
|
||||
| `RX_VK_PREPARE_THREADS=<n>` | The threads the shaders are translated and their driver's part made on before the title, 1 to 64. Unset: every processor, a thread past half of them for each GB of RAM free at the start, and half in a process started above normal priority (the log's "the shaders' preparation runs on" line says how many) |
|
||||
| `RX_VK_WARM_COMPUTES=listed` or `all` | (Triforce, 11-22; `gpu/vk/warm_computes.h`, `tests/test_warm_computes.py`) The compute pipelines the shader preparation's translation pass has the driver compile. `all`: every compute program's texture variants (about 9,700), as before. `listed`: only the programs play dispatched (`triforce_computes.bin`, about a tenth of them; the precompile builds the same ones), the others translated as before and compiled at their first dispatch; with no list yet (nothing played) every one. Unset: `listed` on Intel's GPUs (an Arc A750 spent 5175 s of a 5858 s pass on them, an RTX 4070 SUPER 170 s on the whole pass), `all` on the others. No stamp holds it |
|
||||
| `RX_VK_FALLBACK_SHARED_RECORDS=0` | (Triforce, 11-21, the performance audit's MEM-154) With the compute fallback for task and mesh shaders, each recording thread keeps buffer pairs: 64 MB of records, the same size for every program, and a payload sized by the task program. A payload that fits no pair now makes a pair that takes the newest pair's records and only a new payload; before, 64 MB more of records each time, kept for the session. The log's `vk: mesh fallback: a buffer pair` lines say made or shared. `0`: its own records each time, as before (`gpu/vk/vk_draw.cpp` `fallback_buffers_of`) |
|
||||
| `RX_VK_TASK_MESH_FALLBACK=0` or `1` | Task + mesh draws through the compute fallback (1) or the driver's mesh shaders (0). By default the fallback is on for AMD's Windows driver for RDNA 2 (every RX 6000 card and that generation's integrated GPUs: the driver whose `vk: vendor fixes` line names the "AMD proprietary shader compiler"), where the native path timed out the driver on the RX 6700 XT and RX 6800 XT (issue 996) |
|
||||
| `RX_VK_FALLBACK_LOADED=0` | (Triforce, 11-22, the performance audit's PIPE-62, after Source A's) On the task and mesh fallback, the precompile is handed only the fallback programs whose records are still on the disk, as before. The default also hands it every fallback program already in memory that is ready and not failed (`gpu/vk/vk_shader.cpp` `program_cache_load_some`, in the part outside the translation stamp), so that their compute pipelines are built on the precompile's workers before the title: in a start that prepares, `state_list_prepare` has read the state lists' programs in before the precompile asks, and those got no pipelines until their first draw, which waited up to 50 ms on the recording thread and was left out until they were built. The log says how many: `vk: N mesh fallback programs read in earlier in this start are made ready with the rest`. Only GPUs on the fallback (no mesh shaders, RX 6000 and RDNA2 integrated GPUs on Windows, the menu's Compute row, `RX_VK_TASK_MESH_FALLBACK=1`); the preparing start's load grows by the compiles moved out of play |
|
||||
| `RX_VK_MESH_AHEAD=0` | (Triforce, on by default, after NX2navi's `mesh_ahead`; `=0` as before) An indirect mesh draw's records are copied into a ring as `{count, 1, 1}` before it, outside the pass, so each one ended its pass and the next draw began it again (OoT's foliage, grass and leaves: about 16 a frame at the Market). Now the first indirect mesh draw of a run copies the records of the indirect mesh draws after it as well, in the same three barriers, and those stay in the pass: a run is the indirect mesh draws after it with only state, draws, counter reports and render conditions between (`gpu/vk/vk_replay.cpp` `mesh_run_kind`); a dispatch, a barrier, a copy, a clear, a uniform update, new targets or an event ends it, so no work of the game's between can write the records after they were copied. A draw takes only the entry copied for it (its op, records, count and stride); at most 32 draws and 1 MB of the ring a run (`gpu/vk/mesh_ahead.h`). A `vk: indirect mesh draws` line every 20,000 conversions says how many took their records from an earlier draw |
|
||||
| `RX_VK_NO_PROGRAM_CACHE` (set) | Neither reads nor writes `hookshot_programs.bin` and the pipeline notes |
|
||||
| `RX_VK_PROGRAM_CARRY=0` | The program cache (`triforce_programs.bin`) is good for one build of the translator only, as before: any change to its files, a log line or a host option's number in `gpu/vk/vk_api.h` too, translates every program again, and the pipeline cache, the pipeline notes and the prepare's record go with it. By default the cache is carried over an update that changed nothing of what translates (`gpu/vk/program_carry.h` has the rule, `tests/test_program_carry.py` holds it): the translation stamp (`nx2/build.py` `translation_stamp`) is the translator's files without `vk_api.h`, without the parts of `vk_shader.cpp` marked as outside it, and without comments, blank lines and spaces at lines' ends. The log's `vk: program cache` line at the start says whether the programs were kept, carried over an update of the translator (and from which build), or translated again (and how many the cache had); while they are translated again a line now and then counts them. Switching it either way translates every program once more |
|
||||
| `RX_VK_PROGRAM_CARRY=0` | The program cache (`triforce_programs.bin`) is good for one build of the translator only, as before: any change to its files, a log line or a host option's number in `gpu/vk/vk_api.h` too, translates every program again, and the pipeline cache, the pipeline notes and the prepare's record go with it. By default the cache is carried over an update that changed nothing of what translates (`gpu/vk/program_carry.h` has the rule, `tests/test_program_carry.py` holds it): the translation stamp (`nx2/build.py` `translation_stamp`) is the translator's files without `vk_api.h`, without the parts of `vk_shader.cpp` and `vk_bank.cpp` marked as outside it, and without comments, blank lines and spaces at lines' ends. The build log's `build: translation stamp` line says whether it is the last release's (`nx2/released_translation_stamp.json`, which players' caches are for, and which `tests/test_program_carry.py` holds this source to) or which stamped files moved it against that release; a second line, in brackets, compares it with the previous build in the same folder (its record: `translation_stamp.json` in the build folder, written once the objects are compiled). Both are about the build's part of the stamp: the runtime adds its own settings to it (`disk_stamp`). The log's `vk: program cache` line at the start says whether the programs were kept, carried over an update of the translator (and from which build), or translated again (and how many the cache had); while they are translated again a line now and then counts them. Switching it either way translates every program once more |
|
||||
| `RX_VK_PREPARE_RECHECK=0` | (Triforce, 11-22, after Casual Gamer's #dev-fixes post) Both as before: a start whose record (`triforce_prepared.bin`) says the shaders are prepared takes its word, and the empty mark of a start that died in the driver's part without stage libraries (`triforce_prepared.bin.warming`) leaves that part out on any GPU and driver. By default (`gpu/vk/prepare_again.h`, `vk_draw.cpp` `prepare_run`): where the record says nothing to do, the program cache's head and size are read, and one made again since for another GPU or other settings (another stamp, or its head alone) holds none of the shaders: `preparing again` (logged), the stale record removed first; a cache carried over an update keeps the stamp and passes. And the mark holds what the part is made for (the GPU, the driver, the programs), as the libraries' journal does: another stamp's mark is another driver's, and the part goes on (`tests/test_prepare_again.py`) |
|
||||
| `RX_VK_CACHE_SET=0` | (Triforce) No earlier set of the shader caches is kept or put back (`gpu/vk/cache_set.h` has the rule, `gpu/vk/vk_cache_set.cpp` the files, `tests/test_cache_set.py`). By default, when the caches' stamp changes and the build of the translator did not (a setting of the translation: the menu's Robust buffers row, the mesh shaders row, the GPU, an `RX_VK_` switch of the translation), the set there (the program cache and its index, the pipeline cache and the play file with their `.for`, the prepare's record with its `.check`, `.warming` and `.warming.skip`, the pipeline notes and what is kept beside them by the stamp) is renamed to `<name>.<stamp>.<ext>` when the disk has twice the set and 10 GB free, and `triforce_cache_set.kept.txt` lists it. One set is kept. A start whose stamp is the kept set's puts every piece of it back (a set with a piece missing is deleted), and the set it found is kept in its place; a start of another build deletes it. `triforce_cache_set.txt` names what the set there was made for, and the log's `vk: shader caches:` lines say which part of the stamp changed. A set put back while the player's `triforce_pipeline_states.bin` is not the one it was kept with leaves `triforce_cache_set.states.txt`, and the prepare before the title then goes through the state lists, so that what was met under the other set is built before the game. Files of a kept set's names that no record names (a start that ended in a swap) are deleted at the next start. `RX_VK_CACHE_SET=0` also deletes a kept set; `RX_VK_PCACHE_KEEP_OLD` and `RX_VK_NO_PROGRAM_CACHE` leave it off too (a kept set of this build stays, another build's is deleted) |
|
||||
| `RX_VK_GPL=1` or `0`, `RX_VK_GPL_KEEP_LINKS` (set) | The fast pipeline link (`VK_EXT_graphics_pipeline_library`; `gpu/vk/gpl_rules.h`), on by default since options_version 5: a new pipeline is linked from its program's two shader libraries where the driver has them compiled, and the optimised build replaces it. The Debug tab's Fast pipeline link row is the same without an environment to set (`fast_pipeline_link=1`); the switch goes over the row. With it the preparation has its driver's part ("Compiling shaders"), which now goes on after a start that died in it, leaving out the programs that start had in the driver's hands (`triforce_prepared.bin.warming` and `.warming.skip`), up to three starts in a row. `RX_VK_GPL_KEEP_LINKS`: the linked pipelines the optimised ones replaced are kept for the run, as before, instead of destroyed 600 presents and 10 s later. `RX_VK_NO_WARM` (set): no driver's part; `RX_VK_GPL_SYNC` (set): a cold library is compiled in the draw; `RX_VK_GPL_NO_CACHE` (set): the libraries are not kept in the pipeline cache |
|
||||
| `RX_VK_LIB_CHECK=0` | (Triforce, after NX2navi's e10ef60) On unless `0`. At a start whose record says the driver's part is made for these shaders and this driver, a sample of 12 kept program variants has its two stage libraries made as that part makes them, asking the caches only where the device can (the answer a draw's link gets; without the flag, `RX_VK_GPL_SYNC`, their time against a second making, which comes from the cache), twice, before the game (`gpu/vk/lib_check.h`). When more than half are cold (`mkw_vk_pipelines.bin` lost or refused, or the libraries built otherwise now without `kWarmRecipe` counted up) the driver's part is made again at once, as after a driver update, with its journal and skip list; warm, nothing more happens (some 50 library lookups). `triforce_prepared.bin.check` records that it did: a start that finds them cold again right after leaves them to the draws, as before (each try holds a start for minutes; remove the file to try again). A making again whose cache could not be saved is recorded the same way. A cache file over its bound is not made again at all. The log's `vk: stage libraries:` line says what was found |
|
||||
| `RX_VK_BUILT_CHECK=0`, `=2` | (Triforce, 11-22, the performance audit's PIPE-21, after Source A's and Source B's; `gpu/vk/built_check.h`) On unless `0`. A light precompile (`RX_VK_PRECOMPILE_KEEP`: none kept) records what it built for the caches in `<notes>.built`, and later starts left all of it to its first draw or dispatch on the record's stamp alone. Now, before the record is trusted, up to 24 of the recorded notes are asked of Triforce's own pipeline caches as a draw asks them (without compiling, where the device has `pipelineCreationCacheControl`; without it each is built twice and timed: a first build over 4 times the second and 3 ms more was compiled), and with the record's compute key up to 6 of the listed compute programs as a dispatch asks them. Under 16 answers nothing is said; half of them or more not there: the caches lost them, and everything noted and listed is built again before the title and recorded anew (`vk: precompile's record: ...`). Lost again right after that (`<notes>.built.check`): left to the draws, as before, with a hint about the driver's shader cache size. Also counted: play builds of recorded pipelines that took 40 ms or more and recorded compute programs a dispatch did not find (`vk: precompile's record: in play so far, ...`, at most every 10 s while it grows). `2`: built again at every start (the lab's). `0`: neither the check nor the counter, as before (`gpu/vk/vk_draw.cpp` `built_check_cold`, `precompile_run`, `built_play_build`) |
|
||||
| `RX_VK_SPV_PACK=0` | Every shader module kept for the whole run, as before. By default the SPIR-V of graphics and mesh programs is kept packed in memory (`gpu/vk/spv_store.h`, to about 0.37 of its size) and their shader modules, which the driver otherwise holds for the whole run, are made only for the time a pipeline is created with them, on the thread that builds it. Compute programs, the programs the preparation lets go and the programs a draw reads from the cache itself keep their modules. The log's `vk: shader code packed` lines say what it comes to and what it costs |
|
||||
| `RX_VK_PCACHE_RAM=1` | Off by default (in its one session on, v0.4.0-test9, it gave back nothing the working set showed). With it, once the PC has had under 1.5 GB of RAM available at two looks a second apart, the pipeline cache (when it is 256 MB or more) is destroyed once no pipeline creation is using it (`gpu/vk/pcache_gate.h`): the pipelines built after that go without it and it is not saved again that session, so `mkw_vk_pipelines.bin` keeps its last save. The log's `vk: RAM short ...: the pipeline cache ... is let go` line says when and what the working set did. Whatever this switch says, the cache's save in play waits while a copy of it would not fit in the RAM available with 2 GB to spare (the save at the game's close does not), and the builder of the predicted pipelines behind the game rests while under 3 GB (or a tenth of a PC of more than 30 GB) is available (`gpu/vk/mem_parts.h`) |
|
||||
| `RX_VK_WRITERS_WAIT_MS=<ms>` | (Triforce) How long the game's close waits for the files the renderer is writing on threads of their own (`gpu/vk/file_writers.h`; 2000 by default, `0`: no wait and nothing refused, as before). The close ends the process through ExitProcess, which stops every other thread where it is: the pipeline cache's save in play, the order file, a bug capture's or a debug picture, the hang report, the predicted pipelines' list, the frame log. At the close (`HOS_OPT_EXITING`) no such write begins any more and the ones under way are waited for; one still going at the bound is cut, and is one of the files written whole beside the old (`.part` / `.tmp`, then put in place: the prepared record `triforce_prepared.bin` and the `.for` files are now too), or a list whose reader takes whole records only. The log's `vk: exit: the files being written ... were waited for` line says how long, and what was cut |
|
||||
| `RX_VK_OPTIONS_MERGE=0` | (Triforce) The menu writes its own values over `triforce_options.ini` in place at every change, as before. By default (`gpu/vk/ini_merge.h`, `vk_menu.cpp` `save`) each line it writes is merged by its key with the file as it is then: a line changed outside the game while it runs (a text editor, a tool) and not changed in the game since the game read or wrote the file is written as the file has it, so a change made outside and one made in the menu within the same second both stay (a row changed on both sides is the game's); the game takes such a line at its next start. The file is written whole beside the old one and put in its place (in place only where another program holds it open so that it cannot be replaced). The log's `menu: options: ... changed in triforce_options.ini outside the game` line names such lines |
|
||||
| `RX_VK_MEM_PARTS=0` | No `vk: memory, the parts` line. By default every 600 presents it gives the working set, the game's own memory committed and in RAM (a sample of its pages), the rest of the working set in RAM by what it is (a sample too: the program's code, the driver's code, other code, mapped files and views, write-combined or uncached memory, the heaps and other private memory), the shader modules alive and the packed stages, the pipeline cache, the pipelines and stage libraries kept (how many a draw has had, how many were given back) and the allocator's blocks in system memory (`gpu/vk/mem_parts.h`), and what its walks and samples took. It is written on a thread of its own that nothing waits for; the guest window's walk is made again every eighth line |
|
||||
| `HOS_MEM_ZERO_MARK=1` | (Triforce, 11-22, the performance audit's MEM-13; off unless set; not yet run in the game) Freed guest pages that a Vulkan import holds are zeroed in place, not discarded (`host/hos_mem.c` `discard_pages` and `FreeMemoryPages`, `host/hos_svc.c` UnmapPhysicalMemory). The renderer does not see a bare memset, so its mirror, its captures and the write-back's shadow keep the freed bytes, and a later write-back could put them back over the zeros. With the switch the fill (`host/hos.h` `hos_guest_fill`) marks the pages written, after the memset. Off by default until it is measured: the marked zeros (up to 5.2 GB over a tour) are pages the captures and the mirror syncs then copy, which could hitch an arrival. To measure: two runs a side, the log's "capture ... copied (MB)" and "mirror syncs ... dirty pages", and the frames over 50 ms in each arrival's first 5 seconds |
|
||||
| `RX_VK_SWAP_RESERVE_MB=<MB>`, `RX_VK_TEST_SWAP_MB=<n>` | (Linux; Triforce, 11-22, the performance audit's MEM-141, after Source A's; off unless set, not yet run on Linux) A memory pressure hold that counts the swap. The RAM rules look at `MemAvailable` alone, which a PC with swap keeps up by pushing the game's pages out (a 16 GB Steam Deck's swap filled while it said little). With the reserve set (Source A's is 2560), every 30 presents the PC is short when `MemAvailable` is under 1536 MB or `MemAvailable` and `SwapFree` together are under the reserve, and until both are 256 MB clear of their lines a hold is on: a capture buffer is kept as a spare only up to 32 MB of spares, the staging arenas the GPU is done with are freed as it begins and then after 5 s unused, `malloc_trim` is asked every 600 presents from 64 MB free, idle imports are given back (in all of one hold at most the bytes the PC was short at its worst, still only after 3,600 idle submissions), and an integrated GPU's texture budget is less by what the PC is short, never under 512 MB, coming back 256 MB a look. A PC without swap, or whose swap cannot be read, is never short by the sum. The log's `vk: swap hold: on` and `off` lines say when and what each gave. `0` or not set: no hold, as before; never on Windows. `RX_VK_TEST_SWAP_MB=<n>` plays that much swap free, as `RX_VK_TEST_AVAIL_MB` plays `MemAvailable` (`gpu/vk/linux_pressure.h`, `gpu/vk/vk_memory.cpp` `swap_hold_step`) |
|
||||
| `HOS_MEM_CENSUS=<seconds>` or `0` | (Triforce) The guest memory census (`host/guest_census.h`), on by default every 5 seconds, on a thread of its own: a `mem: census` line with what the runtime handed out of the guest window by kind (the program and the system region, the heap, the address regions and the game's own pages in them, what lies outside them: the physical maps and first touches), the game's own count against the 9809 MB it is told it has, the pages the game let go that stay committed (zeroed under an import, or discarded with a freed region) and what the give-back gave back, the process's commit and working set, and the PC's commit and RAM; and a `mem: census, the renderer` line with the Vulkan back end's big holders (its imports, mirrors, VRAM in use, the allocator's blocks in system memory, the pipeline cache, the pipelines and stage libraries kept, the shader modules). A count of bits a 4 KB page, kept as each place commits, maps or lets go of guest pages. `0`: no line (and, with the give-back off, nothing kept) |
|
||||
| `HOS_MEM_GIVE_BACK=1` or `2` | (Triforce) Off by default, not yet run in the game: the pages the game let go that stay committed because an import held them (`FreeMemoryPages`, `UnmapPhysicalMemory`) or because they were discarded with a freed address region are decommitted once nothing of the renderer imports them, from 4 GB up (below it pages are handed out without a commit), up to 256 MB a census pass, in runs of 16 MB at most; the renderer answers and runs the decommit with its import locks held (`gpu/vk/vk_memory.cpp` `guest_release_unimported`), so no import can lock them between. `1`: every pass; `2`: only while the PC is short (its commit past 85% of its limit, or under 1.5 GB of RAM available). The census line's `given back` says how much |
|
||||
| `HOS_MEM_MAP_RESULT=0` | (Triforce) `MapPhysicalMemory` answers success even where Windows refused the commit, as before. By default it answers Horizon's LimitReached (`0x10801`), which the SDK turns into its out-of-memory result, and the log says `mem: MapPhysicalMemory ...: the commit failed` |
|
||||
| `RX_VK_PRECOMPILE_KEEP=1` or `0` | The precompile keeps every pipeline it builds for the session (1), or keeps none of them: they are built for the caches and let go, and a draw that first needs one builds it from there (0). Unset or `auto`: kept where the RAM available at the precompile and what the game holds already come to 22 GB or more, on a PC of 20 GB or more (`gpu/vk/mem_parts.h` keep_all_pipelines); the log's `vk: precompile:` line says which and why |
|
||||
| `RX_VK_PRECOMPILE_KEEP=1` or `0` | The precompile keeps every pipeline it builds for the session (1), or keeps none of them: they are built for the caches and let go, and a draw that first needs one builds it from there (0). Unset or `auto`: kept where the RAM available at the precompile and what the game holds already (less what reading the pipeline cache added, except on AMD's driver: `own_for_keep`) come to 22 GB or more, on a PC of 20 GB or more (`gpu/vk/mem_parts.h` keep_all_pipelines); the log's `vk: precompile:` line says which and why. (Triforce, 11-22, after Casual Gamer's #dev-fixes post) Unset (not `auto`): on a discrete GPU in a PC of under 20 GB every pipeline is kept while the game is told its mapped pages are used (`HOS_MEM_QUERY_USED`, `keep_all_small_pc`): a 16 GB laptop, ~0.6 GB more private memory, frames of 1 s or more 15 and 11 in two tours -> 3 and 6. A card the driver allows under 6.5 GB still leaves them to their first draw first; integrated GPUs keep the RAM rule; `auto`: the RAM rule, as before |
|
||||
| `RX_VK_TEX_PIPES_AHEAD=0` | (Triforce, on by default; `=0` as before) The texture converters' compute pipelines (the GPU ASTC decoder, the BC encoder, the unswizzle and the swizzle back: `gpu/vk/vk_texture.cpp` `texture_compute_pipeline`, `texture_pipelines_warm`) made through the pipeline cache kept across runs, and all four before the game: in the precompile, right after the cache is read, or at the start when the preparation was skipped at the build. Each was made without a cache inside the first upload that needed it, which with an empty driver cache (a first start, a new driver) waited for the compile, a `vk: slow upload` of 100-320 ms. The ASTC decoder and the BC encoder only where the GPU does not sample ASTC. The `vk: texture converters ready in` line says what it took |
|
||||
| `RX_VK_PIPE_RELEASE=0`, `RX_VK_PIPE_RELEASE_EVERY=<presents>` | Every kept pipeline stays for the session, as before. By default, while the PC's RAM is short (under 1.5 GB available at two looks in a row), every 300 presents up to 512 of the kept pipelines no draw has had yet are given back to the driver (`gpu/vk/pipe_release.h`); a draw that needs one later has it built again by a worker. The log's `vk: RAM short: ... kept pipelines no draw has had given back` lines say how many and what the working set did |
|
||||
| `RX_VK_PCACHE_CARRY=0` | The pipeline cache's file carried over a stamp change (`gpu/vk/pcache_carry.h`): at an update's preparation (Setup's "Preparing shaders", `HOOKSHOT_PREPARE_ONLY`) a `mkw_vk_pipelines.bin` made for other shaders is read all the same when it is this device's and driver's, within its bound, and at most 1.25 times its base (the size of the last set built fresh, kept beside it in `mkw_vk_pipelines.bin.base` with the carries since): the pipelines of shaders the update did not change are hits instead of hours of compiling. The cap is over every carry since the base was built, not a quarter more each time, and a carried cache may never pass the file's bound either. The preparation looks at a carried cache's size every 10 s while it builds and at each save: past the cap (or the bound), nothing more is built into it, it is not written, `mkw_vk_pipelines.bin.nocarry` names the new stamp (a preparation begun again after a Cancel starts fresh), and the preparation builds the driver's part again into a fresh cache: the compute pipelines the carried run built, from the program cache, then the stage libraries, nothing translated again (from the driver's own cache for what it had just compiled), which gets a new base. A carried preparation that is stopped (a Cancel, a closed window) saves its cache under the new stamp with its history marked open in `.base`: the preparation begun again reads it as carried still, capped the same (or, when `.nocarry` names the stamp, not at all), until a carried preparation goes through to its end. The log says `pipeline cache carried over a stamp change (N MB, base M MB)`. `0`: a file for other shaders is never read, as before (the rule of 11-14). The play file keeps its own rule |
|
||||
| `HOS_DRIVER_CACHE_ROOM=0` | (Linux; Triforce, 11-22, the performance audit's PIPE-97, after Source A's and Source B's; not yet run on Linux) The game builds the pipelines its notes predict (about 41,400) into the driver's own shader cache on disk, and NVIDIA's and Mesa's caches hold 1 GiB unless told otherwise and trim themselves to it: part of a full preparation is dropped and compiled again in play. By default the game sets `__GL_SHADER_DISK_CACHE_SIZE` (NVIDIA) and `MESA_SHADER_CACHE_MAX_SIZE` (Mesa: RADV, the Steam Deck) to 10 GiB before Vulkan loads, for its own run and the builder's `--prepare-shaders` run; a size already in the environment stays, and the cache only grows by what is built. The log's `boot: room in the drivers' shader caches:` line gives both values. `HOS_DRIVER_CACHE_ROOM=0`, in the environment or `triforce_env.txt`: neither is set, as before. Nothing is done on Windows, where NVIDIA's driver takes its size from its control panel (`host/hos_main.c` `driver_cache_room`) |
|
||||
| `HOS_DRIVER_CACHE_FOLDER=0` | (Linux; Triforce, 11-22, the performance audit's PIPE-98, after Source A's; not yet run on Linux) NVIDIA's Linux driver keeps no shader cache at all when `__GL_SHADER_DISK_CACHE_PATH` names a folder that is not there: it neither makes it nor falls back to its own folder, and every prepared pipeline is compiled again at each start. By default the game makes the folder the variable names, with its parents, for the user alone, before Vulkan loads (the builder's `--prepare-shaders` run too); the value is never changed, nothing is made when the variable is not set, and a `boot: __GL_SHADER_DISK_CACHE_PATH=<path> is not a folder and cannot be made one` line says when it could not. `HOS_DRIVER_CACHE_FOLDER=0`, in the environment or `triforce_env.txt`: nothing is made, as before. The driver files its cache by the program's file name: the Linux binary stays `triforce` (`tests/test_driver_cache_folder.py` pins `nx2/build.py`'s name), and `__GL_SHADER_DISK_CACHE_APP_NAME` is never set (`host/hos_main.c` `driver_cache_folder`) |
|
||||
| `RX_VK_PCACHE_CARRY_PROJECT=0` | The early drop of a carried pipeline cache (`gpu/vk/pcache_carry.h`). When the stage libraries are built into a cache carried over a stamp change, every 32nd program of the warm's order is built first, the others waiting for it, and the cache's growth over that sample, per program, times all the programs, is where it ends at this rate. With at least 1500 libraries in the sample, a projected growth of at least twice the room it had when they began (its cap, or the bound, less its size then) drops the carry at once, exactly as past its limit (not written, `.nocarry`, the driver's part built again into a fresh cache), a few minutes in rather than when it gets there: an update whose file was built by an older translator misses nearly every library and filled the cache for 34 minutes before it was let go. The sample is spread over the whole order, not its head: the notes' programs go first and the rest in the program cache's file order, and hits and misses come in stretches of it, so a head that misses while the rest hits would have been dropped for nothing. The notes' programs wait for the sample (a few minutes cold). The log says `the pipeline cache carried over a stamp change would grow to about N MB at this rate`. The compute pipelines' pass and the precompile keep the look past the limit alone. `0`: dropped only once past its limit, and the warm in its own order, as before |
|
||||
| `RX_VK_PCACHE_MAX_MB=<MB>` | The bound on the pipeline cache's file, `mkw_vk_pipelines.bin` (`gpu/vk/pcache_bound.h`): a file over it is not read (the cache starts empty and the next save writes a new one), and data over it is not written (the file keeps its last save). Unset: an eighth of the PC's RAM, 2048 MB at least and 8192 MB at most. `0`: no bound, as before |
|
||||
| `RX_VK_PCACHE_LIBS_ONLY=1` or `2` | (Triforce, 11-22, the performance audit's PIPE-78, after Source A's and Source B's; `gpu/vk/pcache_libs.h`) Off unless set. `1`: when a fresh pipeline cache file begins (none read for these shaders), on NVIDIA's own driver with 20 GB of RAM or less, 512 MB or more in the driver's own cache folder (GLCache) and the stage libraries kept in our cache, the file keeps the stage libraries and the compute pipelines alone: whole graphics pipelines are left to the driver's cache and there is no play file, so a file of ~650 MB instead of 1.1-1.6 GB is read and held. Recorded in `<file>.lean` for that file's life (a full file stays full until the next fresh one); not decided in a start that only prepares. `vk: pipeline cache: libraries only (...)`. `2`: lean at every fresh file whatever the PC (the lab's). Whole pipelines then load 3-4 times slower from the driver's shared, capped cache (`gpu/vk/vk_draw.cpp` `pcache_libs_decide`, `build_graphics`, `pcache_play_open`) |
|
||||
| `RX_VK_PCACHE_CARRY_MB=<MB>` | (Triforce, 11-18) The carry of the pipeline cache's file over an update that changed the translation (`gpu/vk/pcache_bound.h` `carried`): a file for other shaders is read all the same when it is no larger than this (1536 MB unset), leaves room under the bound for as much again and the PC has 31 GB of RAM or more (Windows), so the driver finds what it compiled for the shaders that did not change (AMD's driver keeps no cache of its own for these). `0`: never carried, the rule of 11-14 alone |
|
||||
| `RX_VK_PCACHE_PLAY_FILE=0`, `RX_VK_PCACHE_FOLD_MB=<MB>` | The pipeline cache's play file (`gpu/vk/pcache_play.h`, NX2navi's play cache): once the preparation is done, what a run compiles goes into a second cache with a file of its own, `mkw_vk_pipelines_play.bin` beside the first (a creation asks the first cache without compiling, then the play cache), and a save writes that small file; `mkw_vk_pipelines.bin` is written only when the preparation built into it. Before, a save after a few new pipelines wrote the whole file again (2.6 GB at the owner's start after its precompile). At a start whose play file has reached `RX_VK_PCACHE_FOLD_MB` (64) it is folded into the first cache, that session builds into it as before, and its first save writes it and removes the play file. Needs `pipelineCreationCacheControl`. `0`: no play file, as before |
|
||||
| `RX_VK_PCACHE_OWN_PASSES=0` | (Triforce, 11-22, the performance audit's PIPE-95, after Source A's) The back end's own compute passes (FSR 3.1's dozen and its HDR output pass, the anti-aliasing's, the texture converters') are made with a bare creation into the main pipeline cache, as before. The default makes them the way a dispatch's pipeline is made (`gpu/vk/vk_draw.cpp` `shared_cache_compute`, `cached_compute`; `gpu/vk/pcache_play.h`): the main cache asked without compiling, a miss compiled into the play cache, a driver fault caught (the pass is then not made). Bare, they grew the main cache by a little, whose file is written in play only after 64 MB of growth, so they waited for the exit's save of the whole main file (650 MB fresh, 2 to 3 GB with the stage libraries), and an exit that cut that write short had them compiled again at the next start, inside the first upscaled frame. Without a play cache (no `pipelineCreationCacheControl`, or `RX_VK_PCACHE_PLAY_FILE=0`) only the guard is new |
|
||||
| `RX_VK_WARM_SAVE_MIN=<minutes>` | (Triforce) Checkpoint saves of the pipeline cache during the shader preparation's long builds (`gpu/vk/warm_checkpoint.h`, `tests/test_warm_checkpoint.py`): while the driver's part (the stage libraries, about two hours cold on an RX 7900 XT) and the precompile build, `mkw_vk_pipelines.bin` is saved every 10 minutes once at least 1000 were built since the last save, so that a restart, a crash, a power cut or a kill goes on from the last checkpoint (what it saved comes back as hits) instead of from nothing. Each goes through the preparation's own save: the file's bound, a carried session's cap with its history kept open as a stopped one's (`RX_VK_PCACHE_CARRY`), the file written whole with its `.for` and `.base`; it is left out while a copy of the cache would not fit in the RAM available with 2 GB to spare or the disk lacks its size and 1 GB (asked again a minute later), fetched with room for what is built meanwhile, written to the disk before it takes the old file's place, given up when the window is closed or Setup's Cancel is pressed (the stop's own save writes the cache), due only while the part moves (a stuck one goes silent), and it does not count the part as made (the next start still runs it). Beside the file, `.own` says it holds this part's pipelines alone, so that a part over the file's bound after a crash ends as a new file over the bound, not as an older build's file made again from nothing. The log says `vk: the driver's part so far saved for a restart: N MB in X s`. Not on Intel unless `RX_VK_PCACHE_PLAY_SAVE=1` (its driver crashed fetching the cache while pipelines were built with it); `RX_VK_PCACHE_PLAY_SAVE=0`: on no card. `0`: saved at the end alone, as before |
|
||||
| `RX_VK_PRECOMPILE_SAVE_S=<seconds>` | (Triforce, 11-22, the performance audit's PIPE-23, after Source A's; `gpu/vk/precompile_save.h`) A precompile that keeps its pipelines and built for this many seconds or more (30 by default, at most a day) saves the pipeline cache before the title, and says what that wrote: `vk: precompile: N s of building: the pipeline cache saved before the title (... KB in ... ms)`, or why nothing was. It was first saved in play (present 300, after 32 more builds; on Intel only at a clean close), so a crash, a kill or a power cut early in play cost the whole build again at the next start. The save is the play file's alone while there is a play cache (`gpu/vk/pcache_play.h`): the main file, 2 to 3 GB with the stage libraries, is not written before the title. Not when the game went on while workers still build, after a stop, or in a start that only prepares (those save by themselves); the precompile that keeps nothing saves before its record, as before. Also: a preparation without stage libraries counts the compute pipelines it builds into the main cache for that file's save, and saves the cache at its end before its record says the part is made (it ended unsaved). `0`: none of this, as before (`gpu/vk/vk_draw.cpp` `precompile_end_save`, `prepare_compute_pipeline`, `prepare_run`, `pipeline_cache_save`) |
|
||||
| `RX_VK_FETCH_BOUNDS=0` or `1`, `RX_VK_NAN_BITS=0` or `1`, `RX_VK_GATHER_OFFSET=0` or `1` | The translation's vendor and driver workarounds (`gpu/vk/vk_vendor.h`) off or on for one run, whatever the GPU; the log's `vk: vendor fixes` line says which are on. By default: out-of-bounds texel fetches answered with 0 on every GPU but NVIDIA's; NaN tests on a value's bits on AMD's older Windows shader compiler (RX 5000 and RX 6000); gathers nudged by 1/512 of a texel on AMD's and Intel's drivers. They change the shaders' translation (one preparation of the shaders) |
|
||||
| `RX_VK_MIRROR=0`, `RX_VK_MIRROR_MB=<MB>` | No VRAM mirrors of the game's memory pools (on for discrete cards); their budget |
|
||||
| `RX_VK_NAN_SELECTS=0` | (Triforce, after NX2navi's e38f42a, issue #156) Where the NaN tests are made on the bits (`RX_VK_NAN_BITS`: by default AMD's older Windows shader compiler, RX 5000 and RX 6000), a float select of a constant whose bits are a NaN (an integer mask the translation types as a float) is also made a select of the bits, so that compiler cannot fold it into stray black or white blocks (`gpu/vk/spv_nan_select.h`: 32-bit selects, and 16-bit ones in a module that has a 16-bit integer type). It is applied where a module is made (`make_module`), outside the translation stamp: no program is translated again, nothing changes on any other card, and on those cards only the modules that have such a select are new to the driver's caches. So that those are compiled before the game rather than at their first draw or dispatch, the driver's part of the preparation, the light precompile's record and the predicted pipelines' record have a stamp of their own there: the first start on those cards goes through them once more, everything but those modules coming back from the caches (the variants on the driver's part's skip list are carried over). `RX_VK_NAN_SELECTS=0` leaves the selects as they are (the NaN tests on bits stay). The log says `vk: NaN selects: module <crc>, <n> float select(s) of a NaN constant made select(s) of the bits` for the first four modules and every 64th |
|
||||
| `RX_VK_VB_RANGE=0`, `RX_VK_MESH_VB_REBIND=1` | A draw's vertex streams (`vk_draw.cpp` `draw`). `RX_VK_VB_RANGE=0`: all 16 bound again whenever one changed, as before v0.6.0 (by default only the ones that changed, `vertex_bind_range`). `RX_VK_MESH_VB_REBIND=1` (off by default: about 3% at the Market in the lab, and its tickets not reproduced): after a mesh pipeline's bind the next vertex draw binds all 16 streams again with their strides (by default they stay as they were bound, as before: a mesh pipeline has the strides static, and its bind leaves them undefined for the next pipeline that has them dynamic, as it does the topology; `tests/test_draw_binds.py`) |
|
||||
| `RX_VK_MIRROR=0`, `RX_VK_MIRROR_MB=<MB>` | No VRAM mirrors of the game's memory pools (on for discrete cards); their budget (unset: by the card, `gpu/vk/mirror_budget.h`: a quarter of the video memory on a discrete card over 4.5 GB, at most 3 GB; an eighth on cards of 4.5 GB or less and on integrated GPUs up to 6.5 GB; the log's `vk: VRAM mirrors' budget` line. `=768` is what a 6 GB card had before) |
|
||||
| `RX_VK_MIRROR=0`, `RX_VK_MIRROR_MB=<MB>` | No VRAM mirrors of the game's memory pools (on for discrete cards); their budget. Unset, the budget goes by the card (`gpu/vk/mirror_budget.h`): a quarter, at most 3072 MB; an eighth on cards of 4.5 GB or less and on integrated GPUs up to 6.5 GB. Discrete cards between 4.5 and 6.5 GB had the eighth before 11-21: `RX_VK_MIRROR_MB=768` is a 6 GB card's old size. (Triforce, 11-22, the performance audit's MEM-51) Without mirrors (`RX_VK_MIRROR=0`, Intel's integrated GPUs) the replay no longer notes what only a mirror's write-back reads (`gpu/vk/vk_memory.cpp` `wb_notes_off`: the report words of `memory_cpu_owned`, the written pages of `shadow_written_to` and `guest_cpu_wrote`): those lists grew to 65,536 words and 8 million pages, were dropped and grew again. No switch of its own: with mirrors on everything is noted as before |
|
||||
| `RX_VK_DEMOTE_QUICK=0` | A pool the CPU and the GPU both write is tried in guest memory (`vk_memory.cpp` `demote_trials`); by default a trial whose GPU time a frame is over 3 times its baseline and 5 ms more, after 3 frames or more, ends then, settling or measured, and is judged as a slower one is (mirrored again, measured again: `gpu/vk/demote_watch.h`). `0`: every trial runs its 10 settling and its measured frames, as before (in the owner's logs, some twenty frames of 100 ms for a pool at 106 ms against 7.4) |
|
||||
| `RX_VK_IMPORT_CHUNK_MB=<MB>` | The game's memory is imported in whole chunks of its address space, 16 MB each (`0`: by the game's own pools). (Triforce, 11-22, the performance audit's MEM-16, after Source A's) Unset, the chunk is 4 MB where the mirrors are on and whole on an NVIDIA card (NVIDIA before Turing by default, a card without sparse residency buffers, `RX_VK_MIRROR_PIECES=0`): a whole mirror copies all of its import into video memory, the padding too, and Source A measured about a quarter less mirror memory with 4 MB for about half again as many imports. With the mirrors in pieces, without mirrors, and on AMD's and Intel's cards it stays 16 MB (an import stalled the replay 20 to 75 ms on an AMD card). The log says `vk: imports in chunks of N MB` once. An imports-ahead file written at 16 MB is read as it is. `16`: as before on every card |
|
||||
| `RX_VK_IMPORT_AHEAD=1` or `0` | On by default with NVIDIA's driver (`=0` off). Off for test12 to test14: the GPU hung at the title in 6 of 12 lab runs; the cause, the game's freed pages decommitted under an import the background thread had not finished (`bg_held`), is closed and the lab's A/B with it was clean in 10 of 10 (`gpu/vk/import_ahead.h`). The ranges of the game's memory a run imported on a binding's own thread (8 to 17 ms each on an RTX 5090), whole as they were imported (their span over the game's pools included; the first version kept 16 MB chunks, which a binding across their ends imported again as one), are kept in `triforce_imports_ahead.txt` beside the game, at most 256, and the next runs import them on the background import thread as soon as the game's pools reach them, 4 at a look, at each change of the pool table and every 8 submissions (`gpu/vk/import_ahead.h`), each range once a session, and none while the PC's RAM is low (under 3 GB available, or a tenth of the RAM: the RAM's rule gives idle imports back then, and the two took turns on the same ranges in the owner's test9 session). A file of the first version's chunks is read as it is. Unset: off (it was on with NVIDIA's driver only, as `RX_VK_ASYNC_IMPORT` is); `1`: on any card; `0`: off. (Triforce) A race that fits the hang is closed since: the host decommitted the game's freed pages under an import the background thread had locked and not yet put in the pool table (`vk_memory.cpp` `bg_held`; `RX_VK_BG_IMPORT_HOLD=0`: not, as before, for the A/B); it stays off until a lab A/B with `=1` hangs no more. The log's `vk: imports ahead` lines count them and name the ranges sent, `vk: the game's pages ... are freed under a background import` the frees that window met; the stall line's "pools imported where bound" is what is left |
|
||||
| `RX_VK_IMPORT_TOUCH=0` | Off: the pages of a range of the game's memory are not read before the driver imports it. On by default, on Windows, for the imports made on the background thread (`gpu/vk/import_touch.h`): the driver locks a range's pages inside `vkAllocateMemory`, faulting in the untouched ones, and a queue submit from another thread waits for it; the ranges imported ahead are up to 1 GB. Read first, outside the driver, the allocate of the 288 to 752 MB ranges went from 16 to 93 ms to 4 to 13 ms on an RTX 5090, and the longest queue submit beside an import in play from 71 to 93 ms to 10 to 12 ms. The log's `vk: import` lines give a slow import's parts: the first 12 of a session, and the first 48 of 64 MB or more. |
|
||||
| `RX_VK_IMPORT_LEAVING=0` | (Triforce, 11-22, after Casual Gamer's #dev-fixes post) The game's freed pages under an import already given back whose memory is not freed yet (an evicted pool, a retired pool's import given back) are discarded or decommitted, as before. By default they are zeroed in place, as under a live import (`gpu/vk/vk_memory.cpp` `memory_guest_imported`, `imports_leaving_overlap`): the driver keeps those pages locked until the GPU is past them, and a discard there lost the device (v0.4.0 on a 16 GB laptop: 2 tours of 5 without, 0 of 53 with). The log says `freed under an import still being given back` for the first 8 and every 64th (`tests/test_import_leaving.py`). |
|
||||
| `RX_VK_KEEP_RETIRED=1` or `0` | A retired pool's import (a pool merged into a larger one) kept for the session (1) or given back once the GPU is past it (0; `gpu/vk/vk_memory.cpp` `retired_imports_give_back`). Unset: given back on Linux and with NVIDIA's driver, kept on Windows with AMD's and Intel's (device losses right after they went back there, issues 17, 309, 571). (Triforce, 11-22, after Casual Gamer's #dev-fixes post) Unset, those kept are given back all the same past the import rule's high mark of the system heap's budget (`RX_VK_IMPORT_HIGH`, 85%) or for a minute after an import was refused for want of room (`gpu/vk/mem_parts.h` `retired_pressed`; the log says `retired imports given back after all`): on a Radeon 780M the retired imports filled that heap, and 24.9% of the draws were left out for want of their pools (0 with it; refused imports 16 -> 1). `=1` keeps them always, as before. |
|
||||
| `RX_VK_CAP_SPARE_MB=<MB>` or `0` | The submit-time capture's spare buffers, kept for the next captures (12 at most, `gpu/vk/vk_memory.cpp` `cap_spare_max`), held to that many MB; `0`: up to 768 MB, as before. Unset: 32 MB on a card the driver allows 6.5 GB or less, and (Triforce, 11-22, after Casual Gamer's #dev-fixes post) on a PC of under 20 GB of RAM (`gpu/vk/mem_parts.h` `spare_capped`; the log says `capture buffers: 32 MB of spares at most`): on a 16 GB laptop the spares held ~0.45 GB that Windows paged out and in again, capped 10-18% fewer page-ins. Not on AMD's cards, where a capture buffer made anew costs about 100 ms: they keep their spares |
|
||||
| `RX_VK_IMPORT_RAM=1` | The imports' second trigger (`gpu/vk/vk_memory.cpp` `imports_give_back`): with the PC's RAM short (under 1.5 GB available) every import unbound for ~10 s of play is given back, up to 1 GB a pass. (Triforce, 11-22, after Casual Gamer's #dev-fixes post) Off unless set: a 16 GB PC has under 1.5 GB available nearly all the time, so it fired every ~20 s and the imports it gave back came straight back (690 to 1216 imports in a 13-minute tour). The system heap's trigger (`RX_VK_IMPORT_HIGH`) stays as it is. |
|
||||
| `RX_VK_KEEP_RETIRED=wait`, `RX_VK_RETIRED_REFUSED=1` | (Triforce, 11-22, the performance audit's MEM-21, after Source A's; `gpu/vk/retired_give_back.h`; **off unless set**, not yet run in the game) A pool remade larger is retired, and once the GPU is past it its import is pinned RAM nothing binds. Unset, as before: given back at once on Linux and with NVIDIA's driver on Windows, kept for the session with AMD's and Intel's on Windows (given back at once there, an Arc B390, an Ally X and an RX 6600 lost the device right after); `RX_VK_KEEP_RETIRED=0` gives back at once and any other value keeps, as before. `wait`, on any driver: given back `RX_VK_RETIRE_SECS` (30) seconds after the pool retired, `RX_VK_RETIRE_MIN_SECS` (2) while the system heap is past 85% of its budget; with it the imports given back and not freed yet are left out of what the pressure give-back (`RX_VK_IMPORT_HIGH`) reads. `RX_VK_RETIRED_REFUSED=1`: also the retired pools whose mirror was refused (`RX_VK_NO_MIRROR_POOLS`, a pool over 1 GB, video memory refused), never given back before on any OS; on with `wait` unless `=0`. The `vk: imports:` line every 1200 mirror epochs says how many retired pools are still imported |
|
||||
| `HOS_CRASH_THREADS=0` | Off: a crash report has the faulting thread alone. On by default, on Windows (`host/crash_threads.h`): a crash or fatal error's report ends with one `CRASH: beside it, thread ...` line for every other thread, its host stack as module and offset, taken at the report's start on a helper thread; the threads running code come first, then the ones waiting in the system. For the crash while a save loads, which reads an object whose memory holds something else: the lines say what the other threads were doing. |
|
||||
| `HOS_CRASH_TEST_S=<seconds>` | (the lab's) A host thread reads address 8 that long after the start: a crash report on purpose, to look at one from a run in the game (its other threads' lines above). Not for play. |
|
||||
| `EDEN_NX2_GM_LEAN=1` | Only the global-memory helpers a program's instructions call are put into its SPIR-V (`gpu/vk/eden/shader_recompiler/backend/spirv/gm_lean.h`). A stage that reads or writes through a pointer no storage buffer was tracked to carried every helper, six and for a storing stage eighteen, each with a search over every storage buffer in it. Off unless set: the SPIR-V is then what it was. An `EDEN_` name: each setting has its own program cache. The translator's files are in the translation stamp, so a build with this code translates every program again once, whatever the switch says. |
|
||||
| `RX_VK_UPLOAD_AGAIN_MS=<ms>` | A texture uploaded before whose memory the game wrote again, met by a draw after the frame's uploads took this long (16), is uploaded at the next frame instead; its last bytes are drawn meanwhile, at most 8 frames in a row (`gpu/vk/upload_owed.h` `later`). New textures are never left so (theirs is `RX_VK_HOLD_MS`'s rule). `0`: every one at once, as before. The log's "left for the next frame" lines and the stall line count them. `RX_VK_UPLOAD_AGAIN_FRAMES=<n>`: a texture's upload is left so at most that many frames in a row (2: its last bytes drawn a frame or two at most; `8`: as before). With 16 ms nothing was ever left in the lab's runs (the frames with re-upload bursts took 9.8 ms of uploads); `3` spreads a burst over the frames after it, its textures a frame or two late meanwhile, which is why it is not the default |
|
||||
| `RX_VK_UPLOAD_TORN=0` | (Triforce, wp18-flash) A texture uploaded before, 1 MB or more, whose storage the CPU has rewritten since the copy its re-upload would read (a capture's copy of one of its whole pages, every 16th and the last, differs from guest memory at the draw's look) keeps its last bytes for that frame and is uploaded at the next frame with what that frame's capture took (`gpu/vk/upload_torn.h`): a copy taken while the game was still writing the texture was test29's white frames at the Market after a tour (BC6H bytes passing through, decoded to bright colours the bloom spread over the picture). At most one frame in a row, and not for a texture found so in the two presents before (one the CPU rewrites every frame is uploaded as before). Not a dispatch's upload. `0`: uploaded at once, as before. The log's `re-uploads of storage the CPU rewrote since its capture` lines count them, those found and those left (with `0` too: the measure of how often a copy may have been taken mid-write) |
|
||||
| `RX_VK_REUPLOAD_EARLY=0` | The textures the CPU keeps rewriting (uploaded again from its writes twice or more within 120 presents, 1 MB or more, sampled in the frame or the one before, not drawn into by the GPU) are looked at once on the replay thread before a parallel replay's segments begin, after the dry pass, their uploads in the recording before the segments: not made by a segment under the recording lock, where the other recording threads queued behind them (lab S2 after a tour: 4 to 12 such uploads of 28 to 84 MB in ~13% of the frames, the descriptor time 24 ms over the threads against 3). `0`: the segments' looks alone, as before. The log's `textures the CPU keeps rewriting, looked at before` line says how many and how long (`gpu/vk/reupload_early.h`) |
|
||||
| `RX_VK_ZERO_HOLES=0` | (Triforce, Linux, on by default; `=0` as before) The all-zero check of a big texture's storage (32 MB or more: cleared on the GPU when every byte is 0; `RX_VK_ZERO_UPLOAD=0` turns the check off) reads only what the guest memfd holds data for (`lseek` SEEK_DATA and SEEK_HOLE, `gpu/vk/guest_holes.h`), not its holes: a page the game never wrote reads as zero, but a read through the shared mapping made it RAM (the 288 MB shadow map at each Hyrule Field arrival, 200-300 ms on a Steam Deck). Where the window is not a memfd, or a seek fails, the whole storage is read. The `is all zero` and `is not all zero` lines say how many MB were read. `=0`: the whole storage always |
|
||||
| `RX_VK_UPLOAD_SAME=0` | (Triforce) A texture uploaded before whose storage the CPU wrote again is checked against the bytes its image holds (`gpu/vk/upload_same.h`): the units of its storage the writes reached (each level's and layer's GOB-block rows, as its upload reads them) whose bytes hash as at their last upload are not uploaded, and when that is all of them nothing is. The upload of the rest reads the copy the check hashed, so that what is kept is what the image got; any other upload and any GPU write forget it. Textures of 16 MB or less uploaded on the CPU (block-compressed, or under 8 MB), not sparse; one whose checks find nothing the same 4 times in a row is uploaded unchecked for its next 64 re-uploads. Lab S2 after some tours: the game rewrote a few big BC textures the Market samples with the bytes they had, 40 to 60 MB every 4 to 5 frames (the Market at 62-78 fps against 83-96, ~26 GB of uploads in its stay). `0`: every re-upload made as before. The log's `re-uploads checked against the bytes their images hold` line says what it looked at, found the same and uploaded. `RX_VK_UPLOAD_SAME_KEEP=0`: the check hashes every byte it looks at; by default a page the submit-time capture keeps a copy of is hashed once and its hash kept with the copy until a capture copies other bytes into it (about half of those textures' pages passed through other bytes between two captures) |
|
||||
| `RX_VK_UPLOAD_SAME_ASTC=0` | (Triforce) ASTC textures decoded on the GPU (kept as RGBA8, BC3 or BC1; 2D only) are checked too, by `RX_VK_UPLOAD_SAME`'s check: one unit a layer, its levels from the first one the image keeps, which is what the GPU decoder stages of a layer a write reached; the staging reads the copy the check hashed. Lab S2's Market after a tour: the game rewrote such textures with the bytes they had (1536 x 1536 ASTC 5x5 of 11 levels, 768 x 768 kept as BC3, 512 x 512), staged and decoded again unchecked, about 1.4 GB in 10 s (90 fps down to 72, the 1% low 57 to 33). `0`: ASTC re-uploads made as before, every layer a write reached staged and decoded. The `re-uploads checked` line says what of it was ASTC; the `re-uploads not checked` line every 600 frames counts the re-uploads made without the check, by route and by why |
|
||||
| `RX_VK_TWIN_SAME=0` | (Triforce) The parallel replay's twin (a texture an earlier segment samples that a later segment of the same submission uploaded, uploaded again in the earlier segment's uploads so that its draws see the bytes as submitted) uploads only what that submission's uploads into the image asked for (`gpu/vk/upload_same.h` `note_upload`; the whole storage when one of them was whole or the image was made again), and where every unit it reads has a hash kept by `RX_VK_UPLOAD_SAME`'s check, reads a copy of them hashed as copied: when the copy holds the bytes the hashes are of, the hashes are kept. Before, the twin uploaded the whole storage and, unchecked, forgot the hashes the later segment's checked upload had just kept, so the next rewrite of the same bytes was uploaded again, the twin with it, every few frames: lab S2's Market after a tour, about 97% of what was still uploaded unchecked in those loops, up to 6.9 GB in one stay. `0`: the twin uploads the whole storage and forgets the hashes, as before. The log's `the parallel replay's twins` line every 600 frames counts them, the bytes uploaded against the whole, and how many kept the hashes |
|
||||
| `RX_VK_UPLOAD_EARLIEST=0` | (Triforce) A parallel replay's upload of a texture, made by the worker of a later segment of the submission while an earlier one is still being recorded, is recorded into the init command buffer of the earliest segment still being recorded (submitted before that segment's uploads and commands; `gpu/vk/upload_earliest.h`, `vk_texture.cpp` `UploadRedirect`). Every segment before it has ended its recording and no longer samples the texture, and every one from it on finds the upload at or before its place in the queue, so no earlier segment uploads the texture again (the twin, `RX_VK_TWIN_SAME`): it is uploaded once, the same bytes. Lab S2's heavy Market loops (round 48) uploaded 2.1 GB of twins in their last minutes, the big streamed or new textures each uploaded once by a later segment and again by an earlier one; those twins took the frames' upload budget (`RX_VK_UPLOAD_NEW_MB`, `RX_VK_UPLOAD_NEW_MS`), and the new textures after them were left for the next frame, the picture held. Only an upload staged from the CPU as it is recorded is moved: not one read on the GPU (the GPU unswizzle, from the pool) or decided from live memory (the all-zero clear), which in the earlier segment's init would run before a segment between writes that memory on the GPU. Not for a texture the GPU drew (its contents are the GPU's; the CPU's writes over it, `RX_VK_CPU_OVER_GPU`, keep their own path) or a sparse one: those keep the segment's own uploads, and the twin. The uploads' GPU time in an init command buffer is not in the segments' GPU time. `0`: every upload in its segment's own uploads, the twin as before. The log's `uploads recorded into an earlier segment's init command buffer` line every 600 frames (with `0` too) counts them and the bytes, and how often and how long a segment's end waited for its init lock, each segment's own, held while such an upload (or a new image's first layout change) is recorded into its init (its submit waits as long) |
|
||||
| `RX_VK_SHADOW_STAGE=0`, `RX_VK_CAP_UNCACHED=1` | (on by default; the row is Triforce's, 11-22, with the performance audit's MEM-39) A capture buffer asks for cached host memory, but a driver can hand out write-combined memory, which the CPU reads at about 0.3 GB/s. Such a capture's texture pages are copied into a staging block in ordinary memory first, and to the buffer from there, and every CPU read of them uses the staging (`gpu/vk/vk_memory.cpp` `capture_make`, `cap_page_bytes`): the shadow's copies, and since MEM-39 the `RX_VK_TEX_SAME` compare of each copied texture page with its shadow copy, which still read the buffer. `RX_VK_SHADOW_STAGE=0`: no staging, every read from the capture buffer, as before. Where the buffers are cached (the 600-take `shadow staging` line counts them) nothing is staged and nothing changes; the first buffer that is not cached is logged with its memory type. Lab only: `RX_VK_CAP_UNCACHED=1` asks for the capture buffers as memory written in order, which is uncached where the driver has such a type, to make the slow case on any PC, and the `RX_VK_LAB_AB` knob `texsamemap` reads the buffer in the compare in its phases |
|
||||
| `RX_VK_SHADOW_KEEP=0` | (Triforce) A texture page the submit-time capture takes with the bytes its shadow copy holds (the copy the uploads read, `RX_VK_TEX_SAME`'s compare) keeps that copy as it is, not copied again, its kept hash with it (`gpu/vk/shadow_prev.h`). Lab S2's Market after some tours: about half of the ~400 texture pages a capture took, six captures a frame, held their copy's bytes. Only for a page the capture takes once; any other is copied as before, and the shadow holds what the capture holds either way. `0`: every page copied, as before. The log's `texture shadow (600 takes)` line counts the pages compared, left, given back and copied |
|
||||
| `RX_VK_SHADOW_PREV=0` | (Triforce) A texture page the capture takes with other bytes keeps the copy it had, and that copy's hash, beside the new one (`gpu/vk/shadow_prev.h` `Prev`), and a capture that brings those bytes back gives it back, hash and all: no copy, and the re-upload check after it finds the hashes kept (lab S2's Market after some tours: the other half of those pages went back and forth between two versions, and a check hashed each again after every change, 0.2 to 0.3 ms a frame). A kept copy that does not come back within 8 changes of its page, or within 64 captures, goes; at most 64 MB are kept. `0`: none kept, a changed page copied over as before. The `texture shadow` line says how many are kept and how many went |
|
||||
| `RX_VK_SHADOW_VERS` | (Triforce) The copies a texture page keeps beside its own in the shadow (`gpu/vk/shadow_prev.h` `Vers`): `RX_VK_SHADOW_PREV` keeps one, and a page whose captures bring more than two versions (A, B, C, A every few frames) is copied again for every version but the one before the last. `2` to `4` keep that many, newest first, and a capture that brings any kept version's bytes takes that one back, the copy it had becoming the newest, so each version a page cycles through while it is still among the kept copies is copied once: 4 KB a version, under the same 64 MB cap. Unset or `1`: one copy, as before. The `texture shadow` line counts the pages given a copy of their own, one before it, and two or more before |
|
||||
@@ -212,6 +299,16 @@ case-sensitive, and an unknown one is ignored.
|
||||
| `RX_VK_VIEW_KEEP=0` | Any texture's end (an eviction, a dead render target let go, a texture made BC3 from BC1, the compaction moving one) makes every texture look of every recording thread stale, and each is resolved anew when next met (the slot, the cache, the view, under the parallel replay's lock), as before. By default a thread that finds the destroy generation moved keeps the looks of the textures whose views did not go: those are noted by their creation number before the generation moves (`gpu/vk/view_keep.h`, `vk_draw.cpp` `texture_view_of`); never a look of no texture or no view, nor a flat texture's 3D copy. More than 1024 gone since a thread's last pass: all resolved anew. The log's `vk: texture looks kept` lines count them, the stall line the views resolved anew. After NX2navi's `tex_gen_undo` |
|
||||
| `RX_VK_DESC_KEEP=0` or `check` | The per-binding reuse of a draw's descriptors (`gpu/vk/desc_keep.h`, on by default): a draw that builds its descriptors takes, for each sampled texture, user uniform buffer, stage's constants and read-only storage buffer, what the program's last draw on that thread resolved it to, while everything it was resolved from is the same: the texture's handle, its slot's registration, the samplers', no texture destroyed or made again, no texture left for later and the same submission; the buffer's address and size, no inline uniform update, no pool moved or mirror made, the same recording. `0`: every descriptor resolved, as before (so also with `RX_VK_NO_DESC_REUSE`, `RX_VK_SAMPLER_CACHE=0` and the descriptor diagnostics). `check`: every descriptor resolved too, and one that comes out otherwise than what was kept for the same inputs is counted and logged (`vk: descriptor reuse check`): the way to try the rules. The frame statistics' `a frame's descriptors` line says how many were resolved and taken, how many pushes were whole, of the changed bindings or of nothing, and how many sets were written, through a template, or bound again |
|
||||
| `RX_VK_DESC_SIG=0` or `check` | The whole-draw skip by the signature of a draw's descriptor inputs (`gpu/vk/desc_sig.h`, on by default with the per-binding reuse): a draw whose bindings moved, of the program whose descriptors its last draw pushed in that command buffer, first reads what each of them is resolved from (a texture's handle and its slot's version, a user uniform buffer's address and size, a read-only storage buffer's address and size words, a driver bank's stage generation) and the stamps the per-binding reuse gives each kind; when that equals the signature the pushed descriptors were built from, and their build kept every one, the build and the push are left out (a build would take each of them again and push nothing). Push programs only, of the kinds the per-binding reuse keeps: not those with storage buffers they write, tables, texel buffers or storage images, not the mesh fallback or RenoDX's. `0`: built, as before. `check`: built too, and one that comes out otherwise than what is pushed is counted and logged (`vk: descriptor signature check`). The frame statistics' `a frame's descriptor signatures` line says how many draws read theirs and how many were kept whole |
|
||||
| `RX_VK_DESC_COUNTS=0` | (Triforce, 11-22, the performance audit's DESC-22, after Source A's; `gpu/vk/desc_counts.h`) `build_descriptors` walks the program's stages at every build to sum its buffers, images and texel views, as before. The default keeps the three sums packed on the program (`Program::desc_n`, 10 bits each, in the padding after `ready` so that `sizeof(Program)`, which the shader caches' stamp holds, stays what it is): stored at the program's first build once it is translated, read at every later one. A program with more than 1023 of a kind walks at every build. A build that went by kept counts and had one of its three vectors move is made again, walked, and that program walks from then on (one log line). The lab's knob `descwalk` (`RX_VK_LAB_AB`) is this switch in its phases |
|
||||
| `RX_VK_PROF_ALL=1` (the dispatch's pick clock) | (Triforce, 11-22, the performance audit's DESC-30, after Source A's and Source B's) Every profiling scope timed, and with it the clock pair around each compute dispatch's program pick, as before. Unset, the pick's time for the stall line is the change of the thread's exactly timed nanoseconds across the pick (its slow path is timed by `PROF_EXACT`), so a pick the memo answers reads no clock. DESC-30 has no switch of its own, the results being the same: besides the pick, `taau_key` answers from its list parsed once (it wrote the key out and walked the list as text several times a dispatch), `RX_VK_LOG_PUSH` formats its key only when set, the first-pipeline clock is read only when there is one to make, and `texture_frame` fills `RX_VK_LOG_BAKED`'s list only for that switch (read once) and finds its largest textures by a partial sort. The lab's knob `diagold` (`RX_VK_LAB_AB`) puts all of it back in its phases (`gpu/vk/vk_draw.cpp` `dispatch`, `taau_key`, `dispatch_diag_old`; `gpu/vk/vk_texture.cpp` `texture_frame`) |
|
||||
| `RX_VK_LAB_AB=e_draw:<ns>`, `e_dispatch:<ns>`, `d_present_after:<us>` | (Triforce, 11-22, the performance audit's REPLAY-51, after Source B's; lab knobs of the in-run A/B, `gpu/vk/lab_ab.h`, nothing without the variable) The `d_<site>` knobs wait once a frame; `e_draw` and `e_dispatch` wait the knob's nanoseconds at every draw or dispatch, first in `draw()` and `dispatch()` so the profiles leave it out, on whichever thread records, and count each wait. The frame's change against the time spun says how much of that path is on the frame's critical path (200 ns at about 3,050 draws a frame is 0.6 ms of work). A phase's end logs `vk: lab A/B: phase e_draw:<ns> over:` with its waits and ms a second. `d_present_after` is `d_present`'s control: the same wait just after the present's `drain(0)`, where `d_present` is just before it. Pin `RX_VK_PARALLEL` with the `e_` knobs (the log warns otherwise): Automatic moves draws between threads. Off: one relaxed load a draw. `tests/test_lab_ab_each.py` |
|
||||
| `HOS_OOT_SHADOW_STEP=<n>` | (Triforce, 11-21, the performance audit's GAME-05) The game gives each nearby character or object a square depth shadow map sized by its size on screen, 384 to 1,920 a side, so while anything moves each frame asks for depth textures of sides not seen before. The one read of the side is rounded up to a multiple of `<n>` (a power of two up to 256; 64 when not set): 25 sizes, which come round again, so the render targets' pool serves them. A map gets at most 63 more texels a side; its projection does not change. `0` or `1`: the game's own side, as before (`host/oot_shadow_step.h`, `host/oot_shadow_step.c`, `nx2/oot_patches.py` `patch_shadow_step`) |
|
||||
| `HOS_SHADOW_BUCKET=<step>` | (Triforce, 11-21, the performance audit's TEX-85) The game sizes each character's shadow map (square, D32, one level) from the camera's distance every frame and places a frame's render targets first fit in its target heap, so a map a few pixels larger moved every target after it, and each moved one is a new image to the renderer. Such a map wider than 384 is answered the storage size and alignment of the next multiple of the step up (384: sides 768, 1152, 1536, 1920); the texture's own size and layout do not change, only the bytes the game sets aside, by 1.8 to 5.3 MB a map. `0`: every map its own size, as before. Not set: 384, and 0 where the target heap is pinned (`HOS_RT_POOL_MB`, or a 5120-wide output's 900 MB). The log says the step and counts the stepped answers (`host/shadow_slot.h`, `host/nvn_native.c` `shadow_slot_layout`) |
|
||||
| `HOS_OOT_TEX_COMPACT_MS=<n>` | (the lab's) The game's texture data compaction (its `aglTextureDataMgr::Compaction` thread moves a texture's data in the game's heap, a cycle of about 18 frames; idle in a fresh Market, at work at every ask after a tour, where each move is a texture at a new address for the renderer to capture and check): at most one cycle started every n ms. `-1` (a test): none started. Unset or 0: as shipped. The cycles started are logged every 10 s either way ("oot: texture compaction in"). `host/oot_tex_compact.c`, `tests/test_oot_tex_compact.py` |
|
||||
| `HOS_OOT_TEX_ASK_MS=<n>` | (Triforce) The game's texture data manager asks for a compaction round (above) at most once every n ms: its step, every frame, asks whenever no round is asked for and its flag says so, and each ask let through can start a round that moves a texture to a new address. Unset (or not a number): 1000. `0`: every ask, as shipped. `off`: none. A round started always finishes; an ask held back is made again at the next step. The asks let through and held are logged every 10 s ("oot: texture compaction asks in"). `host/oot_tex_compact.h`, `nx2/oot_patches.py` `patch_tex_ask`, `tests/test_oot_tex_compact.py` |
|
||||
| `RX_VK_TEX_WARM=1` | Textures made and uploaded ahead, while the frames are light (`gpu/vk/tex_warm.h`; off unless set). A texture is made and uploaded where a draw first samples it, and the frame's budget for that (12 ms, 64 MB, the picture held) applies only to targets drawn in the frame before, so an area's first frame, whose targets are new, takes every texture of the area at once: 350 to 800 uploads of 250 to 390 MB, 100 to 180 ms, in the lab's tours. With the switch every registered slot is noted, and at the start of a game's submit that follows a light frame (under 400 draws and dispatches: a loading screen, a menu) the noted textures, 8 frames old at least, are made and uploaded, 6 ms a frame. Bytes the game writes afterwards are uploaded again by the write marks, as before. "vk: textures made ahead in light frames" counts them. `tests/test_tex_warm.py` |
|
||||
| `RX_VK_TEX_WARM_LIST=1` or `2` | (Triforce, 11-22, the performance audit's TEX-23, after Source A's; off unless set, and only with `RX_VK_TEX_WARM=1`) The textures made ahead by a list of what was drawn (`gpu/vk/tex_warm.h`). Every registered slot made ahead needs the 40% rule, and on an 8 GB card that rule stops the warming at once. With the switch, a BC or ASTC texture a draw uses within 90 s of the game making it is learnt: its shape and eight 64-byte samples of its bytes, at its storage's address. The list is kept beside the game as `triforce_textures_drawn.bin` (32,768 at most; saved every 300 presents when it changed; a file cut short or of another version is not read). At a light frame the ripe slots the list names are made while the textures and 256 MB more fit their budget and the render targets' pool is not being given back; `1`: the others after them, by the 40% rule, once no noted slot is left ripe; `2`: the listed alone. The look itself learns nothing. "vk: textures made ahead by the list" counts listed, unlisted, learnt and no-room. Unset or `0`: every registered slot as above. Not measured: lab proof first (the entry's own default is `1`). `tests/test_tex_warm_list.py` |
|
||||
| `HOS_MEM_LIMIT=1` or `<MB>` | (the lab's) The game's memory held to what it is told it has, as the console holds it. The game is told 9809 MB, but nothing was refused until the PC's own commit ran out, and it holds 11.7 GB by its own count in a fresh Market and 13.5 GB after a tour (the `mem: census` line), with its GPU heap within 15 MB of full and its texture compaction running every frame. `1`: `AllocateMemoryPages` and `MapPhysicalMemory` are refused past the 9809 MB, and `UsedMemorySize` is the game's count; a number above 1: refused past that many MB. Unset or 0: as before. What the game does when refused is what the lab is to find out. `host/hos_mem.c`, `tests/test_mem_limit.py` Refused, the game asks again thousands of times, each ask a region taken and freed; a region of the game's own freed with none of its pages in it is no longer discarded (`hos_region_discard_needed`), and the regions it frees with pages in them are discarded with the thread's virtual core given up. Those two were the stutter when walking with the limit on: in a three-area lab run the game's own part of the frame was over 8 ms in 24% of the frames before and in 0.3% after (as without the limit), 63.8 fps to 100.0. **`=1` does not fit this build:** the heap takes 6.9 GB of the 9.8 and an area's resources need 4.7 GB and more, so a save's load can starve and stay on its loading screen for good (the owner's, 2026-11-20, read with the hang watch's stacks: the game at 9,807 MB, its load threads idle). Use a size in MB: `12800` loaded and played four areas without reaching it. |
|
||||
| `RX_VK_DESC_SET_KEEP=0`, `RX_VK_DESC_TEMPLATE=0` | A program over the driver's push limit (32 descriptors on NVIDIA's, AMD's and Intel's drivers) has a set written for each draw that builds its descriptors. By default a set whose descriptors are all as those of the last one written for that layout in the recording is bound again instead, while no texture was destroyed or made again and no pool moved, and a set written is written through the program's descriptor update template (Vulkan 1.1). (Triforce, after NX2navi's `desc_template`) A program within the push limit has its descriptors pushed whole (in a new command buffer, or after another program at its bind point) through a push descriptor template of its own (`vkCmdPushDescriptorSetWithTemplateKHR`, one a program and bind point, from the same entries and packed array as a set's), not with the write structs the driver walks one by one; a push of the changed bindings only keeps its write structs. The frame statistics' `a frame's descriptors` line counts the pushes made through it. With `RX_VK_RECORDER` the packet copies the packed array (`gpu/vk/vk_recorder.h`). `RX_VK_DESC_SET_KEEP=0`: a new set each time; `RX_VK_DESC_TEMPLATE=0`: sets written and pushes made with the write structs; both as before |
|
||||
| `RX_VK_CREATE_NEW_MS=<ms>` | While the hold is on, a sampled texture seen for the first time once the frame's makes took this long (8), or its uploads their budget, is not made yet (`vk_texture.cpp` `create_later`): the draw samples the dummy, the frame is held, the next frame makes it. The frame's first make always goes; never a dispatch's. `0`: made at once, as before (a texture left for later was made all the same). The stall line counts the textures made, their time, those not made yet, and the images made |
|
||||
| `RX_VK_UNSWIZZLE_MT_MB=<MB>` | A block-linear level unswizzled on the CPU is split over several threads (a thread for each 2 MB, 8 at most) from this size (4); `16`: from 16 MB, as before |
|
||||
@@ -227,42 +324,113 @@ case-sensitive, and an unknown one is ignored.
|
||||
| `RX_VK_PIPELINE_WARM_FOLLOW=1` | Off by default (test19: the lab's tour showed no gain). `1`: the warm follows the draws: a program read within 64 places (in the notes' order) after one the draws consumed in the last 2 s has its libraries made and linked, one within 192 its libraries only, one farther (or once the draws stopped taking) nothing; and the libraries no draw has had are kept up to 2048, the oldest let go beyond (with the links made from it), so the bound never stops the warm (`gpu/vk/pipe_warm.h`, test18: 2266 links made, 276 taken, the libraries at their bound from the load on); it spends at most 250 ms of the workers' time a second (500 saved up), and never makes again a library it let go. Off: every program read is warmed whole and the libraries stop at 1024, as before |
|
||||
| `RX_VK_COMPUTE_WARM=1` | Off by default (test19: the lab's tour showed no gain). `1`: where the precompile keeps no pipelines, the read-ahead's worker that has just read a compute program play dispatched (`triforce_computes.bin`) makes its compute pipeline, asked of the caches only, as its first dispatch would; the dispatch that takes the program has it. One a program while it waits on the read-ahead's shelf, destroyed when the shelf lets the program go and given back while the RAM is short; once a program variant a session. Off: each compute pipeline is made at its first dispatch, as before |
|
||||
| `RX_VK_PIPELINE_ORDER=0` | Each session writes the order its draws first needed their pipelines in (a new one, or one the precompile kept that no draw had), the first 4096, into `triforce_pipeline_order.bin` beside the pipeline notes now and then, from the presents on a thread of its own (this session's first, then those of the sessions before it has not met). Where the pipeline warm runs (`RX_VK_PIPELINE_WARM`), the next session finds each one's note before play and the warm makes, for a program variant the read-ahead has read, the pipelines that order names for it and no other (32 at most a variant; the notes' other pipelines are not made then, and the warm does not follow the draws): their stage libraries asked of the caches and their links, held for the draws by their place in the order, 1024 at most (beyond, the farthest ahead goes, and none is made farther), and 2048 libraries no draw has had at most. Where the draws are: the middle place of the last 16 pipelines they needed first; a link held 512 places behind it goes with the libraries only it held, and none is made there (`gpu/vk/pipe_order.h`): the save's load-in frame made 86 to 92 ms of pipelines on the draws' threads, the warm's links from the notes let go before the load came (lab round 37: 1964 made, 54 taken). The first session after this writes the file; the next one has it. `0`: neither read nor written, the warm from the notes as before. The stall line counts the pipelines new to the draws, those linked ahead (of them in this order), and the links and stage libraries the draws made themselves; the log's `vk: pipelines made ahead in the order` lines the rest |
|
||||
| `RX_VK_PIPE_AHEAD=<places>` | (Triforce, 11-22, the performance audit's PIPE-81, after Source B's: its first step; `gpu/vk/pipe_ahead.h`) A count, nothing built: with the last sessions' pipeline order in use (light mode), each pipeline the draws first need is counted by its place against where the draws are: within this many places ahead (1024 unset, at most 4096), further ahead, behind, not in the order, and those within the window that the warm had linked. A line every 600 presents while it grows (`vk: pipelines first drawn, by their place in the order: ...`) says whether a builder of whole pipelines just ahead of the draws would meet a third of them or more, the entry's rule for building it at all. `0`: not counted (`gpu/vk/vk_draw.cpp` `order_met`) |
|
||||
| `RX_VK_VRAM_MB=<MB>` | The texture cache's budget as a fixed size, whatever the card. Unset: on a card the driver allows more than 8.5 GB, no size (`RX_VK_TEX_PRESSURE`); on a smaller one 45% of what the driver allows; with `RX_VK_TEX_PRESSURE=0` 70% of it above 8.5 GB, at most 6 GB (the rule before) |
|
||||
| `RX_VK_TEX_PRESSURE=0` or `=<pct>` | (Triforce, after NX2navi's `TEX_VRAM_PRESSURE`) On a card the driver allows more than 8.5 GB, with VK_EXT_memory_budget, not an integrated GPU, without `RX_VK_VRAM_MB` and without a quality preset whose budget applies, the texture budget follows the live use instead of the fixed 6 GB: textures go once the driver's count, less the free space in the blocks they can take back, is past 80% of what the driver allows now, the least recently used first, each unused 2 s or more, 64 a pass, down to 2% under that line (`gpu/vk/tex_pressure.h`); the 90% and 97% rules and the compaction's lines stay. While the system's commit is low the fixed size comes back (`RX_VK_TEX_COMMIT_FREE_MB`). `0`: the fixed size, as before; `<pct>`: that line (50 to 95). The log's `vk: texture budget` line at the start says which, and the `vk: VRAM:` line every 600 presents the budget (by live use: what the textures may hold before the line) and the line |
|
||||
| `RX_VK_TEX_KEEP_TAKEN=0` | (Triforce, after NX2navi's `TEX_KEEP_TAKEN`) While VRAM is short, a texture uploaded from memory that the game let go 30 presents ago goes first (`RX_VK_LET_GO_PCT`); one the game has taken back before waits 8 times the longest it stayed let go before a take-back, when that is longer (`gpu/vk/tex_pressure.h`): made again, the frame that wants it draws the dummy (NX2navi: Kakariko's haze gone every few seconds). The eviction by age still takes it. `0`: the 30 presents alone, as before |
|
||||
| `RX_VK_TEX_COME_BACK=0` | (Triforce, after NX2navi's pause for drops that come back) Where the budget follows the live use: when in 240 presents 64 or more textures the line let go went and half or more of them were made again within 600, the line stands aside for 600 presents, doubled at each such period up to 7200; a period with fewer back ends the doubling (`gpu/vk/tex_pressure.h` `ComeBack`). The 90% and 97% rules and the compaction's lines still hold meanwhile. The log says when a pause begins. `0`: no pause |
|
||||
| `RX_VK_TEX_STEP=<n>` | The live textures one pass of `texture_sweep` over the budget lets go of at most (64 where the budget follows the live use; the render targets drawn over since do not count), the rest at the next look two presents on, not ten. Set, on any card, the fixed size's too; `0`: no step, one cut as before |
|
||||
| `RX_VK_TEX_COMMIT_FREE_MB=<MB>` | Where the budget follows the live use: while less of the system's commit than that is free (the default: the larger of 4 GB and a tenth of the limit, NX2navi's), the fixed size is the budget again (Windows charges a discrete card's memory to the commit, and an allocation that fails there ends the game). `0`: never. Not on Linux |
|
||||
| `RX_VK_TEX_COMMIT_RESERVE_MB=<MB>` | (Triforce, 11-22, the performance audit's OS-05, after Source A's; off unless set, not measured here) On any card, while less of the system's commit than that is free (the page files' room to grow counted in, below), the textures are held to what they hold less the shortfall, never under 1 GB, as the 97% rule takes its excess: the cache's passes give blocks back before an allocation is refused at Windows' commit limit (`HOS_COMMIT_WAIT_MS` waits such a refusal out). Source A's is 2560, on by default there; one `vk: commit limit near` line when it begins and ends and every 600 presents while it holds. Not set or `0`: no cut, as before. Not on Linux (`gpu/vk/commit_room.h`, `gpu/vk/vk_texture.cpp` `texture_frame`) |
|
||||
| `RX_VK_TEX_COMMIT_GROWTH=0` or `=1` | (Triforce, 11-22, OS-05) Whether the room the page files still have to grow (each one's largest size less its size now, a drive's page files capped together by its free space, asked of Windows at most once a second) counts as free commit, for the reserve above and for `RX_VK_TEX_COMMIT_FREE_MB`'s fall-back alike: Source A's first rule, without it, retired textures for 90 minutes while a page file Windows manages could still grow. Read only while less is free than the higher of the two lines. Not set: counted where `RX_VK_TEX_COMMIT_RESERVE_MB` is set, else not (as before); `0`: never; `1`: also without the reserve (`vk_texture.cpp` `commit_now`, `page_file_growth`) |
|
||||
| `RX_VK_SWEEP_ALL=1` | Every texture of the cache ordered by its last use for every pass of `vk_texture.cpp` `texture_sweep`, as before. By default a pass under the budget (every 10 presents, and the dead render targets' passes between them) orders only the textures it can take: those the GPU drew and those the game let go; the others it passes over all the same. Over the budget every texture is ordered. The log's "passes for the dead render targets between the looks" line says what a pass costs |
|
||||
| `RX_VK_TEX_RATE_HIGH=0` | The texture eviction's waits (`vk_texture.cpp` `texture_sweep`: 60 presents unused over the budget, 30 after the game let a texture go, 600 or 3600 for one the GPU drew, the compaction's 600 and 1800) count presents above 60 a second, as before. By default they count their seconds at any rate up to 480 a second (`gpu/vk/present_rate.h`, after NX2navi's M19): at the Market's 94 a second "60 presents" were 0.64 s. Below 60 they count seconds unless `RX_VK_TEX_RATE_LOW=0`. The log says the first time a run goes above 68 a second |
|
||||
| `RX_VK_TEX_DETAIL=full`, `reduced` or `low` | The texture detail for one run, over the Insert menu's Texture detail row: whole textures, or the large ones without their largest level, or without two (`gpu/vk/tex_detail.h`). Unset, the row decides, and its Automatic goes by what the driver allows: full from 10,240 MB, low under 6,144 MB, never full on an integrated GPU |
|
||||
| `RX_VK_TEX_BC1_PARTS=0` | (Triforce, 11-21, the performance audit's TEX-50) An ASTC block of two to four partitions with a colour endpoint mode each is refused unread by the opaque-texture scan, as before, so a texture with one stays BC3. The default reads those modes as the decoder does (their bits below the weights) and takes the block as opaque when every partition's mode has no alpha and is not HDR; the blocks the decoder takes for an error are still refused. The `kept as BC1` log lines count the blocks read this way. And a first start, with no options file, now keeps opaque textures as BC1 as the row's default says: it started at off (`gpu/vk/astc_opaque.h`, `vk_menu.cpp` `tex_bc1_at_start`) |
|
||||
| `RX_VK_TEX_BC1=0/1` | Opaque ASTC textures kept as BC1 instead of BC3 for one run, or not, over the Debug tab's Opaque textures as BC1 row (on by default since options_version 5): a texture the renderer keeps as BC3 whose every block the GPU decoder writes opaque is encoded as BC1, half the video memory, the same texels (`gpu/vk/tex_bc1.h`, `gpu/vk/astc_opaque.h`). One whose memory later holds blocks with alpha, or that a copy on the GPU writes, becomes BC3 for good; the log counts both |
|
||||
| `RX_VK_ASTC_BC_ALL=1` or `0` | Large decoded ASTC textures are kept as BC3, a quarter of RGBA8: the coarse blocks (6 x 6 texels and up) from 2 MB as RGBA8 (`RX_VK_ASTC_BC_MB`), the finer ones (UI, characters) only from 64 MB. Where the driver allows under 8.5 GB the finer ones go from 2 MB too (`gpu/vk/astc_bc_policy.h`). (Triforce, 11-22, the performance audit's TEX-12, after Source A's) And on every integrated GPU, whatever it is allowed: its allowance is a share of the system's RAM (a 16 GB handheld reported 10,361 MB), so it kept those textures as RGBA8 in RAM the game needs too. The log says `all large ASTC textures kept as BC3`, with `an integrated GPU` there. `1`: on any card; `0`: the finer ones as RGBA8 on any card, which is an integrated GPU allowed 8.5 GB or more as it was before |
|
||||
| `RX_VK_BC_SMALL_LAYERS=<n>` | (Triforce, 11-21, the performance audit's TEX-09) The layers one run of the ASTC-to-BC3 re-encode takes for a level of 1024 x 1024 or less, 1 to 8, through a small scratch of its own (1024 x 1024 x 8, 32 MB, and 4 MB more of output buffer). Unset: 8, and 1 on AMD's cards until the picture is checked there (one layer a run was for dark lines between Hyrule Field's ground tiles on an RX 6600). A terrain array of 90 layers and 11 levels was about 990 runs of a decode, an encode, a copy and three full barriers; its levels from the second down are now about 210. Each layer of a run is copied by a region of its own. No small scratch at reduced or low texture detail. `1`: none, every run one layer, as before (`gpu/vk/bc_scratch.h`, `vk_texture.cpp` `bc_small_layers`, `bc_encode_into`) |
|
||||
| `RX_VK_BC_LAYERS=<n>`, `RX_VK_BC_SCRATCH_FULL=1` | The layers one run of the GPU's ASTC-to-BC3 re-encode decodes and encodes, 1 to 8 (1: with more, an array's layers past a run's first came out wrong in the smaller levels, dark lines between Hyrule Field's ground tiles). (Triforce, 11-21, the performance audit's TEX-10) The 2048 x 2048 scratch, its output buffer and the second scratch are made with that many layers, 20 MB a layer (36 with the second), not with 8 whatever a run used: 140 of 160 MB were held and never written. `RX_VK_BC_SCRATCH_FULL=1`: 8 layers, as before (`gpu/vk/bc_scratch.h`, `vk_texture.cpp` `bc_scratch_layers`) |
|
||||
| `RX_VK_TARGET_POOL_MB=<MB>`, `RX_VK_POOL_IDLE=<presents>`, `RX_VK_TARGET_POOL_TRIM=0` | (Triforce, 11-21, the performance audit's TEX-29) The render targets' pool gives a dead target's image to the next target of its shape. Its bound is a twelfth of what the driver allows, 256 to 768 MB (`<MB>` sets it; 0: no pool); it was a fixed 256, which starved at 2560 x 1440. It is trimmed oldest first, whatever the shape. A shape nothing has taken from the pool goes after 8 presents (`RX_VK_POOL_IDLE`), one that was taken before after 120. Above 90% of the allowance it holds half its bound, above 97% nothing, unless a floor of the targets' blocks is kept. `RX_VK_TARGET_POOL_TRIM=0`: emptied above 90%, as before; with `RX_VK_TARGET_POOL_MB=256 RX_VK_POOL_IDLE=120` the pool as it was. The 600-present line `vk: render target images` has the reuse, the bound and the tier (`gpu/vk/target_pool.h`, `vk_texture.cpp` `pool_trim`) |
|
||||
| `RX_VK_STAGING_BURST_S=<seconds>` | (Triforce, 11-22, the performance audit's TEX-28, after Source A's) The uploads stage their bytes in host-visible arenas of 64 MB, and each present gives the idle ones back beyond what is kept: 256 MB, 64 MB where the driver allows 6.5 GB or less (`RX_VK_STAGING_KEEP_MB=<MB>`), and any nothing staged into for 30 s (`RX_VK_STAGING_IDLE_S=<n>`, 0: kept). An arena is taken again only once the GPU is done with the submission that read it, so frames that stage in a row use two in turn, and with 64 MB kept the one that had its turn was freed at every second present of a load and made again the present after. An idle arena staged into in the last 2 seconds now stays while the arenas add up to 256 MB (`gpu/vk/staging_keep.h`), unless VRAM is over 90% of the allowance. Nothing changes where 256 MB are kept anyway. The log's `vk: memory:` line counts the arenas made so far and their time. `0`: as before |
|
||||
| `RX_VK_WROTE_REGIONS=0`, `=2` | (Triforce, 11-21, the performance audit's TEX-02) Every sampled, uploaded texture is asked once an epoch whether the GPU wrote into its storage since its upload, which took a lock and walked the map of written ranges; nearly every answer is no. One bit a 2 MB region of GPU addresses, set where a GPU write ever reached, answers no without the lock when the storage touches no set region; a set bit asks the map as before. `0`: the lock and the walk each time; `2`: a check, both asked and compared, the count of disagreements (which must be 0) logged (`gpu/vk/wrote_regions.h`, `vk_texture.cpp` `texture_gpu_wrote`, `gpu_wrote_into`) |
|
||||
| `RX_VK_PREDICT_BG_STREAM=0` | (Triforce, 11-21, the performance audit's PIPE-83) The builder of the predicted pipelines behind the game (`predict_background`: the starts after a translator or driver update, resting while the game is in play) keeps its plan as record numbers and reads a pipeline's two notes from `triforce_pipelines.bin` when it builds it, each worker through its own handle; it held every note (~27 KB) and a full note of every predicted pipeline until it ended, about 1 GB. The same programs and pipelines are built. `0`: all of them held, as before (`gpu/vk/predict_stream.h`, `vk_draw.cpp` `predict_background`) |
|
||||
| `RX_VK_PREDICT_CHECK=0`, `=2` | (Triforce, 11-22, the performance audit's PIPE-68, after Source B's and Source A's; `gpu/vk/predict_check.h`) On unless `0`. The predicted pipelines are built once for the driver's own cache and a record says which programs are done; a driver can lose them all the same (NVIDIA's cache cap, a cleared cache folder, AMD's Windows driver keeping a third). At a start whose record says all are built, the builder's idle thread, after its delay and only while the frame shown is a light one, samples up to 12 of them spread over the plan: each built for the driver's cache alone and timed, then once more as the warm reference; cold is a first build over 4 times the second and 3 ms more, and the sample ends once its majority is decided. Cold: the record is removed, so they are all built again behind the game at light frames, and `<notes>.predicted.check` takes a strike for these shaders and this driver; cold again after that, the log says this driver does not keep them and no later start checks. Warm: the strike is forgotten. `2`: checked at every start, a recorded stop too. Also counted: the builds in play of programs the plan predicts that took over 20 ms (`vk: predicted pipelines: N builds in play of predicted programs took over 20 ms`, at most every 10 s while it grows). `0`: neither the check nor the counter, as before (`gpu/vk/vk_draw.cpp` `predict_check_cold`, `predict_background`, `predicted_play_build`) |
|
||||
| `RX_VK_PREDICT_TYPES=1` or `0` | (Triforce, 11-22, the performance audit's PIPE-44, after Source A's; `gpu/vk/predict_types.h`) Unset: each predicted pipeline is built once for its program, by its key as play keys it (two predicted layouts that differ only in what is dynamic, a stride, gave the same pipeline twice): the same pipelines, fewer builds. `1`: that, and the plan drops a predicted vertex layout whose attributes definitely differ from the program's vertex inputs (an integer input against a float attribute, or the other signedness, read from the vertex module's SPIR-V; scaled formats count as integers): such a pipeline is invalid. Off by default because it changes which pipelines are built, and it applies to a plan made after it is set (a plan is made once for the shaders). `0`: every predicted pipeline built, as before. The predicted lines say how many were left out as built already, how many programs the programs' file did not lend, the notes of variants it has no shaders for and the layouts that did not fit (`gpu/vk/vk_predict.cpp` `predict_pipelines`, `gpu/vk/vk_draw.cpp` `predict_first`) |
|
||||
| `RX_VK_DRAWN_PAGE_MAP=0` | (Triforce, 11-21, the performance audit's TEX-21) A texture in a virtual pool is checked through its mapping, 64 KB a page, and its page map was recorded at its first check: one the GPU drew first had none, so once the game finalized it the first check took its whole storage as mapped since and uploaded it from memory over what the GPU drew (HUD labels and render targets blank after an area change, up to 15 MB an upload). The map is recorded at the first draw that says who drew it, and the later check gives only the pages mapped anew or written by the CPU. Not for a write that gives no reason (a clear, the movie upscaler). The log counts them. `0`: at the first check, as before (`gpu/vk/drawn_page_map.h`, `vk_texture.cpp` `texture_written`) |
|
||||
| `RX_VK_DEAD_SUM=0`, `RX_VK_DEAD_POOL_NOW=0`, `RX_VK_DEAD_MIN_UNUSED=3` | (Triforce, 11-21, the performance audit's TEX-30) The frame's transient render targets, drawn over from another start: the other targets' parts over one are added up, each byte once, so one covered at its head by one target and at its tail by another, each under an eighth, is let go too (it was kept for good); it is dead after 1 unused present, not 3; and its image goes to the render targets' pool in the pass that lets it go, once the GPU is done with it, not at the next present. `RX_VK_DEAD_SUM=0`: judged one by one; `RX_VK_DEAD_POOL_NOW=0`: pooled at the next present; `RX_VK_DEAD_MIN_UNUSED=3`: three presents: each as before (`gpu/vk/target_overlap.h` `ShiftedOver`, `vk_texture.cpp` `texture_sweep`) |
|
||||
| `RX_VK_ASTC_REUSE=2` | (Triforce, 11-21, the performance audit's TEX-14, its first step; off when not set) When the game comes back to an area it makes its textures again, mostly at other addresses, and the same ASTC blocks are decoded and encoded again while the image made of them the first time may still be in VRAM. With `2` a new ASTC texture's blocks are hashed at its first upload (128 bits), the textures the game finalizes that were uploaded from memory and never drawn into are listed, and each new texture with a listed one's blocks and shape is counted: the log's `decoded ASTC used again` line says how many MB of images a copy would have stood in for, and what the hashing cost. Every texture is decoded as before. The copy itself is not built: the walk it was measured on would have reused 0 to 11 MB, and the audit asks for 500 MB on a tour before it is (`gpu/vk/astc_reuse.h`, `vk_texture.cpp` `reuse_upload`) |
|
||||
| `RX_VK_KEEP_OBSOLETE=1` | (Triforce, 11-21, the performance audit's TEX-43) A texture the GPU drew in one frame is kept after the game finalizes it, for being made again over that storage and sampled undrawn (the terrain's tiles; `RX_VK_KEEP_FINALIZED_MB`). One of 32 KB or more, in no virtual pool, whose storage the CPU has written three quarters of since the release holds nothing that memory holds any more: the sweep lets it go whatever the budget says, where only a draw over it did, and the game's own writes kept each for good (about 200 render target images an hour in players' logs). The log counts them. `1`: kept, as before (`gpu/vk/finalized_obsolete.h`, `vk_texture.cpp` `texture_sweep`) |
|
||||
| `RX_VK_SLOT_RETIRE=<presents>` | (Triforce, 11-21, the performance audit's TEX-76) The game draws each character's shadow map at a fixed address, sized from the camera every frame, and each size is a texture of its own: the ones before it, drawn over, waited 120 presents unused before the sweep took them. A depth target of one level and layer whose start a newer target of the same format and another size was drawn over since its last use goes once unused for `<presents>` presents, 16 when not set; nothing is written back, and its image goes to the render targets' pool. The log counts them. `0`: after the sweep's own wait, as before (`gpu/vk/slot_retire.h`, `vk_texture.cpp` `texture_sweep`) |
|
||||
| `RX_VK_COUNT_BY_TEXELS=1` | (Triforce, 11-22, the performance audit's TEX-86, after Source A's) A texture the GPU samples in the game's own compressed blocks (BC, and ASTC where the log says `vk: ASTC sampled natively`) is counted by its whole blocks (`gpu/vk/tex_count.h`): a level is its width and height rounded up to blocks, times the block's bytes and the layers. It was counted by texels: a byte a texel for BC (twice BC1's and BC4's size) and the 16 bytes of an ASTC block for every texel (16, 64 and 144 times the size at 4 x 4, 8 x 8 and 12 x 12), so the texture budget let textures go for memory nothing held, and the first size estimate left out the top levels of arrays that fit. The count is still lifted to what the allocator gave. Decoded ASTC (NVIDIA's and AMD's desktop drivers) and the renderer's own BC3 and BC1 are counted as before. The log says once which count is on. `1`: by texels, as before |
|
||||
| `RX_VK_EVICT_STALE_FLUSH=1` | (Triforce, 11-22, the performance audit's TEX-R404, after Source A's) Over the budget, the eviction writes each chosen texture the GPU drew back into the game's memory before it goes. The game draws its HUD labels inside the storage of a 1920 x 1080 target it no longer uses; when that target went, its old texels landed over the labels, which were then uploaded from them as noise. A write-back is now left out when another image the GPU drew overlaps the texture's storage and was drawn in a later frame than the texture's own last drawing (`gpu/vk/evict_reason.h`; one drawn in the same frame keeps it); the texture goes all the same. The log names the first 20 (`vk: texture #... goes without its write-back`) and counts them on the `written back into their memory before eviction` line. Nothing changes while no pass writes anything back (a card under its budget). `1`: every chosen texture is written back, as before |
|
||||
| `RX_VK_COMPACT=1`, `RX_VK_COMPACT_PCT=<50..90>`, `RX_VK_COMPACT_MB=<MB>` | VRAM compaction (off by default): the textures that are not render targets in a pool of their own, moved out of sparsely used blocks a few a present so that the blocks go back to the driver, and the texture budget holding the driver's count at that share of what it allows (85); the free space that starts a run (512; 192 while the count is over 90%) |
|
||||
| `RX_VK_EVICT_EXCESS=0` | (Triforce, on by default; `=0`, or the lab's knob `noexcess`, as before) With the compaction on, what the 90% and 97% rules ask of the hold's pass is their excess (`gpu/vk/vram_compact.h` `rule_target`, `gpu/vk/vk_texture.cpp` `texture_frame`): their budget less 64 MB, where the pass went down to 7/8 of it. Those budgets are the textures less the excess, not sizes: 62 MB over the 90% line on an 8 GB card took about 400 MB of textures, all on screen again within the camera's turn, made again, and over the line again. Over the budget's size (the fixed one, or the live line's) the pass still goes down to 7/8 of that size; with both, the lower |
|
||||
| `RX_VK_COMPACT=1`, `RX_VK_COMPACT_PCT=<50..90>`, `RX_VK_COMPACT_MB=<MB>` | VRAM compaction (off by default): the textures that are not render targets in a pool of their own, moved out of sparsely used blocks a few a present so that the blocks go back to the driver, and the texture budget holding the driver's count at that share of what it allows (85); the free space that starts a run (192 while the count is over 90%). `RX_VK_COMPACT_MB` unset: (Triforce, 11-22, the performance audit's TEX-38, after Source A's) a sixteenth of what the driver allows, 64 to 512 MB (`vram_compact.h` `default_min_free`): 512 on a card that allows 8 GB or more, as before; 327 on a 6 GB laptop that allows 5,233 MB; 512 before the first look. `RX_VK_COMPACT_MB=512`: 512 on every card, as before. `tests/test_compact_start.py` |
|
||||
| `RX_VK_MEMORY_PRIORITY=1` or `<targets>,<textures>` | (Triforce, 11-22, the performance audit's TEX-47, after Source A's; off when not set) When a card is short of video memory, Windows moves some of the game's device memory to system memory, read over the bus from then on, and picks what goes. With the switch and a driver that has `VK_EXT_memory_priority`, the game ranks its memory: the render targets' blocks 1.0 (kept first), the sampled textures' 0.25 (moved out first), everything else the driver's own 0.5 (`gpu/vk/memory_priority.h`); `<targets>,<textures>` sets the first two, each from 0 to 1. The textures then come from their own pool also where it is not compacted (`RX_VK_COMPACT`), and a sparse texture's chunks name the textures' rank. The log says `vk: memory priorities on` with the three numbers, or that the driver has no such extension. Source A measured it on an RTX 4090 with the video memory taken by other programs: with 1.3 GB moved out, a median GPU frame of 24 to 29 ms against 109 to 179; with room on the card, no difference. Not run on a small card, and a driver may ignore it: off by default, and without the switch the extension is not asked for. `0`, `off`, `no` or a value that cannot be read: off |
|
||||
| `RX_VK_SKIP_COMPRESSED_OVER_RT=1` | A compressed (ASTC, BC, ETC2/EAC) texture made over storage render targets used is not uploaded, as before: bosses and new enemies all blue the first time |
|
||||
| `RX_VK_NO_WRITEBACK` (set) | GPU writes to mirrored pools are not copied back to guest memory (an experiment, for A/B) |
|
||||
| `RX_VK_MSYNC_PASS=0`, `=1` | (Triforce, 11-21, the performance audit's MEM-48) A mirror sync's pages that come from a capture's buffer go to the pool's VRAM mirror by the write-back diff's compute pass, one dispatch a sync, where they were copy regions of a page or a few each (700 to 1,300 a frame, each read over PCIe after the one before). A run not in whole words, a GPU without subgroup votes in compute and a sync whose chunk table finds no room keep the copies; a mirror written twice in one upload command buffer, once by the pass, gets a full barrier between. On for NVIDIA when not set; `1`: on every GPU; `0`: copy regions, as before. The log's `mirror syncs' pass (600 submits)` line counts dispatches, chunks, fallbacks and barriers; `RX_VK_LAB_AB=nomsyncpass` is the in-run comparison (`gpu/vk/msync_pass.h`, `vk_memory.cpp` `msync_pass_add`, `msync_pass_flush`) |
|
||||
| `RX_VK_WB_FORGET_SORT=1` | (Triforce, 11-21, the performance audit's MEM-61) At the end of each part with write-backs the write-back diff clears, for every page written since, the bit that says its pool's shadow knows the page. The three lists of such pages (the game's writes, the collection's, the replay's) were sorted first, thousands of pages a part, only so that the pool found for one page serves the next; the bits and the counts do not depend on the order, and the lists hold ascending runs as they come. They are no longer sorted. The log's `forgetting the written pages took` line gives the time. `1`: sorted, as before (`vk_memory.cpp` `shadows_forget_written`) |
|
||||
| `RX_VK_WB_DIFF=0` | Write-backs copy every byte again instead of only what changed against a VRAM shadow (the diff is on by default; v2.0.9 and v2.0.10 had it off, issue 1161) |
|
||||
| `RX_VK_LAZY_WB=1`, `=2` or `=0` | The lazy write-back for one run, over the Debug tab's Lazy write-back row (`lazy_write-back=1`; on by default since options_version 5; `docs/lazy-writeback.md`, `gpu/vk/wb_lazy_state.h`): a whole page of what shaders write into a mirrored pool that the CPU leaves alone is no longer copied back at every submission; its page has no access, and whoever touches it (the game's code or the host's, by a fault; a host call that hands it to the kernel; the GPU through the import) has it copied down first. Windows only. On AMD's driver the row alone leaves it off, as NX2navi did after games ended in play there; `=1` turns it on anyway. `=2` is the self-check: every copy is still made, the pages are protected and paid as if not, and each payment compares what it would have copied with guest memory: a `MISMATCH at guest` line is a page it would have got wrong. The log says `vk: lazy write-back on` (or why off) at the start, and every 600 submits `vk: lazy write-back (600 submits)`: the MB not copied, the pages owed, the pages paid by a fault, a host call, a GPU read, a mirror given up and a recording's submit, the payments and their time, and what failed |
|
||||
| `RX_VK_LAZY_PAYERS=<1..4>` | (Triforce, 4 by default; `=1` as before) How many of the lazy write-back's payments copy at once (`gpu/vk/wb_lazy_payers.h`, NX2navi's `wb_lazy_unlocked`). A payment's copy goes onto the queue after everything submitted so far and its thread waits for it (0.5 to 3 ms each in the owner's sessions, up to 21 ms at a load); with one at a time, a second thread that touched another owed page, or the replay giving a mirror up, waited for the first one's copy to come back before its own went onto the queue. Each payment holds a slot of its own (a command buffer and a fence); the pages of two payments are never the same ones (`gpu/vk/wb_lazy_state.h`), and each copy still goes onto the one queue after everything before it. The 600-submit line `vk: lazy write-back (600 submits)` ends with the payments that waited for a free slot and the most slots in use at once |
|
||||
| `RX_VK_GEN_SEED=<n>` | The page write generations (`gpu/vk/write_gen.h`) start at `n` and not at 1 (decimal, or hex with `0x`; 2^62 at most). They are 64 bits; the 32-bit ones of earlier builds ran out after days of play, and textures and mirrors then kept old contents. `RX_VK_GEN_SEED=0xFFFF0000` takes a play test across 2^32 within seconds: the log says `the write generations start at` and, at the crossing, `this run has made 4294967296 write generations`, and nothing in the picture should change there |
|
||||
| `RX_VK_UPSCALE_OFF=1` | (Triforce) The upscaler Off for one run: the game's gameplay upscale networks are not dispatched, their input is stretched linearly into their output (`gpu/vk/upscale_off.h`). Softer than the networks below 100%; only while the game's own upscaler draws (DLSS and FSR take the dispatch first). Not set: as before, the networks run, and on cards that run them on software multiplies the first one is stood in for. The lab's `upoff` phases switch it within a run |
|
||||
| `RX_VK_STUB_SAME_SIZE=0` | (Triforce, 11-22, the performance audit's GPUWORK-21, after Source B's and Source A's; `gpu/vk/stub_same_size.h`) On unless `0`. A gameplay upscale network that cannot run (left out or not translated: `RX_VK_NO_F16`, a card or driver that cannot build it) is stood in for by its input drawn into its output (`gpu/vk/vk_draw.cpp` `upscale_stub`) also where the two are one size: `9dc98871eb7fc101`, the network of Render resolution 100%, was declined as "no larger than its input" and skipped whole, a black 3D under the HUD. Both gameplay networks now take the typed upscale first (it reads the scene's shared-exponent picture and undoes the network's square-root encoding; it was the 3/4 network's alone), then the blit, which warns of wrong colours for both, then nothing. The picture is the upscaler Off's: softer, none of the network's anti-aliasing. Only where the network cannot run. `0`: the decline, and the 3/4 network alone in the typed upscale, as before. `RX_VK_NO_UPSCALE_STUB=1` still turns the whole stub off; `RX_VK_FORCE_UPSCALE_STUB=2` sends every network through it, for a look |
|
||||
| `RX_VK_DLSS=0/1/2`, `RX_VK_DLSS_PRESET=<letter>`, `RX_VK_DLSS_LOG=1`, `RX_VK_REFLEX`, `RX_VK_REFLEX_LOG=1`, `RX_VK_ANTILAG=0/1` | NVIDIA DLSS and Reflex, and AMD Anti-Lag 2, for one run (`=-` on Reflex or Anti-Lag 2: its extensions not even enabled): the readme's NVIDIA DLSS section. `RX_VK_DLSS_TRACE=<frames>` logs one frame's large draws every that many frames, `RX_VK_DLSS_DEBUG=motion` shows the motion vectors, `=alternate` the game's own upscale every other frame |
|
||||
| `RX_VK_FSR4=0/1/2`, `RX_VK_FSR_DIR=<folder>` | AMD FSR 4 for one run (0 never, 1 FSR 4, 2 its Native AA), and another folder for AMD's DLLs (not from `hookshot_env.txt`): the readme's AMD FSR 4 section. `RX_VK_FSR4=1/2` and `RX_VK_DLSS=1/2` go over the Upscaler row, a saved FSR 3.1 too where the engine they ask for runs; `RX_VK_FSR=1` goes over them (one upscaler at a time; `=2`: FSR 3.1 as its Native AA, the 3D at full size). The DLSS trace and debug switches above apply to FSR 4 too, on the frame chain they share |
|
||||
| `RX_VK_FSR4_FG=0/1` | AMD FSR 4's frame generation, the Frame generation row's AMD FSR 4 (`gpu/vk/vk_fsr4.cpp` `fsr4fg`): 0 never in this run (`RX_VK_FSR4=0` too, which keeps AMD's library unloaded); 1 any frame generation AMD's library lists for the card counts, an FSR 3.1 one too, so the path can be tried on a card without FSR 4's (the row then offers AMD FSR 4 there; the log names the version in use) |
|
||||
| `RX_VK_FSR4_DRS=1`, `RX_VK_FSR4_AUTO_EXPOSURE=0` | (Triforce) AMD FSR 4's context as before, for comparing (`gpu/vk/vk_fsr4.cpp` `make_context`, `gpu/vk/temporal_rules.h` `plan_context`): `RX_VK_FSR4_DRS=1` one context with FSR's dynamic-resolution flag for every render size from the start, where a fixed Render resolution otherwise gets a context of its own size without it (and the game's dynamic resolution one with it once the size first changes); `RX_VK_FSR4_AUTO_EXPOSURE=0` its HDR contexts (Upscale before bloom, or an RGBA16F picture with RenoDX's HDR Native) without FSR's auto exposure. A creation or evaluation of DLSS or FSR 4 that fails leaves the game's upscale for 2 s and is tried again; the fourth failure in a row turns that engine off (the Upscaler row then shows Game and says so) until the row is set again |
|
||||
| `RX_VK_SHARPEN_3D=0`, `RX_VK_FSR3_BOOST=0`, `RX_VK_UPSCALE_LOD_BIAS=0/<negative>` | (Triforce) For comparing with before (`gpu/vk/sharpen_rules.h`): the Sharpness row sharpens the 3D before the HUD with DLSS, DLAA, FSR 3.1 and FSR 4 (FSR 3.1's own RCAS, FSR 4's own sharpening, FSR 3.1's RCAS pass over DLSS's picture) and then nothing at the window; `RX_VK_SHARPEN_3D=0` the finished picture at the window for every upscaler, the HUD with it, as before. `RX_VK_FSR3_BOOST=0` FSR 3.1's sharpness the row's alone, without the share towards the most below three quarters of the output's width. `RX_VK_UPSCALE_LOD_BIAS=0` no texture LOD bias while DLSS or FSR scales the 3D with jitter (unset: log2(render / output) - 0.5 in quarters of a level, so -1.5 at Performance, -1 at Quality and -0.5 at the Native AAs, on the wrapping, mipmapped textures of the draws into the scene at the upscaler's render size (or, in the frame the dynamic resolution steps, at the size the scene's camera is drawn at), never the shadow maps, captures, other passes or dispatches; the log says `vk: texture LOD bias` at each change); a negative number, such as `RX_VK_UPSCALE_LOD_BIAS=-1` or `=-1.5`, that bias (-3 at most) in the same draws and only while an upscaler with jitter runs, for trying other values (the log says it once at the start) |
|
||||
| `RX_VK_FSR4_FG=0/1/4` | AMD's frame generation, the Frame generation row's AMD FSR (`gpu/vk/vk_fsr4.cpp` `fsr4fg`): 0 never in this run (`RX_VK_FSR4=0` too, which keeps AMD's library unloaded); 1, as without it, the newest frame generation AMD's library lists for the card, FSR 4's where listed (RX 9000), else FSR 3.1's (3.1.6 on RX 6000 and 7000), the row naming it ("AMD FSR (3.1.6)") and the log the version in use; 4 FSR 4's alone, as before (FG-1) |
|
||||
| `TRIFORCE_MENU_AHEAD=0` | (Triforce) What the options' rows ask of NVIDIA's and AMD's libraries (whether DLSS, FSR 4 and FSR 4's frame generation run here: NGX's start, AMD's loader) asked at the options' open on the presenting thread, as before, and not once on a thread of its own as soon as the game runs (`gpu/vk/vk_menu.cpp` `menu_ahead`; its log line says how long each took). For comparing: the first open waited about 2 s for them in test11 |
|
||||
| `RX_VK_AA=<0..3>`, `RX_VK_AA_KEEP=1` | The anti-aliasing for one run, over the Insert menu's Anti-aliasing row: 0 the game's own SMAA, 1 none, 2 FXAA, 3 SMAA at its Ultra preset in its place (`gpu/vk/aa_rows.h`, `gpu/vk/vk_aa.cpp`). Unset, the row decides; with DLSS, DLAA or FSR drawing, neither applies. The game's SMAA is three compute programs known by their keys (game build `e0f3ccfa`): with another choice in effect its composition is replaced and its edge and weight passes are left out, and `RX_VK_AA_KEEP=1` keeps those two running. The log says `vk: aa:` when a composition is first replaced, why one was left to the game, and when none was found for a minute |
|
||||
| `RX_VK_ASYNC=1` | The replay on a thread of its own instead of the game's submitting thread |
|
||||
| `RX_VK_OCC_QUERY=0`, `RX_VK_OCC_QUERY_SKIP=<addr>[,...]`, `RX_VK_OCC_COND=0`, `RX_VK_OCC_LOG_COND=1` | (on by default since 11-17: +2.7 to +4.6% fps in every scene measured, 10-12% fewer draws, no flicker added; `RX_VK_OCC_QUERY=0` turns it off) The game's samples-passed reports (which objects show; a count of 0 is not drawn) get their real counts: the replay still writes each report as it passes it with 4096 (`RX_VK_OCC_FIXED`, everything visible), and the draws from its reset are counted by Vulkan occlusion queries (precise where the card has them); once the GPU is done with the recording that holds them the count is written into the report's record over the 4096, as NX2navi writes it at completion. The done recordings are found with one look at the recordings' timeline (nothing waits) as a game's fence wait ends (the game reads its counts after it), at each recording's begin and each present, at the latest when the recording's slot comes round. The game's report records rotate (a ring: an address is another object's at its next report), so a count is written only while its report is still the newest at its address, and only when it is whole (every query available, no draw left out, reset and report in one recording, read back within 8 presents); otherwise the record keeps its 4096. The game also predicates draws and clears on these words (render conditions), decided as NX2navi decides them: a word whose newest report is a samples-passed one whose count is still to come is unknown and the condition renders; a word whose count was written (or for which none comes) is read from memory as before, where a written 0 skips the draws and clears it gates. A count goes in only over the value the replay left in the word (a compare-and-write: never over the game's CPU re-arming the record), and a record rewritten in the stream after its report (a small buffer clear, a report of another counter type) gets no count. A parallel replay's segments signal the recordings' timeline and are sealed as they are submitted, so their counts are written too. The count word is written as the replay writes a report (`guest_cpu_write`, and the word kept out of the mirrors' write-backs). With hostQueryReset (Vulkan 1.2) a recording's queries are reset on the CPU once read, only those it used. `RX_VK_OCC_QUERY_SKIP`: report addresses that keep the fixed answer (the log's `occlusion query sites` lines list the first 64 addresses with their counts). The log's `occlusion queries` line every 600 presents: the reports, how many were counted whole and why not, the counts written at completion (and of them 0), those not written and why (lost, superseded by a later report at the address, late, a render condition's), the mean latency in presents and how many were written after the next present, where the done recordings were found, and the render conditions on samples-passed words (rendered because a count was pending, rendered or skipped from a written count, from memory with no count to come, as before in the knob's off phases) with the draws and clears they skipped. `RX_VK_OCC_COND=0`: a condition on a samples-passed word always renders (the counts are still written), to tell the counts from the skips. `RX_VK_OCC_LOG_COND=1`: one such condition in 499 logged (300 lines), with both words, their sources (pending, written, memory) and the present. Lab: the knob `occq` in `RX_VK_LAB_AB` runs the queries the whole run and writes the counts of the reports made in its phases (`gpu/vk/occ_answer.h`, `vk_replay.cpp` "occlusion queries") |
|
||||
| `RX_VK_AA=<0..3>`, `RX_VK_AA_KEEP=1` | The anti-aliasing for one run, over the Insert menu's Anti-aliasing row: 0 the game's own SMAA, 1 none, 2 FXAA, 3 SMAA at its Ultra preset in its place (`gpu/vk/aa_rows.h`, `gpu/vk/vk_aa.cpp`). Unset, the row decides; with DLSS, DLAA or FSR drawing from the tone mapped picture (Upscale before bloom off) the game's SMAA is left out (none: they want jittered frames no other anti-aliasing has been over), and before the bloom it runs as the game's; the switch goes over both, for an A/B (`RX_VK_AA=0`: the game's SMAA under the upscaler). The game's SMAA is three compute programs known by their keys (game build `e0f3ccfa`): with another choice in effect its composition is replaced and its edge and weight passes are left out, and `RX_VK_AA_KEEP=1` keeps those two running. The log says `vk: aa:` when a composition is first replaced, why one was left to the game, and when none was found for a minute |
|
||||
| `RX_VK_ASYNC=1` | The replay on a thread of its own instead of the game's submitting thread (off by default). The game still presents only once the GPU has run its frame, so nothing is released early. (Triforce, `gpu/vk/async_rules.h`; not yet run in the game) With it on, each with a switch of its own to put it back: a signal of the CPU's takes its capture on the game's thread only when a submission handed over before it may still wait for that event, which the host tells at the submit (`RX_VK_ASYNC_EVENT_NOTES=0`: at every signal while the thread has work, as before; the `vk: the replay thread: ... signals of the CPU's` line counts both); the submit's capture shares its copies with the copy helpers and has them all made before the hand-over (`RX_VK_ASYNC_CAPTURE_BEHIND=0`: every copy on the game's thread); the game's submit keeps its virtual core for the hand-over (`HOS_ASYNC_KEEP_CORE=0`: given up and taken again); the game's present poll waits for the replay thread asleep and looks at its event between yields only once the GPU has the frame (`HOS_PRESENT_POLL=0`: the game's own sleeps); a present runs the jobs behind it until the frame's stopped work has gone on and then makes go only what was already stopped at the present before (`RX_VK_PRESENT_DRAIN=1`: every present forces every stopped queue past its wait, as before; `=0`: none does; `RX_VK_PRESENT_WAIT_MS`, 8: how long it runs the jobs behind); and the thread looks for its next job for 100 µs before it sleeps (`RX_VK_ASYNC_SPIN_US=<0..1000>`). Still open, and why it stays off: after a ten-area tour the player's character is drawn black for one frame, 0 to 3 times a minute at the Market (`gpu/vk/async_rules.h` has what the lab ruled out). Two diagnostics for it: `RX_VK_LOG_READBACK_ZERO=1` logs each readback of GPU results that is all 0 where it was not at its readback before, and `RX_VK_REGION_TRAP=1` (with `RX_VK_PASS_TRACE=1` and the frame log) logs the passes of the last frames and writes their render conditions to `region_cond_<n>.txt` when the picture's bottom middle goes dark for a frame, eight times a run. `RX_VK_ASYNC_FORCED=1`: the thread as it was before 11-14, every catch-up forcing |
|
||||
| `RX_VK_OCC_QUERY=0`, `RX_VK_OCC_QUERY_SKIP=<addr>[,...]`, `RX_VK_OCC_COND=0`, `RX_VK_OCC_LOG_COND=1`, `RX_VK_OCC_GATE=0` | (on by default since 11-17: +2.7 to +4.6% fps in every scene measured, 10-12% fewer draws, no flicker added; `RX_VK_OCC_QUERY=0` turns it off) The game's samples-passed reports (which objects show; a count of 0 is not drawn) get their real counts: the replay still writes each report as it passes it with 4096 (`RX_VK_OCC_FIXED`, everything visible), and the draws from its reset are counted by Vulkan occlusion queries (precise where the card has them); once the GPU is done with the recording that holds them the count is written into the report's record over the 4096, as NX2navi writes it at completion. The done recordings are found with one look at the recordings' timeline (nothing waits) as a game's fence wait ends (the game reads its counts after it), at each recording's begin and each present, at the latest when the recording's slot comes round. The game's report records rotate (a ring: an address is another object's at its next report), so a count is written only while its report is still the newest at its address, and only when it is whole (every query available, no draw left out, reset and report in one recording, read back within 8 presents); otherwise the record keeps its 4096. The game also predicates draws and clears on these words (render conditions), decided as NX2navi decides them: a word whose newest report is a samples-passed one whose count is still to come is unknown and the condition renders; a word whose count was written (or for which none comes) is read from memory as before, where a written 0 skips the draws and clears it gates. A count goes in only over the value the replay left in the word (a compare-and-write: never over the game's CPU re-arming the record), and a record rewritten in the stream after its report (a small buffer clear, a report of another counter type) gets no count. A parallel replay's segments signal the recordings' timeline and are sealed as they are submitted, so their counts are written too. The count word is written as the replay writes a report (`guest_cpu_write`, and the word kept out of the mirrors' write-backs). With hostQueryReset (Vulkan 1.2) a recording's queries are reset on the CPU once read, only those it used. `RX_VK_OCC_QUERY_SKIP`: report addresses that keep the fixed answer (the log's `occlusion query sites` lines list the first 64 addresses with their counts). The log's `occlusion queries` line every 600 presents: the reports, how many were counted whole and why not, the counts written at completion (and of them 0), those not written and why (lost, superseded by a later report at the address, late, a render condition's), the mean latency in presents and how many were written after the next present, where the done recordings were found, and the render conditions on samples-passed words (rendered because a count was pending, rendered or skipped from a written count, from memory with no count to come, as before in the knob's off phases) with the draws and clears they skipped. `RX_VK_OCC_COND=0`: a condition on a samples-passed word always renders (the counts are still written), to tell the counts from the skips. `RX_VK_OCC_LOG_COND=1`: one such condition in 499 logged (300 lines), with both words, their sources (pending, written, memory) and the present. (11-22) `RX_VK_OCC_GATE=0` turns off (on by default since its lab A/B: no fps lost at the Market): a count over a draw that a written count's condition left out (between the reset and its report) is the skip's 0, not the object's, and a condition on it renders; the count is still written for the game's CPU. Why: the game's CPU reads a count after its frame wait and draws a hidden object's proxy instead of the object, but most counts land after it has read the 4096, so it goes on drawing the object under the condition, the condition reads the skip's 0 and the object stays hidden (tickets 11-21: items and trees in the Forest Temple, black interiors; `RX_VK_OCC_QUERY=0` showed them). The line's second half counts these counts (counted whole, written, of them 0), the conditions that read one and those the switch rendered, on or off. Cost with it on: a hidden object under such a condition is drawn every other frame instead of never. Lab: the knob `occq` in `RX_VK_LAB_AB` runs the queries the whole run and writes the counts of the reports made in its phases (`gpu/vk/occ_answer.h`, `vk_replay.cpp` "occlusion queries") |
|
||||
| `RX_VK_OCC_DEPTH_ONLY=1` | (Triforce, 11-22, the performance audit's GPUWORK-01, after Source A's; off unless set) Only the occlusion windows whose draws write no colour are counted. The game's occlusion tests draw depth only, but a query here opens at a window's first draw in the pass and stays open to the report or the pass's end, so it can enclose draws that write colour, and a query's end waits for the work it encloses. With the switch, a window's first draw that writes a colour target gives its count up: the open query ends before that draw, no query begins again until the next reset, and the report is incomplete, so its record keeps the 4096 placeholder and what it gates is drawn. Fewer objects are culled with it (Source A: 4% fewer for 0.25 ms of GPU time), never one missing; whether that pays here is for a measurement to say, which is why it is off. The lab's knob `occdepth` (`RX_VK_LAB_AB`) is the switch in its phases. Counted either way, in a third `vk: occlusion queries` line every 600 presents: the counting windows that met a colour draw, the colour draws recorded under an open query, the counts given up and the reports kept 4096 for it (`gpu/vk/occ_answer.h` `Counter::colour_draw`; `gpu/vk/vk_replay.cpp` `occ_draw_colour`; `gpu/vk/vk_draw.cpp` `draw`) |
|
||||
| `RX_VK_OCC_LEAN=3` | (Triforce, 11-22, the performance audit's DESC-82, after Source B's: its first step, the census; off unless set) The game's occlusion proxies write no colour, yet each runs its whole fragment shader and fills its fragment descriptors. With `3`, each draw an open occlusion query counts that writes no colour is classed (`gpu/vk/occ_lean.h`): lean, or the first refusal of a pipeline without the fragment stage (no fragment stage, depth out, sample mask, demote, stores, image writes, atomics, global memory, alpha to coverage, alpha test), and its fragment descriptors added to its class; every 600 presents `vk: occlusion proxies (RX_VK_OCC_LEAN=3` gives each class's draws a frame and descriptors a draw. Nothing else changes: no pipeline, key or descriptor. The entry's lean pipelines (`1`) and their check (`2`) are built only if the census finds more than one fragment descriptor a proxy to save; they are not built, and read as off. `tests/test_occ_lean.py` |
|
||||
| `RX_VK_GATE_WAIT_MS=<1..100>` | (Triforce, off unless set, after NX2navi's `gate_wait_ms`, whose default is 10; not yet run in the game) A submission whose first command buffer begins (after state only) with a wait for an event the game signals from the CPU, unmet in the replay's order, waits at its submit for that signal, at most this long, before its capture and its replay (`gpu/vk/gate_wait.h`, `gpu/vk/vk_replay.cpp` `gate_wait_signal`): the capture then holds what the game wrote up to its signal, and the submission is replayed in the submit call on the submitting thread, instead of stopping at the wait and going on from the order thread (`sync_watch`) with a second capture once the signal came. The wait holds no lock and looks at the event's word in the game's memory. One that runs out goes as before; after 4 that ran out, once they are more than a tenth, it is off for the run (logged). A `vk: RX_VK_GATE_WAIT_MS` line every 600 waits gives their mean and how many ran out; the order line's `captures at a CPU event's wait` and `made to go by presents` say how often the old way was taken |
|
||||
| `RX_VK_WAIT_HOLD_PAUSE_US=<us>` | (Triforce, 11-22, the performance audit's THREAD-11, after Source B's; off unless set, not measured here) A wait of the game's for a fence whose work is stopped at an event's wait holds up to `RX_VK_WAIT_HOLD_US` (3 ms) for another queue to let it on before it forces it, looking again and again: a flush, the timeline's value, the order lock to ask whether the stopped work is still needed, and a yield of the processor. With `<us>` (2 is Source B's; 1000 at most) a gap of PAUSEs that long stands between two looks instead of the yield, and the order lock is taken only when one of its sections has left since the waiter last asked, which is the only time its answer can change; the fence's own value is still read at every look, and the bound and the forced drain stay. Source B measured 59.2 to 59.9 fps and a 1% low of 40.0 to 42.1 with such a gap on a loop that runs far more often than this one (about 15 holds a second here). `0` or not set: as before. Either way the `vk: queues ordered by their events` report is followed by a `vk: fence waits held for stopped work` line: the holds, their looks, the time held, the takes of the order lock and how the holds ended (`gpu/vk/wait_hold.h`, `gpu/vk/vk_replay.cpp` `wait`) |
|
||||
| `RX_VK_WAIT_HOLD_PAUSE_US=<us>` | (Triforce, 11-22, the performance audit's THREAD-11, after Source B's; off unless set, not measured here) A wait of the game's for a fence whose work is stopped at an event's wait holds up to `RX_VK_WAIT_HOLD_US` (3 ms) for another queue to let it on before it forces it, looking again and again: a flush, the timeline's value, the order lock to ask whether the stopped work is still needed, and a yield of the processor. With `<us>` (2 is Source B's; 1000 at most) a gap of PAUSEs that long stands between two looks instead of the yield, and the order lock is taken only when one of its sections has left since the waiter last asked, which is the only time its answer can change, or while a signal of the CPU's (`nvnEventSignal` without the replay thread) is queued and no section has acted on it yet; the fence's own value is still read at every look, and the bound and the forced drain stay. Source B measured 59.2 to 59.9 fps and a 1% low of 40.0 to 42.1 with such a gap on a loop that runs far more often than this one (about 15 holds a second here). `0` or not set: as before. Either way the `vk: queues ordered by their events` report is followed by a `vk: fence waits held for stopped work` line: the holds, their looks, the time held, the takes of the order lock and how the holds ended (`gpu/vk/wait_hold.h`, `gpu/vk/vk_replay.cpp` `wait`) |
|
||||
| `RX_VK_INDEX_REBASE=0` | (Triforce, 11-21, the performance audit's DESC-12) A direct indexed draw binds its index buffer at offset 0 and gives its offset as the draw's first index, so draws at different offsets of one buffer bind it once: bound at each draw's own offset, nearly every indexed draw called `vkCmdBindIndexBuffer`. Only where the offset is a whole number of indices; indirect indexed draws are as before. `RX_VK_PROF_FINE=1` counts the index binds looked up and those made. `0`: every draw binds at its own offset (`gpu/vk/index_rebase.h`, `vk_draw.cpp` `draw`, `bind_index`) |
|
||||
| `RX_VK_RECORDER_OWN=0` | (Triforce, 11-21, the performance audit's REPLAY-04) With the recorder thread, a recording slot's descriptor pools are reset, its extra pools destroyed and its grown streams given back in `draw_begin_recording`, after the recording's first packets, as before: each is a boundary the replay waits at until the recorder has run what came before. The default makes that reset in `begin_recording` right after the slot's command pools are reset, where the recorder has nothing held. The 120-present line `a frame's recorder thread` counts the replay's waits (`gpu/vk/vk_draw.cpp` `draw_slot_reset`, `vk_replay.cpp` `begin_recording`) |
|
||||
| `RX_VK_DESC_POOL_GROW=0`, `RX_VK_DESC_POOL_DIV=<1..32>`, `RX_VK_STREAM_MB=<MB>` | (Triforce, 11-22, the performance audit's DESC-33, after Source A's; `gpu/vk/desc_pool_grow.h`) Each recording slot (48 at most) keeps a descriptor pool for the programs over the push limit, and the driver may keep host memory for all of it 48 times. A slot's pool is made at half size (4096 sets, 16384 uniform buffers and sampled images, and so on) and made whole (8192 sets) at the slot's first reset after a recording ran out of it; a recording that runs out gets a whole extra pool on the spot, as it always did. `RX_VK_DESC_POOL_GROW=0`: whole pools from the start, as before. `RX_VK_DESC_POOL_DIV=<n>` divides both sizes by n. `RX_VK_STREAM_MB=<n>` is the size of each slot's first upload stream (2 by default; a recording that needs more is moved to a bigger one, kept for the slot's next 120 recordings; 24 with `RX_VK_STREAM_GROW_OFF=1`, which skips draws instead). Every 3000 recordings the log's two "the recording streams" lines say the most one recording held of its stream, how many slots are still at half, how many were made whole, the extra pools made, and the most sets and descriptors of each type one recording took: what a smaller default is judged by (the stream's stays 2 MB until those numbers are read in play) (`gpu/vk/vk_draw.cpp` `make_pool`, `slot_reset_locked`, `draw_begin_recording`) |
|
||||
| `RX_VK_CAP_SPARE_FIT=0`, `RX_VK_CAP_STEP_MB=<n>` | (Triforce, 11-22, the performance audit's MEM-33; the first on by default, the second off unless set; not yet run in the game) `RX_VK_CAP_SPARE_FIT=0`: a capture with no spare buffer makes its own with the spares' lock held, takes any spare that fits, and a spare made ahead is made once, as before. Without it (`gpu/vk/cap_spare.h`, `gpu/vk/vk_memory.cpp` `cap_buf_get`) the buffer is made with the lock let go, so the replay's take does not wait behind a submitting thread's allocation to give a buffer back; where spares are not capped at 32 MB a capture leaves alone a spare of 32 MB or more that is over twice its size class, for the load that wants it; the spare a capture of a class of 32 MB or more takes is made again on a worker; a spare is made ahead only if it fits what spares may hold together with the ones held and being made, and a buffer given back counts the ones being made; when the allocation fails, any spare that fits, then the exact size. `RX_VK_CAP_STEP_MB=<n>`: where spares are capped at 32 MB (a card of 6.5 GB or less), a capture over 16 and up to 32 MB gets a buffer in steps of n MB, not the whole 32 MB (Source A: 4; its worst frames were worse in two pairs, so off here). The 600-take line counts the buffers made on a submitting thread and their ms |
|
||||
| `RX_VK_MIRROR_PIECE_IDLE=<submissions>` | (Triforce, 11-22, the performance audit's MEM-26, its first step only; off unless set; not yet run in the game) A mirror in pieces keeps a piece's memory until the whole mirror goes, also where no game pool is left in its import. Giving such pieces back is NOT ported (the unbind and the free must wait for the GPU and for the bind timeline). What it would find is counted (`gpu/vk/piece_idle.h`): every 1200 submissions, after the `mirrors in pieces` line, the MB of pieces no game pool covers; with this switch each binding given a mirror in pieces also notes the submission in its pieces, and the line says how many of those MB no binding reached for that many submissions (600 is the wait the release would use). Under about 100 MB at the end of a tour on a 6 GB card (`RX_VK_TEST_CARD_MB=6144`) the release is not worth porting |
|
||||
| `RX_VK_RANGE_WALK=0` | (Triforce, 11-22, the performance audit's MEM-42; on by default; not yet run in the game) The capture and collection loops (`gpu/vk/vk_memory.cpp` `memory_collect_written`, `capture_make`'s staging and behind loops, `take_capture`'s loops over the texture storage's ranges) ask of every page whether it lies in a sorted range list with a binary search, as before. Without it each loop has a cursor that only moves forward (`gpu/vk/range_walk.h`), one pass over the ranges for the loop; an address below the last one asked searches again, so any order gives the search's answers (`tests/test_range_walk.py` compares them). The `RX_VK_LAB_AB` knob `norangewalk` searches in its phases |
|
||||
| `RX_VK_TABLE_STREAM=0` | (Triforce, 11-22, the performance audit's SYNC-04; on by default; not yet run in the game) The guest page table's changes of a recording (the table the shaders' pointers go through, `gpu/vk/vk_memory.cpp` `memory_table_flush`) are flushed as before: a (page, value) pair for every page changed, all of them sorted, the last of each page kept: 16 bytes a page and a sort on the recording thread, a few ms when a pool of hundreds of MB is imported ahead or merged. Without it the changes are streamed (`gpu/vk/table_stream.h`): runs in page order and apart are appended one after the other, any other set is swept by page with the newest change owning each page, through one reused batch of 8,192 entries. The transfers are the same ones in the same order (`tests/test_page_table_stream.py` compares the two, entry for entry). A flush over 1 ms is logged with its pages, changes and transfers (the first 16) |
|
||||
| `RX_VK_CAPTURE_BEHIND=0` | (Triforce, on by default; `=0` as before) The submit-time capture (`gpu/vk/vk_memory.cpp` `capture_make`) takes the write marks on the game's submitting thread and copies there only the pages read at once (the late pages and the texture storage); the rest of its copies, in parts of 32 pages, go to the capture's copy helpers while that thread replays the submission (`gpu/vk/capture_behind.h`). A read of a page as submitted copies its part itself when no helper has taken it yet, or waits for the helper; every part is done and flushed before a recording is submitted and before the thread goes back to the game. Only with the replay on the submitting thread (not `RX_VK_ASYNC=1`), with copy helpers (`RX_VK_CAPTURE_THREADS`, not `RX_VK_LOW_SPEC`), at least 128 pages behind and at most 512 ahead (a scene's load: copied whole as before). At the Market the old copy was ~0.25 ms of each submit's ~0.35 ms capture, six submits a frame. The 120-present line `a frame's captures at the game's submits` gives their time on the game's threads (the scan, the copies made there, and the copies behind made or waited for by the replay), the MB copied and behind, and who copied the parts; the stall line names the captures when they took 1 ms or more |
|
||||
| `RX_VK_PARALLEL=<0..8>`, `RX_VK_PARALLEL_AUTO=<2..8>` | The parallel replay: a frame's large command buffers recorded on that many threads, always, or wherever short trials as the game runs find it faster than the replay thread alone; `RX_VK_PARALLEL=0`: never. The Debug tab's Replay helper threads row is the second without an environment to set (`replay_helper_threads=` 1 to 7 for 2 to 8 threads); either switch goes over the row. The row's Automatic (8), which it is unless the options file says otherwise, is the count `gpu/vk/replay_threads.h` gives the PC: none, on every PC since 11-17 (it was 2 or 3 with five cores or more: in the owner's play the helper threads brought 10-25 s stretches at 39-48 fps when moving, the game's own frame time 4 to 10-13 ms, and with none there were none); a count on the row, or `RX_VK_PARALLEL_AUTO`, still runs them. The log says at the start what was chosen (`replay helper threads:`) and at each trial which way is in use (`parallel replay, trial`). Between trials the tuner's rule (`gpu/vk/replay_threads.h` `rule`) judges every 120 frames on the replay thread alone: where the replay is plainly the frame's limit (70% of the frame or more) and the helper threads would take at least 1 ms and a tenth of the frame off it, never counting below the GPU's time (the game waits for each frame's GPU work), they are turned on without a trial; where they cannot pay (no command buffer large enough to cut, the GPU's time about as long as the replay's, or the replay under 60% of the frame: the game's own threads are its limit) no trial is made while that holds; trials decide the rest, and a trial that takes the helpers back off holds the rule's "on" for 3,600 presents. The log says so (`parallel replay, the rule`) when its verdict changes. `RX_VK_PARALLEL_RULE=0`: trials only, as before. With DLSS or FSR on, for upscaling or frame generation, the dry pass tells their hooks in the draws in stream order, and each command buffer from the first draw or dispatch that takes what they noted (the upscale, or the engine's point before the bloom) on is recorded in order after the segments before it (`gpu/vk/stream_order.h`); `RX_VK_PARALLEL_TEMPORAL=0`: the replay thread records alone then, as before. The frame statistics' `a frame's parallel replay:` line says in how many frames the threads recorded, the command buffers in segments and alone (and why), and the time in them; the next one (`its parts`) where that time went: the setup before the threads begin, how soon each command buffer's first segment reached the GPU, the helper threads' wake-up, each command buffer's longest segment, the replay thread's wait, the submits, the recording lock's waits, and the segments' GPU time (the `GPU time` line counts the segments too; it left them out). After each trial's line a `trial N's parts` line gives its three parts' frame, replay thread's time, GPU time, the rest of the frame, full barriers and draws, and the helper threads' parts. That header lists what an audit of the parallel replay found and fixed, and what is left. `RX_VK_NO_DRY_COPIES=1`: the dry pass does not mark what copies and texture clears write, as before. The replay thread records the next segment to submit itself when no helper thread has begun it (it only waited before, on the core kept for it); `RX_VK_PARALLEL_OWN=0`: it waits for the helper threads, as before. `RX_VK_PARALLEL_SEG=<32..>`: the draws and dispatches a segment is cut for (160); `RX_VK_PARALLEL_SEGS=<2..12>`: the most segments a command buffer is cut into (6), without which a smaller `RX_VK_PARALLEL_SEG` cuts no finer once a command buffer has six segments' worth |
|
||||
| `RX_VK_CAP_FREE_ASYNC=0` | (Triforce, on by default; `=0` as before) A retired capture buffer the spares cannot keep (past 12 buffers or 768 MB, 32 MB on a card of 6.5 GB or less) is destroyed on a thread of its own (`gpu/vk/vk_memory.cpp` `cap_buf_free`, `destroy_buffer_later`), not in the capture's take on the replay's thread with its locks held: freeing a 64-256 MB host-cached buffer makes the driver unmap and release every page, the `retires` part of a `vk: slow capture take` line. Only buffers the GPU is done with get there; the memory comes back a moment later. The 600-take line counts the buffers and MB handed over. With no thread to be had they are destroyed where they were retired |
|
||||
| `RX_VK_PARALLEL=<0..8>`, `RX_VK_PARALLEL_AUTO=<2..8>` | The parallel replay: a frame's large command buffers recorded on that many threads, always, or wherever short trials as the game runs find it faster than the replay thread alone; `RX_VK_PARALLEL=0`: never. The Debug tab's Replay helper threads row is the second without an environment to set (`replay_helper_threads=` 1 to 7 for 2 to 8 threads); either switch goes over the row. The row's Automatic (8), which it is unless the options file says otherwise, is the count `gpu/vk/replay_threads.h` gives the PC: none with four cores or fewer or on AMD's driver for RDNA 1 and 2, 2 threads with five to seven cores, 3 with eight or more. The log says at the start what was chosen (`replay helper threads:`) and at each trial which way is in use (`parallel replay, trial`). Between trials the tuner's rule (`gpu/vk/replay_threads.h` `rule`) judges every 120 frames on the replay thread alone: where the replay is plainly the frame's limit (70% of the frame or more) and the helper threads would take at least 1 ms and a tenth of the frame off it, never counting below the GPU's time (the game waits for each frame's GPU work), they are turned on without a trial; where they cannot pay (no command buffer large enough to cut, the GPU's time about as long as the replay's, or the replay under 60% of the frame: the game's own threads are its limit) no trial is made while that holds; trials decide the rest, and a trial that takes the helpers back off holds the rule's "on" for 3,600 presents. The log says so (`parallel replay, the rule`) when its verdict changes. `RX_VK_PARALLEL_RULE=0`: trials only, as before. With DLSS or FSR on, for upscaling or frame generation, the dry pass tells their hooks in the draws in stream order, and each command buffer from the first draw or dispatch that takes what they noted (the upscale, or the engine's point before the bloom) on is recorded in order after the segments before it (`gpu/vk/stream_order.h`); `RX_VK_PARALLEL_TEMPORAL=0`: the replay thread records alone then, as before. The frame statistics' `a frame's parallel replay:` line says in how many frames the threads recorded, the command buffers in segments and alone (and why), and the time in them; the next one (`its parts`) where that time went: the setup before the threads begin, how soon each command buffer's first segment reached the GPU, the helper threads' wake-up, each command buffer's longest segment, the replay thread's wait, the submits, the recording lock's waits, and the segments' GPU time (the `GPU time` line counts the segments too; it left them out). After each trial's line a `trial N's parts` line gives its three parts' frame, replay thread's time, GPU time, the rest of the frame, full barriers and draws, and the helper threads' parts. That header lists what an audit of the parallel replay found and fixed, and what is left. `RX_VK_NO_DRY_COPIES=1`: the dry pass does not mark what copies and texture clears write, as before. The replay thread records the next segment to submit itself when no helper thread has begun it (it only waited before, on the core kept for it); `RX_VK_PARALLEL_OWN=0`: it waits for the helper threads, as before. `RX_VK_PARALLEL_SEG=<32..>`: the draws and dispatches a segment is cut for (160); `RX_VK_PARALLEL_SEGS=<2..12>`: the most segments a command buffer is cut into (6), without which a smaller `RX_VK_PARALLEL_SEG` cuts no finer once a command buffer has six segments' worth |
|
||||
| `RX_VK_PARALLEL_BACKOFF=0` | The tuner's trials as before: one every 1,800 presents after one that kept the way, each with 104 frames the other way. With the back-off (the default, `gpu/vk/replay_threads.h` `Tuner`) each trial that keeps the way, the other way longer than both of its own parts, puts the next one off twice as long (3,600, 7,200, then 14,400 presents at most; a margin of 10% or more counts twice), one too close to tell keeps the old interval (the first such one after a change of scene or way: 900 presents), and once the way has held so the other way is tried for 64 frames, not 104; a short trial that finds the other way shorter changes nothing itself, a full trial follows at once. The next trial comes early (900 presents after the last one at the soonest, never while the rule says no trial) when the scene clearly changes: two windows of 120 frames in a row whose draws moved by a quarter (200 at least) or whose replay or GPU time moved by 30% (1 ms at least) from the first window after the way was set, or a trial whose first and last parts did. In the lab's steady Market a trial came every ~2,090 presents, each ~100 frames 1.9 ms longer; the trial lines now end with when the next may come, and `parallel replay, the scene changed` says when one was brought forward |
|
||||
| `RX_VK_RECORDER=thread`, `=defer`, `=sync` | (off unless set; not yet measured in the game) `thread`: the replay thread's `vkCmd*` calls packed with copies of their arguments into a ring and made by a recorder thread of their own, in order (`gpu/vk/vk_recorder.h`); the replay thread waits for it at every command buffer begin, end and reset, submit, wait, readback and destruction. Beside the Replay helper threads too (no longer refused with `RX_VK_PARALLEL`): a parallel replay's segments make their calls themselves, after the ring has been run (`segments_begin`), and the recorder is idle while they record. With it on, the frame statistics' `a frame's recorder thread` line says how many of the replay's calls it made a frame and in how long, and how long the replay thread waited for it; what it saves is the replay time line's `commands` with it against without it. `defer` and `sync` are its test steps (held and run on the same thread). `RX_VK_RECORDER_RING_MB` (8), `RX_VK_RECORDER_SPIN_US`, `RX_VK_RECORDER_STATS=0`, `RX_VK_RECORDER_POISON=1`, `RX_VK_RECORDER_PIN` (`next`, `sibling` or a mask) |
|
||||
| `RX_VK_TUNER_SETTLED=0` | The tuner's rule judges every window and a trial the scene changed under decides, as before. With settled scenes only (the default, `gpu/vk/replay_threads.h` `Tuner`, after Kaefergeneral's #dev-fixes post: on his 5900X and RTX 3090 the rule turned the helper threads on in an area's load and the first trial after the arrival kept them, and Automatic was 6 to 10% slower than Off) the rule judges a window of 120 frames only if the one before it describes the same scene (its draws within a quarter, 200 at least, its replay and GPU times within 30%, 1 ms at least: the back-off's test), so a load's window and the first after it get no verdict and the rule's "on" comes a window after a scene settles; a trial whose first and last parts moved so changes nothing, either way, and the next comes 120 presents after a window like the one before it, not 900 or more later. The trial's line says so (`the scene changed under it`), and `parallel replay, the scene settled` when the next is set |
|
||||
| `RX_VK_RECORDER=thread`, `=defer`, `=sync`, `=off` | (unset: `thread` on an NVIDIA GPU with 12 logical processors or more, and on an AMD GPU with 6 physical cores or more in the process's affinity but for AMD's Windows driver for RX 5000 and RX 6000 (`gpu/vk/recorder_auto.h`); else off. The log's `vk: recorder thread on/off by default` line says which rule applied; `RX_VK_LAB_AB=norec` makes the calls directly in its phases, to measure it) `thread`: the replay thread's `vkCmd*` calls packed with copies of their arguments into a ring and made by a recorder thread of their own, in order (`gpu/vk/vk_recorder.h`); the replay thread waits for it at every command buffer begin, end and reset, submit, wait, readback and destruction. Beside the Replay helper threads too (no longer refused with `RX_VK_PARALLEL`): a parallel replay's segments make their calls themselves, after the ring has been run (`segments_begin`), and the recorder is idle while they record. With it on, the frame statistics' `a frame's recorder thread` line says how many of the replay's calls it made a frame and in how long, and how long the replay thread waited for it; what it saves is the replay time line's `commands` with it against without it. `defer` and `sync` are its test steps (held and run on the same thread). `RX_VK_RECORDER_RING_MB` (8), `RX_VK_RECORDER_SPIN_US`, `RX_VK_RECORDER_STATS=0`, `RX_VK_RECORDER_POISON=1`, `RX_VK_RECORDER_PIN` (`next`, `sibling` or a mask) |
|
||||
| `RX_VK_REPLAY_PRIO=0` or `1` | (Triforce, on by default, after NX2navi's `recorder_prio`; `=0` as before) A thread runs at the highest priority while it replays the game's frames (the submitting thread's replay and its capture, the present, the stopped work the order thread lets on: `gpu/vk/vk_replay.cpp` `ReplayPin`) and gets its own priority back after, so the game's code it runs between replays keeps the game's priority; the core kept for the replay is kept from the game's threads only, and the helper threads and the capture's copy helpers (above normal) outranked a replay at the game's priority there. A thread at that priority or above already is left alone. The replay thread of `RX_VK_ASYNC=1` and the recorder thread of `RX_VK_RECORDER=thread` take the level for good. `=1`: above normal. The log's `vk: a thread that replays runs at` line says which (`gpu/vk/replay_prio.h`) |
|
||||
| `RX_VK_REPLAY_PIN_SOFT=0`, `=2` | (Triforce, 11-22, the performance audit's THREAD-09, after Source A's; Windows) A thread is pinned while it replays to the core the host keeps for the replay, and that core is kept from the game's threads, not from other programs': where another program's high-priority thread holds it, the pinned replay waits for it, ready to run (Source A, a 6+8-core hybrid processor with an overlay service at priority 15: 14 to 37 frames over 40 ms in a 40 s run, none with this). Not set: on a processor with cores of more than one kind the pin is soft: the thread may run on the reserved core and on the fastest-kind cores among its own processors, the reserved core's last logical processor is its ideal one, and the core it is on when the pin starts is left out so that it moves at once; its affinity and ideal processor come back after the replay. The replay thread of `RX_VK_ASYNC=1` gets the same processors for good. A processor of one kind of core keeps the strict pin, and nothing changes there. `0`: the reserved core alone everywhere, as before; `2`: soft everywhere (the lab; the knob `pinsoft` of `RX_VK_LAB_AB` does it by phases). A thread of another program that wakes on the core every millisecond moves the replay again and again (Source A: 54.3 against 44.6 fps, one run each): `0` is for that. The log's `vk: a replay's pin is` line says which (`gpu/vk/replay_pin.h`, `gpu/vk/vk_replay.cpp` `ReplayPin`, `replay_pin_soft`) |
|
||||
| `HOS_VCORES=0`, `HOS_CORES=<1..8>`, `HOS_RESERVE_CORE=0` | No virtual cores; the cores the game sees (6); no core kept for the replay (one is, with 8 or more logical processors) |
|
||||
| `HOS_VCORES=0`, `HOS_CORES=<1..8>`, `HOS_RESERVE_CORE=0`, `=1` | No virtual cores; the cores the game sees (6); no core kept for the replay (one is, with 8 or more logical processors). (Triforce, 11-22, the performance audit's THREAD-49, after Source A's) On the cache die of a two-die X3D processor with SMT off none is kept unless `HOS_RESERVE_CORE=1` asks for it or the replay has a thread of its own (`RX_VK_ASYNC=1`): the game then has all 8 of the die's cores (Source A, a 9950X3D with SMT off: 59.8-59.9 fps with none kept against 56.9-57.4 with one). The log's `cpu: no core kept for the replay on the cache die` line says so. With SMT on and on every other processor nothing changes (`host/hos_x3d.h` `hos_x3d_keep_replay_core`) |
|
||||
| `HOS_AV1=mf`, `HOS_AV1_MISSING=1` | (Triforce, 11-22, the performance audit's IO-32; Windows) The game's AV1 movies on Media Foundation first (Microsoft's AV1 Video Extension), as before, and on dav1d only where the PC has no such decoder. Without it dav1d goes first where the FFmpeg the build links has libdav1d, as on Linux, and Media Foundation where it has not or where libdav1d does not open (`host/video_av1.h`, `host/nn_video.c` `dec_init_sized`): Media Foundation's path decodes in software on every GPU (`host/mf_av1.c` takes the synchronous decoder). `HOS_AV1=dav1d`, the old way to ask for dav1d first, is the default now. `HOS_AV1_MISSING=1`: Media Foundation as if the extension were missing. Each movie logs one line at its Stop, Flush or its decoder's end: its pictures, the decoder, the mean and the worst time to decode a submission, and the pictures skipped to catch up (`host/video_movie.h`). The two decoders were not timed against each other in the game |
|
||||
| `HOS_VIDEO_RGBA=1` | (Triforce, 11-22, the performance audit's IO-36) Every planar 4:2:0 movie picture (libdav1d's) is converted to RGBA when it is decoded, as before: a swscale pass, an 8 MB allocation and an 8 MB row copy for a 1080p picture, on the movie thread. Without it such a picture is kept as NV12 alone, as Media Foundation's NV12 pictures already were, and its pool makes the RGBA only if the game reads RGBA, which this game's movie library does not; planar 4:2:0 with alpha is converted at once either way. The NV12 buffer is zeroed only for an odd size or a format that is not copied into it, and U and V are interleaved 16 pairs a step with SSE2 (`host/video_nv12.h`, `host/nn_video.c` `queue_frame`). The movie's line in the log (IO-32) has the time a picture took with either. Not timed in the game |
|
||||
| `HOS_VIDEO_UNBOUNDED_CATCHUP=1`, `HOS_VIDEO_NO_CATCHUP=1` | (Triforce, 11-22, the performance audit's THREAD-82) The movie decoder's acquire skips the pictures behind the movie's clock and decodes the next ones to skip them too. `HOS_VIDEO_UNBOUNDED_CATCHUP=1`: with no bound but a guard of 600 steps, as before: with a decoder slower than the movie (19.5 ms a picture against 16.7) each picture decoded to catch up puts the clock further ahead, so an acquire decoded up to about 300 pictures with its lock held, threw them away, and the next started further behind. Without it each decode that gives a picture is timed, about the last 8 kept as one number, and the acquire stops decoding ahead when that number is more than the gap between two pictures (from the pictures' own times) or once it has decoded for one gap, and shows the late picture it has (`host/video_catchup.h`, `host/nn_video.c` `dec_acquire`): such a movie falls behind its sound instead of stalling, and its line in the log says "slower than it plays". A decoder faster than the movie catches up as before, a few pictures an acquire. `HOS_VIDEO_NO_CATCHUP=1`: no picture skipped at all (the movie in slow motion under 60 fps). Not run in the game |
|
||||
| `HOS_VIDEO_INPUT_LIMIT=<n>` | (Triforce, 11-22, the performance audit's IO-34) How many submissions the movie decoder holds, not decoded yet or decoded and not taken, before it refuses one: 16 when unset; `0`: no limit, every submission taken, as before. The game submits a whole movie at once on the thread that also takes the pictures, so at a movie's start the pictures that came due while it submitted were skipped. With the limit a submission is refused at once with the console's result for a full decoder (0x1c266f) and the game submits it again later; the stream's last submission is never refused, and a decoder with no codec behind it refuses nothing. Each decoder has its own "ready for a submission" event, clear from a refusal until an acquire, a Stop or a Flush makes room (it was one event for all, always set); the movie's line in the log counts the refusals (`host/video_input.h`, `host/nn_video.c` `dec_submit`, `input_room`). If a movie ever hangs on a black screen, try `=0` first. Not run in the game |
|
||||
| `HOS_MOVIE_PACE=0` | (Triforce, 11-22, the performance audit's PRESENT-30) The frame rate cap is kept while a movie plays, as before. Without it, at a cap of exactly 60 and with the Steady frame rate row off, the frames are paced by 240 while a movie player has updated in the last quarter second, and the game's own limiter and its time step follow as they do at a cap of 240 (`host/movie_pace.h`, `host/nn_vi.c` `movie_pace_decide`, `pace_fps`, `realtime_step`): the game's movie player takes one picture an update at most and its updates follow the frame loop, so at 60 every frame that came late was a picture the decoder skipped. Game time stays real time; the limiter is put back where it was when the movie is over, and the log has a line at the movie's start and one at its end. The cap itself (the Steady row, the vsync event, the hand-off to RivaTuner or Reflex) does not move. Movies use more CPU and power with it. Not run in the game |
|
||||
| `A64_NO_VBYTES=1`, `A64_NO_VMOVES=1` | (Triforce, 11-21, the performance audit's LIFT-02; read when the game is translated, and in the lift key) The translator writes TBL with a one-register table and EXT as loops of single bytes through the stack, a 128-bit vector load as two halves and DUP by element as a loop, each followed by a 16-byte read of the register that cannot be forwarded from those stores. `nx2/fastvec.py` rewrites each on the lifted text as one instruction's helper (PSHUFB; PALIGNR or two shifts; one 16-byte load; one broadcast), the same bytes in the same registers (`tests/test_vbytes.py` runs every shape both ways). `A64_NO_VBYTES=1` keeps the translator's text for TBL and EXT, `A64_NO_VMOVES=1` for the loads and DUP. A build with them needs a hot profile of its own (`RX_PGO=gen`) |
|
||||
| `A64_DMB_LIGHT=1` | (Triforce, 11-22, the performance audit's LIFT-47, after Source B's; read when the game is translated, and in the lift key; off by default) The translator writes every DMB and DSB as `recomp_barrier()`, an out-of-line full fence. x86-64 keeps load-load, load-store and store-store order in hardware, so with this set the eight DMBs that ask only for those (ISHLD, ISHST and the OSH, NSH and full-system forms) are lifted as `A64_DMB_LDST()` (`nx2/insn.py` `dmb_light`), which is nothing but a barrier for the compiler on x86-64 and the full fence on any other host (`nx2/rtgen.py`). A full DMB, every DSB, ISB and STLR's locked store keep theirs. Unset, empty or `0`: the kit's text. `tests/test_dmb_light.py` runs every such word both ways, alone and between a store and a load. Not counted in this game's code and not measured in the game: how many of its barriers are of these kinds is not known, and what other threads see cannot be shown by a test on one thread. With it set the hot functions that hold such a DMB no longer match the shipped hot profile: such a build needs one of its own (`RX_PGO=gen`) |
|
||||
| `HOS_FMA_FAST=0`, `A64_NO_FMA_SOFT=1` | (Triforce, 11-22, the performance audit's LIFT-06, after Source A's; only in a build without FMA3, x86-64-v2: with FMA3 none of it is compiled) Without a hardware FMA every double-precision FMADD, and each single-precision one its binary64 fast path cannot prove, ran the translator's exact body, integer code of many words (about 180 ns a call and 13.7% of a core on an i7-3770, Source A's figures). `nx2/fma_soft.py` puts a short way out at the head of `recomp_fpe_fma64` and `recomp_fpe_fma32` for the plain case: default FPCR (FZ or not), three normal operands and a normal result, by an exact product and sum in binary64, rounded to odd, then rounded once, FPSR.IXC set when inexact; everything else goes on into the body. `tests/test_fma_soft.py` compares both bodies with it and without, value and every byte of the context. `HOS_FMA_FAST=0` (read once when the game runs): the exact bodies only, as before. `A64_NO_FMA_SOFT=1` (read when the game is translated, and in the lift key): the translator's runtime text as it was. Not measured in a game on a CPU without FMA3 |
|
||||
| `A64_NO_FMA_STEPS=1` | (Triforce, 11-22, the performance audit's LIFT-05, after Source A's; read when the game is translated, and in the lift key; only in a build with FMA3, x86-64-v3) The single-precision FRECPS and FRSQRTS steps (2 - a*b and (3 - a*b) / 2, the Newton-Raphson steps of a reciprocal and a reciprocal square root) were computed in binary64 on x86-64 (two widenings, a multiply, a subtraction, a narrowing) with a test for a binary32 midpoint, which went to the exact body. `nx2/fma_steps.py` gives their fast paths the guard the fused multiply-add's already had: with FMA3 one fused instruction, the step rounded once as on the console; the tests that decide whether the result is kept are unchanged (`tests/test_fma_steps.py` runs every form both ways and against the exact body). `A64_NO_FMA_STEPS=1`: the translator's text for the two steps. The compile define `-DA64_FPX_NO_FMA32` returns all three (FMADD/FMLA and the two steps) to the binary64 form. Source A measured the steps alone at 23% to 29% fewer cycles; not measured in the game, and how often this game runs them is not counted |
|
||||
| `A64_VECFP=1` | (Triforce, 11-22, the performance audit's LIFT-03, after Source A's; read when the game is translated, and in the lift key; off by default) The translator's passes turn straight FADD, FSUB and FMUL .4S and the .4S by-element multiplies into one SSE op; other float forms stay a helper call a lane or exact integer code a lane. With this set `nx2/vecfp.py` lifts each of them as `if (!a64_vfpx_q_<form>(c, ...)) { the C as before }`: the helper does the op in SSE and writes the register only when the scalar fast paths' rules prove the result is the console's with no new FPSR bit. `1`: every group; or a list of `elem` (FMUL, FMLA, FMLS .2S by element), `vec` (FMUL .2S; FMLA, FMLS and FDIV .2S and .4S; the multiply-adds need FMA3 and decline without it), `minmax` (FMAX, FMIN, FMAXNM, FMINNM: scalar S, .2S, .4S; kept unless a NaN or, under FZ, a subnormal is involved) and `fcvt` (FCVT S to D and D to S, FCVTL, FCVTL2, FCVTN). Unset, empty or `0`: the translator's text. `tests/test_vecfp.py` runs 137 guest words three ways (with it, without it, exact). Source A measured +3.5% to +5.1% fps where the game's update bounds the frame, for 3.7% more compile time; not measured in this game, which is why it is off. A build with it needs a hot profile of its own (`RX_PGO=gen`) |
|
||||
| `HOS_HEAP_COMMIT=1` | (Triforce, 11-21, the performance audit's MEM-09) On Windows the game's heap (~6.9 GB asked for at its start) is left reserved and committed as it is touched, 64 KB at a first touch, by the handler that commits pages nothing handed out; committed whole, all of it counted against RAM plus the page file, touched or not. A fault another thread's commit answered is tried again, a commit refused at Windows' commit limit is tried again for 5 s, and a file read or write reads each page of its buffer once before the kernel's call, which faults nothing in. The log says `heap: left reserved` and counts the heap's first touches. `1`: all of it committed at the start, as before; so it is in large pages (`HOS_LARGE_PAGES`) and on Linux (`host/heap_commit.h`, `mkw_glue.c` `commit_on_touch`, `hos_mem.c` `SetMemoryHeapSize`) |
|
||||
| `RX_VK_DMABUF_NVIDIA=1`, `RX_VK_NO_DMABUF=1`, `RX_VK_DMABUF_PIECE_MB=<n>` | (Linux) Where the game's memory is a memfd, each pool of it is offered to the driver as a dma-buf made by udmabuf, larger pools as several of at most udmabuf's limit bound into one sparse buffer; the log's `vk: guest memory as dma-bufs:` line says yes or why not. `RX_VK_NO_DMABUF=1`: host-pointer imports only. `RX_VK_DMABUF_PIECE_MB=<n>`: pieces of at most n MB. (Triforce, 11-22, the performance audit's OS-08, after Source A's; not yet run on Linux) NVIDIA's proprietary driver refuses every such dma-buf and the pool ends as a host-pointer import anyway, after a refused import each (up to 198 ms for one during a load) and a kernel message at each start: with that driver none is offered, `/dev/udmabuf` is not opened, and the line says `no (NVIDIA's driver refuses them: host pointers)` (`gpu/vk/dmabuf_gate.h`). NVK and RADV keep their dma-bufs. `RX_VK_DMABUF_NVIDIA=1`: offered to NVIDIA's driver too, as before |
|
||||
| `HOS_COMMIT_WAIT_MS=<ms>` | (Triforce, 11-22, the performance audit's OS-04, after Source A's and Source B's; 5000 unless set) How long a refusal at Windows' commit limit (RAM and the page file full, error 1455) is waited out, tried again every 50 ms: such a refusal often ends in moments, as a page file set to grow grows or commit is given back. The game's own commits waited so already (the row above); now the host's own tables do too (a failed allocation there ended the game at once: `host/host_alloc.h`, `hos_xmalloc` in `host/mkw_glue.c`), and the renderer's failed `new`, which was an uncaught `std::bad_alloc`: its new handler sleeps 50 ms and lets the allocation be tried again, up to this long a thread, but only while the system has less than 4 GiB of commit left (a `new` refused with more free is not the limit's and throws at once), and not for the few allocations that have their own answer to a refusal (`gpu/vk/new_wait.h`, `gpu/vk/vk_main.cpp` `new_refused`). The log has `refused ... made after N ms` for the first rescues. `0`: no wait anywhere, a refusal fails at once; 60000 at most |
|
||||
| `HOS_TEXELS_KEEP_CORE=1` | (Triforce, 11-21, the performance audit's THREAD-20) `nvnTextureReadTexels` and `nvnTextureWriteTexels` reach the back end, which waits for all the GPU work submitted and then for the replay's lock; the game calls them from its loading threads at an area's arrival and at boot. The calling thread gives its virtual core up for that call, as it does around a readback, so the game threads allowed only on that core do not wait with it. A write kept for a renderer not started yet never waits and keeps the core. `1`: kept, as before (`host/rx_backend.c` `rx_nvn_read_texels`, `rx_nvn_write_texels`) |
|
||||
| `HOS_LOG_SYNC=1`, `HOS_LOG_BATCH_MS=<ms>` | The log's lines are written by a thread of their own, not by the thread that logs: a write that blocks (a console, a busy disk) holds no game thread. The writer waits a little after a line and writes the lines of that time in one write (`HOS_LOG_BATCH_MS`, 250 unless set, at most 2000; 0: the lines there are at each wake); a queue half full goes out at once, and every way out of the game writes the queue first. `HOS_LOG_SYNC=1`: each line written by the thread that logs it. (Triforce, 11-22, the performance audit's THREAD-56, after Source A's; not yet run on Linux) The writer is Linux's and the Steam Deck's too now: there every `hos_log` wrote stderr in the calling game thread, its virtual core held, so `HOS_LOG_SYNC=1` is Linux as it was. And `nvnCommandBufferEndRecording`'s two lines (the sweep's, the 50,000-recording line) are written after the recordings' lock is released, the virtual core given up, on every system (`host/hos_thread.c` `log_queue`, `host/nvn_native.c`) |
|
||||
| `RX_VK_INVALIDATE_QUICK=1` | (Triforce, 11-22, the performance audit's THREAD-25, after Source A's; off unless set. Source A has it on; here it waits for a run in the game, as a wrong answer skips the wait a readback of GPU results needs, the exposure flashes' kind of fault) The game invalidates each shape's 64-byte occlusion slot, per view, and the host gives the calling thread's virtual core up before every such call and queues for it again after, though nearly none has anything to wait for. With `1` the back end is asked first, with no lock and no wait: a range with nothing to invalidate, or one below 512 GB with no fast fence poll's order ticket still to wait for, no live texture's storage in it, no texture the GPU wrote ever listed there and no write-back ever made into its pages, is one `invalidate` returns from at once, so the call is left out and the core kept. The two "ever" answers are bits a page that are only set, before their tables change (`gpu/vk/page_marks.h`); a page written back once has the call made for good. Source A measured Hyrule Field at 50.5 to 51.4 fps and its 1% low up by two to four frames a second, its busiest worker keeping the core 31,444 times against 2,604. Every 10 s a `vk: invalidates:` line counts the calls left out and made. With `RX_VK_LOG_INVALIDATE`, `RX_VK_LOG_READBACK` or `RX_VK_INVALIDATE_WAIT` set every call is made; the lab's knob `noinvq` makes them all in its phases (`gpu/vk/vk_replay.cpp` `invalidate_quick`, `host/rx_backend.c` `rx_nvn_invalidate`) |
|
||||
| `HOS_OPEN_KEEP_CORE=1` | (Triforce, 11-21, the performance audit's IO-24) nn::fs::OpenFile gives its virtual core up only around the host's own open, as before. The default gives it up before the path is worked out too: that reaches the button prompts' builder, which builds a file at its first open (a quarter of a second and more) while the other openers wait for it, and none of them holds a core meanwhile. Every return takes the core back before it answers the game (`host/nn_fs.c` OpenFile, `host/prompts.c` `hos_prompts_font_file`) |
|
||||
| `HOS_SHORT_SLEEP_TIMER=1`, `=0` | (Triforce, 11-21, the performance audit's OS-31) How sleeps under a millisecond wait. Not set: with 6 or fewer logical processors in the process's mask (Windows, one processor group) the game's own short sleeps wait on the high-resolution timer, which wakes about 0.5 ms late, and the host's own yield until their time; with more, all yield, as before. The game's idle job workers sleep 20 us and look again about 7,600 times a second, and a yielding sleeper keeps a processor busy. `1` (any value but 0, off, no, false): every short sleep on the timer, as the switch did before; `0`: every short sleep yields. (Triforce, 11-22, the performance audit's OS-32, after Source A's; not yet run on Linux) Off Windows the processors are not counted and, not set, every short sleep yields, as before; `HOS_SHORT_SLEEP_TIMER=game` puts the game's own short sleeps on the timer and leaves the host's yielding at any processor count, on any system: Source A's default off Windows (on Linux the timer wakes tens of microseconds late, not half a millisecond), which was never measured in the game by itself and is to be tried on a Steam Deck before `SHORT_SLEEP_ELSEWHERE` in `host/short_sleep.h` makes it what Linux does when the switch is not set. The log's `sleep:` line says which (`host/short_sleep.h`, `host/hos_thread.c` `sleep_for`) |
|
||||
| `HOS_DISCARD_KEEP_CORE=0`, `=1` | (Triforce, 11-22, the performance audit's OS-40, after Source A's; not set: as before, which is NOT Source A's default. It reverses a choice made here on purpose, changes when a game thread waits, and was not measured here) A discard of memory the game let go is milliseconds in the kernel for a region of some MB, and before it the lazy write-back's pages there are paid and pages a GPU import holds are zeroed; the game threads allowed only on the freeing thread's virtual core wait all the while. Not set: the core is given up for the discard's own kernel call, and only with the memory limit on (`HOS_MEM_LIMIT`), as before. `0`: a freed region's thread gives its core up before the whole of the discard and takes it back once, after the region is unlisted and never under the regions' lock; the discard's own call gives it up without the limit too (`FreeMemoryPages`). Source A at its Market: core waits of 50 ms and more 287 to 19, the longest 177 to 45 ms, frames unchanged; the freeing thread once waited 124 ms for its core back, in a load. `1`: the core kept through every discard, with the limit too. With `0` the log counts such frees and the longest take-back every 1,000 (`host/hos_mem.c` `discard_core`, `hos_region_free`, `discard_pages`) |
|
||||
| `HOS_SHORT_SLEEP_TIMER=1`, `=0` | (Triforce, 11-21, the performance audit's OS-31) How sleeps under a millisecond wait. Not set: with 6 or fewer logical processors in the process's mask (Windows, one processor group) the game's own short sleeps wait on the high-resolution timer, which wakes about 0.5 ms late, and the host's own yield until their time; with more, all yield, as before. The game's idle job workers sleep 20 us and look again about 7,600 times a second, and a yielding sleeper keeps a processor busy. `1` (any value but 0, off, no, false): every short sleep on the timer, as the switch did before; `0`: every short sleep yields. The log's `sleep:` line says which (`host/short_sleep.h`, `host/hos_thread.c` `sleep_for`) |
|
||||
| `HOS_SHORT_SLEEP_POLLERS=<n>`, `=auto` | (Triforce, 11-22, the performance audit's OS-33, after Source A's; off unless set: it changes how the game's threads wait and was not measured here) A cap on the game threads that yield through a sleep under a millisecond at once. Where those sleeps yield (more than 6 logical processors, `HOS_SHORT_SLEEP_TIMER` not set) every idle job worker keeps a processor busy; with the cap, a game thread that would be one more than `<n>` yielding waits on the high-resolution timer for that sleep instead, about 0.5 ms late. `auto`: a quarter of the process's logical processors (2 with 8, 4 with 16, 6 with 24), Source A's rule, whose provisional numbers are 2.7% less CPU a frame at the same frame rate with 16 processors, and 1.7% of the frame rate lost in a 24-thread run held to 2. The game's MainThread and Presentation Thread and the host's own sleeps are never counted and always yield. Not set, `0`, `off`: no limit, as before. The start's `sleep: at most` line says the cap, and with `HOS_SLEEP_LOG=1` a `sleep:` line every 5 s counts the sleeps that took the timer for it (`host/short_sleep.h` `short_sleep_pollers`, `short_sleep_poll_enter`, `host/hos_thread.c` `sleep_for`) |
|
||||
| `HOS_OS_YIELD=0` | (Triforce, 11-22, the performance audit's THREAD-41, after Source A's; off unless set: it changes how the game's threads wait and was not measured here) The game's `YieldThread` hands its virtual core to a waiting game thread of equal or better priority and then also gives the processor up (`SwitchToThread`, a call into the kernel, thousands of times a second from the game's job system). `0`: only the virtual core's hand-over, the console's yield; Windows still takes the processor at the end of a time slice. Source A, the game held to 4 processors: half of its six executors' CPU time was inside that call, and without it the mean frame was 0.26 to 0.34 ms shorter; with 16 processors no difference. The risk is a thread yielding in a loop for one that waits on its processor, on PCs with 2 to 4 logical processors. Not set or `1`: both, as before. With `HOS_VCORES=0` the processor's yield stays whatever this says; `SleepThread(0)` and the short sleeps keep theirs (`host/hos_thread.c` `os_yield`, `YieldThread`) |
|
||||
| `HOS_VCORE_SPIN_US=<us>`, `HOS_VCORE_SPIN_MAX=<n>` | (Triforce, on by default; `HOS_VCORE_SPIN_US=0` as before) A game thread that waits for a virtual core it asked a holder to give up spins for it, up to 250 us, before it sleeps (`host/hos_thread.c` `vc_spin`, after NX2navi's `core_take`): the holder gives the core up at its next checkpoint, mostly within microseconds, and the waiter then runs without an OS wake. Who gets a core does not change, only how soon. At most `HOS_VCORE_SPIN_MAX` threads spin at once and the rest sleep at once: by default a quarter of the logical processors beyond 8, at most 4 (none with 8 or fewer, 1 with 12, 2 with 16). The `vcores:` line (every 5 s) counts the waits that ended in the spin and those that slept, the time spun, the spins left out for the cap, and how soon a granted core ran after a spin and after a sleep; the start's `vcores: a waiter spins up to` line says what is in effect. A yield with no thread waiting for a core takes no lock (NX2navi's yield fast path) |
|
||||
| `HOS_VIDEO_ACQUIRE_TRIES=1`, `HOS_VIDEO_KEEP_CORE=1` | (Triforce, on by default; each `=1` as before) A movie's Acquire (`host/nn_video.c` `dec_acquire`) waits for a picture up to 100 ms by the clock, and not at all after a Stop or Flush with nothing submitted since: the old wait, 50 sleeps of 2 ms that each took 4-5 ms on Windows, ran out only after ~250 ms once a movie had stopped, a frame that long at every load from the title. It also decodes without the calling thread's virtual core, taken back only after the decoder's lock is let go, so other game threads run meanwhile. `HOS_VIDEO_ACQUIRE_TRIES=1`: the 50 sleeps; `HOS_VIDEO_KEEP_CORE=1`: the core held throughout |
|
||||
| `HOS_VCORE_WIDE=1` | (Triforce, 11-22, the performance audit's GAME-22, after Source B's; off unless set, never measured there or here) A game thread whose core mask names two or more cores takes any free virtual core, not only those. Source B's reason: the game's two main threads may run on two of three cores only, where per-core job workers of better priority preempt them while the other cores stand idle. A thread with a one-core mask, which guards the game's lock-free per-core data, or with no mask, stays where it was; no two threads ever run under one core number either way. The risk is the one `HOS_VCORE_ANY=1` (every thread on any core, which crashed) has, for fewer threads: a thread that reads its core number, blocks and goes on under another. The log's `vcores: ... asks for ideal core ... and core mask` lines name every thread whose mask has two or more cores (all masks when the switch is set to anything): with no such line the switch changes nothing (`host/hos_thread.c` `vc_allowed`, `core_mask_note`) |
|
||||
| `RX_VK_HELPER_SPIN_US=<us>` | (Triforce, on by default; `=0` as before) The parallel replay's spins (`gpu/vk/helper_spin.h`, after NX2navi's replay workers): a helper thread with no segment to record spins up to 100 us for the next before it sleeps, and the replay thread spins as long for a segment a helper records before it sleeps for it. The frame statistics' `its spins` line, after the parallel replay's parts, says how often each ended in the spin or slept and the time spun |
|
||||
| `HOS_X3D=0` | (Windows) The game's threads and the replay's core are not kept on the die with the largest L3 cache. By default they are (the replay's core only where one is kept there: `HOS_RESERVE_CORE`), on a processor whose L3 caches differ in size and whose largest serves 8 or more cores (AMD's two-die X3D parts: a 7950X3D's or 9950X3D's 3D V-Cache die; `host/hos_x3d.h`), and the log's `cpu: logical processors ... share the largest L3 cache` line says so. On every other processor nothing changes and the log has no such line |
|
||||
| `HOS_X3D=0` | (Windows) The game's threads and the replay's core are not kept on the die with the largest L3 cache. By default they are, on a processor whose L3 caches differ in size and whose largest serves 8 or more cores (AMD's two-die X3D parts: a 7950X3D's or 9950X3D's 3D V-Cache die; `host/hos_x3d.h`), and the log's `cpu: logical processors ... share the largest L3 cache` line says so. On every other processor nothing changes and the log has no such line |
|
||||
| `HOS_SIM_CPU=<cores>/<threads>` | (Triforce, 11-22, the performance audit's OS-49, after Source B's; a lab switch, off unless set; Windows) A PC with fewer cores, simulated: the process is held to `<cores>` of the PC's physical cores (the die with the largest L3 first, then the fastest class, then the last ones, so that the replay's kept core is among them; one core always stays out; `host/hos_sim_cpu.h`), set before any thread, and the renderer sizes its pools and thread counts by `<threads>` (`gpu/vk/cpu_count.h`: an affinity mask alone does not change `hardware_concurrency`). `6/12` and `4/8` play as those PCs' pools do; `6` alone is 6/6. The log says `cpu: HOS_SIM_CPU=` with the mask, or that it was not applied (then the variable is cleared and nothing changes). Not run in the game. `tests/test_sim_cores.py` |
|
||||
| `RX_VK_SIM_GPU_SLOW=<factor>` | (Triforce, 11-22, the performance audit's OS-49, after Source B's; a lab switch, off unless set) A slower GPU, simulated (`gpu/vk/sim_gpu.h`): for each ms of work the recordings measure, (factor - 1) ms more, from over 1 to 10 (`2.5` is read). A one-invocation compute loop (`shaders/sim_gpu_burn.comp`) ends the replay's own recordings between full barriers, inside the GPU time they are measured over, so the frame's GPU time and Resolution Auto see the slower card; a third timestamp a recording measures what the burn took and the difference is carried (owed time held between -50 and 100 ms, burns of 1 to 16 ms, the loop's time calibrated 0.8/0.2). A line every 10 s: work, added, the factor reached, dropped. It repeats the fast card's relative answer only: no bandwidth, driver or upscaler cost. Not run in the game. `tests/test_sim_cores.py` |
|
||||
| `HOS_POWER_THROTTLING=1` | (Windows) Windows' power throttling of a window not in front left as it is (for A/B runs). By default every run, the shader preparation's too, opts out of it at the start: full speed, not the efficiency speed (EcoQoS) Windows 11 gives such a process, and the 1 ms timer resolution kept, which Windows 11 may otherwise ignore for it (Windows 10: full speed only). The log's `power:` line says what Windows took |
|
||||
| `HOS_HOST_ZSTD=1` or `2` | The game's files (`.zs`) decoded by the host's zstd (`third_party/zstd`) instead of the game's own translated decoder; off unless set, and nobody has played with it on. `1`: the host decodes what `host/host_zstd.h` takes (whole buffers, and the loading threads' streams with their content size and room for it), the game's code the rest, errors included. `2`: check, the game's code decodes everything as before and the host beside it, and the log's `zstd check: ... MISMATCH` lines name every difference (its `zstd:` lines count what was compared): the way to try it before `1`. Game build `e0f3ccfa` only. The lift needs both of its calls (`nx2/oot_patches.py` `patch_host_zstd`): a build log that says `the host's zstd decoder's calls were found at 1 of 2 places` has one only, and the switch then covers only that function |
|
||||
| `HOS_HOST_ZSTD=0` or `2`, `HOS_HOST_ZSTD_AWAY=0/1/2` | The game's files (`.zs`) are decoded by the host's zstd (`third_party/zstd`) instead of the game's own translated decoder: the host decodes what `host/host_zstd.h` takes (whole buffers, and the loading threads' streams with their content size and room for it), the game's code the rest, errors included. (Triforce, 11-21, the performance audit's IO-01) On when not set: the host is given the content's exact size to write into (libzstd may park literals in spare room past a block, where the game's decoder never writes), and check mode ran clean in the game. `0`: the game's own decoder for everything, as before. `2`: check, the game's code decodes everything and the host beside it, and the log's `zstd check: ... MISMATCH` and `wrote past the end` lines name every difference (its `zstd:` lines count what was compared). `HOS_HOST_ZSTD_AWAY`: which decodes give their virtual core up: `1` (not set) whole buffers with 128 KB of input or room, streams never; `0` none; `2` whole buffers and stream feeds from 64 KB, as it was. Game build `e0f3ccfa` only. The lift needs both of its calls (`nx2/oot_patches.py` `patch_host_zstd`): a build log that says `the host's zstd decoder's calls were found at 1 of 2 places` has one only, and the switch then covers only that function |
|
||||
|
||||
### Building
|
||||
|
||||
@@ -272,18 +440,32 @@ A build reads and writes tens of gigabytes. When the game folder or the build fi
|
||||
| Switch | What it does |
|
||||
|---|---|
|
||||
| `HOOKSHOT_JOBS=<n>` (or `--jobs`) | Compilers at once (default one per CPU thread, each started when the free memory holds it; `HOOKSHOT_MEM_GATE=0` turns that check off) |
|
||||
| `HOOKSHOT_LOW_PRIORITY=1` | (Triforce, 11-22, the performance audit's OS-57) (Windows) The builders start the build tools (`make_game.py` and everything it runs) below normal priority, as every build was before. The default is normal priority: Source A reports, without a measurement, that below normal Windows kept the steps that are one process (the read, the lift) on a hybrid Intel CPU's efficiency cores while the performance cores idled, and a first build took over an hour. The compilers then compete with the desktop like any program (`HOOKSHOT_JOBS` bounds them). Read by Triforce Setup (`setup/Setup.cs`), the launcher's build (`launcher/Logic/Build/BuildRunner.cs`) and the two older builders (`builder/HookshotBuilder/Runner.cs`, `builder/py/hookshot_builder/core.py` `build_priority`); Linux sets no nice value either way. The shaders' preparation at a build keeps its workers below normal in the normal-class process (`gpu/vk/vk_draw.cpp` `prepare_priority`) |
|
||||
| `HOOKSHOT_LIFT_JOBS=<n>` | Processes that write the lifted C. Forked on Linux and macOS: default the cores, at most 16, one per 2 GB of free memory. Spawned on Windows (`nx2/emit_pool.py`), where they also cut the big chunks and share the page marks: default half the processors, at most 8, one per GB of free memory. `1`: one process, on every system; the C is the same whatever the count |
|
||||
| `HOOKSHOT_KEEP_BUILD_FILES=1` | Keeps the lifted C and the objects after a build, so that the next one compiles only what changed |
|
||||
| `HOOKSHOT_LIFTED_C_REGEX=1` | (Triforce, 11-22, the performance audit's IO-40) The lifted functions' definitions are found by the patterns' own `finditer`, tried at every line of the lifted C, as before. By default `nx2/lifted_c.py`'s `definitions` and `noted_starts` jump from one `"\nvoid f_"` to the next and try the pattern only there, for `build.py`'s memory estimate, `chunks.py`'s costs and cuts and `split_hot.py`'s pieces: the same matches (`tests/test_lifted_c_scan.py`), so the same files. `lifted_c.py`, `chunks.py` and `split_hot.py` are in the lift key: the first build with this change translates the game once more. The other half of the entry, translating while the package's romfs is still being extracted, is not here |
|
||||
| `HOOKSHOT_KEEP_LIFT=0` | (Triforce, 11-22, the performance audit's LIFT-27) The translated game is kept as little as before: its key (what decides whether a build translates the game again) hashes every `A64_`, `OOT_` and `RX_` variable and the folders' paths, and `nx2/released_translation_stamp.json`, and any failed build forgets it. By default the key takes of the environment only what shapes the C, the lifter's `A64_` switches and `RX_TARGET` (`tests/test_lift_key_env.py` holds the lift's files to that), and leaves out the release's shader translation stamp, which `build.py` alone reads; and a build that failed in its compile, only in the program's own files (`host/`, the renderers) and in nothing the lift wrote, keeps the key once, so that the retry compiles the rest without translating the game again (a second such failure in a row forgets it, as a generated header cut short fails the program's own files too). The key changes once with this, and the two values of the switch have different keys. Not here yet: keeping the translated game after a player's finished build, which is the owner's decision (`nx2/make_game.py` `lift_key`, `keep_lift_after_failure`) |
|
||||
| `HOOKSHOT_EARLY_COMPILE=0` | (Windows) Not compiled beside the lift: libopus and the two renderers, which need no translated code. By default `make_game.py` starts `build.py` with `RX_EARLY=1` for them while the game is translated (the lift's own processes take at most half the processors there), and the build proper finds their objects made |
|
||||
| `HOOKSHOT_MEM_GIANT=1` or `0` | Whether the memory gate counts a function of 1.2 MB or more by the square of its size (a chunk that is one 5 MB function takes 6.2 GB, not the 1.9 GB it is counted at otherwise). By default only on a PC with less than 14 GB free when the compile starts: with more, counting the giants in full halves the compilers running at once for no need |
|
||||
| `HOOKSHOT_MEM_LOG=1` | For each file compiled, `@@mem <file> <peak MB> <counted MB> <seconds>`: the most memory its compiler was seen holding, beside what the memory gate counted it at (`mem_need` in `nx2/build.py`). For fitting the gate after a change to the lift or the compiler |
|
||||
| `HOOKSHOT_PROMPTS_FOLDER_KEY=0` | (Triforce, 11-21, the performance audit's IO-43) A game built from romfs and exefs folders has its button prompts drawn at every build and update, as before. The default keeps them when nothing they are made from changed: with no unpack stamp to tell the dump by, the key is the content of the game's files the tool reads (the font, the textures, the layouts, the camera's pack, the size table, the dictionaries and every language's messages). Every game's key also holds `host/prompts.c` and the tools' release (`nx2/make_game.py` `prompts_key`, `prompt_game_files`) |
|
||||
| `HOOKSHOT_PROMPTS_WIDEN_EACH=1` | (Triforce, 11-22, the performance audit's IO-42) The button prompts' tool widens the "lines that stay" image (a 9 by 9 maximum, what a leader line pays to cross them) at every route, as before. By default the widened array is kept for the last image asked, and every route of one line is given the same image: 4 or 5 widenings a controller face where there were 35 or 37, each a filter over a 2-megapixel image (the five faces' lines on blank stand-in images: 21 s where they took 42). The lines drawn are the same (`nx2/prompt_assets.py` `guide_widened`) |
|
||||
| `HOOKSHOT_DUMP_LINKS_LSTAT=1` | (Triforce, 11-21, the performance audit's IO-41) A build from romfs and exefs folders checks them for links with an `os.lstat` for every entry, as before. The default reads each entry's kind and attributes from the folder's own listing (`os.scandir`), 1.3 to 1.5 s where the one-by-one check took 36 to 49 s over the game's 186,583 files, and stops the build at a folder it cannot list, which the walk passed over. The copy that follows makes each folder once and lets `os.link` say that a file is there already (`nx2/make_game.py` `refuse_dump_links`, `link_or_copy`) |
|
||||
| `HOOKSHOT_NUP_IN_PLACE=0` | (Triforce, 11-22, the performance audit's IO-51) A `.nup` package's unpack writes each file to `<name>.part` and renames it, and resolves the output folder and looks at every folder above the file for every file, as before. The default writes each file straight to its name (one `os.lstat`, then a create that fails if anything is there) and looks at each folder once: under a virus scanner on NTFS the temporary's create and rename and the repeated looks were most of a small file's cost over the game's 186,583 files. A file that is there whole is kept, one of another size is unlinked and written again, one whose write fails is deleted; the files written are the same (`nx2/nup.py` `extract`, `Destination`) |
|
||||
| `HOOKSHOT_FINISH_COPY_ALL=1` | (Triforce, 11-22, the performance audit's IO-45) The end of a build copies every file into the game folder as `<name>.new` and swaps it in, as before, and keeps no note. By default the finish notes in the game folder (`.triforce_installed.json`), for each file it installed, the SHA-1 of the source and the installed copy's size, modification time, file number and mode, and the next finish passes over a file whose source hashes the same and whose installed copy is still as noted, without reading it: `image.bin` and the prebuilt DLLs at an update that did not change them. The exe and the renderer are linked again at every build with the link's time in them, so they are still copied. A file not noted, changed by hand, on a file system without file numbers (FAT, exFAT), or under a note that does not read is copied; deleting the note copies everything (`nx2/make_game.py` `INSTALLED_NOTE`, `installed_same`) |
|
||||
| `HOOKSHOT_LINK_REPRO=1` | (Triforce, 11-22, the performance audit's IO-45) (Windows) The game's exe and the renderer are linked with `/Brepro`: lld writes a hash of the file where it otherwise writes the time of the link, so two links of the same objects are the same bytes, and the finish above passes an unchanged exe over instead of copying its 460 MB. Off unless set: it changes the bytes of every linked file once (`nx2/build.py` `repro_link`) |
|
||||
| `HOOKSHOT_MINGW=<dir>`, `HOOKSHOT_MSVC=1` | The llvm-mingw to build with; the Visual Studio route instead |
|
||||
| `HOOKSHOT_WORK_LOCK=0` | (Triforce, 11-22, the performance audit's IO-47) `make_game.py` takes no lock on its work folder, as before. By default it holds an OS lock on `<work>/make_game.lock` for as long as it runs (`msvcrt.locking` on Windows, `flock` elsewhere), taken after an earlier build left running is stopped and before the stale objects go: a second build on the same folder stops at once with the first one's process id instead of compiling the same objects again and racing on the staged game folder, which nothing prevented on Linux (two builders, a builder beside the launcher, `--cli`). The lock ends with its process, so a build that crashed never blocks the next; an error other than "held by another" is said and the build runs without the lock (`nx2/make_game.py` `lock_work`) |
|
||||
| `HOOKSHOT_SINGLE_INSTANCE=0` | (Triforce) Hookshot Builder takes no lock on its build tools, as before. By default a second builder for the same tools folder (`builder/HookshotBuilder/Instance.cs`, named after `Tools.Root`), its `--cli` included, waits up to 5 s for one that is ending, then says so and ends: two of them built into one work folder and stopped each other's build. Triforce Setup has its own lock (`setup/Guard.cs` `Instance`) |
|
||||
| `TRIFORCE_LEGACY_PATHS=1` | (Triforce) Triforce Setup keeps .NET Framework's legacy path checks, which refuse paths of 260 characters and more whatever its manifest says (an exe csc builds is taken as written for .NET 4.0). By default `setup/Setup.cs` `Main` sets the two switches 4.6.2 defaults to (`Switch.System.IO.UseLegacyPathHandling`, `Switch.System.IO.BlockLongPaths`) before any path is used, so that with Windows' own LongPathsEnabled on Setup reads and writes deep paths |
|
||||
| `HOOKSHOT_SEGMENT_HEAP=0` | (Triforce, Windows; on by default since 11-22: the lab's play A/B, 81.4 against 80.6 fps) The exe's manifest asks for Windows' segment heap (`heapType SegmentHeap`, Windows 10 2004 and newer) for the whole process, its DLLs and the graphics driver too, in place of the NT heap, whose lock AMD's driver's compile threads waited on through the shader preparation (`nx2/win_manifest.py`, `tests/test_segment_heap.py`). The heap is fixed when the process starts: a build with it and one without are the two arms. `0`: the NT heap, as before. The log's `the shaders' preparation runs on` line names the process heap (`segment` or `NT`) |
|
||||
| `RX_CPM=<dir>`, `WGPU_NATIVE=<dir>` | The CPM cache (Vulkan and SPIR-V headers, VMA, FFmpeg) and wgpu-native |
|
||||
| `RX_TARGET=windows` | On Linux: the Windows game, with llvm-mingw's Linux build in `HOOKSHOT_MINGW` |
|
||||
| `RX_RELEASE=1` | A release build (`make_game.py` sets it): no console window, the shaders prepared before the title |
|
||||
| `RX_VK_PGO=gen`, `=<file>`, `=0`; `RX_VK_PGO_FILE=<path>` | (Triforce, 11-21, the performance audit's LIFT-10) A play profile for the renderer's own code (`gpu/vk/*.cpp`; not the vendored recompiler, ImGui or zstd). `gen`: a build whose renderer counts its branches; run it with `RX_VK_PGO_FILE=<path>`, make `<path>.reset` once the scene to record is loaded and `<path>.dump` at its end, then `llvm-profdata merge -o work\triforce_vk.profdata <path>`. `<file>`: built with that profile (its contents are in the object keys, its path is not). Not set: `make_game.py` passes `work\triforce_vk.profdata` when the tools have one and the compiler can read it; `0`: none. A profile from another version of the renderer is taken function by function, the changed ones built without it. Record it again for each release, and compare against `RX_VK_PGO=0` before shipping one (`nx2/build.py` `vk_pgo_flags`, `host/pgo_rt.c`) |
|
||||
| `RX_PGO=gen` or `RX_PGO=<file>` | The hot code counting its branches for a profile, or built with one (`make_game.py` passes the shipped profile) |
|
||||
| `A64_HOT_STICKY=0` | (Triforce, 11-22, the performance audit's LIFT-30, after Source A's; read when the game is translated, and in the lift key) `nx2/split_hot.py` deals the hot functions out afresh and gives every hot piece code_hot.c's whole preamble, as before. By default `<work>\image\hot_pieces.txt` keeps each hot function's piece: the next translation leaves the functions it knows where they were and puts a new one in the piece it shares the most calls with, else in the cheapest, unless that makes the costliest piece more than 1.15 times a fresh split's (then the split is the fresh one); and each piece keeps only the declarations of `f_` and `hos_` names it uses. An update that changes a few hot functions then compiles one or two hot pieces of about ten MB again, not up to eight. The functions' text is the same either way, and the hot profile goes by function name, so it fits both. The file is not in the lift key (`tests/test_sticky_hot_pieces.py`) |
|
||||
| `RX_COLD_OPT=O2` or `=<file>`, `RX_COLD_PART_MB=<n>` | (Triforce, 11-22, the performance audit's LIFT-17, after Source A's; opt-in) The hot pieces are compiled at -O2 with the play profile and every other lifted chunk at -O1. `RX_COLD_OPT=O2`: every other lifted chunk at -O2 too; `=<file>`: only the chunks the file lists, one file name a line (`code_012.c`). Unset, empty or `O1`: as before. Each -O2 chunk is compiled as parts of `RX_COLD_PART_MB` MB by the lift's own estimate (6 when unset; `0`: no cut), cut only where a function begins and written under `<build>/split` with a key file a chunk, so a second build writes nothing (`nx2/cold_parts.py`, `tests/test_chunk_parts.py`): -O2's time grows with the square of a function's size. The lifted files themselves are not touched. Source A's figures: +4.4% and +5.5% fps where the game's update bounds the frame, for about twice the lifted compile's processor time (23 minutes against 5 without the cut); not built or measured with this game. The names begin with `RX_`, so setting them translates the game again once |
|
||||
| `RX_MARCH=<level>` | The CPU level to build for (default this PC's: `x86-64-v3`, else `x86-64-v2`, else `x86-64`) |
|
||||
| `RX_VK_ONLY=1` | Only the Vulkan back end, with no lift |
|
||||
| `OOT_WORK`, `OOT_DUMP`, `OOT_EXEFS`, `OOT_ROMFS` | The work folder and the dump's folders, over `work/dump.txt` |
|
||||
@@ -346,22 +528,24 @@ no other file.
|
||||
|
||||
`hookshot_options.ini`, in the game folder, holds the Insert menu's rows as `<key>=<number>`: the row's name in lower
|
||||
case with `_` for spaces (`frame_generation=2`, `invert_camera_x=1`), except Output resolution, which is `output_res`.
|
||||
`gpu/vk/vk_menu.cpp` writes the whole file at every change (`save`; (Triforce) merged by key with a change made outside the game meanwhile, and written whole: `RX_VK_OPTIONS_MERGE` above), with `options_version=4`,
|
||||
`gpu/vk/vk_menu.cpp` writes the whole file at every change (`save`; (Triforce) merged by key with a change made outside the game meanwhile, and written whole: `RX_VK_OPTIONS_MERGE` above), with `options_version=8`,
|
||||
`microphone_device=<name>` when a microphone is chosen by name, and the controls (`pad_<button>` and `key_<button>`:
|
||||
the README's [Controls](../readme.md#controls)). A value outside a row's range is clamped when it is read. Where the
|
||||
number is not the obvious one:
|
||||
|
||||
| Key | Values |
|
||||
|---|---|
|
||||
| `quality_preset` | 0 Custom, 1 Minimum (6GB), 2 Low (8GB), 3 Balanced (12GB), 4 High (16GB), 5 Ultra (20GB+); each sets Texture detail: Low, Reduced, Full, Full, Full |
|
||||
| `gpu_device` | 0 Auto, n the n-th card with Vulkan 1.3 as the row lists them |
|
||||
| `frame_generation` | 0 Off, 1 Auto, 2 to 8 the multiplier, 9 AMD FSR 4 (the made frame by AMD's frame generation library, `gpu/vk/vk_fsr4.cpp` `fsr4fg`; where that cannot run the value stays in the file and the row shows and runs 2x: `gpu/vk/framegen_rows.h`) |
|
||||
| `frame_generation` | 0 Off, 1 Auto, 2 to 8 the multiplier, 9 AMD FSR frame generation (the made frame by AMD's frame generation library, FSR 4's or FSR 3.1's by the card, with the picture without the HUD; paused with HDR Native or RenoDX's RGBA16F scene, where the renderer's own makes the frame as at 2x: `gpu/vk/vk_fsr4.cpp` `fsr4fg`; where that cannot run the value stays in the file and the row shows and runs 2x: `gpu/vk/framegen_rows.h`) |
|
||||
| `dlss_frame_generation` | 0 Off, 1 2x, 2 3x, 3 4x: NVIDIA DLSS frame generation, the Frame generation row's NVIDIA DLSS values (`gpu/vk/merged_rows.h`; read at the start, `gpu/vk/vk_dlssg.cpp`). The row sets `frame_generation` to 0 with it |
|
||||
| `frame_rate_cap` | 0 60, 1 90, 2 120, 3 144, 4 165, 5 240, 6 the monitor's refresh rate; -1 45, -2 40, -3 30 |
|
||||
| `frame_pacing` | 0 Off, 1 frames on an even line. With `steady_frame_rate`, the Frame pacing row (`gpu/vk/merged_rows.h`): Off is 0 and 0, Even 1 and 0, Steady (any rate) 1 and 1, Steady (refresh steps) 1 and 2 |
|
||||
| `steady_frame_rate` | 0 Off, 1 any rate (the cap, then 200, 180, 160, 144, 120, 110, 100, 90, 80, 72, 66, 60, 55, 50, 45, 40, 36, 30 under it), 2 whole divisions of the display's refresh rate under the cap, from 30 up (`host/pace_steady.h`) |
|
||||
| `resolution` | 0 Auto, 1 100%, 2 75%, 3 67%, 4 50% |
|
||||
| `output_res` | 0 2048x1152, 1 2560x1440, 2 3840x2160, 3 1920x1080, 4 5120x1440, 5 5120x2880 |
|
||||
| `resolution` | 0 Auto, 1 100%, 2 75%, 3 67%, 4 50%, 5 58%, 6 33% (with DLSS and FSR: 3 Quality, 5 Balanced, 4 Performance, 6 Ultra Performance; their Native (100%) is `dlss` 2, 5 or 6) |
|
||||
| `output_res` | 0 2048x1152, 1 2560x1440, 2 3840x2160, 3 1920x1080, 4 5120x1440, 5 5120x2880, 6 5120x2160, 7 1536x864 (the handheld profile; before `options_version` 8 it was `handheld_profile=1`, read as 7) |
|
||||
| `ultrawide` | 0 16:9, 1 16:10, 2 21:9, 3 32:9 (before `options_version` 6, 1 was the monitor's shape: read as the nearest of the four, `gpu/vk/ultrawide_rows.h`) |
|
||||
| `hdr` | 0 Off, 1 Expanded, 2 Native (the game's own) |
|
||||
| `hdr`, `renodx_hdr` | the HDR row (`gpu/vk/merged_rows.h`): `hdr` 0 Off, 1 Expanded, 2 Native (the game's own); `renodx_hdr` 1 with `hdr` 2 is Native + RenoDX |
|
||||
| `nvidia_reflex`, `amd_anti-lag_2` | the Low latency row by the card's maker: 0 Off, 1 On, 2 On + Boost (NVIDIA alone) |
|
||||
| `hdr_paper_white`, `hdr_peak_brightness` | nits: 80 to 400, and 400 to 10,000 |
|
||||
| `renodx_tonemapper` | 0 Vanilla, 1 PsychoV35, 2 RenoDRT |
|
||||
| `renodx_gamma_correction` | 0 Off, 1 2.2, 2 BT.1886 (2.4) |
|
||||
@@ -369,16 +553,14 @@ number is not the obvious one:
|
||||
| `renodx_tone_slope`, `renodx_highlight_saturation` | 0 to 100, 50 unchanged: the first PsychoV35's, the second RenoDRT's |
|
||||
| `renodx_blowout`, `renodx_flare` | 0 to 100, 0 none: RenoDRT's |
|
||||
| `renodx_hue_clip`, `renodx_hue_correction`, `renodx_color_grading` | percent, 0 to 100: 50, 100 and 100 out of the box; the first PsychoV35's, the others RenoDRT's |
|
||||
| `dlss` | the Upscaler: 0 the game's own, 1 NVIDIA DLSS, 2 NVIDIA DLAA, 3 AMD FSR 3.1, 4 AMD FSR 4, 5 AMD FSR 4 Native AA, 6 AMD FSR 3.1 Native AA (the row shows it after FSR 3.1) |
|
||||
| `upscaling` | 0 Off, 1 Catmull-Rom, 2 Lanczos |
|
||||
| `dlss` | the Upscaler: 0 the game's own, 1 NVIDIA DLSS, 2 NVIDIA DLAA, 3 AMD FSR 3.1, 4 AMD FSR 4, 5 AMD FSR 4 Native AA, 6 AMD FSR 3.1 Native AA. The row names the engine; 2, 5 and 6 are its Native (100%) on the Render resolution row (`gpu/vk/upscaler_rows.h`) |
|
||||
| `anti-aliasing` | 0 the game's own SMAA, 1 Off, 2 FXAA, 3 SMAA Ultra |
|
||||
| `texture_detail` | 0 Automatic, 1 Full, 2 Reduced, 3 Low |
|
||||
| `fps_counter` | 0 Off, 1 On, 2 Full (NX2navi's full performance overlay in the counter's place: `vk_menu.cpp` `draw_perf`, the frame times and the figures per frame `gpu/vk/perf_stats.h`, the machine's numbers sampled twice a second on a thread of their own `gpu/vk/perf_machine.cpp`) |
|
||||
| `opaque_textures_as_bc1` | 0 Off, 1 On |
|
||||
| `sharpness`, `rumble_strength`, `motion_sensitivity_x`, `motion_sensitivity_y` | percent |
|
||||
| `mouse_sensitivity` | hundredths: 100 is 1.00 |
|
||||
| `stick_dead_zone` | 0 Default (24%), 1 5%, 2 10%, 3 15%, 4 20%, 5 30% |
|
||||
| `left_stick_dead_zone`, `right_stick_dead_zone` | -1 As Stick dead zone, 0 to 50 percent |
|
||||
| `left_stick_dead_zone`, `right_stick_dead_zone` | -1 Default (XInput's ~24%), 0 to 50 percent (before `options_version` 8 a `stick_dead_zone` of 1 to 5, 5, 10, 15, 20 or 30% for both sticks, is read into each stick's own where it had none) |
|
||||
| `vibration_curve` | hundredths, 20 to 150: the power on the motors' rumble, 100 is 1.00 (none) |
|
||||
| `walk_key` | 0 Off, 1 Caps Lock, 2 Shift, 3 Ctrl, 4 Tab |
|
||||
| `walk_scale` | hundredths, 20 to 90: 51 is 0.51 of the stick's travel |
|
||||
@@ -389,7 +571,7 @@ number is not the obvious one:
|
||||
| `microphone` | 0 Off, 1 Default, 2 and up a microphone (the name in `microphone_device` decides which) |
|
||||
| `mouse_camera` | 0 As the stick, 1 Native |
|
||||
| `layout_preset` | 0 Nintendo, 1 Xbox / PC, 2 Swap Face, 3 Custom |
|
||||
| `button_prompts` | 0 Auto (the controller there at the start; none: the keyboard and mouse), 1 Switch, 2 Xbox, 3 PlayStation 4, 4 PlayStation 5, 5 Steam Deck, 6 Keyboard & mouse (`host/prompts.c`, `nx2/prompt_keys.py`) |
|
||||
| `button_prompts` | 0 Auto (the controller there at the start, XInput's without a name the Xbox's; none: the device used last in the run before, `<user>/prompts_auto.txt`, else the keyboard and mouse), 1 Switch, 2 Xbox, 3 PlayStation 4, 4 PlayStation 5, 5 Steam Deck, 6 Keyboard & mouse (`host/prompts.c`, `nx2/prompt_keys.py`) |
|
||||
| `replay_helper_threads` | 0 Off, 1 to 7 the parallel replay tried on 2 to 8 threads, 8 Automatic (the default; the Debug tab). A file that says 0 stays Off: delete the line, or choose Automatic on the Debug tab, for the default |
|
||||
|
||||
The Game language row is not in this file: its choice is the code line of `language.txt` in the game folder, which the
|
||||
@@ -397,8 +579,18 @@ menu rewrites in place (`gpu/vk/game_language.h`: the code alone on that line, t
|
||||
code the file itself names) and the host reads at the start (`host/nn_applet.c`). Nor are the Mod cheats rows: which
|
||||
of a mod's cheats are on is the host's to keep, in `triforce_cheats.txt` (*Mods: code patches and cheats* above).
|
||||
|
||||
(Triforce) `options_version=8` grouped the rows and merged those that chose one thing twice (`gpu/vk/merged_rows.h`; the
|
||||
436f9ac-based builds wrote 7 for it, which v0.5.1 had already given to Frame pacing's default: its 7 still has the old rows'
|
||||
lines, so a file before 8 is moved, and one of those builds' 7, without them, keeps what it has). A file
|
||||
from before keeps its values; these lines are read once and not written again, their rows' jobs done otherwise:
|
||||
`quality_preset` (the textures' and the mirrors' memory budgets are the card's own, from its video memory), `upscaling`
|
||||
(the window's filter follows the sizes: `gpu/vk/upscaler_rows.h` `auto_filter`, AMD FSR 1 when the picture is enlarged, the
|
||||
plain copy otherwise and always with HDR Native), `reflex_frame_limit` (off, the old default, until Reflex holding the cap
|
||||
with DLSS frame generation has been played: `RX_VK_REFLEX_LIMIT=1` for a run), `handheld_profile` (an `output_res`) and `stick_dead_zone` (each
|
||||
stick's own).
|
||||
|
||||
The other rows are 0 Off and 1 On. Some are read at the start, before the menu exists, by the code that needs them:
|
||||
`handheld_profile` and `output_res` (`host/nn_applet.c`), `ultrawide` (`host/hos_main.c`), `frame_rate_cap`
|
||||
`output_res` (`host/nn_applet.c`; 7 is the handheld profile), `ultrawide` (`host/hos_main.c`), `frame_rate_cap`
|
||||
(`host/nn_vi.c`; the monitor's rate is the display's the window opens on, rounded, 30 to 240, and 60 when it cannot be read), `robust_buffers`
|
||||
(`gpu/vk/vk_main.cpp`), `texture_detail` (`gpu/vk/vk_texture.cpp`, at the first texture) and the controls (`host/nn_hid.c`).
|
||||
|
||||
|
||||
67
docs/launcher-color-scheme.md
Normal file
67
docs/launcher-color-scheme.md
Normal file
@@ -0,0 +1,67 @@
|
||||
# The launcher's color scheme
|
||||
|
||||
Settings > Launcher has a **Color scheme** row under Music and Sounds. Its value is a diamond swatch and the hex
|
||||
(`#E0B23E`). Selecting it (mouse, Enter, A) drops a picker open under the row, with the launcher's own .25 s height
|
||||
transition; selecting the row again, or Escape / B, closes it. The picker has a saturation / brightness square, a hue bar
|
||||
(one of the launcher's sliders), **Hex**, **R**, **G** and **B** fields checked as typed (six hex digits with or without
|
||||
`#`, whole numbers 0-255; a wrong value gets a red border and a line saying what is allowed), eight ready colors with
|
||||
Triforce gold first, and **Reset to gold**.
|
||||
|
||||
The color takes the place of the gold everywhere the launcher uses it: text and links, tab underlines, section titles,
|
||||
sliders and their diamonds, borders, hairlines, outlines, glows, the focus ring, the build line and the wordmark. The
|
||||
polished bars (Play, "Find my best settings", "Build the game", Apply, ...) keep their gradient, inner hairline, sheen and
|
||||
emboss, all made from the new color, and their text takes dark or light ink, whichever has more contrast. Triforce gold
|
||||
gives the look exactly as it was: with it the page sets nothing, and the stylesheets' own values draw it.
|
||||
|
||||
Two limits keep any color usable, both far from gold:
|
||||
|
||||
- **Text and lines never go too dark.** What is drawn in the color on the dark ground is lightened until it reads at
|
||||
4.5:1 or better on `#0a0908` (black draws them in `#787878`).
|
||||
- **Polished bars never go too light.** They are shaded no lighter than 78% lightness, so a near-white color gives a
|
||||
silver bar, not a flat white one.
|
||||
|
||||
## How it works
|
||||
|
||||
- **theme.css** holds the gold as a family of `r, g, b` variables (`--gold-rgb`, `--gold-hi-rgb`, ... and the bars'
|
||||
own `--gold-bar-*-rgb`), each with today's value; `v3.css`, `proto.css` and `app.css` use them in place of every gold
|
||||
literal, alphas kept.
|
||||
- **app.js** ("settings: Color scheme") moves each of today's shades from gold to the chosen color: the hue turns by as
|
||||
much, the saturation scales by as much, the lightness keeps its share of the way to white or to black. At gold it
|
||||
gives back every literal exactly. `paintColor()` sets the variables on `<html>` with the class `tint`, and removes them
|
||||
all for gold. The page adds the row itself after `sfx`; a row the launcher sends with `id: 'color'` takes its place.
|
||||
- **Pictures.** The crest (`img/crest.png`) is redrawn under `html.tint` with `hue-rotate / saturate / brightness`,
|
||||
masked by `img/crest-gold.png` (its metal only), so the three stones stay. The title ornaments and glows get the same
|
||||
filter chain from `--tint-h/-s/-b`. The game's own logo and its glow are the game's art and are not tinted. CSS
|
||||
`hue-rotate` is an approximation: far turns (blue, violet) come close but not exact.
|
||||
|
||||
## How it is kept
|
||||
|
||||
1. The page sends `{t:'cmd', c:'color', hex:'#rrggbb'}`, 400 ms after the last change (as `sound`), and keeps the same
|
||||
value in `localStorage['triforce.color']`, which it reads at start before the first screen.
|
||||
2. The launcher takes only a `#rrggbb` (`Logic/LauncherColor.cs`, `FromCommand` / `Parse`), in lower case. It takes it
|
||||
as the message arrives (`App/Backend.Core.cs`, `ColorArrived`, called from `OnMessage` before the command goes to a
|
||||
worker), into `LauncherColorChoice`, which holds the player's last color while the launcher runs. The command's
|
||||
worker (`On("color")`, `Keep`) then keeps the newest one as `Settings.Color`: `HKCU\Software\Triforce\Color` on
|
||||
Windows, `Color=` in `builder.ini` on Linux, `registry.txt` in a test run. Anything else is left out, with one log
|
||||
line a run.
|
||||
3. The launcher sends back `LauncherColorChoice.Current` (the player's last color, else the kept one) as `state.color`
|
||||
at start (`OnReady`, beside `sound`) and with the list the Settings page asks for each time it opens
|
||||
(`settings.list`). The page then uses it, and it wins over the page's own storage, unless a choice of the player's is
|
||||
still waiting to be sent. Because the launcher sends what it holds and not what it has written, a `--snapshot` run
|
||||
(which writes nothing) and a `settings.list` whose worker runs before the `color` sent just ahead of it both send
|
||||
the new color, not the old one.
|
||||
4. A settings file from before the color has no `Color`: it reads as Triforce gold (`#e0b23e`), which is also what
|
||||
**Reset to gold** sends. An uninstall removes it with the other settings.
|
||||
|
||||
## Checks
|
||||
|
||||
- `dotnet run --project launcher/LogicTests color`: the parsing of the page's message, the keeping and reading back in
|
||||
`registry.txt` and `builder.ini`, old files, a bad kept value, `--snapshot`'s no writes, and the color sent back
|
||||
under `--snapshot` and when the commands' workers run out of order.
|
||||
- `python -I -B tests/test_launcher_color.py`: the page and the launcher agree on the message, the default and the image,
|
||||
the image rides in the exe (the `ui/**` embed), and every word the page shows spells "color": the page's own
|
||||
(`app.js`, `demo.js`, `index.html`) and every string in the launcher's C# (`App`, `Logic`, `Core`), the game options'
|
||||
help the Settings rows show as their tooltips among them. That help is the game menu's own words
|
||||
(`gpu/vk/vk_menu.cpp`, which "game options: schema matches vk_menu.cpp" compares); the menu's own table is spelled
|
||||
"color" by the in-game change set, not by this one.
|
||||
- `node --check launcher/ui/app.js`.
|
||||
43
docs/launcher-music.md
Normal file
43
docs/launcher-music.md
Normal file
@@ -0,0 +1,43 @@
|
||||
# The launcher's music
|
||||
|
||||
The launcher plays the player's own game's music: Saria's Song on the reveal, the Temple of Time while it builds, the
|
||||
item fanfare when the build is done, and the Fairy Fountain on the main screens (`MUSIC` in `launcher/ui/app.js`).
|
||||
Nothing of it is in the repository or the exe: `launcher/Core/GameFiles` decodes the game's BWAV files into WAV files
|
||||
in `%LOCALAPPDATA%\Triforce\launcher\media` (`<track>-<key>.wav`), and the page asks for them as `audio/<track>.wav`.
|
||||
|
||||
## The loop
|
||||
|
||||
Each of the three songs plays an intro once and then loops from a sample after it to its end, as in the game:
|
||||
|
||||
| Track | File | Loop |
|
||||
|---|---|---|
|
||||
| Saria's Song | the eight `BGM_LostWood_0` .. `_7` layers, mixed | after a short intro, to the end (every layer the same) |
|
||||
| Fairy Fountain | `BGM_GreatFairyFountain` | after a long intro, to the end |
|
||||
| Temple of Time | `BGM_ShrineOfTime_Child` | from a fraction of a second in, to the end |
|
||||
| Item get | `BGM_ItemGet_Large` | none: it plays once |
|
||||
|
||||
The BWAV header gives the loop (each channel's end at 0x3C, 0xFFFFFFFF for none, and start at 0x40).
|
||||
`Bwav.Decode` reads it, `Bwav.Mix` keeps it when every layer has the same one, and `Bwav.ToWav` writes it as a `smpl`
|
||||
chunk after the samples: one forward loop, its last sample counted in, as the format has it. The samples stay at byte
|
||||
44, so a reader that knows only the plain header still reads the file.
|
||||
|
||||
The page plays music through Web Audio: a track is fetched and decoded once into an `AudioBuffer`, and an
|
||||
`AudioBufferSourceNode` loops it between `loopStart` and `loopEnd`, sample for sample (the context runs at the game's
|
||||
48 kHz, so nothing is resampled). Its volume goes through a `GainNode` with the same fades, volume and mute as before. A
|
||||
WAV without a `smpl` chunk (made by an older launcher) loops whole. Without Web Audio, or for a file it cannot decode,
|
||||
an `<audio>` element plays it as before. The item fanfare starts at its full level (a fade-in would swallow its first
|
||||
notes); a track faded out before it is read never starts, and a track that stops lets go of its decoded samples.
|
||||
|
||||
Before, an `<audio>` element looped the whole file: the intro came back on every loop, the end jumped to the start with
|
||||
a step in the wave, and the element paused between the end and the start.
|
||||
|
||||
A launcher with this change decodes the sounds again once (the WAV cache's key has `SoundVersion` in it, and the files
|
||||
made before are removed); the title art keeps its files.
|
||||
|
||||
## Tests
|
||||
|
||||
- `dotnet run --project launcher/LogicTests media`: the loop read from a BWAV the test writes, kept by the mix, written
|
||||
as `smpl` and read back, and the cache made again.
|
||||
- `python -I -B tests/test_launcher_music.py`: the page's music code run in node with stand-ins for Web Audio, fetch and
|
||||
`<audio>` (`tests/launcher_music_test.js`), and the page and the launcher checked to read and write the loop at the
|
||||
same place.
|
||||
@@ -227,6 +227,11 @@ int nvn_depth_minus_w(void);
|
||||
void rx_nvn_submit(const uint64_t *handles, int n);
|
||||
/* (the same with the queue it came from: the game's queues have their own state and order each other with events) */
|
||||
void rx_nvn_submit_q(const uint64_t *handles, int n, uint64_t queue);
|
||||
/* (Triforce, gpu/vk/async_rules.h; host/rx_backend.c) the replay on a thread of the back end's own (RX_VK_ASYNC=1): whether it
|
||||
is on; the events the submit this thread makes next waits for; the present poll's wait for that thread (1: nothing left) */
|
||||
int rx_async_replay(void);
|
||||
void rx_nvn_submit_waits(const uint64_t *events, int n);
|
||||
int rx_nvn_replay_idle_wait(uint64_t timeout_ns);
|
||||
/* fence value of everything submitted so far; waits until the GPU reached a fence (1: reached, 0: timed out) */
|
||||
uint64_t rx_nvn_fence(void);
|
||||
uint64_t rx_nvn_fence_q(uint64_t queue); /* (hookshot) a fence of one queue */
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <span>
|
||||
|
||||
#include "common/alignment.h"
|
||||
#include "../vk/cpu_count.h" // ((Triforce, 11-22, OS-49) the threads to size by: HOS_SIM_CPU
|
||||
#include "common/div_ceil.h"
|
||||
#include "video_core/texture_cache/format_lookup_table.h"
|
||||
#include "video_core/textures/astc.h"
|
||||
@@ -766,7 +767,7 @@ std::unique_ptr<Image> decode(const TICEntry& tic, const TexInfo& info_in, uint6
|
||||
copy_layers >= 4 && level_size.depth == 1 && (size_t)level_size.width * level_size.height * 4 <= (8u << 20)) {
|
||||
const Extent3D block = AdjustMipBlockSize(tiles, li.block, level, li.num_levels);
|
||||
const u32 stride_alignment = StrideAlignment(tiles, info.block, gob, li.bpp_log2);
|
||||
const unsigned nthreads = std::max(1u, std::min<unsigned>(copy_layers, std::thread::hardware_concurrency() - 1));
|
||||
const unsigned nthreads = std::max(1u, std::min<unsigned>(copy_layers, cpu_count() - 1));
|
||||
std::atomic<u32> next_layer{0};
|
||||
static std::atomic<int64_t> t_swz, t_dec, t_up;
|
||||
auto work = [&] {
|
||||
|
||||
@@ -33,11 +33,19 @@ inline int chosen(int row, int env) {
|
||||
const int v = env >= 0 ? env : row;
|
||||
return v >= GAME && v < kValues ? v : GAME;
|
||||
}
|
||||
/// DLSS, DLAA, FSR 3.1, FSR 4 and their native modes anti-alias the 3D themselves, from frames the game's own pass has not
|
||||
/// smoothed any better: while one of them draws (upscaler: what runs, upscaler_rows.h) the row does not apply
|
||||
/// DLSS, DLAA, FSR 3.1, FSR 4 and their native modes anti-alias the 3D themselves: while one of them draws (upscaler: what
|
||||
/// runs, upscaler_rows.h) the row does not apply
|
||||
inline bool upscaler_own(int upscaler) { return upscaler != upscaler_rows::GAME; }
|
||||
/// What is in effect: the choice, or the game's own while such an upscaler draws (its frame is then drawn as before the row)
|
||||
inline int effective(int choice, int upscaler) { return upscaler_own(upscaler) ? (int)GAME : choice; }
|
||||
/// What is in effect: the choice with the game's own upscaler. ((Triforce, FSR3-06, FSR4-5) While such an upscaler draws from
|
||||
/// the tone mapped picture (Upscale before bloom off), none: the game's SMAA is left out, as AMD and NVIDIA ask for jittered
|
||||
/// frames no other anti-aliasing has been over (SMAA before them softened what they gather, and its edges, found anew in
|
||||
/// each jittered frame, flickered). It was the game's own SMAA before. Before the bloom (before_bloom) the upscaler takes
|
||||
/// the scene, which the SMAA has not been over: the game's own then, as before. env_set (RX_VK_AA for the run): its choice
|
||||
/// there too, for an A/B (RX_VK_AA=0: the game's SMAA under the upscaler)
|
||||
inline int effective(int choice, int upscaler, bool before_bloom = false, bool env_set = false) {
|
||||
if (!upscaler_own(upscaler) || env_set) return choice;
|
||||
return before_bloom ? (int)GAME : (int)OFF;
|
||||
}
|
||||
/// The row has nothing to choose then (shown without arrows; Left and Right leave the saved value alone), nor with
|
||||
/// RX_VK_AA set for the run
|
||||
inline bool fixed(int upscaler, bool env_set) { return upscaler_own(upscaler) || env_set; }
|
||||
|
||||
145
gpu/vk/achievement_rows.h
Normal file
145
gpu/vk/achievement_rows.h
Normal file
@@ -0,0 +1,145 @@
|
||||
// (Triforce) Achievements on the menu's side: the list the host names (host/achievements.c; vk_api.h HOS_OPT_ACH_*), which of
|
||||
// them are earned, the one a notice shows, and the Achievements page's choice and pages. vk_menu.cpp draws them.
|
||||
//
|
||||
// The achievements are the host's: it reads the lists, asks the save data and keeps what was earned. The menu is told
|
||||
// each one's name, the line about it, its icon and the day it was earned, a byte a call as the save rows' lines are, and
|
||||
// later each one earned as it is. An icon is drawn, not a picture file: a shape and a tone (host/achievements.h has the
|
||||
// same in the same order, ACH_SHAPES and ACH_TONES; tests/test_achievements.py holds the two together).
|
||||
//
|
||||
// The host's calls (text, add, done, earn) come on its threads, one at a time (its lock); the list is drawn on the
|
||||
// renderer's: names, lines and icons are written before count says they are there and never after, a day before its
|
||||
// achievement's earned says so.
|
||||
//
|
||||
// No ImGui and no Vulkan: tests/test_achievements.py compiles it alone.
|
||||
#pragma once
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace achievement_rows {
|
||||
constexpr int kSlots = 128; // (host/achievements.h ACH_MAX)
|
||||
constexpr int kName = 41, kAbout = 161, kDay = 16;
|
||||
constexpr int kEarned = 256; // (vk_api.h HOS_ACH_EARNED)
|
||||
enum Shape { kStar, kSword, kGem, kMedal, kNote, kToken, kShield, kShapes };
|
||||
enum Tone { kGold, kGreen, kRed, kBlue, kPurple, kOrange, kYellow, kSilver, kTones };
|
||||
constexpr int shape_of(int icon) { return (icon & 15) < kShapes ? icon & 15 : kStar; }
|
||||
constexpr int tone_of(int icon) { return (icon >> 4 & 15) < kTones ? icon >> 4 & 15 : kGold; }
|
||||
|
||||
struct List {
|
||||
char names[kSlots][kName] = {};
|
||||
char abouts[kSlots][kAbout] = {};
|
||||
char days[kSlots][kDay] = {};
|
||||
unsigned char icons[kSlots] = {};
|
||||
std::atomic<int> earned[kSlots] = {};
|
||||
std::atomic<int> count{0}; // (the achievements shown: 0 until the host's list is whole)
|
||||
std::atomic<int> fresh{-1}; // (the one earned now, until the notice takes it)
|
||||
// the host's side
|
||||
char in[kName + kAbout + kDay + 8] = {};
|
||||
int in_n = 0, added = 0;
|
||||
|
||||
/// HOS_OPT_ACH_TEXT: the next byte of what is being named
|
||||
void text(int byte) {
|
||||
if (byte > 0 && byte < 256 && in_n + 1 < (int)sizeof in) in[in_n++] = (char)byte;
|
||||
}
|
||||
/// `from` copied into a field of `cap` bytes, cut at a whole letter
|
||||
static void put(char* to, int cap, const char* from) {
|
||||
int n = (int)strlen(from);
|
||||
if (n > cap - 1) {
|
||||
n = cap - 1;
|
||||
while (n && ((unsigned char)from[n] & 0xC0) == 0x80) n--;
|
||||
}
|
||||
memcpy(to, from, (size_t)n);
|
||||
to[n] = 0;
|
||||
}
|
||||
/// HOS_OPT_ACH_ADD: the bytes so far are the next achievement's name and, each after a line feed, the line about it and
|
||||
/// the day it was earned; bits: its icon, and kEarned
|
||||
void add(int bits) {
|
||||
in[in_n] = 0;
|
||||
in_n = 0;
|
||||
if (count.load(std::memory_order_acquire) || added >= kSlots) return; // (shown already, or no room left)
|
||||
const int slot = added++;
|
||||
char* about = strchr(in, '\n');
|
||||
char* day = about ? strchr(about + 1, '\n') : nullptr;
|
||||
if (about) *about++ = 0;
|
||||
if (day) *day++ = 0;
|
||||
put(names[slot], kName, in[0] ? in : "(no name)");
|
||||
put(abouts[slot], kAbout, about ? about : "");
|
||||
put(days[slot], kDay, day ? day : "");
|
||||
icons[slot] = (unsigned char)(bits & 255);
|
||||
earned[slot].store((bits & kEarned) != 0, std::memory_order_relaxed);
|
||||
}
|
||||
/// HOS_OPT_ACH_COUNT: the list is whole: shown from now on
|
||||
void done(int n) {
|
||||
in_n = 0;
|
||||
if (count.load(std::memory_order_acquire)) return;
|
||||
count.store(n < 0 ? 0 : n < added ? n : added, std::memory_order_release);
|
||||
}
|
||||
/// HOS_OPT_ACH_EARNED: the achievement at that place was earned now, the bytes so far the day. false: no such place
|
||||
bool earn(int slot) {
|
||||
in[in_n] = 0;
|
||||
in_n = 0;
|
||||
if (slot < 0 || slot >= shown()) return false;
|
||||
if (!earned[slot].load(std::memory_order_relaxed)) put(days[slot], kDay, in);
|
||||
earned[slot].store(1, std::memory_order_release);
|
||||
fresh.store(slot, std::memory_order_release);
|
||||
return true;
|
||||
}
|
||||
int shown() const { return count.load(std::memory_order_acquire); }
|
||||
bool is_earned(int slot) const { return slot >= 0 && slot < kSlots && earned[slot].load(std::memory_order_acquire) != 0; }
|
||||
int earned_count() const {
|
||||
int n = 0;
|
||||
for (int i = 0, end = shown(); i < end; i++) n += is_earned(i);
|
||||
return n;
|
||||
}
|
||||
/// The one earned since the last ask, for the notice; -1 none
|
||||
int take_fresh() { return fresh.load(std::memory_order_relaxed) < 0 ? -1 : fresh.exchange(-1, std::memory_order_acq_rel); }
|
||||
};
|
||||
|
||||
/// The page's cards: `columns` to a row, `capacity` to a page (both 1 at least), n of them
|
||||
struct View {
|
||||
int choice = 0, page = 0;
|
||||
|
||||
static int pages(int n, int capacity) { return n <= 0 ? 1 : (n + (capacity < 1 ? 1 : capacity) - 1) / (capacity < 1 ? 1 : capacity); }
|
||||
/// The choice kept to the list, and the page shown to the pages there are
|
||||
void keep(int n, int capacity) {
|
||||
choice = n <= 0 ? 0 : choice < 0 ? 0 : choice >= n ? n - 1 : choice;
|
||||
const int last = pages(n, capacity) - 1;
|
||||
page = page < 0 ? 0 : page > last ? last : page;
|
||||
}
|
||||
/// The page that shows the choice
|
||||
void reveal(int capacity) { page = choice / (capacity < 1 ? 1 : capacity); }
|
||||
/// The arrows (cards: Left and Right, rows: Up and Down), Page Up and Down (turns), Home and End. true: the choice moved
|
||||
bool move(int cards, int rows, int turns, bool home, bool end, int n, int columns, int capacity) {
|
||||
if (n <= 0) return false;
|
||||
const int was = choice;
|
||||
const int step = cards + rows * (columns < 1 ? 1 : columns) + turns * (capacity < 1 ? 1 : capacity);
|
||||
choice = home ? 0 : end ? n - 1 : choice + step;
|
||||
keep(n, capacity);
|
||||
if (choice == was) return false;
|
||||
reveal(capacity);
|
||||
return true;
|
||||
}
|
||||
/// The wheel, or a page arrow that leaves the choice where it is: the page shown turned. true: it changed
|
||||
bool turn(int by, int n, int capacity) {
|
||||
const int was = page;
|
||||
page += by;
|
||||
keep(n, capacity);
|
||||
return page != was;
|
||||
}
|
||||
/// A click on a card. true: the choice changed
|
||||
bool choose(int slot, int n) {
|
||||
if (slot < 0 || slot >= n || slot == choice) return false;
|
||||
choice = slot;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/// How far a notice has come in, 0 (out of sight) to 1 (in place): in over the first 250 ms of its `shown_ms`, out over
|
||||
/// the last 300
|
||||
inline float notice_in(int64_t age_ms, int64_t shown_ms) {
|
||||
if (age_ms < 0 || age_ms >= shown_ms) return 0;
|
||||
const float in = (float)age_ms / 250.0f, out = (float)(shown_ms - age_ms) / 300.0f;
|
||||
const float k = in < out ? in : out;
|
||||
return k > 1 ? 1 : k;
|
||||
}
|
||||
} // namespace achievement_rows
|
||||
@@ -13,4 +13,12 @@ inline bool all_by_vram(uint64_t allowed) {
|
||||
return allowed && allowed < (8704ull << 20);
|
||||
}
|
||||
|
||||
// (Triforce, 11-22, the performance audit's TEX-12, after Source A's) And every integrated GPU, whatever it is allowed. Its
|
||||
// allowance is a share of the system's RAM (a 16 GB handheld reported 10,361 MB), so by the allowance alone it kept the
|
||||
// fine-block textures of 2 to 64 MB as RGBA8, in RAM the game needs too, inside a texture budget capped at 2,560 MB.
|
||||
// Source A measured the difference on a discrete card (RX_VK_ASTC_BC_ALL 0 against 1, Kokiri Forest: decoded ASTC
|
||||
// 2,496-2,532 MB against 1,579-1,587, the GPU's frame the same); it was not run on an integrated GPU there either.
|
||||
// The shape of tex_detail::by_vram(allowed, integrated). RX_VK_ASTC_BC_ALL=0: the finer ones as RGBA8, as before
|
||||
inline bool all(uint64_t allowed, bool integrated) { return integrated || all_by_vram(allowed); }
|
||||
|
||||
} // namespace astc_bc_policy
|
||||
|
||||
@@ -18,12 +18,28 @@
|
||||
// 65535 / 65535 = 1. Modes 4, 5, 10, 12 and 13 carry alpha, and 2, 3, 7, 11, 14 and 15 are the HDR ones, which take the
|
||||
// decoder's other path: no for all of those, without decoding them (such a block may be opaque all the same).
|
||||
// One partition has its mode in bits 13 to 16. Several partitions share one mode when bits 23 and 24 are zero (the mode is
|
||||
// bits 25 to 28); when they do not, the modes' other bits sit below the weights and are not looked for: no.
|
||||
// bits 25 to 28).
|
||||
// - (Triforce, 11-21, the performance audit's TEX-50, after Source B's) When bits 23 and 24 are not zero each partition has a
|
||||
// mode of its own, read as the decoder reads it: 2, 5 or 8 more bits for 2, 3 or 4 partitions sit right below the weights
|
||||
// (at 128 less the weights' bits less their own count); with bits 25 to 28 under them they are a class bit a partition,
|
||||
// then two mode bits a partition, and a partition's mode is (bits 23 and 24 as a number, less 1, plus its class bit) * 4
|
||||
// plus its two bits. Yes only when every partition's mode is one of 0, 1, 6, 8 and 9. Those bits count in the decoder's
|
||||
// last error too: 96 bits of weights, the 29 read and 5 or 8 more wrap, and the block is an error. Such blocks were
|
||||
// refused unread, and a texture with one of them stayed BC3. parts_too = false (RX_VK_TEX_BC1_PARTS=0): refused, as before.
|
||||
#pragma once
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
|
||||
namespace astc_opaque {
|
||||
|
||||
/// Whether a block with a mode a partition is looked at (above); false: refused unread, as before. Set once, at the start
|
||||
inline bool parts_too = true;
|
||||
/// How many such blocks were found opaque (the log's)
|
||||
inline std::atomic<uint64_t> parts_passed{0};
|
||||
|
||||
/// Whether the decoder gives both endpoints of a colour endpoint mode the alpha 255: the modes without alpha, low dynamic range
|
||||
constexpr bool opaque_mode(unsigned cem) { return cem == 0 || cem == 1 || cem == 6 || cem == 8 || cem == 9; }
|
||||
|
||||
/// `n` bits (16 at most) of a block from bit `at`, the lowest first, as the decoder's StreamBits reads them
|
||||
inline uint32_t bits(const uint8_t* b, unsigned at, unsigned n) {
|
||||
uint32_t v = 0;
|
||||
@@ -88,17 +104,32 @@ inline bool block(const uint8_t b[16], unsigned bw, unsigned bh) {
|
||||
range = range - 2 + (layout != 9 && (mode & 0x200) ? 6 : 0);
|
||||
const unsigned wbits = weight_bits(weights, range);
|
||||
if (wbits < 24 || wbits > 96) return false;
|
||||
unsigned read, cem;
|
||||
unsigned read, cem = 0, extra = 0;
|
||||
uint32_t base = 0;
|
||||
if (parts == 1) {
|
||||
cem = bits(b, 13, 4), read = 17;
|
||||
} else {
|
||||
const uint32_t base = bits(b, 23, 6);
|
||||
if (base & 3) return false; // (a mode a partition: not looked for)
|
||||
cem = base >> 2, read = 29;
|
||||
base = bits(b, 23, 6);
|
||||
read = 29;
|
||||
if (base & 3) { // (a mode a partition: its other bits are below the weights)
|
||||
if (!parts_too) return false;
|
||||
extra = parts == 2 ? 2 : parts == 3 ? 5 : 8;
|
||||
} else {
|
||||
cem = base >> 2;
|
||||
}
|
||||
}
|
||||
// (the decoder's last error, its count of the remaining bits wrapping. With one shared mode it cannot: 96 + 29 + 2)
|
||||
if (wbits + read + (dual ? 2u : 0u) > 128) return false;
|
||||
return cem == 0 || cem == 1 || cem == 6 || cem == 8 || cem == 9;
|
||||
// (the decoder's last error, its count of the remaining bits wrapping. With one shared mode it cannot: 96 + 29 + 2. With a
|
||||
// mode a partition it can: 96 + 29 + 8)
|
||||
if (wbits + read + extra + (dual ? 2u : 0u) > 128) return false;
|
||||
if (!extra) return opaque_mode(cem);
|
||||
// (the decoder's own order: (extra << 6 | base) >> 2 is a class bit a partition, then two bits a partition)
|
||||
const uint32_t all = ((bits(b, 128 - wbits - extra, extra) << 6) | base) >> 2;
|
||||
for (unsigned i = 0; i < parts; i++) {
|
||||
const unsigned cls = (base & 3) - 1 + ((all >> i) & 1);
|
||||
if (!opaque_mode((cls << 2) | ((all >> (parts + 2 * i)) & 3))) return false;
|
||||
}
|
||||
parts_passed.fetch_add(1, std::memory_order_relaxed);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Whether every one of `n` blocks (16 bytes each, in any order) is one the decoder writes opaque
|
||||
|
||||
133
gpu/vk/astc_reuse.h
Normal file
133
gpu/vk/astc_reuse.h
Normal file
@@ -0,0 +1,133 @@
|
||||
// (Triforce, 11-21, the performance audit's TEX-14, after Source A's) Decoded ASTC used again.
|
||||
//
|
||||
// The game's textures are ASTC, decoded on the GPU and for the most part encoded again as BC3 or BC1: tens of ms of GPU
|
||||
// time and the decoder's scratch for each. When the game leaves an area it finalizes its textures, and when it comes back
|
||||
// it makes them again, mostly at other addresses: the same blocks are decoded and encoded again while the image made of
|
||||
// them the first time may still be in VRAM, kept until the cache needs its room. Source A hashes an ASTC texture's blocks
|
||||
// at its first whole upload, lists a texture the game finalizes under that hash, and gives a new texture with the same
|
||||
// blocks and the same shape that image by a GPU copy, the old one going after it. Its tours of two areas four times at an
|
||||
// 8 GB budget: peak decoded ASTC 3,603 to 2,562 MB, evictions 23,378 to 16,109, the slowest frame 637 to 487 ms.
|
||||
//
|
||||
// What keeps a hit right: 128 bits of hash over the blocks as the decoder is given them; every field of the image that
|
||||
// the decode made and of the storage it was decoded from (Shape); and a source that was uploaded from memory and never
|
||||
// drawn into, still listed (used again at its own address or gone, it is unlisted).
|
||||
//
|
||||
// RX_VK_ASTC_REUSE: 0 or not set, off (the audit: off until measured in play); 2: the blocks are hashed, the finalized
|
||||
// textures listed and each hit counted, and every texture decoded as before: what a reuse would save, for no risk;
|
||||
// 1: the hit's image is copied.
|
||||
//
|
||||
// No Vulkan here: tests/test_astc_reuse.py compiles it.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "upload_same.h" // (content_hash: the first of the two lanes)
|
||||
|
||||
namespace astc_reuse {
|
||||
|
||||
enum Mode { kOff = 0, kCopy = 1, kCount = 2 };
|
||||
/// RX_VK_ASTC_REUSE's mode: 1 and 2 as they are, anything else off
|
||||
inline Mode mode(const char* asked) {
|
||||
if (!asked || !*asked) return kOff;
|
||||
const int v = atoi(asked);
|
||||
return v == 1 ? kCopy : v == 2 ? kCount : kOff;
|
||||
}
|
||||
|
||||
/// A second hash of n bytes, of other constants and another mix than upload_same::content_hash's: eight chains over 64
|
||||
/// bytes a step, as there, so that both read at memory's speed
|
||||
inline uint64_t lane2(const void* p, uint64_t n) {
|
||||
const uint8_t* b = static_cast<const uint8_t*>(p);
|
||||
const auto rotl = [](uint64_t x, int r) { return (x << r) | (x >> (64 - r)); };
|
||||
uint64_t h = 0xD6E8FEB86659FD93ull + n * 0x9FB21C651E98DF25ull, i = 0;
|
||||
if (n >= 512) {
|
||||
uint64_t c[8];
|
||||
for (int k = 0; k < 8; k++) c[k] = h + 0xA0761D6478BD642Full * (uint64_t)(2 * k + 1);
|
||||
for (; i + 64 <= n; i += 64) {
|
||||
uint64_t w[8];
|
||||
std::memcpy(w, b + i, 64);
|
||||
for (int k = 0; k < 8; k++) c[k] = rotl(c[k] + w[k] * 0xE7037ED1A0B428DBull, 29) * 0x8EBC6AF09C88C6E3ull;
|
||||
}
|
||||
for (int k = 0; k < 8; k++) h = rotl(h ^ c[k], 23) * 0x589965CC75374CC3ull + 0x1D8E4E27C47D124Full;
|
||||
}
|
||||
for (; i + 8 <= n; i += 8) {
|
||||
uint64_t w;
|
||||
std::memcpy(&w, b + i, 8);
|
||||
h = rotl(h + w * 0xE7037ED1A0B428DBull, 29) * 0x8EBC6AF09C88C6E3ull;
|
||||
}
|
||||
for (; i < n; i++) h = rotl(h ^ b[i], 11) * 0x589965CC75374CC3ull;
|
||||
h ^= h >> 32, h *= 0xD6E8FEB86659FD93ull, h ^= h >> 32;
|
||||
return h;
|
||||
}
|
||||
|
||||
/// The blocks' hash, 128 bits, made of pieces given in order (a big texture's storage is read 64 MB at a time): each piece
|
||||
/// goes through both lanes kStep bytes at a time, while they are in the cache, and is folded in with its length
|
||||
struct Hash {
|
||||
uint64_t a = 0, b = 0;
|
||||
bool operator==(const Hash& o) const { return a == o.a && b == o.b; }
|
||||
explicit operator bool() const { return (a | b) != 0; }
|
||||
};
|
||||
inline constexpr uint64_t kStep = 256u << 10;
|
||||
struct Hasher {
|
||||
Hash h;
|
||||
uint64_t bytes = 0;
|
||||
void add(const uint8_t* p, uint64_t n) {
|
||||
for (uint64_t at = 0; at < n; at += kStep) {
|
||||
const uint64_t m = n - at < kStep ? n - at : kStep;
|
||||
h.a = (h.a ^ upload_same::content_hash(p + at, m)) * 0x9E3779B97F4A7C15ull + m;
|
||||
h.b = (h.b + lane2(p + at, m)) * 0xC2B2AE3D27D4EB4Full ^ (m << 1 | 1);
|
||||
}
|
||||
bytes += n;
|
||||
}
|
||||
/// The hash, never all zero (zero is "not hashed")
|
||||
Hash done() const { return (h.a | h.b) ? h : Hash{1, 0}; }
|
||||
};
|
||||
|
||||
/// What has to be the same besides the blocks for one image to stand for another: the image the decode made (its format,
|
||||
/// size, levels and layers, the top levels left out and whether by the card's texture detail, kept as BC3 or BC1 or
|
||||
/// RGBA8, BC1 given up for BC3, resized for AMD) and the storage it was decoded from (the NVN format, the key's layout)
|
||||
struct Shape {
|
||||
uint32_t format, width, height, depth, levels, layers, skip, nvn_format, layout;
|
||||
bool bc, bc_resized, bc1, bc1_no, detail_skip;
|
||||
bool operator==(const Shape& o) const {
|
||||
return format == o.format && width == o.width && height == o.height && depth == o.depth && levels == o.levels &&
|
||||
layers == o.layers && skip == o.skip && nvn_format == o.nvn_format && layout == o.layout && bc == o.bc &&
|
||||
bc_resized == o.bc_resized && bc1 == o.bc1 && bc1_no == o.bc1_no && detail_skip == o.detail_skip;
|
||||
}
|
||||
};
|
||||
|
||||
/// The finalized textures whose image may serve again, by their blocks' hash. T is the cache's texture; one is in the list
|
||||
/// at most once: listed and unlisted by its pointer
|
||||
template <class T>
|
||||
class Freed {
|
||||
public:
|
||||
void list(const Hash& hash, T* t) { by_hash.emplace(hash.a, Entry{hash.b, t}); }
|
||||
void unlist(const Hash& hash, T* t) {
|
||||
auto [a, b] = by_hash.equal_range(hash.a);
|
||||
for (auto it = a; it != b; ++it)
|
||||
if (it->second.t == t) {
|
||||
by_hash.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
/// One listed with this hash, both lanes, whose shape is `shape` (shape_of(T*) gives each one's) and that is not
|
||||
/// `self`; null: none
|
||||
template <class ShapeOf>
|
||||
T* find(const Hash& hash, const Shape& shape, const T* self, ShapeOf shape_of) const {
|
||||
auto [a, b] = by_hash.equal_range(hash.a);
|
||||
for (auto it = a; it != b; ++it)
|
||||
if (it->second.b == hash.b && it->second.t != self && shape_of(it->second.t) == shape) return it->second.t;
|
||||
return nullptr;
|
||||
}
|
||||
size_t size() const { return by_hash.size(); }
|
||||
|
||||
private:
|
||||
struct Entry {
|
||||
uint64_t b;
|
||||
T* t;
|
||||
};
|
||||
std::unordered_multimap<uint64_t, Entry> by_hash;
|
||||
};
|
||||
|
||||
} // namespace astc_reuse
|
||||
137
gpu/vk/async_rules.h
Normal file
137
gpu/vk/async_rules.h
Normal file
@@ -0,0 +1,137 @@
|
||||
// (Triforce) The replay thread's rules (RX_VK_ASYNC=1, off by default): what it took to make the thread a place frames can be
|
||||
// replayed on without the faults the lab's runs of it showed. Nothing here releases the game early: the game still presents only
|
||||
// once the GPU has run its frame (its own event poll), so the picture and its order are the submitting thread's replay's.
|
||||
//
|
||||
// What the runs showed (rounds 22 and 23, vk_replay.cpp's own counters): the thread took the replay of the game's main thread's
|
||||
// two queues off the part of the frame both of the game's chains wait for (about 1.3 ms at the Market), and the frame got only 0.4
|
||||
// to 0.8 ms shorter, because
|
||||
// 1. a capture was taken at every signal of the CPU's while the thread had any work (26,654 in 26,400 frames, 0.25 ms each on
|
||||
// the game's thread), where the submitting thread's replay needs one only when a queue really goes on from a wait for that
|
||||
// event (126 to 1,028 a run);
|
||||
// 2. the submit's capture made every copy on the game's thread, where the submitting thread's replay leaves them to the copy
|
||||
// helpers;
|
||||
// 3. the game's submit gave its virtual core up and took it again around a hand-over of a quarter millisecond;
|
||||
// 4. the game's present poll slept in steps of the system's timer, about 0.6 ms late on average;
|
||||
// 5. every present made the stopped queues go past their waits (5,649 to 15,166 waits gone past a run against 0), which is
|
||||
// also the first suspect of the flicker after a tour.
|
||||
// The rules below are 1 and 5, apart from Vulkan and from the replay's state so that tests/test_async_rules.py can run them; 2 to
|
||||
// 4 are in vk_replay.cpp submit_q, host/nvn_native.c nvnQueueSubmitCommands and host/hos_thread.c present_poll. Each has a switch
|
||||
// of its own, and all of it is behind RX_VK_ASYNC=1.
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <deque>
|
||||
#include <vector>
|
||||
|
||||
namespace mkwvk::async_rules {
|
||||
|
||||
/// A switch that is on unless set to 0 (RX_VK_ASYNC_EVENT_NOTES, RX_VK_ASYNC_CAPTURE_BEHIND)
|
||||
inline bool on_unless_zero(const char* env) {
|
||||
return !env || !*env || std::atoi(env) != 0;
|
||||
}
|
||||
|
||||
// ---- 1. the capture at a signal of the CPU's ----
|
||||
// The game writes what a queue's work reads after it submitted that work, up to its signal of the event the work waits for; the
|
||||
// console's GPU reads memory after its wait. With the replay on its own thread that capture has to be taken at the signal, on the
|
||||
// game's thread (later the game has written on). It is needed only when a submission handed over before the signal holds a wait
|
||||
// for that event that the replay has not passed: every submission handed over after the signal has its own capture, taken after
|
||||
// the game's writes. The host tells the events a submission waits for (its walk at the submit sees the wait ops:
|
||||
// host/nvn_native.c resolve_deferred); a submission is noted from its hand-over until it is replayed whole.
|
||||
|
||||
constexpr uint64_t kAnyEvent = ~0ull; // (a submission whose waits the host did not tell: it may wait for any event)
|
||||
constexpr size_t kMaxNotes = 256; // (more than this pending: every signal takes its capture, as before, until those past it are done)
|
||||
|
||||
struct Notes {
|
||||
struct Note {
|
||||
uint64_t value; // (the submission's timeline value: its hand-over's)
|
||||
std::vector<uint64_t> events; // (the events it waits for; kAnyEvent: not told)
|
||||
};
|
||||
std::deque<Note> pending; // (in hand-over order)
|
||||
bool over = false; // (a submission past kMaxNotes is not replayed whole yet: waits_for answers yes)
|
||||
// ((Triforce) the submissions handed over past the bound, by value: their events are not known, so every event counts until
|
||||
// each of them is done. The flag fell once `pending` was empty, which could be while one past the bound was still stopped
|
||||
// at its wait, and its signal then took no capture)
|
||||
std::vector<uint64_t> unnoted;
|
||||
|
||||
/// A submission handed over. told: the host gave its waits (events, n; n 0: it waits for none, and nothing is noted)
|
||||
void add(uint64_t value, bool told, const uint64_t* events, int n) {
|
||||
if (told && n <= 0) return;
|
||||
if (pending.size() >= kMaxNotes) {
|
||||
over = true;
|
||||
unnoted.push_back(value);
|
||||
return;
|
||||
}
|
||||
Note note{value, {}};
|
||||
if (!told) note.events.push_back(kAnyEvent);
|
||||
else
|
||||
for (int i = 0; i < n; i++)
|
||||
if (std::find(note.events.begin(), note.events.end(), events[i]) == note.events.end()) note.events.push_back(events[i]);
|
||||
pending.push_back(std::move(note));
|
||||
}
|
||||
/// The submission of that value replayed whole (none of it stopped at a wait any more)
|
||||
void done(uint64_t value) {
|
||||
for (auto it = pending.begin(); it != pending.end(); ++it)
|
||||
if (it->value == value) {
|
||||
pending.erase(it);
|
||||
break;
|
||||
}
|
||||
for (auto it = unnoted.begin(); it != unnoted.end(); ++it)
|
||||
if (*it == value) {
|
||||
unnoted.erase(it);
|
||||
break;
|
||||
}
|
||||
if (unnoted.empty()) over = false;
|
||||
}
|
||||
/// Whether a submission handed over and not replayed whole may hold a wait for the event
|
||||
bool waits_for(uint64_t event) const {
|
||||
if (over) return true;
|
||||
for (const Note& note : pending)
|
||||
for (const uint64_t e : note.events)
|
||||
if (e == event || e == kAnyEvent) return true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/// Whether a signal of the CPU's takes a capture on the game's thread. behind: the replay thread has work handed over and not
|
||||
/// recorded. notes_on: RX_VK_ASYNC_EVENT_NOTES (off: every signal with the thread behind, as before)
|
||||
inline bool capture_at_signal(bool behind, bool notes_on, const Notes& notes, uint64_t event) {
|
||||
if (!behind) return false;
|
||||
return !notes_on || notes.waits_for(event);
|
||||
}
|
||||
|
||||
// ---- 5. what a present on the replay thread does with the queues stopped at a wait ----
|
||||
// Force: every stopped queue past its wait (as it was by default: the waits gone past). Keep: nothing forced (a load stood for
|
||||
// good with it: only a present makes a load's stopped work go). Stale: the jobs behind the present are run first, a few
|
||||
// milliseconds at most, until the frame's stopped work has gone on, and then only what was already stopped at the present before
|
||||
// is made to go (vk_replay.cpp drain_stale). RX_VK_PRESENT_DRAIN: unset or 2 stale, 1 force, 0 keep
|
||||
enum class PresentDrain { Keep = 0, Force = 1, Stale = 2 };
|
||||
inline PresentDrain present_drain(const char* env) {
|
||||
if (!env || !*env) return PresentDrain::Stale;
|
||||
const int v = std::atoi(env);
|
||||
return v == 0 ? PresentDrain::Keep : v == 1 ? PresentDrain::Force : PresentDrain::Stale;
|
||||
}
|
||||
|
||||
// ---- what is still open (2026-11-19, lab rounds 52 to 60; the thread stays off by default) ----
|
||||
// Standing at the Market the thread gave 104.3 fps for 97.5 and a 1% low of 81.7 for 75.2, with no flicker (3 runs each). After
|
||||
// a ten-area tour the player's character is drawn black for one frame, 0 to 3 times a minute at the Market (the default: none in
|
||||
// 2 tours); with the presents forcing again (RX_VK_PRESENT_DRAIN=1) 37 to 111 times, so rule 5 is what keeps it rare. Every pass
|
||||
// and dispatch of such a frame is there with its draws: the character is lit from wrong inputs, in a frame after one whose replay
|
||||
// ran late. Ruled out: these rules (the thread without them does it too), texture uploads (none in three of four such frames),
|
||||
// a readback handing the game a word it had set to 0 (none at 43 such frames: RX_VK_LOG_READBACK_ZERO), the conditions on
|
||||
// occlusion counts and the occlusion answers (RX_VK_OCC_COND=0, RX_VK_OCC_QUERY=0: still there), and the game's request flags
|
||||
// (all read set around eight such frames). Not settled: whether the lab's frame log, whose readback and disk writes are on this
|
||||
// thread, is what makes the replay late there (one tour each: 3 such frames with its writes, none with RX_VK_FRAMELOG_DROP=1).
|
||||
// RX_VK_REGION_TRAP=1 with RX_VK_PASS_TRACE=1 and the frame log logs the passes and conditions around the first eight.
|
||||
|
||||
// ---- the replay thread's look for its next job ----
|
||||
/// RX_VK_ASYNC_SPIN_US: how long the thread looks for a job before it sleeps, in nanoseconds: 100 us unset, 0 none, 1000 at most.
|
||||
/// The thread is on the core kept from the game's threads, and a wake of a sleeping thread is tens of microseconds for each of a
|
||||
/// frame's hand-overs
|
||||
inline int64_t spin_ns(const char* env) {
|
||||
if (!env || !*env) return 100 * 1000;
|
||||
return (int64_t)std::clamp(std::atoi(env), 0, 1000) * 1000;
|
||||
}
|
||||
|
||||
} // namespace mkwvk::async_rules
|
||||
@@ -71,6 +71,28 @@ inline bool split_in_pass(const char* env, uint32_t vendor, bool every_draw) {
|
||||
return false; // helper threads record most frames there, and the rule stands aside for them) and no gain (90.6 / 89.2 fps
|
||||
// against 92.8 / 90.3 with the old barriers)
|
||||
}
|
||||
/// ((Triforce, 11-22, the performance audit's REPLAY-14, after Source A's) Two workarounds for Intel's drivers at a submission's
|
||||
/// splits (vk_replay.cpp maybe_split and the dry pass's points). No other vendor has either unless its switch asks.
|
||||
/// RX_VK_SPLIT_BEFORE_DRAW: a part ends only right before a plain draw. On an Arc B580 a command buffer that begins with mesh
|
||||
/// draws drew its later plain draws as exploded triangles (Source A: 40 shard frames of 1,121 before, 0 of 1,101 after). Unset:
|
||||
/// on for Intel's GPUs (vendor 0x8086); 0 off; anything else on, on any GPU
|
||||
inline bool split_before_draw(const char* env, uint32_t vendor) {
|
||||
if (env && *env) return std::strcmp(env, "0") != 0;
|
||||
return vendor == 0x8086;
|
||||
}
|
||||
/// RX_VK_SPLIT_UBFLUSH: whether a part's end writes the submission's uniform updates so far into the game's memory. Without
|
||||
/// mirrors they land in the memory later parts' other reads and the game's CPU see, mid-submission, where an unsplit submission
|
||||
/// writes them once at its end: white blocks and flashes on Intel's integrated GPUs (Source A: 1 run of 3 before, 0 of 3
|
||||
/// after). Unset: on, as before, but off on Intel's GPUs without mirrors; 0 off; anything else on
|
||||
inline bool split_ub_flush(const char* env, uint32_t vendor, bool mirrors) {
|
||||
if (env && *env) return std::strcmp(env, "0") != 0;
|
||||
return !(vendor == 0x8086 && !mirrors);
|
||||
}
|
||||
/// A part may end right before this op: a plain draw (NOP_DRAW, _IDX, _INDIRECT: not a mesh draw, not a dispatch) that will
|
||||
/// draw (rendering on, no rasterizer discard)
|
||||
constexpr bool cut_ok(bool plain_draw, bool render_enabled, bool raster_discard) {
|
||||
return plain_draw && render_enabled && !raster_discard;
|
||||
}
|
||||
/// Whether a part's split goes on in the same pass: the rule on, a pass open at the split, nothing recorded at the part's end (quiet:
|
||||
/// the work count as it was after the pass's end) and no event's write held then (written behind a full barrier before the part's
|
||||
/// write-backs, which copy its word to the game's memory: the GPU drained there all the same). ((Triforce, P4) no parallel replay's
|
||||
@@ -85,6 +107,25 @@ inline bool split_start_full(bool carry, bool recorded_between) {
|
||||
return !carry || recorded_between;
|
||||
}
|
||||
|
||||
/// ((Triforce, 11-22, the performance audit's SYNC-66, after Source B's) RX_VK_CHUNK: how many draws and dispatches a part of a
|
||||
/// long submission has (vk_replay.cpp maybe_split). 120 on every card since the parts were made: the GPU starts early, and each
|
||||
/// split costs a queue submit, two full barriers and the part's bookkeeping, about 27 times a frame in a serial replay. Source B
|
||||
/// cuts at 128 where the GPU idles while the CPU records and at 4096 on desktop drivers; what pays here is not measured on any
|
||||
/// driver, so the default by driver is 120 for each until the lab picks one (S1 and S2 with RX_VK_PARALLEL=0 and the lab knob
|
||||
/// chunk:<n>). vendor: the card's PCI vendor; radv: Mesa's RADV
|
||||
constexpr int64_t kPartDraws = 120;
|
||||
inline int64_t part_draws_default(uint32_t vendor, bool radv) {
|
||||
(void)vendor, (void)radv;
|
||||
return kPartDraws;
|
||||
}
|
||||
/// The size in force: RX_VK_CHUNK's number when the variable is set (0 or less: whole submissions, never split); else
|
||||
/// knob_or_default, the lab knob chunk:<n>'s number in its phases and the driver's default outside them
|
||||
inline int64_t part_draws(bool env_set, int64_t env_value, int64_t knob_or_default) {
|
||||
return env_set ? env_value : knob_or_default;
|
||||
}
|
||||
/// As the size was read before: the variable's number, 120 unset
|
||||
inline int64_t part_draws_before(const char* env) { return env ? std::atoll(env) : 120; }
|
||||
|
||||
/// RX_VK_EVENT_BARRIER: "late" the rule on any card; "full" (or any other value) as before; unset or empty: with the pass barrier's
|
||||
/// game mode (pass_barrier::game: NVIDIA's driver unless RX_VK_PASS_BARRIER says otherwise)
|
||||
inline bool event_late(const char* env, bool pass_game) {
|
||||
@@ -139,5 +180,18 @@ inline bool batch_flush(Batch m, bool added_held, size_t held, size_t cap) {
|
||||
if (m == Batch::Parts && !added_held) return true;
|
||||
return held >= cap;
|
||||
}
|
||||
/// ((Triforce, 11-22, the performance audit's SYNC-09, after Source A's) RX_VK_BATCH_IDLE: a submit that joins the held batch
|
||||
/// sends it at once when the GPU has finished every batch sent. A held batch otherwise waits for a wait, a present, the 2 ms
|
||||
/// poll or the cap of 32 while the GPU sits idle beside it, until the game waits mid-frame at a capture's late pages; while the
|
||||
/// GPU is busy, submits still group. Source A has it on wherever batching is (RADV), off where guest memory stayed host-pointer
|
||||
/// imports (each submit there pays amdgpu's page check, 15-45 ms). HERE: on only with a number other than 0; unset it is OFF,
|
||||
/// on every driver, until a Linux RADV machine has run it (the audit's lab proof; with NVIDIA's driver and AMD's and Intel's on
|
||||
/// Windows nothing is held). No guard for host-pointer imports is built: with the switch off unless asked there is nothing for it to guard
|
||||
inline bool batch_idle_on(const char* env) { return env && std::atoi(env) != 0; }
|
||||
/// Whether a held batch is looked at for an idle GPU after a submit joined it: the switch on, Hold mode only (Parts sends by
|
||||
/// its own rule, when the game's submit returns), and something held (the cap's flush may just have sent it all)
|
||||
inline bool batch_idle(Batch m, bool held, bool on) {
|
||||
return on && m == Batch::Hold && held;
|
||||
}
|
||||
|
||||
} // namespace mkwvk::barrier_rules
|
||||
|
||||
66
gpu/vk/bc_scratch.h
Normal file
66
gpu/vk/bc_scratch.h
Normal file
@@ -0,0 +1,66 @@
|
||||
// (Triforce, 11-21, the performance audit's TEX-10, after Source A's) How many layers the BC3 scratch has.
|
||||
//
|
||||
// Big ASTC textures are decoded into a 2048 x 2048 RGBA8 scratch and encoded again as BC3 on the GPU, into an output
|
||||
// buffer. Both were made with 8 layers, 128 + 32 = 160 MB (and the second scratch of the textures encoded at another
|
||||
// size, 128 MB more), whatever a run used; and a run decodes one layer (RX_VK_BC_LAYERS, the dark-line fix), so 140 MB
|
||||
// were held and never written, for good once made (RX_VK_BC_IDLE_S is 0). Sized by the layers one run uses they are
|
||||
// 16 + 4 = 20 MB. Source A measured 139 MiB less GPU memory on a Steam Deck, the median of 7 pairs, at the same fps.
|
||||
// RX_VK_BC_SCRATCH_FULL=1: all 8 layers, as before.
|
||||
//
|
||||
// The rule alone, no Vulkan: tests/test_bc_scratch_layers.py compiles it.
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace bc_scratch {
|
||||
|
||||
inline constexpr uint32_t kDim = 2048, kMost = 8; // (the largest level a BC3 texture may have; the most layers a run may take)
|
||||
|
||||
/// The layers one run decodes and encodes: RX_VK_BC_LAYERS's value, 1 to kMost; not set, or not a number, 1
|
||||
inline uint32_t run_layers(const char* asked) {
|
||||
return asked ? std::clamp<uint32_t>((uint32_t)std::max(atoi(asked), 0), 1u, kMost) : 1u;
|
||||
}
|
||||
/// The scratch's layers: a run's, or all of them when full (RX_VK_BC_SCRATCH_FULL)
|
||||
inline uint32_t layers(uint32_t run, bool full) { return full ? kMost : std::clamp(run, 1u, kMost); }
|
||||
/// The output buffer's bytes: BC3's 16 bytes a block of 4 x 4, every layer
|
||||
inline uint64_t out_bytes(uint32_t layers) { return (uint64_t)(kDim / 4) * (kDim / 4) * layers * 16; }
|
||||
/// What the scratch holds, in MB: the image and its output buffer, and the second image when there is one
|
||||
inline uint64_t mb(uint32_t layers, bool second) {
|
||||
const uint64_t image = (uint64_t)kDim * kDim * 4 * layers;
|
||||
return (image + out_bytes(layers) + (second ? image : 0)) >> 20;
|
||||
}
|
||||
|
||||
// ---- (Triforce, 11-21, the performance audit's TEX-09, after Source A's) the small scratch ----
|
||||
// A run is a decode, an encode, a copy and three full barriers, and one layer a run made a 1365 x 1365 x 90 terrain array
|
||||
// of 11 levels about 990 of them: the GPU spent most of that time between the runs (Source A, Hyrule Field's entry on an
|
||||
// RX 9070 XT: 50 ms of GPU an array at one layer a run, 16-17 ms at 8; the lab's own array took 114.8 ms of an RTX 5090 in
|
||||
// one upload command buffer). Levels of kSmallDim or less each way, the arrays' second level down, go small_layers() layers
|
||||
// a run through a scratch of their own, kSmallDim x kSmallDim x 8: 32 MB, and the output buffer 8 MB for 4. One layer a
|
||||
// run was for dark lines between Hyrule Field's ground tiles on an RX 6600, layers after a run's first wrong at the small
|
||||
// levels, cause never found: so on AMD's cards the default stays 1 until the picture is checked there, and each layer of a
|
||||
// run is copied by a region of its own, at the encoder's own layer stride. A level of a texture encoded at another size
|
||||
// keeps the first scratch. RX_VK_BC_SMALL_LAYERS=<n>: the layers a run, 1 to 8; 1: no small scratch, as before.
|
||||
inline constexpr uint32_t kSmallDim = 1024;
|
||||
|
||||
/// The small scratch's layers, a run's of a small level: RX_VK_BC_SMALL_LAYERS, 1 to kMost; not set, kMost, and 1 on AMD's
|
||||
/// cards (vendor 0x1002)
|
||||
inline uint32_t small_layers(const char* asked, uint32_t vendor) {
|
||||
if (asked && *asked) return std::clamp<uint32_t>((uint32_t)std::max(atoi(asked), 0), 1u, kMost);
|
||||
return vendor == 0x1002 ? 1u : kMost;
|
||||
}
|
||||
/// Whether a level decoded at w x h goes through the small scratch: there is one, the level fits it, and the texture is not
|
||||
/// one encoded at another size (which has the second scratch)
|
||||
inline bool small_level(uint32_t w, uint32_t h, bool have_small, bool resized) {
|
||||
return have_small && !resized && w <= kSmallDim && h <= kSmallDim;
|
||||
}
|
||||
/// The small scratch's part of the output buffer, and its image, in bytes
|
||||
inline uint64_t small_out_bytes(uint32_t layers) { return (uint64_t)(kSmallDim / 4) * (kSmallDim / 4) * layers * 16; }
|
||||
inline uint64_t small_image_bytes(uint32_t layers) { return (uint64_t)kSmallDim * kSmallDim * 4 * layers; }
|
||||
/// Where layer k of a run begins in the encoder's output: host_shaders/bc_encoder.comp writes block
|
||||
/// (z * blocks_y + y) * blocks_x + x, 16 bytes a block, 8 where only the colour half is written (an image kept as BC1)
|
||||
inline uint64_t layer_offset(uint32_t k, uint32_t w, uint32_t h, bool bc1) {
|
||||
return (uint64_t)k * ((w + 3) / 4) * ((h + 3) / 4) * (bc1 ? 8 : 16);
|
||||
}
|
||||
|
||||
} // namespace bc_scratch
|
||||
164
gpu/vk/built_check.h
Normal file
164
gpu/vk/built_check.h
Normal file
@@ -0,0 +1,164 @@
|
||||
// Whether the caches still have what the light precompile's record says it built (no game, no GPU: the rules; vk_draw.cpp
|
||||
// built_check_cold, precompile_run, built_play_build). After lib_check.h, which asks the same of the stage libraries, and
|
||||
// predict_check.h, which asks it of the predicted pipelines.
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's PIPE-21, after Source A's and Source B's.) A light precompile (little RAM:
|
||||
// precompile_keeps_all) builds the noted pipelines for the caches, lets them go, and records their keys in <notes>.built,
|
||||
// the compute programs' as one key. A later start trusts that record on its stamp alone: what it lists is left to its first
|
||||
// draw or dispatch, to be built from the caches there. When the caches lost it (the pipeline cache file deleted or refused,
|
||||
// the play file lost, a driver's own cache cleared or past its cap), each of those first draws compiles in play while the
|
||||
// record still says built: a draw left out or waiting for a whole build, a dispatch waiting 50 ms and then left out. Source A
|
||||
// measured a cleared NVIDIA cache: 702,312 draws left out and 21.3 s of draw waits in 140 s of play, against 456 and none
|
||||
// once everything was built again before the title.
|
||||
//
|
||||
// The check. Before the record is trusted, up to kGraphics of the recorded notes (spread over them from another place each
|
||||
// start) are asked of Triforce's own caches as a draw asks, and up to kComputes of the listed compute programs as a dispatch
|
||||
// asks, where the device can ask without compiling (FAIL_ON_PIPELINE_COMPILE_REQUIRED): the answer is the caches' own.
|
||||
// Not a scratch cache of the check's own: AMD's Windows driver keeps no cache of its own (pcache_bound.h), so a question
|
||||
// put to the driver alone would always be cold there. Without the flag, a pipeline is built twice and timed, as lib_check
|
||||
// does: the second comes from the cache by construction, and a first over kRatio times it and kSlackMs more was compiled.
|
||||
// Under kAnswers answers the sample says nothing (the record is trusted, as before); at half of them or more cold it is cold.
|
||||
//
|
||||
// Cold: the record is not trusted this start, everything noted and every listed compute program is built again before the
|
||||
// title (as for a fresh record), and the record is written anew after it. <notes>.built.check keeps, for the stamp, that the
|
||||
// check built them again (kStrikes 0): cold again right after that, the caches do not keep them on this PC (often a driver's
|
||||
// shader cache that is too small), and they are left to their first draws, as before this check, with a hint in the log. A
|
||||
// warm sample forgets that.
|
||||
//
|
||||
// In play, a counter of what the check is for: recorded pipelines whose first build took kSlowUs or more, and recorded
|
||||
// compute programs the dispatch's ask did not find, logged at most every kSayMs while it grows.
|
||||
//
|
||||
// RX_VK_BUILT_CHECK: 1 by default; 0 no check and no counter, as before; 2 always cold (the lab's and the tests').
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace built_check {
|
||||
|
||||
inline constexpr int kGraphics = 24; // (recorded notes asked: Source A asks 48, Source B six computes)
|
||||
inline constexpr int kLook = 2 * kGraphics; // (notes looked at for them: one may have lost its program)
|
||||
inline constexpr int kComputes = 6; // (listed compute programs asked)
|
||||
inline constexpr int kAnswers = 16; // (fewer answers say nothing)
|
||||
inline constexpr double kRatio = 4.0; // (without the flag: a first build against the second, compiled above)
|
||||
inline constexpr double kSlackMs = 3.0; // (and this much more)
|
||||
inline constexpr int kStrikes = 0; // (built again once, and cold again right after: left to the draws)
|
||||
inline constexpr int64_t kSlowUs = 40000; // (a play build of a recorded pipeline over this was compiled)
|
||||
inline constexpr int64_t kSayMs = 10000; // (the counter's line: at most this often)
|
||||
|
||||
/// RX_VK_BUILT_CHECK: 0 off, 1 on (unset too), 2 always cold
|
||||
inline int mode(const char* env) {
|
||||
if (!env || !*env) return 1;
|
||||
const int v = std::atoi(env);
|
||||
return v <= 0 ? 0 : v >= 2 ? 2 : 1;
|
||||
}
|
||||
|
||||
/// One pipeline asked. asked: asked of the caches only; answered_cold: they said a compile is required; made: it was made
|
||||
/// (both times, not asked). One the driver refuses says nothing of the caches
|
||||
struct Probe {
|
||||
bool asked = false, answered_cold = false, made = false;
|
||||
double first_ms = 0, again_ms = 0;
|
||||
};
|
||||
inline bool counts(const Probe& p) { return p.answered_cold || p.made; }
|
||||
inline bool cold(const Probe& p) {
|
||||
return p.answered_cold || (!p.asked && p.made && p.first_ms > kRatio * p.again_ms + kSlackMs);
|
||||
}
|
||||
|
||||
struct Tally {
|
||||
int got = 0, cold = 0, answered = 0;
|
||||
};
|
||||
inline Tally tally(const std::vector<Probe>& probes) {
|
||||
Tally t;
|
||||
for (const Probe& p : probes)
|
||||
if (counts(p)) t.got++, t.cold += cold(p), t.answered += p.answered_cold;
|
||||
return t;
|
||||
}
|
||||
|
||||
enum class Verdict { Unknown, Warm, Cold };
|
||||
/// Under kAnswers answers nothing; half of them or more cold: cold
|
||||
inline Verdict verdict(const Tally& t) {
|
||||
if (t.got < kAnswers) return Verdict::Unknown;
|
||||
return t.cold * 2 >= t.got ? Verdict::Cold : Verdict::Warm;
|
||||
}
|
||||
|
||||
/// k places spread over n, the first at seed's place in the first step: each start asks other pipelines
|
||||
inline std::vector<size_t> spots(size_t n, size_t k, uint64_t seed) {
|
||||
std::vector<size_t> at;
|
||||
if (!n || !k) return at;
|
||||
const size_t step = std::max<size_t>(1, n / k);
|
||||
for (size_t i = (size_t)(seed % step); i < n && at.size() < k; i += step) at.push_back(i);
|
||||
return at;
|
||||
}
|
||||
|
||||
// ---- <notes>.built.check: "built-check <stamp> <strikes>"
|
||||
|
||||
struct State {
|
||||
bool found = false;
|
||||
uint64_t stamp = 0;
|
||||
int strikes = 0;
|
||||
};
|
||||
inline State state_read(const std::string& path) {
|
||||
State s;
|
||||
FILE* f = fopen(path.c_str(), "rb");
|
||||
if (!f) return s;
|
||||
char line[96]{};
|
||||
const size_t n = fread(line, 1, sizeof line - 1, f);
|
||||
fclose(f);
|
||||
line[n] = 0;
|
||||
unsigned long long stamp = 0;
|
||||
int strikes = 0;
|
||||
if (sscanf(line, "built-check %16llx %d", &stamp, &strikes) == 2 && strikes >= 0)
|
||||
s.found = true, s.stamp = stamp, s.strikes = strikes;
|
||||
return s;
|
||||
}
|
||||
/// Written whole beside the old one, then put in place (a start that ends in the middle leaves the old file)
|
||||
inline bool state_write(const std::string& path, uint64_t stamp, int strikes) {
|
||||
char line[96];
|
||||
const int n = snprintf(line, sizeof line, "built-check %016llx %d\n", (unsigned long long)stamp, strikes);
|
||||
const std::string tmp = path + ".tmp";
|
||||
FILE* f = fopen(tmp.c_str(), "wb");
|
||||
if (!f) return false;
|
||||
bool ok = fwrite(line, 1, (size_t)n, f) == (size_t)n;
|
||||
ok = fclose(f) == 0 && ok;
|
||||
if (ok) {
|
||||
remove(path.c_str()); // (rename does not replace on Windows)
|
||||
ok = rename(tmp.c_str(), path.c_str()) == 0;
|
||||
}
|
||||
if (!ok) remove(tmp.c_str());
|
||||
return ok;
|
||||
}
|
||||
|
||||
enum class Do { Nothing, Again, Stop };
|
||||
/// What a start does with the verdict, the record of the last starts and the stamp now. always: mode 2, built again at every
|
||||
/// start whatever was recorded. *next: the strikes to record once they are built again (Again only)
|
||||
inline Do decide(Verdict v, const State& had, uint64_t stamp, bool always, int* next) {
|
||||
if (always) return *next = 0, Do::Again;
|
||||
if (v != Verdict::Cold) return Do::Nothing;
|
||||
const bool same = had.found && had.stamp == stamp; // (built again for this stamp, and cold again since)
|
||||
if (same && had.strikes >= kStrikes) return Do::Stop;
|
||||
*next = same ? had.strikes + 1 : 0;
|
||||
return Do::Again;
|
||||
}
|
||||
|
||||
// ---- the counter: play builds of recorded pipelines the caches did not have
|
||||
|
||||
/// Whether a build of that many microseconds was compiled rather than found
|
||||
inline bool slow(int64_t us) { return us >= kSlowUs; }
|
||||
/// Whether the counter's line is due: said_ms, when it was last written (0: never)
|
||||
inline bool say(int64_t now_ms, int64_t said_ms) { return !said_ms || now_ms - said_ms >= kSayMs; }
|
||||
/// keys sorted without repeats, for has()
|
||||
inline std::vector<uint64_t> sorted(std::vector<uint64_t> keys) {
|
||||
std::sort(keys.begin(), keys.end());
|
||||
keys.erase(std::unique(keys.begin(), keys.end()), keys.end());
|
||||
return keys;
|
||||
}
|
||||
inline bool has(const std::vector<uint64_t>& sorted_keys, uint64_t key) {
|
||||
return std::binary_search(sorted_keys.begin(), sorted_keys.end(), key);
|
||||
}
|
||||
|
||||
} // namespace built_check
|
||||
275
gpu/vk/cache_set.h
Normal file
275
gpu/vk/cache_set.h
Normal file
@@ -0,0 +1,275 @@
|
||||
// (Triforce) One earlier set of the shader caches, for a change of a setting: the rule (vk_cache_set.cpp does the files).
|
||||
//
|
||||
// Why. Everything the game keeps of its shaders is kept for one stamp (vk_shader.cpp disk_stamp, program_cache_stamp): the
|
||||
// program cache (triforce_programs.bin), the pipeline cache (mkw_vk_pipelines.bin by its .for, and the play file), the
|
||||
// pipeline notes and the prepare's record. A start of another stamp drops all of them whole, and prepares every shader again:
|
||||
// on AMD's driver 1.5 to 2 hours (91,600 stage libraries at 16 a second, a cold precompile, the translation). Most stamps
|
||||
// change with the translator, and then nothing of the old set is any use again. Some change with a setting: the menu's Robust
|
||||
// buffers row (the translation's out-of-bounds buffer reads, vk_coopmat.cpp fetch_bounds_buffers), the mesh shaders row, a GPU
|
||||
// of a laptop's two, an RX_VK_ switch of the translation. Switching such a setting back made the same two hours again.
|
||||
// So: when the stamp changed and the build part did not (the translator and its C++ library, vk_shader.cpp
|
||||
// program_cache_build_part: what only a new build changes), the set there is kept, renamed to <name>.<stamp>.<ext>, when the
|
||||
// disk has room for it and for the new one (twice the set and 10 GB free). One set is kept, no more. A start whose stamp is the
|
||||
// kept set's puts it back (every piece, or none: a set with a piece missing or of another size is refused and deleted), and
|
||||
// the set it found takes its place as the kept one. A start of another build deletes the kept set: it is of no use to it.
|
||||
// What a start found, and what changed (triforce_cache_set.txt beside the caches, the parts of the stamp), is in the log.
|
||||
// The driver matches what it is handed by its own hash of the whole creation: a set put back is the very data the driver made
|
||||
// for that stamp, and the caches' own checks (the .for files, the program cache's head, the pipeline cache's device and UUID
|
||||
// header) still read it as they read any start's.
|
||||
// A set put back has the pipeline notes of its own time: what the player met while the other set was there is in the
|
||||
// player's state list (triforce_pipeline_states.bin, not a piece: it is good for any stamp). When that list is not the one
|
||||
// the set was kept with, kStatesPending asks the prepare before the title to go through the lists (vk_draw.cpp prepare_run,
|
||||
// state_list_prepare), as a prepare of every shader would have: those pipelines are built then, not at their first draw.
|
||||
// Files of a kept set's names that no record names (a start that ended in a swap, a record that cannot be read) are deleted
|
||||
// at the next start: no set is left on the disk that nothing knows of.
|
||||
// RX_VK_CACHE_SET=0: no set kept or put back (a change of stamp drops the caches, as before), and a kept set is deleted;
|
||||
// RX_VK_PCACHE_KEEP_OLD and RX_VK_NO_PROGRAM_CACHE leave it off too (a kept set of this build stays, another build's is
|
||||
// deleted). tests/test_cache_set.py (cache_set_files.h does the files)
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace cache_set {
|
||||
|
||||
// (every file kept for one stamp, as the game folder names it: vk_shader.cpp disk_init's two, vk_draw.cpp pcache_init's (the
|
||||
// carry's .base too, pcache_carry.h) and pcache_play_open's, the prepare's record and what prepare_run keeps beside it, the notes
|
||||
// and what vk_draw.cpp keeps beside them by the stamp. The first is the set's own: a set is the one its program cache's head names)
|
||||
inline constexpr const char* kPieces[] = {
|
||||
"triforce_programs.bin", "triforce_programs.idx",
|
||||
"mkw_vk_pipelines.bin", "mkw_vk_pipelines.bin.for",
|
||||
"mkw_vk_pipelines.bin.base", // (the carry's history of that file, by its stamp: pcache_carry.h)
|
||||
"mkw_vk_pipelines.bin.own", // ((Triforce) that file holds the driver's part's own alone: vk_draw.cpp pcache_own_mark)
|
||||
"mkw_vk_pipelines_play.bin", "mkw_vk_pipelines_play.bin.for",
|
||||
"triforce_prepared.bin", "triforce_prepared.bin.check",
|
||||
"triforce_prepared.bin.warming", "triforce_prepared.bin.warming.skip",
|
||||
"triforce_pipelines.bin", "triforce_pipelines.bin.predicted",
|
||||
"triforce_pipelines.bin.plan", "triforce_pipelines.bin.built",
|
||||
"triforce_states_applied.bin",
|
||||
};
|
||||
inline constexpr size_t kPieceCount = sizeof kPieces / sizeof kPieces[0];
|
||||
inline constexpr const char* kRecord = "triforce_cache_set.txt"; // (what the set there was made for)
|
||||
inline constexpr const char* kKept = "triforce_cache_set.kept.txt"; // (the kept set: what it was made for, and its pieces)
|
||||
inline constexpr const char* kStates = "triforce_pipeline_states.bin"; // (the player's state list, vk_draw.cpp: not a piece)
|
||||
inline constexpr const char* kStatesPending = "triforce_cache_set.states.txt"; // (a set put back: the lists to go through)
|
||||
inline constexpr uint32_t kProgramsMagic = 0x31505348; // (vk_shader.cpp kDiskMagic: the program cache's head)
|
||||
inline constexpr uint64_t kMargin = 10ull << 30; // (free beyond twice the set)
|
||||
|
||||
/// RX_VK_CACHE_SET: on unless it is 0
|
||||
inline bool on(const char* env) { return !(env && env[0] == '0' && !env[1]); }
|
||||
|
||||
/// A piece's name in the kept set: its name to the first '.', the stamp's 16 digits, the rest
|
||||
/// (mkw_vk_pipelines.bin.for: mkw_vk_pipelines.0123456789abcdef.bin.for)
|
||||
inline std::string kept_name(const std::string& live, uint64_t stamp) {
|
||||
char hex[20];
|
||||
std::snprintf(hex, sizeof hex, "%016llx", (unsigned long long)stamp);
|
||||
const size_t dot = live.find('.');
|
||||
if (dot == std::string::npos) return live + "." + hex;
|
||||
return live.substr(0, dot) + "." + hex + live.substr(dot);
|
||||
}
|
||||
|
||||
/// Whether a file's name is a piece's name in a kept set (kept_name's), and the stamp it names
|
||||
inline bool kept_piece_of(const std::string& file, uint64_t* stamp) {
|
||||
for (const char* p : kPieces) {
|
||||
const std::string live = p;
|
||||
const size_t dot = live.find('.');
|
||||
const std::string stem = live.substr(0, dot), rest = live.substr(dot);
|
||||
if (file.size() != stem.size() + 17 + rest.size() || file.compare(0, stem.size(), stem) || file[stem.size()] != '.' ||
|
||||
file.compare(file.size() - rest.size(), rest.size(), rest))
|
||||
continue;
|
||||
uint64_t v = 0;
|
||||
bool hex = true;
|
||||
for (size_t i = stem.size() + 1; i < stem.size() + 17 && hex; i++) {
|
||||
const char c = file[i];
|
||||
hex = (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f');
|
||||
v = v << 4 | (uint64_t)(c <= '9' ? c - '0' : c - 'a' + 10);
|
||||
}
|
||||
if (!hex) continue;
|
||||
*stamp = v;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// The stamp a program cache's first 16 bytes name (magic, the build that wrote it, the stamp); false: no program cache's head
|
||||
inline bool programs_head(const uint8_t* b, size_t n, uint64_t* stamp) {
|
||||
if (n < 16) return false;
|
||||
uint32_t magic;
|
||||
std::memcpy(&magic, b, 4);
|
||||
if (magic != kProgramsMagic) return false;
|
||||
std::memcpy(stamp, b + 8, 8);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// What a set was made for (the stamp, the build part, and the parts of the stamp by name for the log) and, for the kept
|
||||
/// one, its pieces as they were renamed: each one's name in the game folder and its size
|
||||
struct Record {
|
||||
uint64_t stamp = 0, build = 0;
|
||||
std::vector<std::pair<std::string, uint64_t>> parts;
|
||||
std::string env; // (the stamp's RX_VK_ and EDEN_ switches that were set, by name)
|
||||
uint64_t states = 0; // (the kept one: the player's state list as it was when kept, cache_set_files.h states_id; 0: none)
|
||||
std::vector<std::pair<std::string, uint64_t>> pieces;
|
||||
uint64_t bytes() const {
|
||||
uint64_t n = 0;
|
||||
for (const auto& p : pieces) n += p.second;
|
||||
return n;
|
||||
}
|
||||
};
|
||||
|
||||
inline std::string format(const Record& r) {
|
||||
std::string s = "triforce-cache-set 1\n";
|
||||
char line[160];
|
||||
std::snprintf(line, sizeof line, "stamp %016llx\nbuild %016llx\n", (unsigned long long)r.stamp, (unsigned long long)r.build);
|
||||
s += line;
|
||||
for (const auto& [name, v] : r.parts) {
|
||||
std::snprintf(line, sizeof line, "part %s %016llx\n", name.c_str(), (unsigned long long)v);
|
||||
s += line;
|
||||
}
|
||||
s += "env " + (r.env.empty() ? std::string("-") : r.env) + "\n";
|
||||
if (r.states) {
|
||||
std::snprintf(line, sizeof line, "states %016llx\n", (unsigned long long)r.states);
|
||||
s += line;
|
||||
}
|
||||
for (const auto& [name, size] : r.pieces) {
|
||||
std::snprintf(line, sizeof line, "piece %s %llu\n", name.c_str(), (unsigned long long)size);
|
||||
s += line;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
/// format's text read back; false when it is not one (no head, no stamp or build, a piece that is not one of kPieces)
|
||||
inline bool parse(const std::string& text, Record* out) {
|
||||
Record r;
|
||||
bool head = false, stamp = false, build = false;
|
||||
size_t at = 0;
|
||||
while (at < text.size()) {
|
||||
size_t end = text.find('\n', at);
|
||||
if (end == std::string::npos) end = text.size();
|
||||
std::string line = text.substr(at, end - at);
|
||||
at = end + 1;
|
||||
if (!line.empty() && line.back() == '\r') line.pop_back();
|
||||
if (line.empty()) continue;
|
||||
const size_t sp = line.find(' ');
|
||||
const std::string key = line.substr(0, sp), rest = sp == std::string::npos ? "" : line.substr(sp + 1);
|
||||
if (!head) {
|
||||
if (line != "triforce-cache-set 1") return false;
|
||||
head = true;
|
||||
continue;
|
||||
}
|
||||
unsigned long long v = 0;
|
||||
char name[96];
|
||||
if (key == "stamp" && std::sscanf(rest.c_str(), "%16llx", &v) == 1) {
|
||||
r.stamp = v, stamp = true;
|
||||
} else if (key == "build" && std::sscanf(rest.c_str(), "%16llx", &v) == 1) {
|
||||
r.build = v, build = true;
|
||||
} else if (key == "part" && std::sscanf(rest.c_str(), "%95s %16llx", name, &v) == 2) {
|
||||
r.parts.push_back({name, v});
|
||||
} else if (key == "states" && std::sscanf(rest.c_str(), "%16llx", &v) == 1) {
|
||||
r.states = v;
|
||||
} else if (key == "env") {
|
||||
r.env = rest == "-" ? "" : rest;
|
||||
} else if (key == "piece" && std::sscanf(rest.c_str(), "%95s %llu", name, &v) == 2) {
|
||||
bool known = false;
|
||||
for (const char* p : kPieces) known = known || !std::strcmp(p, name);
|
||||
if (!known) return false;
|
||||
r.pieces.push_back({name, v});
|
||||
}
|
||||
}
|
||||
if (!head || !stamp || !build) return false;
|
||||
*out = std::move(r);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// The parts by name whose value is not the same in a and b (a part only one of them has counts as changed), for the log
|
||||
inline std::vector<std::string> changed(const Record& a, const Record& b) {
|
||||
std::vector<std::string> out;
|
||||
if (a.build != b.build) out.push_back("build");
|
||||
const auto find = [](const Record& r, const std::string& name) -> const uint64_t* {
|
||||
for (const auto& p : r.parts)
|
||||
if (p.first == name) return &p.second;
|
||||
return nullptr;
|
||||
};
|
||||
for (const auto& p : a.parts) {
|
||||
const uint64_t* v = find(b, p.first);
|
||||
if (!v || *v != p.second) out.push_back(p.first);
|
||||
}
|
||||
for (const auto& p : b.parts)
|
||||
if (!find(a, p.first)) out.push_back(p.first);
|
||||
return out;
|
||||
}
|
||||
|
||||
/// Room for a set kept beside the new one: twice the set and kMargin free, counting what deleting the old kept set frees
|
||||
inline bool room(uint64_t free_bytes, uint64_t freed, uint64_t set_bytes) {
|
||||
const uint64_t have = free_bytes + freed < free_bytes ? ~0ull : free_bytes + freed;
|
||||
if (set_bytes > (~0ull - kMargin) / 2) return false;
|
||||
return have >= 2 * set_bytes + kMargin;
|
||||
}
|
||||
|
||||
/// What a start knows: its stamp and build part; the set there (its program cache's head, and the record of what it was made
|
||||
/// for when the record names that stamp); the kept set (its record, and whether every piece is there whole); the disk
|
||||
struct Facts {
|
||||
bool on = false; // (keeping and putting back allowed)
|
||||
bool off_forgets = false; // (off by RX_VK_CACHE_SET=0: a kept set of this build is deleted too, for its space)
|
||||
uint64_t stamp = 0, build = 0; // (this start's)
|
||||
bool live = false; // (a program cache there, its head read)
|
||||
uint64_t live_stamp = 0; // (what its head names)
|
||||
bool live_named = false; // (the record names live_stamp: live_build is known)
|
||||
uint64_t live_build = 0, live_bytes = 0;
|
||||
bool kept = false; // (a kept set's record)
|
||||
uint64_t kept_stamp = 0, kept_build = 0, kept_bytes = 0;
|
||||
bool kept_whole = false; // (each of its pieces there at its size, its program cache's head naming kept_stamp)
|
||||
bool space_known = false;
|
||||
uint64_t free_bytes = 0;
|
||||
};
|
||||
enum class Do {
|
||||
Same, // (the set there is this stamp's: nothing to do)
|
||||
Restore, // (the kept set is this stamp's: put back; keep_live: the set there becomes the kept one, else it is deleted)
|
||||
Keep, // (the set there is kept, renamed; the caches start empty for this stamp)
|
||||
Drop, // (nothing renamed: the caches drop the set there, as before)
|
||||
};
|
||||
struct Plan {
|
||||
Do what = Do::Drop;
|
||||
bool forget = false; // (the kept set is deleted first)
|
||||
bool keep_live = false; // (Restore: the set there is kept in its place)
|
||||
};
|
||||
|
||||
inline Plan decide(const Facts& f) {
|
||||
Plan p;
|
||||
const bool same = f.live && f.live_stamp == f.stamp;
|
||||
if (!f.on) {
|
||||
// (off: nothing kept or put back. A kept set of another build is of no use to any build again: deleted; one of this
|
||||
// build too when the off is RX_VK_CACHE_SET=0's, the switch that frees its space)
|
||||
p.what = same ? Do::Same : Do::Drop;
|
||||
p.forget = f.kept && (f.kept_build != f.build || f.off_forgets);
|
||||
return p;
|
||||
}
|
||||
bool kept_ours = f.kept && f.kept_build == f.build;
|
||||
// (another build's kept set is of no use to this one, nor to any later: deleted. A kept set that names the set there
|
||||
// is what a start that ended while it swapped the two left: its pieces are not where it says)
|
||||
p.forget = f.kept && (!kept_ours || (same && f.kept_stamp == f.stamp));
|
||||
if (same) {
|
||||
p.what = Do::Same;
|
||||
return p;
|
||||
}
|
||||
const bool live_ours = f.live && f.live_named && f.live_build == f.build;
|
||||
if (kept_ours && f.kept_stamp == f.stamp) {
|
||||
if (f.kept_whole) {
|
||||
p.what = Do::Restore;
|
||||
p.keep_live = live_ours;
|
||||
return p;
|
||||
}
|
||||
p.forget = true; // (a piece missing or cut: refused)
|
||||
}
|
||||
if (live_ours && f.space_known && room(f.free_bytes, f.kept ? f.kept_bytes : 0, f.live_bytes)) {
|
||||
p.what = Do::Keep;
|
||||
p.forget = f.kept; // (one set kept: the one there takes the old one's place)
|
||||
return p;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
} // namespace cache_set
|
||||
306
gpu/vk/cache_set_files.h
Normal file
306
gpu/vk/cache_set_files.h
Normal file
@@ -0,0 +1,306 @@
|
||||
// (Triforce) The kept set of the shader caches in the game folder: what a start finds there, and what it renames, deletes and
|
||||
// writes for cache_set.h's rule. The standard library and file_whole.h alone, nothing of the device: vk_cache_set.cpp gives it
|
||||
// this start's record (the stamp and its parts) and the switches, and tests/test_cache_set.py runs it on a folder of its own.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "cache_set.h"
|
||||
#include "file_whole.h"
|
||||
|
||||
namespace cache_set {
|
||||
|
||||
using Log = void (*)(const char* fmt, ...);
|
||||
|
||||
inline std::string stamp_hex(uint64_t s) {
|
||||
char hex[20];
|
||||
std::snprintf(hex, sizeof hex, "%016llx", (unsigned long long)s);
|
||||
return hex;
|
||||
}
|
||||
inline bool read_text(const std::string& path, std::string* out) {
|
||||
FILE* f = std::fopen(path.c_str(), "rb");
|
||||
if (!f) return false;
|
||||
char buf[4096];
|
||||
out->clear();
|
||||
for (size_t n; (n = std::fread(buf, 1, sizeof buf, f)) > 0 && out->size() < (1u << 20);) out->append(buf, n);
|
||||
std::fclose(f);
|
||||
return true;
|
||||
}
|
||||
inline bool read_record(const std::string& path, Record* r) {
|
||||
std::string text;
|
||||
return read_text(path, &text) && parse(text, r);
|
||||
}
|
||||
/// The stamp a program cache's head names
|
||||
inline bool head_of(const std::string& path, uint64_t* stamp) {
|
||||
FILE* f = std::fopen(path.c_str(), "rb");
|
||||
if (!f) return false;
|
||||
uint8_t b[16];
|
||||
const size_t n = std::fread(b, 1, sizeof b, f);
|
||||
std::fclose(f);
|
||||
return programs_head(b, n, stamp);
|
||||
}
|
||||
inline bool size_of(const std::string& path, uint64_t* size) {
|
||||
std::error_code ec;
|
||||
if (!std::filesystem::is_regular_file(path, ec) || ec) return false;
|
||||
const auto n = std::filesystem::file_size(path, ec);
|
||||
if (ec) return false;
|
||||
*size = (uint64_t)n;
|
||||
return true;
|
||||
}
|
||||
/// The pieces in the game folder by their names there, and their sizes
|
||||
inline std::vector<std::pair<std::string, uint64_t>> pieces_there(const std::string& dir) {
|
||||
std::vector<std::pair<std::string, uint64_t>> out;
|
||||
for (const char* p : kPieces) {
|
||||
uint64_t n = 0;
|
||||
if (size_of(dir + p, &n)) out.push_back({p, n});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
/// The player's state list (kStates) as it is now: its bytes hashed, with its size; 0 when there is none, or no record in it
|
||||
inline uint64_t states_id(const std::string& dir) {
|
||||
FILE* f = std::fopen((dir + kStates).c_str(), "rb");
|
||||
if (!f) return 0;
|
||||
uint64_t h = 0xCBF29CE484222325ull, total = 0;
|
||||
std::vector<uint8_t> buf(1 << 16);
|
||||
for (size_t n; (n = std::fread(buf.data(), 1, buf.size(), f)) > 0; total += n)
|
||||
for (size_t i = 0; i < n; i++) h = (h ^ buf[i]) * 1099511628211ull;
|
||||
std::fclose(f);
|
||||
for (int i = 0; i < 8; i++) h = (h ^ (uint8_t)(total >> (8 * i))) * 1099511628211ull;
|
||||
return total > 12 ? (h | 1) : 0; // (12: the list's head alone)
|
||||
}
|
||||
/// Every piece of the kept set there, at its size, and its program cache's head naming its stamp
|
||||
inline bool kept_whole(const std::string& dir, const Record& kept) {
|
||||
bool programs = false;
|
||||
for (const auto& [name, size] : kept.pieces) {
|
||||
const std::string at = dir + kept_name(name, kept.stamp);
|
||||
uint64_t n = 0;
|
||||
if (!size_of(at, &n) || n != size) return false;
|
||||
if (name == kPieces[0]) {
|
||||
uint64_t stamp = 0;
|
||||
if (!head_of(at, &stamp) || stamp != kept.stamp) return false;
|
||||
programs = true;
|
||||
}
|
||||
}
|
||||
return programs;
|
||||
}
|
||||
/// The kept set deleted: every piece its stamp names (what its record lists, and what a start cut short left), then its record
|
||||
inline void forget(const std::string& dir, const Record& kept) {
|
||||
for (const char* p : kPieces) {
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(dir + kept_name(p, kept.stamp), ec);
|
||||
}
|
||||
std::remove((dir + kKept).c_str());
|
||||
}
|
||||
/// The files of a kept set's names (kept_piece_of) that are not the kept set's (kept: its record read; kept_stamp: its stamp)
|
||||
/// deleted: what a start that ended in a swap left, or a set whose record cannot be read. Their count and bytes
|
||||
inline std::pair<size_t, uint64_t> sweep(const std::string& dir, bool kept, uint64_t kept_stamp) {
|
||||
std::pair<size_t, uint64_t> gone{0, 0};
|
||||
std::error_code ec;
|
||||
std::vector<std::filesystem::path> drop;
|
||||
for (std::filesystem::directory_iterator it(dir.empty() ? std::string(".") : dir, ec), end; !ec && it != end; it.increment(ec)) {
|
||||
std::error_code e2;
|
||||
if (!it->is_regular_file(e2) || e2) continue;
|
||||
uint64_t stamp = 0;
|
||||
if (!kept_piece_of(it->path().filename().string(), &stamp) || (kept && stamp == kept_stamp)) continue;
|
||||
drop.push_back(it->path());
|
||||
}
|
||||
for (const auto& p : drop) {
|
||||
std::error_code sized, removed;
|
||||
const auto n = std::filesystem::file_size(p, sized);
|
||||
if (std::filesystem::remove(p, removed) && !removed) gone.first++, gone.second += sized ? 0 : (uint64_t)n;
|
||||
}
|
||||
return gone;
|
||||
}
|
||||
/// Each file renamed (a file there in the way replaced), or none: one that cannot be leaves those done renamed back
|
||||
inline bool move_all(const std::vector<std::pair<std::string, std::string>>& moves, Log log) {
|
||||
for (size_t i = 0; i < moves.size(); i++) {
|
||||
if (file_writers::replace_file(moves[i].first, moves[i].second)) continue;
|
||||
log("vk: shader caches: %s cannot be renamed to %s: the set is left as it was", moves[i].first.c_str(),
|
||||
moves[i].second.c_str());
|
||||
for (size_t j = i; j-- > 0;) file_writers::replace_file(moves[j].second, moves[j].first);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
inline std::string joined(const std::vector<std::string>& v) {
|
||||
std::string s;
|
||||
for (const auto& x : v) s += (s.empty() ? "" : ", ") + (x == "robust" ? std::string("Robust buffers") : x);
|
||||
return s;
|
||||
}
|
||||
|
||||
/// The switches a start has (vk_cache_set.cpp reads them from the environment)
|
||||
struct Switches {
|
||||
bool on = true; // (RX_VK_CACHE_SET not 0, RX_VK_PCACHE_KEEP_OLD not set)
|
||||
bool off_forgets = false; // (off by RX_VK_CACHE_SET=0: a kept set is deleted)
|
||||
bool space_given = false; // (tests: the disk's free space as given, not as the disk says)
|
||||
uint64_t free_bytes = 0;
|
||||
};
|
||||
|
||||
/// The start's kept set decided and done in dir (its name ends in a separator, or is empty): now is this start's record (the
|
||||
/// stamp, the build part, the parts). What a start does before anything opens a cache
|
||||
inline Plan run(const std::string& dir, const Record& now, const Switches& sw, Log log) {
|
||||
Record had, kept;
|
||||
const bool had_read = read_record(dir + kRecord, &had);
|
||||
Facts f;
|
||||
f.on = sw.on, f.off_forgets = sw.off_forgets;
|
||||
f.stamp = now.stamp, f.build = now.build;
|
||||
f.kept = read_record(dir + kKept, &kept);
|
||||
// (no set is left there that nothing knows of: before the free space is measured, which it frees)
|
||||
const auto [swept, swept_bytes] = sweep(dir, f.kept, kept.stamp);
|
||||
if (swept)
|
||||
log("vk: shader caches: %zu files of a kept set no record names deleted (%llu MB: a start that ended while it swapped "
|
||||
"the sets, or a record that cannot be read)", swept, (unsigned long long)(swept_bytes >> 20));
|
||||
f.live = head_of(dir + kPieces[0], &f.live_stamp);
|
||||
f.live_named = f.live && had_read && had.stamp == f.live_stamp;
|
||||
f.live_build = had.build;
|
||||
const std::vector<std::pair<std::string, uint64_t>> live = pieces_there(dir);
|
||||
for (const auto& p : live) f.live_bytes += p.second;
|
||||
if (f.kept) {
|
||||
f.kept_stamp = kept.stamp, f.kept_build = kept.build, f.kept_bytes = kept.bytes();
|
||||
f.kept_whole = kept_whole(dir, kept);
|
||||
}
|
||||
if (sw.space_given) {
|
||||
f.space_known = true, f.free_bytes = sw.free_bytes;
|
||||
} else {
|
||||
std::error_code ec;
|
||||
const auto space = std::filesystem::space(dir.empty() ? std::string(".") : dir, ec);
|
||||
f.space_known = !ec;
|
||||
f.free_bytes = ec ? 0 : (uint64_t)space.available;
|
||||
}
|
||||
const Plan plan = decide(f);
|
||||
|
||||
if (f.live && f.live_stamp != f.stamp) { // (what changed, when it is known)
|
||||
std::string what = "not known: the set there has no record of what it was made for (a build before this rule)";
|
||||
if (f.live_named) {
|
||||
const std::vector<std::string> parts = changed(had, now);
|
||||
what = parts.empty() ? "a part of the translation's settings not named here (its per-GPU settings)" : joined(parts);
|
||||
if (had.env != now.env) what += "; the switches set: " + (had.env.empty() ? "none" : had.env) + " -> " +
|
||||
(now.env.empty() ? "none" : now.env);
|
||||
}
|
||||
log("vk: shader caches: made for %s, this start is %s: changed: %s", stamp_hex(f.live_stamp).c_str(),
|
||||
stamp_hex(f.stamp).c_str(), what.c_str());
|
||||
}
|
||||
if (plan.forget && f.kept) {
|
||||
forget(dir, kept);
|
||||
log("vk: shader caches: the kept set for %s (%llu MB) deleted: %s", stamp_hex(kept.stamp).c_str(),
|
||||
(unsigned long long)(kept.bytes() >> 20),
|
||||
kept.build != now.build ? "it is another build's"
|
||||
: !f.on ? "RX_VK_CACHE_SET=0"
|
||||
: !f.kept_whole && kept.stamp == now.stamp ? "a piece of it is missing or not its size"
|
||||
: "one set is kept, and this one takes its place");
|
||||
} else if (f.kept && !f.on) {
|
||||
log("vk: shader caches: the kept set for %s (%llu MB, as <name>.%s.<ext>) stays while it is off (RX_VK_PCACHE_KEEP_OLD; "
|
||||
"RX_VK_CACHE_SET=0 deletes it)", stamp_hex(kept.stamp).c_str(), (unsigned long long)(kept.bytes() >> 20),
|
||||
stamp_hex(kept.stamp).c_str());
|
||||
}
|
||||
const auto renames = [&](const std::vector<std::pair<std::string, uint64_t>>& pieces, uint64_t stamp, bool to_kept) {
|
||||
std::vector<std::pair<std::string, std::string>> m;
|
||||
for (const auto& p : pieces) {
|
||||
const std::string a = dir + p.first, b = dir + kept_name(p.first, stamp);
|
||||
m.push_back(to_kept ? std::make_pair(a, b) : std::make_pair(b, a));
|
||||
}
|
||||
return m;
|
||||
};
|
||||
if (plan.what == Do::Keep) {
|
||||
// (its record first: a start that ends while the pieces are renamed leaves a set the next one refuses and deletes)
|
||||
Record k = had;
|
||||
k.pieces = live;
|
||||
k.states = states_id(dir);
|
||||
if (!file_writers::write_whole(dir + kKept, format(k))) {
|
||||
log("vk: shader caches: %s cannot be written: the set there is not kept", kKept);
|
||||
} else if (!move_all(renames(live, f.live_stamp, true), log)) {
|
||||
std::remove((dir + kKept).c_str());
|
||||
} else {
|
||||
log("vk: shader caches: the set for %s kept (%llu MB, %zu files, as <name>.%s.<ext>): a start for it again puts it "
|
||||
"back, and its shaders are not prepared again (RX_VK_CACHE_SET=0: not kept). The caches start empty for "
|
||||
"this stamp", stamp_hex(f.live_stamp).c_str(), (unsigned long long)(f.live_bytes >> 20), live.size(),
|
||||
stamp_hex(f.live_stamp).c_str());
|
||||
}
|
||||
} else if (plan.what == Do::Restore) {
|
||||
bool ok = true;
|
||||
std::vector<std::pair<std::string, std::string>> aside;
|
||||
if (plan.keep_live) {
|
||||
aside = renames(live, f.live_stamp, true);
|
||||
ok = move_all(aside, log);
|
||||
}
|
||||
if (ok && !move_all(renames(kept.pieces, kept.stamp, false), log)) {
|
||||
ok = false;
|
||||
for (size_t j = aside.size(); j-- > 0;) file_writers::replace_file(aside[j].second, aside[j].first);
|
||||
}
|
||||
if (!ok) {
|
||||
log("vk: shader caches: the kept set for %s is not put back: the caches drop the set there, as before",
|
||||
stamp_hex(kept.stamp).c_str());
|
||||
} else {
|
||||
// (the pieces the kept set did not have are of the set there: theirs are another stamp's, or none)
|
||||
if (!plan.keep_live)
|
||||
for (const auto& p : live) {
|
||||
bool theirs = false;
|
||||
for (const auto& q : kept.pieces) theirs = theirs || q.first == p.first;
|
||||
if (!theirs) std::remove((dir + p.first).c_str());
|
||||
}
|
||||
const uint64_t states = states_id(dir);
|
||||
bool kept_now = false;
|
||||
if (plan.keep_live) {
|
||||
Record k = had;
|
||||
k.pieces = live;
|
||||
k.states = states;
|
||||
kept_now = file_writers::write_whole(dir + kKept, format(k));
|
||||
if (!kept_now) {
|
||||
for (const auto& p : live) std::remove((dir + kept_name(p.first, f.live_stamp)).c_str());
|
||||
std::remove((dir + kKept).c_str());
|
||||
}
|
||||
} else {
|
||||
std::remove((dir + kKept).c_str());
|
||||
}
|
||||
// (the player met pipelines while the set put back was not there: its notes lack them. The prepare before the
|
||||
// title goes through the state lists, and they are built before the game, as a prepare of every shader would)
|
||||
const bool lists = states && states != kept.states;
|
||||
if (lists && !file_writers::write_whole(dir + kStatesPending, "put back " + stamp_hex(kept.stamp) + "\n"))
|
||||
log("vk: shader caches: %s cannot be written: the pipelines met since the set was kept are built in play",
|
||||
kStatesPending);
|
||||
log("vk: shader caches: the kept set for %s put back (%llu MB, %zu files): its shaders are not prepared again%s%s",
|
||||
stamp_hex(kept.stamp).c_str(), (unsigned long long)(kept.bytes() >> 20), kept.pieces.size(),
|
||||
kept_now ? (", and the set for " + stamp_hex(f.live_stamp) + " is kept in its place").c_str()
|
||||
: plan.keep_live ? ", and the set there could not be kept: deleted" : "",
|
||||
lists ? "; the pipeline state list changed since it was kept: its pipelines are noted before the title" : "");
|
||||
}
|
||||
} else if (plan.what == Do::Drop && f.live && f.live_stamp != f.stamp) {
|
||||
const char* why = !f.on ? "RX_VK_CACHE_SET=0 or RX_VK_PCACHE_KEEP_OLD"
|
||||
: !f.live_named ? "what it was made for is not known"
|
||||
: f.live_build != f.build ? "another build of the translator made it: it is of no use again"
|
||||
: "the disk has no room for it beside a new one (twice the set and 10 GB free)";
|
||||
log("vk: shader caches: the set for %s (%llu MB) is not kept: %s; free %llu MB", stamp_hex(f.live_stamp).c_str(),
|
||||
(unsigned long long)(f.live_bytes >> 20), why, (unsigned long long)(f.free_bytes >> 20));
|
||||
}
|
||||
// (what the set there is made for from now on: this start's caches are written for its stamp)
|
||||
std::string text;
|
||||
const std::string want = format(now);
|
||||
if (!read_text(dir + kRecord, &text) || text != want)
|
||||
if (!file_writers::write_whole(dir + kRecord, want)) log("vk: shader caches: %s cannot be written", kRecord);
|
||||
return plan;
|
||||
}
|
||||
|
||||
/// A start that leaves the caches alone (RX_VK_NO_PROGRAM_CACHE: no program cache to say which set is there): a kept set of
|
||||
/// another build is still deleted, and files of a kept set's names that no record names
|
||||
inline void tidy(const std::string& dir, uint64_t build, Log log) {
|
||||
Record kept;
|
||||
const bool known = read_record(dir + kKept, &kept);
|
||||
const auto [swept, swept_bytes] = sweep(dir, known, kept.stamp);
|
||||
if (swept)
|
||||
log("vk: shader caches: %zu files of a kept set no record names deleted (%llu MB)", swept,
|
||||
(unsigned long long)(swept_bytes >> 20));
|
||||
if (known && kept.build != build) {
|
||||
forget(dir, kept);
|
||||
log("vk: shader caches: the kept set for %s (%llu MB) deleted: it is another build's", stamp_hex(kept.stamp).c_str(),
|
||||
(unsigned long long)(kept.bytes() >> 20));
|
||||
} else if (known) {
|
||||
log("vk: shader caches: the kept set for %s (%llu MB) stays: RX_VK_NO_PROGRAM_CACHE", stamp_hex(kept.stamp).c_str(),
|
||||
(unsigned long long)(kept.bytes() >> 20));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace cache_set
|
||||
64
gpu/vk/cap_spare.h
Normal file
64
gpu/vk/cap_spare.h
Normal file
@@ -0,0 +1,64 @@
|
||||
// (Triforce, 11-22, the performance audit's MEM-33, after Source A's) Which spare capture buffer a capture takes, how
|
||||
// much the spares and the ones being made ahead may hold together, and a capture's size in steps.
|
||||
//
|
||||
// A capture's buffer comes from the spares (retired buffers, and the 32 to 192 MB ones made ahead on a worker), or is
|
||||
// made new on the game's submitting thread. Three things were so before:
|
||||
// - the new buffer was made with cap_free_mu held (AMD's driver: about 0.8 ms a MB), and the replay's take, holding
|
||||
// pools_mu, waits on that mutex to retire a buffer;
|
||||
// - any spare that fit was taken, so a 2 MB capture could sit in a load's 192 MB spare for the 24 submissions a capture
|
||||
// is kept, and the load then made its own on the game's thread;
|
||||
// - a spare made ahead was made once: the one a load took was not made again.
|
||||
// The rules here are the decisions alone (no Vulkan, no lock): tests/test_capture_spare_reuse.py compiles them, and
|
||||
// vk_memory.cpp's cap_buf_get, cap_prewarm_class and cap_buf_free ask them. RX_VK_CAP_SPARE_FIT=0: as before.
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace cap_spare {
|
||||
|
||||
constexpr uint64_t kMB = 1ull << 20;
|
||||
constexpr uint64_t kBig = 32 * kMB; // (a load's spare: the classes made ahead start here)
|
||||
constexpr uint64_t kHeld = 768 * kMB; // (the most the spares hold, whatever the card)
|
||||
constexpr size_t kMost = 12; // (and the most there are)
|
||||
|
||||
/// A capture of size class `cls` leaves the spare of `size` bytes alone: a big one (32 MB or more) over twice its class.
|
||||
/// any_size: no spare is left alone (spares capped at 32 MB, the switch off, or the fallback after a failed allocation)
|
||||
constexpr bool skips(uint64_t size, uint64_t cls, bool any_size) { return !any_size && size >= kBig && size > 2 * cls; }
|
||||
|
||||
/// The spare a capture of `need` bytes (class `cls`) takes of n spares, size_of(i) the i-th one's bytes: the smallest that
|
||||
/// fits and is not left alone, the first of equals. n: none
|
||||
template <class SizeOf>
|
||||
constexpr size_t pick(size_t n, const SizeOf& size_of, uint64_t need, uint64_t cls, bool any_size) {
|
||||
size_t best = n;
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
const uint64_t s = size_of(i);
|
||||
if (s >= need && !skips(s, cls, any_size) && (best == n || s < size_of(best))) best = i;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/// Room for one more spare of `size` bytes to be made ahead: with what the spares hold and what is being made (reserved)
|
||||
/// it stays within what spares may hold (spare_max: the card's, cap_spare_max) and 768 MB
|
||||
constexpr bool room(uint64_t held, uint64_t reserved, uint64_t size, uint64_t spare_max) {
|
||||
const uint64_t limit = spare_max < kHeld ? spare_max : kHeld;
|
||||
return held + reserved <= limit && size <= limit - (held + reserved);
|
||||
}
|
||||
|
||||
/// A buffer of `size` bytes given back is kept as a spare: fewer than 12 with the ones being made (workers), none over 256
|
||||
/// MB (keep_old, RX_VK_CAPTURE_KEEP_OLD: 64), and with the bytes being made (reserved) within the limit. With no workers
|
||||
/// and nothing reserved this is the rule as it was
|
||||
constexpr bool keeps(size_t spares, size_t workers, uint64_t held, uint64_t reserved, uint64_t size, uint64_t spare_max, bool keep_old) {
|
||||
const uint64_t limit = keep_old ? spare_max : (spare_max < kHeld ? spare_max : kHeld);
|
||||
return spares + workers < kMost && size <= (keep_old ? 64 * kMB : 256 * kMB) && held + reserved <= limit &&
|
||||
size <= limit - (held + reserved);
|
||||
}
|
||||
|
||||
/// (RX_VK_CAP_STEP_MB=<n>, 0: off) a capture over 16 and up to 32 MB in steps of step_mb MB, not the whole 32 MB class,
|
||||
/// where spares are capped at 32 MB (a card of 6.5 GB or less). cls: its class as it is (cap_buf_size)
|
||||
constexpr uint64_t stepped(uint64_t need, uint64_t cls, uint64_t step_mb, bool capped) {
|
||||
if (!step_mb || !capped || cls != kBig || need <= 16 * kMB || need > kBig) return cls;
|
||||
const uint64_t step = step_mb * kMB, v = (need + step - 1) / step * step;
|
||||
return v < cls ? v : cls;
|
||||
}
|
||||
|
||||
} // namespace cap_spare
|
||||
110
gpu/vk/capture_tables.h
Normal file
110
gpu/vk/capture_tables.h
Normal file
@@ -0,0 +1,110 @@
|
||||
// (Triforce, 11-21, the upscaler audit's UPS-02) The stored draws' two tables, kept from one frame to the next.
|
||||
//
|
||||
// While NVIDIA DLSS, AMD FSR 4 or AMD FSR 3.1 upscales, every plain draw into the scene stores its positions and is drawn
|
||||
// again into the motion vectors (vk_temporal.cpp capture_motion). Two tables go with that, both filled again every frame:
|
||||
// the draws of a model so far this frame (which of them a draw is: the n-th this frame is the n-th the frame before), and
|
||||
// the frame before's draws by their key (where each one's positions of that frame are). Both were std::unordered_map,
|
||||
// emptied and filled each frame: a node from the heap for every entry and back to it a frame later, about 1,400 of each
|
||||
// a frame in the owner's log of 11-21 ("captured motion ... of 1444 stored a frame ... 0.650 ms CPU a frame"), on the
|
||||
// thread that records the frame. Here they keep their memory: the count in one open-addressed array (flat_map.h) that is
|
||||
// emptied in place, the frame before's draws in two lists that take turns, found through such an array. A frame of about
|
||||
// the size of the one before takes nothing from the heap.
|
||||
//
|
||||
// RX_VK_CAPTURE_TABLES=0: std::unordered_map again, a node an entry, as before (kept()).
|
||||
//
|
||||
// No Vulkan: tests/test_capture_tables.py compiles this and counts the heap's calls.
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <unordered_map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "flat_map.h"
|
||||
|
||||
namespace capture_tables {
|
||||
|
||||
/// RX_VK_CAPTURE_TABLES (value, null when unset): kept unless it is 0
|
||||
inline bool kept(const char* value) { return !value || !*value || std::atoi(value) != 0; }
|
||||
|
||||
/// An array emptied for the next frame: in place, so the frame fills it without the heap; given back when it is far
|
||||
/// larger than what the frame put in it (a frame of many draws once, then few), so emptying it does not walk all of that
|
||||
template <class K, class V>
|
||||
inline void empty_for_next(FlatMap<K, V>& m) {
|
||||
if (m.capacity() > 8 * (m.size() + 512)) m.clear();
|
||||
else m.reset();
|
||||
}
|
||||
|
||||
/// The room a frame's list is given at its start: the frame before's count (kept), so it grows once and not a dozen times
|
||||
/// from nothing; 0, as before, with the switch off
|
||||
inline size_t room(size_t taken, bool keep) { return keep ? taken : 0; }
|
||||
|
||||
/// How many of a model's draws came so far this frame
|
||||
class Nth {
|
||||
public:
|
||||
explicit Nth(bool keep = true) : keep_(keep) {}
|
||||
/// The draws of `model` before this one, which is counted
|
||||
int next(uint64_t model) { return keep_ ? flat_[model]++ : node_[model]++; }
|
||||
void clear() {
|
||||
if (keep_) empty_for_next(flat_);
|
||||
else node_.clear();
|
||||
}
|
||||
size_t size() const { return keep_ ? flat_.size() : node_.size(); }
|
||||
|
||||
private:
|
||||
bool keep_;
|
||||
FlatMap<uint64_t, int> flat_;
|
||||
std::unordered_map<uint64_t, int> node_;
|
||||
};
|
||||
|
||||
/// A frame's entries by key, and the frame before's: turn() makes what was put since the last turn the frame before's,
|
||||
/// put() notes one of this frame's (the last with a key stands), before() finds the frame before's
|
||||
template <class V>
|
||||
class Before {
|
||||
public:
|
||||
explicit Before(bool keep = true) : keep_(keep) {}
|
||||
void turn() {
|
||||
if (!keep_) {
|
||||
node_old_ = std::move(node_now_);
|
||||
node_now_.clear();
|
||||
return;
|
||||
}
|
||||
std::swap(now_, old_), std::swap(now_at_, old_at_);
|
||||
now_.clear(); // (its memory kept)
|
||||
empty_for_next(now_at_);
|
||||
}
|
||||
void put(uint64_t key, const V& v) {
|
||||
if (!keep_) {
|
||||
node_now_[key] = v;
|
||||
return;
|
||||
}
|
||||
uint32_t& at = now_at_[key]; // (the entry's place in now_, plus one: 0 is none yet)
|
||||
if (at) now_[at - 1] = v;
|
||||
else now_.push_back(v), at = (uint32_t)now_.size();
|
||||
}
|
||||
/// The frame before's entry of `key`, null when it had none: good until the next turn() or clear()
|
||||
const V* before(uint64_t key) {
|
||||
if (!keep_) {
|
||||
const auto it = node_old_.find(key);
|
||||
return it == node_old_.end() ? nullptr : &it->second;
|
||||
}
|
||||
const auto* s = old_at_.find(key);
|
||||
return s ? &old_[s->second - 1] : nullptr;
|
||||
}
|
||||
/// Nothing of either frame (the chain let go: its memory too)
|
||||
void clear() {
|
||||
std::vector<V>().swap(now_), std::vector<V>().swap(old_);
|
||||
now_at_.clear(), old_at_.clear();
|
||||
node_now_.clear(), node_old_.clear();
|
||||
}
|
||||
size_t size() const { return keep_ ? now_.size() : node_now_.size(); }
|
||||
|
||||
private:
|
||||
bool keep_;
|
||||
std::vector<V> now_, old_;
|
||||
FlatMap<uint64_t, uint32_t> now_at_, old_at_;
|
||||
std::unordered_map<uint64_t, V> node_now_, node_old_;
|
||||
};
|
||||
|
||||
} // namespace capture_tables
|
||||
@@ -23,6 +23,7 @@ inline const char* name(char c) {
|
||||
case 'u': return "upload of texture";
|
||||
case 'g': return "GPU unswizzle of texture";
|
||||
case 'w': return "write-back diff pass, chunks";
|
||||
case 's': return "mirror syncs' pass, chunks"; // ((Triforce, 11-21, MEM-48))
|
||||
case 'r': return "recording begun, value";
|
||||
case 'v': return "uploads of the recording, value";
|
||||
case 'z': return "recording ended, value";
|
||||
@@ -45,6 +46,9 @@ inline const char* gap(char c) {
|
||||
return "that pool's write-back copies (its mirror -> guest memory, and the shadow's fill), then the write-back diff pass if "
|
||||
"one follows (w): with no w after it, the end of the recording (z)";
|
||||
case 'u': case 'g': return "that texture's upload or unswizzle itself";
|
||||
case 's':
|
||||
return "the mirror syncs' pass (one compute dispatch in the recording's uploads, reading a capture's buffer and writing "
|
||||
"the pool's VRAM mirror by device address; RX_VK_MSYNC_PASS=0: copy regions), then the sync's copies from guest memory";
|
||||
case 'w':
|
||||
return "the write-back diff pass (one compute dispatch over every pool's chunks, reading mirrors and shadows and writing guest "
|
||||
"memory by device address), then its barrier and the end of the recording (z)";
|
||||
|
||||
120
gpu/vk/commit_room.h
Normal file
120
gpu/vk/commit_room.h
Normal file
@@ -0,0 +1,120 @@
|
||||
// (Triforce, 11-22, the performance audit's OS-05, after Source A's) The textures give commit back near Windows' commit limit,
|
||||
// and the page files' room to grow counts as commit still to come.
|
||||
//
|
||||
// Windows charges every block of a discrete card's memory to the process's commit, as it does the game's own memory. Where the
|
||||
// system's commit runs out (RAM and the page files full) an allocation is refused, and the game ends unless the refusal passes
|
||||
// (OS-04's wait, HOS_COMMIT_WAIT_MS, helps only if commit comes back). Source A takes the shortfall under a reserve of free
|
||||
// commit (2,560 MB) off the texture budget on any card, so that eviction and compaction give blocks back. Its first rule fired
|
||||
// while a page file Windows manages could still grow (292,526 textures retired in 90 minutes, black textures); the fix counts
|
||||
// each page file's room to grow, capped by its drive's free space, as commit still free.
|
||||
//
|
||||
// The rules here, apart from Windows so that tests/test_commit_room.py can run them:
|
||||
// - reserve_of: RX_VK_TEX_COMMIT_RESERVE_MB, the reserve. Off (0) unless set: the entry's 2560 is not measured on this tree
|
||||
// - growth_on: RX_VK_TEX_COMMIT_GROWTH, whether the growth is counted: 0 never, another number always, unset where a reserve is
|
||||
// - low_line, read_growth: the growth is read only while less is free than the higher of the reserve and the line of
|
||||
// tex_pressure::commit_low (whose fall-back to the fixed size then gets the growth too: vk_texture.cpp commit_now)
|
||||
// - cap: the textures at most what they hold less the shortfall under the reserve, never under 1 GB (Source A has no floor,
|
||||
// and its false cut went to 0)
|
||||
// - growth: the page files' room to grow, from the records of NtQuerySystemInformation's class 0x90 (undocumented: each
|
||||
// record is checked against the buffer, and one that is not inside it ends the walk), a drive's page files capped together
|
||||
// by its free space. vk_texture.cpp page_file_growth asks Windows, at most once a second, and answers 0 on any failure.
|
||||
// Written from the audit's description: Source A's file is not on this PC.
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace commit_room {
|
||||
|
||||
inline constexpr uint64_t kFloor = 1ull << 30; // (the textures are never capped under 1 GB)
|
||||
inline constexpr int64_t kMostMb = 65536; // (the reserve at most)
|
||||
|
||||
/// RX_VK_TEX_COMMIT_RESERVE_MB in bytes: 0 (unset, empty, no number, 0 or less): no cut, as before; at most kMostMb MB
|
||||
inline uint64_t reserve_of(const char* env) {
|
||||
if (!env || !*env) return 0;
|
||||
const long long mb = std::atoll(env);
|
||||
return mb <= 0 ? 0 : (uint64_t)std::min<long long>(mb, kMostMb) << 20;
|
||||
}
|
||||
|
||||
/// RX_VK_TEX_COMMIT_GROWTH: unset or empty, counted where a reserve is set; 0 (or no number), never; another number, always
|
||||
inline bool growth_on(const char* env, uint64_t reserve) {
|
||||
if (!env || !*env) return reserve != 0;
|
||||
return std::atoi(env) != 0;
|
||||
}
|
||||
|
||||
/// tex_pressure::commit_low's line in bytes: want_mb MB; -1 (less than 0) the larger of 4 GB and a tenth of the limit; 0, or a
|
||||
/// limit not known (0), none
|
||||
inline uint64_t low_line(uint64_t limit, int64_t want_mb) {
|
||||
if (!limit || !want_mb) return 0;
|
||||
return want_mb > 0 ? (uint64_t)want_mb << 20 : std::max<uint64_t>(4096ull << 20, limit / 10);
|
||||
}
|
||||
|
||||
/// Whether the page files' growth is read at this look: counted (on), and less free (avail) than the higher of the reserve and
|
||||
/// commit_low's line (low)
|
||||
inline bool read_growth(bool on, uint64_t avail, uint64_t reserve, uint64_t low) { return on && avail < std::max(reserve, low); }
|
||||
|
||||
/// The textures' cap: what they hold (total) less the shortfall of what is free (avail, the growth in it) under the reserve,
|
||||
/// never under kFloor. UINT64_MAX (no cap) with no reserve, or with the reserve free
|
||||
inline uint64_t cap(uint64_t total, uint64_t avail, uint64_t reserve) {
|
||||
if (!reserve || avail >= reserve) return UINT64_MAX;
|
||||
const uint64_t shortfall = reserve - avail;
|
||||
return std::max(kFloor, total > shortfall ? total - shortfall : 0);
|
||||
}
|
||||
|
||||
/// NtQuerySystemInformation's class for the page files' records (SystemPageFileInformationEx)
|
||||
inline constexpr unsigned kPageFileClass = 0x90;
|
||||
|
||||
/// One record of that class as 64-bit Windows lays it out; sizes in pages
|
||||
struct PageFileRecord {
|
||||
uint32_t next; // (bytes from this record to the next; 0: the last)
|
||||
uint32_t total_pages; // (its size now)
|
||||
uint32_t in_use_pages, peak_pages;
|
||||
uint16_t name_bytes, name_room; // (the name: UTF-16, such as \??\C:\pagefile.sys, in the same buffer)
|
||||
const uint16_t* name;
|
||||
uint32_t min_pages, max_pages; // (the size it may grow to)
|
||||
};
|
||||
static_assert(sizeof(void*) != 8 || sizeof(PageFileRecord) == 40, "the record as 64-bit Windows lays it out");
|
||||
|
||||
/// The drive letter of a page file's name ('C' for \??\C:\pagefile.sys), 0 where it has none
|
||||
inline char drive_of(const uint16_t* name, size_t chars) {
|
||||
for (size_t i = 0; i + 1 < chars; i++) {
|
||||
const uint16_t c = name[i];
|
||||
if (name[i + 1] == ':' && ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))) return (char)(c >= 'a' ? c - 32 : c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// The page files' room to grow in bytes, from the records in buf[0, len): a record's (max - size) pages of `page` bytes, the
|
||||
/// records of one drive summed and capped by that drive's free space (free_of('C'), bytes). A record that is not wholly inside
|
||||
/// the buffer, whose name is not, or whose next one would overlap it, ends the walk: what came before it counts
|
||||
template <class FreeOf>
|
||||
inline uint64_t growth(const uint8_t* buf, size_t len, uint64_t page, FreeOf free_of) {
|
||||
uint64_t by_drive[26] = {};
|
||||
const uintptr_t base = (uintptr_t)buf;
|
||||
for (size_t at = 0; len >= sizeof(PageFileRecord) && at <= len - sizeof(PageFileRecord);) {
|
||||
PageFileRecord r;
|
||||
std::memcpy(&r, buf + at, sizeof r);
|
||||
char drive = 0;
|
||||
if (r.name_bytes) {
|
||||
const uintptr_t n = (uintptr_t)r.name;
|
||||
if (n < base || n - base > len || r.name_bytes > len - (n - base)) break;
|
||||
uint16_t chars[64] = {};
|
||||
const size_t count = std::min<size_t>(r.name_bytes / 2, 64);
|
||||
std::memcpy(chars, buf + (n - base), count * 2);
|
||||
drive = drive_of(chars, count);
|
||||
}
|
||||
if (drive && r.max_pages > r.total_pages) by_drive[drive - 'A'] += (uint64_t)(r.max_pages - r.total_pages) * page;
|
||||
if (!r.next) break;
|
||||
if (r.next < sizeof r || r.next > len - at) break;
|
||||
at += r.next;
|
||||
}
|
||||
uint64_t sum = 0;
|
||||
for (int d = 0; d < 26; d++)
|
||||
if (by_drive[d]) sum += std::min<uint64_t>(by_drive[d], free_of((char)('A' + d)));
|
||||
return sum;
|
||||
}
|
||||
|
||||
} // namespace commit_room
|
||||
125
gpu/vk/compute_pin.h
Normal file
125
gpu/vk/compute_pin.h
Normal file
@@ -0,0 +1,125 @@
|
||||
// Which compute programs are held to 32 lanes (requiredSubgroupSize), by what the program can tell (no game, no GPU: a rule).
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's PIPE-52, after Source A's and Source B's.) The console's programs are written
|
||||
// for warps of 32 lanes, so every compute pipeline asked for subgroups of 32 (vk_draw.cpp pin_subgroup). Most programs
|
||||
// cannot tell how many lanes run beside them: they never vote, never read a lane mask or their lane's index, never
|
||||
// shuffle between lanes. Mesa's Intel driver compiles a pinned program for 32 lanes only (SIMD32), which on its large
|
||||
// programs is minutes and gigabytes: Source A measured a 730 KB program at 0.8-1 GB over 23-25 s pinned and at most 300 MB
|
||||
// unpinned (an Iris Xe, Mesa 26.2.4), with 271 of 1046 variants still pinned by this rule.
|
||||
//
|
||||
// A program is pinned when it can see its lanes:
|
||||
// - a vote, a lane mask, the lane's index, a shuffle, FSWZADD or a matrix multiply (Shader::Info's flags);
|
||||
// - a barrier of Subgroup scope in its module: this translator's own case, the barrier its lowering puts between a
|
||||
// warp's shared-memory store and load, which takes the subgroup to be the warp. No flag records it, so the module is
|
||||
// looked at (subgroup_barrier below), and a module nobody looked at counts as having one;
|
||||
// - shared memory in a workgroup of 32 invocations or fewer, where the workgroup is one warp and its lanes run in step.
|
||||
// Everything else gets the driver's own choice: no required size, and no full-subgroups flag either.
|
||||
//
|
||||
// RX_VK_COMPUTE_PIN, read once:
|
||||
// all every compute program pinned, as it was (the default on every driver but Mesa's Intel one)
|
||||
// lanes the rule above (the default on Mesa's Intel driver)
|
||||
// shared the rule above, and any shared memory pins, whatever the workgroup: for a program whose warps keep
|
||||
// shared memory in step in a workgroup over 32, which nothing else here sees
|
||||
// A doubt pins: an unknown value of the switch is the driver's default, a program without a stage is pinned.
|
||||
// The graphics stages and the mesh fallback's compute stages are not asked here: they stay with pin_subgroup.
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace compute_pin {
|
||||
enum class Mode { All, Lanes, Shared };
|
||||
|
||||
/// What one compute program is, as the rule needs it
|
||||
struct Facts {
|
||||
bool has_stage = false; // (false: nothing known, pinned)
|
||||
bool vote = false; // Shader::Info::uses_subgroup_vote
|
||||
bool mask = false; // uses_subgroup_mask
|
||||
bool lane_index = false; // uses_subgroup_invocation_id
|
||||
bool shuffles = false; // uses_subgroup_shuffles
|
||||
bool fswzadd = false; // uses_fswzadd
|
||||
bool matrices = false; // uses_cooperative_matrix
|
||||
bool subgroup_barrier = true; // its module has an OpControlBarrier of Subgroup scope (true until a look says no)
|
||||
uint32_t shared_memory = 0; // bytes of shared memory
|
||||
uint64_t invocations = 0; // the workgroup's x * y * z
|
||||
};
|
||||
|
||||
/// The program can tell how many lanes run in its subgroup, or which one it is
|
||||
constexpr bool sees_lanes(const Facts& f) {
|
||||
return f.vote || f.mask || f.lane_index || f.shuffles || f.fswzadd || f.matrices || f.subgroup_barrier;
|
||||
}
|
||||
|
||||
/// RX_VK_COMPUTE_PIN's value (nullptr: unset) on this driver
|
||||
inline Mode mode_for(const char* env, bool mesa_intel) {
|
||||
if (env && !std::strcmp(env, "all")) return Mode::All;
|
||||
if (env && !std::strcmp(env, "lanes")) return Mode::Lanes;
|
||||
if (env && !std::strcmp(env, "shared")) return Mode::Shared;
|
||||
return mesa_intel ? Mode::Lanes : Mode::All;
|
||||
}
|
||||
|
||||
inline const char* name(Mode m) {
|
||||
return m == Mode::All ? "all" : m == Mode::Lanes ? "lanes" : "shared";
|
||||
}
|
||||
|
||||
/// The program's pipeline asks for subgroups of 32
|
||||
constexpr bool needed(Mode m, const Facts& f) {
|
||||
if (m == Mode::All || !f.has_stage) return true;
|
||||
if (sees_lanes(f)) return true;
|
||||
if (f.shared_memory) return m == Mode::Shared || f.invocations <= 32;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Whether a SPIR-V module's entry point is a compute shader's (OpEntryPoint with the GLCompute model): the only modules
|
||||
/// the rule is asked about, so the only ones worth a note. One that does not read as SPIR-V: no
|
||||
inline bool compute_entry(const uint32_t* code, size_t words) {
|
||||
constexpr uint32_t kMagic = 0x07230203, kOpEntryPoint = 15, kOpFunction = 54, kGLCompute = 5;
|
||||
if (!code || words < 5 || code[0] != kMagic) return false;
|
||||
for (size_t at = 5; at < words;) {
|
||||
const uint32_t count = code[at] >> 16, op = code[at] & 0xffffu;
|
||||
if (!count || at + count > words || op == kOpFunction) return false;
|
||||
if (op == kOpEntryPoint && count >= 2) return code[at + 1] == kGLCompute;
|
||||
at += count;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// Whether a SPIR-V module has an OpControlBarrier whose execution scope is the constant Subgroup (3). A module that does
|
||||
/// not read as SPIR-V counts as having one. words: the module's 32-bit words
|
||||
inline bool subgroup_barrier(const uint32_t* code, size_t words) {
|
||||
constexpr uint32_t kMagic = 0x07230203, kOpConstant = 43, kOpControlBarrier = 224, kScopeSubgroup = 3;
|
||||
if (!code || words < 5 || code[0] != kMagic) return true;
|
||||
// (the scopes are constants, and constants come before the functions: one pass for the barriers' scope ids, kept small,
|
||||
// and their values looked up at the end)
|
||||
constexpr size_t kMost = 64;
|
||||
uint32_t scopes[kMost];
|
||||
size_t n_scopes = 0;
|
||||
for (size_t at = 5; at < words;) {
|
||||
const uint32_t count = code[at] >> 16, op = code[at] & 0xffffu;
|
||||
if (!count || at + count > words) return true;
|
||||
if (op == kOpControlBarrier && count >= 4) {
|
||||
const uint32_t id = code[at + 1];
|
||||
bool seen = false;
|
||||
for (size_t i = 0; i < n_scopes; i++) seen = seen || scopes[i] == id;
|
||||
if (!seen) {
|
||||
if (n_scopes == kMost) return true; // (more scope ids than a module has: a doubt)
|
||||
scopes[n_scopes++] = id;
|
||||
}
|
||||
}
|
||||
at += count;
|
||||
}
|
||||
if (!n_scopes) return false;
|
||||
size_t resolved = 0;
|
||||
for (size_t at = 5; at < words;) {
|
||||
const uint32_t count = code[at] >> 16, op = code[at] & 0xffffu;
|
||||
if (op == kOpConstant && count >= 4) {
|
||||
for (size_t i = 0; i < n_scopes; i++)
|
||||
if (scopes[i] == code[at + 2]) {
|
||||
if (code[at + 3] == kScopeSubgroup) return true;
|
||||
resolved++;
|
||||
}
|
||||
}
|
||||
at += count;
|
||||
}
|
||||
return resolved != n_scopes; // (a scope that is no plain constant: a doubt)
|
||||
}
|
||||
} // namespace compute_pin
|
||||
41
gpu/vk/cpu_count.h
Normal file
41
gpu/vk/cpu_count.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// (Triforce, 11-22, the performance audit's OS-49, after Source B's) The logical processors the renderer sizes its pools and
|
||||
// its threads' counts by: std::thread::hardware_concurrency, or, while the lab's HOS_SIM_CPU=<cores>/<threads> holds the
|
||||
// process to fewer of the PC's cores (host/hos_sim_cpu.h), its <threads>: an affinity mask alone does not change what
|
||||
// hardware_concurrency answers, and the pools would be a 24-thread PC's on 6 cores. The host clears the variable when it did
|
||||
// not apply it, so the two agree. Windows only, as the host's part; unset, hardware_concurrency as before. Every such count in
|
||||
// gpu/ goes through cpu_count() but vk_shader.cpp's (a file the shader cache's stamp is made from):
|
||||
// tests/test_sim_cores.py checks that, and the rule.
|
||||
#pragma once
|
||||
#include <cstdlib>
|
||||
#include <thread>
|
||||
|
||||
namespace cpu_count_rule {
|
||||
/// The threads HOS_SIM_CPU asks for ("6/12": 12; "6": 6), when fewer than the PC's hw (0: not known); else 0: not set, not
|
||||
/// "<cores>[/<threads>]" with each from 1 to 256 and threads not under cores, or not fewer
|
||||
inline unsigned sim_threads(const char* e, unsigned hw) {
|
||||
if (!e || !*e) return 0;
|
||||
char* end = nullptr;
|
||||
const long c = std::strtol(e, &end, 10);
|
||||
if (end == e) return 0;
|
||||
long t = c;
|
||||
if (*end == '/') {
|
||||
const char* s = end + 1;
|
||||
t = std::strtol(s, &end, 10);
|
||||
if (end == s) return 0;
|
||||
}
|
||||
if (*end || c < 1 || c > 256 || t < c || t > 256) return 0;
|
||||
return hw && (unsigned)t >= hw ? 0 : (unsigned)t;
|
||||
}
|
||||
} // namespace cpu_count_rule
|
||||
|
||||
/// The logical processors to size by (read once)
|
||||
inline unsigned cpu_count() {
|
||||
static const unsigned n = [] {
|
||||
const unsigned hw = std::thread::hardware_concurrency();
|
||||
#ifdef _WIN32
|
||||
if (const unsigned sim = cpu_count_rule::sim_threads(std::getenv("HOS_SIM_CPU"), hw)) return sim;
|
||||
#endif
|
||||
return hw;
|
||||
}();
|
||||
return n;
|
||||
}
|
||||
39
gpu/vk/dead_count.h
Normal file
39
gpu/vk/dead_count.h
Normal file
@@ -0,0 +1,39 @@
|
||||
// (Triforce, 11-21, the performance audit's THREAD-21, its first step) What destroying the dead images costs a present.
|
||||
//
|
||||
// A texture let go waits in a list until the GPU is done with it, and texture_frame then destroys every one that is, in
|
||||
// the middle of the present being recorded: a render target's image goes to the pool (cheap), every other image is
|
||||
// destroyed with its views. The audit's port bounds that to a share a present, after the present's submit, as Source B
|
||||
// does on its GPU thread's idle moments. Its own proof asks for the cost first: "if no present spends 3 ms in the loop,
|
||||
// stop". This is that count, and nothing else changes: a line for a present whose loop took kSayMs or more, and every
|
||||
// 600 presents the totals and the worst present.
|
||||
//
|
||||
// No Vulkan here: tests/test_dead_count.py compiles it.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace dead_count {
|
||||
|
||||
inline constexpr double kSayMs = 2.0; // (a present's loop that gets a line of its own)
|
||||
inline constexpr double kWorthMs = 3.0; // (the audit's line: under it in every present, the bounded step is not built)
|
||||
inline constexpr uint64_t kReport = 600; // (presents between the totals' lines)
|
||||
|
||||
struct Counts {
|
||||
uint64_t presents = 0, destroyed = 0, pooled = 0, over_say = 0, over_worth = 0;
|
||||
double ms = 0, worst_ms = 0;
|
||||
uint64_t worst_destroyed = 0, worst_left = 0;
|
||||
/// A present's loop: n_destroyed images destroyed and n_pooled put in the pool in loop_ms, left still waiting. True
|
||||
/// when the present gets a line of its own
|
||||
bool note(uint64_t n_destroyed, uint64_t n_pooled, double loop_ms, uint64_t left) {
|
||||
presents++, destroyed += n_destroyed, pooled += n_pooled, ms += loop_ms;
|
||||
if (loop_ms > worst_ms) worst_ms = loop_ms, worst_destroyed = n_destroyed, worst_left = left;
|
||||
if (loop_ms >= kWorthMs) over_worth++;
|
||||
if (loop_ms < kSayMs) return false;
|
||||
over_say++;
|
||||
return true;
|
||||
}
|
||||
/// Whether the totals' line is due, at present `present`
|
||||
bool due(uint64_t present) const { return presents != 0 && present % kReport == 0; }
|
||||
void reset() { *this = Counts{}; }
|
||||
};
|
||||
|
||||
} // namespace dead_count
|
||||
@@ -1,41 +0,0 @@
|
||||
// (Triforce) The Debug tab's value cells: how wide they are, and whether the tools stand in two columns (vk_menu.cpp
|
||||
// draw_debug_rows measures the texts and draws; the arithmetic is here so that tests/test_debug_tab_layout.py can run it).
|
||||
//
|
||||
// The tab has the Debug tools switch across its top, the tools under their groups' headings in one column or two, and the
|
||||
// Developer rows across its foot. The cells of what stands under one another are one width, so their left edges line up:
|
||||
// a column's tools alike, and the switch and the Developer rows, which span the columns, alike. A Developer row of more
|
||||
// than two values asks more than Off and On: before, it alone was wider than the rows around it.
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace mkwvk::debug_tab {
|
||||
|
||||
struct Widths {
|
||||
bool two = false; // (the tools in two columns)
|
||||
float cell[2] = {}; // (a column's tools' cells; both the same in one column)
|
||||
float span = 0; // (the switch's and the Developer rows' cells)
|
||||
};
|
||||
|
||||
/// col_w: a column's width when there are two; room: the tab's width. name_need: the longest name of each column with its
|
||||
/// room in the name's cell; cell_full and cell_tight: what the column's widest cell asks, and its narrowest. span_need: what
|
||||
/// the widest of the switch's and the Developer rows' cells asks.
|
||||
/// Two columns only when each holds its longest name whole beside its cells at their narrowest; the cells are then as wide
|
||||
/// as the name leaves them, up to what they ask, and the spanning cells as wide as the second column's (they end at the
|
||||
/// same edge) or as they ask. In one column every cell is one width: what the widest of all asks, less only when the
|
||||
/// longest name needs the room, and never under the narrowest
|
||||
inline Widths widths(float col_w, float room, const float name_need[2], const float cell_full[2], const float cell_tight[2], float span_need) {
|
||||
Widths w;
|
||||
w.two = col_w >= name_need[0] + cell_tight[0] && col_w >= name_need[1] + cell_tight[1];
|
||||
if (w.two) {
|
||||
for (int k = 0; k < 2; k++) w.cell[k] = std::max(cell_tight[k], std::min(cell_full[k], col_w - name_need[k]));
|
||||
w.span = std::max(span_need, w.cell[1]);
|
||||
} else {
|
||||
const float widest = std::max({cell_full[0], cell_full[1], span_need});
|
||||
const float narrowest = std::max(cell_tight[0], cell_tight[1]);
|
||||
w.cell[0] = w.cell[1] = w.span = std::max(std::min(widest, room - std::max(name_need[0], name_need[1])), narrowest);
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
} // namespace mkwvk::debug_tab
|
||||
67
gpu/vk/desc_counts.h
Normal file
67
gpu/vk/desc_counts.h
Normal file
@@ -0,0 +1,67 @@
|
||||
// A program's descriptor counts kept with the program (no game, no GPU: a rule; vk_shader.h Program::desc_n, vk_draw.cpp
|
||||
// build_descriptors).
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's DESC-22, after Source A's.) build_descriptors sums the program's buffers,
|
||||
// images and texel views at every build, six lists a stage, only to size three reserve() calls that keep the pointers
|
||||
// it hands the writes stable. The sums are fixed once the program is translated: its stages are filled before it is
|
||||
// ready and never after. So the three are packed into one word kept on the program, stored at its first build once
|
||||
// ready and read at every later one; a word that is not a count walks as before.
|
||||
//
|
||||
// The word is 32 bits because that is what the program has room for: the padding after Program::ready. The struct must
|
||||
// not grow: sizeof(Program) is in the program cache's stamp, and a change of it throws every player's caches away. So
|
||||
// three counts of 10 bits; a program with more than 1023 of a kind is not kept (kUnset is what its pack gives) and walks
|
||||
// at every build, as before.
|
||||
//
|
||||
// A short count would let a vector move in the middle of a build and leave the writes with stale pointers. It cannot
|
||||
// come from the walk that stores it, but the build checks all the same that none of the three moved, and a program
|
||||
// whose did is marked kNever, walked from then on, and built again at once.
|
||||
//
|
||||
// RX_VK_DESC_COUNTS=0: the walk at every build, as before. The lab's knob "descwalk" does the same in its phases.
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace mkwvk::desc_counts {
|
||||
|
||||
inline constexpr uint32_t kUnset = ~0u; // not counted yet, or too many of a kind to pack
|
||||
inline constexpr uint32_t kNever = 0xFFFFFFFEu; // its kept counts were short once: walked at every build from then on
|
||||
inline constexpr uint32_t kMost = 1023; // the most of a kind a word holds (10 bits)
|
||||
|
||||
/// RX_VK_DESC_COUNTS: on unless set to 0
|
||||
inline bool on(const char* env) {
|
||||
return !env || std::atoi(env) != 0;
|
||||
}
|
||||
|
||||
/// The three counts as one word, or kUnset where one does not fit
|
||||
constexpr uint32_t pack(size_t bufs, size_t imgs, size_t views) {
|
||||
if (bufs > kMost || imgs > kMost || views > kMost) return kUnset;
|
||||
return (uint32_t)bufs | (uint32_t)imgs << 10 | (uint32_t)views << 20;
|
||||
}
|
||||
|
||||
/// Whether the word holds counts (its two top bits are clear: kUnset and kNever have them set)
|
||||
constexpr bool holds(uint32_t word) {
|
||||
return (word >> 30) == 0;
|
||||
}
|
||||
|
||||
/// The counts of a word that holds them; false, and nothing written, for one that does not (walk)
|
||||
constexpr bool unpack(uint32_t word, size_t* bufs, size_t* imgs, size_t* views) {
|
||||
if (!holds(word)) return false;
|
||||
*bufs = word & kMost, *imgs = (word >> 10) & kMost, *views = (word >> 20) & kMost;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Whether a build that walked stores its counts: the rule on, the program translated (its stages do not change after),
|
||||
/// and the word still unset (never over kNever)
|
||||
constexpr bool stores(bool on, bool ready, uint32_t word) {
|
||||
return on && ready && word == kUnset;
|
||||
}
|
||||
|
||||
/// The guard at a build's end: whether one of the three vectors' storage moved since the reserve (before/after: their
|
||||
/// data() pointers), in a build that went by kept counts. A build that walked reserved exactly, as it always did
|
||||
constexpr bool moved(bool walked, const void* bufs0, const void* bufs1, const void* imgs0, const void* imgs1, const void* views0,
|
||||
const void* views1) {
|
||||
return !walked && (bufs0 != bufs1 || imgs0 != imgs1 || views0 != views1);
|
||||
}
|
||||
|
||||
} // namespace mkwvk::desc_counts
|
||||
97
gpu/vk/desc_pool_grow.h
Normal file
97
gpu/vk/desc_pool_grow.h
Normal file
@@ -0,0 +1,97 @@
|
||||
// A recording slot's descriptor pool, made at half size and made whole once a recording runs out of it (no game, no GPU:
|
||||
// a rule; vk_draw.cpp make_pool, slot_reset_locked, draw_begin_recording).
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's DESC-33, after Source A's.) Each of the recording slots (48 at most) keeps a
|
||||
// descriptor pool of 8192 sets and up to 32768 descriptors a type, and the driver may keep host memory for all of that,
|
||||
// 48 times. Few recordings come near it: Source A saw one take at most 289 sets on a desktop card, and no pool at half
|
||||
// size run out in three scenes on a handheld. So a slot's pool starts at half (4096 sets, 16384 uniform buffers and
|
||||
// combined image samplers, and so on down the types).
|
||||
//
|
||||
// A recording that runs out is given a whole extra pool, as it always was (bind_descriptors), and that is the mark: at
|
||||
// the slot's next reset, where the extra pools are destroyed anyway, a slot that has any and whose own pool is not whole
|
||||
// has it destroyed and made again whole. From then on the slot is as it was before this rule. A busy slot so pays one
|
||||
// extra pool, once.
|
||||
//
|
||||
// RX_VK_DESC_POOL_GROW=0: whole pools from the start, as before. RX_VK_DESC_POOL_DIV=<n> still divides both sizes.
|
||||
// What the recordings took (sets and descriptors a type, the most one recording took of each) and how many pools were
|
||||
// added and slots made whole go into the log's "recording streams" line, so a size can be judged from a run's log.
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace mkwvk::desc_pool_grow {
|
||||
|
||||
/// RX_VK_DESC_POOL_GROW: on unless set to 0
|
||||
inline bool on(const char* env) {
|
||||
return !env || std::atoi(env) != 0;
|
||||
}
|
||||
|
||||
/// A whole pool's sets, and its descriptors by type in the order of Took::n
|
||||
inline constexpr uint32_t kSets = 8192;
|
||||
enum Kind { kUniform, kStorage, kSampled, kStorageImage, kUniformTexel, kStorageTexel, kKinds };
|
||||
inline constexpr uint32_t kWhole[kKinds] = {32768, 16384, 32768, 4096, 2048, 2048};
|
||||
|
||||
/// The shift a new slot's pool is made with: half with the rule on, whole without it
|
||||
constexpr uint32_t first_shift(bool on) {
|
||||
return on ? 1u : 0u;
|
||||
}
|
||||
|
||||
/// A count of a pool made at `shift` (0 whole, 1 half) and divided by RX_VK_DESC_POOL_DIV's n (1..32): never 0
|
||||
constexpr uint32_t count(uint32_t whole, uint32_t shift, uint32_t div) {
|
||||
const uint32_t n = (whole >> (shift > 8 ? 8 : shift)) / (div ? div : 1);
|
||||
return n ? n : 1;
|
||||
}
|
||||
|
||||
/// Whether a slot's own pool is made again whole at its reset: its last recording ran out (it has extra pools) and the
|
||||
/// pool is not whole yet
|
||||
constexpr bool remake(uint32_t shift, size_t extra_pools) {
|
||||
return shift != 0 && extra_pools != 0;
|
||||
}
|
||||
|
||||
/// Which of the six a Vulkan descriptor type is (VkDescriptorType's numbers, so that this header needs no Vulkan):
|
||||
/// kKinds for any other
|
||||
constexpr int kind(uint32_t vk_type) {
|
||||
switch (vk_type) {
|
||||
case 6: return kUniform; // VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER
|
||||
case 7: return kStorage; // VK_DESCRIPTOR_TYPE_STORAGE_BUFFER
|
||||
case 1: return kSampled; // VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
|
||||
case 3: return kStorageImage; // VK_DESCRIPTOR_TYPE_STORAGE_IMAGE
|
||||
case 4: return kUniformTexel; // VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER
|
||||
case 5: return kStorageTexel; // VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER
|
||||
default: return kKinds;
|
||||
}
|
||||
}
|
||||
|
||||
/// What one recording took of its slot's pools: sets, and descriptors by type
|
||||
struct Took {
|
||||
uint32_t sets = 0;
|
||||
uint32_t n[kKinds] = {};
|
||||
};
|
||||
|
||||
/// One more set allocated, with these writes (W: VkWriteDescriptorSet, or a test's own with the same two fields)
|
||||
template <class W>
|
||||
inline void took(Took& t, const W* writes, size_t count_of) {
|
||||
t.sets++;
|
||||
for (size_t i = 0; i < count_of; i++) {
|
||||
const int k = kind((uint32_t)writes[i].descriptorType);
|
||||
if (k < kKinds) t.n[k] += (uint32_t)writes[i].descriptorCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// The most any recording took of each, raised by one recording's
|
||||
inline void peak(Took& most, const Took& t) {
|
||||
if (t.sets > most.sets) most.sets = t.sets;
|
||||
for (int k = 0; k < kKinds; k++)
|
||||
if (t.n[k] > most.n[k]) most.n[k] = t.n[k];
|
||||
}
|
||||
|
||||
/// Whether what a recording took fits a pool made at `shift` and divided by div (the tests', and the log's reader's)
|
||||
constexpr bool fits(const Took& t, uint32_t shift, uint32_t div) {
|
||||
if (t.sets > count(kSets, shift, div)) return false;
|
||||
for (int k = 0; k < kKinds; k++)
|
||||
if (t.n[k] > count(kWhole[k], shift, div)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace mkwvk::desc_pool_grow
|
||||
@@ -4,6 +4,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
@@ -16,6 +17,50 @@ inline bool scene_size_fits(uint32_t w, uint32_t h, uint32_t ow, uint32_t oh) {
|
||||
return w && h && ow && oh && w <= ow && h <= oh && (uint64_t)w * 3 >= ow && (uint64_t)h * 3 >= oh;
|
||||
}
|
||||
|
||||
/// ((Triforce, 11-22, the performance audit's PRESENT-38, after Source A's) One quality mode's range of render sizes for
|
||||
/// an output, as NGX answers it (ok: it answered one).
|
||||
struct ModeRange {
|
||||
uint32_t min_w = 0, min_h = 0, max_w = 0, max_h = 0;
|
||||
bool ok = false;
|
||||
};
|
||||
/// How far outside a range a render size may be and still be that mode's: a 64th of the range's largest size on that
|
||||
/// axis, 2 pixels at least. The Render resolution row's shares are twelfths of the output rounded up, NGX's own sizes
|
||||
/// are rounded down: 854x480 against NGX's 853x480 for Ultra Performance at 2560x1440.
|
||||
constexpr uint32_t mode_slack(uint32_t largest) { return largest / 64 > 2 ? largest / 64 : 2; }
|
||||
/// The mode (an index into ranges) that takes a render size of w x h for an output of ow x oh, or -1. The first range
|
||||
/// that holds the size; else, with slack on, the first it is outside of by no more than mode_slack on each axis, and
|
||||
/// only for a size DLSS scales at all (scene_size_fits: the output 1 to 3 times it). *widened: taken by the slack.
|
||||
inline int mode_for(const ModeRange* ranges, size_t n, uint32_t w, uint32_t h, uint32_t ow, uint32_t oh, bool slack, bool* widened) {
|
||||
*widened = false;
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
const ModeRange& r = ranges[i];
|
||||
if (r.ok && w >= r.min_w && h >= r.min_h && w <= r.max_w && h <= r.max_h) return (int)i;
|
||||
}
|
||||
if (!slack || !scene_size_fits(w, h, ow, oh)) return -1;
|
||||
for (size_t i = 0; i < n; i++) {
|
||||
const ModeRange& r = ranges[i];
|
||||
if (!r.ok) continue;
|
||||
const uint32_t sw = mode_slack(r.max_w), sh = mode_slack(r.max_h);
|
||||
if (w + sw >= r.min_w && h + sh >= r.min_h && w <= r.max_w + sw && h <= r.max_h + sh) return *widened = true, (int)i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// ((Triforce, 11-22, the performance audit's PRESENT-32, after Source A's) Whether a feature is made in a one-size mode
|
||||
/// (NGX's DLAA mode: vk_dlss.cpp prepare's `same` list): its render size is the output's. Before, whenever the two sizes
|
||||
/// were equal. NVIDIA DLSS with the Render resolution row at Auto starts at the output's size, so it got a one-size
|
||||
/// feature, and the game's dynamic resolution left that size some frames later: a second feature made in play (Source
|
||||
/// A's save load-in: 119 ms, then 29.5 ms 17 frames on). With the rule (rule: RX_VK_DLSS_PREWARM=1), one-size only where
|
||||
/// NVIDIA DLAA is the Upscaler's choice (dlaa); DLSS at the output's size takes the scaled mode whose range holds it
|
||||
/// (mode_for: Quality's reaches the output's size), and Auto's smaller sizes then draw with that same feature. Off by
|
||||
/// default: DLSS at full size then draws with the scaled mode's network, not DLAA's, a picture nobody has compared yet
|
||||
inline bool dlaa_feature(bool rule, bool dlaa, uint32_t rw, uint32_t rh, uint32_t ow, uint32_t oh) {
|
||||
const bool full = rw == ow && rh == oh;
|
||||
return rule ? full && dlaa : full;
|
||||
}
|
||||
/// RX_VK_DLSS_PREWARM (value, null when unset): the rule above is on only when it is 1
|
||||
inline bool prewarm_rule(const char* text) { return text && *text && std::atoi(text) == 1; }
|
||||
|
||||
/// Whether s is all ASCII: NGX's Linux library takes only such paths (vk_dlss.cpp wide())
|
||||
inline bool ascii(std::string_view s) {
|
||||
for (const char c : s)
|
||||
@@ -84,4 +129,28 @@ inline std::wstring utf8_to_wide(std::string_view s, bool* bad = nullptr) {
|
||||
return out;
|
||||
}
|
||||
|
||||
/// ((Triforce, 11-21, the performance audit's PRESENT-37, after Source A's) The preset DLSS draws with while the DLSS model
|
||||
/// row is stepped through (vk_dlss.cpp prepare). The row goes K, M, L, NVIDIA's default and applies live, so K to L passes
|
||||
/// M: a feature was made for each preset passed, tens of ms of CPU each, and NGX keeps a released feature's video memory for
|
||||
/// some seconds: Source A's 16 GB card at 3440x1440 held 1419 MB of DLSS's for K, M and L at once against 813 MB for L
|
||||
/// alone, and where memory was short NGX refused the next feature. A new preset is taken once the row has held it for
|
||||
/// `frames`; until then the feature already made draws on with its own. With no feature (the first, or one let go) the
|
||||
/// row's preset is taken at once
|
||||
struct PresetSettle {
|
||||
unsigned wanted = ~0u; // (the row's preset, as last seen)
|
||||
uint64_t since = 0; // (the frame it was first seen in)
|
||||
/// The preset for frame `now`: want, the row's; have, the feature's; has: there is a feature
|
||||
unsigned pick(unsigned want, unsigned have, bool has, uint64_t now, uint64_t frames) {
|
||||
if (want != wanted) wanted = want, since = now;
|
||||
if (!has || want == have) return want;
|
||||
return now - since >= frames ? want : have;
|
||||
}
|
||||
};
|
||||
/// RX_VK_DLSS_MODEL_SETTLE's frames: 30 when not set; 0 (and what is no number, or less): at once, as before
|
||||
inline uint64_t settle_frames(const char* text) {
|
||||
if (!text || !*text) return 30;
|
||||
const long v = std::atol(text);
|
||||
return v > 0 ? (uint64_t)v : 0;
|
||||
}
|
||||
|
||||
} // namespace mkwvk::dlss_checks
|
||||
|
||||
58
gpu/vk/dlss_feature.h
Normal file
58
gpu/vk/dlss_feature.h
Normal file
@@ -0,0 +1,58 @@
|
||||
// (Triforce, 11-21, the upscaler audit's UPS-01) The render size NVIDIA DLSS's feature is made for.
|
||||
//
|
||||
// vk_dlss.cpp made every feature for the largest render size its quality mode allows, so that the game's dynamic
|
||||
// resolution could change the render size under it without the feature being made again. NGX answers that largest size as
|
||||
// the output's own (the owner's log of 11-21: "feature 1 made ...: 2944x1243 (2208x932 to 4416x1864) -> 4416x1864, mode
|
||||
// 2, preset M"), so with the Render resolution row at a fixed share, where the render size never changes, the feature was
|
||||
// still made for 2.25 times the pixels it was ever given at Quality, 4 times at Performance and 9 at Ultra Performance,
|
||||
// and the chain's three input images with it. NVIDIA's guide (DLSS Programming Guide 310.6.0, 3.2 and 5.2.8) has the
|
||||
// optimal render size passed to the creation "exactly as given", and says of the second generation transformer's presets
|
||||
// L and M that their cost follows the size the feature is initialized for, which is why it is to be the dynamic range's
|
||||
// largest only where there is a dynamic range. The same log has DLSS's own video memory at 1069 MB for that feature, where
|
||||
// NVIDIA's table has 456 MB for preset M at 4K.
|
||||
//
|
||||
// So: a fixed share gets a feature of its own render size (exact), as AMD FSR 4 gets a context of its own
|
||||
// (temporal_rules.h plan_context). Where the render size is the game's to change (the row's Auto), or once it has changed
|
||||
// under one output in this run, the feature is made for the mode's whole range, as before. DLAA's is the output's either
|
||||
// way.
|
||||
//
|
||||
// RX_VK_DLSS_FEATURE_MAX=1: every feature for its mode's largest render size, as before (whole_range()).
|
||||
//
|
||||
// No NGX, no Vulkan: tests/test_dlss_feature.py compiles this.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace dlss_feature {
|
||||
|
||||
/// RX_VK_DLSS_FEATURE_MAX (value, null when unset): not 0, every feature for its mode's largest render size, as before
|
||||
inline bool whole_range(const char* value) { return value && *value && std::atoi(value) != 0; }
|
||||
|
||||
/// What a feature is made for: w x h, and whether that is the one render size it takes (exact) or the largest of a range
|
||||
struct Size {
|
||||
uint32_t w, h;
|
||||
bool exact;
|
||||
};
|
||||
|
||||
/// The size to make a feature for, for a frame of rw x rh in a mode whose render sizes go up to max_w x max_h. aa: DLAA,
|
||||
/// the render size the output's (its range is that one size). range: the render size may change under this output (the
|
||||
/// row's Auto, the size seen changing, or the switch)
|
||||
inline Size size(bool aa, bool range, uint32_t rw, uint32_t rh, uint32_t max_w, uint32_t max_h) {
|
||||
if (aa || range || rw > max_w || rh > max_h) return {max_w, max_h, false};
|
||||
return {rw, rh, true};
|
||||
}
|
||||
|
||||
/// Whether a feature made for fw x fh takes a frame of rw x rh: its one size (exact), or any from min_w x min_h up to its own
|
||||
inline bool takes(bool exact, uint32_t fw, uint32_t fh, uint32_t min_w, uint32_t min_h, uint32_t rw, uint32_t rh) {
|
||||
if (exact) return rw == fw && rh == fh;
|
||||
return rw <= fw && rh <= fh && rw >= min_w && rh >= min_h;
|
||||
}
|
||||
|
||||
/// Whether this frame shows that the render size changes under one output: a feature of one size (exact) for the same
|
||||
/// output, preset and colour (same), and a frame of another size. The caller keeps it for the run: the next feature, and
|
||||
/// every one after it, is made for the mode's whole range
|
||||
inline bool found_range(bool same, bool exact, uint32_t fw, uint32_t fh, uint32_t rw, uint32_t rh) {
|
||||
return same && exact && (rw != fw || rh != fh);
|
||||
}
|
||||
|
||||
} // namespace dlss_feature
|
||||
@@ -93,6 +93,36 @@ inline void unjitter(float m[16], const float jitter[2]) {
|
||||
}
|
||||
}
|
||||
|
||||
/// ((Triforce, 11-20) the owner's "DLSS flicker": the whole picture and the shadows, while the camera moves, with NVIDIA
|
||||
/// DLSS frame generation on, and not without it.) Streamline's camera matrices are in the clip space of the depth buffer it
|
||||
/// is given: its depth value is that clip space's z over w, 1 at the near plane with depthInverted. The game's projection
|
||||
/// is NVN's, clip z from -1 at the near plane to 1 at the far one, and the depth frame generation gets is FSR's copy
|
||||
/// (vk_fsr3_inputs.cpp): d = (1 - ndc z) / 2 where the game's buffer has 0 at the near plane (flipped: Camera::flip_depth),
|
||||
/// (ndc z + 1) / 2 where it is reversed already. Given the game's own matrices with that depth, a depth read as clip z put
|
||||
/// what is far a fifth of a metre from the camera and what is near at the far plane, so whatever Streamline works out from
|
||||
/// the depth and the camera's move was wrong as soon as the camera moved, and right while it stood. Only DLSS frame
|
||||
/// generation takes matrices (FSR takes the near and far planes and the field of view), so nothing else showed it.
|
||||
/// The depth's clip space is the game's with z' = (w - z) / 2 (flipped) or (w + z) / 2: Z * clip, Z the identity but for
|
||||
/// its z row, (0 0 -1/2 1/2) or (0 0 1/2 1/2).
|
||||
/// A projection (or a view-projection) into the depth's clip space: Z * m, row major (clip = M * position)
|
||||
inline void depth_clip_projection(const float m[16], bool flipped, float out[16]) {
|
||||
const float s = flipped ? -0.5f : 0.5f;
|
||||
for (int i = 0; i < 16; i++) out[i] = m[i];
|
||||
for (int c = 0; c < 4; c++) out[2 * 4 + c] = s * m[2 * 4 + c] + 0.5f * m[3 * 4 + c];
|
||||
}
|
||||
/// A clip-to-clip matrix of the game's (this frame's clip space to the frame before's: reprojection) between the depth's
|
||||
/// clip spaces: Z * m * inverse(Z), inverse(Z)'s z row (0 0 -2 1) or (0 0 2 -1). The identity stays the identity
|
||||
inline void depth_clip_reprojection(const float m[16], bool flipped, float out[16]) {
|
||||
const float k = flipped ? -2.0f : 2.0f, t = flipped ? 1.0f : -1.0f;
|
||||
float r[16];
|
||||
for (int row = 0; row < 4; row++) { // (m * inverse(Z): the z column scaled, and added to the w column)
|
||||
r[row * 4 + 0] = m[row * 4 + 0], r[row * 4 + 1] = m[row * 4 + 1];
|
||||
r[row * 4 + 2] = k * m[row * 4 + 2];
|
||||
r[row * 4 + 3] = m[row * 4 + 3] + t * m[row * 4 + 2];
|
||||
}
|
||||
depth_clip_projection(r, flipped, out); // (Z * that)
|
||||
}
|
||||
|
||||
/// A jitter in clip space as DLSS takes it: in render pixels, x right and y down (clip y is up)
|
||||
inline void jitter_to_pixels(const float clip[2], unsigned width, unsigned height, float out[2]) {
|
||||
out[0] = clip[0] * 0.5f * (float)width;
|
||||
|
||||
38
gpu/vk/dmabuf_gate.h
Normal file
38
gpu/vk/dmabuf_gate.h
Normal file
@@ -0,0 +1,38 @@
|
||||
// (Triforce, 11-22, the performance audit's OS-08, after Source A's) Whether guest memory is offered to the driver as
|
||||
// udmabuf dma-bufs at all, and what the start's line says (vk_memory.cpp import_dma_buf asks at its first call; plain code:
|
||||
// tests/test_dmabuf_driver_gate.py runs it anywhere).
|
||||
//
|
||||
// On Linux the guest window is a memfd and each pool is first offered to the driver as a dma-buf made by udmabuf. NVIDIA's
|
||||
// proprietary driver refuses every one (VK_ERROR_OUT_OF_DEVICE_MEMORY) and the pool ends as a host-pointer import anyway:
|
||||
// 49-50 refused imports a run and a kernel message at each start on Source A's RTX 4090, the first refusal 2.5-3.7 ms, one
|
||||
// of a 64 MB piece 198 ms on the presentation thread during a save load. So with that driver /dev/udmabuf is not opened
|
||||
// and the pools are host-pointer imports from the start. NVK and RADV have other driver ids and keep their dma-bufs.
|
||||
// RX_VK_DMABUF_NVIDIA=1: tried on NVIDIA's driver too, as before (for a later driver that takes them).
|
||||
#pragma once
|
||||
|
||||
namespace dmabuf_gate {
|
||||
|
||||
/// What the start found. fn: the host gave its memfd function (false also with RX_VK_NO_DMABUF). memfd: the window is a
|
||||
/// memfd. ext: the device imports dma-bufs (VK_EXT_external_memory_dma_buf and its fd properties call). nvidia: NVIDIA's
|
||||
/// proprietary driver, and RX_VK_DMABUF_NVIDIA not set
|
||||
struct Facts {
|
||||
bool fn = false, memfd = false, ext = false, nvidia = false;
|
||||
};
|
||||
|
||||
/// Whether /dev/udmabuf is opened: only then can a pool be offered as a dma-buf
|
||||
inline bool try_udmabuf(const Facts& f) { return f.fn && f.memfd && f.ext && !f.nvidia; }
|
||||
|
||||
/// As it was: NVIDIA's driver was offered them too
|
||||
inline bool try_udmabuf_before(const Facts& f) { return f.fn && f.memfd && f.ext; }
|
||||
|
||||
/// The start's "vk: guest memory as dma-bufs: ..." answer. opened: /dev/udmabuf opened (asked only after try_udmabuf)
|
||||
inline const char* answer(const Facts& f, bool opened) {
|
||||
if (try_udmabuf(f) && opened) return "yes";
|
||||
if (!f.fn) return "no (no memfd window, or RX_VK_NO_DMABUF)";
|
||||
if (!f.memfd) return "no (the window is anonymous memory)";
|
||||
if (!f.ext) return "no (VK_EXT_external_memory_dma_buf)";
|
||||
if (f.nvidia) return "no (NVIDIA's driver refuses them: host pointers)";
|
||||
return "no (/dev/udmabuf cannot be opened)";
|
||||
}
|
||||
|
||||
} // namespace dmabuf_gate
|
||||
41
gpu/vk/drawn_page_map.h
Normal file
41
gpu/vk/drawn_page_map.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// (Triforce, 11-21, the performance audit's TEX-21, after Source A's) A texture the GPU drew gets its page map at its first
|
||||
// draw.
|
||||
//
|
||||
// A texture in a virtual pool (its storage mapped 64 KB a page) is checked through its mapping: texture_dirty keeps each
|
||||
// page's guest address (page_map) and says which pages were mapped anew or written since. The map is recorded at the
|
||||
// texture's first check, which for a texture uploaded from memory is its first upload. One the GPU drew first is marked
|
||||
// uploaded by the draw and never checked, so it has no map; once the game finalizes it, its first check finds none, takes
|
||||
// that as "everything was mapped since", and the whole storage is uploaded from memory over what the GPU drew: a HUD
|
||||
// label or a render target gone blank after an area change, and an upload of up to 15 MB each. Source A's sessions from
|
||||
// Hyrule Field to Castle Town: such whole uploads of HUD labels 6, other HUD 4 to 6, render targets 4 to 9, all to 0.
|
||||
// Here: the map is recorded at the first draw that says who drew it, by one walk of the mapping (the storage's size / 64 KB
|
||||
// lookups, once a texture). The later check then gives only the pages mapped anew or written by the CPU.
|
||||
// Not for a write that gives no reason ("?": a clear, the movie upscaler): those keep the path that brings a font cache's
|
||||
// letters back from memory. RX_VK_DRAWN_PAGE_MAP=0: no map at the draw, as before.
|
||||
//
|
||||
// The rule alone: tests/test_drawn_page_map.py compiles it, and texture_dirty cut from the source.
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace drawn_page_map {
|
||||
|
||||
inline constexpr uint64_t kVirtual = 1ull << 40; // (a virtual pool's addresses start here)
|
||||
inline constexpr uint64_t kPage = 1ull << 16; // (and its pages are 64 KB)
|
||||
|
||||
/// RX_VK_DRAWN_PAGE_MAP: off only with 0
|
||||
inline bool on(const char* asked) { return !asked || !*asked || atoi(asked) != 0; }
|
||||
|
||||
/// The pages of a storage of guest_size bytes
|
||||
constexpr size_t pages(uint64_t guest_size) { return (size_t)((guest_size + kPage - 1) / kPage); }
|
||||
|
||||
/// Whether a write by `why` into a texture at gpu, of guest_size bytes of storage, whose map holds map_pages pages now,
|
||||
/// records its map first
|
||||
inline bool seeds(bool switch_on, const char* why, uint64_t gpu, uint64_t guest_size, size_t map_pages) {
|
||||
if (!switch_on || !why || !std::strcmp(why, "?")) return false;
|
||||
return gpu >= kVirtual && guest_size != 0 && map_pages != pages(guest_size);
|
||||
}
|
||||
|
||||
} // namespace drawn_page_map
|
||||
140
gpu/vk/driver_faults.h
Normal file
140
gpu/vk/driver_faults.h
Normal file
@@ -0,0 +1,140 @@
|
||||
// Programs the driver faulted on, kept out of it, and one build of a program at a time (no game, no GPU: the rules and the
|
||||
// gate; vk_draw.cpp fault_quarantine, build_graphics, guarded_graphics). Apart from Vulkan so that
|
||||
// tests/test_driver_faults.py runs it alone, on many made-up PCs.
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's PIPE-57, after Source A's.) The guards catch a fault inside the driver's
|
||||
// compiler (vk_draw.cpp guarded_graphics), and a fault during the start's own shader work starts the game again
|
||||
// (driver_fault_restart). Nothing remembered the program: the next start asked the driver for it again, faulted again and
|
||||
// restarted again, and in play a second thread could ask for the same program while the driver was still inside the
|
||||
// first. Source A saw that on AMD's Windows driver (an RX 6800 XT): in a freeze, three threads sat in the driver on two
|
||||
// programs' builds while the presenting thread waited for one of them; a preparation stuck at "6625 of 6627, nothing
|
||||
// finished for 30 s" took 32.5 s, and 4.2 s with three faulted programs kept out on the first run, 2.3 s after. Triforce
|
||||
// has the same class of report: "two of 4926 on an RX 5700 XT, stuck at 99%".
|
||||
//
|
||||
// What. On AMD's own Windows driver (or everywhere with RX_VK_DRIVER_FAULTS=2):
|
||||
// - a program whose pipeline build faulted in the driver is not asked of the driver again this run, and its key goes to
|
||||
// triforce_driver_faults.txt beside the executable, one line under the vendor and the driver's version, written by the
|
||||
// fault's handler before the restart can end the process (so a start that faults does not fault again); later starts
|
||||
// with that driver skip those programs, and say so once (delete the file to try again; another driver version ignores
|
||||
// the lines);
|
||||
// - one build of a program at a time: a second waits at the gate, outside the driver, and a probe that asks the caches
|
||||
// only is told a compile is required.
|
||||
// Elsewhere (NVIDIA's, Intel's, Mesa's drivers, AMD's on Linux) nothing of it runs, as before: the NVIDIA fault of 11-13
|
||||
// was a race in the driver, not a bad program. RX_VK_DRIVER_FAULTS=0: nowhere.
|
||||
#pragma once
|
||||
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace driver_faults {
|
||||
|
||||
/// RX_VK_DRIVER_FAULTS: 0 off, 1 (unset) AMD's Windows driver, 2 every driver
|
||||
inline int mode(const char* env) {
|
||||
if (!env || !*env) return 1;
|
||||
const int v = std::atoi(env);
|
||||
return v <= 0 ? 0 : v >= 2 ? 2 : 1;
|
||||
}
|
||||
/// Whether the quarantine, its file and the gate are on: mode 2 anywhere, mode 1 on Windows with AMD's own driver
|
||||
/// (VK_DRIVER_ID_AMD_PROPRIETARY)
|
||||
inline bool on(int mode, bool windows, bool amd_proprietary) {
|
||||
return mode >= 2 || (mode == 1 && windows && amd_proprietary);
|
||||
}
|
||||
|
||||
inline constexpr int kLine = 35; // ("vvvvvvvv dddddddd kkkkkkkkkkkkkkkk\n")
|
||||
|
||||
/// One line of the file into out (kLine bytes and a 0): made without the C library, as the fault's handler makes it
|
||||
inline int line(char* out, uint32_t vendor, uint32_t driver, uint64_t key) {
|
||||
static const char hex[] = "0123456789abcdef";
|
||||
int n = 0;
|
||||
for (int i = 7; i >= 0; i--) out[n++] = hex[(vendor >> (4 * i)) & 0xF];
|
||||
out[n++] = ' ';
|
||||
for (int i = 7; i >= 0; i--) out[n++] = hex[(driver >> (4 * i)) & 0xF];
|
||||
out[n++] = ' ';
|
||||
for (int i = 15; i >= 0; i--) out[n++] = hex[(key >> (4 * i)) & 0xF];
|
||||
out[n++] = '\n';
|
||||
out[n] = 0;
|
||||
return n;
|
||||
}
|
||||
/// The keys of the file's lines for this vendor and driver version; another's, and a broken line, are passed over
|
||||
inline std::vector<uint64_t> parse(const std::string& text, uint32_t vendor, uint32_t driver) {
|
||||
std::vector<uint64_t> keys;
|
||||
const auto hexval = [](const std::string& s, size_t at, int digits, uint64_t* v) {
|
||||
if (at + (size_t)digits > s.size()) return false;
|
||||
uint64_t x = 0;
|
||||
for (int i = 0; i < digits; i++) {
|
||||
const char c = s[at + i];
|
||||
const int d = c >= '0' && c <= '9' ? c - '0' : c >= 'a' && c <= 'f' ? c - 'a' + 10 : c >= 'A' && c <= 'F' ? c - 'A' + 10 : -1;
|
||||
if (d < 0) return false;
|
||||
x = x << 4 | (uint64_t)d;
|
||||
}
|
||||
*v = x;
|
||||
return true;
|
||||
};
|
||||
size_t at = 0;
|
||||
while (at < text.size()) {
|
||||
size_t end = text.find('\n', at);
|
||||
if (end == std::string::npos) end = text.size();
|
||||
std::string l = text.substr(at, end - at);
|
||||
if (!l.empty() && l.back() == '\r') l.pop_back();
|
||||
uint64_t v = 0, d = 0, k = 0;
|
||||
if (l.size() == (size_t)kLine - 1 && l[8] == ' ' && l[17] == ' ' && hexval(l, 0, 8, &v) && hexval(l, 9, 8, &d) &&
|
||||
hexval(l, 18, 16, &k) && v == vendor && d == driver)
|
||||
keys.push_back(k);
|
||||
at = end + 1;
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
/// The run's quarantine and the gate: begin before a program's build, end after it (with whether it faulted)
|
||||
class Quarantine {
|
||||
public:
|
||||
enum class Begin { Go, Busy, Faulted };
|
||||
void load(const std::vector<uint64_t>& keys) {
|
||||
std::lock_guard lk(mu_);
|
||||
bad_.insert(keys.begin(), keys.end());
|
||||
}
|
||||
/// Faulted: not asked of the driver. Busy: another build of it is inside the driver and the caller may not wait (a
|
||||
/// probe of the caches). Go: this build may go in; the caller ends it with end(). may_wait: wait at the gate instead
|
||||
Begin begin(uint64_t key, bool may_wait) {
|
||||
std::unique_lock lk(mu_);
|
||||
for (;;) {
|
||||
if (bad_.count(key)) return Begin::Faulted;
|
||||
if (!busy_.count(key)) break;
|
||||
if (!may_wait) return Begin::Busy;
|
||||
cv_.wait(lk);
|
||||
}
|
||||
busy_.insert(key);
|
||||
return Begin::Go;
|
||||
}
|
||||
/// True when it faulted now for the first time
|
||||
bool end(uint64_t key, bool faulted) {
|
||||
bool fresh = false;
|
||||
{
|
||||
std::lock_guard lk(mu_);
|
||||
busy_.erase(key);
|
||||
if (faulted) fresh = bad_.insert(key).second;
|
||||
}
|
||||
cv_.notify_all();
|
||||
return fresh;
|
||||
}
|
||||
bool faulted(uint64_t key) const {
|
||||
std::lock_guard lk(mu_);
|
||||
return bad_.count(key) != 0;
|
||||
}
|
||||
size_t count() const {
|
||||
std::lock_guard lk(mu_);
|
||||
return bad_.size();
|
||||
}
|
||||
|
||||
private:
|
||||
mutable std::mutex mu_;
|
||||
std::condition_variable cv_;
|
||||
std::unordered_set<uint64_t> bad_, busy_;
|
||||
};
|
||||
|
||||
} // namespace driver_faults
|
||||
65
gpu/vk/evict_reason.h
Normal file
65
gpu/vk/evict_reason.h
Normal file
@@ -0,0 +1,65 @@
|
||||
// Whether the write-back of a texture the eviction chose is stale: another image was drawn over its storage since its own
|
||||
// last drawing (no game, no GPU: a rule). tests/test_evict_reason.py
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's TEX-R404, after Source A's.) Over the budget, the eviction writes each chosen
|
||||
// texture the GPU drew back into the game's memory before it goes, so that one made again over that storage is uploaded
|
||||
// with what the GPU drew. The game draws its HUD labels (110 x 110, 46 x 46, 140 x 140) inside the storage of a
|
||||
// 1920 x 1080 target it no longer uses. The eviction's own tests do not see that: drawn_over looks only at images of the
|
||||
// same start, and target_overlap.h leaves out an image inside the target. So when the target went, its old texels landed
|
||||
// over the labels, the pages counted as written, and the labels, finalized, were uploaded from them as noise (Source A:
|
||||
// in 3 of 3 runs of two minutes in Hyrule Field at a 6 GB allowance, none with the rule).
|
||||
//
|
||||
// The rule: a write-back is left out when another image the GPU drew overlaps the texture's storage and was drawn in a
|
||||
// later frame than the texture's own last drawing. The texture still goes. One drawn in the same frame keeps the
|
||||
// write-back (a frame's targets drawn side by side), and so does one that only touches it. What is given up: the parts
|
||||
// of the texture the newer image does not cover are not written back either; made again there and sampled undrawn, it
|
||||
// starts from what the memory holds, as before the write-back existed. RX_VK_EVICT_STALE_FLUSH=1: written back, as before.
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
namespace evict_reason {
|
||||
|
||||
/// RX_VK_EVICT_STALE_FLUSH: unset, empty or 0 leaves a stale write-back out; anything else writes it back, as before
|
||||
inline bool flush_stale(const char* env) { return env && *env && std::atoi(env) != 0; }
|
||||
|
||||
/// Whether the storage [lo, hi) and [olo, ohi) share a byte (ranges that touch do not)
|
||||
constexpr bool overlaps(uint64_t lo, uint64_t hi, uint64_t olo, uint64_t ohi) {
|
||||
return lo < hi && olo < ohi && lo < ohi && olo < hi;
|
||||
}
|
||||
|
||||
/// Whether a texture last drawn in frame `last` holds texels older than what is in its storage: `other` is the frame of
|
||||
/// the newest drawing of another image over that storage (0: none)
|
||||
constexpr bool write_back_stale(uint64_t last, uint64_t other) { return other > last; }
|
||||
|
||||
/// A texture whose write-back the eviction is about to make
|
||||
struct Candidate {
|
||||
uint64_t lo = 0, hi = 0; // its storage
|
||||
size_t index = 0; // the caller's own: its place in the eviction's list
|
||||
const void* self = nullptr; // itself, so that it is not taken for another image over its own storage
|
||||
uint64_t newest = 0; // the frame of the newest drawing of another image over its storage (0: none)
|
||||
};
|
||||
|
||||
/// Puts the candidates in the order of their starts, for note(); returns the longest one's size
|
||||
inline uint64_t by_start(std::vector<Candidate>& c) {
|
||||
std::sort(c.begin(), c.end(), [](const Candidate& a, const Candidate& b) { return a.lo < b.lo; });
|
||||
uint64_t longest = 0;
|
||||
for (const Candidate& k : c) longest = std::max(longest, k.hi > k.lo ? k.hi - k.lo : 0);
|
||||
return longest;
|
||||
}
|
||||
|
||||
/// One image the GPU drew, [olo, ohi), last drawn in frame `o_written`: every candidate it overlaps (but itself) takes
|
||||
/// that frame when it is newer than what the candidate has. `c` is in by_start's order, `longest` what by_start gave
|
||||
inline void note(std::vector<Candidate>& c, uint64_t longest, uint64_t olo, uint64_t ohi, uint64_t o_written, const void* other) {
|
||||
if (ohi <= olo) return;
|
||||
// (a candidate over [olo, ohi) starts before ohi and after olo less its size: the search begins at olo less the longest)
|
||||
auto it = std::lower_bound(c.begin(), c.end(), olo > longest ? olo - longest : 0,
|
||||
[](const Candidate& k, uint64_t g) { return k.lo < g; });
|
||||
for (; it != c.end() && it->lo < ohi; ++it)
|
||||
if (it->self != other && overlaps(it->lo, it->hi, olo, ohi) && o_written > it->newest) it->newest = o_written;
|
||||
}
|
||||
|
||||
} // namespace evict_reason
|
||||
73
gpu/vk/fallback_size_policy.h
Normal file
73
gpu/vk/fallback_size_policy.h
Normal file
@@ -0,0 +1,73 @@
|
||||
// Mesh-fallback compute stages too big for two Mesa drivers are not handed to them (no game, no GPU: a rule).
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's PIPE-56, after Source A's.) A mesh program on a GPU without mesh shaders runs
|
||||
// as compute stages (vk_draw.cpp fallback_compute_pipelines). Every stage went to the driver, and a refusal was only
|
||||
// remembered after the build. Two drivers do not get that far on the largest stages:
|
||||
// - Mesa's RADV on GCN 1 to 4 (GFX6-8: vk_vendor.h radv_gcn). Source A's numbers under drm-shim with a 6 GB cap: the
|
||||
// 79,947-phi stage not built after 45-90 s and killed (25 GB at 150 s), where GFX9 and Navi built it in 13-14 s at
|
||||
// 2.9 GB. Limit: 50,000 OpPhi in one stage (2 of about 800 modules are over it);
|
||||
// - Mesa's Intel driver. An Iris Xe: a 251-call stage hit a 14 GB cap unfinished after 27 minutes. Limits: 20,000 OpPhi
|
||||
// or 200 OpFunctionCall in one stage (10 of 376 stages left out in Source A's full preparation).
|
||||
// A program with a stage over its driver's limit goes into the failed set before anything is built, as a program the
|
||||
// driver refused does: its draws are left out. Which objects those are is not known. No other driver has a limit, and the
|
||||
// switches set none there: NVIDIA, Intel's Windows driver, AMD's own drivers and RADV from Vega on build every stage.
|
||||
//
|
||||
// RX_VK_FALLBACK_PHI_LIMIT=<n>, RX_VK_FALLBACK_CALL_LIMIT=<n>: the two limits on those two drivers; 0: no limit.
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace fallback_size {
|
||||
constexpr uint32_t kOpFunctionCall = 57, kOpPhi = 245;
|
||||
constexpr uint32_t kGcnPhis = 50000, kIntelPhis = 20000, kIntelCalls = 200;
|
||||
|
||||
struct Size {
|
||||
uint32_t phis = 0, calls = 0;
|
||||
};
|
||||
struct Limits {
|
||||
uint32_t phis = 0, calls = 0; // (0: none)
|
||||
};
|
||||
enum class Driver { Other, RadvGcn, MesaIntel };
|
||||
|
||||
/// A module's OpPhi and OpFunctionCall instructions. One that does not read as SPIR-V counts 0 of both
|
||||
inline Size count(const uint32_t* code, size_t words) {
|
||||
Size s;
|
||||
if (!code || words < 5 || code[0] != 0x07230203u) return s;
|
||||
for (size_t at = 5; at < words;) {
|
||||
const uint32_t n = code[at] >> 16, op = code[at] & 0xffffu;
|
||||
if (!n || at + n > words) return Size{};
|
||||
s.phis += op == kOpPhi, s.calls += op == kOpFunctionCall;
|
||||
at += n;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
inline uint32_t spirv_phis(const uint32_t* code, size_t words) { return count(code, words).phis; }
|
||||
inline uint32_t spirv_calls(const uint32_t* code, size_t words) { return count(code, words).calls; }
|
||||
|
||||
/// A limit's switch: unset, empty or not a number, the driver's own; 0, none; else the number
|
||||
inline uint32_t parse_limit(const char* env, uint32_t own) {
|
||||
if (!env || !*env) return own;
|
||||
char* end = nullptr;
|
||||
const unsigned long long v = std::strtoull(env, &end, 10);
|
||||
if (end == env || *end) return own;
|
||||
return v > 0xffffffffull ? 0xffffffffu : (uint32_t)v;
|
||||
}
|
||||
|
||||
/// The driver: RADV on a GCN 1 to 4 GPU first (it is never Mesa's Intel driver), then Mesa's Intel driver
|
||||
constexpr Driver driver_of(bool radv_gcn, bool mesa_intel) {
|
||||
return radv_gcn ? Driver::RadvGcn : mesa_intel ? Driver::MesaIntel : Driver::Other;
|
||||
}
|
||||
|
||||
/// The limits on that driver, with the two switches' values (nullptr: unset). None on any other driver, whatever is set
|
||||
inline Limits limits(Driver d, const char* phi_env, const char* call_env) {
|
||||
if (d == Driver::Other) return Limits{};
|
||||
const Limits own = d == Driver::RadvGcn ? Limits{kGcnPhis, 0} : Limits{kIntelPhis, kIntelCalls};
|
||||
return Limits{parse_limit(phi_env, own.phis), parse_limit(call_env, own.calls)};
|
||||
}
|
||||
|
||||
/// The stage is over a limit: its program is not built
|
||||
constexpr bool refused(const Limits& l, const Size& s) {
|
||||
return (l.phis && s.phis > l.phis) || (l.calls && s.calls > l.calls);
|
||||
}
|
||||
} // namespace fallback_size
|
||||
38
gpu/vk/fg_motion.h
Normal file
38
gpu/vk/fg_motion.h
Normal file
@@ -0,0 +1,38 @@
|
||||
// (Triforce, 11-22, the owner's DLSS frame generation flicker, again) Whose motion vectors frame generation is given.
|
||||
//
|
||||
// Since FG-4 (vk_fsr3_inputs.cpp chain_motion), while NVIDIA DLSS or AMD FSR 4 upscales, frame generation's motion is the
|
||||
// upscaler chain's: the camera's from the depth, with every draw of the scene that stored its positions drawn again over
|
||||
// it (vk_temporal.cpp capture_motion). With NVIDIA DLSS frame generation that showed as the owner's flicker of 11-20 again
|
||||
// (the whole picture while the camera moved), on a build with the clip-space fix of that day (dlss_math.h
|
||||
// depth_clip_projection) in it. The owner's runs of 11-22 (DLSS at 50%, 2x frame generation, HDR, before the bloom):
|
||||
// - RX_VK_FG_OWN_MOTION=0, the camera's motion alone: no flicker;
|
||||
// - the chain's motion with the upscaler audit's commits all set back (RX_VK_CAPTURE_TABLES=0, RX_VK_REDRAW_STATE=0,
|
||||
// RX_VK_DLSS_FEATURE_MAX=1): the flicker, so it is not theirs;
|
||||
// - RX_VK_DLSS_PROBE=1 in that run: the redraw's motion of the scene's largest draw within 0.03 px of the camera's.
|
||||
// What in the chain's motion Streamline takes for a flicker is not known: its made frames are not in any log or shot. DLSS
|
||||
// frame generation finds what moves by itself with its own optical flow, and FSR's inputs give it the depth and the
|
||||
// camera, so it is given the camera's motion alone: what the first run showed. AMD's frame generation and FSR 3.1's
|
||||
// interpolation keep the chain's, as since FG-4 (no flicker of theirs is reported).
|
||||
//
|
||||
// RX_VK_DLSSG_OWN_MOTION=1: DLSS frame generation is given the chain's motion again, as before. RX_VK_FG_OWN_MOTION=0 still
|
||||
// gives every generator the camera's alone.
|
||||
//
|
||||
// No Vulkan: tests/test_fg_motion.py compiles this.
|
||||
#pragma once
|
||||
#include <cstdlib>
|
||||
|
||||
namespace fg_motion {
|
||||
|
||||
/// A switch read as the renderer reads its others: set and not 0 (value null when unset)
|
||||
inline bool set_on(const char* value) { return value && *value && std::atoi(value) != 0; }
|
||||
/// RX_VK_FG_OWN_MOTION=0 (value null when unset): the camera's motion alone, for every generator
|
||||
inline bool camera_alone(const char* value) { return value && *value && std::atoi(value) == 0; }
|
||||
|
||||
/// Whether frame generation is given the upscaler chain's motion this frame. dlssg: NVIDIA DLSS frame generation runs in
|
||||
/// this session (vk_dlssg.h active). fg_own: RX_VK_FG_OWN_MOTION; dlssg_own: RX_VK_DLSSG_OWN_MOTION (null when unset)
|
||||
inline bool chain(bool dlssg, const char* fg_own, const char* dlssg_own) {
|
||||
if (camera_alone(fg_own)) return false;
|
||||
return !dlssg || set_on(dlssg_own);
|
||||
}
|
||||
|
||||
} // namespace fg_motion
|
||||
42
gpu/vk/finalized_obsolete.h
Normal file
42
gpu/vk/finalized_obsolete.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// (Triforce, 11-21, the performance audit's TEX-43, after Source A's) A finalized texture the GPU drew whose storage the
|
||||
// game has since written over.
|
||||
//
|
||||
// A texture the GPU drew in one frame is kept after the game finalizes it (texture_sweep keep_finalized, up to
|
||||
// RX_VK_KEEP_FINALIZED_MB): the game may make a texture over that storage again and sample it without drawing it, as the
|
||||
// terrain does with its 260 x 260 tiles. Within the budget only a draw over one let it go, and the game's own CPU writes
|
||||
// to that memory never did: in players' logs about 200 render target images an hour stayed for good, most of them such
|
||||
// tiles, with the blocks they pin. Source A's rule: once the CPU has written three quarters or more of the storage since
|
||||
// the release, the game has put other data there, the image holds nothing that memory holds on the console, and the
|
||||
// sweep lets it go whatever the budget says. Only one of 32 KB or more (a small one shares its pages with what the game
|
||||
// keeps beside it, and a write there says nothing of it) and not one in a virtual pool. Its laps of Hyrule Field at a
|
||||
// 6 GB allowance: render target images 129, 166, 221 against 128, 131, 129; the kept ones 131 against 41.
|
||||
// The answer is kept with the texture: once rewritten it stays so until it is released again, and one not yet rewritten
|
||||
// is looked at again at most every kRecheck presents (the look walks its pages' write generations).
|
||||
// RX_VK_KEEP_OBSOLETE=1: kept, as before.
|
||||
//
|
||||
// The rule alone: tests/test_finalized_obsolete.py compiles it.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace finalized_obsolete {
|
||||
|
||||
inline constexpr uint64_t kMinBytes = 32u << 10;
|
||||
inline constexpr uint64_t kVirtual = 1ull << 40;
|
||||
inline constexpr uint64_t kRecheck = 60;
|
||||
|
||||
/// RX_VK_KEEP_OBSOLETE: not 0 keeps them, as before
|
||||
inline bool keep(const char* asked) { return asked && atoi(asked) != 0; }
|
||||
|
||||
/// Whether a texture can be one: finalized after the GPU wrote it, in no virtual pool, of 32 KB of storage or more
|
||||
constexpr bool candidate(bool released, bool gpu_written, uint64_t gpu, uint64_t guest_size) {
|
||||
return released && gpu_written && gpu < kVirtual && guest_size >= kMinBytes;
|
||||
}
|
||||
|
||||
/// Whether `written` bytes of a storage of guest_size, written by the CPU since the release, make it rewritten
|
||||
constexpr bool rewritten(uint64_t written, uint64_t guest_size) { return guest_size != 0 && written * 4 >= guest_size * 3; }
|
||||
|
||||
/// Whether one not rewritten when last looked at, in present `checked` (0: never), is looked at again in present `frame`
|
||||
constexpr bool due(uint64_t frame, uint64_t checked) { return !checked || frame - checked >= kRecheck; }
|
||||
|
||||
} // namespace finalized_obsolete
|
||||
74
gpu/vk/first_start.h
Normal file
74
gpu/vk/first_start.h
Normal file
@@ -0,0 +1,74 @@
|
||||
// (Triforce, 11-22, the performance audit's PRESENT-46, after Source A's) A first start sized to the card: the Render
|
||||
// resolution row set once on a weak GPU.
|
||||
//
|
||||
// With no options file every card started the same: the Render resolution at Auto, the game's dynamic resolution. Source A
|
||||
// reads the card and puts it in a tier; its tier 1 is an integrated GPU (a handheld's is one), a card without mesh shaders,
|
||||
// or a card with 4.5 GB of video memory or less, and it draws the 3D at 50% there, or at 33% on an integrated GPU beside
|
||||
// 4 processor threads or fewer (its note: an i3-1115G4's own GPU took 60 to 220 ms a frame at 50%).
|
||||
//
|
||||
// This is that test, for a first start only (vk_menu.cpp menu_first_start): no options file, RX_VK_LOW_SPEC not set,
|
||||
// nothing saved by it, so a start after the player has saved anything is the player's own. Left out, as the audit's
|
||||
// entry says: Source A's preset row, its fingerprint that chooses again on new hardware (it would overwrite the player's
|
||||
// rows), its tuner in play, any change of the upscaler or of the output's size, and its test of the SteamDeck variable,
|
||||
// which took desktop PCs started from that launcher for handhelds: a handheld is found by its integrated GPU alone.
|
||||
//
|
||||
// RX_VK_FIRST_START_AUTO: not set or 0, off (as before; the default until the owner has decided what a first start on a
|
||||
// weak card gets). 1: on. A larger number: on, the card taken as having that many MB of video memory, for the lab.
|
||||
//
|
||||
// No Vulkan, no menu: tests/test_first_start.py compiles this.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace first_start {
|
||||
|
||||
/// What is read of the card
|
||||
struct Card {
|
||||
bool integrated = false; // (VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU)
|
||||
bool mesh_shaders = true; // (VK_EXT_mesh_shader, as the device was made)
|
||||
uint64_t vram_mb = 0; // (its video memory; 0: not known)
|
||||
unsigned threads = 0; // (the processor's threads; 0: not known)
|
||||
};
|
||||
|
||||
constexpr uint64_t kSmallVramMb = 4608; // 4.5 GB: tier 1 up to here
|
||||
constexpr unsigned kFewThreads = 4; // an integrated GPU beside this many threads or fewer: 33%
|
||||
constexpr int kRowHalf = 4, kRowThird = 6; // opts.resolution's 50% and 33% (upscaler_rows.h)
|
||||
|
||||
enum Why { kKeep = 0, kIntegrated, kNoMeshShaders, kSmallVram };
|
||||
/// The Render resolution row for the card's first start: row 0, the row left as it is (not tier 1)
|
||||
struct Choice {
|
||||
int row = 0;
|
||||
Why why = kKeep;
|
||||
};
|
||||
|
||||
inline Choice choose(const Card& c) {
|
||||
if (c.integrated) return {c.threads && c.threads <= kFewThreads ? kRowThird : kRowHalf, kIntegrated};
|
||||
if (!c.mesh_shaders) return {kRowHalf, kNoMeshShaders};
|
||||
if (c.vram_mb && c.vram_mb <= kSmallVramMb) return {kRowHalf, kSmallVram};
|
||||
return {};
|
||||
}
|
||||
|
||||
inline const char* why_text(Why w) {
|
||||
switch (w) {
|
||||
case kIntegrated: return "an integrated GPU";
|
||||
case kNoMeshShaders: return "no mesh shaders";
|
||||
case kSmallVram: return "4.5 GB of video memory or less";
|
||||
default: return "not a weak card";
|
||||
}
|
||||
}
|
||||
|
||||
/// RX_VK_FIRST_START_AUTO (value, null when unset): -1 off; 0 on, the card's own video memory; otherwise on, the card
|
||||
/// taken as having that many MB
|
||||
inline int64_t switch_mb(const char* text) {
|
||||
if (!text || !*text) return -1;
|
||||
const long long v = std::atoll(text);
|
||||
return v <= 0 ? -1 : v == 1 ? 0 : (int64_t)v;
|
||||
}
|
||||
|
||||
/// Whether the first start's choice is made at all: the switch on, no options file, RX_VK_LOW_SPEC not asked (it sets the
|
||||
/// row itself), and no switch that sets the Render resolution for this run (HOS_DYNRES)
|
||||
inline bool applies(bool has_options, bool low_spec, bool resolution_env, int64_t switch_value) {
|
||||
return switch_value >= 0 && !has_options && !low_spec && !resolution_env;
|
||||
}
|
||||
|
||||
} // namespace first_start
|
||||
94
gpu/vk/flat_map.h
Normal file
94
gpu/vk/flat_map.h
Normal file
@@ -0,0 +1,94 @@
|
||||
// (hookshot) From Hookshot eda64e895 (dukenheimer; FlatMap by Corentin Bonjour, Hookshot PR 2774). tests/test_flat_map.py
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
/// An integer key's value, kept in one array: open addressing, linear probing, at most 3/4 full, the slot from a
|
||||
/// multiplicative hash. For the replay's per-thread caches, searched on every draw: std::unordered_map divided by a prime
|
||||
/// and followed a node pointer per lookup. No erase of one key (those caches are only cleared whole). A clear keeps a small
|
||||
/// array and gives a large one back. An insert can move every entry: no reference or pointer is held across one.
|
||||
template <class K, class V>
|
||||
class FlatMap {
|
||||
public:
|
||||
struct Slot {
|
||||
K first{};
|
||||
bool used = false;
|
||||
V second{};
|
||||
};
|
||||
|
||||
Slot* find(K key) {
|
||||
if (!count_) return nullptr;
|
||||
for (size_t i = index(key);; i = (i + 1) & mask_) {
|
||||
Slot& s = slots_[i];
|
||||
if (!s.used) return nullptr;
|
||||
if (s.first == key) return &s;
|
||||
}
|
||||
}
|
||||
Slot* end() const { return nullptr; }
|
||||
|
||||
V& operator[](K key) {
|
||||
if (Slot* s = find(key)) return s->second;
|
||||
if ((count_ + 1) * 4 > slots_.size() * 3) grow();
|
||||
return place(key).second;
|
||||
}
|
||||
|
||||
size_t size() const { return count_; }
|
||||
size_t capacity() const { return slots_.size(); }
|
||||
|
||||
/// (Triforce) every entry, as f(key, value&): no insert inside f (it can move every entry)
|
||||
template <class F>
|
||||
void each(F&& f) {
|
||||
for (Slot& s : slots_)
|
||||
if (s.used) f(s.first, s.second);
|
||||
}
|
||||
|
||||
void clear() {
|
||||
if (count_ && slots_.size() > kKeptSlots) { // (a cache cleared at its size limit: its memory goes back too)
|
||||
count_ = 0;
|
||||
std::vector<Slot>().swap(slots_);
|
||||
mask_ = 0, shift_ = 64;
|
||||
return;
|
||||
}
|
||||
reset();
|
||||
}
|
||||
|
||||
/// Empty, the array kept whatever its size: for a map emptied often that fills again to about the same size
|
||||
/// (RecordingRes::c1_at, at every recording's start), so it isn't given back and grown again from 16 each time
|
||||
void reset() {
|
||||
if (!count_) return;
|
||||
count_ = 0;
|
||||
for (Slot& s : slots_)
|
||||
if (s.used) s = Slot{};
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr size_t kKeptSlots = 4096;
|
||||
|
||||
size_t index(K key) const { return (size_t)((uint64_t)key * 0x9E3779B97F4A7C15ull >> shift_); }
|
||||
|
||||
Slot& place(K key) {
|
||||
size_t i = index(key);
|
||||
while (slots_[i].used) i = (i + 1) & mask_;
|
||||
Slot& s = slots_[i];
|
||||
s.first = key, s.used = true;
|
||||
count_++;
|
||||
return s;
|
||||
}
|
||||
|
||||
void grow() {
|
||||
std::vector<Slot> old(slots_.empty() ? 16 : slots_.size() * 2);
|
||||
old.swap(slots_);
|
||||
mask_ = slots_.size() - 1;
|
||||
shift_ = 64;
|
||||
for (size_t n = slots_.size(); n > 1; n >>= 1) shift_--;
|
||||
count_ = 0;
|
||||
for (Slot& s : old)
|
||||
if (s.used) place(s.first).second = std::move(s.second);
|
||||
}
|
||||
|
||||
std::vector<Slot> slots_;
|
||||
size_t count_ = 0, mask_ = 0;
|
||||
unsigned shift_ = 64;
|
||||
};
|
||||
78
gpu/vk/focus_anim.h
Normal file
78
gpu/vk/focus_anim.h
Normal file
@@ -0,0 +1,78 @@
|
||||
// (Triforce, 11-19) The Mods and Quit entries under the pause menu's System list, and Quit's dialog, animated as the game
|
||||
// animates its own System page buttons and its own dialogs. His "the mods and quit tabs ... have no animations either" and
|
||||
// "the quit menu submenu also has no animations". Each button of the System list (and of the game's dialogs) is the part
|
||||
// PaCommonBtnThin_00 of the Common archive's layout; a dialog is SystemWindow_00 with three of them, 188 units apart. The
|
||||
// parts play their own animations; here are their times and amounts, read from the layouts' curves (the keys: a frame, a
|
||||
// value and a slope, Hermite between them, 60 frames a second, as mods_entry_anim.h reads the title's):
|
||||
// Select 8 frames: the cursor (N_Cursor_00) shown from the first, its alpha from 0 to 1 by frame 4
|
||||
// UnSelect 14 frames: its alpha from 1 to 0 by frame 8, hidden at 14
|
||||
// In 20 frames: the window's question and buttons (N_In_00) from alpha 0 to 1 by frame 15 (slow to start: its
|
||||
// slopes 0.02 and 0.14), and rising into place from 38 units under it (122 to 142 at frame 5, 160 at 20)
|
||||
// Out 2 frames: their alpha from 1 to 0, straight
|
||||
// The buttons' cursor does not slide from one to the next: the button let go fades its cursor out while the new one fades
|
||||
// its in. No ImGui and no Vulkan: tests/test_pause_mods_anim.py compiles it alone.
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include "mods_entry_anim.h" // (the layouts' curves: Key, curve, frames)
|
||||
|
||||
namespace focus_anim {
|
||||
|
||||
using mods_entry::curve;
|
||||
using mods_entry::frames;
|
||||
using mods_entry::Key;
|
||||
using mods_entry::kFrameNs;
|
||||
|
||||
// (PaCommonBtnThin_00's: N_Cursor_00's alpha)
|
||||
constexpr Key kSelect[] = {{0, 0, 0}, {4, 1, 0}};
|
||||
constexpr Key kUnSelect[] = {{0, 1, 0}, {8, 0, 0}};
|
||||
constexpr int64_t kSelectNs = 8 * kFrameNs, kUnSelectNs = 14 * kFrameNs;
|
||||
// (SystemWindow_00's: N_In_00's alpha and its height, its place 160 units up)
|
||||
constexpr Key kInAlpha[] = {{0, 0, 0.02f}, {15, 1, 0.14f}};
|
||||
constexpr Key kInY[] = {{0, 122, 5.6094f}, {5, 142, 2.50235f}, {20, 160, 0}};
|
||||
constexpr Key kOutAlpha[] = {{0, 1, -0.5f}, {2, 0, -0.5f}};
|
||||
constexpr float kInPlace = 160;
|
||||
constexpr int64_t kInNs = 20 * kFrameNs, kOutNs = 2 * kFrameNs;
|
||||
|
||||
/// A button's cursor from one drawing to the next: how much of it shows (N_Cursor_00's alpha, 0 to 1)
|
||||
struct Focus {
|
||||
bool sel = false; // (it had the cursor at the last step)
|
||||
float from = 0; // (shown when the cursor last came or went)
|
||||
int64_t since_ns = 0; // (...and when)
|
||||
float shown = 0;
|
||||
/// One drawing at now: whether the button has the cursor. settle: as it stands once its animation is done (a still,
|
||||
/// a picture that compares, a window just opened)
|
||||
void step(int64_t now, bool selected, bool settle = false) {
|
||||
if (settle || !since_ns) {
|
||||
sel = selected, from = shown = selected ? 1.0f : 0.0f, since_ns = now;
|
||||
return;
|
||||
}
|
||||
if (selected != sel) from = shown, sel = selected, since_ns = now;
|
||||
const float f = frames(now - since_ns);
|
||||
// (a change back half way: from where it is, as mods_entry::Anim, not from the curve's own start)
|
||||
shown = sel ? std::max(from, curve(kSelect, f)) : from * curve(kUnSelect, f);
|
||||
shown = std::clamp(shown, 0.0f, 1.0f);
|
||||
}
|
||||
};
|
||||
|
||||
/// A dialog's window t ns after it opened (In) or after it closed (Out, out = true): its alpha, and how far under its place
|
||||
/// it is (the layout's units, up positive: 0 in place)
|
||||
struct Window {
|
||||
float alpha = 1, drop = 0;
|
||||
};
|
||||
inline Window window_at(int64_t t, bool out = false) {
|
||||
Window w;
|
||||
if (t < 0) t = 0;
|
||||
const float f = frames(t);
|
||||
if (out) {
|
||||
w.alpha = std::clamp(curve(kOutAlpha, f), 0.0f, 1.0f);
|
||||
return w;
|
||||
}
|
||||
w.alpha = std::clamp(curve(kInAlpha, f), 0.0f, 1.0f);
|
||||
w.drop = std::max(0.0f, kInPlace - curve(kInY, f));
|
||||
return w;
|
||||
}
|
||||
/// (the window takes input once its In has played, as the game's)
|
||||
inline bool window_ready(int64_t t) { return t >= kInNs; }
|
||||
|
||||
} // namespace focus_anim
|
||||
@@ -1,25 +1,30 @@
|
||||
// (Triforce) Foliage in the sun's far shadow cascades drawn with one face culled (vk_draw.cpp draw_cull, for dynamic_state;
|
||||
// RX_VK_FOLIAGE_SHADOW_CULL, off unless set), apart from Vulkan so that tests/test_foliage_shadow.py can run its rule.
|
||||
// (Triforce) The foliage in the sun's far shadow cascades, made cheaper (vk_draw.cpp draw_cull, for dynamic_state; and
|
||||
// foliage_rate, for the mesh draws), apart from Vulkan so that tests/test_foliage_shadow.py can run its rules. After NX2navi's
|
||||
// 754ded9 (epicmeme546's): 18 to 43 fps at Kokiri Forest's entrance on an RX 7900 XT there, the two halves together.
|
||||
//
|
||||
// The game draws its foliage cards (grass, ferns, leaves) double-sided with mesh programs, into the shadow cascades too: the
|
||||
// sun's three cascades are the layers of one depth array, 1600 x 1600 in the owner's logs. Seen from the sun the stacked,
|
||||
// alpha-tested cards cover the same texels many times over: NX2navi counted about 1,000 million fragments in one such draw of
|
||||
// the far cascade. With the switch, a draw of a mesh program (native, or through the compute fallback) into a cascade from the
|
||||
// given layer on, that culls neither face, is drawn with its back faces culled (its front ones with an "f"): half the cards'
|
||||
// fragments there. Cull mode is dynamic state, so no other pipeline is made. A cascade here is Triforce's own test for one,
|
||||
// as for the cascades' depth bias in dynamic_state: depth only, square, wider than 768 (the characters' own shadow maps, 768
|
||||
// and less, are never touched).
|
||||
// the far cascade. A cascade here is Triforce's own test for one, as for the cascades' depth bias in dynamic_state: depth only,
|
||||
// square, wider than 768 (the characters' own shadow maps, 768 and less, are never touched).
|
||||
//
|
||||
// The behaviour of NX2navi's NX2NAVI_FOLIAGE_SHADOW_CULL (epicmeme546's, on there from layer 1), written anew. It is not the same
|
||||
// picture: a card that faces away from the sun no longer casts its shadow in those cascades. Where cards stand in crossed pairs
|
||||
// or clumps others cover the same texels, but a lone card's shadow can go, so it is off here: a switch to compare, at
|
||||
// RX_VK_FOLIAGE_SHADOW_CULL=1 as NX2navi has it.
|
||||
// 1. The cull (RX_VK_FOLIAGE_SHADOW_CULL, on from layer 1 as NX2navi has it). A draw of a mesh program (native, or through the
|
||||
// compute fallback) into a cascade from the given layer on, that culls neither face, is drawn with its back faces culled (its
|
||||
// front ones with an "f"): half the cards' fragments there. Cull mode is dynamic state, so no other pipeline is made. It is not
|
||||
// quite the same picture: a card that faces away from the sun no longer casts its shadow in those cascades. Where cards stand in
|
||||
// crossed pairs or clumps (the game's foliage almost everywhere) the others cover the same texels; a lone card's shadow can go,
|
||||
// in the middle and far cascades only, where a texel is tens of centimetres to metres of ground and such a card is a fraction of
|
||||
// one. NX2navi kept it so (nothing done for a lone card), and so does this; the near cascade (layer 0) is drawn as the game asks.
|
||||
// RX_VK_FOLIAGE_SHADOW_CULL=off: as the game asks everywhere.
|
||||
//
|
||||
// Not done: NX2navi's second half, NX2NAVI_FOLIAGE_SHADOW_VRS (one fragment shaded per 2 x 2 pixels in those cascades, so the
|
||||
// leaves' alpha test runs a quarter as often). It needs VK_KHR_fragment_shading_rate enabled on the device, the shading rate as
|
||||
// dynamic state in every mesh pipeline and its libraries (a change to every mesh pipeline's creation, which the driver's cache
|
||||
// then misses) and vkCmdSetFragmentShadingRateKHR, which takes pointers, carried by the recorder (vk_recorder.h, vk_work.h);
|
||||
// none of that can be checked without the game, and its picture is not the same either (a coarser cut-out of the leaves).
|
||||
// 2. The shading rate (RX_VK_FOLIAGE_SHADOW_VRS, from layer 2 as NX2navi has it). The same draws, of native mesh programs, from
|
||||
// that layer on shade one fragment per 2 x 2 pixels (VK_KHR_fragment_shading_rate, pipelineFragmentShadingRate): the leaves'
|
||||
// alpha test runs a quarter as often. Depth is still tested and written for each texel; what is coarser is the alpha cut-out, in
|
||||
// 2 x 2 texels of the far cascade, metres of ground each. The rate is dynamic state in the pipelines that can draw such a draw and
|
||||
// in no other: native mesh programs with no colour target and a depth one (pipeline_rate), whose key that already names; they
|
||||
// set it at each draw (1 x 1 into any other target), their stage libraries are keyed apart. Where the device has no
|
||||
// pipelineFragmentShadingRate (older Intel, some APUs), without native mesh shaders, or RX_VK_FOLIAGE_SHADOW_VRS=off, the
|
||||
// extension is not enabled and no pipeline changes.
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
@@ -30,30 +35,59 @@ namespace mkwvk::foliage_shadow {
|
||||
|
||||
constexpr int kNone = 0, kFront = 1, kBack = 2; // (NVN's faces: NVN_FACE_NONE, _FRONT, _BACK)
|
||||
constexpr uint32_t kCascadeMin = 769; // (a cascade is wider than 768: vk_draw.cpp dynamic_state's test)
|
||||
constexpr int kCullFrom = 1, kRateFrom = 2; // (NX2navi's layers: the cull from the middle cascade, the rate in the far one)
|
||||
|
||||
struct Rule {
|
||||
int from = -1; // (the first cascade layer it applies to; -1: off)
|
||||
bool front = false; // (the front faces culled, not the back ones)
|
||||
};
|
||||
|
||||
/// RX_VK_FOLIAGE_SHADOW_CULL=<layer>[f]: from that layer of the cascades on (the game has three, 0 to 2; 1 is NX2navi's), the back
|
||||
/// faces culled, the front ones with an "f" after the number. Unset, empty or not starting with a digit: off
|
||||
/// RX_VK_FOLIAGE_SHADOW_CULL=<layer>[f]: from that layer of the cascades on (the game has three, 0 to 2), the back faces culled,
|
||||
/// the front ones with an "f" after the number. Unset or empty: from layer 1, the back faces (NX2navi's). Anything not starting
|
||||
/// with a digit ("off", "-1"): off
|
||||
inline Rule parse(const char* e) {
|
||||
Rule r;
|
||||
if (!e || *e < '0' || *e > '9') return r;
|
||||
if (!e || !*e) return r.from = kCullFrom, r;
|
||||
if (*e < '0' || *e > '9') return r;
|
||||
r.from = std::atoi(e);
|
||||
r.front = std::strchr(e, 'f') != nullptr;
|
||||
return r;
|
||||
}
|
||||
|
||||
/// The face a draw culls: the game's (cull, NVN's face), or under the rule the one it names, for a draw of a mesh program into a
|
||||
/// cascade (no colour target, a depth target width x height, square and wider than 768, the depth view's first layer at
|
||||
/// rule.from or past it) that culls neither face
|
||||
/// RX_VK_FOLIAGE_SHADOW_VRS=<layer>: from that layer of the cascades on, one fragment per 2 x 2 pixels. Unset or empty: from
|
||||
/// layer 2 (NX2navi's). Anything not starting with a digit ("off", "-1"): off, and the device's extension is not asked for.
|
||||
/// Returns the first layer, -1 off
|
||||
inline int parse_rate(const char* e) {
|
||||
if (!e || !*e) return kRateFrom;
|
||||
if (*e < '0' || *e > '9') return -1;
|
||||
return std::atoi(e);
|
||||
}
|
||||
|
||||
/// A draw into a cascade from layer `from` on (no colour target, a depth target width x height, square and wider than 768, the
|
||||
/// depth view's first layer at from or past it), of a mesh program, that culls neither face as the game draws it
|
||||
inline bool far_foliage(int from, int game, bool mesh_program, int colour_targets, bool depth, uint32_t width, uint32_t height,
|
||||
uint32_t layer) {
|
||||
if (from < 0 || game != kNone || !mesh_program || colour_targets != 0 || !depth) return false;
|
||||
return width == height && width >= kCascadeMin && layer >= (uint32_t)from;
|
||||
}
|
||||
|
||||
/// The face a draw culls: the game's (cull, NVN's face), or under the rule the one it names, for far_foliage's draws
|
||||
inline int cull(const Rule& rule, int game, bool mesh_program, int colour_targets, bool depth, uint32_t width, uint32_t height,
|
||||
uint32_t layer) {
|
||||
if (rule.from < 0 || game != kNone || !mesh_program || colour_targets != 0 || !depth) return game;
|
||||
if (width != height || width < kCascadeMin || layer < (uint32_t)rule.from) return game;
|
||||
if (!far_foliage(rule.from, game, mesh_program, colour_targets, depth, width, height, layer)) return game;
|
||||
return rule.front ? kFront : kBack;
|
||||
}
|
||||
|
||||
/// Whether a pipeline has the shading rate as dynamic state: the rate is on (on), the program a native mesh one, no colour
|
||||
/// target and a depth one. Only what its key names (vk_draw.cpp pipeline_key): every pipeline of a key is made alike
|
||||
inline bool pipeline_rate(bool on, bool native_mesh, int colour_targets, bool depth_format) {
|
||||
return on && native_mesh && colour_targets == 0 && depth_format;
|
||||
}
|
||||
|
||||
/// The fragment size (1 or 2, both ways) a draw through such a pipeline sets: 2 for far_foliage's draws from layer `from` on
|
||||
inline uint32_t rate(int from, int game, bool native_mesh, int colour_targets, bool depth, uint32_t width, uint32_t height,
|
||||
uint32_t layer) {
|
||||
return far_foliage(from, game, native_mesh, colour_targets, depth, width, height, layer) ? 2u : 1u;
|
||||
}
|
||||
|
||||
} // namespace mkwvk::foliage_shadow
|
||||
|
||||
@@ -28,6 +28,7 @@ struct Split {
|
||||
double wb_wait = 0; // (the waits for write-backs still on the GPU, wherever they were: memory sync's capture, a read)
|
||||
double wb_held = 0; // (of them, the part after the writer's recording was done: the timeline held, not the GPU)
|
||||
double qs_bg = 0; // (the queue submits made while a background import ran)
|
||||
double gpu_waits = 0; // ((Triforce, 11-22, SYNC-27) every thread's time in calls that block on the GPU: gpu_wait_kinds.h)
|
||||
};
|
||||
|
||||
/// Outside the replay and the present: the game's own update, its waits for the replay and the GPU among it. As the stall line's
|
||||
@@ -35,12 +36,13 @@ inline double outside(const Split& s) { return s.interval - s.replay - s.present
|
||||
|
||||
/// The columns, after the trace's first ones (their names; the line's values in this order: line)
|
||||
constexpr const char* kColumns =
|
||||
"replay_ms,present_ms,dispatch_ms,qsubmit_ms,par_wait_ms,outside_ms,game_wait_ms,captures_ms,wb_wait_ms,wb_held_ms,qs_bg_ms";
|
||||
"replay_ms,present_ms,dispatch_ms,qsubmit_ms,par_wait_ms,outside_ms,game_wait_ms,captures_ms,wb_wait_ms,wb_held_ms,qs_bg_ms,"
|
||||
"gpu_waits_ms";
|
||||
|
||||
/// The values for kColumns, comma-separated, no line end: snprintf's count
|
||||
inline int line(const Split& s, char* out, size_t cap) {
|
||||
return std::snprintf(out, cap, "%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f", s.replay, s.present, s.dispatch,
|
||||
s.qsubmit, s.par_wait, outside(s), s.game_wait, s.captures, s.wb_wait, s.wb_held, s.qs_bg);
|
||||
return std::snprintf(out, cap, "%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f", s.replay, s.present, s.dispatch,
|
||||
s.qsubmit, s.par_wait, outside(s), s.game_wait, s.captures, s.wb_wait, s.wb_held, s.qs_bg, s.gpu_waits);
|
||||
}
|
||||
|
||||
} // namespace mkwvk::frame_trace
|
||||
|
||||
49
gpu/vk/framegen_idle.h
Normal file
49
gpu/vk/framegen_idle.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// (Triforce, 11-21, the performance audit's PRESENT-18, after Source A's) When frame generation's images are let go.
|
||||
//
|
||||
// The built-in interpolation's frames, lumas, flows and made-frame sets (and, for AMD FSR 4's frame generation, the four
|
||||
// images of the picture without the HUD) are made at the first frame that needs them and were kept until a resize: turned
|
||||
// off, or left for NVIDIA's own frame generation, they stayed in VRAM for the run. Source A measured 150 to 160 MiB given
|
||||
// back at 2560 x 1440 with 2x after its switch away. They are let go after kPresents presents in a row with frame
|
||||
// generation off, about two seconds at 60: a row stepped through on the way to another choice keeps them. A present that
|
||||
// recorded made frames counts as on whatever the row says by then: its set is busy until the display thread has shown
|
||||
// it, and a drain then would wait for a job that is only queued afterwards. So the count is taken after the present's
|
||||
// queue (vk_replay.cpp, after framegen_queue). They are made again at the next frame that needs them, as after a resize.
|
||||
// RX_VK_FG_KEEP=1: kept, as before.
|
||||
//
|
||||
// The rule alone, no Vulkan: tests/test_framegen_idle.py compiles it.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace framegen_idle {
|
||||
|
||||
inline constexpr uint32_t kPresents = 120;
|
||||
|
||||
/// The presents in a row off, after this one: on now, or used at this present, starts again
|
||||
inline uint32_t next_off(uint32_t off, bool on_now, bool used) { return on_now || used ? 0 : off < UINT32_MAX ? off + 1 : off; }
|
||||
|
||||
/// Whether this present lets them go: there are some, and they have been off long enough
|
||||
inline bool due(uint32_t off, bool have) { return have && off >= kPresents; }
|
||||
|
||||
/// One present, as framegen_idle sees it after the present's queue
|
||||
struct Present {
|
||||
bool on; // frame generation on by the row, read again (framegen_on)
|
||||
bool recorded; // this present recorded made frames (framegen_record's true)
|
||||
bool hudless_wanted; // AMD FSR 4's frame generation is the row's (fsr4fg::frames_wanted)
|
||||
bool have_images; // the shared images are there (fg.w)
|
||||
bool have_hudless; // the images of the picture without the HUD are there
|
||||
};
|
||||
struct Counts {
|
||||
uint32_t off = 0, hudless_off = 0;
|
||||
};
|
||||
struct Release {
|
||||
bool shared, hudless;
|
||||
};
|
||||
/// The two counts after this present, and what it lets go. keep: RX_VK_FG_KEEP, nothing ever
|
||||
inline Release step(Counts& c, const Present& p, bool keep) {
|
||||
c.off = next_off(c.off, p.on, p.recorded);
|
||||
c.hudless_off = next_off(c.hudless_off, p.on && p.hudless_wanted, false);
|
||||
if (keep) return {false, false};
|
||||
return {due(c.off, p.have_images), due(c.hudless_off, p.have_hudless)};
|
||||
}
|
||||
|
||||
} // namespace framegen_idle
|
||||
40
gpu/vk/framegen_refresh.h
Normal file
40
gpu/vk/framegen_refresh.h
Normal file
@@ -0,0 +1,40 @@
|
||||
// (Triforce, 11-21, the upscaler audit's UPS-05) A fixed multiplier's frames, no more than the display can show.
|
||||
//
|
||||
// The Frame generation row's 2x to 8x make that many frames for each of the game's whatever the display's refresh rate
|
||||
// is; only the row's Auto goes by it. The owner's log of 11-20 has 5x on a 165 Hz display with the game near 66 frames a
|
||||
// second: 1,655 frames shown in every 5 s (331 a second, two for each refresh), each present call 2.2 to 3.0 ms where it
|
||||
// takes 0.03 ms without frame generation, and the display thread's line "0 frames shown on time, 1655 late". Half of the
|
||||
// made frames were never on the screen (the swapchain is mailbox: the newest at each refresh), and each was a pass over
|
||||
// the whole picture and a present the display thread could not keep up with.
|
||||
//
|
||||
// With the switch, a fixed multiplier makes no more frames than refreshes fall in one frame of the game: the game's
|
||||
// recent frame time over the display's period, rounded up, a tenth of a refresh forgiven so a game at a whole fraction
|
||||
// of the refresh rate is not given one more for its frames' jitter. Never more than the row asks, never fewer than the
|
||||
// game's own frame. The row's Auto and AMD FSR's own are not touched.
|
||||
//
|
||||
// RX_VK_FRAMEGEN_REFRESH=1: on. Off unless set (the row's number is the frames made, as before): it changes what a row
|
||||
// the player set shows, so it is the owner's to turn on.
|
||||
//
|
||||
// No Vulkan: tests/test_framegen_refresh.py compiles this.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace framegen_refresh {
|
||||
|
||||
/// RX_VK_FRAMEGEN_REFRESH (value, null when unset): on when it is not 0; unset, off
|
||||
inline bool on(const char* value) { return value && *value && std::atoi(value) != 0; }
|
||||
|
||||
/// The frames shown for each of the game's (the game's own among them) with a fixed multiplier m, the game's frames game_ns
|
||||
/// apart, the display refreshing every period_ns. An unknown frame time or period: m
|
||||
inline int frames(int m, int64_t game_ns, int64_t period_ns) {
|
||||
if (m <= 1 || game_ns <= 0 || period_ns <= 0) return m;
|
||||
// (the refreshes in a frame of the game, rounded up, a tenth of one forgiven: ceil(game / period - 0.1))
|
||||
const int64_t most = (game_ns * 10 + period_ns * 9 - 1) / (period_ns * 10);
|
||||
return most < 1 ? 1 : most < m ? (int)most : m;
|
||||
}
|
||||
|
||||
/// The display's period for a refresh rate in mHz (vk_main.cpp display_refresh_mhz); 0 when it is not known
|
||||
inline int64_t period_ns(int refresh_mhz) { return refresh_mhz > 0 ? (int64_t)(1000000000000LL / refresh_mhz) : 0; }
|
||||
|
||||
} // namespace framegen_refresh
|
||||
@@ -11,13 +11,44 @@
|
||||
namespace mkwvk::framegen_rows {
|
||||
|
||||
/// opts.framegen (saved as frame_generation): 0 Off, 1 Auto, 2 to 8 the multiplier, as before (an options file from before
|
||||
/// keeps its meaning), then 9: AMD FSR 4, one frame made by AMD's library between each two of the game's
|
||||
/// keeps its meaning), then 9: AMD FSR frame generation, one frame made by AMD's library between each two of the game's
|
||||
/// ((Triforce, FG-1) whichever version AMD's library has for the card: FSR 4's on an RX 9000, FSR 3.1's elsewhere. The
|
||||
/// name FSR4 stays: it is the value's, saved in options files as 9)
|
||||
enum { OFF = 0, AUTO = 1, kMaxMult = 8, FSR4 = 9, kRowMax = FSR4 };
|
||||
|
||||
/// ((Triforce, FG-9) RX_VK_FRAMEGEN_MULT=<0..9>, over the options file for a lab run: the row's whole range, 9 AMD's frame
|
||||
/// generation among it (it ran 2 to 8 alone before, and a 9 became the renderer's own 8x). Not a number: 2, as before
|
||||
inline int env_row(const char* e) {
|
||||
if (!e || !*e) return 2;
|
||||
int v = 0;
|
||||
if (std::sscanf(e, "%d", &v) != 1) return 2;
|
||||
return v < OFF ? (int)OFF : v > kRowMax ? (int)kRowMax : v;
|
||||
}
|
||||
|
||||
/// ((Triforce, FG-1) The row's value 9 by the version AMD's library makes the frames with: "AMD FSR (3.1.6)", "AMD FSR
|
||||
/// (4.0.2)"; "AMD FSR" before it is known. out holds n bytes
|
||||
inline const char* row_label(char* out, size_t n, const char* version) {
|
||||
if (!out || !n) return "";
|
||||
unsigned v[3] = {0, 0, 0};
|
||||
const bool known = version && std::sscanf(version, "%u.%u.%u", &v[0], &v[1], &v[2]) == 3;
|
||||
if (known) std::snprintf(out, n, "AMD FSR (%u.%u.%u)", v[0], v[1], v[2]);
|
||||
else std::snprintf(out, n, "AMD FSR");
|
||||
return out;
|
||||
}
|
||||
|
||||
/// Why AMD FSR 4 cannot make the frames here (the row says it); FG_OK when it can. FG_NOT_YET: not asked, the device is not
|
||||
/// made yet
|
||||
enum Why { FG_OK, FG_NOT_BUILT, FG_ENV_OFF, FG_NOT_YET, FG_NO_LIBRARY, FG_NO_FILE, FG_NO_MODEL, FG_FAILED, FG_WHY_COUNT };
|
||||
|
||||
/// ((Triforce) Why, in words, for the log line a run with the row at AMD FSR gets when AMD's library cannot make its frames)
|
||||
constexpr const char* why_name(Why w) {
|
||||
return w == FG_OK ? "it can" : w == FG_NOT_BUILT ? "not in this build (HOOKSHOT_FSR, Windows)"
|
||||
: w == FG_ENV_OFF ? "switched off (RX_VK_FSR4_FG=0 or RX_VK_FSR4=0)" : w == FG_NOT_YET ? "not asked yet (no device)"
|
||||
: w == FG_NO_LIBRARY ? "AMD's loader is not beside the game" : w == FG_NO_FILE ? "amd_fidelityfx_framegeneration_vk.dll is not beside it"
|
||||
: w == FG_NO_MODEL ? "AMD's library lists no frame generation it can take for this GPU"
|
||||
: w == FG_FAILED ? "it failed earlier in this run" : "?";
|
||||
}
|
||||
|
||||
/// The row's last value on this PC: AMD FSR 4 where it is offered, 8x elsewhere (the row as it was)
|
||||
constexpr int row_hi(bool fsr4_offered) { return fsr4_offered ? (int)FSR4 : (int)kMaxMult; }
|
||||
/// What the row shows, and what runs, for a value: itself, or 2x for a saved AMD FSR 4 on a PC where it is not offered
|
||||
@@ -38,16 +69,17 @@ inline bool parse_version(const char* name, unsigned v[3]) {
|
||||
v[0] = v[1] = v[2] = 0;
|
||||
return name && std::sscanf(name, "%u.%u.%u", &v[0], &v[1], &v[2]) == 3;
|
||||
}
|
||||
/// Of the frame generation versions AMD's library lists for this GPU, the one contexts are made with: the newest FSR 4, the
|
||||
/// first of equal ones; -1 when it lists none. An FSR 3.1 frame generation alone is not FSR 4: it never stands in under
|
||||
/// FSR 4's name, as vk_fsr4.cpp's upscaler takes no FSR 3.1 either. any (RX_VK_FSR4_FG=1, for trying the path on a card
|
||||
/// without FSR 4): the newest of whatever is listed
|
||||
inline int pick_version(const char* const* names, int n, bool any) {
|
||||
/// Of the frame generation versions AMD's library lists for this GPU, the one contexts are made with: the newest, the first
|
||||
/// of equal ones, so FSR 4's (4.x) wherever it is listed (RX 9000), else FSR 3.1's (3.1.x: RX 6000 and 7000, whose driver
|
||||
/// lists 3.1.6 alone, NX2navi 5bdf583 on the owner's RX 7900 XT); -1 when it lists none it can read. ((Triforce, FG-1)
|
||||
/// Before, a list of FSR 3.1 alone gave -1 and the row never offered AMD's frame generation on those cards. The row names
|
||||
/// the version it runs, row_label.) only_fsr4 (RX_VK_FSR4_FG=4): 4.x or nothing, as it was
|
||||
inline int pick_version(const char* const* names, int n, bool only_fsr4) {
|
||||
int best = -1;
|
||||
unsigned bv[3] = {0, 0, 0};
|
||||
for (int i = 0; i < n; i++) {
|
||||
unsigned v[3];
|
||||
if (!parse_version(names[i], v) || (!any && v[0] != 4)) continue;
|
||||
if (!parse_version(names[i], v) || (only_fsr4 && v[0] != 4)) continue;
|
||||
const bool newer = v[0] != bv[0] ? v[0] > bv[0] : v[1] != bv[1] ? v[1] > bv[1] : v[2] > bv[2];
|
||||
if (best < 0 || newer) best = i, bv[0] = v[0], bv[1] = v[1], bv[2] = v[2];
|
||||
}
|
||||
@@ -67,14 +99,34 @@ inline Pose pose_of(const float v[12]) {
|
||||
}
|
||||
return p;
|
||||
}
|
||||
/// A camera cut between two frames frame_ms apart: the camera moved over 5 units, or turned over 10 degrees while it
|
||||
/// moved over half a unit, for each 60th of a second (a slower frame may move in proportion, up to four times; the game's
|
||||
/// world is in metres, its near plane at 0.1). A made frame between the two pictures of a cut would blend two views that
|
||||
/// have nothing to do with each other: such a frame starts a new history and none is made. The thresholds are NX2navi's,
|
||||
/// from its camera traces of the same game (a median of 0.05 m and 0.08 degrees a frame in play, area loads of 5 to
|
||||
/// 180 m in one frame)
|
||||
inline bool camera_cut(const Pose& before, const Pose& now, float frame_ms) {
|
||||
const float scale = !(frame_ms > 0.0f) ? 1.0f : frame_ms < 16.667f ? 1.0f : frame_ms > 66.667f ? 4.0f : frame_ms / 16.667f;
|
||||
/// What counts as a camera cut: the turn (with a move) in degrees for each 60th of a second, and the least the time between
|
||||
/// the two frames is scaled to (in 60ths of a second; four at the most)
|
||||
struct CutRule {
|
||||
float turn_degrees;
|
||||
float min_scale;
|
||||
};
|
||||
/// Frame generation's (vk_fsr4.cpp fsr4fg): NX2navi's first thresholds (6e87c92), 10 degrees, never less than one 60th
|
||||
constexpr CutRule kFrameGenCut{10.0f, 1.0f};
|
||||
/// The upscalers' (FSR 3.1: vk_fsr3_inputs.cpp; DLSS and FSR 4: vk_temporal.cpp's chain): NX2navi's 2495391, 30 degrees.
|
||||
/// A quick swing of the camera around Link turns it 11 to 18 degrees and moves it 0.9 to 1.4 m a frame: at 10 degrees each
|
||||
/// frame of the swing started a new history, the scene at its render size for those frames, blocky at the smaller modes.
|
||||
/// ((Triforce) never less than one 60th, as frame generation's: NX2navi scaled from a quarter of one, but the time here is
|
||||
/// the CPU's between two recordings of the upscale, not the game's step, and the replay records frames back to back
|
||||
/// after a stall (a shader compile, an area load): a few ms apart, which at a quarter took a 1.25 m move, or a 7.5 degree
|
||||
/// turn with 0.125 m, for a cut, an ordinary swing among them. Above 60 fps a cut is the same move as at 60: an area load
|
||||
/// (5 to 180 m in a frame) or a jump of the camera still is one)
|
||||
constexpr CutRule kUpscalerCut{30.0f, 1.0f};
|
||||
|
||||
/// A camera cut between two frames frame_ms apart: the camera moved over 5 units, or turned over the rule's degrees while
|
||||
/// it moved over half a unit, for each 60th of a second (a slower frame may move in proportion, up to four times, a faster
|
||||
/// one down to the rule's least; the game's world is in metres, its near plane at 0.1). A made frame between the two
|
||||
/// pictures of a cut would blend two views that have nothing to do with each other: such a frame starts a new history and
|
||||
/// none is made; an upscaler's history from before a cut is no use after it. The thresholds are NX2navi's, from its camera
|
||||
/// traces of the same game (a median of 0.05 m and 0.08 degrees a frame in play, area loads of 5 to 180 m in one frame)
|
||||
inline bool camera_cut(const Pose& before, const Pose& now, float frame_ms, const CutRule& rule = kFrameGenCut) {
|
||||
const float least = rule.min_scale > 0.0f ? rule.min_scale : 1.0f;
|
||||
const float k = frame_ms / 16.667f;
|
||||
const float scale = !(frame_ms > 0.0f) ? 1.0f : k < least ? least : k > 4.0f ? 4.0f : k;
|
||||
float move2 = 0.0f, dot = 0.0f, la = 0.0f, lb = 0.0f;
|
||||
for (int i = 0; i < 3; i++) {
|
||||
const float d = now.pos[i] - before.pos[i];
|
||||
@@ -84,8 +136,8 @@ inline bool camera_cut(const Pose& before, const Pose& now, float frame_ms) {
|
||||
const float move = std::sqrt(move2);
|
||||
const float cosine = dot / std::sqrt(la * lb);
|
||||
const float turn = std::acos(cosine < -1.0f ? -1.0f : cosine > 1.0f ? 1.0f : cosine); // (radians)
|
||||
constexpr float kTenDegrees = 0.17453293f;
|
||||
return move > 5.0f * scale || (turn > kTenDegrees * scale && move > 0.5f * scale);
|
||||
const float turn_limit = rule.turn_degrees * 0.017453293f; // (radians)
|
||||
return move > 5.0f * scale || (turn > turn_limit * scale && move > 0.5f * scale);
|
||||
}
|
||||
|
||||
/// What a present with the row at AMD FSR 4 shows between the game's last frame and this one
|
||||
@@ -93,8 +145,52 @@ enum Made {
|
||||
MADE, ///< AMD's library made the frame
|
||||
OWN, ///< it did not take this present (no scene's depth and motion: a menu, a movie; not available; failed): the
|
||||
///< renderer's own interpolation makes the frame, as at 2x
|
||||
SKIP ///< a new history (the first frame, a gap, a camera cut): AMD's library was given the frame and no frame is made
|
||||
SKIP, ///< a new history (the first frame, a gap, a camera cut): AMD's library was given the frame and no frame is made
|
||||
/// ((Triforce, FG-2) the scene's depth and motion are there but AMD's library is not given the frame: no picture
|
||||
/// without the HUD this frame. The game's frame is shown alone: never a made frame of AMD's with the HUD moved in it
|
||||
/// (NX2navi 5bdf583's rule), and not the renderer's own in its place. (HDR Native and an RGBA16F scene, which hold for
|
||||
/// every present, are OWN: held_made)
|
||||
GAME
|
||||
};
|
||||
/// Whether a present's answer shows the game's frame alone, nothing made or blended before it (SKIP, GAME)
|
||||
constexpr bool game_frame_alone(Made m) { return m == SKIP || m == GAME; }
|
||||
|
||||
/// ((Triforce, FG-2) Why a present with the scene's depth and motion was not given to AMD's library, for its log.
|
||||
/// HELD_HDR_NATIVE: the game's own HDR (present_native_pq), whose picture without the HUD only the game could encode.
|
||||
/// HELD_HDR_SCENE: a run whose scene is RenoDX's RGBA16F (vk_temporal.cpp temporal_scene_format), whose upscale output is
|
||||
/// no picture without the HUD this renderer can encode as the presented one is. HELD_NO_HUDLESS: this frame has none
|
||||
enum Held { HELD_NONE, HELD_NO_HUDLESS, HELD_HDR_NATIVE, HELD_HDR_SCENE, HELD_COUNT };
|
||||
/// The reason, from what the present has: the game's own HDR first, then the run's RGBA16F scene (neither can have a
|
||||
/// picture without the HUD), then the picture without the HUD of this frame
|
||||
constexpr Held held_for(bool hdr_native, bool hdr_scene, bool have_hudless) {
|
||||
return hdr_native ? HELD_HDR_NATIVE : hdr_scene ? HELD_HDR_SCENE : !have_hudless ? HELD_NO_HUDLESS : HELD_NONE;
|
||||
}
|
||||
/// ((Triforce) Whether a reason holds for every present while it lasts (HDR Native, the RGBA16F scene), not for one frame
|
||||
/// that is missing its picture without the HUD. Then AMD's library is not asked at all (fsr4fg::frames_wanted: no inputs
|
||||
/// are made for it) and the renderer's own interpolation makes the one frame, as at 2x (OWN), which is what a saved 9 ran
|
||||
/// as on an RX 6000 or 7000 before AMD's FSR 3.1 frame generation was offered there. Only a frame missing its picture
|
||||
/// without the HUD shows the game's frame alone (GAME)
|
||||
constexpr bool held_whole_run(Held h) { return h == HELD_HDR_NATIVE || h == HELD_HDR_SCENE; }
|
||||
/// What a held present shows: the renderer's own frame for a reason that lasts, the game's frame alone for a missing picture
|
||||
constexpr Made held_made(Held h) { return held_whole_run(h) ? OWN : GAME; }
|
||||
|
||||
/// ((Triforce, FG-2) The picture without the HUD is taken at the gameplay upscale's output (its size ow x oh), the present
|
||||
/// is the window texture (sw x sh) cropped to x, y, w, h (vk_present_rect.h present_source_rect). The part of the output that
|
||||
/// is the present's crop, scaled when the two sizes differ (the handheld size's scaled crop, NX2navi 81cdd67), in whole
|
||||
/// pixels inside the output; all zero when there is nothing to take
|
||||
struct SourceRect {
|
||||
int32_t x0 = 0, y0 = 0, x1 = 0, y1 = 0;
|
||||
};
|
||||
inline SourceRect hudless_source(uint32_t ow, uint32_t oh, uint32_t sw, uint32_t sh, uint32_t x, uint32_t y, uint32_t w,
|
||||
uint32_t h) {
|
||||
SourceRect r;
|
||||
if (!ow || !oh || !sw || !sh || !w || !h || x >= sw || y >= sh) return r;
|
||||
const uint64_t rx = x + w > sw ? sw : (uint64_t)x + w, ry = y + h > sh ? sh : (uint64_t)y + h;
|
||||
r.x0 = (int32_t)((uint64_t)x * ow / sw), r.y0 = (int32_t)((uint64_t)y * oh / sh);
|
||||
r.x1 = (int32_t)(rx * ow / sw), r.y1 = (int32_t)(ry * oh / sh);
|
||||
if (r.x1 <= r.x0 || r.y1 <= r.y0) r = SourceRect{};
|
||||
return r;
|
||||
}
|
||||
|
||||
/// A frame generation context as it was made: the presented picture's size, the largest scene it takes, and whether the
|
||||
/// scene's far plane is at infinity (a context is made for one kind of depth)
|
||||
@@ -136,4 +232,24 @@ template <class Ops> void teardown(Ops& ops, bool exiting) {
|
||||
ops.destroy_images();
|
||||
}
|
||||
|
||||
// ---- (Triforce, 11-20) What a present writes into a set of frames: never past the frames the set was made with ----
|
||||
// The owner's "upscaling crash": 0xc0000005 reading 0x590 in NVIDIA's driver, inside a vkCmdCopyImage the recorder thread
|
||||
// ran, in three runs of 11-20, each with frame interpolation on and the Frame generation row stepped up in the options
|
||||
// (Auto in the first, 3x at the next start, 5x at the one after). The sets' frames are made for the row's multiplier when
|
||||
// a present begins (vk_framegen.cpp ensure_size); the present then waits for the display thread to let a set go, and
|
||||
// while frames are made the display thread is the one that runs the menu (present_image, menu_tick), so a step of the row
|
||||
// lands in that wait. The multiplier read again after it was more than the frames made, and the game's frame was copied
|
||||
// into an image that was never made (VK_NULL_HANDLE). A step down only left frames unused. The row's new multiplier takes
|
||||
// effect at the next present, which makes the sets anew.
|
||||
/// The multiplier a present records with: the row's, and no more than the frames its sets were made with
|
||||
constexpr int set_multiplier(int row_multiplier, int made_with) {
|
||||
const int most = made_with < 1 ? 1 : made_with;
|
||||
return row_multiplier < 1 ? 1 : row_multiplier > most ? most : row_multiplier;
|
||||
}
|
||||
/// The game's own frame's place in a set, after `made` made ones: the set's last frame at most
|
||||
constexpr int game_slot(int made, int made_with) {
|
||||
const int last = (made_with < 1 ? 1 : made_with) - 1;
|
||||
return made < 0 ? 0 : made > last ? last : made;
|
||||
}
|
||||
|
||||
} // namespace mkwvk::framegen_rows
|
||||
|
||||
@@ -56,4 +56,44 @@ inline float view_distance(const Camera& c, float device_depth) {
|
||||
return c.device_to_view_depth[1] / (device_depth - c.device_to_view_depth[0]);
|
||||
}
|
||||
|
||||
/// The jitter sequence's length for FSR 3.1, AMD's own rule (ffxFsr3GetJitterPhaseCount, ffx_upscale.h): 8 times the
|
||||
/// width's scale squared, truncated, with no upper bound: 18 at Quality (1.5x), 23 at Balanced, 32 at Performance, 71 or 72
|
||||
/// at Ultra Performance (3x), 8 for the Native AA. AMD FSR 4 on the frame chain takes it too ((Triforce, FSR4-10)
|
||||
/// vk_temporal.cpp chain); NVIDIA's rule (dlss_math.h dlss_jitter_phases, by area, rounded, 64 at most) stays DLSS's
|
||||
inline unsigned jitter_phases(unsigned render_width, unsigned display_width) {
|
||||
if (!render_width || !display_width) return 8;
|
||||
const float ratio = (float)display_width / (float)render_width;
|
||||
const int n = (int)(8.0f * ratio * ratio);
|
||||
return n < 1 ? 1u : (unsigned)n;
|
||||
}
|
||||
|
||||
/// The size FSR 3.1's render-size images are made at (the SDK's maxRenderSize), and whether they are made again, for a frame
|
||||
/// of rw x rh into uw x uh with images of have_w x have_h for an output of have_uw x have_uh (0 x 0: none yet). They are kept
|
||||
/// for any frame that fits them, so the game's dynamic resolution (the Render resolution row's Auto) changes only the
|
||||
/// render size each dispatch is given and the history goes on, as the SDK's FFX_FSR3UPSCALER_ENABLE_DYNAMIC_RESOLUTION
|
||||
/// does: its passes clamp what they read to the frame's render size (ClampUv, ClampLoad). Made again only for another
|
||||
/// output, or for a frame larger than them: at the output's size then (a size that grew is the dynamic resolution's, and
|
||||
/// the images are not made again for its next step), and at once with dynamic (the row's Auto). A fixed share is made at
|
||||
/// its own size. Never smaller than the frame, nor larger than the output unless the frame is
|
||||
struct ImagePlan {
|
||||
unsigned width = 0, height = 0;
|
||||
bool remake = false;
|
||||
};
|
||||
inline ImagePlan plan_images(unsigned have_w, unsigned have_h, unsigned have_uw, unsigned have_uh, unsigned rw, unsigned rh,
|
||||
unsigned uw, unsigned uh, bool dynamic) {
|
||||
ImagePlan p;
|
||||
rw = rw ? rw : 1, rh = rh ? rh : 1, uw = uw ? uw : 1, uh = uh ? uh : 1;
|
||||
const bool same_output = have_w && have_h && have_uw == uw && have_uh == uh;
|
||||
if (same_output && rw <= have_w && rh <= have_h) {
|
||||
p.width = have_w, p.height = have_h;
|
||||
return p;
|
||||
}
|
||||
// (a larger frame for the same output: the dynamic resolution's step up)
|
||||
const bool full = dynamic || same_output;
|
||||
p.width = full && uw > rw ? uw : rw;
|
||||
p.height = full && uh > rh ? uh : rh;
|
||||
p.remake = true;
|
||||
return p;
|
||||
}
|
||||
|
||||
} // namespace mkwvk::fsr3_math
|
||||
|
||||
148
gpu/vk/game_grid.h
Normal file
148
gpu/vk/game_grid.h
Normal file
@@ -0,0 +1,148 @@
|
||||
// (Triforce, 11-19) Where the game's 2D layouts are in the window: the 3840 x 2160 grid its menus and lists are laid out on
|
||||
// (the units host/oot_menu.c tells the Mods entry's list in), as the window shows it. The lab's "Title in a 16:9 window (1600x900,
|
||||
// 21:9 picture letterboxed): Mods drawn below the picture, larger, far from the list": the entry was drawn on a 16:9 column of
|
||||
// the window's whole height, which is the grid only when the picture fills the window's height.
|
||||
// - The picture: in the window between black bars, as the present puts it (vk_present_rect.h present_rect, with the
|
||||
// picture's shape: Aspect ratio's 16:10, 21:9 or 32:9, else its pixels').
|
||||
// - The grid in it: the game's layouts keep their 16:9 shape in the picture's middle on a wider picture (host/oot_wide_hud.h:
|
||||
// every layout but the kept backgrounds and fades is squeezed by 16:9 over the picture's ratio, host/hos_main.c
|
||||
// hos_wide_squeeze), its height the picture's; on a narrower one (16:10) the grid is the whole picture, narrower than 16:9
|
||||
// (the layouts squeezed across, not cut). HUD position moves panes of the HUD's own layouts only (oot_hud_out), not
|
||||
// the lists'.
|
||||
// No ImGui and no Vulkan: tests/test_mods_grid.py compiles it alone.
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
#include "vk_present_rect.h"
|
||||
|
||||
namespace mkwvk::game_grid {
|
||||
|
||||
/// The grid's rectangle in the window's pixels: its left and top, its width and height (2160 units down, 3840 across)
|
||||
struct Place {
|
||||
float x = 0, y = 0, w = 0, h = 0;
|
||||
bool picture = false; // ((11-19) from a picture the present showed; false: the window's column, none known yet)
|
||||
/// ((Triforce, 11-20) the picture itself in the window (the present's rectangle, whole pixels), with picture: the game
|
||||
/// draws nothing outside it)
|
||||
float pic_x = 0, pic_y = 0, pic_w = 0, pic_h = 0;
|
||||
};
|
||||
|
||||
/// The game's picture (picture_w x picture_h, 0 not known yet) shown in a window_w x window_h window, aspect the picture's
|
||||
/// shape (0: its pixels'). With no picture known, the window's middle 16:9 column of its whole height, as before
|
||||
inline Place of(uint32_t picture_w, uint32_t picture_h, uint32_t window_w, uint32_t window_h, double aspect) {
|
||||
Place g;
|
||||
if (!window_w || !window_h) return g;
|
||||
if (!picture_w || !picture_h) {
|
||||
g.h = (float)window_h;
|
||||
g.w = std::min((float)window_w, std::floor((float)window_h * 16.0f / 9.0f + 0.5f));
|
||||
g.x = std::floor(((float)window_w - g.w) * 0.5f);
|
||||
return g;
|
||||
}
|
||||
const PresentRect p = present_rect(picture_w, picture_h, nullptr, window_w, window_h, PresentAspect{aspect});
|
||||
const double ratio = (double)p.w / (double)p.h, squeeze = std::min(1.0, (16.0 / 9.0) / ratio);
|
||||
g.h = (float)p.h, g.y = (float)p.y, g.picture = true;
|
||||
g.pic_x = (float)p.x, g.pic_y = (float)p.y, g.pic_w = (float)p.w, g.pic_h = (float)p.h;
|
||||
g.w = (float)((double)p.w * squeeze);
|
||||
g.x = (float)p.x + ((float)p.w - g.w) * 0.5f;
|
||||
return g;
|
||||
}
|
||||
|
||||
/// A drawing made on a 16:9 column of the grid's height (its own pixels, from 0: w = h x 16 / 9 wide, unit h / 720) put on
|
||||
/// the grid: x across times kx (1 on a 16:9 grid; under 1 where the layouts are squeezed across), then moved by ox, oy
|
||||
struct Map {
|
||||
float ox = 0, oy = 0, kx = 1;
|
||||
float x(float px) const { return ox + px * kx; }
|
||||
float y(float py) const { return oy + py; }
|
||||
/// (the window's pixel back in the drawing's: the mouse)
|
||||
float back_x(float wx) const { return (wx - ox) / kx; }
|
||||
float back_y(float wy) const { return wy - oy; }
|
||||
};
|
||||
inline float column_w(const Place& g) { return std::floor(g.h * 16.0f / 9.0f + 0.5f); }
|
||||
/// ((Triforce, 11-19) on a 16:9 grid (a wider picture's middle, or a 16:9 one) the column is put on whole pixels, not
|
||||
/// stretched: the text drawn on it is on whole pixels already (ImGui's glyphs), and a part of a pixel across or a scale a
|
||||
/// little off 1 (the grid's width from the picture's, the column's rounded) left it between pixels, soft. Only a grid
|
||||
/// narrower than 16:9 (16:10) is squeezed across, as the game squeezes its layouts there)
|
||||
inline Map map_of(const Place& g) {
|
||||
Map m;
|
||||
const float cw = column_w(g);
|
||||
if (cw > 0 && g.w >= cw - 1.0f) {
|
||||
m.ox = std::round(g.x + (g.w - cw) * 0.5f), m.oy = std::round(g.y), m.kx = 1.0f;
|
||||
return m;
|
||||
}
|
||||
m.ox = std::round(g.x), m.oy = std::round(g.y), m.kx = cw > 0 ? g.w / cw : 1.0f;
|
||||
return m;
|
||||
}
|
||||
|
||||
/// A page's 16:9 column (its own pixels from 0: w x h, unit h / 720) and where it goes in the window (map)
|
||||
struct Column {
|
||||
Map map;
|
||||
float w = 0, h = 0;
|
||||
/// ((Triforce, 11-20) over the game's panes: the picture's right edge in the column's own pixels (past w where the
|
||||
/// picture is wider than the grid); 0 otherwise
|
||||
float game_x1 = 0;
|
||||
};
|
||||
/// ((Triforce, 11-19) the column a page of ours is drawn on in a window_w x window_h window. on_game: over the game's own
|
||||
/// panes (its Options screen under our tabs and their header, the Mods entry's list): on the game's grid, as those panes
|
||||
/// are, so that our plates cover them; the lab's "16:9 window, 21:9 picture letterboxed: the game's Default Settings and
|
||||
/// Back and the left edge of its help box show through beside our panel" was our tabs on the window's column of its whole
|
||||
/// height while the game's panes were on the picture's grid. Else (our options over play), and with no picture known yet,
|
||||
/// the window's middle 16:9 column of its whole height, as before (narrower windows: the whole window, not squeezed)
|
||||
inline Column column_of(const Place& grid, float window_w, float window_h, bool on_game) {
|
||||
Column c;
|
||||
if (on_game && grid.picture) {
|
||||
c.map = map_of(grid), c.w = column_w(grid), c.h = grid.h;
|
||||
c.game_x1 = c.map.back_x(grid.pic_x + grid.pic_w);
|
||||
return c;
|
||||
}
|
||||
c.w = std::min(window_w, std::floor(window_h * 16.0f / 9.0f + 0.5f)), c.h = window_h;
|
||||
c.map.ox = std::floor((window_w - c.w) * 0.5f);
|
||||
return c;
|
||||
}
|
||||
|
||||
/// ((Triforce, 11-20) A rectangle of the window, in its pixels
|
||||
struct Rect {
|
||||
float x0 = 0, y0 = 0, x1 = 0, y1 = 0;
|
||||
};
|
||||
/// ((Triforce, 11-20) A dim over a whole window_w x window_h window cut where the game's picture ends (g, from of): out[0]
|
||||
/// the picture, where a dim keeps its colour, then the bars beside, above or below it (up to four, none overlapping, all
|
||||
/// of them and the picture the window exactly), where a dim must be black. The lab's check 3 of 26670c0: our dialogs' dim
|
||||
/// (rgba(8, 5, 2, ...), lighter than black) turned the black bars a dark brown, luminance about 9. Black at the same alpha
|
||||
/// never lightens them; over the picture the dim stays as it was. With no picture known: the whole window, one part.
|
||||
/// Returns how many
|
||||
inline int dim_parts(const Place& g, float window_w, float window_h, Rect out[5]) {
|
||||
out[0] = {0, 0, window_w, window_h};
|
||||
if (!g.picture) return 1;
|
||||
const float x0 = std::clamp(g.pic_x, 0.0f, window_w), x1 = std::clamp(g.pic_x + g.pic_w, x0, window_w);
|
||||
const float y0 = std::clamp(g.pic_y, 0.0f, window_h), y1 = std::clamp(g.pic_y + g.pic_h, y0, window_h);
|
||||
out[0] = {x0, y0, x1, y1};
|
||||
int n = 1;
|
||||
if (y0 > 0) out[n++] = {0, 0, window_w, y0}; // (above)
|
||||
if (y1 < window_h) out[n++] = {0, y1, window_w, window_h}; // (below)
|
||||
if (x0 > 0) out[n++] = {0, y0, x0, y1}; // (left, between those)
|
||||
if (x1 < window_w) out[n++] = {x1, y0, window_w, y1}; // (right)
|
||||
return n;
|
||||
}
|
||||
|
||||
/// ((Triforce, 11-20) The game's guides band at the foot of its Options screen (SystemOverlay_00's N_Footer_00: W_GuideBg_00
|
||||
/// and W_GuideBg_01, right-aligned 2110 and 2174 units right of the middle, 160 high from 19 under the foot) goes on past the
|
||||
/// 16:9 column's right edge (1920): on a picture wider than the grid its end shows beside the column. The lab's check 3 of
|
||||
/// 26670c0 (the game's own tab: 16x9_10, 21x9_10, fs_10): the band seen to 238 to 240 units past the column's edge (the
|
||||
/// window pane's last texels clear), from 126 units over the foot, and our guides' plate ending at the column's edge left
|
||||
/// 75 px of it in the 1600 x 900 window and 155 px in fullscreen 3440 x 1440. Where the band ends, in units right of the middle
|
||||
constexpr float kGuideBandRight = 2160;
|
||||
/// ((Triforce, 11-20, a review of 1104352) The Options screen chosen from the pause menu (host/oot_menu.c tells it as 2): its
|
||||
/// footer may be the pause menu's own (MenuOverlay_00's band panes end 2110 units right of the middle; in the pause menu's
|
||||
/// fs_30_sys_on_title_screen.png its band fades out by about 2100), not SystemOverlay_00's to 2160. No lab shot of that screen
|
||||
/// yet: our plate ends at the smaller of the two there, so that it never runs about 50 units (33 px in fullscreen 3440 x 1440)
|
||||
/// past the game's band as a dark sliver over the bars' black
|
||||
constexpr float kPauseGuideBandRight = 2110;
|
||||
/// (where our guides' plate ends over the game's panes on column c, in its own pixels from 0: as far as the game's band
|
||||
/// (band_right units right of the middle: kGuideBandRight, the title's Options; kPauseGuideBandRight, the pause menu's), up to
|
||||
/// the picture's right edge (the game draws nothing past it); the column's right edge on a 16:9 or narrower picture (16:10:
|
||||
/// the grid is the whole picture), over play, or with no picture known)
|
||||
inline float guide_band_x1(const Column& c, float band_right = kGuideBandRight) {
|
||||
const float band = c.w * 0.5f + band_right * c.h / 2160.0f;
|
||||
return std::max(c.w, std::min(band, c.game_x1));
|
||||
}
|
||||
|
||||
} // namespace mkwvk::game_grid
|
||||
@@ -25,6 +25,15 @@
|
||||
// back from the driver's own cache in a moment. Only after kTries starts in a row that began the step and did not end it
|
||||
// is the step left out, as it was after the first. NX2navi's journal and skip list are not its owner's lines alone, so
|
||||
// nothing of them is copied: this is written from what they do.
|
||||
// ((Triforce, 11-18) A try is a start that died with the driver compiling for the step: the journal is opened before the
|
||||
// step, and its "began" word says whether that can be so. The stage libraries' pass (warm_libraries) writes it (and
|
||||
// flushes it) just before its first build_graphics, and it stays: their compiles run back to back. The program pass's
|
||||
// compute warms come first and are spread over the translation, which calls no compiler of the driver's: for them the
|
||||
// word is written just before a guarded_compute when none is under way (Journal::Compiling) and written back to 0 when the
|
||||
// last of them returned. A start that died or was stopped with the word at 0 used no try (the next one finds the count it
|
||||
// found itself): before the step, or in the translation between or after the compute warms, the 5-40 minutes after an
|
||||
// update. One with the word written counts as before, a kill in a hung driver call included. A journal of an older build,
|
||||
// without the word, counts as before)
|
||||
//
|
||||
// And the rules of the link itself, which were in graphics_pipeline's lines:
|
||||
// - a draw is linked only from libraries that are all there; a cold or failed library, or a link the driver refuses,
|
||||
@@ -123,10 +132,13 @@ inline constexpr uint32_t kJournalMagic = 0x4A574654; // ("TFWJ")
|
||||
inline constexpr uint32_t kSkipMagic = 0x53574654; // ("TFWS")
|
||||
inline constexpr int kSlots = 64; // (the workers of the preparation at most: prepare_threads.h)
|
||||
inline constexpr uint32_t kTries = 3; // (starts in a row that may begin the step and not end it)
|
||||
inline constexpr uint32_t kBeganMark = 0x42574654; // ("TFWB": the driver may be compiling for the step)
|
||||
inline constexpr long kBeganAt = 16 + 16 * kSlots; // (the word after the slots; a file without it is an older build's)
|
||||
|
||||
/// What a start found of the last one's journal
|
||||
struct Left {
|
||||
bool found = false; // (a journal was there: the last start began the step and did not end it)
|
||||
bool began = true; // (and the driver may have been compiling for it: false, it used no try)
|
||||
uint32_t tries = 0; // (the starts in a row that did so, the last one counted; 0: none, or another driver's)
|
||||
std::vector<Id> in_hand; // (the variants its workers had in the driver's hands when it ended)
|
||||
};
|
||||
@@ -145,11 +157,16 @@ inline Left journal_left(const std::string& path, uint64_t stamp) {
|
||||
l.tries = 1;
|
||||
} else if (was == stamp) {
|
||||
l.tries = head[1] ? head[1] : 1;
|
||||
for (int i = 0; i < kSlots; i++) {
|
||||
int slots = 0;
|
||||
for (; slots < kSlots; slots++) {
|
||||
uint64_t r[2];
|
||||
if (fread(r, 8, 2, f) != 2) break;
|
||||
if (r[0] || r[1]) l.in_hand.push_back({r[0], r[1]});
|
||||
}
|
||||
// ((Triforce) the began word: 0, the start ended with no compile of the step under way, and it is not counted.
|
||||
// Without the word (an older build's journal, or one cut short) or with anything else in it, it counts, as before)
|
||||
uint32_t began = kBeganMark;
|
||||
if (slots == kSlots && fread(&began, 4, 1, f) == 1 && began == 0 && l.in_hand.empty()) l.began = false, l.tries--;
|
||||
}
|
||||
fclose(f);
|
||||
return l;
|
||||
@@ -165,19 +182,55 @@ public:
|
||||
Journal(const Journal&) = delete;
|
||||
Journal& operator=(const Journal&) = delete;
|
||||
~Journal() { close(); }
|
||||
/// tries: the starts in a row that began the step, this one counted
|
||||
/// tries: the starts in a row that began the step, this one counted (it counts only while the word is on the disk: began(), Compiling)
|
||||
bool open(const std::string& path, uint64_t stamp, uint32_t tries) {
|
||||
std::lock_guard lk(mu_);
|
||||
if (f_) fclose(f_);
|
||||
began_.store(false, std::memory_order_relaxed);
|
||||
compiling_ = 0;
|
||||
f_ = fopen(path.c_str(), "wb");
|
||||
if (!f_) return false;
|
||||
const uint32_t head[2] = {kJournalMagic, tries};
|
||||
const uint64_t zero[2 * kSlots]{};
|
||||
const uint32_t not_yet = 0;
|
||||
const bool ok = fwrite(head, 4, 2, f_) == 2 && fwrite(&stamp, 8, 1, f_) == 1 &&
|
||||
fwrite(zero, 8, (size_t)(2 * kSlots), f_) == (size_t)(2 * kSlots) && fflush(f_) == 0;
|
||||
fwrite(zero, 8, (size_t)(2 * kSlots), f_) == (size_t)(2 * kSlots) && fwrite(¬_yet, 4, 1, f_) == 1 &&
|
||||
fflush(f_) == 0;
|
||||
if (!ok) fclose(f_), f_ = nullptr;
|
||||
return ok;
|
||||
}
|
||||
/// ((Triforce) Any worker of the stage libraries' pass, just before a compile call: the start counts as a try from
|
||||
/// here on, for good. The first call writes the word; the others wait for it on the lock, then go by the flag. No
|
||||
/// journal: nothing. (A failed write, over bytes the file has already, is tried once: the marks go on as before it)
|
||||
void began() {
|
||||
if (began_.load(std::memory_order_acquire)) return;
|
||||
std::lock_guard lk(mu_);
|
||||
if (!f_ || began_.load(std::memory_order_relaxed)) return;
|
||||
word(kBeganMark);
|
||||
began_.store(true, std::memory_order_release);
|
||||
}
|
||||
bool has_begun() const { return began_.load(std::memory_order_acquire); }
|
||||
/// ((Triforce) One compile of the step that is not one of a run of them (the program pass's compute warms), held for as
|
||||
/// long as the driver has it: the first of those under way writes the word, the last to return writes 0 over it, so a
|
||||
/// start that dies between them, in the translation, uses no try. Once began() wrote it, the word stays. No journal:
|
||||
/// nothing. (A 0 that cannot be written leaves the word as it was: the start counts, as before)
|
||||
class Compiling {
|
||||
public:
|
||||
explicit Compiling(Journal& j) : j_(j.enter() ? &j : nullptr) {}
|
||||
Compiling(const Compiling&) = delete;
|
||||
Compiling& operator=(const Compiling&) = delete;
|
||||
~Compiling() {
|
||||
if (j_) j_->leave();
|
||||
}
|
||||
|
||||
private:
|
||||
Journal* j_;
|
||||
};
|
||||
/// Whether the word is written now (by began(), or a Compiling under way): what a start that died here would leave
|
||||
bool counts() {
|
||||
std::lock_guard lk(mu_);
|
||||
return f_ && (began_.load(std::memory_order_relaxed) || compiling_ > 0);
|
||||
}
|
||||
/// Worker slot's variant, about to go to the driver ({0, 0}: it came back). A slot past the last has no line
|
||||
void mark(int slot, Id id) {
|
||||
if (slot < 0 || slot >= kSlots) return;
|
||||
@@ -192,8 +245,24 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void word(uint32_t v) { // (under mu_)
|
||||
if (fseek(f_, kBeganAt, SEEK_SET) == 0 && fwrite(&v, 4, 1, f_) == 1) fflush(f_);
|
||||
}
|
||||
bool enter() {
|
||||
std::lock_guard lk(mu_);
|
||||
if (!f_ || began_.load(std::memory_order_relaxed)) return false;
|
||||
if (compiling_++ == 0) word(kBeganMark);
|
||||
return true;
|
||||
}
|
||||
void leave() {
|
||||
std::lock_guard lk(mu_);
|
||||
if (!f_ || compiling_ == 0) return;
|
||||
if (--compiling_ == 0 && !began_.load(std::memory_order_relaxed)) word(0);
|
||||
}
|
||||
std::mutex mu_;
|
||||
FILE* f_ = nullptr;
|
||||
std::atomic<bool> began_{false};
|
||||
unsigned compiling_ = 0; // (the Compiling under way; mu_)
|
||||
};
|
||||
|
||||
/// The skip list at path for this stamp (another stamp's, or no file: empty)
|
||||
|
||||
@@ -2,10 +2,68 @@
|
||||
there. */
|
||||
#pragma once
|
||||
|
||||
#include <cctype>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace mkwvk::gpu_choice {
|
||||
|
||||
/// The row's choice as a position in the Vulkan 1.3 devices (0-based), or -1 for Auto. menu: opts.gpu_device (0 Auto,
|
||||
/// n the n-th usable device); usable: how many there are now. A choice past them (a GPU taken out since) is Auto.
|
||||
inline int menu_device(int menu, int usable) { return menu > 0 && menu <= usable ? menu - 1 : -1; }
|
||||
|
||||
/// ((Triforce) 11-20) A device's name as the choice compares it: lower case, every run of white space one space, none at
|
||||
/// either end. Windows and Vulkan name the same card alike but not always to the space ("AMD Radeon RX 7800 XT" from one
|
||||
/// AMD driver, "AMD Radeon RX 7800 XT" from the other)
|
||||
inline std::string name_key(const std::string& s) {
|
||||
std::string out;
|
||||
bool space = false;
|
||||
for (unsigned char c : s) {
|
||||
if (std::isspace(c) || c < 0x20) { space = !out.empty(); continue; }
|
||||
if (space) out += ' ', space = false;
|
||||
out += (char)std::tolower(c);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// ((Triforce) 11-20, tickets "iGPU used on laptop with dGPU to compile shaders", "Launcher choosing the wrong GPU when
|
||||
/// compiling shaders" and two more) The device a choice means: by its name when one was saved (triforce_options.ini
|
||||
/// gpu_device_name, which the launcher and the menu write with the number), else by the number as before (menu_device).
|
||||
/// The launcher numbered the cards in Windows' order before the game had ever run (no triforce_gpus.txt yet), and Vulkan's
|
||||
/// is often the other way round on a laptop: its "2: RTX 5060" was the game's 2, the 860M, and the build prepared every
|
||||
/// shader there. A name that matches several cards (two of the same) takes the numbered one when its name is that name,
|
||||
/// else the first. No name, or none matching (the card taken out): the number decides. Auto (menu 0) is Auto whatever name
|
||||
/// the file still has. names: the usable devices' names in the game's order. Returns a position in them (0-based) or -1 for Auto
|
||||
inline int pick(const std::string& want, const std::vector<std::string>& names, int menu) {
|
||||
if (menu <= 0) return -1; // (Auto: a name left in the file chooses nothing)
|
||||
const std::string key = name_key(want);
|
||||
if (!key.empty()) {
|
||||
const int numbered = menu_device(menu, (int)names.size());
|
||||
if (numbered >= 0 && name_key(names[(size_t)numbered]) == key) return numbered;
|
||||
for (size_t i = 0; i < names.size(); i++)
|
||||
if (name_key(names[i]) == key) return (int)i;
|
||||
}
|
||||
return menu_device(menu, (int)names.size());
|
||||
}
|
||||
|
||||
/// ((Triforce) 11-22, tickets "igpu targeted for shader cache", "Launcher \"GPU device\" setting is non-functional" (RX 6600
|
||||
/// with a Ryzen 5600G's graphics) and on 0.6.0 "still picking IGPU for building shaders") The choice that pick takes by its
|
||||
/// number alone (no saved name, or a name no card has here) when that number is the processor's graphics while a card of its
|
||||
/// own is listed: not taken, Auto instead. Such a number comes from an options file written before 11-20, when the launcher
|
||||
/// numbered the cards in Windows' order (the display class's driver keys: the processor graphics' driver first on a 5600G)
|
||||
/// and saved no name with it; the update to 0.6.0 still prepared its shaders there and the game started there, as no name
|
||||
/// came with the number until the row was chosen again. A choice saved with its name (the launcher and the menu since 11-20)
|
||||
/// is taken as it is, the processor graphics too. types: the usable devices' VkPhysicalDeviceType (1 integrated, 2 discrete),
|
||||
/// in the game's order, as names
|
||||
inline bool unnamed_integrated(const std::string& want, const std::vector<std::string>& names, const std::vector<int>& types,
|
||||
int menu) {
|
||||
const int k = pick(want, names, menu);
|
||||
if (k < 0 || (size_t)k >= types.size() || types[(size_t)k] != 1) return false;
|
||||
const std::string key = name_key(want);
|
||||
if (!key.empty() && name_key(names[(size_t)k]) == key) return false; // (chosen by its name)
|
||||
for (const int t : types)
|
||||
if (t == 2) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace mkwvk::gpu_choice
|
||||
|
||||
57
gpu/vk/gpu_clock.h
Normal file
57
gpu/vk/gpu_clock.h
Normal file
@@ -0,0 +1,57 @@
|
||||
// (Triforce) Whether the renderer holds an AMD GPU at amdgpu's stable power state while the game runs, and which one (Linux:
|
||||
// vk_gpu_clock.cpp; RX_VK_GPU_CLOCK). Plain code with no system calls: tests/test_gpu_clock.py runs it on made-up devices.
|
||||
//
|
||||
// The Steam Deck's automatic GPU clock drops while the frame waits on the CPU or a readback (200 MHz for 27% of a Kokiri run), so
|
||||
// the GPU work after the wait runs slow. amdgpu lets any process that opens the GPU's render node ask for a stable power state
|
||||
// through a context of its own (DRM_IOCTL_AMDGPU_CTX, AMDGPU_CTX_OP_SET_STABLE_PSTATE, Linux 5.18): no root and no sysfs write.
|
||||
// The kernel gives the level back when that context goes, at the process's end too, a crash or kill -9 included. Measured on a
|
||||
// Deck OLED (SteamOS 3.9.5, plugged in): Kokiri handheld 11.1 -> 16.2 fps, 1% low 6.8 -> 12.1, GPU time 58 -> 32 ms at the same
|
||||
// 15 W; Hyrule Field +19% for 4 W more. It costs battery where the APU was under its power cap.
|
||||
//
|
||||
// - Unset: the peak state, on the Deck's APU only (its Vulkan name, or SteamDeck=1 from Steam on an integrated AMD GPU), and
|
||||
// only while the level is amdgpu's own (power_dpm_force_performance_level "auto"): a level the player set is left alone.
|
||||
// - RX_VK_GPU_CLOCK=0: nothing opened. =peak (or 1), =standard: that state on any AMD GPU, whatever the level.
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
|
||||
namespace mkwvk::gpu_clock {
|
||||
|
||||
enum Want { kNone, kPeak, kStandard };
|
||||
|
||||
// (uapi/drm/amdgpu_drm.h, written out: no libdrm and no kernel headers needed to build)
|
||||
constexpr uint32_t kCtxOpAlloc = 1, kCtxOpSetStablePstate = 6;
|
||||
constexpr uint32_t kPstateStandard = 1, kPstatePeak = 4;
|
||||
constexpr uint32_t kCtxArgBytes = 16; // (union drm_amdgpu_ctx)
|
||||
/// DRM_IOCTL_AMDGPU_CTX: DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CTX, union drm_amdgpu_ctx) = _IOWR('d', 0x40 + 0x02, 16 bytes)
|
||||
constexpr unsigned long kCtxIoctl = (3ul << 30) | ((unsigned long)kCtxArgBytes << 16) | ((unsigned long)'d' << 8) | 0x42ul;
|
||||
|
||||
/// The Deck's APU: "AMD Custom GPU 0405" (LCD) or "0932" (OLED) in its Vulkan name; or SteamDeck=1 (Steam sets it there) on an
|
||||
/// integrated GPU
|
||||
inline bool deck_apu(const char* device_name, bool integrated, const char* steam_deck_env) {
|
||||
if (device_name && (std::strstr(device_name, "Custom GPU 0405") || std::strstr(device_name, "Custom GPU 0932"))) return true;
|
||||
return integrated && steam_deck_env && !std::strcmp(steam_deck_env, "1");
|
||||
}
|
||||
|
||||
struct Choice {
|
||||
Want want;
|
||||
const char* why;
|
||||
};
|
||||
|
||||
/// switch_value: RX_VK_GPU_CLOCK (nullptr unset); level: power_dpm_force_performance_level's text, first word (nullptr: unread)
|
||||
inline Choice choose(const char* switch_value, uint32_t vendor_id, bool integrated, const char* device_name,
|
||||
const char* steam_deck_env, const char* level) {
|
||||
if (vendor_id != 0x1002) return {kNone, "not an AMD GPU"};
|
||||
if (switch_value && *switch_value) {
|
||||
if (!std::strcmp(switch_value, "0")) return {kNone, "RX_VK_GPU_CLOCK=0"};
|
||||
if (!std::strcmp(switch_value, "peak") || !std::strcmp(switch_value, "1")) return {kPeak, "RX_VK_GPU_CLOCK=peak"};
|
||||
if (!std::strcmp(switch_value, "standard")) return {kStandard, "RX_VK_GPU_CLOCK=standard"};
|
||||
}
|
||||
if (!deck_apu(device_name, integrated, steam_deck_env)) return {kNone, "not a Steam Deck (RX_VK_GPU_CLOCK=peak: any AMD GPU)"};
|
||||
if (!level) return {kNone, "the GPU's performance level could not be read"};
|
||||
if (std::strcmp(level, "auto")) return {kNone, "the GPU's performance level is set by hand"};
|
||||
return {kPeak, "the Steam Deck's GPU, its level amdgpu's own"};
|
||||
}
|
||||
|
||||
} // namespace mkwvk::gpu_clock
|
||||
86
gpu/vk/gpu_wait_kinds.h
Normal file
86
gpu/vk/gpu_wait_kinds.h
Normal file
@@ -0,0 +1,86 @@
|
||||
// (Triforce, 11-22, the performance audit's SYNC-27, after Source A's) The host's time in calls that block on the GPU,
|
||||
// counted by kind where the Vulkan calls are wrapped (vk_work.h).
|
||||
//
|
||||
// The log's "GPU-bound wait" counts only the waits for a recording slot: it reads about 0 while threads wait on the GPU
|
||||
// elsewhere (a fence of the game's, a write-back, the present's frame fence, a device idle, a query read that waits).
|
||||
// Those were timed apart or not at all. Here every blocking wait is timed in one place and summed by kind:
|
||||
// fences vkWaitForFences with a timeout above 0
|
||||
// timelines vkWaitSemaphores with a timeout above 0
|
||||
// idle vkQueueWaitIdle, vkDeviceWaitIdle
|
||||
// queries vkGetQueryPoolResults with VK_QUERY_RESULT_WAIT_BIT
|
||||
// A poll (timeout 0, no wait bit) counts nothing. A wait made inside another counts once, as the outer one (a depth of
|
||||
// the thread's). A wait inside an Exclude scope counts nothing: pacing (the driver's low-latency sleep), which is not a
|
||||
// wait for the GPU's work. The totals only grow; each reader keeps its own last values (Reader), so the log's line and
|
||||
// the frame trace's column each see every nanosecond.
|
||||
//
|
||||
// The cost is two clock reads a blocking wait. RX_VK_GPU_WAITS=0, or the lab knob nogpuwaits in its phases: the calls
|
||||
// straight through, nothing counted. No Vulkan here: tests/test_gpu_waits.py compiles it.
|
||||
#pragma once
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
#include "lab_ab.h"
|
||||
|
||||
namespace gpu_wait_kinds {
|
||||
|
||||
enum Kind : int { FENCE = 0, TIMELINE = 1, IDLE = 2, QUERY = 3, KINDS = 4 };
|
||||
|
||||
struct Totals {
|
||||
std::atomic<int64_t> ns[KINDS]{}, n[KINDS]{};
|
||||
};
|
||||
inline Totals totals; // (every thread's, since the start: they only grow)
|
||||
inline thread_local int depth = 0; // (this thread is inside a counted wait)
|
||||
inline thread_local int excluded = 0; // (this thread is inside an Exclude scope)
|
||||
|
||||
/// Counted at all (RX_VK_GPU_WAITS, read once; on unless 0), and not in the lab knob's phases
|
||||
inline bool on() {
|
||||
static const bool env = [] {
|
||||
const char* e = getenv("RX_VK_GPU_WAITS");
|
||||
return !(e && *e && atoi(e) == 0);
|
||||
}();
|
||||
return env && !mkwvk::lab_ab::on("nogpuwaits");
|
||||
}
|
||||
|
||||
/// The waits made on this thread while one of these lives count nothing
|
||||
struct Exclude {
|
||||
Exclude() { excluded++; }
|
||||
~Exclude() { excluded--; }
|
||||
Exclude(const Exclude&) = delete;
|
||||
Exclude& operator=(const Exclude&) = delete;
|
||||
};
|
||||
|
||||
/// call(), and its time under `kind` when it blocks (blocks: a timeout above 0, the wait bit), unless this thread is
|
||||
/// inside a counted wait or an Exclude scope, or the count is off. What call() returns
|
||||
template <class Call>
|
||||
inline auto timed(Kind kind, bool blocks, Call&& call) -> decltype(call()) {
|
||||
if (!blocks || depth || excluded || !on()) return call();
|
||||
depth++;
|
||||
const auto t0 = std::chrono::steady_clock::now();
|
||||
const auto result = call();
|
||||
const int64_t ns = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now() - t0).count();
|
||||
depth--;
|
||||
totals.ns[kind].fetch_add(ns, std::memory_order_relaxed);
|
||||
totals.n[kind].fetch_add(1, std::memory_order_relaxed);
|
||||
return result;
|
||||
}
|
||||
|
||||
/// One reader's last values: take() gives what was counted since its last take (ns and waits by kind, either may be
|
||||
/// null) and returns the nanoseconds of all kinds together
|
||||
struct Reader {
|
||||
int64_t last_ns[KINDS]{}, last_n[KINDS]{};
|
||||
int64_t take(int64_t* ns_by_kind, int64_t* n_by_kind) {
|
||||
int64_t all = 0;
|
||||
for (int k = 0; k < KINDS; k++) {
|
||||
const int64_t ns = totals.ns[k].load(std::memory_order_relaxed), n = totals.n[k].load(std::memory_order_relaxed);
|
||||
if (ns_by_kind) ns_by_kind[k] = ns - last_ns[k];
|
||||
if (n_by_kind) n_by_kind[k] = n - last_n[k];
|
||||
all += ns - last_ns[k];
|
||||
last_ns[k] = ns, last_n[k] = n;
|
||||
}
|
||||
return all;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace gpu_wait_kinds
|
||||
112
gpu/vk/guest_holes.h
Normal file
112
gpu/vk/guest_holes.h
Normal file
@@ -0,0 +1,112 @@
|
||||
// (Triforce) The all-zero upload check's reads (vk_texture.cpp upload_all_zero): which bytes of a storage it reads, split between its
|
||||
// threads. tests/test_guest_holes.py.
|
||||
//
|
||||
// On Linux, where /dev/udmabuf is usable, the guest window is a memfd's (host/hos_main.c). A page the game never wrote is a hole
|
||||
// there: it reads as zero, but a read through the shared mapping makes the kernel allocate and zero it. The check read every byte
|
||||
// of a 32 MB+ storage, so the never-written 288 MB shadow map (12288 x 12288 D16) became RAM at each Hyrule Field arrival, and
|
||||
// took 200-300 ms of the replay thread on a Steam Deck. fd_data_extents asks the memfd where its data is (lseek SEEK_DATA and
|
||||
// SEEK_HOLE): a hole is zero by definition, and SEEK_DATA may call a hole data, never the other way round (a page in swap is
|
||||
// data), so reading only the data says the same. Anywhere else, or on any failure, one extent of the whole storage.
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
#if defined(__linux__) || defined(GUEST_HOLES_TEST) // (the test: its own lseek)
|
||||
#include <cerrno>
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace mkwvk::guest_holes {
|
||||
|
||||
struct Extent {
|
||||
uint64_t lo, hi; // (bytes from the storage's start)
|
||||
};
|
||||
|
||||
inline uint64_t bytes(const std::vector<Extent>& ex) {
|
||||
uint64_t n = 0;
|
||||
for (const Extent& e : ex) n += e.hi - e.lo;
|
||||
return n;
|
||||
}
|
||||
|
||||
/// Thread t's part of n: the extents' bytes, not their range, split into n runs of whole 4 KB (the last takes the rest); every
|
||||
/// byte of the extents in exactly one part
|
||||
inline std::vector<Extent> share(const std::vector<Extent>& ex, uint32_t t, uint32_t n) {
|
||||
std::vector<Extent> out;
|
||||
const uint64_t total = bytes(ex);
|
||||
if (!n || t >= n || !total) return out;
|
||||
const uint64_t per = ((total / n) + 4095) & ~4095ull;
|
||||
const uint64_t a = std::min<uint64_t>(total, (uint64_t)t * per), b = t + 1 == n ? total : std::min<uint64_t>(total, a + per);
|
||||
uint64_t at = 0; // (bytes of the extents before e)
|
||||
for (const Extent& e : ex) {
|
||||
const uint64_t len = e.hi - e.lo, lo = std::max(a, at), hi = std::min(b, at + len);
|
||||
if (lo < hi) out.push_back({e.lo + (lo - at), e.lo + (hi - at)});
|
||||
at += len;
|
||||
if (at >= b) break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// Whether any byte of p's extents is not 0, read on nthreads threads (this one among them), each stopping once one found it
|
||||
inline bool any_set(const uint8_t* p, const std::vector<Extent>& ex, uint32_t nthreads) {
|
||||
std::atomic<bool> found{false};
|
||||
if (ex.empty()) return false;
|
||||
nthreads = std::max(nthreads, 1u);
|
||||
auto part = [&](uint32_t t) {
|
||||
for (const Extent& e : share(ex, t, nthreads))
|
||||
for (uint64_t at = e.lo; at < e.hi && !found.load(std::memory_order_relaxed); at += 65536) {
|
||||
const uint64_t end = std::min<uint64_t>(e.hi, at + 65536);
|
||||
uint64_t acc = 0;
|
||||
uint64_t k = at;
|
||||
for (; k + 8 <= end; k += 8) {
|
||||
uint64_t w;
|
||||
std::memcpy(&w, p + k, 8);
|
||||
acc |= w;
|
||||
}
|
||||
for (; k < end; k++) acc |= p[k];
|
||||
if (acc) found.store(true, std::memory_order_relaxed);
|
||||
}
|
||||
};
|
||||
if (nthreads > 1) {
|
||||
std::vector<std::thread> th;
|
||||
for (uint32_t t = 1; t < nthreads; t++) th.emplace_back(part, t);
|
||||
part(0);
|
||||
for (auto& x : th) x.join();
|
||||
} else {
|
||||
part(0);
|
||||
}
|
||||
return found.load();
|
||||
}
|
||||
|
||||
#if defined(__linux__) || defined(GUEST_HOLES_TEST) // (the test: its own lseek)
|
||||
/// The data of [off, off + len) in fd, as extents from off (none: all holes). At most max extents: past them, the rest as one.
|
||||
/// False when the file cannot say (a seek failed): the caller reads it all
|
||||
inline bool fd_data_extents(int fd, uint64_t off, uint64_t len, std::vector<Extent>* out, size_t max = 1024) {
|
||||
out->clear();
|
||||
const uint64_t end = off + len;
|
||||
uint64_t pos = off;
|
||||
while (pos < end) {
|
||||
if (out->size() + 1 >= max) { // (the last one: the rest, whole)
|
||||
out->push_back({pos - off, len});
|
||||
return true;
|
||||
}
|
||||
const off_t d = lseek(fd, (off_t)pos, SEEK_DATA);
|
||||
if (d < 0) {
|
||||
if (errno == ENXIO) return true; // (no data from pos to the file's end)
|
||||
return out->clear(), false;
|
||||
}
|
||||
if ((uint64_t)d >= end) return true;
|
||||
const off_t h = lseek(fd, d, SEEK_HOLE);
|
||||
if (h < 0 || (uint64_t)h <= (uint64_t)d) return out->clear(), false;
|
||||
const uint64_t hi = std::min<uint64_t>(end, (uint64_t)h);
|
||||
out->push_back({(uint64_t)d - off, hi - off});
|
||||
pos = hi;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace mkwvk::guest_holes
|
||||
@@ -9,6 +9,21 @@ namespace mkwvk::hangwatch {
|
||||
|
||||
constexpr int kReports = 3; // (at most this many a run: a game that stalls again and again says so three times)
|
||||
|
||||
// ((Triforce) The stacks asked for from outside: a file of this name beside the report's, "triforce_hang.txt.now" in the game
|
||||
// folder, is looked for every second; the watch takes it away and writes where every thread is, into the log and the
|
||||
// report's file, whether or not a frame is shown. For a game that goes on showing frames and gets nowhere: the owner's
|
||||
// save that did not load on 2026-11-20 showed its loading screen at 240 frames a second for minutes, one game thread
|
||||
// (BaseProcCreateAndDeleteThread) at a whole core, and the stall's own report never came: frames were shown. Asked for
|
||||
// with a file because that needs nothing done to the game's process from outside. At most kAsked a run)
|
||||
constexpr const char* kAskSuffix = ".now";
|
||||
constexpr int kAsked = 16;
|
||||
/// Whether an ask found now is served: the first kAsked of a run (`served`: how many were, counted up here)
|
||||
inline bool ask(int& served) {
|
||||
if (served >= kAsked) return false;
|
||||
served++;
|
||||
return true;
|
||||
}
|
||||
|
||||
struct Watch {
|
||||
int64_t presents = -1; // the presents counted at the last look
|
||||
int still = 0; // judged seconds running without one
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
// what it waits for comes within it, it never decides anything. The audit's trace: the helpers began a segment 0.262 ms after
|
||||
// they were given it, and the replay thread waited 1.74 ms a frame for them (r22-trace). tests/test_helper_spin.py
|
||||
//
|
||||
// RX_VK_HELPER_SPIN_US=<us>: the spin's bound (100, NX2navi's; at most 1000000); 0: no spin, straight to the wait as before
|
||||
// RX_VK_HELPER_SPIN_US=<us>: the spin's bound (20 since 11-21; 100 before, NX2navi's; at most 1000000); 0: no spin, straight to the wait as before
|
||||
#pragma once
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
@@ -20,7 +20,8 @@ namespace helper_spin {
|
||||
|
||||
/// The bound in nanoseconds that RX_VK_HELPER_SPIN_US's text gives (null: unset)
|
||||
inline int64_t bound_ns(const char* text) {
|
||||
if (!text || !*text) return 100000;
|
||||
if (!text || !*text) return 20000; // ((Triforce, 11-21) 20 us, was 100 (NX2navi's): with the game's threads the frame's limit, a
|
||||
// helper spinning 100 us took its SMT sibling from them. Lab A/B 79.3 -> 80.0, 1% low +2.0)
|
||||
const long long us = std::atoll(text);
|
||||
return us <= 0 ? 0 : us >= 1000000 ? 1000000000LL : us * 1000;
|
||||
}
|
||||
|
||||
53
gpu/vk/import_budget.h
Normal file
53
gpu/vk/import_budget.h
Normal file
@@ -0,0 +1,53 @@
|
||||
// What the idle imports' valve measures the system heap against (no game, no GPU: a rule).
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's MEM-22, after Source A's.) An import is a pool of the game's memory the driver
|
||||
// pins and counts in the system heap. vk_memory.cpp imports_give_back gives idle ones back past RX_VK_IMPORT_HIGH percent
|
||||
// (85) of that heap's budget, down to RX_VK_IMPORT_LOW percent (75), but by default only where the budget is under 12 GB:
|
||||
// on a PC with more, live imports pile up for the whole session (2.0 GB at a fresh Market, 6.5 GB after ten areas), and
|
||||
// on Linux's amdgpu every submission pays for each one. Source A's numbers (Arch, RX 9070 XT, RADV, 32 GB, a 15,434 MB
|
||||
// budget): uncapped after about two hours 221 live imports (7,392 MB), queue submit 1.11-1.14 ms, read-back waits
|
||||
// 6.29-7.03 ms, 1,511 MB of swap, 44-48 fps; capped, 50-64 live (2,256-2,720 MB), 0.32-0.73 ms, 0.64-1.14 ms, no swap,
|
||||
// 63-68 fps (with other settings changed in the same runs: the cap's own share is not known).
|
||||
//
|
||||
// So with Mesa's RADV and a budget of 12 GB or more the valve is on and measures the heap against 4,500 MB, not the whole
|
||||
// budget, and a pass of it gives back 1 GB at most. Everything else is as it was:
|
||||
// - a budget under 12 GB: the whole budget, on (any driver);
|
||||
// - 12 GB or more on any other driver: off unless RX_VK_IMPORT_HIGH is set, then the whole budget;
|
||||
// - RX_VK_IMPORT_HIGH or RX_VK_IMPORT_LOW set by the player: the whole budget, as before, RADV too.
|
||||
// RX_VK_IMPORT_CAP_MB=<n>: the cap on any driver and any budget (it turns the valve on); =0: no cap, which is RADV's
|
||||
// behaviour before. A given-back import costs 5-45 ms when its pool is bound again, which is why only pools idle for 600
|
||||
// submissions go.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
|
||||
namespace import_budget {
|
||||
constexpr uint64_t kMB = 1ull << 20;
|
||||
constexpr uint64_t kBigBudget = 12ull << 30; // from here the valve was off by default
|
||||
constexpr uint64_t kCapMb = 4500; // RADV's cap at a big budget
|
||||
constexpr uint64_t kPassMost = 1ull << 30; // a capped pass gives back this much at most
|
||||
|
||||
struct Rule {
|
||||
bool on = false; // the heap's trigger runs
|
||||
uint64_t cap = 0; // bytes the heap is measured against at most (0: the whole budget)
|
||||
};
|
||||
|
||||
/// budget: the system heap's budget when the rule is first asked. high_set, low_set: the player set RX_VK_IMPORT_HIGH,
|
||||
/// RX_VK_IMPORT_LOW. cap_mb: RX_VK_IMPORT_CAP_MB (-1: unset). radv: the driver is Mesa's RADV
|
||||
constexpr Rule rule(uint64_t budget, bool high_set, bool low_set, int64_t cap_mb, bool radv) {
|
||||
const bool before = high_set || budget < kBigBudget; // (as it was: on where the budget is small, or asked for)
|
||||
if (cap_mb > 0) return Rule{true, (uint64_t)cap_mb * kMB};
|
||||
if (cap_mb == 0 || high_set || low_set || !radv || budget < kBigBudget) return Rule{before, 0};
|
||||
return Rule{true, kCapMb * kMB};
|
||||
}
|
||||
|
||||
/// What the heap's use is measured against now (the budget moves; the cap does not)
|
||||
constexpr uint64_t measured(const Rule& r, uint64_t budget) {
|
||||
return r.cap && r.cap < budget ? r.cap : budget;
|
||||
}
|
||||
|
||||
/// How much a pass by the heap's trigger wants back: down to the target, and 1 GB at most where the cap is what measures
|
||||
constexpr uint64_t pass_want(const Rule& r, uint64_t budget, uint64_t used, uint64_t target) {
|
||||
const uint64_t want = used > target ? used - target : 0;
|
||||
return r.cap && r.cap < budget && want > kPassMost ? kPassMost : want;
|
||||
}
|
||||
} // namespace import_budget
|
||||
50
gpu/vk/import_touch.h
Normal file
50
gpu/vk/import_touch.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/* (Triforce) The pages of a range read before the driver imports it (vk_memory.cpp import_pool, RX_VK_IMPORT_TOUCH).
|
||||
An import of the game's memory (VK_EXT_external_memory_host) is the driver locking the range's pages inside
|
||||
vkAllocateMemory, and while it does a vkQueueSubmit2 from another thread waits for it. The ranges imported ahead are
|
||||
whole, up to 1 GB, and much of one is pages nobody has touched since they were committed: the driver faults each in under
|
||||
its lock. In the lab's Market stands (RTX 5090, rounds 74 and 77) the allocate of the ranges of 288 to 752 MB took 16 to
|
||||
93 ms and the frame's queue submit stood beside it for as long: the 26 to 64 ms hitches of the owner's walks. With each
|
||||
page read first, on the importing thread and outside the driver, the same allocates took 4 to 13 ms, and the longest
|
||||
queue submit beside an import in play 10 to 12 ms for 71 to 93.
|
||||
Only on the background import thread (the imports another thread's submit stands beside: an import on a binding's own
|
||||
thread gains nothing and the read would add to it), only on Windows, and only where the range was committed whole. There
|
||||
the reads add no memory: the import holds every page of its range in RAM as it is. They are not free in time: a stand's
|
||||
imports of 64 MB or more took 581 and 614 ms with the read (392 and 420 ms reading, 168 and 172 allocating) against 405 ms
|
||||
without, on the background thread; 1,212 ms in the first run after a build.
|
||||
Plain functions: tests/test_import_touch.py checks them.
|
||||
RX_VK_IMPORT_TOUCH=0: off, as before. */
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace mkwvk::import_touch {
|
||||
|
||||
constexpr size_t kPage = 4096;
|
||||
constexpr size_t kRun = 4u << 20; // (bytes read in one guarded call: a run that faults is left to the driver, the next goes on)
|
||||
|
||||
constexpr uint64_t kLargeMb = 64; // (imports of this size or more: their own count of log lines, vk_memory.cpp import_pool's report)
|
||||
|
||||
/// RX_VK_IMPORT_TOUCH: on unless it is 0
|
||||
inline bool on(const char* env) { return !(env && env[0] == '0' && !env[1]); }
|
||||
|
||||
/// Whether an import's pages are read first: the switch, on the background import thread, the range committed whole
|
||||
inline bool may(bool on, bool background_thread, bool committed_whole) { return on && background_thread && committed_whole; }
|
||||
|
||||
/// The length of the run at off in a range of bytes: kRun, or what is left
|
||||
inline size_t run(uint64_t bytes, uint64_t off) { return off >= bytes ? 0 : (size_t)(bytes - off < kRun ? bytes - off : kRun); }
|
||||
|
||||
/// One byte of each page of [p, p + n) read, p on a page's start: the pages read. Not inlined: the caller's handler takes a
|
||||
/// fault only across a call (vk_memory.cpp guarded_copy has why)
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
__attribute__((noinline))
|
||||
#endif
|
||||
inline uint64_t read_pages(const volatile uint8_t* p, size_t n) {
|
||||
uint64_t pages = 0;
|
||||
unsigned sink = 0;
|
||||
for (size_t i = 0; i < n; i += kPage) sink += p[i], pages++;
|
||||
(void)sink;
|
||||
return pages;
|
||||
}
|
||||
|
||||
} // namespace mkwvk::import_touch
|
||||
30
gpu/vk/index_rebase.h
Normal file
30
gpu/vk/index_rebase.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// (Triforce, 11-21, the performance audit's DESC-12, after Source A's) An indexed draw's index buffer bound at offset 0,
|
||||
// with the draw's offset given as its first index.
|
||||
//
|
||||
// The game's draws share one buffer at different offsets, so bind_index's skip (the same buffer, offset and type as the
|
||||
// one on the command buffer) rarely held: nearly every indexed draw called vkCmdBindIndexBuffer, about 2,900 calls a frame
|
||||
// in the Market. Bound at 0 with the offset as the draw's firstIndex, the skip holds until the buffer or the index type
|
||||
// changes. Only where the offset is a whole number of indices that fits a first index; otherwise the draw binds at its
|
||||
// offset as before. Indirect indexed draws are not touched: their first index is in the GPU's records.
|
||||
// RX_VK_INDEX_REBASE=0: every draw binds at its own offset, as before.
|
||||
//
|
||||
// The rule alone, no Vulkan: tests/test_index_rebase.py compiles it.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace index_rebase {
|
||||
|
||||
/// The switch's value: on unless it is set to 0
|
||||
inline bool on(const char* asked) { return !(asked && *asked && atoi(asked) == 0); }
|
||||
|
||||
/// Whether a draw whose indices start offset bytes into its buffer, unit bytes an index, can be drawn from the buffer bound
|
||||
/// at 0: *first is then its first index. Not when the offset falls inside an index, nor past what a first index the draw's
|
||||
/// own range is added to can hold
|
||||
inline bool rebase(uint64_t offset, uint32_t unit, uint32_t* first) {
|
||||
if (!unit || offset % unit || offset / unit > 0x7fffffffull) return false;
|
||||
*first = (uint32_t)(offset / unit);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace index_rebase
|
||||
@@ -10,12 +10,21 @@
|
||||
A knob named d_<site> is a delay: a busy wait of <value> microseconds at that site, at most once a frame (delay(), below):
|
||||
what the frame's time answers to a part of it taking longer, which is whether that part is on the frame's critical path
|
||||
(1 ms in for 1 ms of delay) or has slack (nothing). Any other name is a switch the code reads with on("<name>").
|
||||
(Triforce, 11-22, the performance audit's REPLAY-51, after Source B's) A knob named e_<event> is a delay at every
|
||||
occurrence of an event, not once a frame: a busy wait of <value> NANOseconds at each draw (e_draw) or dispatch
|
||||
(e_dispatch), first in vk_draw.cpp's draw() and dispatch() so that the profiles leave it out, on whichever thread
|
||||
records, counted (each(), below). The frame's change against the time spun says how much of that path is on the frame's
|
||||
critical path: 200 ns at ~3,050 draws a frame is 0.6 ms of work. One line a phase gives each knob's spins and ms a second
|
||||
(each_report). d_present_after is d_present's after: the same wait just after the present's drain(0), where d_present is
|
||||
just before it. Pin RX_VK_PARALLEL for e_ knobs: Automatic moves draws between threads (the replay warns).
|
||||
Not for players: nothing reads these without the variable. */
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
@@ -32,6 +41,17 @@ inline std::atomic<uint64_t> frame_no{0}; // (presents counted here)
|
||||
inline std::atomic<uint64_t> fired[16]; // (the frame each delay last waited in)
|
||||
inline std::atomic<uint32_t> pres_thread{0}; // (the thread that presents: the game's Presentation thread, in the plain mode)
|
||||
inline int64_t phase_frames = 300, skip_frames = 30;
|
||||
// ((Triforce, 11-22, REPLAY-51) the e_ knobs: each event's wait in this phase (ns, 0: none), and what was spun)
|
||||
enum Each { E_DRAW = 0, E_DISPATCH = 1, E_COUNT = 2 };
|
||||
inline const char* const each_names[E_COUNT] = {"e_draw", "e_dispatch"};
|
||||
inline std::atomic<int64_t> each_ns[E_COUNT];
|
||||
inline std::atomic<uint64_t> each_spins[E_COUNT], each_spun_ns[E_COUNT];
|
||||
struct EachPhase { // (the presenting thread's: the phase being counted)
|
||||
int knob = 0;
|
||||
std::chrono::steady_clock::time_point since{};
|
||||
};
|
||||
inline EachPhase each_phase;
|
||||
inline char each_line[256]; // (the line of a phase just over, for the replay to log; empty: none)
|
||||
|
||||
inline void init() {
|
||||
if (n_knobs >= 0) return;
|
||||
@@ -53,6 +73,53 @@ inline void init() {
|
||||
if (const char* s = getenv("RX_VK_LAB_AB_SKIP")) skip_frames = atoll(s);
|
||||
n_knobs = n;
|
||||
}
|
||||
/// ((Triforce, 11-22, REPLAY-51) Whether any knob is an e_ one (the replay warns once unless RX_VK_PARALLEL is pinned)
|
||||
inline bool any_each() {
|
||||
for (int i = 0; i < n_knobs; i++)
|
||||
for (const char* name : each_names)
|
||||
if (!strcmp(knobs[i].name, name)) return true;
|
||||
return false;
|
||||
}
|
||||
/// (phase_tick, the presenting thread) The phase is knob k (0: none): at a change, the line of the phase that ended (each_line,
|
||||
/// when it had an e_ knob: its spins and ms a second), and the events' waits for this one
|
||||
inline void each_tick(int k) {
|
||||
if (k == each_phase.knob && each_phase.since.time_since_epoch().count()) return;
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
each_line[0] = 0;
|
||||
const int was = each_phase.knob;
|
||||
if (was > 0 && each_phase.since.time_since_epoch().count()) {
|
||||
const double s = std::chrono::duration<double>(now - each_phase.since).count();
|
||||
for (int e = 0; e < E_COUNT; e++) {
|
||||
if (strcmp(knobs[was - 1].name, each_names[e])) continue;
|
||||
const uint64_t spins = each_spins[e].exchange(0, std::memory_order_relaxed);
|
||||
const uint64_t ns = each_spun_ns[e].exchange(0, std::memory_order_relaxed);
|
||||
snprintf(each_line, sizeof each_line, "vk: lab A/B: phase %s:%lld over: %.0f waits a second, %.2f ms a second spun "
|
||||
"(%llu waits in %.1f s)", each_names[e], (long long)knobs[was - 1].value, s > 0 ? spins / s : 0.0,
|
||||
s > 0 ? ns / 1e6 / s : 0.0, (unsigned long long)spins, s);
|
||||
}
|
||||
}
|
||||
for (int e = 0; e < E_COUNT; e++)
|
||||
each_ns[e].store(k > 0 && !strcmp(knobs[k - 1].name, each_names[e]) ? std::max<int64_t>(0, knobs[k - 1].value) : 0,
|
||||
std::memory_order_relaxed);
|
||||
each_phase.knob = k, each_phase.since = now;
|
||||
}
|
||||
/// At every occurrence of an event (first in draw() and dispatch()): one relaxed load without its knob; with it, a busy wait
|
||||
/// of the knob's nanoseconds, counted
|
||||
inline void each(int event) {
|
||||
const int64_t ns = each_ns[event].load(std::memory_order_relaxed);
|
||||
if (!ns) return;
|
||||
const auto t0 = std::chrono::steady_clock::now(), until = t0 + std::chrono::nanoseconds(ns);
|
||||
auto now = t0;
|
||||
while (now < until) {
|
||||
#if defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)
|
||||
__builtin_ia32_pause();
|
||||
#endif
|
||||
now = std::chrono::steady_clock::now();
|
||||
}
|
||||
each_spins[event].fetch_add(1, std::memory_order_relaxed);
|
||||
each_spun_ns[event].fetch_add((uint64_t)std::chrono::duration_cast<std::chrono::nanoseconds>(now - t0).count(),
|
||||
std::memory_order_relaxed);
|
||||
}
|
||||
/// Once a present, on the presenting thread: the phase this frame belongs to (the trace's column)
|
||||
inline int phase_tick() {
|
||||
init();
|
||||
@@ -61,6 +128,7 @@ inline int phase_tick() {
|
||||
const uint64_t phase = f / (uint64_t)phase_frames; // (0 none, 1 knob 1, 2 none, 3 knob 2, ...)
|
||||
const int k = (phase & 1) ? (int)((phase / 2) % (uint64_t)n_knobs) + 1 : 0;
|
||||
active.store(k, std::memory_order_relaxed);
|
||||
each_tick(k); // ((Triforce, 11-22, REPLAY-51) the e_ knobs' waits for this phase, and the line of the one before)
|
||||
const bool settling = (int64_t)(f % (uint64_t)phase_frames) < skip_frames;
|
||||
return settling ? -(k + 1) : k; // (-1: none, settling; -(k + 1): knob k, settling)
|
||||
}
|
||||
|
||||
49
gpu/vk/late_inline.h
Normal file
49
gpu/vk/late_inline.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// (Triforce, 11-22, the performance audit's MEM-80, after Source B's) Which of take_capture's no-wait rules for late pages run.
|
||||
//
|
||||
// A late page is one the CPU wrote while a submission still on the GPU writes it back (vk_memory.cpp capture_make). By default
|
||||
// every late page is waited for (RX_VK_LATE_QUEUE: at the queue's next submit) and taken again. RX_VK_LATE_NEW=1 (the lab
|
||||
// knob latenew) turns four rules on that take the wait away from some of them: pages of pools with no mirror skipped, pages
|
||||
// with the bytes they were last synced with left as they are, pages written back in part synced in their other parts (the
|
||||
// partial rule, late_partial), pages written back whole put off. Each brought brightness steps back at the Castle Town save.
|
||||
//
|
||||
// RX_VK_LATE_INLINE=1 (the lab knob lateinline), OFF unless set: the partial rule ALONE, Source B's analogue (the CPU's
|
||||
// bytes go in, the GPU's ranges stay the GPU's, nothing waits); the other three stay off, and the pages they would take
|
||||
// (no mirror, texture storage, whole write-backs, unknown ranges) are waited for as before.
|
||||
//
|
||||
// And the partial rule asks which ranges are still on the GPU against the GPU's progress capture_make read before its
|
||||
// copies, not a second read at the take: a write-back that landed between the copy and the take is then still counted in
|
||||
// flight, so its range is not synced from the older copy (the bug Source B fixed with the same change). This is so under
|
||||
// RX_VK_LATE_NEW too.
|
||||
//
|
||||
// The rule alone: no Vulkan, no game. tests/test_late_inline.py.
|
||||
#pragma once
|
||||
#include <cstdlib>
|
||||
|
||||
namespace late_inline {
|
||||
|
||||
/// RX_VK_LATE_INLINE: a number other than 0 on, 0 off; unset: the lab knob lateinline (on only in its phases)
|
||||
inline bool on(const char* env, bool knob) {
|
||||
if (env) return std::atoi(env) != 0;
|
||||
return knob;
|
||||
}
|
||||
|
||||
struct Rules {
|
||||
bool any = false; // (any rule: the late pages looked at one by one; else every one waited for, as by default)
|
||||
bool skip = false; // (a page of a pool with no mirror: not waited for)
|
||||
bool same = false; // (a page with the bytes it was last synced with: left as it is)
|
||||
bool part = false; // (a page written back in part: its other parts synced, no wait)
|
||||
bool defer = false; // (a page written back whole: put off)
|
||||
};
|
||||
/// late_new: RX_VK_LATE_NEW or its knob; inline_on: on() above; same_on, part_on, defer_on: RX_VK_LATE_SAME, RX_VK_LATE_PART,
|
||||
/// RX_VK_LATE_DEFER as read today (on, on, off unless set)
|
||||
inline Rules rules(bool late_new, bool inline_on, bool same_on, bool part_on, bool defer_on) {
|
||||
Rules r;
|
||||
r.any = late_new || inline_on;
|
||||
r.skip = late_new;
|
||||
r.same = late_new && same_on;
|
||||
r.part = r.any && part_on;
|
||||
r.defer = late_new && defer_on;
|
||||
return r;
|
||||
}
|
||||
|
||||
} // namespace late_inline
|
||||
160
gpu/vk/lib_check.h
Normal file
160
gpu/vk/lib_check.h
Normal file
@@ -0,0 +1,160 @@
|
||||
// (Triforce, after NX2navi e10ef60's library warm check, runtime/vk_pipeline.c lw_probe and lw_main) Whether the stage libraries
|
||||
// the preparation made are still in the pipeline cache, at a start whose record says they were made (vk_draw.cpp lib_check_cold,
|
||||
// called by prepare_run). Apart from Vulkan so that tests/test_lib_check.py runs its rules alone.
|
||||
//
|
||||
// Why. triforce_prepared.bin's second stamp (vk_draw.cpp warmed_stamp) says the driver's part of the shaders was made for these
|
||||
// programs, this driver and kWarmRecipe, and a start with that stamp goes straight to the precompile. Nothing looked at whether
|
||||
// the libraries were still there. They are kept in our pipeline cache (gpl_libs_cached: asked for as a draw's link asks, the
|
||||
// driver answers from the cache it is handed and not from its own on disk), so they are cold again when mkw_vk_pipelines.bin is
|
||||
// lost or refused (deleted, another device's header, a short read), or when what a library is built with changed without
|
||||
// kWarmRecipe counted up. Cold, no new pipeline is linked: each waits for a whole build, or its draws are left out for the frames
|
||||
// that takes. NX2navi measured it on an RX 7900 XT (26.10.1) with all 42,142 of its prepared libraries cold, one entry each in the
|
||||
// driver's cache after a change of their dynamic states: 93 ms a vertex and 242 ms a fragment library, a walk through a village
|
||||
// skipped 11,180 draws and made 94 draws wait 5.5 s in all, four of them 1.0 to 2.0 s; with them warm again 0.3 and 0.7 ms.
|
||||
//
|
||||
// What. A sample of kSample kept program variants, spread over the program cache (from another place each start), each one's two
|
||||
// shader libraries made as the driver's part makes them, timed, and made once more at once. Where the device can (gpl_ask_only)
|
||||
// they are asked of the caches only, with the flag a draw's link asks with (FAIL_ON_PIPELINE_COMPILE_REQUIRED), and the answer
|
||||
// is the driver's own on every vendor: cold is "a compile is required", the very answer that leaves a draw without its link.
|
||||
// Without the flag (RX_VK_GPL_SYNC) the times say it, against a reference made on the spot: the second making comes from the
|
||||
// cache by construction, the warm time of this driver on this PC, so no fixed time is needed (a library from the cache is 0.3 to
|
||||
// 3 ms on one driver or another, one compiled 30 to 300 ms); cold is a first making over kRatio times the second and kSlackMs
|
||||
// more. The sample is cold when more than half of its variants are, its median; under half a sample (a program cache with fewer
|
||||
// variants) says nothing.
|
||||
//
|
||||
// Cold, the driver's part is made again at once, before the game, as after a driver update: every processor the preparation may
|
||||
// have (prepare_threads.h, which counts the RAM free), the start-up screen's "Compiling shaders", its journal and skip list
|
||||
// (gpl_rules.h), and the cache saved after it. Not on idle threads in play: Triforce's builder behind the game measured 55-64 fps
|
||||
// against 41-47 with it compiling (vk_draw.cpp, before predict_background), and that is what a cold list of tens of thousands of
|
||||
// libraries would do for most of a session. Warm (the start's usual case), nothing more happens than the sample: twelve program
|
||||
// reads and some fifty library lookups.
|
||||
//
|
||||
// It is not made again for ever: a making again holds the start for minutes. <prepared>.check records, for the stamp, that the
|
||||
// check made the part again, and how many starts in a row found the libraries cold again right after (strikes). Past kStrikes the
|
||||
// driver or the PC does not keep them (a cache that does not stay, a driver that answers cold for what it has), and the libraries
|
||||
// are left to the draws that need them, as before this check: with kStrikes 0 the part is made again once, and a start that finds
|
||||
// it cold again right after stops there. NX2navi tries three times, but it warms in play; here each try is a start held. A making
|
||||
// again whose cache could not be written (over the bound, or its save failed) or that warm_begin left out (gpl_rules.h kTries starts that died in it)
|
||||
// is recorded the same way. A start that finds them warm removes the file, and a later loss is made again. RX_VK_LIB_CHECK=0: no
|
||||
// check, as before.
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace lib_check {
|
||||
|
||||
inline constexpr int kSample = 12; // (variants sampled, NX2navi's LW_SAMPLE)
|
||||
inline constexpr int kLook = 2 * kSample; // (programs looked at for them: one may have no variant with libraries)
|
||||
inline constexpr double kRatio = 4.0; // (first making against the second: cold above)
|
||||
inline constexpr double kSlackMs = 3.0; // (and this much more: lookups of a few milliseconds say nothing)
|
||||
inline constexpr int kStrikes = 0; // (made again once, and cold again right after: left to the draws)
|
||||
|
||||
/// RX_VK_LIB_CHECK: on unless "0"
|
||||
inline bool on(const char* env) { return !env || strcmp(env, "0") != 0; }
|
||||
|
||||
/// One variant sampled: its two libraries' first making and the second (ms, both libraries together). asked: made asking the
|
||||
/// caches only; answered_cold: they said a compile is required; made: both were made both times (a library the driver refuses
|
||||
/// says nothing of the cache). Asked, the answer alone counts: a driver that made the library without a compile has it, however
|
||||
/// long its first lookup took. Not asked, the times say it
|
||||
struct Probe {
|
||||
bool asked = false, answered_cold = false, made = false;
|
||||
double first_ms = 0, again_ms = 0;
|
||||
};
|
||||
inline bool counts(const Probe& p) { return p.answered_cold || p.made; }
|
||||
inline bool cold(const Probe& p) {
|
||||
return p.answered_cold || (!p.asked && p.made && p.first_ms > kRatio * p.again_ms + kSlackMs);
|
||||
}
|
||||
|
||||
/// What a sample comes to: the variants that count, the cold ones, and the median times (for the log)
|
||||
struct Tally {
|
||||
int got = 0, cold = 0, answered = 0;
|
||||
double first_median = 0, again_median = 0;
|
||||
};
|
||||
inline double median(std::vector<double> v) {
|
||||
if (v.empty()) return 0;
|
||||
std::sort(v.begin(), v.end());
|
||||
return v[v.size() / 2];
|
||||
}
|
||||
inline Tally tally(const std::vector<Probe>& probes) {
|
||||
Tally t;
|
||||
std::vector<double> first, again;
|
||||
for (const Probe& p : probes) {
|
||||
if (!counts(p)) continue;
|
||||
t.got++, t.cold += cold(p), t.answered += p.answered_cold;
|
||||
first.push_back(p.first_ms);
|
||||
if (p.made) again.push_back(p.again_ms);
|
||||
}
|
||||
t.first_median = median(first), t.again_median = median(again);
|
||||
return t;
|
||||
}
|
||||
|
||||
enum class Verdict { Unknown, Warm, Cold };
|
||||
inline Verdict verdict(const Tally& t) {
|
||||
if (t.got * 2 < kSample) return Verdict::Unknown;
|
||||
return t.cold * 2 > t.got ? Verdict::Cold : Verdict::Warm;
|
||||
}
|
||||
|
||||
/// k places spread over n, the first at seed's place in the first step: each start samples other programs
|
||||
inline std::vector<size_t> spots(size_t n, size_t k, uint64_t seed) {
|
||||
std::vector<size_t> at;
|
||||
if (!n || !k) return at;
|
||||
const size_t step = std::max<size_t>(1, n / k);
|
||||
for (size_t i = (size_t)(seed % step); i < n && at.size() < k; i += step) at.push_back(i);
|
||||
return at;
|
||||
}
|
||||
|
||||
// ---- <prepared>.check: "lib-check <stamp> <strikes>"
|
||||
|
||||
struct State {
|
||||
bool found = false;
|
||||
uint64_t stamp = 0;
|
||||
int strikes = 0;
|
||||
};
|
||||
inline State state_read(const std::string& path) {
|
||||
State s;
|
||||
FILE* f = fopen(path.c_str(), "rb");
|
||||
if (!f) return s;
|
||||
char line[96]{};
|
||||
const size_t n = fread(line, 1, sizeof line - 1, f);
|
||||
fclose(f);
|
||||
line[n] = 0;
|
||||
unsigned long long stamp = 0;
|
||||
int strikes = 0;
|
||||
if (sscanf(line, "lib-check %16llx %d", &stamp, &strikes) == 2 && strikes >= 0)
|
||||
s.found = true, s.stamp = stamp, s.strikes = strikes;
|
||||
return s;
|
||||
}
|
||||
/// Written whole beside the old one, then put in place (a start that ends in the middle leaves the old file)
|
||||
inline bool state_write(const std::string& path, uint64_t stamp, int strikes) {
|
||||
char line[96];
|
||||
const int n = snprintf(line, sizeof line, "lib-check %016llx %d\n", (unsigned long long)stamp, strikes);
|
||||
const std::string tmp = path + ".tmp";
|
||||
FILE* f = fopen(tmp.c_str(), "wb");
|
||||
if (!f) return false;
|
||||
bool ok = fwrite(line, 1, (size_t)n, f) == (size_t)n;
|
||||
ok = fclose(f) == 0 && ok;
|
||||
if (ok) {
|
||||
remove(path.c_str()); // (rename does not replace on Windows)
|
||||
ok = rename(tmp.c_str(), path.c_str()) == 0;
|
||||
}
|
||||
if (!ok) remove(tmp.c_str());
|
||||
return ok;
|
||||
}
|
||||
|
||||
enum class Do { Nothing, Again, Stop };
|
||||
/// What a start does with a sample's verdict, the record had of the last starts and the stamp now. *next: the strikes to record
|
||||
/// once the part is made again (Again only)
|
||||
inline Do decide(Verdict v, const State& had, uint64_t stamp, int* next) {
|
||||
if (v != Verdict::Cold) return Do::Nothing;
|
||||
const bool same = had.found && had.stamp == stamp; // (made again for this stamp, and cold again since)
|
||||
if (same && had.strikes >= kStrikes) return Do::Stop;
|
||||
*next = same ? had.strikes + 1 : 0;
|
||||
return Do::Again;
|
||||
}
|
||||
|
||||
} // namespace lib_check
|
||||
153
gpu/vk/linux_pressure.h
Normal file
153
gpu/vk/linux_pressure.h
Normal file
@@ -0,0 +1,153 @@
|
||||
// (Triforce, 11-22, the performance audit's MEM-141, after Source A's) A memory pressure hold for Linux and the Steam Deck that
|
||||
// counts the swap too (vk_memory.cpp steps it from memory_ram_watch, off Windows; this is the rule, plain code:
|
||||
// tests/test_linux_pressure.py runs it anywhere).
|
||||
//
|
||||
// The RAM rules looked at MemAvailable alone. A Linux PC with swap keeps MemAvailable up by pushing the game's pages out:
|
||||
// on a 16 GB Steam Deck Source A saw the swap fill (4,036 MB at the peak, 0 MB free at the lowest) while MemAvailable said
|
||||
// little, and the stalls were the pages coming back. So the swap left counts: the PC is short when MemAvailable is under
|
||||
// 1536 MB (the imports' own line), or when MemAvailable and SwapFree together are under the reserve (RX_VK_SWAP_RESERVE_MB).
|
||||
// While it is short a hold is on and the renderer gives memory back sooner:
|
||||
// - a capture buffer is kept as a spare only up to 32 MB of spares (not 768);
|
||||
// - the staging arenas the GPU is done with are freed when the hold begins, then after 5 s unused (not 30);
|
||||
// - malloc_trim is asked every 600 presents from 64 MB free (not every 1800 from 192);
|
||||
// - idle imports are given back, in all of one episode at most as many bytes as the PC was short at its worst (not up to
|
||||
// 1 GB a pass: the thrash of imports given back and made again was seen here before), and still only after 3,600 idle
|
||||
// submissions;
|
||||
// - on an integrated GPU, whose "VRAM" is the same RAM, the texture budget is less by what the PC is short (never under
|
||||
// 512 MB), and comes back 256 MB a sample.
|
||||
// The hold ends once MemAvailable and the sum are both 256 MB clear of their lines. A PC without swap, or one whose swap
|
||||
// cannot be read, is never short by the sum: not known is not short. The program modules are let go by the program pack
|
||||
// already (vk_shader.cpp), so the hold has no valve for them.
|
||||
//
|
||||
// RX_VK_SWAP_RESERVE_MB=<MB>: the reserve; 0 or not set: no hold at all, as before. Source A's is 2560; it is off here until
|
||||
// a Steam Deck run has shown it. RX_VK_TEST_SWAP_MB=<n> plays that much swap free, as RX_VK_TEST_AVAIL_MB plays MemAvailable.
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace linux_pressure {
|
||||
|
||||
constexpr uint64_t kMB = 1ull << 20;
|
||||
constexpr uint64_t kAvailLine = 1536 * kMB; // (short under this much MemAvailable, whatever the swap)
|
||||
constexpr uint64_t kClear = 256 * kMB; // (the hold ends once both are this far clear of their lines)
|
||||
constexpr uint64_t kSourceReserve = 2560 * kMB; // (Source A's reserve: MemAvailable + SwapFree)
|
||||
constexpr uint64_t kSampleEvery = 30; // (presents between two looks)
|
||||
constexpr uint64_t kSpareCap = 32 * kMB; // (capture spares while held)
|
||||
constexpr int64_t kArenaIdleS = 5; // (a staging arena unused this long goes, while held)
|
||||
constexpr uint64_t kTrimEvery = 600; // (presents between two malloc_trim looks, while held)
|
||||
constexpr uint64_t kTrimMB = 64; // (free MB in the arenas from which malloc_trim is asked, while held)
|
||||
constexpr uint64_t kBudgetFloor = 512 * kMB; // (an integrated GPU's textures are never cut under this)
|
||||
constexpr uint64_t kBudgetBack = 256 * kMB; // (the cut comes back this much a sample)
|
||||
|
||||
/// RX_VK_SWAP_RESERVE_MB's text as bytes; 0 (not set, empty, 0, not a number): no hold
|
||||
inline uint64_t reserve_of(const char* e) {
|
||||
const long long mb = e && *e ? atoll(e) : 0;
|
||||
return mb > 0 ? (uint64_t)mb * kMB : 0;
|
||||
}
|
||||
|
||||
/// What /proc/meminfo said. A field that is not there is not known (has_*), never 0
|
||||
struct Meminfo {
|
||||
uint64_t total = 0, avail = 0, swap_total = 0, swap_free = 0;
|
||||
bool has_total = false, has_avail = false, has_swap_total = false, has_swap_free = false;
|
||||
};
|
||||
|
||||
/// /proc/meminfo's text ("Name: <n> kB" a line)
|
||||
inline Meminfo parse(const char* text) {
|
||||
Meminfo m;
|
||||
auto field = [text](const char* name, uint64_t* out) {
|
||||
const size_t len = strlen(name);
|
||||
for (const char* p = text; p && *p; p = strchr(p, '\n'), p = p ? p + 1 : p) {
|
||||
if (strncmp(p, name, len) || p[len] != ':') continue;
|
||||
const char* v = p + len + 1;
|
||||
while (*v == ' ' || *v == '\t') v++;
|
||||
if (*v < '0' || *v > '9') return false;
|
||||
*out = strtoull(v, nullptr, 10) << 10; // (kB)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
m.has_total = field("MemTotal", &m.total);
|
||||
m.has_avail = field("MemAvailable", &m.avail);
|
||||
m.has_swap_total = field("SwapTotal", &m.swap_total);
|
||||
m.has_swap_free = field("SwapFree", &m.swap_free);
|
||||
return m;
|
||||
}
|
||||
|
||||
/// One look at the PC's memory. swap_known: there is swap and what is free of it was read
|
||||
struct Sample {
|
||||
bool avail_known = false, swap_known = false;
|
||||
uint64_t avail = 0, swap_free = 0;
|
||||
};
|
||||
|
||||
/// The sample of a meminfo, with the lab's played values over it (negative: not played). Swapless (SwapTotal 0), or SwapFree
|
||||
/// or SwapTotal unreadable: the swap is not known. A played swap counts as known
|
||||
inline Sample sample_of(const Meminfo& m, long long test_avail_mb = -1, long long test_swap_mb = -1) {
|
||||
Sample s;
|
||||
s.avail_known = m.has_avail, s.avail = m.avail;
|
||||
s.swap_known = m.has_swap_total && m.has_swap_free && m.swap_total > 0, s.swap_free = s.swap_known ? m.swap_free : 0;
|
||||
if (test_avail_mb >= 0) s.avail_known = true, s.avail = (uint64_t)test_avail_mb * kMB;
|
||||
if (test_swap_mb >= 0) s.swap_known = true, s.swap_free = (uint64_t)test_swap_mb * kMB;
|
||||
return s;
|
||||
}
|
||||
|
||||
/// How many bytes the PC is short: the larger of what MemAvailable lacks to its line and what the sum lacks to the reserve.
|
||||
/// 0: not short, or not known
|
||||
inline uint64_t shortfall(const Sample& s, uint64_t reserve) {
|
||||
if (!reserve || !s.avail_known) return 0;
|
||||
const uint64_t by_avail = s.avail < kAvailLine ? kAvailLine - s.avail : 0;
|
||||
const uint64_t sum = s.avail + s.swap_free;
|
||||
const uint64_t by_sum = s.swap_known && sum < reserve ? reserve - sum : 0;
|
||||
return std::max(by_avail, by_sum);
|
||||
}
|
||||
|
||||
/// Both lines cleared by kClear (the hold may end). Not known: clear
|
||||
inline bool clear(const Sample& s, uint64_t reserve) {
|
||||
if (!reserve || !s.avail_known) return true;
|
||||
if (s.avail < kAvailLine + kClear) return false;
|
||||
return !s.swap_known || s.avail + s.swap_free >= reserve + kClear;
|
||||
}
|
||||
|
||||
/// The hold: on from a short sample until a clear one. One episode is one stretch of it
|
||||
struct Hold {
|
||||
bool held = false;
|
||||
uint64_t deepest = 0; // (the episode's largest shortfall)
|
||||
uint64_t given = 0; // (the bytes of imports given back in this episode)
|
||||
uint64_t now = 0; // (the last sample's shortfall)
|
||||
uint64_t cut = 0; // (an integrated GPU's texture budget is less by this)
|
||||
uint64_t episodes = 0;
|
||||
|
||||
enum Step { Same, Entered, Left };
|
||||
/// One sample. reserve 0: never held
|
||||
Step step(const Sample& s, uint64_t reserve) {
|
||||
const uint64_t lacking = shortfall(s, reserve);
|
||||
Step r = Same;
|
||||
if (!held && lacking) held = true, deepest = 0, given = 0, episodes++, r = Entered;
|
||||
else if (held && clear(s, reserve)) held = false, r = Left;
|
||||
now = held ? lacking : 0;
|
||||
if (held) deepest = std::max(deepest, lacking);
|
||||
// (the budget's cut: down at once to what is lacking, back up kBudgetBack a sample)
|
||||
cut = now > cut ? now : std::max(now, cut > kBudgetBack ? cut - kBudgetBack : 0);
|
||||
return r;
|
||||
}
|
||||
/// The bytes of idle imports this episode may still give back: its largest shortfall, less what it gave
|
||||
uint64_t episode_want() const { return held && deepest > given ? deepest - given : 0; }
|
||||
void gave(uint64_t bytes) { given += bytes; }
|
||||
};
|
||||
|
||||
/// The valves' sizes, held or not
|
||||
inline uint64_t spare_cap(bool held, uint64_t usual) { return held ? std::min(usual, kSpareCap) : usual; }
|
||||
/// (idle_s 0: the player keeps the arenas: kept while held too)
|
||||
inline int64_t arena_idle_s(bool held, int64_t usual) { return held && usual > kArenaIdleS ? kArenaIdleS : usual; }
|
||||
inline uint64_t trim_every(bool held, uint64_t usual) { return held ? std::min(usual, kTrimEvery) : usual; }
|
||||
/// (trim_mb 0: never, held or not)
|
||||
inline uint64_t trim_mb(bool held, uint64_t usual) { return held && usual ? std::min(usual, kTrimMB) : usual; }
|
||||
/// An integrated GPU's texture budget less the cut: never under the floor, never more than it was
|
||||
inline uint64_t cut_budget(uint64_t budget, uint64_t cut) {
|
||||
if (!cut || budget <= kBudgetFloor) return budget;
|
||||
return std::max(kBudgetFloor, budget > cut ? budget - cut : 0);
|
||||
}
|
||||
|
||||
} // namespace linux_pressure
|
||||
213
gpu/vk/lock_census.h
Normal file
213
gpu/vk/lock_census.h
Normal file
@@ -0,0 +1,213 @@
|
||||
// (Triforce, 11-22, the performance audit's THREAD-68, after Source B's) The lock census: who holds the lock a thread waits for.
|
||||
//
|
||||
// The log has totals of the waits for the renderer's locks (the memory sync's lock wait, the virtual cores' line, the order lock's
|
||||
// slow takes), none of which names the holder. With RX_VK_LOCK_CENSUS=1 a lock that is busy when a thread comes for it notes the
|
||||
// waiter, the thread that held it, and how long the wait was; every 10 s a thread of the census's own logs the 12 pairs that
|
||||
// waited longest:
|
||||
// vk: lock census: Presentation Thread <- MainThread (replay_mu) 17.2 ms/s (2900/s, 6 us each)
|
||||
// Counted: replay_mu (DrainingMutex), sync_order_mu (OrderMutex), held_mu, and in vk_memory.cpp pools_mu, sync_mu and cap_mu.
|
||||
// Only the counting is ported: Source B's also samples the holders' stacks, which disturbs a millisecond or two a second.
|
||||
//
|
||||
// Off (unset, or 0): every lock is taken exactly as before, behind one branch on a value read once. On: a free lock is one
|
||||
// try_lock and a store of its holder; only a busy lock reads the clock, twice. The holder is read without the lock, so a holder
|
||||
// that lets go at that moment can be misnamed, never more. The census's own mutex is taken last, with the counted lock held, and
|
||||
// nothing that holds it ever takes a counted lock. With RX_VK_LAB_AB naming a knob lockcensus it counts only in that knob's phases.
|
||||
//
|
||||
// No windows.h here (vk_recorder.h, which includes this, has none): a thread's name is read through g_thread_name, which
|
||||
// vk_replay.cpp sets. tests/test_lock_census.py cuts DrainingMutex and OrderMutex out and compiles them with this.
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
namespace mkwvk {
|
||||
void logf(const char* fmt, ...); // (vk_main.cpp)
|
||||
|
||||
namespace lock_census {
|
||||
|
||||
/// RX_VK_LOCK_CENSUS, read once: 1 (any number but 0) counts
|
||||
inline bool enabled() {
|
||||
static const bool v = [] {
|
||||
const char* e = getenv("RX_VK_LOCK_CENSUS");
|
||||
return e && atoi(e) != 0;
|
||||
}();
|
||||
return v;
|
||||
}
|
||||
inline std::atomic<bool> phase_on{true}; // (lab: false outside the knob's phases)
|
||||
inline bool counting() { return enabled() && phase_on.load(std::memory_order_relaxed); }
|
||||
|
||||
/// The clock a busy lock reads (a test counts the reads through it)
|
||||
inline int64_t steady_ns() {
|
||||
return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
|
||||
}
|
||||
inline int64_t (*now_ns)() = steady_ns;
|
||||
inline std::atomic<int> period_ms{10000}; // (between two reports)
|
||||
constexpr int kTop = 12;
|
||||
|
||||
struct Pair {
|
||||
int64_t ns = 0, n = 0;
|
||||
};
|
||||
/// The census's own state. Names are kept as pointers to strings that are never freed, one per distinct name
|
||||
struct Book {
|
||||
std::mutex mu;
|
||||
std::map<std::string, const char*> names;
|
||||
std::map<std::tuple<const char*, const char*, const char*>, Pair> pairs; // (waiter, holder, lock)
|
||||
bool reporter = false;
|
||||
int64_t since_ns = 0;
|
||||
};
|
||||
inline Book& book() {
|
||||
static Book* b = new Book; // (never destroyed: a thread may count while the process ends)
|
||||
return *b;
|
||||
}
|
||||
/// the one pointer for a name (book().mu held)
|
||||
inline const char* intern(Book& b, const char* name) {
|
||||
auto it = b.names.find(name);
|
||||
if (it == b.names.end()) {
|
||||
char* kept = new char[strlen(name) + 1];
|
||||
strcpy(kept, name);
|
||||
it = b.names.emplace(name, kept).first;
|
||||
}
|
||||
return it->second;
|
||||
}
|
||||
|
||||
/// A thread as the census names it: its description (the game's threads and the renderer's own are named), else its number. The
|
||||
/// slot is never freed, so a lock's note of its holder can be read after that thread has ended
|
||||
struct Slot {
|
||||
std::atomic<const char*> name{"?"};
|
||||
int64_t named_ns = 0; // (its own thread's: when the name was last read)
|
||||
};
|
||||
/// (set by vk_replay.cpp, which has windows.h: the calling thread's description into out, left empty when it has none; and what
|
||||
/// the reporting thread does first, which names it)
|
||||
inline void (*g_thread_name)(char* out, size_t cap) = nullptr;
|
||||
inline void (*g_report_start)() = nullptr;
|
||||
inline void name_slot(Slot* s) {
|
||||
char text[96] = "";
|
||||
if (g_thread_name) g_thread_name(text, sizeof text);
|
||||
if (!text[0]) snprintf(text, sizeof text, "thread %zu", std::hash<std::thread::id>()(std::this_thread::get_id()) % 100000);
|
||||
Book& b = book();
|
||||
std::lock_guard lk(b.mu);
|
||||
s->name.store(intern(b, text), std::memory_order_relaxed);
|
||||
}
|
||||
/// the calling thread's slot; named at its first use, and again by `again_at` (a waiter's clock read: a thread named after its
|
||||
/// first lock is not "thread 1234" for the whole session) when a second has passed
|
||||
inline const Slot* me(int64_t again_at = 0) {
|
||||
thread_local Slot* mine = nullptr;
|
||||
if (!mine) {
|
||||
mine = new Slot;
|
||||
mine->named_ns = again_at; // (0 on a free lock, which reads no clock: named again at this thread's first wait)
|
||||
name_slot(mine);
|
||||
} else if (again_at && again_at - mine->named_ns > 1000000000) {
|
||||
mine->named_ns = again_at;
|
||||
name_slot(mine);
|
||||
}
|
||||
return mine;
|
||||
}
|
||||
|
||||
/// The pairs counted since the last call, the longest waited first, kTop at most, as the log's lines; all counts start again
|
||||
inline std::vector<std::string> report(int64_t now) {
|
||||
Book& b = book();
|
||||
std::vector<std::pair<std::tuple<const char*, const char*, const char*>, Pair>> rows;
|
||||
double seconds = 0;
|
||||
{
|
||||
std::lock_guard lk(b.mu);
|
||||
rows.assign(b.pairs.begin(), b.pairs.end());
|
||||
b.pairs.clear();
|
||||
seconds = (double)(now - b.since_ns) / 1e9;
|
||||
b.since_ns = now;
|
||||
}
|
||||
if (seconds <= 0) seconds = 1e-9;
|
||||
std::sort(rows.begin(), rows.end(), [](const auto& x, const auto& y) { return x.second.ns > y.second.ns; });
|
||||
std::vector<std::string> out;
|
||||
for (size_t i = 0; i < rows.size() && i < (size_t)kTop; i++) {
|
||||
const auto& [key, p] = rows[i];
|
||||
char line[320];
|
||||
snprintf(line, sizeof line, "vk: lock census: %s <- %s (%s) %.1f ms/s (%.0f/s, %.0f us each)", std::get<0>(key), std::get<1>(key),
|
||||
std::get<2>(key), (double)p.ns / 1e6 / seconds, (double)p.n / seconds, p.n ? (double)p.ns / 1e3 / (double)p.n : 0.0);
|
||||
out.emplace_back(line);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
inline void report_main() {
|
||||
if (g_report_start) g_report_start();
|
||||
for (;;) {
|
||||
// (slept in steps, the period read at each: a test shortens it while this thread sleeps)
|
||||
for (int slept = 0; slept < period_ms.load(std::memory_order_relaxed); slept += 50)
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
for (const std::string& line : report(now_ns())) logf("%s", line.c_str());
|
||||
}
|
||||
}
|
||||
/// A wait is over: self waited ns for the lock `lock`, which `holder` held when it came (null: not known). The first one starts
|
||||
/// the reporting thread
|
||||
inline void waited(const Slot* self, const Slot* holder, const char* lock, int64_t ns, int64_t now) {
|
||||
Book& b = book();
|
||||
bool start = false;
|
||||
{
|
||||
std::lock_guard lk(b.mu);
|
||||
if (!b.since_ns) b.since_ns = now - ns;
|
||||
Pair& p = b.pairs[{self->name.load(std::memory_order_relaxed), holder ? holder->name.load(std::memory_order_relaxed) : intern(b, "?"),
|
||||
intern(b, lock)}];
|
||||
p.ns += ns, p.n++;
|
||||
if (!b.reporter) b.reporter = start = true;
|
||||
}
|
||||
if (start) std::thread(report_main).detach();
|
||||
}
|
||||
|
||||
/// m.lock() for a counted lock. owner: where that lock keeps its holder (set here, cleared by unlocking())
|
||||
template <class M>
|
||||
inline void lock(M& m, std::atomic<const Slot*>& owner, const char* name) {
|
||||
if (!counting()) { // (off: the lock as it was)
|
||||
m.lock();
|
||||
return;
|
||||
}
|
||||
if (m.try_lock()) { // (free: no clock read)
|
||||
owner.store(me(), std::memory_order_relaxed);
|
||||
return;
|
||||
}
|
||||
const Slot* holder = owner.load(std::memory_order_relaxed);
|
||||
const int64_t t0 = now_ns();
|
||||
m.lock();
|
||||
const int64_t t1 = now_ns();
|
||||
const Slot* self = me(t1);
|
||||
owner.store(self, std::memory_order_relaxed);
|
||||
waited(self, holder, name, t1 - t0, t1);
|
||||
}
|
||||
/// m.try_lock() for a counted lock
|
||||
template <class M>
|
||||
inline bool try_lock(M& m, std::atomic<const Slot*>& owner) {
|
||||
if (!m.try_lock()) return false;
|
||||
if (counting()) owner.store(me(), std::memory_order_relaxed);
|
||||
return true;
|
||||
}
|
||||
/// just before a counted lock's unlock: it has no holder
|
||||
inline void unlocking(std::atomic<const Slot*>& owner) {
|
||||
if (owner.load(std::memory_order_relaxed)) owner.store(nullptr, std::memory_order_relaxed);
|
||||
}
|
||||
|
||||
/// A std::mutex the census counts, for std::lock_guard and std::unique_lock
|
||||
struct CensusMutex {
|
||||
const char* name;
|
||||
std::mutex m;
|
||||
std::atomic<const Slot*> owner{nullptr};
|
||||
explicit CensusMutex(const char* n) : name(n) {}
|
||||
void lock() { lock_census::lock(m, owner, name); }
|
||||
bool try_lock() { return lock_census::try_lock(m, owner); }
|
||||
void unlock() {
|
||||
unlocking(owner);
|
||||
m.unlock();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace lock_census
|
||||
} // namespace mkwvk
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -199,5 +200,41 @@ constexpr uint64_t kKeepAllBytes = 22ull << 30;
|
||||
inline bool keep_all_pipelines(uint64_t total, uint64_t avail, uint64_t own) {
|
||||
return total >= (20ull << 30) && avail + own >= kKeepAllBytes;
|
||||
}
|
||||
/// (11-18) What the process holds that counts as the game's for keep_all_pipelines: its working set (ws) less what reading the
|
||||
/// pipeline cache added (cache_read; the driver holds that all session, so it is no room for the pipelines). Two 32 GB PCs on
|
||||
/// v0.5.1 with 2.7 and 3.0 GB cache files (4.7 and 4.9 GB of working set once read): 18.2 GB available + 7.0 held and 19.1 +
|
||||
/// 7.7, both over 22 GB, everything kept, and RAM short all session (39 times on one; the other lost the GPU after the save
|
||||
/// loaded). Without the cache: 20.5 and 21.9 GB, kept by none. Not on AMD's driver (amd: the vendor 0x1002), which the rule
|
||||
/// keeps as it was: there a pipeline left to its first draw cost ~100 ms (an RX 6650 XT: 152 of them in one 15.7 s frame),
|
||||
/// worse than the RAM
|
||||
inline uint64_t own_for_keep(uint64_t ws, uint64_t cache_read, bool amd) {
|
||||
if (amd) return ws;
|
||||
return ws > cache_read ? ws - cache_read : 0;
|
||||
}
|
||||
/// (11-22, after Casual Gamer's fix) Whether the game is told its mapped pages are used (host/hos_mem.c query_used), from the
|
||||
/// host's switches as it reads them: HOS_MEM_QUERY_USED not "0", and the census on (hos_mem_census_on: HOS_MEM_CENSUS not 0 or
|
||||
/// less, or HOS_MEM_GIVE_BACK above 0)
|
||||
inline bool query_used_on(const char* query_used, const char* census, const char* give_back) {
|
||||
const bool census_on = !(census && atoi(census) <= 0) || (give_back && atoi(give_back) > 0);
|
||||
return !(query_used && query_used[0] == '0' && !query_used[1]) && census_on;
|
||||
}
|
||||
/// (11-22) Whether the precompile keeps every pipeline for a PC of under 20 GB (vk_draw.cpp precompile_keeps_all): on a discrete
|
||||
/// GPU with the game told its mapped pages are used (query_on), which lets old areas go; total 0: not known
|
||||
inline bool keep_all_small_pc(bool discrete, uint64_t total, bool query_on) {
|
||||
return discrete && query_on && total && total < (20ull << 30);
|
||||
}
|
||||
|
||||
/// (11-22, after Casual Gamer's fix) Whether the retired imports kept for good (vk_memory.cpp retired_imports_give_back: Windows,
|
||||
/// AMD's and Intel's drivers) are given back all the same: the system heap past high percent of its budget (used of budget;
|
||||
/// a budget of 0: not known), or an import refused for want of room within the last kRefusedHoldMs (refused_ms: when, as now_ms
|
||||
/// counts; 0: never)
|
||||
constexpr int64_t kRefusedHoldMs = 60000;
|
||||
inline bool retired_pressed(uint64_t used, uint64_t budget, int high, int64_t now_ms, int64_t refused_ms) {
|
||||
return (budget && high > 0 && used > budget / 100 * (uint64_t)high) || (refused_ms && now_ms - refused_ms < kRefusedHoldMs);
|
||||
}
|
||||
/// (11-22, after Casual Gamer's fix) Whether the capture's spare buffers are held to 32 MB (vk_memory.cpp cap_spare_max): on a
|
||||
/// card the driver allows 6.5 GB or less (small_card), or on a PC of under 20 GB of RAM (ram_total; 0: not known)
|
||||
constexpr uint64_t kSpareRamBytes = 20ull << 30;
|
||||
inline bool spare_capped(bool small_card, uint64_t ram_total) { return small_card || (ram_total && ram_total < kSpareRamBytes); }
|
||||
|
||||
} // namespace mem_parts
|
||||
|
||||
73
gpu/vk/memory_priority.h
Normal file
73
gpu/vk/memory_priority.h
Normal file
@@ -0,0 +1,73 @@
|
||||
// VK_EXT_memory_priority: which device memory the system should keep in video memory when the card is short (no game, no
|
||||
// GPU: the switch's reading and the tiers). tests/test_memory_priority.py
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's TEX-47, after Source A's.) When a card is short of video memory, Windows moves
|
||||
// some of a program's device memory to system memory, which the GPU then reads over the bus, and it picks what goes. With
|
||||
// this extension a program ranks its memory from 0 to 1: the lower goes first. Source A gives the render targets 1.0,
|
||||
// the sampled textures 0.25 and the rest 0.5, and measured it on an RTX 4090 with the video memory taken by other
|
||||
// programs and the textures held to an 8 GB card's blocks: with 1.3 GB moved out, the GPU's median frame was 109 to
|
||||
// 179 ms unset and 24 to 29 ms on. The textures' low rank is the lever: with them at 0.5 (`1,0.5`) it ended at 68 ms.
|
||||
//
|
||||
// Off unless RX_VK_MEMORY_PRIORITY is set: no small card has run it, drivers may ignore it, and in Source A's runs the
|
||||
// wrong tiers were worse than none. Unset, the extension is not asked for and nothing here is used.
|
||||
// RX_VK_MEMORY_PRIORITY unset, empty, 0, off, no: off
|
||||
// 1: render targets 1.0, textures 0.25, the rest 0.5
|
||||
// <targets>,<textures>: those two, each from 0 to 1; the rest 0.5
|
||||
// anything else (one number that is not 0 or 1, three numbers, a number outside 0 to 1): off
|
||||
// With the extension on, the allocator (VMA) gives every pool and every allocation of its own the priority its create
|
||||
// info names, and one that names none gets 0, below the textures: so every one in vk_vma.cpp names its tier.
|
||||
#pragma once
|
||||
#include <cctype>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace memory_priority {
|
||||
|
||||
inline constexpr float kDefault = 0.5f; // (what a driver gives memory that names no priority)
|
||||
|
||||
struct Tiers {
|
||||
bool on = false;
|
||||
float targets = kDefault, textures = kDefault, other = kDefault;
|
||||
};
|
||||
|
||||
/// RX_VK_MEMORY_PRIORITY as written (see the top of the file); what cannot be read is off
|
||||
inline Tiers parse(const char* env) {
|
||||
Tiers t;
|
||||
if (!env) return t;
|
||||
while (*env == ' ' || *env == '\t') env++;
|
||||
char word[32] = {};
|
||||
size_t n = std::strlen(env);
|
||||
while (n && (env[n - 1] == ' ' || env[n - 1] == '\t')) n--;
|
||||
if (!n || n >= sizeof word) return t;
|
||||
for (size_t i = 0; i < n; i++) word[i] = (char)std::tolower((unsigned char)env[i]);
|
||||
if (!std::strcmp(word, "0") || !std::strcmp(word, "off") || !std::strcmp(word, "no")) return t;
|
||||
if (!std::strcmp(word, "1")) {
|
||||
t.on = true, t.targets = 1.0f, t.textures = 0.25f;
|
||||
return t;
|
||||
}
|
||||
// (two numbers and a comma between them, nothing else)
|
||||
char* end = nullptr;
|
||||
const double a = std::strtod(word, &end);
|
||||
if (end == word || *end != ',') return t;
|
||||
const char* second = end + 1;
|
||||
const double b = std::strtod(second, &end);
|
||||
if (end == second || *end) return t;
|
||||
if (!std::isfinite(a) || !std::isfinite(b) || a < 0 || a > 1 || b < 0 || b > 1) return t;
|
||||
t.on = true, t.targets = (float)a, t.textures = (float)b;
|
||||
return t;
|
||||
}
|
||||
|
||||
/// The tiers a run uses: the switch's where the device has the extension and its feature, else none (all the default)
|
||||
inline Tiers active(const char* env, bool device_has_it) { return device_has_it ? parse(env) : Tiers{}; }
|
||||
|
||||
/// What a piece of device memory is for. Held: the lab's ballast (RX_VK_TEST_CARD_MB), which must stay on the card
|
||||
enum class Kind { Target, Texture, Other, Held };
|
||||
|
||||
/// Its priority under the tiers; the default for everything while they are off
|
||||
inline float of(const Tiers& t, Kind k) {
|
||||
if (!t.on) return kDefault;
|
||||
return k == Kind::Target ? t.targets : k == Kind::Texture ? t.textures : k == Kind::Held ? 1.0f : t.other;
|
||||
}
|
||||
|
||||
} // namespace memory_priority
|
||||
@@ -25,6 +25,10 @@
|
||||
namespace menu_sound {
|
||||
// (vk_api.h HOS_MENU_SOUND_*: vk_menu.cpp holds them against these)
|
||||
constexpr int kNone = 0, kOpen = 1, kClose = 2, kCursor = 3, kDecide = 4, kCancel = 5, kTabLeft = 6, kTabRight = 7;
|
||||
// ((Triforce) and the Mods screen's and entry's own, which sound_of never names: the fanfare of a mod installed, and the
|
||||
// system menu's cursor and "decide" of the game's lists the Mods entry is under. (11-19) The queue took the seven above
|
||||
// only and dropped these without a word: moving onto Mods, A on it, Quit's dialog and the fanfare were silent)
|
||||
constexpr int kFanfare = 8, kSysCursor = 9, kSysDecide = 10, kLast = kSysDecide;
|
||||
|
||||
// (State::page: the tabs' rows, a page over them, and the restart question, whose two buttons L and R choose between)
|
||||
constexpr int kPageRows = 0, kPageAsk = 5;
|
||||
@@ -104,9 +108,9 @@ struct Queue {
|
||||
Entry entries[kQueue] = {};
|
||||
std::atomic<unsigned> head{0}, tail{0}; // (taken up to head, put up to tail)
|
||||
|
||||
/// The menu's thread: a sound asked for at now_ns. false when it is none of the seven, or the queue is full
|
||||
/// The menu's thread: a sound asked for at now_ns. false when it is none of the sounds (1 to kLast), or the queue is full
|
||||
bool put(int sound, int64_t now_ns) {
|
||||
if (sound <= kNone || sound > kTabRight) return false;
|
||||
if (sound <= kNone || sound > kLast) return false;
|
||||
const unsigned t = tail.load(std::memory_order_relaxed);
|
||||
if (t - head.load(std::memory_order_acquire) >= kQueue) return false;
|
||||
entries[t % kQueue] = {sound, now_ns};
|
||||
|
||||
109
gpu/vk/merged_rows.h
Normal file
109
gpu/vk/merged_rows.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/* (Triforce, options_version 7; 8 on v0.5.1) The Insert menu's rows that each stand for two saved values (vk_menu.cpp), and
|
||||
what an options file from before version 8 becomes (v0.5.1 wrote 7 for its Frame pacing default, with the old rows' keys
|
||||
still in it; the 436f9ac-based builds wrote 7 for this, without them: kVersion is 8 so that both are moved, and the second
|
||||
has nothing to move). The notes "(Triforce, options_version 7)" across the source and the tests name this change by its
|
||||
436f9ac-based number: on this line it is version 8, and version 7 is v0.5.1's Frame pacing default (vk_menu.cpp
|
||||
menu_init, "version < 7"); a file of 7 can still have the old rows' keys. The owner: "there's multiple settings that do
|
||||
multiple things and they contradict each other ... If a setting can be implemented in some other way, then remove the
|
||||
setting entirely". So one row chooses what two did: HDR (and RenoDX HDR), Frame generation (and DLSS frame generation), Frame pacing (and Steady frame rate), Low latency
|
||||
(NVIDIA Reflex or AMD Anti-Lag 2, by the graphics card's maker). The saved values keep their keys and their meanings, for the
|
||||
renderer and the host read them, some before the menu (hdr=, renodx_hdr=, frame_generation=, dlss_frame_generation=,
|
||||
frame_pacing=, steady_frame_rate=, nvidia_reflex=, amd_anti-lag_2=): the rows are views of them.
|
||||
Plain functions, no Vulkan, no menu: tests/test_merged_rows.py checks them, with a copy of the owner's own options. */
|
||||
#pragma once
|
||||
|
||||
namespace mkwvk::merged_rows {
|
||||
|
||||
// ---- HDR: Off | Expanded | Native | Native + RenoDX (opts.hdr 0 to 2, opts.renodx 0 or 1: RenoDX runs only with Native) ----
|
||||
enum { HDR_OFF = 0, HDR_EXPANDED = 1, HDR_NATIVE = 2, HDR_RENODX = 3 };
|
||||
constexpr int hdr_row(int hdr, int renodx) {
|
||||
return hdr == HDR_NATIVE && renodx ? (int)HDR_RENODX : hdr < 0 ? 0 : hdr > HDR_NATIVE ? (int)HDR_NATIVE : hdr;
|
||||
}
|
||||
inline void hdr_set(int row, int& hdr, int& renodx) {
|
||||
hdr = row >= HDR_RENODX ? (int)HDR_NATIVE : row < 0 ? 0 : row;
|
||||
renodx = row >= HDR_RENODX;
|
||||
}
|
||||
|
||||
// ---- Frame generation: opts.framegen's own values (framegen_rows.h: 0 Off, 1 Auto, 2 to 8, 9 AMD FSR 4), then NVIDIA DLSS
|
||||
// 2x, 3x and 4x (opts.dlssg 1 to 3, read at the start: a restart). Choosing one sets the other to Off ----
|
||||
enum { FG_DLSS = 10, FG_DLSS_LAST = 12 };
|
||||
constexpr int framegen_row(int framegen, int dlssg) { return dlssg >= 1 && dlssg <= 3 ? FG_DLSS + dlssg - 1 : framegen; }
|
||||
inline void framegen_set(int row, int& framegen, int& dlssg) {
|
||||
if (row >= FG_DLSS) {
|
||||
dlssg = row > FG_DLSS_LAST ? 3 : row - FG_DLSS + 1, framegen = 0;
|
||||
} else {
|
||||
dlssg = 0, framegen = row < 0 ? 0 : row;
|
||||
}
|
||||
}
|
||||
/// The row's choices here, in order: Off, Auto, 2x to 8x; AMD FSR 4 where its library makes the frames; NVIDIA DLSS 2x to 4x
|
||||
/// where DLSS frame generation can run. out holds 13 at most; their count
|
||||
inline int framegen_choices(int* out, bool fsr4_offered, bool dlss_offered) {
|
||||
int n = 0;
|
||||
for (int v = 0; v <= 8; v++) out[n++] = v;
|
||||
if (fsr4_offered) out[n++] = 9;
|
||||
for (int v = FG_DLSS; dlss_offered && v <= FG_DLSS_LAST; v++) out[n++] = v;
|
||||
return n;
|
||||
}
|
||||
|
||||
// ---- Frame pacing: Off | Even (opts.pace 1) | Steady, any rate | Steady, refresh steps (opts.steady_fps 1 and 2, host/pace_steady.h:
|
||||
// read at the start, a restart). Steady shows frames on an even line too, so it keeps frame_pacing on ----
|
||||
enum { PACE_OFF = 0, PACE_EVEN = 1, PACE_STEADY_ANY = 2, PACE_STEADY_STEPS = 3 };
|
||||
constexpr int pacing_row(int pace, int steady) {
|
||||
return steady == 1 ? (int)PACE_STEADY_ANY : steady == 2 ? (int)PACE_STEADY_STEPS : pace ? (int)PACE_EVEN : (int)PACE_OFF;
|
||||
}
|
||||
inline void pacing_set(int row, int& pace, int& steady) {
|
||||
pace = row != PACE_OFF;
|
||||
steady = row == PACE_STEADY_ANY ? 1 : row == PACE_STEADY_STEPS ? 2 : 0;
|
||||
}
|
||||
|
||||
// ---- Low latency: Off | On | On + Boost, NVIDIA Reflex on an NVIDIA card (opts.reflex 0 to 2), AMD Anti-Lag 2 on an AMD one
|
||||
// (opts.antilag 0 or 1: no Boost). No row where neither runs ----
|
||||
enum Vendor { LATENCY_NONE = 0, LATENCY_NVIDIA = 1, LATENCY_AMD = 2 };
|
||||
constexpr int latency_hi(Vendor v) { return v == LATENCY_NVIDIA ? 2 : v == LATENCY_AMD ? 1 : 0; }
|
||||
constexpr int latency_row(Vendor v, int reflex, int antilag) {
|
||||
return v == LATENCY_NVIDIA ? (reflex < 0 ? 0 : reflex > 2 ? 2 : reflex) : v == LATENCY_AMD ? (antilag ? 1 : 0) : 0;
|
||||
}
|
||||
inline void latency_set(int row, Vendor v, int& reflex, int& antilag) {
|
||||
if (v == LATENCY_NVIDIA) reflex = row < 0 ? 0 : row > 2 ? 2 : row;
|
||||
else if (v == LATENCY_AMD) antilag = row > 0;
|
||||
}
|
||||
|
||||
/// The next of a row's choices (ascending) from v, dir +1 or -1, wrapping. A value that is not among them (saved where it
|
||||
/// could run) steps to its neighbours by value
|
||||
inline int step_in(const int* choices, int n, int v, int dir) {
|
||||
if (n <= 0) return v;
|
||||
int i = 0;
|
||||
while (i < n && choices[i] < v) i++;
|
||||
if (i < n && choices[i] == v) return choices[(i + (dir > 0 ? 1 : n - 1)) % n];
|
||||
return dir > 0 ? choices[i % n] : choices[(i + n - 1) % n];
|
||||
}
|
||||
|
||||
// ---- The options file from before version 8 ----
|
||||
constexpr int kVersion = 8; // (vk_menu.cpp save writes it)
|
||||
constexpr int kHandheldOutput = 7; // (the Output resolution row's 1536x864, the game's handheld profile: opts.output_res 7)
|
||||
/// The keys a file before version 8 can have that the menu no longer writes, each row's job done otherwise: quality_preset (its
|
||||
/// memory limits are the card's own, sized from its video memory), upscaling (the window's filter follows the sizes:
|
||||
/// upscaler_rows.h auto_filter), reflex_frame_limit (off, its old default, until it has been played: RX_VK_REFLEX_LIMIT=1
|
||||
/// for a run, vk_menu.h reflex_limit), handheld_profile (an Output
|
||||
/// resolution), stick_dead_zone (each stick's own row). save drops their lines
|
||||
constexpr const char* kDropped[] = {"quality_preset", "upscaling", "reflex_frame_limit", "handheld_profile", "stick_dead_zone"};
|
||||
constexpr int kDroppedCount = sizeof kDropped / sizeof kDropped[0];
|
||||
/// What a file before version 8 had in those keys that 8 keeps elsewhere (the struct keeps its first name)
|
||||
struct Before7 {
|
||||
int handheld = 0; // (handheld_profile=)
|
||||
int stick_shared = 0; // (stick_dead_zone=: 0 XInput's ~24%, 1 to 5 the shares below)
|
||||
};
|
||||
/// The stick dead zone row's shares, in percent (host/nn_hid.c hos_stick_axis's cuts: a stick's own of the same percent cuts
|
||||
/// at the same place, hos_stick_axis_own); -1 XInput's own, the Left and Right stick dead zones' Default
|
||||
constexpr int kSharedZone[6] = {-1, 5, 10, 15, 20, 30};
|
||||
/// A file from before version 8 as 8 has it, the same in play: the handheld profile as the Output resolution's handheld
|
||||
/// size, the shared stick dead zone in each stick's own row where it had none of its own
|
||||
inline void migrate(int version, const Before7& old, int& output_res, int& lstick_dead_zone, int& rstick_dead_zone) {
|
||||
if (version >= kVersion) return;
|
||||
if (old.handheld) output_res = kHandheldOutput;
|
||||
const int shared = old.stick_shared > 0 && old.stick_shared < 6 ? kSharedZone[old.stick_shared] : -1;
|
||||
if (lstick_dead_zone < 0) lstick_dead_zone = shared;
|
||||
if (rstick_dead_zone < 0) rstick_dead_zone = shared;
|
||||
}
|
||||
|
||||
} // namespace mkwvk::merged_rows
|
||||
38
gpu/vk/mesa_spilling.h
Normal file
38
gpu/vk/mesa_spilling.h
Normal file
@@ -0,0 +1,38 @@
|
||||
// Mesa's Intel shader compiler told to spill registers at rate 2, before the driver is loaded (no game, no GPU: a rule).
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's PIPE-55, after Source A's.) Mesa's drivers read their options (driconf) from
|
||||
// the environment by name. shader_spilling_rate is read by the Intel compiler alone: after a register allocation that
|
||||
// failed, it spills that many times more registers at once, so a program that does not fit is built in fewer, larger
|
||||
// steps. A program that does not spill builds the same. Source A's numbers on an Iris Xe (i9-13900H, 32 GB, Mesa 26.2.4):
|
||||
// one compute program not built after 20 minutes and 13 GB at the driver's own rate, 32 s and 1.7 GB at rate 2; another
|
||||
// 531 s and 7.6 GB against 87 s and 4 GB; rate 3 took 165 s there and rate 4 did not finish in 8 minutes. The driver's
|
||||
// own estimate for a spilling program's speed at rate 2 is from 12% better to 53% worse.
|
||||
//
|
||||
// The Linux build sets it in create_instance (vk_main.cpp) without overwriting, so a value the player set wins.
|
||||
// RX_VK_NO_SPILLING_RATE=1 leaves the driver as it is. The Windows build sets nothing: under Proton the driver reads the
|
||||
// Linux environment, which the Windows build cannot write, and those players put shader_spilling_rate=2 in the launch
|
||||
// options.
|
||||
// Nothing here is read by NVIDIA's or AMD's drivers, RADV included.
|
||||
#pragma once
|
||||
#include <cstdlib>
|
||||
|
||||
namespace mesa_spilling {
|
||||
constexpr const char* kName = "shader_spilling_rate";
|
||||
constexpr const char* kRate = "2";
|
||||
|
||||
/// The build sets the rate: off Windows, unless RX_VK_NO_SPILLING_RATE is set to something other than 0. off: its value
|
||||
inline bool wanted(bool windows_build, const char* off) {
|
||||
return !windows_build && !(off && std::atoi(off) != 0);
|
||||
}
|
||||
|
||||
/// What the driver will read once the build has done its part: the player's own value where there is one (set without
|
||||
/// overwriting), else the rate where it is wanted, else nullptr (the driver's own rate)
|
||||
inline const char* effective(const char* players, bool is_wanted) {
|
||||
return players ? players : is_wanted ? kRate : nullptr;
|
||||
}
|
||||
|
||||
/// The log names the rate on Mesa's Intel driver alone
|
||||
constexpr bool told(bool mesa_intel) {
|
||||
return mesa_intel;
|
||||
}
|
||||
} // namespace mesa_spilling
|
||||
27
gpu/vk/mirror_budget.h
Normal file
27
gpu/vk/mirror_budget.h
Normal file
@@ -0,0 +1,27 @@
|
||||
// (Triforce) The VRAM mirrors' budget by the card (vk_memory.cpp mirror_budget; RX_VK_MIRROR_MB=<MB> goes over it). Plain code with
|
||||
// no Vulkan calls: tests/test_mirror_budget.py runs it on made-up cards.
|
||||
//
|
||||
// - A discrete card over 4.5 GB: a quarter of its video memory, at most 3 GB. On a 6 GB card (RTX 3060 Laptop, Hyrule Field,
|
||||
// whole mirrors) 512 MB of mirrors gave 17.6 fps, 1024 MB 30.7 and a quarter (1498 MB) 39.2: the pools left in system memory
|
||||
// were read over PCIe each frame. The eighth those cards had (768 MB) sat between two sizes measured as losses. Textures on
|
||||
// cards of 8.5 GB or less are 45% of the allowance and give memory back at 90% and 97% of it (vk_texture.cpp), the room a
|
||||
// quarter needs; the eighth was set for a 6 GB laptop before that rule, when a quarter and the textures went past the card.
|
||||
// - 4.5 GB or less, and an integrated GPU up to 6.5 GB: an eighth (no smaller size was measured on a real small card, and an
|
||||
// integrated GPU's "video memory" is the system's).
|
||||
// - Video memory not known: 3 GB.
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
|
||||
namespace mkwvk::mirror_size {
|
||||
|
||||
constexpr uint64_t kMB = 1ull << 20;
|
||||
|
||||
constexpr uint64_t bytes(uint64_t vram, bool discrete) {
|
||||
if (!vram) return 3072 * kMB;
|
||||
if (vram <= 4608 * kMB || (!discrete && vram <= 6656 * kMB)) return vram / 8;
|
||||
return std::min<uint64_t>(vram / 4, 3072 * kMB);
|
||||
}
|
||||
|
||||
} // namespace mkwvk::mirror_size
|
||||
42
gpu/vk/mirror_spare.h
Normal file
42
gpu/vk/mirror_spare.h
Normal file
@@ -0,0 +1,42 @@
|
||||
// (Triforce, 11-21, the performance audit's MEM-27, after Source A's: its first step) What the mirrors' sparse buffers cost.
|
||||
//
|
||||
// A mirror in pieces is a sparse buffer: address space, not memory, yet the driver charges by its size. Source A measured
|
||||
// about 0.06 ms a MB to create one and 0.07 to destroy it (NVIDIA 617.42), 52 to 64 ms batches of destructions at an area
|
||||
// change, and the game frees its pools there and makes them again at the same sizes. Its answer is to keep a freed
|
||||
// mirror's buffer, unbound, for the next mirror of exactly that size. Before that is built here, this counts: the creates
|
||||
// and destroys, their time, the longest, and how many creates a buffer freed earlier, of exactly their size, could have
|
||||
// served. The line "vk: mirrors' sparse buffers" every 1200 submissions has them (vk_memory.cpp).
|
||||
//
|
||||
// The count alone, no Vulkan: tests/test_mirror_spare.py compiles it.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
|
||||
namespace mirror_spare {
|
||||
|
||||
struct Counts {
|
||||
uint64_t creates = 0, destroys = 0, servable = 0; // (servable: creates a freed buffer of their size was there for)
|
||||
double create_ms = 0, destroy_ms = 0, longest_create_ms = 0, longest_destroy_ms = 0;
|
||||
uint64_t create_bytes = 0, destroy_bytes = 0, over = 0; // (over: calls of more than kLongMs)
|
||||
std::map<uint64_t, uint32_t> freed; // (sizes freed and not yet matched by a create)
|
||||
};
|
||||
inline constexpr double kLongMs = 4.0;
|
||||
|
||||
/// A sparse buffer of size bytes was destroyed in ms
|
||||
inline void destroyed(Counts& c, uint64_t size, double ms) {
|
||||
c.destroys++, c.destroy_ms += ms, c.destroy_bytes += size, c.over += ms > kLongMs;
|
||||
if (ms > c.longest_destroy_ms) c.longest_destroy_ms = ms;
|
||||
c.freed[size]++;
|
||||
}
|
||||
/// A sparse buffer of size bytes was created in ms; true when one freed before, of exactly that size, could have served
|
||||
inline bool created(Counts& c, uint64_t size, double ms) {
|
||||
c.creates++, c.create_ms += ms, c.create_bytes += size, c.over += ms > kLongMs;
|
||||
if (ms > c.longest_create_ms) c.longest_create_ms = ms;
|
||||
auto it = c.freed.find(size);
|
||||
if (it == c.freed.end()) return false;
|
||||
if (!--it->second) c.freed.erase(it);
|
||||
c.servable++;
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace mirror_spare
|
||||
125
gpu/vk/mods_entry_anim.h
Normal file
125
gpu/vk/mods_entry_anim.h
Normal file
@@ -0,0 +1,125 @@
|
||||
// (Triforce, 11-19) The Mods entry under the title's list, animated as the game animates its own entries. Each entry of the
|
||||
// title's list (Continue, New Game, Options, ...) is the part PaCommonBtnTitle_00 of the Title archive's layout, and the
|
||||
// part plays its own animations as its button takes and lets go of the cursor: Select, UnSelect, LoopRandom while it has
|
||||
// it, Decide when it is pressed. The Mods entry is drawn by the renderer one pitch under the list's last entry
|
||||
// (vk_menu.cpp draw_title_mods); here are its times and amounts, read from the part's curves (the layout's keys: a frame,
|
||||
// a value and a slope, Hermite between them, 60 frames a second) and from the title layout's (Title_00):
|
||||
// Select every pane of the chosen look from 0 to 1, the unchosen text from 1 to 0, over 1 frame
|
||||
// UnSelect back, over 8 frames
|
||||
// LoopRandom while chosen: 0.6, 0.5 at frame 20, 0.6 at 40 (the filigree's strength: 0.47 to 0.6 in the lab's shot)
|
||||
// Decide 16 frames: the filigree from 1 to 0.85 of its size from frame 8 (its glow to 0.95), the band's sparkle
|
||||
// (W_Bg_01) from 0 at frame 2 to 1 at 16; the game's next screen comes after it
|
||||
// the list Title_00's 15-frame rise from 0 to 1 (its keys' slopes 0.02 and 0.14), as the entry comes with the list;
|
||||
// and gone, as UnSelect, once the list has not been seen for 150 ms (vk_menu.cpp mods_list_fresh's: a game
|
||||
// frame late, at the 30 fps cap or in a hitch, is not the list going); back after that, its In goes on from
|
||||
// where the entry was, not from nothing
|
||||
// No ImGui and no Vulkan: tests/test_mods_entry_anim.py compiles it alone.
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdint>
|
||||
|
||||
namespace mods_entry {
|
||||
|
||||
/// A key of the layout's curves: its frame, its value, its slope (a value a frame)
|
||||
struct Key {
|
||||
float frame, value, slope;
|
||||
};
|
||||
/// A curve at frame f: the first key's value before it, the last's after; two keys at one frame are a step
|
||||
inline float curve(const Key* k, int n, float f) {
|
||||
if (f <= k[0].frame) return k[0].value;
|
||||
for (int i = 0; i + 1 < n; i++) {
|
||||
const Key &a = k[i], &b = k[i + 1];
|
||||
if (f > b.frame) continue;
|
||||
const float len = b.frame - a.frame;
|
||||
if (len <= 0) return b.value;
|
||||
const float t = (f - a.frame) / len, t2 = t * t, t3 = t2 * t;
|
||||
return (2 * t3 - 3 * t2 + 1) * a.value + (t3 - 2 * t2 + t) * a.slope * len + (-2 * t3 + 3 * t2) * b.value +
|
||||
(t3 - t2) * b.slope * len;
|
||||
}
|
||||
return k[n - 1].value;
|
||||
}
|
||||
|
||||
// (PaCommonBtnTitle_00's curves, as the layout keeps them)
|
||||
constexpr Key kSelect[] = {{0, 0, 0}, {1, 1, 0}};
|
||||
constexpr Key kUnSelect[] = {{0, 1, 0}, {8, 0, 0}};
|
||||
constexpr Key kLoop[] = {{0, 0.6f, 0}, {20, 0.5f, 0}, {40, 0.6f, 0}};
|
||||
constexpr Key kDecideDeco[] = {{8, 1, 0}, {8, 1, -0.04341f}, {16, 0.85f, 0}};
|
||||
constexpr Key kDecideGlow[] = {{8, 1, 0}, {8, 1, -0.01246f}, {16, 0.95f, 0}};
|
||||
constexpr Key kDecideFlash[] = {{0, 0, 0}, {2, 0, 0}, {16, 1, 0}};
|
||||
// (Title_00's: the list coming in)
|
||||
constexpr Key kListIn[] = {{0, 0, 0.02f}, {15, 1, 0.14f}};
|
||||
template <int N>
|
||||
inline float curve(const Key (&k)[N], float f) { return curve(k, N, f); }
|
||||
|
||||
constexpr int64_t kFrameNs = 16666667; // (a frame of the layout's: 1/60 s)
|
||||
constexpr int64_t kDecideNs = 16 * kFrameNs; // (Decide's length: the Mods screen opens after it)
|
||||
constexpr int64_t kLoopNs = 40 * kFrameNs;
|
||||
constexpr int64_t kListGoneNs = 150000000; // (the list not seen for this long: it went. As mods_list_fresh)
|
||||
constexpr int64_t kListShownNs = kListGoneNs + 8 * kFrameNs; // (...and the entry has gone with it after this)
|
||||
inline float frames(int64_t ns) { return (float)((double)ns / (double)kFrameNs); }
|
||||
|
||||
/// How far into the list's In (ns) it shows `amount` (0 to 1): its curve rises all the way, so a search of its 15 frames
|
||||
inline int64_t in_at(float amount) {
|
||||
if (amount <= 0) return 0;
|
||||
float lo = 0, hi = 15;
|
||||
for (int i = 0; i < 24; i++) {
|
||||
const float mid = (lo + hi) * 0.5f;
|
||||
(curve(kListIn, mid) < amount ? lo : hi) = mid;
|
||||
}
|
||||
return (int64_t)((double)hi * (double)kFrameNs);
|
||||
}
|
||||
|
||||
/// ((Triforce, 11-20) the game's own alpha of its buttons as the amount the entry is drawn with. The game blends its
|
||||
/// buttons in linear light; the overlay blends in the window's code values unless the window is HDR. A white word at alpha
|
||||
/// a over a dark picture is a^(1/2.2) of the way to white in code values when blended in linear light: drawn at a itself
|
||||
/// in code values, the entry was dimmer than the game's buttons all through a fade (a quarter of the way where they were
|
||||
/// half way), though it began and ended with them. linear: the overlay blends in linear light too (HDR): a itself)
|
||||
inline float list_amount(float game_alpha, bool linear) {
|
||||
const float a = std::clamp(game_alpha, 0.0f, 1.0f);
|
||||
return linear ? a : std::pow(a, 1.0f / 2.2f);
|
||||
}
|
||||
|
||||
/// The entry's state from one drawing to the next: how chosen it looks (focus) and how much of it shows with the list
|
||||
struct Anim {
|
||||
bool sel = false; // (it had the cursor at the last step)
|
||||
float from = 0; // (focus when the cursor last came or went)
|
||||
int64_t since_ns = 0; // (...and when)
|
||||
bool there = false; // (the list was seen at the last step)
|
||||
int64_t list_ns = 0; // (when the list came)
|
||||
float gone_from = 0; // (shown when the list went)
|
||||
float focus = 0, shown = 0;
|
||||
/// One drawing at now: whether the entry has the cursor, how long since the host last told of the list.
|
||||
/// ((Triforce, 11-20) list_alpha: how much of its own buttons the game shows now (0 to 1, the host's word each frame:
|
||||
/// HOS_OPT_MODS_ALPHA); the entry shows as much while the list is there, so it comes and goes with them, frame for
|
||||
/// frame, whatever animation the game plays (the title's opening, a second long, after a second and a half of
|
||||
/// nothing; the 15 frames as the list comes back). Under 0: not told, the list's In by this clock, as before)
|
||||
void step(int64_t now, bool selected, int64_t list_age_ns, float list_alpha = -1.0f) {
|
||||
if (!since_ns || selected != sel) from = since_ns ? focus : (selected ? 1.0f : 0.0f), sel = selected, since_ns = now;
|
||||
const float f = frames(now - since_ns);
|
||||
focus = sel ? std::max(from, curve(kSelect, f)) : from * curve(kUnSelect, f);
|
||||
const bool seen = list_age_ns < kListGoneNs;
|
||||
if (seen && !there) list_ns = now - in_at(shown); // ((Triforce, 11-19) from where it is: no blink to nothing)
|
||||
if (!seen && there) gone_from = shown;
|
||||
there = seen;
|
||||
shown = !seen ? gone_from * curve(kUnSelect, frames(list_age_ns - kListGoneNs))
|
||||
: list_alpha >= 0 ? list_alpha : curve(kListIn, frames(now - list_ns));
|
||||
shown = std::clamp(shown, 0.0f, 1.0f), focus = std::clamp(focus, 0.0f, 1.0f);
|
||||
}
|
||||
/// LoopRandom's value now (it runs from the cursor's coming)
|
||||
float loop(int64_t now) const { return curve(kLoop, frames((now - since_ns) % kLoopNs)); }
|
||||
};
|
||||
|
||||
/// Decide at t ns after the press: the filigree's size, its glow's, the band's sparkle (0 to 1)
|
||||
struct Decide {
|
||||
float deco = 1, glow = 1, flash = 0;
|
||||
};
|
||||
inline Decide decide_at(int64_t t) {
|
||||
Decide d;
|
||||
if (t < 0) return d;
|
||||
const float f = std::min(frames(t), 16.0f);
|
||||
d.deco = curve(kDecideDeco, f), d.glow = curve(kDecideGlow, f), d.flash = curve(kDecideFlash, f);
|
||||
return d;
|
||||
}
|
||||
|
||||
} // namespace mods_entry
|
||||
48
gpu/vk/mods_page_anim.h
Normal file
48
gpu/vk/mods_page_anim.h
Normal file
@@ -0,0 +1,48 @@
|
||||
// (Triforce, 11-20) The Mods screen as it opens. The owner: "Mod menu fade in". The entry that opens it is animated as the
|
||||
// game's own entries are (mods_entry_anim.h on the title, focus_anim.h under the pause menu's System list), and Quit's
|
||||
// dialog opens as the game's SystemWindow_00; the screen itself came at once, whole, on the frame after the press. It
|
||||
// fades in now as the game's lists and windows do: the alpha of Title_00's list and of SystemWindow_00's N_In_00 (the
|
||||
// same keys in both layouts: 0 to 1 over 15 frames, slow to start, slopes 0.02 and 0.14), with no rise, as a whole screen
|
||||
// has none. It takes input once that has played, as the game's own screens and Quit's dialog do. Back is a cut, as the
|
||||
// game's windows go in 2 frames.
|
||||
// No ImGui and no Vulkan: tests/test_mods_page_anim.py compiles it alone.
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include "mods_entry_anim.h" // (the layouts' curves: Key, curve, frames)
|
||||
|
||||
namespace mods_page {
|
||||
|
||||
using mods_entry::curve;
|
||||
using mods_entry::frames;
|
||||
using mods_entry::Key;
|
||||
using mods_entry::kFrameNs;
|
||||
|
||||
constexpr Key kInAlpha[] = {{0, 0, 0.02f}, {15, 1, 0.14f}};
|
||||
constexpr int64_t kInNs = 15 * kFrameNs;
|
||||
|
||||
/// How much of the screen shows t ns after it opened (0 to 1)
|
||||
inline float in_alpha(int64_t t) {
|
||||
if (t <= 0) return 0;
|
||||
return std::clamp(curve(kInAlpha, frames(t)), 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
/// The screen from one tick to the next: whether it is shown, and since when
|
||||
struct Page {
|
||||
bool shown = false; // (it was the page shown at the last step)
|
||||
int64_t since_ns = 0; // (when it came; 0 while it is not shown)
|
||||
/// One tick at now: whether the Mods screen is the page shown. A screen that comes starts its In; one that goes has none
|
||||
void step(int64_t now, bool on) {
|
||||
if (on && !shown) since_ns = now;
|
||||
if (!on) since_ns = 0;
|
||||
shown = on;
|
||||
}
|
||||
/// How much of it shows at now. settle: as it stands once its In is done (a still, a picture that compares). A screen
|
||||
/// asked for and not stepped yet (the page was set this tick, the step comes at the tick's end) shows nothing: drawn in
|
||||
/// between at full, it flashed whole for a frame before its In began
|
||||
float alpha(int64_t now, bool settle = false) const { return settle ? 1.0f : !shown ? 0.0f : in_alpha(now - since_ns); }
|
||||
/// (it takes input once its In has played, as the game's)
|
||||
bool ready(int64_t now) const { return shown && now - since_ns >= kInNs; }
|
||||
};
|
||||
|
||||
} // namespace mods_page
|
||||
95
gpu/vk/msync_pass.h
Normal file
95
gpu/vk/msync_pass.h
Normal file
@@ -0,0 +1,95 @@
|
||||
// (Triforce, 11-21, the performance audit's MEM-48, after Source A's) A mirror sync's pages from the captures by one compute
|
||||
// dispatch: the rules.
|
||||
//
|
||||
// A pool the GPU reads has a mirror in VRAM, and a sync brings the pages the CPU wrote into it. Those that come from a
|
||||
// capture's buffer (host memory) went as copy regions, a page or a few each, 700 to 1,300 a frame: the GPU reads each
|
||||
// region over PCIe after the one before. The write-back diff's pass (shaders/wb_diff.comp) reads a source, compares it
|
||||
// with a shadow and writes a destination where they differ; with the shadow and the destination both the mirror it is a
|
||||
// copy, a workgroup a chunk, every chunk of a sync in one dispatch. Source A's RTX 5080 in Hyrule Field: the syncs' GPU
|
||||
// time 1.41 to 0.69 ms a frame, 79.7 to 83.1 fps where the GPU bounds the frame.
|
||||
//
|
||||
// What keeps it right:
|
||||
// - a run goes as chunks only in whole words at word-aligned addresses (words); any other run of a sync is copied;
|
||||
// - the chunk tables are host memory in a ring of blocks, each table from an atom of its own (the flush covers whole
|
||||
// atoms), a block taken again only once the GPU is done with the recording that last read it (Ring); a sync whose
|
||||
// table finds no room is copied, as before;
|
||||
// - copies into one buffer are in order among themselves, a dispatch is not: where a mirror is written twice in one
|
||||
// upload command buffer and one of the two is the pass, a full barrier goes between (barrier_first). The pass's own
|
||||
// chunks and a sync's other copies never share a page.
|
||||
// RX_VK_MSYNC_PASS: on for NVIDIA when not set (measured there; no gain on an RX 5600 XT), 1: on every GPU, 0: copies.
|
||||
//
|
||||
// No Vulkan here: tests/test_msync_pass.py compiles it.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace msync_pass {
|
||||
|
||||
inline constexpr int kBlocks = 16;
|
||||
inline constexpr uint64_t kBlockBytes = 256u << 10; // (8192 chunks of 32 bytes: a frame's syncs took about 1,300)
|
||||
inline constexpr uint64_t kChunkBytes = 64u << 10; // (the pass's chunk at most)
|
||||
|
||||
/// Whether the pass is used: asked, RX_VK_MSYNC_PASS's value; not set: on NVIDIA's GPUs
|
||||
inline bool on(const char* asked, bool nvidia) {
|
||||
if (!asked || !*asked) return nvidia;
|
||||
return atoi(asked) != 0;
|
||||
}
|
||||
|
||||
/// Whether a run from src to dst (addresses) of size bytes can go as chunks
|
||||
constexpr bool words(uint64_t src, uint64_t dst, uint64_t size) { return size != 0 && !((src | dst | size) & 3); }
|
||||
|
||||
/// A run's chunks: emit(source, destination, count, vectors), the count in 16-byte vectors or in words. split(at, size,
|
||||
/// e(at, bytes, vectors)) is the write-back diff's (wbd_split: the words before the first 16-byte line, the lines 64 KB
|
||||
/// at a time, the words after). Addresses not alike within 16 bytes go in words alone
|
||||
template <class Split, class Emit>
|
||||
void run_chunks(uint64_t src, uint64_t dst, uint64_t size, Split&& split, Emit&& emit) {
|
||||
if ((src ^ dst) & 15) {
|
||||
for (uint64_t at = 0; at < size; at += kChunkBytes) {
|
||||
const uint64_t len = size - at < kChunkBytes ? size - at : kChunkBytes;
|
||||
emit(src + at, dst + at, (uint32_t)(len / 4), false);
|
||||
}
|
||||
return;
|
||||
}
|
||||
split(dst, size, [&](uint64_t a, uint64_t len, bool vecs) { emit(src + (a - dst), a, (uint32_t)(len / (vecs ? 16 : 4)), vecs); });
|
||||
}
|
||||
|
||||
/// What wrote a mirror so far in an upload command buffer
|
||||
enum : uint8_t { kCopies = 1, kPass = 2 };
|
||||
/// Whether a full barrier goes before a write of kind `now` into a mirror that `before` wrote earlier in the same
|
||||
/// upload command buffer: the pass after anything, and anything after the pass
|
||||
constexpr bool barrier_first(uint8_t before, uint8_t now) { return now == kPass ? before != 0 : (before & kPass) != 0; }
|
||||
|
||||
/// The tables' blocks: which are made, the newest recording that reads each, and how far each is filled
|
||||
struct Ring {
|
||||
struct Block {
|
||||
bool made = false;
|
||||
uint64_t value = 0, fill = 0;
|
||||
};
|
||||
Block b[kBlocks];
|
||||
int cur = -1;
|
||||
/// Room for a table of `bytes` read by the recording rec_value, the GPU done up to `completed`: the block's index
|
||||
/// and *at, the table's offset in it, a multiple of align; -1: none (too big, or the next block is still read).
|
||||
/// A block returned with made false is the caller's to make before it writes
|
||||
int get(uint64_t bytes, uint64_t align, uint64_t rec_value, uint64_t completed, uint64_t* at) {
|
||||
if (!bytes || bytes > kBlockBytes || !align) return -1;
|
||||
if (cur >= 0) {
|
||||
Block& c = b[cur];
|
||||
const uint64_t start = (c.fill + align - 1) / align * align;
|
||||
if (start + bytes <= kBlockBytes) {
|
||||
c.fill = start + bytes;
|
||||
if (rec_value > c.value) c.value = rec_value;
|
||||
*at = start;
|
||||
return cur;
|
||||
}
|
||||
}
|
||||
const int next = (cur + 1) % kBlocks;
|
||||
Block& n = b[next];
|
||||
if (n.made && n.value > completed) return -1;
|
||||
cur = next;
|
||||
n.fill = bytes, n.value = rec_value;
|
||||
*at = 0;
|
||||
return next;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace msync_pass
|
||||
49
gpu/vk/new_wait.h
Normal file
49
gpu/vk/new_wait.h
Normal file
@@ -0,0 +1,49 @@
|
||||
// (Triforce, 11-22, the performance audit's OS-04, after Source A's and Source B's) A `new` of the renderer's that fails at
|
||||
// Windows' commit limit waits before it throws.
|
||||
//
|
||||
// A refused allocation in the renderer was an uncaught std::bad_alloc: the game ended. At the commit limit (RAM and the page
|
||||
// file full) a refusal often ends in moments, as the page file grows or commit is given back, so the renderer's new handler
|
||||
// (vk_main.cpp new_refused, set in mkwvk_init) sleeps 50 ms and lets the allocation be tried again, for up to 5 s a thread
|
||||
// (HOS_COMMIT_WAIT_MS, the host's switch for the same wait: 0, none), and throws after that. Only while the system has less
|
||||
// than 4 GiB of commit left: a `new` refused with more than that free was not refused for the limit (a size no memory could
|
||||
// hold), and throws at once, as before. Source A's is the wait; the 4 GiB rule is Source B's, written anew here.
|
||||
//
|
||||
// A `new (std::nothrow)` whose caller has its own answer to a refusal (a staging block, a copy that is only a saving, the
|
||||
// recorder's ring) is not held up: NoWait around it makes the handler throw at once, and the nothrow new answers null.
|
||||
//
|
||||
// The rule alone, no system calls: tests/test_commit_limit.py compiles it.
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace mkwvk::new_wait {
|
||||
|
||||
constexpr uint64_t kNear = 4ull << 30; // (the commit left under which a refusal is taken for the limit's)
|
||||
constexpr int kStepMs = 50, kWaitMs = 5000, kMostMs = 60000;
|
||||
|
||||
/// HOS_COMMIT_WAIT_MS in ms: not set (or empty) 5000; a number that many, 0 and less none, 60000 at most
|
||||
inline int wait_ms(const char* env) {
|
||||
if (!env || !*env) return kWaitMs;
|
||||
const long v = std::atol(env);
|
||||
return v <= 0 ? 0 : v > kMostMs ? kMostMs : (int)v;
|
||||
}
|
||||
|
||||
inline thread_local int t_waited_ms = 0; // (what this thread has waited in all: its 5 s are not given twice)
|
||||
inline thread_local int t_no_wait = 0; // (NoWait scopes open on this thread)
|
||||
|
||||
/// Around a new (std::nothrow) that must answer at once
|
||||
struct NoWait {
|
||||
NoWait() { t_no_wait++; }
|
||||
~NoWait() { t_no_wait--; }
|
||||
NoWait(const NoWait&) = delete;
|
||||
NoWait& operator=(const NoWait&) = delete;
|
||||
};
|
||||
|
||||
/// A `new` was refused. true: sleep a step and let it be tried again; false: throw. known and avail: the system's commit left,
|
||||
/// when it could be read; waited_ms: this thread's waits so far; max_ms: wait_ms's; no_wait: NoWait scopes open
|
||||
inline bool waits(bool known, uint64_t avail, int waited_ms, int max_ms, int no_wait) {
|
||||
return !no_wait && known && avail < kNear && waited_ms < max_ms;
|
||||
}
|
||||
|
||||
} // namespace mkwvk::new_wait
|
||||
@@ -15,6 +15,8 @@
|
||||
// The game also predicates draws on these words (render conditions, NOP_RENDER_COND): as NX2navi decides them
|
||||
// (runtime/vk_exec_xfer.c cond_enabled), a word whose newest report is a samples-passed one with its count still to come is
|
||||
// unknown, and the condition renders; a word whose count was written is read from memory, where a real 0 can skip the draw.
|
||||
// (11-22) A count over a draw that such a skip left out is marked (Counter::gate, Writers::kGatedSrc, the line counts them);
|
||||
// RX_VK_OCC_GATE=1: a condition on it renders (cond_decide), so a skip's 0 cannot hide the same object again and again.
|
||||
//
|
||||
// Counter one counting, from a reset to its report, over the queries its draws began: the replay's (one per NVN
|
||||
// queue's state, under replay_mu) or a parallel replay's segment's (the helper thread's: a segment starts with
|
||||
@@ -95,6 +97,7 @@ struct Rep {
|
||||
uint32_t first = 0, n = 0;
|
||||
uint64_t pos = 0;
|
||||
int64_t present = 0;
|
||||
bool gated = false; // (a draw of its count left out by a condition that read a written count: Counter::gate)
|
||||
};
|
||||
|
||||
/// One samples-passed counting. The replay calls reset() at a SAMPLES_PASSED reset, draw_enter() as a draw goes into draw(),
|
||||
@@ -113,8 +116,10 @@ struct Counter {
|
||||
int open = -1; // (the query begun and not ended, its index in the block)
|
||||
bool lost = false; // (a draw in another recording, or the block full)
|
||||
uint32_t ops = 0, issued = 0; // (draws that went into draw() while counting, and those it recorded)
|
||||
enum Why { kNone, kSkipped, kOtherCmd, kFull };
|
||||
enum Why { kNone, kSkipped, kOtherCmd, kFull, kColour };
|
||||
Why why = kNone;
|
||||
bool gated = false; // (since the reset a draw was left out by a render condition that read a written count)
|
||||
bool colour = false; // ((Triforce, 11-22, GPUWORK-01) a draw that writes colour came in since the reset)
|
||||
|
||||
/// A parallel replay's segment starts (or ends), or the replay's counting is given up: nothing is counting
|
||||
void segment() { *this = Counter{}; }
|
||||
@@ -126,7 +131,35 @@ struct Counter {
|
||||
state = kCounting, slot = none ? -1 : slot_, serial = none ? 0 : serial_, first = next, open = -1, lost = none;
|
||||
ops = issued = 0;
|
||||
why = none ? kOtherCmd : kNone;
|
||||
gated = false;
|
||||
colour = false;
|
||||
}
|
||||
/// (11-22) A draw the replay passes with rendering off because a condition read a written count (a 0 of an earlier
|
||||
/// report): while counting, this count is gated, NVN counts nothing for that draw and neither do the queries. Such a count
|
||||
/// is a skip's result, not the object's visibility (Writers::kGatedSrc)
|
||||
void gate(bool keep) {
|
||||
if (counting(keep)) gated = true;
|
||||
}
|
||||
/// ((Triforce, 11-22, the performance audit's GPUWORK-01, after Source A's) A draw that writes colour comes in, its pass
|
||||
/// open, before begin(). The game's occlusion tests draw depth only (a bounding box against the depth buffer); a query
|
||||
/// that stays open over colour draws makes the GPU wait at its end for the work it encloses. What the caller does with
|
||||
/// the answer: first, this is the window's first such draw, and open, a query is open over it (both counted, whether or
|
||||
/// not the rule is on); lose, the rule is on (depth_only) and the count is given up: the caller ends the open query and
|
||||
/// calls lose_colour(). Nothing for a count not counting or lost already
|
||||
struct Colour {
|
||||
bool first = false, open = false, lose = false;
|
||||
};
|
||||
Colour colour_draw(bool keep, bool depth_only) {
|
||||
Colour r;
|
||||
if (!counting(keep) || lost) return r;
|
||||
r.first = !colour, colour = true;
|
||||
r.open = open >= 0;
|
||||
r.lose = depth_only;
|
||||
return r;
|
||||
}
|
||||
/// The count given up for a colour draw (its open query ended by the caller): no query begins until the next reset,
|
||||
/// its report is incomplete, so the record keeps the placeholder and its render condition renders
|
||||
void lose_colour() { lost = true, why = kColour; }
|
||||
void draw_enter(bool keep) {
|
||||
if (counting(keep)) ops++;
|
||||
}
|
||||
@@ -162,11 +195,91 @@ struct Counter {
|
||||
if (!complete && !lost) why = kSkipped;
|
||||
state = kReported;
|
||||
if (!complete) return kIncomplete;
|
||||
rep->first = first, rep->n = next - first;
|
||||
rep->first = first, rep->n = next - first, rep->gated = gated;
|
||||
return kMeasured;
|
||||
}
|
||||
};
|
||||
|
||||
/// A map from 64-bit keys, open addressing with linear probes and backward-shift deletion (no tombstones): no allocation per
|
||||
/// entry. The replay placed one entry for every samples-passed report (~2,600 a frame at the Market) in a std::unordered_map,
|
||||
/// a node allocated and freed each time: 0.76 ms a frame of the Presentation Thread (all-thread sample, 2026-11-20)
|
||||
// ((Triforce, 11-21) The keys, the used marks and the values in three arrays: a probe reads 9 bytes a slot, not a 48-byte slot.
|
||||
// The game's report addresses rotate through ~49,000 a 600-present period, ~27,000 live at once (kKeepAge): the table of slots was
|
||||
// ~3 MB, past the core's L2, and its probes and the prune's walk over it were 5% of the Presentation Thread (exact profile of a
|
||||
// line-table build, 2026-11-21). Same entries, same order of probes and shifts as before)
|
||||
template <class V>
|
||||
class FlatU64 {
|
||||
public:
|
||||
V* find(uint64_t k) {
|
||||
if (!n_) return nullptr;
|
||||
for (size_t i = idx(k);; i = (i + 1) & mask_) {
|
||||
if (!used_[i]) return nullptr;
|
||||
if (keys_[i] == k) return &vals_[i];
|
||||
}
|
||||
}
|
||||
const V* find(uint64_t k) const { return const_cast<FlatU64*>(this)->find(k); }
|
||||
V& operator[](uint64_t k) {
|
||||
if (V* v = find(k)) return *v;
|
||||
if ((n_ + 1) * 10 > keys_.size() * 7) grow();
|
||||
size_t i = idx(k);
|
||||
while (used_[i]) i = (i + 1) & mask_;
|
||||
keys_[i] = k, vals_[i] = V{}, used_[i] = 1;
|
||||
n_++;
|
||||
return vals_[i];
|
||||
}
|
||||
size_t count(uint64_t k) const { return find(k) ? 1 : 0; }
|
||||
size_t erase(uint64_t k) {
|
||||
if (!n_) return 0;
|
||||
size_t i = idx(k);
|
||||
for (;; i = (i + 1) & mask_) {
|
||||
if (!used_[i]) return 0;
|
||||
if (keys_[i] == k) break;
|
||||
}
|
||||
// backward shift: the entries after the hole that would be found from a slot at or before it move into it
|
||||
for (size_t j = (i + 1) & mask_;; j = (j + 1) & mask_) {
|
||||
if (!used_[j]) break;
|
||||
const size_t home = idx(keys_[j]);
|
||||
const bool moves = i <= j ? (home <= i || home > j) : (home <= i && home > j);
|
||||
if (moves) keys_[i] = keys_[j], vals_[i] = vals_[j], i = j;
|
||||
}
|
||||
keys_[i] = 0, vals_[i] = V{}, used_[i] = 0;
|
||||
n_--;
|
||||
return 1;
|
||||
}
|
||||
template <class F>
|
||||
void erase_if(F pred) { // (the keys to go first, then each erased: a shift during the walk would skip or revisit entries)
|
||||
gone_.clear();
|
||||
for (size_t i = 0; i < keys_.size(); i++)
|
||||
if (used_[i] && pred(keys_[i], vals_[i])) gone_.push_back(keys_[i]);
|
||||
for (uint64_t k : gone_) erase(k);
|
||||
}
|
||||
bool empty() const { return n_ == 0; }
|
||||
size_t size() const { return n_; }
|
||||
|
||||
private:
|
||||
size_t idx(uint64_t k) const { return (size_t)((k * 0x9E3779B97F4A7C15ull) >> shift_) & mask_; }
|
||||
void grow() {
|
||||
std::vector<uint64_t> ok;
|
||||
std::vector<uint8_t> ou;
|
||||
std::vector<V> ov;
|
||||
ok.swap(keys_), ou.swap(used_), ov.swap(vals_);
|
||||
const size_t cap = ok.empty() ? 1024 : ok.size() * 2;
|
||||
keys_.assign(cap, 0), used_.assign(cap, 0), vals_.assign(cap, V{});
|
||||
mask_ = cap - 1;
|
||||
shift_ = 64;
|
||||
for (size_t c = cap; c > 1; c >>= 1) shift_--;
|
||||
n_ = 0;
|
||||
for (size_t i = 0; i < ok.size(); i++)
|
||||
if (ou[i]) (*this)[ok[i]] = ov[i];
|
||||
}
|
||||
std::vector<uint64_t> keys_;
|
||||
std::vector<uint8_t> used_;
|
||||
std::vector<V> vals_;
|
||||
std::vector<uint64_t> gone_; // (erase_if's list, kept: no allocation a prune)
|
||||
size_t n_ = 0, mask_ = 0;
|
||||
int shift_ = 64;
|
||||
};
|
||||
|
||||
/// Per report address, the newest samples-passed report the replay wrote there (in stream order: placed) and where its
|
||||
/// count stands: NX2navi's Pending table (runtime/vk_exec_xfer.c: seq, written, unknown, "the last report to addr
|
||||
/// decides"). A count read back goes into its record only while its report is the newest there (the game's records rotate,
|
||||
@@ -182,12 +295,15 @@ public:
|
||||
kWritten, // (its count is in the record: completion wrote it)
|
||||
kFinal // (no count comes: skip list, knob off, a clear flag, not counted whole, lost, late, the CPU wrote it)
|
||||
};
|
||||
enum Src { kNone, kPendingSrc, kWrittenSrc, kFinalSrc }; // (what a render condition reading the word finds)
|
||||
// (what a render condition reading the word finds. kGatedSrc: written, a count over a draw a written count's condition
|
||||
// left out, see Counter::gate)
|
||||
enum Src { kNone, kPendingSrc, kWrittenSrc, kFinalSrc, kGatedSrc };
|
||||
struct Placed {
|
||||
uint64_t pos = 0;
|
||||
int64_t present = 0;
|
||||
uint64_t value = 0; // (what the replay, or a count written since, put in the word: a count is written only over it)
|
||||
State state = kFinal;
|
||||
bool gated = false; // (its count, written, was over a draw a written count's condition left out)
|
||||
};
|
||||
/// A report's placeholder `value` written at the replay, at pos in the stream (the newest there from now on). write:
|
||||
/// its count is to be written once read back (not on RX_VK_OCC_QUERY_SKIP, the lab knob on, not a clear flag)
|
||||
@@ -199,27 +315,28 @@ public:
|
||||
/// What a count read back for the report at (addr, pos) may do. (Two reports at one address with no draw between share
|
||||
/// a place; in stream order the last one's count is written last, over the first one's)
|
||||
Verdict verdict(uint64_t addr, uint64_t pos) const {
|
||||
auto it = m_.find(addr);
|
||||
if (it == m_.end()) return kUnknown; // (not reported for kKeepAge presents, or rewritten in the stream)
|
||||
if (it->second.pos > pos) return kSuperseded; // (reported again since: another object's record now)
|
||||
if (it->second.pos != pos) return kUnknown;
|
||||
return it->second.state == kFinal ? kFixed : kWrite;
|
||||
const auto* it = m_.find(addr);
|
||||
if (!it) return kUnknown; // (not reported for kKeepAge presents, or rewritten in the stream)
|
||||
if (it->pos > pos) return kSuperseded; // (reported again since: another object's record now)
|
||||
if (it->pos != pos) return kUnknown;
|
||||
return it->state == kFinal ? kFixed : kWrite;
|
||||
}
|
||||
/// The value the report at addr left in its word (the placeholder, or the count written since)
|
||||
uint64_t value(uint64_t addr) const {
|
||||
auto it = m_.find(addr);
|
||||
return it == m_.end() ? 0 : it->second.value;
|
||||
const auto* it = m_.find(addr);
|
||||
return !it ? 0 : it->value;
|
||||
}
|
||||
/// The count of the report at (addr, pos) is in its record now
|
||||
void wrote(uint64_t addr, uint64_t pos, uint64_t count) {
|
||||
auto it = m_.find(addr);
|
||||
if (it != m_.end() && it->second.pos == pos) it->second.state = kWritten, it->second.value = count;
|
||||
/// The count of the report at (addr, pos) is in its record now (gated: counted over a draw a written count's condition
|
||||
/// left out)
|
||||
void wrote(uint64_t addr, uint64_t pos, uint64_t count, bool gated = false) {
|
||||
auto* it = m_.find(addr);
|
||||
if (it && it->pos == pos) it->state = kWritten, it->value = count, it->gated = gated;
|
||||
}
|
||||
/// No count comes for the report at (addr, pos) (not counted whole, lost, late, never sent, the CPU wrote the record):
|
||||
/// a condition reads its word from memory from now on, as before
|
||||
void settle(uint64_t addr, uint64_t pos) {
|
||||
auto it = m_.find(addr);
|
||||
if (it != m_.end() && it->second.pos == pos && it->second.state == kPending) it->second.state = kFinal;
|
||||
auto* it = m_.find(addr);
|
||||
if (it && it->pos == pos && it->state == kPending) it->state = kFinal;
|
||||
}
|
||||
/// A report of another counter type at addr (a timestamp: base behaviour) is the newest there now
|
||||
bool erase(uint64_t addr) { return m_.erase(addr) != 0; }
|
||||
@@ -236,26 +353,25 @@ public:
|
||||
/// (unknown: renders), written (memory holds it), or none to come (memory). A count pending longer than kLateAge
|
||||
/// presents is not written any more (complete: late): memory
|
||||
Src word(uint64_t addr, int64_t now) const {
|
||||
auto it = m_.find(addr);
|
||||
if (it == m_.end()) return kNone;
|
||||
switch (it->second.state) {
|
||||
case kPending: return now - it->second.present > kLateAge ? kFinalSrc : kPendingSrc;
|
||||
case kWritten: return kWrittenSrc;
|
||||
const auto* it = m_.find(addr);
|
||||
if (!it) return kNone;
|
||||
switch (it->state) {
|
||||
case kPending: return now - it->present > kLateAge ? kFinalSrc : kPendingSrc;
|
||||
case kWritten: return it->gated ? kGatedSrc : kWrittenSrc;
|
||||
case kFinal: break;
|
||||
}
|
||||
return kFinalSrc;
|
||||
}
|
||||
/// The addresses not reported for more than `age` presents go (a count still to come for them is not written)
|
||||
void prune(int64_t now, int64_t age) {
|
||||
for (auto it = m_.begin(); it != m_.end();)
|
||||
it = now - it->second.present > age ? m_.erase(it) : std::next(it);
|
||||
m_.erase_if([now, age](uint64_t, const Placed& p) { return now - p.present > age; });
|
||||
}
|
||||
size_t size() const { return m_.size(); }
|
||||
|
||||
private:
|
||||
// (the pages a report went into, by a hash of the page, as NX2navi's rep_pages: a clear elsewhere looks nothing up)
|
||||
static uint32_t page(uint64_t a) { return (uint32_t)(((a >> 12) * 0x9E3779B97F4A7C15ull) >> 48); }
|
||||
std::unordered_map<uint64_t, Placed> m_;
|
||||
FlatU64<Placed> m_; // (by report address: FlatU64, no allocation per report)
|
||||
std::vector<uint8_t> page_ = std::vector<uint8_t>(1u << 16);
|
||||
};
|
||||
|
||||
@@ -263,23 +379,33 @@ private:
|
||||
/// they differ) over the words' sources (Writers::word), after NX2navi's cond_enabled: a samples-passed count not done yet
|
||||
/// renders; a written one, as any other word, is read from memory (base_enabled: the replay's answer from memory). active:
|
||||
/// RX_VK_OCC_QUERY=1 or the lab knob's phase (else the answer is the base one, whatever the table says); cond_on: false
|
||||
/// with RX_VK_OCC_COND=0, every condition on a samples-passed word renders
|
||||
/// with RX_VK_OCC_COND=0, every condition on a samples-passed word renders.
|
||||
/// (11-22) gate_on (RX_VK_OCC_GATE=1): a word whose count was written over a draw that a written count's condition left
|
||||
/// out (Writers::kGatedSrc) is unknown, and the condition renders. The count is a skip's result, not the object's: on the
|
||||
/// console the game's CPU reads a 0 before it records the next frame and draws the object's proxy instead; here the count
|
||||
/// often lands after the CPU has read the placeholder (4096: visible), the game goes on drawing the object under the
|
||||
/// condition, the condition reads the skip's 0, the next count is 0 again, and the object stays hidden for good. Off: as a
|
||||
/// written count (read from memory)
|
||||
struct Cond {
|
||||
enum Kind { kNotSamples, kBase, kUnknown, kForced, kWrittenOn, kWrittenOff, kMemory };
|
||||
enum Kind { kNotSamples, kBase, kUnknown, kForced, kWrittenOn, kWrittenOff, kMemory, kGated };
|
||||
bool enabled;
|
||||
Kind kind;
|
||||
};
|
||||
inline Cond cond_decide(bool base_enabled, Writers::Src sx, Writers::Src sy, bool active, bool cond_on) {
|
||||
inline Cond cond_decide(bool base_enabled, Writers::Src sx, Writers::Src sy, bool active, bool cond_on, bool gate_on = false) {
|
||||
if (sx == Writers::kNone && sy == Writers::kNone) return {base_enabled, Cond::kNotSamples};
|
||||
if (!active) return {base_enabled, Cond::kBase};
|
||||
if (!cond_on) return {true, Cond::kForced};
|
||||
if (sx == Writers::kPendingSrc || sy == Writers::kPendingSrc) return {true, Cond::kUnknown};
|
||||
if (sx == Writers::kWrittenSrc || sy == Writers::kWrittenSrc)
|
||||
const bool gated = sx == Writers::kGatedSrc || sy == Writers::kGatedSrc;
|
||||
if (gated && gate_on) return {true, Cond::kGated};
|
||||
if (sx == Writers::kWrittenSrc || sy == Writers::kWrittenSrc || gated)
|
||||
return {base_enabled, base_enabled ? Cond::kWrittenOn : Cond::kWrittenOff};
|
||||
return {base_enabled, Cond::kMemory};
|
||||
}
|
||||
inline const char* src_name(Writers::Src s) {
|
||||
return s == Writers::kPendingSrc ? "pending" : s == Writers::kWrittenSrc ? "written" : s == Writers::kFinalSrc ? "memory, no count to come" : "memory";
|
||||
return s == Writers::kPendingSrc ? "pending" : s == Writers::kWrittenSrc ? "written"
|
||||
: s == Writers::kGatedSrc ? "written, over a draw a written count skipped"
|
||||
: s == Writers::kFinalSrc ? "memory, no count to come" : "memory";
|
||||
}
|
||||
|
||||
/// What happened since the last line (under the caller's lock)
|
||||
@@ -294,9 +420,16 @@ struct Stats {
|
||||
int64_t rewritten = 0; // records rewritten in the stream after their report (a small clear, another counter type)
|
||||
int64_t measured = 0, no_reset = 0, incomplete = 0, doubles = 0; // counted whole by queries, and those not
|
||||
int64_t inc_skipped = 0, inc_other_cmd = 0, inc_full = 0; // why not whole
|
||||
// ((Triforce, 11-22, GPUWORK-01) and of the incomplete ones, those given up for a colour draw in their window
|
||||
// (RX_VK_OCC_DEPTH_ONLY); the windows that met a colour draw, the colour draws under an open query, the counts given up
|
||||
// (colour_line, a line of its own: line() is at the log's length already)
|
||||
int64_t inc_colour = 0, colour_windows = 0, colour_open = 0, colour_lost = 0;
|
||||
// render conditions that read a samples-passed report's word (Cond::Kind), and the work they skipped
|
||||
int64_t conds = 0, cond_base = 0, cond_unknown = 0, cond_forced = 0, cond_written_on = 0, cond_written_off = 0, cond_memory = 0;
|
||||
int64_t draws_skipped = 0, clears_skipped = 0;
|
||||
// (11-22) counts over a draw a written count's condition left out (Counter::gate): counted whole, written (of them 0),
|
||||
// the conditions that read one, and those RX_VK_OCC_GATE=1 rendered
|
||||
int64_t gated = 0, gated_written = 0, gated_zeros = 0, cond_gated_read = 0, cond_gated = 0;
|
||||
// at completion
|
||||
int64_t written = 0, zeros = 0; // counts written into their records (of them 0: the object hidden)
|
||||
int64_t lost = 0; // a query not available once its recording was done: 4096 stays
|
||||
@@ -313,7 +446,17 @@ struct Stats {
|
||||
if (k == Cond::kNotSamples) return;
|
||||
conds++;
|
||||
(k == Cond::kBase ? cond_base : k == Cond::kUnknown ? cond_unknown : k == Cond::kForced ? cond_forced
|
||||
: k == Cond::kWrittenOn ? cond_written_on : k == Cond::kWrittenOff ? cond_written_off : cond_memory)++;
|
||||
: k == Cond::kWrittenOn ? cond_written_on : k == Cond::kWrittenOff ? cond_written_off : k == Cond::kGated ? cond_gated
|
||||
: cond_memory)++;
|
||||
}
|
||||
/// ((Triforce, 11-22, the performance audit's GPUWORK-01) The colour draws' line, into out. on: the rule is on
|
||||
int colour_line(char* out, size_t size, int64_t presents, bool on) const {
|
||||
return snprintf(out, size,
|
||||
"vk: occlusion queries (RX_VK_OCC_QUERY), %lld presents (3): %lld counting windows met a draw that "
|
||||
"writes colour, %lld such draws were recorded under an open query; depth-only counting "
|
||||
"(RX_VK_OCC_DEPTH_ONLY) is %s: %lld counts given up at a colour draw, %lld reports kept 4096 for it",
|
||||
(long long)presents, (long long)colour_windows, (long long)colour_open, on ? "on" : "off",
|
||||
(long long)colour_lost, (long long)inc_colour);
|
||||
}
|
||||
/// The line, into out
|
||||
int line(char* out, size_t size, int64_t presents, size_t tracked) const {
|
||||
@@ -331,7 +474,8 @@ struct Stats {
|
||||
"%lld (%lld as before: knob occq off; %lld rendered: a count pending (unknown); %lld rendered: "
|
||||
"RX_VK_OCC_COND=0; %lld rendered from a written count; %lld skipped from a written count; %lld from "
|
||||
"memory, no count to come); skipped by them: %lld draws and dispatches, %lld clears; %lld addresses "
|
||||
"this period, %zu tracked",
|
||||
"this period, %zu tracked; counts over a draw such a skip left out: %lld counted whole, %lld written "
|
||||
"(%lld of them 0), %lld conditions read one (%lld rendered: RX_VK_OCC_GATE=1)",
|
||||
(long long)presents, (long long)reports, (long long)in_segments, (long long)skipped, (long long)fixed,
|
||||
(long long)flagged, (long long)rewritten, (long long)measured, (long long)no_reset,
|
||||
(long long)incomplete, (long long)inc_skipped, (long long)inc_other_cmd, (long long)inc_full,
|
||||
@@ -341,7 +485,8 @@ struct Stats {
|
||||
(long long)at[kAtWait], (long long)at[kAtBegin], (long long)at[kAtPresent], (long long)at[kAtReuse],
|
||||
(long long)conds, (long long)cond_base, (long long)cond_unknown, (long long)cond_forced,
|
||||
(long long)cond_written_on, (long long)cond_written_off, (long long)cond_memory,
|
||||
(long long)draws_skipped, (long long)clears_skipped, (long long)addrs, tracked);
|
||||
(long long)draws_skipped, (long long)clears_skipped, (long long)addrs, tracked, (long long)gated,
|
||||
(long long)gated_written, (long long)gated_zeros, (long long)cond_gated_read, (long long)cond_gated);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -382,9 +527,10 @@ void complete(const std::vector<Rep>& reps, const uint64_t* pairs, uint32_t used
|
||||
w.settle(p.addr, p.pos);
|
||||
continue;
|
||||
}
|
||||
w.wrote(p.addr, p.pos, sum);
|
||||
w.wrote(p.addr, p.pos, sum, p.gated);
|
||||
const int64_t lat = std::max<int64_t>(0, now - p.present);
|
||||
st.written++, st.zeros += sum ? 0 : 1, st.lat_sum += lat, st.lat_ge1 += lat >= 1, st.lat_ge2 += lat >= 2;
|
||||
if (p.gated) st.gated_written++, st.gated_zeros += sum ? 0 : 1;
|
||||
}
|
||||
}
|
||||
/// A recording's reports that never went to the GPU: no count comes for them
|
||||
@@ -439,15 +585,26 @@ struct Sites {
|
||||
};
|
||||
|
||||
/// The distinct addresses reported since the last line (bounded)
|
||||
/// (a fixed open-addressing table of 131072 keys, 0 meaning empty (a report address is never 0), cleared at each line: it
|
||||
/// was a std::unordered_set, a node allocated for each report's address only to count them for the log, 2,600 a frame)
|
||||
struct Distinct {
|
||||
std::unordered_set<uint64_t> seen;
|
||||
static constexpr size_t kSlots = 1u << 17, kMost = 65536;
|
||||
std::vector<uint64_t> slot = std::vector<uint64_t>(kSlots, 0);
|
||||
int64_t n = 0;
|
||||
void note(uint64_t addr) {
|
||||
if (seen.size() < 65536) seen.insert(addr);
|
||||
if (!addr || n >= (int64_t)kMost) return;
|
||||
for (size_t i = (size_t)((addr * 0x9E3779B97F4A7C15ull) >> 47) & (kSlots - 1);; i = (i + 1) & (kSlots - 1)) {
|
||||
if (slot[i] == addr) return;
|
||||
if (!slot[i]) {
|
||||
slot[i] = addr, n++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
int64_t take() {
|
||||
const int64_t n = (int64_t)seen.size();
|
||||
seen.clear();
|
||||
return n;
|
||||
const int64_t r = n;
|
||||
if (n) std::fill(slot.begin(), slot.end(), 0), n = 0;
|
||||
return r;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
82
gpu/vk/occ_lean.h
Normal file
82
gpu/vk/occ_lean.h
Normal file
@@ -0,0 +1,82 @@
|
||||
// (Triforce, 11-22, the performance audit's DESC-82, after Source B's: its first step, the census) The game's occlusion tests
|
||||
// draw proxies that write no colour, and each such draw runs its whole fragment shader and fills its fragment descriptors.
|
||||
// Source B makes a sibling pipeline without the fragment stage for a counted draw that writes no colour and whose fragment
|
||||
// shader has no effect but colour (no depth or sample-mask output, no demote, no stores, image writes, atomics or global
|
||||
// memory) and whose state has neither alpha to coverage nor an alpha test. It was never on by default nor measured; its
|
||||
// census at Kakariko counted about 2,570 colour-off draws of about 3,420 counted. The entry's own order is the census first,
|
||||
// and the lean pipelines only if the census finds more than one fragment descriptor a proxy to save.
|
||||
//
|
||||
// This is the census alone. RX_VK_OCC_LEAN=3: each draw under an open occlusion query that writes no colour is classed
|
||||
// (classify: lean, or the first refusal), and its fragment stage's descriptors added to its class; every 600 presents one
|
||||
// line gives each class's draws and descriptors a frame (vk_replay.cpp status_tick). No pipeline, key or descriptor changes.
|
||||
// 1 (the lean pipelines) and 2 (their check) are not built: they read as off. Unset: nothing of it runs.
|
||||
//
|
||||
// The rules alone: tests/test_occ_lean.py compiles them.
|
||||
#pragma once
|
||||
#include <atomic>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace occ_lean {
|
||||
|
||||
/// RX_VK_OCC_LEAN: 3 for the census; anything else is off (1 and 2: the steps after the census, not built)
|
||||
inline int mode_of(const char* e) { return e && *e && std::atoi(e) == 3 ? 3 : 0; }
|
||||
|
||||
enum Class { kLean, kNoFragment, kDepth, kSampleMask, kDemote, kStores, kImageWrites, kAtomics, kGlobal, kA2c, kAlphaTest, kClasses };
|
||||
inline const char* const kNames[kClasses] = {"lean", "no fragment stage", "depth out", "sample mask", "demote", "stores",
|
||||
"image writes", "atomics", "global memory", "alpha to coverage", "alpha test"};
|
||||
|
||||
/// What the class reads of a draw: its fragment stage's (Shader::Info) and its state's
|
||||
struct Facts {
|
||||
bool has_fragment = true;
|
||||
bool depth_out = false, sample_mask = false, demote = false, stores = false, image_writes = false, atomics = false,
|
||||
global = false;
|
||||
bool a2c = false, alpha_test = false;
|
||||
};
|
||||
|
||||
/// The draw's class: no fragment stage (nothing to leave out), the first refusal of the shader's then of the state's, or lean
|
||||
inline Class classify(const Facts& f) {
|
||||
if (!f.has_fragment) return kNoFragment;
|
||||
if (f.depth_out) return kDepth;
|
||||
if (f.sample_mask) return kSampleMask;
|
||||
if (f.demote) return kDemote;
|
||||
if (f.stores) return kStores;
|
||||
if (f.image_writes) return kImageWrites;
|
||||
if (f.atomics) return kAtomics;
|
||||
if (f.global) return kGlobal;
|
||||
if (f.a2c) return kA2c;
|
||||
if (f.alpha_test) return kAlphaTest;
|
||||
return kLean;
|
||||
}
|
||||
|
||||
/// The counts, any recording thread (relaxed)
|
||||
struct Census {
|
||||
std::atomic<uint64_t> draws[kClasses]{};
|
||||
std::atomic<uint64_t> descriptors[kClasses]{};
|
||||
void note(Class c, uint32_t frag_descriptors) {
|
||||
draws[c].fetch_add(1, std::memory_order_relaxed);
|
||||
descriptors[c].fetch_add(frag_descriptors, std::memory_order_relaxed);
|
||||
}
|
||||
/// The line for `presents` presents (draws and fragment descriptors a frame, the lean ones' descriptors a draw, then each
|
||||
/// refusal that met any), and the counts set back. Its length
|
||||
int line(char* out, size_t n, uint64_t presents) {
|
||||
uint64_t d[kClasses], s[kClasses], all = 0;
|
||||
for (int i = 0; i < kClasses; i++)
|
||||
d[i] = draws[i].exchange(0, std::memory_order_relaxed), s[i] = descriptors[i].exchange(0, std::memory_order_relaxed),
|
||||
all += d[i];
|
||||
const double p = presents ? (double)presents : 1.0;
|
||||
int at = std::snprintf(out, n, "vk: occlusion proxies (RX_VK_OCC_LEAN=3, %llu presents): %.0f colour-off counted draws a frame; "
|
||||
"lean %.0f a frame with %.2f fragment descriptors each", (unsigned long long)presents, all / p,
|
||||
d[kLean] / p, d[kLean] ? (double)s[kLean] / (double)d[kLean] : 0.0);
|
||||
for (int i = 1; i < kClasses && at > 0 && (size_t)at < n; i++)
|
||||
if (d[i])
|
||||
at += std::snprintf(out + at, n - (size_t)at, "; %s %.0f (%.2f descriptors each)", kNames[i], d[i] / p,
|
||||
(double)s[i] / (double)d[i]);
|
||||
return at;
|
||||
}
|
||||
};
|
||||
inline Census census;
|
||||
|
||||
} // namespace occ_lean
|
||||
100
gpu/vk/page_marks.h
Normal file
100
gpu/vk/page_marks.h
Normal file
@@ -0,0 +1,100 @@
|
||||
// (Triforce, 11-22, the performance audit's THREAD-25, after Source A's) Pages that something ever happened to, asked without a lock;
|
||||
// and the question an invalidate asks of them first.
|
||||
//
|
||||
// The game invalidates each shape's 64-byte occlusion slot, per view: tens of thousands of nvnBufferInvalidateMappedRange calls in a
|
||||
// few seconds. The host gives the calling thread's virtual core up before every one and queues for it again after, as the call can
|
||||
// wait for the replay or for a write-back still on the GPU; nearly always it has nothing to wait for. What it would wait for is
|
||||
// known from three things: a write-back ever made into the range's pages, a texture the GPU wrote ever listed there, and a live
|
||||
// texture's storage there. The first two are tables under their own locks; PageMarks keeps, beside each, one bit a 4 KB page that is
|
||||
// only ever set, set before the table changes and under the table's lock, and read with no lock. A range with no mark in either and
|
||||
// no texture storage is one invalidate() returns from without waiting, so the host may keep the core and not make the call
|
||||
// (invalidate_quick in vk_replay.cpp, asked through mkwvk_invalidate_quick by host/rx_backend.c).
|
||||
//
|
||||
// A mark is never taken back: a page written back once declines for good, and waits as before. Addresses at or past 512 GB are
|
||||
// not kept and answer as marked. The header is written from the audit's description of Source A's, whose file is not here.
|
||||
//
|
||||
// RX_VK_INVALIDATE_QUICK=1 turns the question on; off unless set (see docs/development.md for why). tests/test_invalidate_quick.py
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace mkwvk {
|
||||
|
||||
struct PageMarks {
|
||||
static constexpr uint64_t kSpan = 1ull << 39; // (512 GB: the guest window, and the GPU's addresses the pools lie in)
|
||||
static constexpr uint64_t kPageShift = 12, kPages = kSpan >> kPageShift;
|
||||
static constexpr uint64_t kChunkPages = 1ull << 18; // (a chunk: 1 GB of addresses, 32 KB of bits, made at its first mark)
|
||||
static constexpr uint64_t kChunks = kPages / kChunkPages, kChunkWords = kChunkPages / 64;
|
||||
std::atomic<std::atomic<uint64_t>*> chunks[kChunks] = {};
|
||||
|
||||
/// every page with a byte in [lo, hi) marked (what lies at or past 512 GB is not kept: any() answers true there)
|
||||
void mark(uint64_t lo, uint64_t hi) {
|
||||
if (hi > kSpan) hi = kSpan;
|
||||
if (hi <= lo) return;
|
||||
const uint64_t last = (hi - 1) >> kPageShift;
|
||||
for (uint64_t p = lo >> kPageShift; p <= last;) {
|
||||
std::atomic<uint64_t>* c = chunks[p / kChunkPages].load(std::memory_order_acquire);
|
||||
if (!c) {
|
||||
std::atomic<uint64_t>* made = new std::atomic<uint64_t>[kChunkWords];
|
||||
for (uint64_t i = 0; i < kChunkWords; i++) made[i].store(0, std::memory_order_relaxed);
|
||||
if (chunks[p / kChunkPages].compare_exchange_strong(c, made, std::memory_order_acq_rel)) c = made;
|
||||
else delete[] made; // (another thread made it first: c is its chunk)
|
||||
}
|
||||
// (the pages of this word from p to the word's end, or to `last`)
|
||||
const uint64_t in_chunk = p % kChunkPages, bit = in_chunk % 64;
|
||||
const uint64_t word_last = p - bit + 63, to = word_last < last ? word_last : last;
|
||||
const uint64_t n = to - p + 1;
|
||||
const uint64_t mask = (n == 64 ? ~0ull : ((1ull << n) - 1)) << bit;
|
||||
c[in_chunk / 64].fetch_or(mask, std::memory_order_seq_cst);
|
||||
p = to + 1;
|
||||
}
|
||||
}
|
||||
/// whether a page with a byte in [lo, lo + size) was ever marked; true for a range that reaches 512 GB or wraps
|
||||
bool any(uint64_t lo, uint64_t size) const {
|
||||
if (!size) return false;
|
||||
if (lo >= kSpan || size > kSpan - lo) return true;
|
||||
const uint64_t last = (lo + size - 1) >> kPageShift;
|
||||
for (uint64_t p = lo >> kPageShift; p <= last;) {
|
||||
const std::atomic<uint64_t>* c = chunks[p / kChunkPages].load(std::memory_order_seq_cst);
|
||||
if (!c) { // (a chunk never marked: skipped whole)
|
||||
p = (p / kChunkPages + 1) * kChunkPages;
|
||||
continue;
|
||||
}
|
||||
const uint64_t in_chunk = p % kChunkPages, bit = in_chunk % 64;
|
||||
const uint64_t word_last = p - bit + 63, to = word_last < last ? word_last : last;
|
||||
const uint64_t n = to - p + 1;
|
||||
const uint64_t mask = (n == 64 ? ~0ull : ((1ull << n) - 1)) << bit;
|
||||
if (c[in_chunk / 64].load(std::memory_order_seq_cst) & mask) return true;
|
||||
p = to + 1;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
namespace inv_quick { // (the rule of vk_replay.cpp's invalidate_quick)
|
||||
|
||||
/// Whether the question is asked at all. quick: RX_VK_INVALIDATE_QUICK (a number other than 0 turns it on; off unless set). The
|
||||
/// three others are switches that make invalidate() log every call or wait for every range: with one set, every call is made
|
||||
inline bool on(const char* quick, const char* log_invalidate, const char* log_readback, const char* wait_all) {
|
||||
return quick && std::atoi(quick) != 0 && !log_invalidate && !log_readback && !wait_all;
|
||||
}
|
||||
|
||||
/// What is known of a range when the question is asked
|
||||
struct Look {
|
||||
uint64_t gpu = 0, size = 0;
|
||||
bool ticket_pending = false; // (a fast fence poll's order ticket not yet left: invalidate() waits for that section first)
|
||||
bool tex_storage = false; // (a live texture's storage in the range's pages: tex_pages_any)
|
||||
bool vw_marked = false; // (a texture the GPU wrote ever listed there)
|
||||
bool wb_marked = false; // (a write-back ever made into its pages in the game's memory)
|
||||
};
|
||||
/// true: invalidate(gpu, size) would return without waiting for anything and without work: the call may be left out
|
||||
inline bool nothing_to_wait_for(const Look& l) {
|
||||
if (!l.size) return true;
|
||||
if (l.gpu >= PageMarks::kSpan || l.size > PageMarks::kSpan - l.gpu) return false;
|
||||
return !l.ticket_pending && !l.tex_storage && !l.vw_marked && !l.wb_marked;
|
||||
}
|
||||
|
||||
} // namespace inv_quick
|
||||
} // namespace mkwvk
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <new>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
@@ -49,6 +50,36 @@ inline uint64_t bytes(const char* env, uint64_t ram_bytes) {
|
||||
/// Whether a file or data of that size is within the bound (0: none)
|
||||
inline bool within(uint64_t size, uint64_t bound) { return !bound || size <= bound; }
|
||||
|
||||
// ((Triforce, 11-18) The carry over an update. The rule of 11-14 left a file made for other shaders (an update that changed the
|
||||
// translation) unread: right for the growth, but on AMD's driver, which keeps no cache of its own for these, it meant every
|
||||
// pipeline and stage library compiled again after each such update: 87 minutes before the title on an RX 7900 XT (32 of them
|
||||
// the 14,467 noted pipelines, 53 the 88,742 stage libraries). What the update did not change still matches the old file: of
|
||||
// two caches a translator apart on the lab's PC, 39.6 % of the SPIR-V modules were the same (12.3 % of their bytes). So a file
|
||||
// for other shaders is read all the same when it is no larger than the carry limit: the driver finds again what it compiled for
|
||||
// the shaders that did not change, and the save writes old and new together for the new shaders. The limit stops the growth:
|
||||
// a fresh file is 650-860 MB, one carried and saved again is over 1536 MB, and the next update's start leaves it unread, as
|
||||
// before. RX_VK_PCACHE_CARRY_MB=<MB> sets the limit, 0: never carried (the rule of 11-14 alone))
|
||||
inline constexpr uint64_t kCarryMb = 1536;
|
||||
/// The carry limit in bytes (0: none carried). env: RX_VK_PCACHE_CARRY_MB (null or no number: the default)
|
||||
inline uint64_t carry_limit(const char* env) {
|
||||
if (env && *env) {
|
||||
char* end = nullptr;
|
||||
const unsigned long long mb = strtoull(env, &end, 10);
|
||||
if (end != env && !*end && env[0] != '-') return mb > (UINT64_MAX >> 20) ? kCarryMb << 20 : (uint64_t)mb << 20;
|
||||
}
|
||||
return kCarryMb << 20;
|
||||
}
|
||||
/// Whether a file for other shaders (not same) of size bytes is read all the same: carried over the update. And only when it
|
||||
/// leaves room under the bound (bound, 0: none) for as much again: the update's own pipelines go into the same file, and a save
|
||||
/// over the bound is not written, so a carried file that left no room would have them compiled again at every start
|
||||
/// And only on a PC with the RAM for it (ram_bytes, 0: not known, then never): the driver holds the carried data for the whole
|
||||
/// session, up to 1-1.5 GB more than a fresh file, and on 16 GB PCs that already run short of RAM (logs that say so dozens of
|
||||
/// times a session) that is paging and hitches in play. 31 GB and more: a 32 GB PC reports a little under 32
|
||||
inline constexpr uint64_t kCarryRamGb = 31;
|
||||
inline bool carried(bool same, uint64_t size, uint64_t limit, uint64_t bound, uint64_t ram_bytes) {
|
||||
return !same && limit && size > 32 && size <= limit && (!bound || size <= bound / 2) && ram_bytes >= (kCarryRamGb << 30);
|
||||
}
|
||||
|
||||
enum class Read {
|
||||
Ok,
|
||||
None, // (no such file: a first start)
|
||||
@@ -57,6 +88,7 @@ enum class Read {
|
||||
OverBound, // (longer than the bound: not a byte of it read)
|
||||
NoMemory, // (no block of its size)
|
||||
Cut, // (the read ended early: nothing of it is used)
|
||||
Foreign, // ((Triforce) its header is another GPU's or driver's: not read past it)
|
||||
};
|
||||
|
||||
inline const char* why(Read r) {
|
||||
@@ -66,13 +98,19 @@ inline const char* why(Read r) {
|
||||
case Read::OverBound: return "it is over the bound";
|
||||
case Read::NoMemory: return "there is no memory for a block of its size";
|
||||
case Read::Cut: return "reading it ended early";
|
||||
case Read::Foreign: return "it is another GPU's or driver's";
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
|
||||
/// The whole file into out, or nothing: out is empty unless the answer is Ok. *len: the file's length whenever it could be
|
||||
/// asked, read or not. least: a file of at most this many bytes is refused; bound: one longer than this too (0: none)
|
||||
inline Read read(const char* path, uint64_t least, uint64_t bound, std::vector<uint8_t>& out, uint64_t* len) {
|
||||
/// asked, read or not. least: a file of at most this many bytes is refused; bound: one longer than this too (0: none).
|
||||
/// ((Triforce) head_ok: when given, the file's first kHead bytes (a pipeline cache's header) are read alone and handed to it
|
||||
/// with the file's length; refused, the rest is not read (Foreign). The file's stamp names only the translated shaders, so
|
||||
/// after a driver update a file of 0.65-1.6 GB was read whole only for its header to be refused)
|
||||
constexpr size_t kHead = 32;
|
||||
inline Read read(const char* path, uint64_t least, uint64_t bound, std::vector<uint8_t>& out, uint64_t* len,
|
||||
bool (*head_ok)(const uint8_t* head, uint64_t size) = nullptr) {
|
||||
out.clear();
|
||||
*len = 0;
|
||||
FILE* f = fopen(path, "rb");
|
||||
@@ -90,7 +128,14 @@ inline Read read(const char* path, uint64_t least, uint64_t bound, std::vector<u
|
||||
else if ((uint64_t)n <= least) r = Read::Short;
|
||||
else if (!within((uint64_t)n, bound)) r = Read::OverBound;
|
||||
else if ((uint64_t)n > SIZE_MAX) r = Read::NoMemory;
|
||||
else {
|
||||
uint8_t head[kHead];
|
||||
size_t got = 0;
|
||||
if (r == Read::Ok && head_ok && (uint64_t)n >= kHead) {
|
||||
got = fread(head, 1, kHead, f);
|
||||
if (got != kHead) r = Read::Cut;
|
||||
else if (!head_ok(head, (uint64_t)n)) r = Read::Foreign;
|
||||
}
|
||||
if (r == Read::Ok) {
|
||||
try {
|
||||
out.resize((size_t)n);
|
||||
} catch (const std::bad_alloc&) {
|
||||
@@ -98,7 +143,7 @@ inline Read read(const char* path, uint64_t least, uint64_t bound, std::vector<u
|
||||
} catch (const std::length_error&) {
|
||||
r = Read::NoMemory;
|
||||
}
|
||||
size_t got = 0;
|
||||
if (r == Read::Ok && got) std::memcpy(out.data(), head, got);
|
||||
while (r == Read::Ok && got < out.size()) {
|
||||
const size_t piece = std::min(out.size() - got, kPiece);
|
||||
const size_t had = fread(out.data() + got, 1, piece, f);
|
||||
|
||||
237
gpu/vk/pcache_carry.h
Normal file
237
gpu/vk/pcache_carry.h
Normal file
@@ -0,0 +1,237 @@
|
||||
// (Triforce) The pipeline cache's file carried over a stamp change at an update's preparation, capped (vk_draw.cpp pcache_init,
|
||||
// pipeline_cache_save, pcache_carry_rebuild; vk_main.cpp's HOOKSHOT_PREPARE_ONLY start), apart from Vulkan so that
|
||||
// tests/test_pcache_carry.py runs its rules.
|
||||
//
|
||||
// Why. mkw_vk_pipelines.bin is kept for one stamp (program_cache_stamp, written beside it as <file>.for: the rule of 11-14).
|
||||
// Any change of the stamp threw the whole file away, and the stamp changes with every translator update, a Robust buffers
|
||||
// toggle, a vk_bank.cpp edit no translation calls (436f9ac -> int2: sampler_bias_changed). The update's preparation then built
|
||||
// the ~91,600 stage libraries and the precompiled pipelines into an empty cache: 5608 s for the warm on AMD 26.10.1 with its
|
||||
// own cache wiped, 1868 s for the precompile, where a cache that has them takes 16.4 s and 4.4 s. The driver finds an entry by
|
||||
// its own hash of the whole creation, so an entry of the old file whose shader did not change is a hit, and one whose shader
|
||||
// did is never used, never wrong.
|
||||
//
|
||||
// Why the rule of 11-14 is there all the same: growth. With the old files always read, each translator update added its
|
||||
// ~650 MB to pipelines of shaders that no longer exist, and a player's file reached 4.1 GB, "RAM short" in play. So:
|
||||
// - only at an update's preparation (HOOKSHOT_PREPARE_ONLY, Setup's "Preparing shaders"), only a file of this device and
|
||||
// driver (the header's vendor, device and pipelineCacheUUID, checked as before) within the file's bound (pcache_bound.h),
|
||||
// and only while the file is at most kCapNum/kCapDen (1.25) times its base;
|
||||
// - the base: the size of the last set built fresh, kept beside the file in <file>.base (Side) with the number of carries
|
||||
// since. A file with no side file of its own (one written before this rule, or under RX_VK_PCACHE_KEEP_OLD) is taken as
|
||||
// one fresh set: the rule of 11-14 kept it for one stamp. While a file has never been carried into, what play adds to it
|
||||
// is that set's too, and raises the base; once carried into, the base stays what it was, so the cap is the whole growth
|
||||
// over every carry since the set was built (cumulative, not a quarter more at each update);
|
||||
// - a carried session whose cache grows past what it may hold (limit: the cap, or the file's bound where that is lower, so
|
||||
// a carried cache never ends up over the bound unwritten) stops building into it as soon as that is seen (looked at every
|
||||
// kCheckMs while the preparation's workers build, and at each save; while the stage libraries are built, as soon as a
|
||||
// sample of them shows that the rate it grows at clearly takes it there: the early drop, below), does not write it, and
|
||||
// names this stamp in <file>.nocarry, so that a preparation begun again after a kill starts fresh rather than carrying the
|
||||
// same file again.
|
||||
// vk_main.cpp's preparation then builds the shaders' driver part again into a fresh cache (the compute pipelines the
|
||||
// carried run built and the stage libraries, from the program cache: nothing translated again), which is saved with a
|
||||
// new base. What the carried run compiled is in the driver's own cache by then, where the driver keeps one;
|
||||
// - a carried save writes the new stamp beside the file (unlike RX_VK_PCACHE_KEEP_OLD): it is these shaders' file now. So
|
||||
// the side file says too that the carried preparation is not done yet (Side::open): one that was stopped (Setup's Cancel,
|
||||
// the builder's stop after a long silence, a closed window) saved its merged cache under the new stamp, and the
|
||||
// preparation begun again would read it as these shaders' own file, uncapped, and build the rest of the warm into it with
|
||||
// only the bound to stop it. It is read as carried instead (resumed: capped, refused by .nocarry, built again into a fresh
|
||||
// cache past its limit), until a carried preparation goes through to its end (vk_main.cpp, pcache_carry_done). Its save
|
||||
// writes the side file before the data and the .for (begun), so that one cut between them is read so too;
|
||||
// RX_VK_PCACHE_CARRY=0: no carry, the rule of 11-14 as it was. The play file (pcache_play.h) keeps its own rule: it is
|
||||
// for one stamp, as before. A cache changes how long a pipeline takes to make, never the pipeline.
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
namespace pcache_carry {
|
||||
|
||||
inline constexpr uint64_t kCapNum = 5, kCapDen = 4; // (1.25 times the base)
|
||||
inline constexpr char kMagic[8] = {'T', 'F', 'P', 'C', 'B', 'A', 'S', 'E'};
|
||||
inline constexpr size_t kSideBytes = 40; // (magic 8, the stamp's 16 hex digits, base 8, carries 4, open 4)
|
||||
|
||||
/// RX_VK_PCACHE_CARRY: on unless set to 0
|
||||
inline bool on(const char* env) { return !env || std::atoi(env) != 0; }
|
||||
|
||||
/// The most a file of that base may hold and still be carried into, or saved by a carried session
|
||||
inline uint64_t cap(uint64_t base) {
|
||||
return base > UINT64_MAX / kCapNum ? UINT64_MAX : base * kCapNum / kCapDen;
|
||||
}
|
||||
inline bool fits(uint64_t size, uint64_t base) { return size <= cap(base); }
|
||||
/// What a carried session's cache may hold: its cap, or the file's bound (pcache_bound.h, 0: none) where that is lower. Over
|
||||
/// the bound it could not be written at all (pipeline_cache_save), and the update's preparation would end with the old file
|
||||
inline uint64_t limit(uint64_t base, uint64_t bound) {
|
||||
const uint64_t c = cap(base);
|
||||
return bound && bound < c ? bound : c;
|
||||
}
|
||||
/// How often the preparation looks at a carried cache's size while its workers build (vk_draw.cpp pcache_carry_check)
|
||||
inline constexpr unsigned kCheckMs = 10000;
|
||||
|
||||
// (Triforce, 11-18) The early drop (vk_draw.cpp warm_libraries, pcache_carry_early). Past its limit alone was seen only once it
|
||||
// got there: on an RX 7900 XT an update carried a 1973 MB file built by an older translator, nearly every stage library missed
|
||||
// (pre-raster 1.3-2.0 s each, fragment 0.18 s, as cold), and the cache reached 2469 MB of its 2467 after 2040 s and 36,906 of
|
||||
// the ~91,600 libraries (16,018 of 42,532 programs): 34 minutes built into a cache that was then let go, before the fresh build
|
||||
// began. So a carried warm builds a sample of the whole order first, and the cache's growth over it, per program of the sample,
|
||||
// times the programs of the whole order, on top of what it held when they began, is where it ends at this rate (projected);
|
||||
// clearly past its limit (drop_early), it is dropped then, as past it (pcache_carry_over, .nocarry, the rebuild into a fresh
|
||||
// cache), a few minutes in rather than half an hour.
|
||||
// - the sample: every kSampleStride-th program of the warm's order (sample_order), built before the others, which wait for its
|
||||
// projection to begin (so that the growth looked at is the sample's alone), and looked at once. Not the order's head: the
|
||||
// warm takes the programs a state list loaded and those the notes name first (9,420 of 42,532 programs, some 20,000
|
||||
// libraries), the others in the program cache's file order, so that hits and misses come in stretches of it. That run had
|
||||
// one: 12,391 libraries between 960 and 1080 s at 0.17 s a pre-raster, as hits, then 5.2 s each. A head that misses
|
||||
// while the rest hits projected 4.5 times its growth (42,532 / 9,420), past any margin: dropped, and the ~70,000 libraries
|
||||
// that would have been hits compiled cold into the fresh cache. Every 32nd of the whole order follows such stretches as
|
||||
// they lie. The sample costs nothing built (the same programs, only sooner), but the notes' programs wait for it: some
|
||||
// 1,330 programs, ~2,900 libraries, a few minutes cold, much less where they hit; and the workers idle while its last
|
||||
// programs are built;
|
||||
// - the margin: the projected growth over the warm at least kProjectNum/kProjectDen (2) times the room the cache had at its
|
||||
// start (its limit less its size then), for what the sample's libraries differ from the others in size. A carry that would
|
||||
// not fit and is not dropped early is dropped later all the same, once it is past (over); at least kProjectLibs stage
|
||||
// libraries in the sample, or none is made (a warm of under ~22,000 programs, whose cold build takes less time);
|
||||
// - the growth is counted from the cache's size when the libraries began (what prepare_run's compute pipelines added before
|
||||
// is in that size, and so out of the room). The compute pass is not projected (its programs done are translations, the
|
||||
// compute ones first, and nothing after them builds into the cache) and keeps the look past the limit alone, as do
|
||||
// precompile_run and the saves;
|
||||
// RX_VK_PCACHE_CARRY_PROJECT=0: only once past the limit, and the warm in its own order, as before
|
||||
inline constexpr uint64_t kSampleStride = 32; // (the sample: every 32nd program of the warm's order)
|
||||
inline constexpr uint64_t kProjectLibs = 1500; // (and at least so many stage libraries built for it)
|
||||
inline constexpr uint64_t kProjectNum = 2, kProjectDen = 1; // (the margin: the projected growth over the room at the start)
|
||||
|
||||
/// RX_VK_PCACHE_CARRY_PROJECT: on unless set to 0
|
||||
inline bool project_on(const char* env) { return !env || std::atoi(env) != 0; }
|
||||
|
||||
/// How many of the warm's total programs the sample takes: every kSampleStride-th, from the first
|
||||
inline uint64_t sample_count(uint64_t total) { return total / kSampleStride + (total % kSampleStride != 0); }
|
||||
/// The program of the warm's order (0 .. total-1) built at its claim c (c < total): the sample's first (c < sample_count, every
|
||||
/// kSampleStride-th, in order), then the others in their order. Every program once
|
||||
inline uint64_t sample_order(uint64_t c, uint64_t total) {
|
||||
const uint64_t m = sample_count(total);
|
||||
if (c < m) return c * kSampleStride;
|
||||
c -= m;
|
||||
return c / (kSampleStride - 1) * kSampleStride + c % (kSampleStride - 1) + 1;
|
||||
}
|
||||
|
||||
/// Where a cache of now bytes, from bytes when the warm began, ends at the rate it grew with done of total programs done (the
|
||||
/// growth per program done, times the programs left, on top of now). Nothing grown, nothing done or nothing left: now
|
||||
inline uint64_t projected(uint64_t now, uint64_t from, uint64_t done, uint64_t total) {
|
||||
if (!done || now <= from || done >= total) return now;
|
||||
const double end = (double)now + (double)(now - from) * (double)(total - done) / (double)done;
|
||||
return end >= 18446744073709549568.0 ? UINT64_MAX : (uint64_t)end;
|
||||
}
|
||||
/// Whether a carried cache is dropped now on its projection, its sample built (done of the total programs, the sample's
|
||||
/// libs stage libraries, now bytes): the sample large enough, it grew, programs are left, it had room under its limit at the
|
||||
/// warm's start (limit: the cap, or the bound where lower), and the projected growth is at least the margin times that room.
|
||||
/// Past the limit already, the growth may be under the margin: over says it
|
||||
inline bool drop_early(uint64_t now, uint64_t from, uint64_t done, uint64_t total, uint64_t libs, uint64_t limit) {
|
||||
if (libs < kProjectLibs || from >= limit || now <= from || done >= total) return false;
|
||||
const uint64_t grown = projected(now, from, done, total) - from;
|
||||
return (double)grown * (double)kProjectDen >= (double)(limit - from) * (double)kProjectNum;
|
||||
}
|
||||
|
||||
/// What <file>.base says: the stamp of the file it was written with (the .for's 16 hex digits), the base, the carries since,
|
||||
/// and whether the file was saved by a carried preparation that has not gone through to its end (open: 1; a side file of
|
||||
/// before this, whose 4 last bytes were spare and 0, is not)
|
||||
struct Side {
|
||||
char stamp[16]{};
|
||||
uint64_t base = 0;
|
||||
uint32_t carried = 0;
|
||||
uint32_t open = 0;
|
||||
};
|
||||
|
||||
inline void put(const Side& s, uint8_t out[kSideBytes]) {
|
||||
std::memset(out, 0, kSideBytes);
|
||||
std::memcpy(out, kMagic, 8);
|
||||
std::memcpy(out + 8, s.stamp, 16);
|
||||
std::memcpy(out + 24, &s.base, 8);
|
||||
std::memcpy(out + 32, &s.carried, 4);
|
||||
std::memcpy(out + 36, &s.open, 4);
|
||||
}
|
||||
/// False: not a side file (too short, another magic)
|
||||
inline bool get(const uint8_t* in, size_t n, Side* s) {
|
||||
if (n < kSideBytes || std::memcmp(in, kMagic, 8)) return false;
|
||||
std::memcpy(s->stamp, in + 8, 16);
|
||||
std::memcpy(&s->base, in + 24, 8);
|
||||
std::memcpy(&s->carried, in + 32, 4);
|
||||
std::memcpy(&s->open, in + 36, 4);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// The file's history at a start: its side file when that was written with the file's own stamp (for: the .for's 16 digits,
|
||||
/// null when there is none), else one fresh set of the file's size
|
||||
inline Side history(bool side_read, const Side& side, const char* file_for, uint64_t file_size) {
|
||||
if (side_read && file_for && !std::memcmp(side.stamp, file_for, 16) && side.base) return side;
|
||||
Side s;
|
||||
if (file_for) std::memcpy(s.stamp, file_for, 16);
|
||||
s.base = file_size;
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Whether a file for another stamp is read at this start (carried): an update's preparation, the switch on, no carry refused
|
||||
/// for these shaders already (refused: <file>.nocarry names this stamp), the file within its bound and at most cap(base) of
|
||||
/// its history. The device's header is checked after, on its bytes
|
||||
inline bool may_carry(bool on, bool preparing, bool refused, bool within_bound, uint64_t file_size, const Side& had) {
|
||||
return on && preparing && !refused && within_bound && file_size > 32 && had.base && fits(file_size, had.base);
|
||||
}
|
||||
|
||||
/// Whether a file for these shaders (same: its .for names this stamp) is read as carried all the same at this start
|
||||
/// (resumed): an update's preparation, the switch on, and its history open, saved by a carried preparation that did not go
|
||||
/// through to its end. Read with the history it has (Start::Same: no carry counted again), capped as the carried run was;
|
||||
/// refused (<file>.nocarry names this stamp: that run went past its limit), it is not read at all, and the cache starts fresh
|
||||
inline bool resumed(bool on, bool preparing, bool same, const Side& had) {
|
||||
return on && preparing && same && had.open != 0;
|
||||
}
|
||||
|
||||
/// Whether the side file says a carried session of these shaders (stamp: this stamp's 16 digits) began a save that did not
|
||||
/// get as far as the .for (file_for: its 16 digits, null when there is none): open, named for these shaders, while the .for
|
||||
/// names another stamp or none. A carried save writes the side file first, then the data, then the .for (vk_draw.cpp
|
||||
/// pipeline_cache_save), so that a save cut anywhere (a crash, a power cut, a kill in a checkpoint of warm_checkpoint.h)
|
||||
/// leaves the session's own history: the file there is the old one or the merged one, both within that session's limit.
|
||||
/// Read with that history as a file of these shaders whose carried preparation is not done (resumed), never as one fresh set
|
||||
/// of its size, uncapped
|
||||
inline bool begun(bool side_read, const Side& side, const char* stamp, const char* file_for) {
|
||||
return side_read && side.open && side.base && !std::memcmp(side.stamp, stamp, 16) &&
|
||||
(!file_for || std::memcmp(file_for, stamp, 16));
|
||||
}
|
||||
|
||||
/// ((Triforce, 11-19) Whether v0.5.2's carry outside Setup's preparation (pcache_bound.h carried: a file for other shaders
|
||||
/// read whole by its size and the PC's RAM) is asked at all: not at the preparation (may_carry's), not for a file read as
|
||||
/// carried or resumed already, not when a carry was refused for these shaders (refused: <file>.nocarry names them. So
|
||||
/// warm_libraries leaves a file it dropped for what it held that nothing asks for, its .for gone: read again, its cache would
|
||||
/// be over the bound again and not written, and the stage libraries compiled at their first draw every session), and not for
|
||||
/// a carried preparation's save cut short (begun: its own capped history, read as resumed)
|
||||
inline bool plain_carry(bool preparing, bool carried, bool resumed, bool refused, bool begun) {
|
||||
return !preparing && !carried && !resumed && !refused && !begun;
|
||||
}
|
||||
|
||||
/// The session's history from the start: fresh (nothing read), the file's own (read for these shaders), or one carry more
|
||||
/// (read across a stamp change: open until its preparation goes through to its end)
|
||||
enum class Start { Fresh, Same, Carried };
|
||||
inline Side session(Start how, const Side& had) {
|
||||
Side s;
|
||||
if (how == Start::Fresh) return s;
|
||||
s = had;
|
||||
if (how == Start::Carried) s.carried = had.carried + 1, s.open = 1;
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Whether a session's cache of size bytes is past what it may hold: a carried session's over its limit (the cap, or the bound
|
||||
/// where lower). The others never (the bound alone, as before: pipeline_cache_save)
|
||||
inline bool over(bool carried_session, uint64_t size, const Side& s, uint64_t bound) {
|
||||
return carried_session && size > limit(s.base, bound);
|
||||
}
|
||||
/// Whether a save of size bytes is written as far as the carry goes: not when it is over
|
||||
inline bool save_ok(bool carried_session, uint64_t size, const Side& s, uint64_t bound) {
|
||||
return !over(carried_session, size, s, bound);
|
||||
}
|
||||
|
||||
/// The history once size bytes are saved under stamp: a file never carried into is one set, so its base follows it (the
|
||||
/// largest saved); one carried into keeps its base. Open stays as the session has it
|
||||
inline Side saved(const Side& s, uint64_t size, const char* stamp) {
|
||||
Side n = s;
|
||||
std::memcpy(n.stamp, stamp, 16);
|
||||
if (!n.carried && size > n.base) n.base = size;
|
||||
return n;
|
||||
}
|
||||
|
||||
} // namespace pcache_carry
|
||||
107
gpu/vk/pcache_libs.h
Normal file
107
gpu/vk/pcache_libs.h
Normal file
@@ -0,0 +1,107 @@
|
||||
// A pipeline cache file of stage libraries and compute pipelines alone, on NVIDIA PCs of little RAM (no game, no GPU: the
|
||||
// rule, the driver's cache folder and its size, the record; vk_draw.cpp pcache_libs_decide, pcache_init, build_graphics,
|
||||
// pcache_play_open). Apart from Vulkan so that tests/test_pcache_libs.py runs it on many made-up PCs.
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's PIPE-78, after Source A's and Source B's.) mkw_vk_pipelines.bin is read whole at
|
||||
// every start and held by the driver all session: about 650 MB fresh, 1.1 to 1.6 GB with the play's pipelines on a 16 GB PC
|
||||
// (pcache_bound.h), where paging is what hitches. Source A leaves its file unread on NVIDIA's own driver with 20 GB of RAM or
|
||||
// less and 512 MB or more in the driver's own disk cache (GLCache), whole pipelines then coming from that cache: on a 16 GB
|
||||
// RTX 3070 Ti, peak memory 12,481 -> 12,029 and 12,638 -> 11,822 MB over a tour, fps 54.3 -> 54.6, a pipeline's load 1.9 ->
|
||||
// 5.0 ms. Triforce cannot drop the file: a stage library asked under the compile-required flag must be in the cache it hands
|
||||
// the driver (21 of 21 cold otherwise). So the file keeps the libraries and the compute pipelines, and only whole graphics
|
||||
// pipelines are left to the driver's cache, with no play file.
|
||||
//
|
||||
// Decided only when a fresh file begins (none read for these shaders), and kept in <file>.lean ("lean <stamp>") for that
|
||||
// file's life: a full file stays full and a lean one lean until the next fresh one. Not in a start that only prepares.
|
||||
//
|
||||
// RX_VK_PCACHE_LIBS_ONLY: unset or 0, off (every pipeline in the file, as before); 1, by the rule; 2, at every fresh file
|
||||
// whatever the PC (the lab's and the tests'). Off by default: the driver's cache is shared and capped, and on a 32 GB PC
|
||||
// Source A measured p99 17.23 -> 18.58 ms.
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
|
||||
namespace pcache_libs {
|
||||
|
||||
inline constexpr uint64_t kRamMost = 20ull << 30; // (20 GB of RAM or less)
|
||||
inline constexpr uint64_t kGlCacheLeast = 512ull << 20; // (512 MB or more in the driver's own cache)
|
||||
|
||||
/// RX_VK_PCACHE_LIBS_ONLY: 0 off (unset too), 1 by the rule, 2 forced
|
||||
inline int mode(const char* env) {
|
||||
if (!env || !*env) return 0;
|
||||
const int v = std::atoi(env);
|
||||
return v <= 0 ? 0 : v >= 2 ? 2 : 1;
|
||||
}
|
||||
|
||||
struct Pc {
|
||||
bool nvidia_proprietary = false; // (VK_DRIVER_ID_NVIDIA_PROPRIETARY)
|
||||
uint64_t ram = 0; // (the PC's RAM, bytes; 0 unknown)
|
||||
uint64_t glcache = 0; // (bytes in the driver's own cache folder)
|
||||
bool gpl = false; // (the stage libraries are wanted and kept in our cache: gpl_wanted, gpl_libs_cached)
|
||||
bool prepare_only = false; // (a start that only prepares)
|
||||
};
|
||||
/// Whether the fresh file is a lean one
|
||||
inline bool choose(int mode, const Pc& pc) {
|
||||
if (mode <= 0 || pc.prepare_only) return false;
|
||||
if (mode >= 2) return true;
|
||||
return pc.nvidia_proprietary && pc.gpl && pc.ram && pc.ram <= kRamMost && pc.glcache >= kGlCacheLeast;
|
||||
}
|
||||
|
||||
/// The folder NVIDIA's driver keeps its Vulkan and OpenGL cache in: on Windows <LOCALAPPDATA>\NVIDIA\GLCache; elsewhere
|
||||
/// __GL_SHADER_DISK_CACHE_PATH, else <XDG_CACHE_HOME>/nvidia/GLCache, else <HOME>/.cache/nvidia/GLCache. Empty: unknown
|
||||
inline std::string nvidia_cache_dir(bool windows, const char* localappdata, const char* gl_path, const char* xdg, const char* home) {
|
||||
if (windows) return localappdata && *localappdata ? std::string(localappdata) + "\\NVIDIA\\GLCache" : std::string();
|
||||
if (gl_path && *gl_path) return gl_path;
|
||||
if (xdg && *xdg) return std::string(xdg) + "/nvidia/GLCache";
|
||||
if (home && *home) return std::string(home) + "/.cache/nvidia/GLCache";
|
||||
return {};
|
||||
}
|
||||
/// The bytes of the files under a folder, at most most_entries looked at (a folder that is not there: 0)
|
||||
inline uint64_t folder_bytes(const std::string& dir, size_t most_entries = 200000) {
|
||||
uint64_t sum = 0;
|
||||
if (dir.empty()) return 0;
|
||||
std::error_code ec;
|
||||
const std::filesystem::path root(std::u8string(reinterpret_cast<const char8_t*>(dir.data()), dir.size())); // (UTF-8)
|
||||
std::filesystem::recursive_directory_iterator it(root, std::filesystem::directory_options::skip_permission_denied, ec);
|
||||
for (size_t n = 0; !ec && it != std::filesystem::recursive_directory_iterator() && n < most_entries; it.increment(ec), n++) {
|
||||
std::error_code e2;
|
||||
if (it->is_regular_file(e2)) {
|
||||
const uint64_t s = it->file_size(e2);
|
||||
if (!e2) sum += s;
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
// ---- <file>.lean: "lean <stamp>"
|
||||
|
||||
inline bool lean_read(const std::string& path, const char* stamp16) {
|
||||
FILE* f = fopen(path.c_str(), "rb");
|
||||
if (!f) return false;
|
||||
char line[40]{};
|
||||
const size_t n = fread(line, 1, sizeof line - 1, f);
|
||||
fclose(f);
|
||||
line[n] = 0;
|
||||
return n >= 21 && !memcmp(line, "lean ", 5) && !memcmp(line + 5, stamp16, 16);
|
||||
}
|
||||
inline bool lean_write(const std::string& path, const char* stamp16) {
|
||||
FILE* f = fopen(path.c_str(), "wb");
|
||||
if (!f) return false;
|
||||
const bool ok = fprintf(f, "lean %.16s\n", stamp16) > 0;
|
||||
return fclose(f) == 0 && ok;
|
||||
}
|
||||
|
||||
/// What a start does: fresh (no file read for these shaders), whether the rule says lean now, and the record of the file
|
||||
/// read. Lean for the session: a fresh file the rule makes lean, or a file read whose record says lean (and the switch on)
|
||||
inline bool lean_now(int mode, bool fresh, bool chose, bool recorded) {
|
||||
if (mode <= 0) return false;
|
||||
return fresh ? chose : recorded;
|
||||
}
|
||||
|
||||
} // namespace pcache_libs
|
||||
@@ -22,6 +22,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace pcache_play {
|
||||
|
||||
@@ -33,6 +34,13 @@ inline bool routes(bool main_cache, bool play_cache, bool preparing) {
|
||||
return main_cache && play_cache && !preparing;
|
||||
}
|
||||
|
||||
/// ((Triforce, 11-22, the performance audit's PIPE-95, after Source A's) RX_VK_PCACHE_OWN_PASSES: whether the back end's own
|
||||
/// compute passes (FSR 3.1's, the anti-aliasing's, the texture converters': vk_draw.cpp shared_cache_compute) are made
|
||||
/// through the play cache as the game's are, on unless set to 0 (0: bare into the main cache, as before)
|
||||
inline bool own_passes(const char* env) {
|
||||
return !env || std::atoi(env) != 0;
|
||||
}
|
||||
|
||||
/// At the start, the play file read: whether it is folded into the main cache now (fold_bytes 0: never)
|
||||
inline bool fold_due(uint64_t play_bytes, uint64_t fold_bytes) {
|
||||
return fold_bytes && play_bytes >= fold_bytes;
|
||||
|
||||
62
gpu/vk/piece_idle.h
Normal file
62
gpu/vk/piece_idle.h
Normal file
@@ -0,0 +1,62 @@
|
||||
// (Triforce, 11-22, the performance audit's MEM-26, its first step, after Source A's) What a mirror in pieces holds that
|
||||
// no game pool covers any more, and how much of that no binding has reached for a while: counted, nothing released.
|
||||
//
|
||||
// A mirror in pieces gives a piece its memory when a binding first reaches it, and keeps it until the whole mirror goes.
|
||||
// The mirror is an import's (a chunk of guest memory around what was bound), and the game's pools inside it come and go:
|
||||
// a long-lived import keeps the memory of every piece any area reached, also where no game pool is left. Source A gives
|
||||
// such memory back after two waits of 600 submissions. Before that is ported (the unbind and the free must wait for the
|
||||
// GPU and for the bind timeline: memory freed under a compute pass that reads it lost devices before) this counts what
|
||||
// it would find, every 1200 submissions, in the "mirrors in pieces" line: under about 100 MB at the end of a tour on a
|
||||
// 6 GB card, the release is not worth having.
|
||||
//
|
||||
// Counted by piece. A release frees whole runs of pieces (one allocation a run), so this is the most it could give back.
|
||||
// The rule alone, no Vulkan: tests/test_mirror_piece_idle.py compiles it against a page-by-page model.
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace piece_idle {
|
||||
|
||||
using Ranges = std::vector<std::pair<uint64_t, uint64_t>>; // ([first, second))
|
||||
|
||||
/// The ranges sorted and merged: disjoint, ascending, none empty (touching ones joined)
|
||||
inline void merge(Ranges& r) {
|
||||
std::sort(r.begin(), r.end());
|
||||
size_t m = 0;
|
||||
for (const auto& e : r) {
|
||||
if (e.second <= e.first) continue;
|
||||
if (m && e.first <= r[m - 1].second) r[m - 1].second = std::max(r[m - 1].second, e.second);
|
||||
else r[m++] = e;
|
||||
}
|
||||
r.resize(m);
|
||||
}
|
||||
|
||||
struct Count {
|
||||
uint64_t held = 0; // (bytes of the pieces that have memory)
|
||||
uint64_t uncovered = 0; // (of them, the pieces no game pool touches)
|
||||
uint64_t idle = 0; // (of those, the ones no binding reached for idle_for submissions; 0 when that is not tracked)
|
||||
};
|
||||
|
||||
/// A mirror at guest address lo of `size` bytes, in pieces of 1 << shift bytes: resident(i) says piece i has memory,
|
||||
/// last(i) the submission a binding last reached it at. pools: the game's pools, merged (merge above). now: this
|
||||
/// submission; idle_for: 0, or how many submissions without a binding make a piece idle. Adds to out
|
||||
template <class Resident, class Last>
|
||||
inline void count(uint64_t lo, uint64_t size, uint32_t shift, const Resident& resident, const Last& last, const Ranges& pools, uint64_t now,
|
||||
uint64_t idle_for, Count& out) {
|
||||
const uint64_t piece = 1ull << shift, n = (size + piece - 1) >> shift;
|
||||
size_t at = 0; // (the first pool that ends after the piece's start: the pieces come ascending)
|
||||
for (uint64_t i = 0; i < n; i++) {
|
||||
if (!resident(i)) continue;
|
||||
const uint64_t a = lo + (i << shift), b = lo + std::min(size, (i + 1) << shift);
|
||||
out.held += b - a;
|
||||
while (at < pools.size() && pools[at].second <= a) at++;
|
||||
if (at < pools.size() && pools[at].first < b) continue; // (a game pool touches it)
|
||||
out.uncovered += b - a;
|
||||
if (idle_for && now - last(i) >= idle_for) out.idle += b - a;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace piece_idle
|
||||
48
gpu/vk/pipe_ahead.h
Normal file
48
gpu/vk/pipe_ahead.h
Normal file
@@ -0,0 +1,48 @@
|
||||
// Where the pipelines the draws first need stand in the last sessions' order, against where the draws are (no game, no GPU:
|
||||
// the rules; vk_draw.cpp order_met, graphics_pipeline, draw_left_out_take). Apart from Vulkan so that tests/test_pipe_ahead.py
|
||||
// runs them.
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's PIPE-81, after Source B's: its first step.) Where the precompile keeps no
|
||||
// pipelines (light mode: precompile_keeps_all), every pipeline of a load is new at its first draw: linked there from its
|
||||
// stage libraries, or by the warm a moment earlier (pipe_warm.h, pipe_order.h). The entry proposes building whole pipelines
|
||||
// just ahead of the draws on light frames, from the order's next places, and keeping them; and it says to count first:
|
||||
// each pipeline first drawn, its place ahead of where the draws are (pipe_order.h Front) or none, and whether the warm had
|
||||
// linked it. Under a third within the window: stop, the builder is not worth its RAM and its compiles.
|
||||
//
|
||||
// This is that count, and only it: nothing is built or kept. A line every 600 presents while it grows (with the order used):
|
||||
// within the window ahead, further ahead, behind, not in the order, and how many of those within the window the warm had
|
||||
// linked; and whether the builder would be worth it by the entry's rule.
|
||||
//
|
||||
// RX_VK_PIPE_AHEAD=<places>: the window, 1024 unset (1 to 4096); 0: not counted.
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace pipe_ahead {
|
||||
|
||||
inline constexpr int64_t kWindow = 1024;
|
||||
inline constexpr int64_t kMost = 4096;
|
||||
|
||||
/// RX_VK_PIPE_AHEAD: the window in places, kWindow unset; 0 off; clamped to 1..kMost
|
||||
inline int64_t window(const char* env) {
|
||||
if (!env || !*env) return kWindow;
|
||||
const long long v = std::atoll(env);
|
||||
return v <= 0 ? 0 : v > kMost ? kMost : (int64_t)v;
|
||||
}
|
||||
|
||||
enum class Where { None, Near, Far, Behind };
|
||||
/// A pipeline first drawn at place in the order (-1: not in it), the draws at front (Front::furthest; -1: not yet placed,
|
||||
/// counted from the order's start)
|
||||
inline Where where(int64_t place, int64_t front, int64_t window_places) {
|
||||
if (place < 0) return Where::None;
|
||||
const int64_t from = front < 0 ? 0 : front;
|
||||
if (place < from) return Where::Behind;
|
||||
return place - from <= window_places ? Where::Near : Where::Far;
|
||||
}
|
||||
/// The entry's rule for the builder: worth it when a third or more of the pipelines first drawn were within the window
|
||||
inline bool worth(int64_t within, int64_t all) {
|
||||
return all > 0 && within * 3 >= all;
|
||||
}
|
||||
|
||||
} // namespace pipe_ahead
|
||||
@@ -32,6 +32,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
#include <deque>
|
||||
#include <iterator>
|
||||
@@ -45,7 +46,11 @@
|
||||
|
||||
namespace mkwvk::pipe_order {
|
||||
|
||||
constexpr size_t kKeysMax = program_order::kKeysMax; // (pipelines a session's order keeps, and the file)
|
||||
// ((Triforce, 11-21) 16384, was the programs' 4096: one ten-area tour needs 3918 pipelines, so an adult tour pushed half of the
|
||||
// child tour's out and its next tour linked 828 of 2274 ahead where it had linked 1455 of 2012 (pipeline stalls 1.3 -> 2.6 s,
|
||||
// the worst 174 -> 464 ms). The file only: what the warm holds stays bounded by kLinksMax and kLibsMax below, and the programs'
|
||||
// read-ahead (its RAM) by program_order's own 4096. 8 bytes a pipeline: 128 KB at most)
|
||||
constexpr size_t kKeysMax = 16384; // (pipelines a session's order keeps, and the file)
|
||||
constexpr size_t kPerVariant = 32; // (the order's pipelines made for a program variant, at most: as the notes')
|
||||
constexpr size_t kLinksMax = 1024; // (links held for draws that have not come: a load's, beside the title's taken)
|
||||
constexpr size_t kLibsMax = 2048; // (stage libraries the warm made that no draw has had: two a program variant of 1024)
|
||||
@@ -58,9 +63,13 @@ inline bool on(const char* env) { return !(env && env[0] == '0' && !env[1]); }
|
||||
|
||||
/// The file: program_order.h's form, its own magic
|
||||
inline std::vector<uint8_t> write(const std::vector<uint64_t>& keys) { return program_order::write(keys, kMagic); }
|
||||
inline std::vector<uint64_t> read(const uint8_t* data, size_t n) { return program_order::read(data, n, kMagic); }
|
||||
using program_order::merge;
|
||||
using Record = program_order::Record;
|
||||
inline std::vector<uint64_t> read(const uint8_t* data, size_t n) { return program_order::read(data, n, kMagic, kKeysMax); }
|
||||
inline std::vector<uint64_t> merge(const std::vector<uint64_t>& now, const std::vector<uint64_t>& before, size_t max = kKeysMax) {
|
||||
return program_order::merge(now, before, max);
|
||||
}
|
||||
struct Record : program_order::Record {
|
||||
Record() { max = kKeysMax; }
|
||||
};
|
||||
|
||||
/// One pipeline of the order: its place, its note's record in the notes file
|
||||
struct Entry {
|
||||
@@ -154,12 +163,19 @@ public:
|
||||
by_place_.emplace(std::make_pair(place, key), o);
|
||||
place_of_.emplace(key, place);
|
||||
while (by_place_.size() > max_) {
|
||||
const auto last = std::prev(by_place_.end());
|
||||
gone.push_back(last->second);
|
||||
place_of_.erase(last->first.second);
|
||||
by_place_.erase(last);
|
||||
// ((Triforce, 11-21, soft) one behind the draws first (the farthest behind), then the farthest ahead as before
|
||||
const bool back = soft_ && by_place_.begin()->first.first < behind_at_;
|
||||
const auto out = back ? by_place_.begin() : std::prev(by_place_.end());
|
||||
gone.push_back(out->second);
|
||||
place_of_.erase(out->first.second);
|
||||
by_place_.erase(out);
|
||||
}
|
||||
}
|
||||
/// ((Triforce, 11-21) RX_VK_ORDER_SOFT_BEHIND) Soft: behind() lets nothing go, it marks where behind begins; those held there
|
||||
/// stay for a draw that comes back to them (a tour's shared pipelines sit in another session's region of the merged order,
|
||||
/// and the draws went back and forth: 1265 of 3048 links let go as behind in a child tour after an adult one) and go first
|
||||
/// when a new link needs the room. The bound (max) is the same
|
||||
void soft(bool on) { soft_ = on; }
|
||||
/// The link held for key, taken out (a draw's from now on): false when none is
|
||||
bool take(uint64_t key, One& out) {
|
||||
const auto it = place_of_.find(key);
|
||||
@@ -172,6 +188,10 @@ public:
|
||||
}
|
||||
/// Those placed before at, taken out into gone
|
||||
void behind(int64_t at, std::vector<One>& gone) {
|
||||
if (soft_) {
|
||||
behind_at_ = std::max(behind_at_, at);
|
||||
return;
|
||||
}
|
||||
const auto end = by_place_.lower_bound({at, 0});
|
||||
for (auto it = by_place_.begin(); it != end;) {
|
||||
gone.push_back(it->second);
|
||||
@@ -193,7 +213,8 @@ public:
|
||||
}
|
||||
/// Whether a link at place would stay held: room left, or nearer than the farthest held (made, not let go at once)
|
||||
bool room(int64_t place) const {
|
||||
return by_place_.size() < max_ || (!by_place_.empty() && place < std::prev(by_place_.end())->first.first);
|
||||
return by_place_.size() < max_ || (!by_place_.empty() && place < std::prev(by_place_.end())->first.first) ||
|
||||
(soft_ && !by_place_.empty() && by_place_.begin()->first.first < behind_at_);
|
||||
}
|
||||
/// Whether a link held was linked from library lib
|
||||
bool uses(uint64_t lib) const {
|
||||
@@ -216,6 +237,8 @@ private:
|
||||
return false;
|
||||
}
|
||||
size_t max_;
|
||||
bool soft_ = false;
|
||||
int64_t behind_at_ = INT64_MIN;
|
||||
std::map<std::pair<int64_t, uint64_t>, One> by_place_; // ((place, key): the nearest first)
|
||||
std::unordered_map<uint64_t, int64_t> place_of_;
|
||||
};
|
||||
|
||||
@@ -39,6 +39,13 @@
|
||||
// libraries after it, so the draws of such a pipeline waited for the whole build. The same objects are made either way.
|
||||
// A draw that waits runs the first job itself (vk_jobs.cpp jobs_wait): the libraries and the link, not the whole build.
|
||||
// RX_VK_PIPE_FAST_WORKERS=0: the whole build first, as before.
|
||||
// - choose(), depth_new ((Triforce, 11-22, the performance audit's PIPE-29, after Source B's): a depth-tested draw into a
|
||||
// pass drawn once whose shaders write no memory, outside a samples-passed count and the item icon capture's kept targets):
|
||||
// from the frame's wait pool, then left out, and a pipeline that ran out of time is left out at once until it is built
|
||||
// (vk_draw.cpp). Source B froze 11-13 s twice on an Arc B580 compiling some fifty new pipelines for such passes, and made
|
||||
// them wait at most 50 ms a frame. RX_VK_PIPE_DEPTH_BUDGET=1; off by default on every driver, Intel's too, where the
|
||||
// entry would have it on: a render into a new depth target that is left out can stay missing until it is drawn again,
|
||||
// and that trade is the owner's to make (depth_budget).
|
||||
// A wait from a budget is vk_jobs.cpp jobs_wait_for: the pipeline's job goes to the front of the queue, and is not run on the
|
||||
// draw's thread (a compile there would outlast the bound).
|
||||
#pragma once
|
||||
@@ -46,6 +53,7 @@
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
namespace pipe_wait {
|
||||
|
||||
@@ -139,7 +147,12 @@ private:
|
||||
// ---- the draw's choice
|
||||
|
||||
enum class Act { Skip, Wait, WaitAll };
|
||||
enum Kind { K_NONE, K_ONESHOT, K_FULL, K_LAST };
|
||||
enum Kind { K_NONE, K_ONESHOT, K_FULL, K_LAST, K_DEPTH };
|
||||
|
||||
/// ((Triforce, 11-22, PIPE-29) RX_VK_PIPE_DEPTH_BUDGET: on when set to anything but 0; unset, off on every driver)
|
||||
inline bool depth_budget(const char* env) {
|
||||
return env && *env && std::atoi(env) != 0;
|
||||
}
|
||||
|
||||
struct Rules {
|
||||
bool always_wait = false; // (RX_VK_PIPE_SKIP=0: every pipeline waited for)
|
||||
@@ -155,9 +168,16 @@ struct Choice {
|
||||
|
||||
/// A draw whose pipeline is not ready. kept: its pass (kept()); writes: its shaders write memory; full: full_screen(); held:
|
||||
/// the hold of the last picture would take this frame if it lacks a draw (present_hold.h DEFERS, the pipelines counted);
|
||||
/// pool_ns, last_ns: what the frame's wait pool and its last wait have left
|
||||
inline Choice choose(const Rules& r, bool kept, bool writes, bool full, bool held, int64_t pool_ns, int64_t last_ns) {
|
||||
/// pool_ns, last_ns: what the frame's wait pool and its last wait have left. depth_new ((Triforce, 11-22, PIPE-29)
|
||||
/// RX_VK_PIPE_DEPTH_BUDGET, the caller's: a depth-tested draw into a pass drawn once whose shaders write no memory): from the
|
||||
/// pool, then left out
|
||||
inline Choice choose(const Rules& r, bool kept, bool writes, bool full, bool held, int64_t pool_ns, int64_t last_ns,
|
||||
bool depth_new = false) {
|
||||
if (r.always_wait) return {Act::WaitAll, 0, K_NONE};
|
||||
if (!kept && !writes && depth_new) {
|
||||
if (pool_ns >= kMinWaitNs) return {Act::Wait, pool_ns, K_DEPTH};
|
||||
return {Act::Skip, 0, K_NONE};
|
||||
}
|
||||
if (!kept || writes) {
|
||||
if (!r.oneshot_budget) return {Act::WaitAll, 0, K_NONE};
|
||||
if (pool_ns >= kMinWaitNs) return {Act::Wait, pool_ns, K_ONESHOT};
|
||||
|
||||
92
gpu/vk/precompile_save.h
Normal file
92
gpu/vk/precompile_save.h
Normal file
@@ -0,0 +1,92 @@
|
||||
// The pipeline cache saved before the title after a long precompile, and after a preparation without stage libraries
|
||||
// (no game, no GPU: a rule; vk_draw.cpp precompile_run, prepare_run, prepare_compute_pipeline, pipeline_cache_save).
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's PIPE-23, after Source A's.) A precompile that keeps every pipeline (enough
|
||||
// RAM: precompile_keeps_all) ended without a save: what it compiled was first written in play, at present 300 and only
|
||||
// after 32 more builds, and on Intel only at a clean close. A crash, a kill or a power cut before that cost the whole
|
||||
// build again at the next start, minutes of it when the driver's own cache did not have them either. Source A wrote its
|
||||
// cache before the title once the precompile had built for 30 s or more (after a 1,454 s compile on a handheld: 439 MB
|
||||
// in 821 ms, and the next start's precompile took 13 s).
|
||||
//
|
||||
// Here the same, with two differences that are this project's:
|
||||
// - the save is the play file's alone while there is a play cache (pcache_play.h): the precompile's compiles went into
|
||||
// it. The main cache's hits count as builds too (cached_create), and on NVIDIA the main cache grows by the driver's
|
||||
// copies, so an ordinary forced save would write the whole main file, 2 to 3 GB, before the title. With no play
|
||||
// cache (a start that folded the play file, or no pipelineCreationCacheControl) the main file is what there is, and
|
||||
// it is saved;
|
||||
// - not where something else saves or the workers still build: a precompile the game went on from (its workers build
|
||||
// behind the game: no fetch while they do, Intel's driver crashed there), a stopped one (the stop's own save), a
|
||||
// start that only prepares (its end saves), and the light precompile (it saves before its record, as before).
|
||||
//
|
||||
// The second gap: a preparation without stage libraries compiled its compute pipelines into the main cache, counted
|
||||
// them nowhere the save looks (pcache_main_built) and ended without a save, where the one with libraries saves after
|
||||
// them (warm_libraries). Now they are counted, and that preparation saves before its record says it is made.
|
||||
//
|
||||
// RX_VK_PRECOMPILE_SAVE_S=<seconds>: the build time from which the precompile's end saves, 30 by default, at most a day;
|
||||
// 0: never, and the preparation's count and save are off too, all as before.
|
||||
#pragma once
|
||||
#include <cstdlib>
|
||||
|
||||
namespace mkwvk::precompile_save {
|
||||
|
||||
inline constexpr int kAfterS = 30; // Source A's
|
||||
inline constexpr int kMostS = 86400;
|
||||
|
||||
/// RX_VK_PRECOMPILE_SAVE_S: the seconds of building from which the precompile's end saves (0: never)
|
||||
inline int after_s(const char* env) {
|
||||
if (!env || !*env) return kAfterS;
|
||||
const long v = std::atol(env);
|
||||
return v <= 0 ? 0 : v > kMostS ? kMostS : (int)v;
|
||||
}
|
||||
|
||||
/// Whether the rule is on at all (the preparation's count and its save go by this too)
|
||||
constexpr bool on(int save_s) {
|
||||
return save_s > 0;
|
||||
}
|
||||
|
||||
/// Whether a precompile that built for build_s seconds is a long one: only those say anything
|
||||
constexpr bool long_build(double build_s, int save_s) {
|
||||
return save_s > 0 && build_s >= (double)save_s;
|
||||
}
|
||||
|
||||
/// Whether the keep-all precompile's end saves now. gone_on: the game went on while workers still build; stopped: a stop
|
||||
/// was asked; prepare_only: a start that only prepares
|
||||
constexpr bool due(double build_s, int save_s, bool gone_on, bool stopped, bool prepare_only) {
|
||||
return long_build(build_s, save_s) && !gone_on && !stopped && !prepare_only;
|
||||
}
|
||||
|
||||
enum class Outcome {
|
||||
Saved, // (written: the line gives its size and time)
|
||||
Nothing, // (the cache holds nothing its files lack)
|
||||
GoneOn,
|
||||
Stopped,
|
||||
PrepareOnly,
|
||||
NoCache, // (no pipeline cache this session)
|
||||
};
|
||||
|
||||
/// Why a long precompile's end does not save (only asked when due() said no, or with no cache)
|
||||
constexpr Outcome why_not(bool gone_on, bool stopped, bool prepare_only, bool cache) {
|
||||
return !cache ? Outcome::NoCache : stopped ? Outcome::Stopped : gone_on ? Outcome::GoneOn :
|
||||
prepare_only ? Outcome::PrepareOnly : Outcome::Nothing;
|
||||
}
|
||||
|
||||
/// The log line's words after "vk: precompile: N s of building: "
|
||||
constexpr const char* said(Outcome o) {
|
||||
switch (o) {
|
||||
case Outcome::Saved: return "the pipeline cache saved before the title";
|
||||
case Outcome::Nothing: return "the pipeline cache holds nothing new to save before the title";
|
||||
case Outcome::GoneOn: return "the pipeline cache is not saved before the title: the game went on and the workers still build";
|
||||
case Outcome::Stopped: return "the pipeline cache is not saved here: the stop's own save writes it";
|
||||
case Outcome::PrepareOnly: return "the pipeline cache is not saved here: this start only prepares and saves at its end";
|
||||
case Outcome::NoCache: return "there is no pipeline cache to save";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/// Whether a preparation without stage libraries saves the cache before its record is written: the rule on, not behind
|
||||
/// the game, and compute pipelines built into the main cache
|
||||
constexpr bool prepare_saves(int save_s, bool libraries_warmed, bool background, unsigned long long computes_built) {
|
||||
return on(save_s) && !libraries_warmed && !background && computes_built > 0;
|
||||
}
|
||||
|
||||
} // namespace mkwvk::precompile_save
|
||||
211
gpu/vk/predict_check.h
Normal file
211
gpu/vk/predict_check.h
Normal file
@@ -0,0 +1,211 @@
|
||||
// Whether the driver still has the predicted pipelines, at a start whose record says they were all built (no game, no
|
||||
// GPU: the rules; vk_draw.cpp predict_check_cold, predict_background, predicted_play_build). After lib_check.h, which
|
||||
// asks the same of the stage libraries.
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's PIPE-68, after Source B's and Source A's.) The predicted pipelines (the ones
|
||||
// the notes predict for programs no note names) are built once for the driver's own cache and let go, and a record
|
||||
// (<notes>.predicted) says which programs are done; once it says all, no start looks again. But the driver's cache is
|
||||
// the driver's: NVIDIA's has a size cap, AMD's Windows driver kept 30 to 44% of what Source B had prepared, and a cache
|
||||
// folder can be cleared. Source B found 105 dispatches waiting 115 s in all on prepared pipelines the driver had dropped,
|
||||
// while its record still said built. Then each of those programs' first draw compiles in play: the freezes on arrival
|
||||
// the prediction is there to take away.
|
||||
//
|
||||
// The check. At a start whose record says all built, on the builder's idle thread after its delay and, as the builder,
|
||||
// only while the frame shown is a light one: up to kSample predicted pipelines from the plan, spread over it from
|
||||
// another place each start, each built for the driver's cache alone and timed, then built once more at once. The second
|
||||
// comes from the driver's memory by construction, so it is this driver's warm time on this PC and no fixed time is
|
||||
// needed: a first build over kRatio times the second and kSlackMs more was compiled. Not asked with
|
||||
// FAIL_ON_PIPELINE_COMPILE_REQUIRED: under that flag a driver answers only from the cache it is handed, and these are in
|
||||
// none of ours. The sample ends once its majority is decided.
|
||||
//
|
||||
// Cold (more than half of a sample): the record is removed, so the builder builds them all again behind the game at
|
||||
// light frames, this session and the next, and <notes>.predicted.check takes a strike for this stamp. Cold again at a
|
||||
// start after they were built again: this driver does not keep them. That is said once and recorded, and no later start
|
||||
// checks for this stamp (the compiles of the check itself are not free), so the pipelines are left to their first draw
|
||||
// as before the prediction. Warm: the strike is forgotten. Another stamp (a new driver, new shaders) begins anew.
|
||||
//
|
||||
// The counter, for what the check is worth: builds in play of programs the plan predicts that took over 20 ms, which a
|
||||
// driver that had them does not need. Logged at most every 10 s while it grows.
|
||||
//
|
||||
// RX_VK_PREDICT_CHECK: 1 by default; 0: no check and no counter, as before; 2: checked at every start, a recorded
|
||||
// "does not keep them" too (the lab's).
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace predict_check {
|
||||
|
||||
inline constexpr int kSample = 12; // (pipelines sampled, as lib_check's)
|
||||
inline constexpr int kLook = 2 * kSample; // (plan entries looked at for them: one may have lost its notes or its program)
|
||||
inline constexpr double kRatio = 4.0; // (the first build against the second: compiled above)
|
||||
inline constexpr double kSlackMs = 3.0; // (and this much more: lookups of a few milliseconds say nothing)
|
||||
inline constexpr int kStrikes = 1; // (the record removed once; cold again after that: stop)
|
||||
inline constexpr int64_t kSlowUs = 20000; // (a play build of a predicted program over this was compiled)
|
||||
inline constexpr int64_t kSayMs = 10000; // (the counter's line: at most this often)
|
||||
|
||||
/// RX_VK_PREDICT_CHECK: 0 off, 1 on (unset too), 2 every start
|
||||
inline int mode(const char* env) {
|
||||
if (!env || !*env) return 1;
|
||||
const int v = std::atoi(env);
|
||||
return v <= 0 ? 0 : v >= 2 ? 2 : 1;
|
||||
}
|
||||
|
||||
/// One pipeline sampled: made both times, and what each took (ms). One the driver refuses says nothing of its cache
|
||||
struct Probe {
|
||||
bool made = false;
|
||||
double first_ms = 0, again_ms = 0;
|
||||
};
|
||||
inline bool cold(const Probe& p) {
|
||||
return p.made && p.first_ms > kRatio * p.again_ms + kSlackMs;
|
||||
}
|
||||
|
||||
struct Tally {
|
||||
int got = 0, cold = 0;
|
||||
double first_median = 0, again_median = 0;
|
||||
};
|
||||
inline double median(std::vector<double> v) {
|
||||
if (v.empty()) return 0;
|
||||
std::sort(v.begin(), v.end());
|
||||
return v[v.size() / 2];
|
||||
}
|
||||
inline Tally tally(const std::vector<Probe>& probes) {
|
||||
Tally t;
|
||||
std::vector<double> first, again;
|
||||
for (const Probe& p : probes) {
|
||||
if (!p.made) continue;
|
||||
t.got++, t.cold += cold(p);
|
||||
first.push_back(p.first_ms), again.push_back(p.again_ms);
|
||||
}
|
||||
t.first_median = median(first), t.again_median = median(again);
|
||||
return t;
|
||||
}
|
||||
|
||||
enum class Verdict { Unknown, Warm, Cold };
|
||||
/// Cold when more than half of the sample is; under half a sample says nothing
|
||||
inline Verdict verdict(const Tally& t) {
|
||||
if (t.got * 2 < kSample) return Verdict::Unknown;
|
||||
return t.cold * 2 > t.got ? Verdict::Cold : Verdict::Warm;
|
||||
}
|
||||
/// Whether the sample needs no more probes: it is full, or what is still to come cannot change its verdict
|
||||
inline bool decided(const Tally& t) {
|
||||
return t.got >= kSample || t.cold * 2 > kSample || (t.got - t.cold) * 2 >= kSample;
|
||||
}
|
||||
|
||||
/// k places spread over n, the first at seed's place in the first step: each start samples other pipelines
|
||||
inline std::vector<size_t> spots(size_t n, size_t k, uint64_t seed) {
|
||||
std::vector<size_t> at;
|
||||
if (!n || !k) return at;
|
||||
const size_t step = std::max<size_t>(1, n / k);
|
||||
for (size_t i = (size_t)(seed % step); i < n && at.size() < k; i += step) at.push_back(i);
|
||||
return at;
|
||||
}
|
||||
|
||||
/// The records of some notes in the notes file f, read from its start: a head of {stamp, rec_bytes}, then records of
|
||||
/// rec_bytes whose first 8 bytes are the key (0: the first after the head). Only the keys are read, each record's rest
|
||||
/// stepped over, and the walk ends once every wanted key is found. A key twice keeps its first record. Empty when the
|
||||
/// head is another build's
|
||||
inline std::unordered_map<uint64_t, uint32_t> find(FILE* f, uint64_t stamp, uint64_t rec_bytes, const std::vector<uint64_t>& keys) {
|
||||
std::unordered_map<uint64_t, uint32_t> at;
|
||||
uint64_t head[2] = {0, 0};
|
||||
if (!f || rec_bytes < 8 || rec_bytes > (1u << 30) || fread(head, 8, 2, f) != 2 || head[0] != stamp || head[1] != rec_bytes) return at;
|
||||
std::unordered_map<uint64_t, bool> want;
|
||||
for (const uint64_t k : keys) want.emplace(k, false);
|
||||
size_t left = want.size();
|
||||
uint64_t key = 0;
|
||||
for (uint32_t i = 0; left && fread(&key, 8, 1, f) == 1; i++) {
|
||||
const auto w = want.find(key);
|
||||
if (w != want.end() && !w->second) w->second = true, at.emplace(key, i), left--;
|
||||
if (fseek(f, (long)(rec_bytes - 8), SEEK_CUR) != 0) break;
|
||||
}
|
||||
return at;
|
||||
}
|
||||
|
||||
// ---- <notes>.predicted.check: "predict-check <stamp> <strikes>"
|
||||
|
||||
struct State {
|
||||
bool found = false;
|
||||
uint64_t stamp = 0;
|
||||
int strikes = 0;
|
||||
};
|
||||
inline State state_read(const std::string& path) {
|
||||
State s;
|
||||
FILE* f = fopen(path.c_str(), "rb");
|
||||
if (!f) return s;
|
||||
char line[96]{};
|
||||
const size_t n = fread(line, 1, sizeof line - 1, f);
|
||||
fclose(f);
|
||||
line[n] = 0;
|
||||
unsigned long long stamp = 0;
|
||||
int strikes = 0;
|
||||
if (sscanf(line, "predict-check %16llx %d", &stamp, &strikes) == 2 && strikes >= 0)
|
||||
s.found = true, s.stamp = stamp, s.strikes = strikes;
|
||||
return s;
|
||||
}
|
||||
/// Written whole beside the old one, then put in place (a start that ends in the middle leaves the old file)
|
||||
inline bool state_write(const std::string& path, uint64_t stamp, int strikes) {
|
||||
char line[96];
|
||||
const int n = snprintf(line, sizeof line, "predict-check %016llx %d\n", (unsigned long long)stamp, strikes);
|
||||
const std::string tmp = path + ".tmp";
|
||||
FILE* f = fopen(tmp.c_str(), "wb");
|
||||
if (!f) return false;
|
||||
bool ok = fwrite(line, 1, (size_t)n, f) == (size_t)n;
|
||||
ok = fclose(f) == 0 && ok;
|
||||
if (ok) {
|
||||
remove(path.c_str()); // (rename does not replace on Windows)
|
||||
ok = rename(tmp.c_str(), path.c_str()) == 0;
|
||||
}
|
||||
if (!ok) remove(tmp.c_str());
|
||||
return ok;
|
||||
}
|
||||
|
||||
/// Whether the record says this driver does not keep them, for this stamp: cold again after they were built again
|
||||
inline bool stopped(const State& had, uint64_t stamp) {
|
||||
return had.found && had.stamp == stamp && had.strikes > kStrikes;
|
||||
}
|
||||
/// Whether a start checks at all: the switch, and (but for mode 2) not once the record says stop for this stamp
|
||||
inline bool runs(int mode, const State& had, uint64_t stamp) {
|
||||
return mode >= 2 || (mode == 1 && !stopped(had, stamp));
|
||||
}
|
||||
|
||||
enum class Do { Nothing, Again, Stop };
|
||||
/// What a start does with a sample's verdict, the record of the last starts and the stamp now. *next: the strikes to
|
||||
/// record (Again and Stop). Again: the record of what is built is removed, and the builder builds them again
|
||||
inline Do decide(Verdict v, const State& had, uint64_t stamp, int* next) {
|
||||
if (v != Verdict::Cold) return Do::Nothing;
|
||||
const bool same = had.found && had.stamp == stamp; // (found cold for this stamp before, and built again since)
|
||||
*next = same ? had.strikes + 1 : 1;
|
||||
return same && had.strikes >= kStrikes ? Do::Stop : Do::Again;
|
||||
}
|
||||
|
||||
// ---- the counter: play builds of predicted programs the driver compiled
|
||||
|
||||
/// Whether a build of that many microseconds was compiled rather than found
|
||||
inline bool slow(int64_t us) {
|
||||
return us > kSlowUs;
|
||||
}
|
||||
/// Whether the counter's line is due: said_ms, when it was last written (0: never)
|
||||
inline bool say(int64_t now_ms, int64_t said_ms) {
|
||||
return !said_ms || now_ms - said_ms >= kSayMs;
|
||||
}
|
||||
/// The plan's programs as a sorted list without repeats, for has() (Plan: entries with .prog)
|
||||
template <class Plan>
|
||||
std::vector<uint64_t> programs(const std::vector<Plan>& plan) {
|
||||
std::vector<uint64_t> keys;
|
||||
keys.reserve(plan.size());
|
||||
for (const Plan& p : plan) keys.push_back(p.prog);
|
||||
std::sort(keys.begin(), keys.end());
|
||||
keys.erase(std::unique(keys.begin(), keys.end()), keys.end());
|
||||
return keys;
|
||||
}
|
||||
inline bool has(const std::vector<uint64_t>& sorted, uint64_t prog) {
|
||||
return std::binary_search(sorted.begin(), sorted.end(), prog);
|
||||
}
|
||||
|
||||
} // namespace predict_check
|
||||
74
gpu/vk/predict_stream.h
Normal file
74
gpu/vk/predict_stream.h
Normal file
@@ -0,0 +1,74 @@
|
||||
// (Triforce, 11-21, the performance audit's PIPE-83, after Source B's) The predicted builder's plan as record numbers, its
|
||||
// notes read when their program's turn comes.
|
||||
//
|
||||
// predict_background (vk_draw.cpp) builds, behind the game, the predicted pipelines the start did not get to: on the starts
|
||||
// after a translator or driver update that is most of them, and it rests while the game is in play, so it runs for much of
|
||||
// a session. It read every note of the notes file (a PipeNote is ~27 KB), made a full note of every predicted pipeline, and
|
||||
// held both until it ended: about 1 GB with the game's 14,535 notes and 24,182 predicted pipelines. The draws, the
|
||||
// read-ahead and the warm read a note by its record already (pipe_note_at). Here: the notes file is gone through once into
|
||||
// one record's buffer for each key's record number, the plan becomes {variant, the vertex note's record, the output note's
|
||||
// record} for each program still to build, 16 bytes a pipeline, and a worker reads the two notes through its own handle
|
||||
// when it builds that pipeline. The same programs and pipelines; a note gone since drops its pipeline, as before.
|
||||
// RX_VK_PREDICT_BG_STREAM=0: every note and predicted note held, as before.
|
||||
//
|
||||
// No Vulkan and no PipeNote here: tests/test_predict_stream.py compiles it with a file of its own.
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace predict_stream {
|
||||
|
||||
/// One predicted pipeline: its program's variant, and the records of the note whose vertex layout and of the note whose
|
||||
/// targets and state it takes
|
||||
struct Entry {
|
||||
uint64_t variant;
|
||||
uint32_t vertex_rec, output_rec;
|
||||
};
|
||||
/// A program still to build and its pipelines, in the plan's order
|
||||
struct Program {
|
||||
uint64_t prog;
|
||||
std::vector<Entry> entries;
|
||||
};
|
||||
|
||||
/// Each note's key to its record (0: the first after the head), of the notes file f at its start: a head of {stamp,
|
||||
/// rec_bytes}, then records of rec_bytes whose first 8 bytes are the key. rec: a buffer of rec_bytes each is read into;
|
||||
/// sane(): whether the one in it is used (it may mend it). A key twice keeps its first record, as pipe_notes_read. Empty
|
||||
/// when the head is another build's
|
||||
template <class Sane>
|
||||
std::unordered_map<uint64_t, uint32_t> index(FILE* f, uint64_t stamp, uint64_t rec_bytes, void* rec, Sane&& sane) {
|
||||
std::unordered_map<uint64_t, uint32_t> at;
|
||||
uint64_t head[2] = {0, 0};
|
||||
if (!f || rec_bytes < 8 || fread(head, 8, 2, f) != 2 || head[0] != stamp || head[1] != rec_bytes) return at;
|
||||
for (uint32_t i = 0; fread(rec, (size_t)rec_bytes, 1, f) == 1; i++) {
|
||||
if (!sane()) continue;
|
||||
uint64_t key;
|
||||
std::memcpy(&key, rec, 8);
|
||||
at.emplace(key, i);
|
||||
}
|
||||
return at;
|
||||
}
|
||||
|
||||
/// The plan (entries with prog, variant, vertex_note, output_note: PredictPlan) as the programs still to build: those not
|
||||
/// in had, in the order the plan first names them, each with its pipelines in the plan's order. A pipeline one of whose
|
||||
/// notes is not in the index is dropped, and a program left with none is not listed
|
||||
template <class Plan>
|
||||
std::vector<Program> group(const std::vector<Plan>& plan, const std::unordered_map<uint64_t, uint32_t>& at,
|
||||
const std::unordered_set<uint64_t>& had) {
|
||||
std::vector<Program> out;
|
||||
std::unordered_map<uint64_t, size_t> where;
|
||||
for (const Plan& p : plan) {
|
||||
if (had.count(p.prog)) continue;
|
||||
const auto v = at.find(p.vertex_note), o = at.find(p.output_note);
|
||||
if (v == at.end() || o == at.end()) continue;
|
||||
const auto [it, fresh] = where.try_emplace(p.prog, out.size());
|
||||
if (fresh) out.push_back(Program{p.prog, {}});
|
||||
out[it->second].entries.push_back(Entry{p.variant, v->second, o->second});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
} // namespace predict_stream
|
||||
96
gpu/vk/predict_types.h
Normal file
96
gpu/vk/predict_types.h
Normal file
@@ -0,0 +1,96 @@
|
||||
// The prediction's checks (no game, no GPU: vk_predict.cpp predict_pipelines and vk_draw.cpp predict_run,
|
||||
// predict_background): whether a predicted vertex layout can feed a program's vertex inputs, and the switch.
|
||||
//
|
||||
// (Triforce, 11-22, the performance audit's PIPE-44, after Source A's.) The predicted pipelines take a program no note names
|
||||
// and give it the vertex layout of notes of the same vertex module, or else the layout most programs with its vertex inputs
|
||||
// had. A program's key already says which of its inputs it reads as integers (vk_shader.cpp graphics_key), so a layout
|
||||
// borrowed from another program can hand an integer input a float attribute, or the other signedness: such a pipeline is
|
||||
// invalid (VUID-VkGraphicsPipelineCreateInfo-Input-08733), built for nothing or worse. Source A reads each vertex input's
|
||||
// base type from the module's SPIR-V and drops a predicted layout whose attribute types definitely differ: 8,209 of 64,797
|
||||
// predicted pipelines on its PC, none by colour. Scaled formats count as integers here (the translator reads them so).
|
||||
//
|
||||
// And a program's predictions can give the same pipeline twice (two layouts that differ only in what is dynamic, a stride):
|
||||
// Source A found 420 built twice. Built once each now, by the pipeline's key, as play keys them: the same pipelines.
|
||||
//
|
||||
// RX_VK_PREDICT_TYPES: unset, each pipeline built once (the same pipelines as before, fewer builds); 1, that and the type
|
||||
// check, which drops pipelines (off by default: it changes which pipelines exist, and a plan is made once for the shaders,
|
||||
// so it applies to a plan made after it is set); 0, as before.
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
namespace predict_types {
|
||||
|
||||
/// RX_VK_PREDICT_TYPES: 0 as before, 1 (unset) built once, 2 built once and the type check
|
||||
inline int mode(const char* env) {
|
||||
if (!env || !*env) return 1;
|
||||
return std::atoi(env) == 0 ? 0 : std::atoi(env) == 1 ? 2 : 1;
|
||||
}
|
||||
inline bool once(int mode) { return mode >= 1; }
|
||||
inline bool typed(int mode) { return mode >= 2; }
|
||||
|
||||
/// A module's vertex inputs by location (under 32): read, read as an integer, read as a signed integer
|
||||
struct Locations {
|
||||
uint32_t mask = 0, ints = 0, sign = 0;
|
||||
};
|
||||
|
||||
/// The Input (storage class 1) variables with a Location in a SPIR-V module, and each one's base type: through its
|
||||
/// pointer type to a vector's or an array's element, an OpTypeInt (signedness) or anything else (float). Built-ins carry
|
||||
/// no Location and are not counted
|
||||
inline Locations locations(const std::vector<uint32_t>& w) {
|
||||
std::unordered_map<uint32_t, uint32_t> loc, pointee, element;
|
||||
std::unordered_map<uint32_t, int> int_sign; // (OpTypeInt id: 1 signed, 0 unsigned)
|
||||
std::vector<std::pair<uint32_t, uint32_t>> inputs; // (variable id, its pointer type)
|
||||
for (size_t i = 5; i < w.size();) {
|
||||
const uint32_t op = w[i] & 0xFFFF, n = w[i] >> 16;
|
||||
if (!n || i + n > w.size()) break;
|
||||
if (op == 71 && n >= 4 && w[i + 2] == 30) loc[w[i + 1]] = w[i + 3]; // OpDecorate Location
|
||||
else if (op == 59 && n >= 4 && w[i + 3] == 1) inputs.push_back({w[i + 2], w[i + 1]}); // OpVariable Input
|
||||
else if (op == 32 && n >= 4) pointee[w[i + 1]] = w[i + 3]; // OpTypePointer
|
||||
else if ((op == 23 || op == 28) && n >= 4) element[w[i + 1]] = w[i + 2]; // OpTypeVector, OpTypeArray
|
||||
else if (op == 21 && n >= 4) int_sign[w[i + 1]] = w[i + 3] ? 1 : 0; // OpTypeInt
|
||||
i += n;
|
||||
}
|
||||
Locations out;
|
||||
for (const auto& [var, ptr] : inputs) {
|
||||
const auto l = loc.find(var);
|
||||
if (l == loc.end() || l->second >= 32) continue;
|
||||
const auto p = pointee.find(ptr);
|
||||
if (p == pointee.end()) continue;
|
||||
uint32_t t = p->second;
|
||||
for (int depth = 0; depth < 4; depth++) { // (a vector of, an array of vectors of)
|
||||
const auto e = element.find(t);
|
||||
if (e == element.end()) break;
|
||||
t = e->second;
|
||||
}
|
||||
const uint32_t bit = 1u << l->second;
|
||||
out.mask |= bit;
|
||||
if (const auto s = int_sign.find(t); s != int_sign.end()) {
|
||||
out.ints |= bit;
|
||||
if (s->second) out.sign |= bit;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/// What an attribute of the layout hands its location: nothing known (unset: it reads zeros, as play's), a float, an
|
||||
/// unsigned or a signed integer (scaled formats are read as integers)
|
||||
enum class Kind : uint8_t { Unknown, Float, Uint, Sint };
|
||||
|
||||
/// Whether a layout's attributes (kinds by location) can feed the module's inputs: false only where a read location's
|
||||
/// attribute is definitely of the other kind (integer against float, or the other signedness)
|
||||
inline bool fits(const Locations& in, const Kind kinds[16]) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (!(in.mask >> i & 1) || kinds[i] == Kind::Unknown) continue;
|
||||
const bool want_int = in.ints >> i & 1, want_sign = in.sign >> i & 1;
|
||||
if ((kinds[i] != Kind::Float) != want_int) return false;
|
||||
if (want_int && (kinds[i] == Kind::Sint) != want_sign) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace predict_types
|
||||
79
gpu/vk/prepare_again.h
Normal file
79
gpu/vk/prepare_again.h
Normal file
@@ -0,0 +1,79 @@
|
||||
// (Triforce, 11-22, after Casual Gamer's #dev-fixes post) Two ways a start took its shaders for prepared when they were not, apart
|
||||
// from Vulkan so that tests/test_prepare_again.py runs them (vk_draw.cpp prepare_run).
|
||||
//
|
||||
// The program cache made again for another GPU. triforce_prepared.bin says the shaders were translated for this stamp
|
||||
// (program_cache_stamp: the translator and what of the GPU and its driver changes a translation). A start on another GPU or
|
||||
// with other settings that did not prepare (or did not rewrite the record) makes triforce_programs.bin again for its own
|
||||
// stamp: back here the record still matches, prepare_check says nothing to do, the program cache opens with none of these
|
||||
// shaders (vk_shader.cpp disk_init throws the other stamp's away), and every program is translated in play. So when the
|
||||
// record says nothing to do, the program cache's head (kDiskMagic, its stamp) and size are read: a cache of another stamp, or
|
||||
// of its head alone, holds none of them, and the shaders are prepared again. A cache carried over an update keeps the stamp in
|
||||
// its head (its second word, the build that wrote it, is another: program_carry.h) and passes.
|
||||
//
|
||||
// The mark of the driver's part without stage libraries, <prepared>.warming: "this step began and did not end", an empty file.
|
||||
// A start that found it left the part out for good, on whatever GPU and driver came next. Now it holds what the part is made
|
||||
// for (vk_draw.cpp libraries_stamp: the GPU, the driver, the programs), as the libraries' journal does (gpl_rules.h
|
||||
// journal_left): a mark of another stamp is another driver's, and the part goes on. An empty one (an older build's) is this
|
||||
// driver's, as before.
|
||||
// RX_VK_PREPARE_RECHECK=0: neither, as before.
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
|
||||
namespace prepare_again {
|
||||
|
||||
inline constexpr uint32_t kProgramsMagic = 0x31505348; // (vk_shader.cpp kDiskMagic: the program cache's head)
|
||||
inline constexpr uint64_t kProgramsHead = 16; // (the magic, the build that wrote it, the stamp)
|
||||
|
||||
/// RX_VK_PREPARE_RECHECK: on unless it is 0
|
||||
inline bool on(const char* env) { return !(env && env[0] == '0' && !env[1]); }
|
||||
|
||||
/// Whether a program cache, by its first n bytes (head) and its size, holds none of the shaders of stamp: no program cache's
|
||||
/// head, another stamp's, or its head alone
|
||||
inline bool programs_none(const uint8_t* head, size_t n, uint64_t size, uint64_t stamp) {
|
||||
if (n < kProgramsHead || size <= kProgramsHead) return true;
|
||||
uint32_t magic;
|
||||
uint64_t was;
|
||||
std::memcpy(&magic, head, 4), std::memcpy(&was, head + 8, 8);
|
||||
return magic != kProgramsMagic || was != stamp;
|
||||
}
|
||||
/// The same for the file at path (none there: none of them). *size: its size, 0 when there is none
|
||||
inline bool programs_none_at(const std::string& path, uint64_t stamp, uint64_t* size = nullptr) {
|
||||
std::error_code ec;
|
||||
const uint64_t n = std::filesystem::is_regular_file(path, ec) && !ec ? (uint64_t)std::filesystem::file_size(path, ec) : 0;
|
||||
const uint64_t whole = ec ? 0 : n;
|
||||
if (size) *size = whole;
|
||||
uint8_t head[kProgramsHead]{};
|
||||
size_t got = 0;
|
||||
if (FILE* f = std::fopen(path.c_str(), "rb")) {
|
||||
got = std::fread(head, 1, sizeof head, f);
|
||||
std::fclose(f);
|
||||
}
|
||||
return programs_none(head, got, whole, stamp);
|
||||
}
|
||||
|
||||
/// What the last start left of the driver's part without stage libraries: no mark, a mark of this stamp (or an empty one, an
|
||||
/// older build's; or any, with by_stamp false: RX_VK_PREPARE_RECHECK=0), or one of another stamp
|
||||
enum class Mark { None, Ours, Other };
|
||||
inline Mark mark_left(const std::string& path, uint64_t stamp, bool by_stamp) {
|
||||
FILE* f = std::fopen(path.c_str(), "rb");
|
||||
if (!f) return Mark::None;
|
||||
uint64_t was = 0;
|
||||
const bool stamped = std::fread(&was, 8, 1, f) == 1;
|
||||
std::fclose(f);
|
||||
return !by_stamp || !stamped || was == stamp ? Mark::Ours : Mark::Other;
|
||||
}
|
||||
/// The mark written before the part: the stamp it is made for (empty with by_stamp false, as before). False: not written
|
||||
inline bool mark_write(const std::string& path, uint64_t stamp, bool by_stamp) {
|
||||
FILE* f = std::fopen(path.c_str(), "wb");
|
||||
if (!f) return false;
|
||||
const bool ok = !by_stamp || std::fwrite(&stamp, 8, 1, f) == 1;
|
||||
return std::fclose(f) == 0 && ok;
|
||||
}
|
||||
|
||||
} // namespace prepare_again
|
||||
@@ -14,6 +14,19 @@
|
||||
// is in the driver's compiler at once when the preparation begins). So the workers past half are given only what RAM is
|
||||
// free when the preparation starts, 1 GB each; with the RAM not known, half. Never fewer than half: what it was.
|
||||
// RX_VK_PREPARE_THREADS=<n> sets the number outright, 1 to 64.
|
||||
//
|
||||
// (Triforce, 11-18) And measured: on AMD's Windows driver for RDNA 1 and 2 (vk_vendor.h amd_older_compiler) the compiles do
|
||||
// not add up. With an empty driver cache the preparation begins with the compute programs, up to 64 texture variants each,
|
||||
// every worker in the driver's compiler at once (warm_compute): on an RX 6800 XT (24 processors) each of those compiles
|
||||
// ran 6-8 times slower with 22 workers than with 6 (the 8x4x4 programs 17-37 s against 2.4-3.8 s, the 128x1x1 ones
|
||||
// 120-145 s against 22 s), and the translation pass ended at minute 24 against minute 15; 12 workers ended its compute part
|
||||
// a minute behind 6, 16 between 12 and 22. Neither the shared pipeline cache nor the shader modules were it. But the
|
||||
// steps after it, the stage libraries and the precompile, mostly graphics pipelines, went slower on 6 (the libraries 2222 s
|
||||
// against 2074 s on 23; the precompile about 35 min against 27): so the cap is the translation pass's alone (translate,
|
||||
// vk_draw.cpp prepare_run), kAmdOlderMost at most on that driver; the switch still decides outright. 8 workers on every
|
||||
// step (11-18) ended the translation at minute 15 as 6 did, the libraries in about 2010 s and the precompile in about
|
||||
// 27 min as 23 did, title at 4640 s: 8 it is. The libraries kept only about 4 of the 8 busy, the precompile's last
|
||||
// pipelines all 8: both left on count's
|
||||
#pragma once
|
||||
|
||||
#include <algorithm>
|
||||
@@ -27,6 +40,9 @@ inline constexpr uint64_t kRamAWorker = 1ull << 30;
|
||||
/// What it was, and what the preparation behind the game is counted from: half the processors, 1 to 32
|
||||
inline unsigned half(unsigned cpus) { return std::clamp(cpus / 2, 1u, 32u); }
|
||||
|
||||
/// The most workers of the translation pass on AMD's Windows driver for RDNA 1 and 2 (above)
|
||||
inline constexpr unsigned kAmdOlderMost = 8;
|
||||
|
||||
/// cpus: the logical processors; ram_free: the physical memory free now, 0 when it is not known; above_normal: the process
|
||||
/// was started above normal priority; asked: RX_VK_PREPARE_THREADS, 0 or less when it is not set
|
||||
inline unsigned count(unsigned cpus, uint64_t ram_free, bool above_normal, int asked) {
|
||||
@@ -36,4 +52,20 @@ inline unsigned count(unsigned cpus, uint64_t ram_free, bool above_normal, int a
|
||||
return (unsigned)std::clamp<uint64_t>(ram_free / kRamAWorker, least, most);
|
||||
}
|
||||
|
||||
/// The translation pass's workers (prepare_run): all, count's; on AMD's older driver kAmdOlderMost at most, unless the
|
||||
/// switch asked for a number
|
||||
inline unsigned translate(unsigned all, bool amd_older, bool asked) {
|
||||
return amd_older && !asked ? std::min(all, kAmdOlderMost) : all;
|
||||
}
|
||||
|
||||
/// (Triforce) Which heap the process is on (Windows), by the signature word at byte 16 of GetProcessHeap()'s header: the
|
||||
/// segment heap's (an exe built with HOOKSHOT_SEGMENT_HEAP=1, nx2/win_manifest.py) or the NT heap's; said in the log's line
|
||||
/// on the preparation's threads, so that a run says which of the two exes it was
|
||||
inline constexpr uint32_t kSegmentHeapSignature = 0xDDEEDDEEu;
|
||||
inline constexpr uint32_t kNtHeapSignature = 0xFFEEFFEEu;
|
||||
inline const char* heap_name(uint32_t signature) {
|
||||
return signature == kSegmentHeapSignature ? "segment" : signature == kNtHeapSignature ? "NT" : "not known";
|
||||
}
|
||||
inline bool segment_heap(uint32_t signature) { return signature == kSegmentHeapSignature; }
|
||||
|
||||
} // namespace prepare_threads
|
||||
|
||||
@@ -21,6 +21,9 @@
|
||||
precompile's loads (where the records are and when they are read, never what one holds: program_cache_read, in the stamp,
|
||||
reads each and checks its key). What a record holds, how it is written and read, the keys and the answers a record is
|
||||
picked by all stay in the stamp.
|
||||
- The parts of vk_bank.cpp so marked: code no translation can reach (sampler_bias_changed, which only vk_draw.cpp's
|
||||
sampler_for reads by). What a translation calls there, what those read and what writes that (texture_of's registrations:
|
||||
register_texture, texture_released) stay in the stamp; tests/test_program_carry.py bank_check holds it.
|
||||
- Comments, blank lines and the spaces at the ends of lines, in the C and C++ files.
|
||||
The run-time part of the stamp is as before (disk_stamp: the depth mode, the GPU's mesh shaders and warps, the per-GPU
|
||||
translation settings, the C++ library's layouts, the RX_VK_ and EDEN_ switches that change a translation). So a record is
|
||||
|
||||
@@ -100,11 +100,11 @@ inline std::vector<uint8_t> write(const std::vector<uint64_t>& keys, uint32_t ma
|
||||
}
|
||||
|
||||
/// The keys of a file's bytes; none when they are not a whole file of this version (cut short, another file, a bad check word)
|
||||
inline std::vector<uint64_t> read(const uint8_t* data, size_t n, uint32_t magic = kMagic) {
|
||||
inline std::vector<uint64_t> read(const uint8_t* data, size_t n, uint32_t magic = kMagic, size_t max_keys = kKeysMax) {
|
||||
uint32_t head[4];
|
||||
if (!data || n < 24) return {};
|
||||
std::memcpy(head, data, 16);
|
||||
if (head[0] != magic || head[1] != kVersion || head[2] > kKeysMax || n != 16 + (size_t)head[2] * 8 + 8) return {};
|
||||
if (head[0] != magic || head[1] != kVersion || head[2] > max_keys || n != 16 + (size_t)head[2] * 8 + 8) return {};
|
||||
std::vector<uint64_t> keys(head[2]);
|
||||
if (!keys.empty()) std::memcpy(keys.data(), data + 16, keys.size() * 8);
|
||||
uint64_t c;
|
||||
@@ -129,8 +129,9 @@ struct Record {
|
||||
std::vector<uint64_t> keys;
|
||||
std::unordered_set<uint64_t> seen;
|
||||
size_t saved = 0; // (keys.size() at the last write)
|
||||
size_t max = kKeysMax; // ((Triforce, 11-21) the pipelines' order keeps more: pipe_order.h kKeysMax)
|
||||
bool add(uint64_t key) {
|
||||
if (!key || keys.size() >= kKeysMax || !seen.insert(key).second) return false;
|
||||
if (!key || keys.size() >= max || !seen.insert(key).second) return false;
|
||||
keys.push_back(key);
|
||||
return true;
|
||||
}
|
||||
|
||||
37
gpu/vk/range_walk.h
Normal file
37
gpu/vk/range_walk.h
Normal file
@@ -0,0 +1,37 @@
|
||||
// (Triforce, 11-22, the performance audit's MEM-42, after Source A's) Is an address in a sorted list of ranges, asked for
|
||||
// the pages of a whole loop: a cursor that only moves forward.
|
||||
//
|
||||
// The capture and collection loops ask of every page whether it lies in a range list sorted by first address (the
|
||||
// captures' ranges, the texture storage's), and each asked with a binary search. A loop's pages come ascending, or
|
||||
// nearly, so one pass over the ranges serves the whole loop. An address below the last one asked searches again, so any
|
||||
// order gives the answers the search gave: tests/test_range_walk.py compares the two.
|
||||
//
|
||||
// A walk lives inside one loop, under the lock of its list: the list must not change while it is used.
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace range_walk {
|
||||
|
||||
using Ranges = std::vector<std::pair<uint64_t, uint64_t>>; // ([first, second), sorted by first)
|
||||
|
||||
struct RangeWalk {
|
||||
const Ranges& r;
|
||||
bool search = false; // (always search, as before: RX_VK_RANGE_WALK=0, the lab knob norangewalk)
|
||||
size_t next = 0; // (the first range that begins after the last address asked)
|
||||
uint64_t last = 0;
|
||||
|
||||
/// a lies in one of the ranges: std::upper_bound(r, {a, ~0}) != begin && a < prev->second, as the loops asked
|
||||
bool in(uint64_t a) {
|
||||
if (search || a < last) next = (size_t)(std::upper_bound(r.begin(), r.end(), std::make_pair(a, ~uint64_t(0))) - r.begin());
|
||||
else
|
||||
while (next < r.size() && r[next].first <= a) next++;
|
||||
last = a;
|
||||
return next != 0 && a < r[next - 1].second;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace range_walk
|
||||
123
gpu/vk/readback_late.h
Normal file
123
gpu/vk/readback_late.h
Normal file
@@ -0,0 +1,123 @@
|
||||
// (Triforce, 11-22, the performance audit's SYNC-19, after Source A's) Late readbacks: ranges the CPU reads back without
|
||||
// the wait for their write-back. The replay's invalidate (vk_replay.cpp) waits for the write-back of every range the game is
|
||||
// about to read: without it the game read 0 from its exposure meter one frame and twice the sum the next (the white flashes).
|
||||
// Some ranges the game reads right after it submitted the work that fills them, so the console cannot count on that work
|
||||
// either: there the wait is the GPU's whole latency for nothing but a value one frame newer. Source A names such ranges and
|
||||
// reads them from what guest memory holds, the last write-back made:
|
||||
// a size in hex every range of that size (Source A's default is 3980: the culling camera block, 0x3980 bytes)
|
||||
// newest a range whose writer is the newest submission handed out (the game cannot have waited for it)
|
||||
// RX_VK_READBACK_LATE=<rule>[,<rule>...]. Unset: NO rule here until the lab has run it (the audit's lab proof: a handheld or an
|
||||
// AMD iGPU, where the waits are long); =0: none either. The lab knob rblate (lab_ab.h) turns the rules a later default would
|
||||
// have (default_rules: 3980) on in its phases when the variable is unset. A late range keeps its note for the CPU's
|
||||
// write-back (memory_note_readback) and skips the catch-up and the wait, nothing else.
|
||||
// What it risks: a late read hands the game the frame before's values; with mirrors, when the CPU resets a range read late,
|
||||
// the pending write-back lands over its reset (the exposure meter's 2x flashes). `newest` can catch that meter, so it is
|
||||
// never a default. RX_VK_LOG_READBACK_RANGES=1 counts the readbacks by range (RangeLog) to find such ranges on other hardware.
|
||||
// tests/test_readback_late.py
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace mkwvk::readback_late {
|
||||
|
||||
constexpr int kMaxSizes = 8;
|
||||
/// The size Source A reads late by default: the culling camera block
|
||||
constexpr uint64_t kCameraBlock = 0x3980;
|
||||
|
||||
struct Rules {
|
||||
uint64_t sizes[kMaxSizes] = {};
|
||||
int n = 0;
|
||||
bool newest = false;
|
||||
int bad = 0; // (parts of the text that were neither a hex size nor "newest", or sizes past kMaxSizes: left out)
|
||||
bool any() const { return n > 0 || newest; }
|
||||
bool has(uint64_t size) const {
|
||||
for (int i = 0; i < n; i++)
|
||||
if (sizes[i] == size) return true;
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
/// The rules a default would have once the lab has passed them (and the knob rblate has now): the camera block's size alone
|
||||
inline Rules default_rules() {
|
||||
Rules r;
|
||||
r.sizes[r.n++] = kCameraBlock;
|
||||
return r;
|
||||
}
|
||||
|
||||
/// RX_VK_READBACK_LATE's text. Unset or empty: no rule (until the lab passes; then default_rules()). "0": none. Otherwise parts
|
||||
/// separated by commas: "newest", or a size in hex with or without 0x. A part that is neither is left out and counted in bad
|
||||
inline Rules parse(const char* text) {
|
||||
Rules r;
|
||||
if (!text || !*text) return r;
|
||||
for (const char* p = text; *p;) {
|
||||
const char* end = std::strchr(p, ',');
|
||||
const size_t len = end ? (size_t)(end - p) : std::strlen(p);
|
||||
if (len == 6 && !std::strncmp(p, "newest", 6)) {
|
||||
r.newest = true;
|
||||
} else if (len > 0 && len < 20) {
|
||||
char part[24] = {};
|
||||
std::memcpy(part, p, len);
|
||||
char* stop = nullptr;
|
||||
const unsigned long long v = std::strtoull(part, &stop, 16);
|
||||
if (stop == part || *stop) r.bad++;
|
||||
else if (v == 0) {} // ("0": none, and no rule of its own)
|
||||
else if (r.has(v)) {}
|
||||
else if (r.n < kMaxSizes) r.sizes[r.n++] = v;
|
||||
else r.bad++;
|
||||
} else if (len) {
|
||||
r.bad++;
|
||||
}
|
||||
if (!end) break;
|
||||
p = end + 1;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
/// Whether a readback of `size` bytes is read late. writer_newest: its write-back's value is at or past the newest value
|
||||
/// handed out (the fence a game's submit got last)
|
||||
inline bool wanted(const Rules& r, uint64_t size, bool writer_newest) {
|
||||
return (r.newest && writer_newest) || r.has(size);
|
||||
}
|
||||
/// The decision invalidate makes: only a range whose write-back is still ahead of the GPU (pending) can be late; one whose
|
||||
/// write-back is done waits for nothing anyway
|
||||
inline bool late(const Rules& r, uint64_t size, uint64_t writer_value, uint64_t gpu_done, uint64_t newest_handed_out) {
|
||||
return r.any() && writer_value > gpu_done && wanted(r, size, writer_value >= newest_handed_out);
|
||||
}
|
||||
|
||||
/// RX_VK_LOG_READBACK_RANGES: the readbacks by range. Not thread safe: the caller locks
|
||||
struct RangeLog {
|
||||
struct Row {
|
||||
int64_t readbacks = 0, waits = 0, wait_ns = 0, newest = 0, late = 0;
|
||||
};
|
||||
std::map<std::pair<uint64_t, uint64_t>, Row> rows; // ((address, size))
|
||||
size_t cap = 4096; // (the game reads a ring of slots at new addresses: past this, the rest is counted together)
|
||||
Row other;
|
||||
void note(uint64_t gpu, uint64_t size, bool waited, int64_t ns, bool writer_newest, bool was_late) {
|
||||
Row* row = &other;
|
||||
auto it = rows.find({gpu, size});
|
||||
if (it != rows.end()) row = &it->second;
|
||||
else if (rows.size() < cap) row = &rows[{gpu, size}];
|
||||
row->readbacks++, row->waits += waited, row->wait_ns += waited ? ns : 0, row->newest += writer_newest, row->late += was_late;
|
||||
}
|
||||
struct Line {
|
||||
uint64_t gpu = 0, size = 0;
|
||||
Row row;
|
||||
};
|
||||
/// The n ranges that waited longest in all, longest first (ties: the lower address first)
|
||||
std::vector<Line> top(size_t n) const {
|
||||
std::vector<Line> all;
|
||||
all.reserve(rows.size());
|
||||
for (const auto& [key, row] : rows) all.push_back({key.first, key.second, row});
|
||||
std::stable_sort(all.begin(), all.end(), [](const Line& a, const Line& b) { return a.row.wait_ns > b.row.wait_ns; });
|
||||
if (all.size() > n) all.resize(n);
|
||||
return all;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mkwvk::readback_late
|
||||
56
gpu/vk/recorder_auto.h
Normal file
56
gpu/vk/recorder_auto.h
Normal file
@@ -0,0 +1,56 @@
|
||||
// (Triforce) The recorder thread's default (vk_recorder.h g_auto_thread, RX_VK_RECORDER unset), chosen once the device is known
|
||||
// (vk_main.cpp pick_device). Plain code with no Vulkan or system calls: tests/test_recorder_auto.py runs it on made-up PCs.
|
||||
//
|
||||
// - NVIDIA: on with 12 logical processors or more, as since 11-16 (lab, RTX 4070 SUPER + i7-13700K: Market +11%; held to 8
|
||||
// logical processors -10%: the recorder needs a core of its own).
|
||||
// - AMD: on with 6 physical cores or more in the process's affinity. AMD's driver spends about twice NVIDIA's CPU time on a call,
|
||||
// so the replay thread's vkCmd* calls cost it more; taken out of a renderer of the same per-call design, the densest Market view
|
||||
// (~2,500 draws) fell 16-25% behind on RX 7900 XTX, 9070 XT and 9060 XT cards. Physical cores, not logical processors: the
|
||||
// recorder spins on a core while the replay records, and an SMT sibling of a busy core is not one (a 4-core Steam Deck: off).
|
||||
// Not on AMD's older Windows driver (vk_vendor.h amd_older_compiler, RX 5000 and RX 6000): it lost the device with commands
|
||||
// recorded beside the replay thread (replay_threads.h), so it waits for a lab of its own.
|
||||
// - Anything else (Intel, a GPU not named): off, nothing measured.
|
||||
// RX_VK_RECORDER=thread or =off goes over this either way.
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace mkwvk::recorder_default {
|
||||
|
||||
enum Why : int { kNvidia, kNvidiaFew, kAmd, kAmdFew, kAmdUnknown, kAmdOlder, kOther };
|
||||
|
||||
/// Why the recorder is on or off by default. logical: cpu_count() (cpu_count.h: hardware_concurrency, or the lab's HOS_SIM_CPU); physical: physical_cores (0: unknown)
|
||||
constexpr Why why(uint32_t vendor_id, unsigned logical, unsigned physical, bool amd_older) {
|
||||
if (vendor_id == 0x10DE) return logical >= 12 ? kNvidia : kNvidiaFew;
|
||||
if (vendor_id == 0x1002) {
|
||||
if (amd_older) return kAmdOlder;
|
||||
if (!physical) return kAmdUnknown;
|
||||
return physical >= 6 ? kAmd : kAmdFew;
|
||||
}
|
||||
return kOther;
|
||||
}
|
||||
constexpr bool on(Why w) { return w == kNvidia || w == kAmd; }
|
||||
constexpr bool rule(uint32_t vendor_id, unsigned logical, unsigned physical, bool amd_older) {
|
||||
return on(why(vendor_id, logical, physical, amd_older));
|
||||
}
|
||||
constexpr const char* text(Why w) {
|
||||
switch (w) {
|
||||
case kNvidia: return "NVIDIA, 12 logical processors or more";
|
||||
case kNvidiaFew: return "NVIDIA, under 12 logical processors";
|
||||
case kAmd: return "AMD, 6 physical cores or more";
|
||||
case kAmdFew: return "AMD, under 6 physical cores";
|
||||
case kAmdUnknown: return "AMD, the physical cores not known";
|
||||
case kAmdOlder: return "AMD's driver for RX 5000 and RX 6000 (not tried there)";
|
||||
default: return "not an NVIDIA or AMD GPU (not measured)";
|
||||
}
|
||||
}
|
||||
|
||||
/// The physical cores with at least one logical processor in affinity: masks[i] is core i's logical processors (one
|
||||
/// RelationProcessorCore entry each: GetLogicalProcessorInformation, which on Linux reads sysfs's package and core ids)
|
||||
inline unsigned physical_cores(const uint64_t* masks, int n, uint64_t affinity) {
|
||||
unsigned cores = 0;
|
||||
for (int i = 0; i < n; i++) cores += (masks[i] & affinity) != 0;
|
||||
return cores;
|
||||
}
|
||||
|
||||
} // namespace mkwvk::recorder_default
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user