Add AMD Anti-Lag 2 to the low latency setting, with an auto value that picks Reflex or Anti-Lag for the GPU

The reflex setting gains an auto value. With auto, on or boost the device uses NVIDIA Reflex when the driver has VK_NV_low_latency2, otherwise AMD Anti-Lag 2 when it has VK_AMD_anti_lag (Mesa RADV, AMD's Windows driver); with neither it does nothing. Anti-Lag marks the INPUT stage where the window texture is acquired and the PRESENT stage just before vkQueuePresentKHR, with the pacer's frame limit as maxFPS. The default stays off. The menu row is renamed Low Latency in all four languages.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ripps818andClaude Sonnet 5.5 committed 2026-11-22 23:24:48 -06:00
1 parent 7f17cad783
commit 84e44f3aed
11 files changed
+70 -23

No files matched your search

+1 -1
View File
@@ -146,7 +146,7 @@ static const CfgMeta metas[] = {
{"DLSS", "dlaa", "dlaa|quality|balanced|performance|ultra_performance", LIVE},
{"FSR_SHARPNESS", "80", "0..100", LIVE}, // vk_dlaa.c fsr_evaluate
{"DLSS_PRESET", "default", "default|k|j", LIVE}, {"DLSS_FIXED_EXPOSURE", "0", "0|1", LIVE}, {"DLAA_EFFECTS_AFTER", "0", "0|1", LIVE},
{"DLSS_CHAR_MASK", "65", "0|35|65|100", LIVE}, {"REFLEX", "off", "off|on|boost", RESTART}, {"FXAA", "1", "0|1", LIVE},
{"DLSS_CHAR_MASK", "65", "0|35|65|100", LIVE}, {"REFLEX", "off", "off|auto|on|boost", RESTART}, {"FXAA", "1", "0|1", LIVE},
{"LOD_STEADY", "0", "0|1", RESTART}, // sets steady
{"ASPECT", "fit", "fit|stretch", LIVE}, {"MOVIE_ASPECT", "keep", "keep|stretch", LIVE}, {"FOV", "100", "70..140", LIVE},
{"ANISO", "game", "game|2|4|8|16", RESTART}, // vk_texture.c sampler_features
+4
View File
@@ -33,6 +33,10 @@ void vk_reflex_marker(int marker, uint64_t present_id); // present_id: the fra
uint64_t vk_reflex_frame_begin(void); // SIMULATION_START: the new frame's present ID
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.
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
// ---- shader service client (gfx_shader.c)
enum { GFX_STAGE_VS, GFX_STAGE_TCS, GFX_STAGE_TES, GFX_STAGE_GS, GFX_STAGE_FS, GFX_STAGE_CS };
+26 -3
View File
@@ -390,8 +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)%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", drv);
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,
(unsigned long long)g_lat.n, g_reflex_mode == 2 ? "boost" : g_reflex_mode == 1 ? "on" : "off",
c->has_amd_antilag ? "on" : "off", drv);
g_lat.n = g_lat.ns = 0;
}
@@ -405,7 +406,8 @@ uint64_t vk_reflex_submit_id(void) { return t_reflex_submit ? t_reflex_submit :
void vk_reflex_present_frame(uint64_t id) {
// g_blit_pid feeds flip_locked's VkPresentIdKHR (Reflex) and latency_note (TOTK_TRACE=perf); with neither, the
// present skips the lock
if (!vk_has_reflex() && !(rt_trace & RT_TRACE_PERF)) return;
VkCtx *c = vk_ctx();
if (!vk_has_reflex() && !(c && c->has_amd_antilag) && !(rt_trace & RT_TRACE_PERF)) return;
plat_rmutex_lock(&g_pl);
g_blit_pid = id;
plat_rmutex_unlock(&g_pl);
@@ -452,6 +454,26 @@ void vk_reflex_sleep(void) {
}
}
// ---- AMD Anti-Lag 2 (VK_AMD_anti_lag)
static PFN_vkAntiLagUpdateAMD g_antilag_update;
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;
// 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);
}
void vk_antilag_input(uint64_t frame) { antilag_update(VK_ANTI_LAG_STAGE_INPUT_AMD, frame); }
void vk_antilag_present(uint64_t frame) { antilag_update(VK_ANTI_LAG_STAGE_PRESENT_AMD, frame); }
// ---- swapchain
static const char *g_present_got = ""; // the TOTK_VK_PRESENT value of the mode the swapchain got; "" before one
@@ -503,6 +525,7 @@ static void flip_one(void) {
pid_info.pPresentIds = &pid;
vk_reflex_marker(4, pid); // VK_LATENCY_MARKER_PRESENT_START_NV
}
if (!generated) vk_antilag_present(frame_pid);
VkPresentInfoKHR pi = {.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
.pNext = with_id ? &pid_info : NULL,
.waitSemaphoreCount = 1,
+3 -1
View File
@@ -688,7 +688,9 @@ NVN_API(nvnWindowAcquireTexture) {
perf_end(PERF_PACE, p0);
}
vk_reflex_sleep();
vk_reflex_marker(0, vk_reflex_frame_begin()); // VK_LATENCY_MARKER_SIMULATION_START_NV: a new frame and its ID
uint64_t fid = vk_reflex_frame_begin();
vk_reflex_marker(0, fid); // VK_LATENCY_MARKER_SIMULATION_START_NV: a new frame and its ID
vk_antilag_input(fid);
// The sync means "the display no longer reads this image". Presents are copies queued in submit order, so it is
// already satisfied: fenced = 3 with fence 0.
if (s) {
+2 -2
View File
@@ -838,8 +838,8 @@ static void tab_screen(float scale) {
opt_toggle("TOTK_DLSS_FIXED_EXPOSURE", UI_MENU_DLSS_FIXED_EXPOSURE, UI_MENU_DLSS_FIXED_EXPOSURE_DESC);
opt_toggle("TOTK_DLAA_EFFECTS_AFTER", UI_MENU_DLAA_EFFECTS_AFTER, UI_MENU_DLAA_EFFECTS_AFTER_DESC);
}
static const UiTextId reflex[] = {UI_MENU_REFLEX_OFF, UI_MENU_REFLEX_ON, UI_MENU_REFLEX_BOOST};
opt_choice("TOTK_REFLEX", UI_MENU_REFLEX, reflex, 3, UI_MENU_REFLEX_DESC);
static const UiTextId reflex[] = {UI_MENU_REFLEX_OFF, UI_MENU_REFLEX_AUTO, UI_MENU_REFLEX_ON, UI_MENU_REFLEX_BOOST};
opt_choice("TOTK_REFLEX", UI_MENU_REFLEX, reflex, 4, UI_MENU_REFLEX_DESC);
opt_toggle("TOTK_FXAA", UI_MENU_FXAA, UI_MENU_FXAA_DESC);
rows_color();
opt_group(UI_MENU_HDR_GROUP);
+12 -8
View File
@@ -174,8 +174,9 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_DLSS_PERFORMANCE] = "Performance", [UI_MENU_DLSS_ULTRA] = "Ultra Performance",
[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] = "NVIDIA Reflex Low Latency",
[UI_MENU_REFLEX_DESC] = "Reduces system latency on NVIDIA GPUs using VK_NV_low_latency2. On + Boost keeps GPU clocks high in CPU-bound scenes.",
[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_AUTO] = "Auto",
[UI_MENU_REFLEX_OFF] = "Off",
[UI_MENU_REFLEX_ON] = "On",
[UI_MENU_REFLEX_BOOST] = "On + Boost",
@@ -819,8 +820,9 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_DLSS_PERFORMANCE] = "Производительность", [UI_MENU_DLSS_ULTRA] = "Макс. производительность",
[UI_MENU_FXAA] = "Сглаживание игры (FXAA)",
[UI_MENU_FXAA_DESC] = "Собственное сглаживание FXAA. Слегка размывает мелкие детали; с DLAA оно не нужно.",
[UI_MENU_REFLEX] = "NVIDIA Reflex Low Latency",
[UI_MENU_REFLEX_DESC] = "Снижает задержку системы на видеокартах NVIDIA с помощью VK_NV_low_latency2. «Вкл + Ускорение» удерживает высокие частоты GPU при упоре в процессор.",
[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_AUTO] = "Авто",
[UI_MENU_REFLEX_OFF] = "Выкл",
[UI_MENU_REFLEX_ON] = "Вкл",
[UI_MENU_REFLEX_BOOST] = "Вкл + Ускорение",
@@ -1932,8 +1934,9 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
[UI_MENU_FXAA] = "Antisserrilhado do jogo (FXAA)",
[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] = "NVIDIA Reflex Low Latency",
[UI_MENU_REFLEX_DESC] = "Reduz a latência do sistema em GPUs NVIDIA usando VK_NV_low_latency2. Ligado + Boost mantém os clocks da GPU altos quando limitado pela CPU.",
[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_AUTO] = "Automático",
[UI_MENU_REFLEX_OFF] = "Desligado",
[UI_MENU_REFLEX_ON] = "Ligado",
[UI_MENU_REFLEX_BOOST] = "Ligado + Boost",
@@ -2689,8 +2692,9 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
[UI_MENU_DLSS_CHARS_FULL] = "强",
[UI_MENU_FXAA] = "游戏抗锯齿(FXAA)",
[UI_MENU_FXAA_DESC] = "游戏自身的 FXAA 边缘平滑。会让细节略微模糊;开启 DLAA 时不需要。",
[UI_MENU_REFLEX] = "NVIDIA Reflex 低延迟",
[UI_MENU_REFLEX_DESC] = "在支持 VK_NV_low_latency2 的 NVIDIA 显卡上降低系统延迟。开 + 增强 (On + Boost) 会在 CPU 瓶颈时保持 GPU 高频率。",
[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_AUTO] = "自动",
[UI_MENU_REFLEX_OFF] = "关",
[UI_MENU_REFLEX_ON] = "开",
[UI_MENU_REFLEX_BOOST] = "开 + 增强",
+1 -1
View File
@@ -63,7 +63,7 @@ typedef enum {
UI_MENU_DLSS_BALANCED, UI_MENU_DLSS_PERFORMANCE, UI_MENU_DLSS_ULTRA, UI_MENU_DLSS_PRESET, UI_MENU_DLSS_PRESET_DESC,
UI_MENU_DLSS_PRESET_DEFAULT, UI_MENU_DLSS_PRESET_K, UI_MENU_DLSS_PRESET_J, UI_MENU_DLSS_CHARS, UI_MENU_DLSS_CHARS_DESC,
UI_MENU_DLSS_CHARS_OFF, UI_MENU_DLSS_CHARS_LIGHT, UI_MENU_DLSS_CHARS_MEDIUM, UI_MENU_DLSS_CHARS_FULL, UI_MENU_FXAA, UI_MENU_FXAA_DESC,
UI_MENU_REFLEX, UI_MENU_REFLEX_DESC, UI_MENU_REFLEX_OFF, UI_MENU_REFLEX_ON, UI_MENU_REFLEX_BOOST,
UI_MENU_REFLEX, UI_MENU_REFLEX_DESC, UI_MENU_REFLEX_AUTO, UI_MENU_REFLEX_OFF, UI_MENU_REFLEX_ON, UI_MENU_REFLEX_BOOST,
UI_MENU_SCENE_UPSCALER, UI_MENU_SCENE_UPSCALER_DESC, UI_MENU_SCENE_UPSCALER_OFF, UI_MENU_SCENE_UPSCALER_DLSS,
UI_MENU_SCENE_UPSCALER_FSR3, UI_MENU_SCENE_UPSCALER_NO_DLSS_GPU, UI_MENU_SCENE_UPSCALER_NO_DLSS_DLL, UI_MENU_FSR3_SHARPNESS,
UI_MENU_FSR3_SHARPNESS_DESC,
+2 -1
View File
@@ -38,7 +38,8 @@ typedef struct VkCtx {
has_astc_ldr, // textureCompressionASTC_LDR (enabled when reported)
has_calibrated, // VK_KHR/EXT_calibrated_timestamps (GPU idle split in the perf line)
has_hdr_metadata, // VK_EXT_hdr_metadata (vk_hdr.c vk_hdr_metadata)
has_nv_reflex; // VK_NV_low_latency2 (NVIDIA Reflex Low Latency)
has_nv_reflex, // VK_NV_low_latency2 (NVIDIA Reflex Low Latency)
has_amd_antilag; // VK_AMD_anti_lag (AMD Anti-Lag 2)
// Feedback loops (maxwell.md 1.9, vk_exec_draw.c feedback_prepare): a draw samples a target of its open pass that
// an earlier draw of the pass wrote. TOTK_FEEDBACK=0: VK_FEEDBACK_OFF (sampled in GENERAL without a barrier, the
// old behaviour); VK_FEEDBACK_LAYOUT with VK_EXT_attachment_feedback_loop_layout and dynamicRenderingLocalRead
+14 -3
View File
@@ -289,6 +289,7 @@ typedef struct {
VkPhysicalDeviceDynamicRenderingLocalReadFeaturesKHR lr;
VkPhysicalDeviceAddressBindingReportFeaturesEXT abr;
VkPhysicalDevicePresentIdFeaturesKHR pid;
VkPhysicalDeviceAntiLagFeaturesAMD al;
} FeatureChain;
static int create_device(void) {
@@ -357,16 +358,21 @@ static int create_device(void) {
g_vk.has_nv_checkpoints = 1;
ext[n_ext++] = VK_NV_DEVICE_DIAGNOSTIC_CHECKPOINTS_EXTENSION_NAME;
}
// NVIDIA Reflex Low Latency (VK_NV_low_latency2 requires VK_KHR_present_id)
// 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).
const char *rv = cfg_value("TOTK_REFLEX");
if (rv && strcmp(rv, "off") != 0 && strcmp(rv, "0") != 0) {
if (strcmp(rv, "off") != 0 && strcmp(rv, "0") != 0) {
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)) {
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 {
rt_log("Reflex: VK_NV_low_latency2 not available");
rt_log("Low latency: neither VK_NV_low_latency2 nor VK_AMD_anti_lag is available");
}
}
// Graphics pipeline library: chained last so it can be dropped again when vk_caps_gpl declines it.
@@ -418,6 +424,11 @@ static int create_device(void) {
g_vk.has_nv_reflex = 0;
rt_log("Reflex: VK_NV_low_latency2 not available (no presentId feature)");
}
if (g_vk.has_amd_antilag && !c->al.antiLag) {
g_vk.has_amd_antilag = 0;
rt_log("Anti-Lag: VK_AMD_anti_lag not available (no antiLag feature)");
}
if (g_vk.has_amd_antilag) rt_log("Anti-Lag: AMD Anti-Lag 2 on (VK_AMD_anti_lag)");
g_vk.has_astc_ldr = h->textureCompressionASTC_LDR;
{
const char *e = cfg_get("TOTK_FEEDBACK");