Anti-Lag 2 runs only with reflex = auto, so on and boost keep their old Reflex-only meaning

A player who had reflex = on on an AMD GPU got nothing from it before #1416 and would have got Anti-Lag after an
update without asking for it. on and boost now enable NVIDIA Reflex alone and log the same line as before when it is
missing; auto picks Reflex or Anti-Lag. The Anti-Lag entry point loads with atomics, since the game thread and the
present thread both make the first call, and the TOTK_TRACE=perf latency line keeps its old text unless Anti-Lag is
on. The menu description, docs/settings.md and totk.ini.example say which value turns on what.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Valiantsin DzerakhandClaude Opus 5.5 committed 2026-11-23 18:34:39 +03:00
1 parent 8619d1bb3f
commit e15aae0606
6 files changed
+31 -19

No files matched your search

+1 -1
View File
@@ -211,7 +211,7 @@ Many rows below are developer tools that only act together with another setting
| `mvprev_grow` (default `1`) | `0` keeps only three banks in the previous-frame tables. | Object motion that depends on the other banks is no longer tracked. | Caution |
| `mvprev_skip` | Hex bank mask of banks left out of the previous-frame copy, replacing the default. | Different banks are tracked, which changes object motion. | Caution |
| `mvprev_trust` | Hex bank mask of banks whose found previous-frame copy is taken without the check. | A copy that does not match is used anyway, which can give wrong motion. | Caution |
| `reflex` (default `off`) | `off`, `auto`, `on`, or `boost`; reduces system input latency with what the GPU supports: NVIDIA Reflex Low Latency (`VK_NV_low_latency2`) or AMD Anti-Lag 2 (`VK_AMD_anti_lag`, Mesa RADV and AMD's Windows driver). Read at start. | `auto` and `on` pick the extension the GPU has and do nothing when it has neither. Both coordinate simulation and presentation so input reaches the screen sooner when the GPU is the limit, holding frames to the frame limit the pacer uses (`fps_limit`, the monitor's rate for `display`). `boost` also keeps NVIDIA GPU clocks high in CPU-bound scenes. | Safe |
| `reflex` (default `off`) | `off`, `auto`, `on`, or `boost`; reduces system input latency. `on` and `boost` enable NVIDIA Reflex Low Latency (`VK_NV_low_latency2`); `auto` enables Reflex, or AMD Anti-Lag 2 (`VK_AMD_anti_lag`, Mesa RADV and AMD's Windows driver) on a GPU without Reflex. Read at start. | Only one of the two runs; on a GPU with neither extension the setting does nothing. Both coordinate simulation and presentation so input reaches the screen sooner when the GPU is the limit, holding frames to the frame limit the pacer uses (`fps_limit`, the monitor's rate for `display`). `boost` also keeps NVIDIA GPU clocks high in CPU-bound scenes. | Safe |
## Scheduling and host
+1 -1
View File
@@ -34,7 +34,7 @@ uint64_t vk_reflex_frame_begin(void); // SIMULATION_START: the new frame's pre
uint64_t vk_reflex_frame(void); // the ID of the frame the game simulates now
void vk_reflex_sleep(void); // before SIMULATION_START: the driver's latency sleep
// AMD Anti-Lag 2 (gfx_present.c, VK_AMD_anti_lag): the driver paces the CPU from the INPUT call to the PRESENT call of a
// frame. Both return at once with low latency off or the GPU lacking the extension.
// frame. Both return at once unless reflex = auto turned Anti-Lag on at device creation (vk_device.c create_device).
void vk_antilag_input(uint64_t frame); // before the frame's input and simulation; may sleep
void vk_antilag_present(uint64_t frame); // right before the frame's vkQueuePresentKHR
+12 -5
View File
@@ -390,9 +390,9 @@ static void latency_note(VkCtx *c, uint64_t pid) {
"end %.2f ms", full, gi.timingCount, full ? sum / full / 1000.0 : 0.0);
}
}
rt_log("reflex: frame start to present %.2f ms over %llu frames (reflex %s, anti-lag %s)%s", g_lat.n ? g_lat.ns / 1e6 / g_lat.n : 0.0,
rt_log("reflex: frame start to present %.2f ms over %llu frames (reflex %s%s)%s", g_lat.n ? g_lat.ns / 1e6 / g_lat.n : 0.0,
(unsigned long long)g_lat.n, g_reflex_mode == 2 ? "boost" : g_reflex_mode == 1 ? "on" : "off",
c->has_amd_antilag ? "on" : "off", drv);
c->has_amd_antilag ? ", anti-lag on" : "", drv);
g_lat.n = g_lat.ns = 0;
}
@@ -457,18 +457,25 @@ void vk_reflex_sleep(void) {
// ---- AMD Anti-Lag 2 (VK_AMD_anti_lag)
static PFN_vkAntiLagUpdateAMD g_antilag_update;
// The INPUT call runs on the game thread (nvnWindowAcquireTexture), the PRESENT call on the present thread (flip_one,
// g_pl held): both carry the frame's ID, as the spec asks of a frame's two calls. The first call of either thread loads
// the entry point; the atomics keep that load race-free.
static void antilag_update(VkAntiLagStageAMD stage, uint64_t frame) {
VkCtx *c = vk_ctx();
if (!c || !c->has_amd_antilag || !frame) return;
if (!g_antilag_update) g_antilag_update = (PFN_vkAntiLagUpdateAMD)vkGetDeviceProcAddr(c->device, "vkAntiLagUpdateAMD");
if (!g_antilag_update) return;
PFN_vkAntiLagUpdateAMD fn = __atomic_load_n(&g_antilag_update, __ATOMIC_ACQUIRE);
if (!fn) {
fn = (PFN_vkAntiLagUpdateAMD)vkGetDeviceProcAddr(c->device, "vkAntiLagUpdateAMD");
if (!fn) return;
__atomic_store_n(&g_antilag_update, fn, __ATOMIC_RELEASE);
}
// the driver holds frames to the pacer's frame limit, as Reflex's minimum interval does (0: no limit known)
double hz = frame_step_limit_hz();
VkAntiLagPresentationInfoAMD pi = {
.sType = VK_STRUCTURE_TYPE_ANTI_LAG_PRESENTATION_INFO_AMD, .stage = stage, .frameIndex = frame};
VkAntiLagDataAMD d = {.sType = VK_STRUCTURE_TYPE_ANTI_LAG_DATA_AMD, .mode = VK_ANTI_LAG_MODE_ON_AMD,
.maxFPS = hz > 0 ? (uint32_t)(hz + 0.5) : 0, .pPresentationInfo = &pi};
g_antilag_update(c->device, &d);
fn(c->device, &d);
}
void vk_antilag_input(uint64_t frame) { antilag_update(VK_ANTI_LAG_STAGE_INPUT_AMD, frame); }
+4 -4
View File
@@ -177,7 +177,7 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_FXAA] = "Game anti-aliasing (FXAA)",
[UI_MENU_FXAA_DESC] = "The game's own FXAA edge smoothing. It blurs fine detail a little; with DLAA on it is not needed.",
[UI_MENU_REFLEX] = "Low Latency",
[UI_MENU_REFLEX_DESC] = "Reduces system latency. Auto picks NVIDIA Reflex or AMD Anti-Lag 2 for the GPU (VK_NV_low_latency2, VK_AMD_anti_lag); On + Boost keeps NVIDIA GPU clocks high in CPU-bound scenes. Applies after a restart.",
[UI_MENU_REFLEX_DESC] = "Reduces system latency. On uses NVIDIA Reflex (VK_NV_low_latency2); On + Boost also keeps NVIDIA GPU clocks high in CPU-bound scenes. Auto uses Reflex on NVIDIA and AMD Anti-Lag 2 (VK_AMD_anti_lag) on AMD. Applies after a restart.",
[UI_MENU_REFLEX_AUTO] = "Auto",
[UI_MENU_REFLEX_OFF] = "Off",
[UI_MENU_REFLEX_ON] = "On",
@@ -827,7 +827,7 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_FXAA] = "Сглаживание игры (FXAA)",
[UI_MENU_FXAA_DESC] = "Собственное сглаживание FXAA. Слегка размывает мелкие детали; с DLAA оно не нужно.",
[UI_MENU_REFLEX] = "Низкая задержка",
[UI_MENU_REFLEX_DESC] = "Снижает задержку системы. «Авто» выбирает NVIDIA Reflex или AMD Anti-Lag 2 под видеокарту (VK_NV_low_latency2, VK_AMD_anti_lag); «Вкл + Ускорение» удерживает высокие частоты GPU NVIDIA при упоре в процессор. Применяется после перезапуска.",
[UI_MENU_REFLEX_DESC] = "Снижает задержку системы. «Вкл» включает NVIDIA Reflex (VK_NV_low_latency2); «Вкл + Ускорение» также удерживает высокие частоты GPU NVIDIA при упоре в процессор. «Авто» включает Reflex на NVIDIA и AMD Anti-Lag 2 (VK_AMD_anti_lag) на AMD. Применяется после перезапуска.",
[UI_MENU_REFLEX_AUTO] = "Авто",
[UI_MENU_REFLEX_OFF] = "Выкл",
[UI_MENU_REFLEX_ON] = "Вкл",
@@ -1945,7 +1945,7 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
[UI_MENU_FXAA_DESC] = "A suavização de bordas FXAA do próprio jogo. Borra um pouco os detalhes finos; com o DLAA "
"ligado não é necessária.",
[UI_MENU_REFLEX] = "Baixa latência",
[UI_MENU_REFLEX_DESC] = "Reduz a latência do sistema. Automático escolhe NVIDIA Reflex ou AMD Anti-Lag 2 conforme a GPU (VK_NV_low_latency2, VK_AMD_anti_lag); Ligado + Boost mantém os clocks da GPU NVIDIA altos quando limitado pela CPU. Aplica após reiniciar.",
[UI_MENU_REFLEX_DESC] = "Reduz a latência do sistema. Ligado usa o NVIDIA Reflex (VK_NV_low_latency2); Ligado + Boost também mantém os clocks da GPU NVIDIA altos quando limitado pela CPU. Automático usa o Reflex na NVIDIA e o AMD Anti-Lag 2 (VK_AMD_anti_lag) na AMD. Aplica após reiniciar.",
[UI_MENU_REFLEX_AUTO] = "Automático",
[UI_MENU_REFLEX_OFF] = "Desligado",
[UI_MENU_REFLEX_ON] = "Ligado",
@@ -2707,7 +2707,7 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
[UI_MENU_FXAA] = "游戏抗锯齿(FXAA)",
[UI_MENU_FXAA_DESC] = "游戏自身的 FXAA 边缘平滑。会让细节略微模糊;开启 DLAA 时不需要。",
[UI_MENU_REFLEX] = "低延迟",
[UI_MENU_REFLEX_DESC] = "降低系统延迟。自动会按显卡选择 NVIDIA Reflex 或 AMD Anti-Lag 2 (VK_NV_low_latency2、VK_AMD_anti_lag);开 + 增强 (On + Boost) 会在 CPU 瓶颈时保持 NVIDIA 显卡高频率。重启后生效。",
[UI_MENU_REFLEX_DESC] = "降低系统延迟。开使用 NVIDIA Reflex (VK_NV_low_latency2);开 + 增强 (On + Boost) 还会在 CPU 瓶颈时保持 NVIDIA 显卡高频率。自动在 NVIDIA 显卡上使用 Reflex,在 AMD 显卡上使用 AMD Anti-Lag 2 (VK_AMD_anti_lag)。重启后生效。",
[UI_MENU_REFLEX_AUTO] = "自动",
[UI_MENU_REFLEX_OFF] = "关",
[UI_MENU_REFLEX_ON] = "开",
+9 -4
View File
@@ -377,21 +377,26 @@ static int create_device(void) {
g_vk.has_nv_checkpoints = 1;
ext[n_ext++] = VK_NV_DEVICE_DIAGNOSTIC_CHECKPOINTS_EXTENSION_NAME;
}
// Low latency (the reflex setting): auto, on and boost use what the GPU has, NVIDIA Reflex (VK_NV_low_latency2,
// which requires VK_KHR_present_id) or AMD Anti-Lag 2 (VK_AMD_anti_lag: RADV and AMD's Windows driver).
// Low latency (the reflex setting). on and boost: NVIDIA Reflex (VK_NV_low_latency2, which requires
// VK_KHR_present_id), as before Anti-Lag came in, so a GPU without Reflex still gets nothing new from them. auto:
// Reflex, or AMD Anti-Lag 2 (VK_AMD_anti_lag: RADV and AMD's Windows driver) on a GPU without Reflex. Only one of
// the two runs. off (the default) enables neither extension.
const char *rv = cfg_value("TOTK_REFLEX");
if (strcmp(rv, "off") != 0 && strcmp(rv, "0") != 0) {
int want_antilag = !strcmp(rv, "auto");
if (has_ext(ep, ne, VK_KHR_PRESENT_ID_EXTENSION_NAME) && has_ext(ep, ne, "VK_NV_low_latency2")) {
g_vk.has_nv_reflex = 1;
ext[n_ext++] = VK_KHR_PRESENT_ID_EXTENSION_NAME;
ext[n_ext++] = "VK_NV_low_latency2";
CHAIN(pid, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_ID_FEATURES_KHR);
} else if (has_ext(ep, ne, VK_AMD_ANTI_LAG_EXTENSION_NAME)) {
} else if (want_antilag && has_ext(ep, ne, VK_AMD_ANTI_LAG_EXTENSION_NAME)) {
g_vk.has_amd_antilag = 1;
ext[n_ext++] = VK_AMD_ANTI_LAG_EXTENSION_NAME;
CHAIN(al, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ANTI_LAG_FEATURES_AMD);
} else {
} else if (want_antilag) {
rt_log("Low latency: neither VK_NV_low_latency2 nor VK_AMD_anti_lag is available");
} else {
rt_log("Reflex: VK_NV_low_latency2 not available");
}
}
// Graphics pipeline library: chained last so it can be dropped again when vk_caps_gpl declines it.
+4 -4
View File
@@ -345,10 +345,10 @@
# processes these effects too, as before (the default until the inventory preview, the scope and water edges are
# checked on NVIDIA). The upscaling DLSS modes always process them. Changes while the game runs take effect at once.
# dlaa_effects_after = 0
# Low latency: off, auto, on or boost. Reduces system input latency with what the GPU has: NVIDIA Reflex
# (VK_NV_low_latency2) or AMD Anti-Lag 2 (VK_AMD_anti_lag: Mesa RADV, AMD's Windows driver). auto and on pick the
# one the GPU supports and do nothing on a GPU with neither; boost also keeps NVIDIA GPU clocks high in CPU-bound
# scenes. Frames are held to the frame limit the pacer uses. Read at start.
# Low latency: off, auto, on or boost. Reduces system input latency. on and boost enable NVIDIA Reflex
# (VK_NV_low_latency2); boost also keeps NVIDIA GPU clocks high in CPU-bound scenes. auto enables Reflex, or AMD
# Anti-Lag 2 (VK_AMD_anti_lag: Mesa RADV, AMD's Windows driver) on a GPU without Reflex. On a GPU with neither the
# setting does nothing. Frames are held to the frame limit the pacer uses. Read at start.
# reflex = off
# The game's own FXAA after the post effects; with DLAA on it is not needed. Changes while the game runs take effect at
# once.