From 5d06d60bd71047f765382d5444be829d799d9dc6 Mon Sep 17 00:00:00 2001 From: Zenrap0518 Date: Mon, 2 Nov 2026 14:15:36 -0700 Subject: [PATCH 01/56] Match HDR tonemapping more closely to RenoDX defaults --- runtime/shaders/hdr_tonemap.frag | 287 +++++++++++++++++++++++++++---- 1 file changed, 257 insertions(+), 30 deletions(-) diff --git a/runtime/shaders/hdr_tonemap.frag b/runtime/shaders/hdr_tonemap.frag index 4f42ac36..15ca96fb 100644 --- a/runtime/shaders/hdr_tonemap.frag +++ b/runtime/shaders/hdr_tonemap.frag @@ -1,13 +1,23 @@ #version 450 +// Portions adapted from RenoDX. Copyright (C) 2025-2026 Carlos Lopez Jr. and RenoDX contributors. +// SPDX-License-Identifier: MIT // The game's tonemap pass for HDR output (runtime/vk_hdr.c vk_hdr_shader_swap puts it in place of the translated // shader when TOTK_HDR=1). Same inputs as the game's: fp_t_tcb_8 (bloom, clamped to 10000 as the game does) plus -// fp_t_tcb_A (the scene), weights in c1[0] and the saturation grade in c3[0]. The game maps luminance and each channel -// with 1 - e^-x, blends the two by the luminance curve squared, clamps to 0..1 and grades saturation. Here the curve is -// the game's up to PIVOT and a straight line with its slope above, so mid-greys look as in SDR and highlights keep -// going; the grade works on the colour divided by its largest channel above 1; a roll-off on the largest channel stops -// at the display's peak. The output is relative to the HUD's white (1.0), which the present maps to TOTK_HDR_UI_NITS. -// Approach after RenoDX's TotK mod by souperman9 and Musa (github.com/clshortfuse/renodx, src/games/totk, MIT): its -// "extended vanilla" curve. +// fp_t_tcb_A (the scene), weights in c1[0] and the saturation grade in c3[0]. +// +// The HDR reconstruction follows RenoDX's TotK defaults more closely than the original recomp implementation: +// - the game's 1 - e^-x tone curve is extended along its tangent above 0.18; +// - the vanilla SDR tonemap is kept as a donor for hue and purity; +// - MacLeod-Boynton hue/purity transfer is performed through XYZ/LMS in BT.2020, using RenoDX's default 70% hue +// emulation and 65% SDR blowout; +// - the game's saturation grade is applied after a temporary neutral max-channel compression, then expanded back; +// - the result is constrained to non-negative BT.709 and display-mapped with per-channel Neutwo in linear BT.2020. +// The output remains linear BT.709 relative to the HUD's white (1.0), so the game's later HUD passes and the existing +// HDR10 present encoder continue to work unchanged. +// +// Color reconstruction and Neutwo math adapted from RenoDX (MIT), clshortfuse/renodx commit +// 43c067b755a6a741f6500b2b936570f1462dcfbe, notably src/games/totk/tonemap.slang, +// src/games/totk/macleod_boynton.hlsli and src/shaders/tonemap/neutwo.hlsl. // Bindings are those of the game's translated shader: vk_hdr.c rewrites them from the original's names. layout(location = 0) in vec4 uv; layout(location = 0) out vec4 color; @@ -22,15 +32,236 @@ layout(set = 0, binding = 3, std140) uniform C1 { vec4 v[4096]; } fp_c1; layout(set = 0, binding = 4, std140) uniform C3 { vec4 v[4096]; } fp_c3; const float PIVOT = 0.18; +const float HUE_STRENGTH = 0.70; +const float PURITY_STRENGTH = 0.65; +const float MB_EPSILON = 1e-20; +const float MB_INTERVAL_MAX = 1e30; +const float MB_NEAR_WHITE_EPSILON = 1e-14; +const float MB_T_MIN = 1e-6; -float curve(float x) { // the game's 1 - e^-x below PIVOT, its tangent there above - float y0 = 1.0 - exp(-PIVOT); - return x <= PIVOT ? 1.0 - exp(-x) : y0 + exp(-PIVOT) * (x - PIVOT); -} - -vec3 curve3(vec3 x) { return vec3(curve(x.r), curve(x.g), curve(x.b)); } +// Column-major GLSL matrices. Values match the RenoDX TotK MacLeod-Boynton implementation. +const mat3 XYZ_TO_LMS_2006 = mat3( + vec3(0.185082982238733, -0.134433056469973, 0.000789456671966863), + vec3(0.584081279463687, 0.405752392775348, -0.000912281325916184), + vec3(-0.0240722415044404, 0.0358252602217631, 0.0198490812339463)); +const mat3 LMS_TO_XYZ_2006 = mat3( + vec3(2.628474773947687, 0.8765342837340055, -0.06425592569153735), + vec3(-3.761263499279893, 1.2003038085515867, 0.20476359921126536), + vec3(9.9763571339745, -1.1033785928646218, 49.93266413348867)); +const mat3 BT709_TO_XYZ = mat3( + vec3(0.4123907993, 0.2126390059, 0.0193308187), + vec3(0.3575843394, 0.7151686788, 0.1191947798), + vec3(0.1804807884, 0.0721923154, 0.9505321522)); +const mat3 XYZ_TO_BT709 = mat3( + vec3(3.2409699419, -0.9692436363, 0.0556300797), + vec3(-1.5373831776, 1.8759675015, -0.2039769589), + vec3(-0.4986107603, 0.0415550574, 1.0569715142)); +const mat3 BT2020_TO_XYZ = mat3( + vec3(0.6369580483, 0.2627002120, 0.0), + vec3(0.1446169036, 0.6779980715, 0.0280726930), + vec3(0.1688809752, 0.0593017165, 1.0609850577)); +const mat3 XYZ_TO_BT2020 = mat3( + vec3(1.7166511880, -0.6666843518, 0.0176398574), + vec3(-0.3556707838, 1.6164812366, -0.0427706133), + vec3(-0.2533662814, 0.0157685458, 0.9421031212)); float maxc(vec3 c) { return max(c.r, max(c.g, c.b)); } +float minc(vec3 c) { return min(c.r, min(c.g, c.b)); } +float div_safe(float a, float b, float fallback) { return b == 0.0 ? fallback : a / b; } + +vec3 to_bt2020(vec3 c) { return XYZ_TO_BT2020 * (BT709_TO_XYZ * c); } +vec3 to_bt709(vec3 c) { return XYZ_TO_BT709 * (BT2020_TO_XYZ * c); } + +float vanilla_curve(float x) { return 1.0 - exp(-x); } +float extended_curve(float x) { + float y0 = vanilla_curve(PIVOT); + return x <= PIVOT ? vanilla_curve(x) : y0 + exp(-PIVOT) * (x - PIVOT); +} +vec3 extended_curve3(vec3 x) { + return vec3(extended_curve(x.r), extended_curve(x.g), extended_curve(x.b)); +} + +// RenoDX's generic TotK extended-vanilla path uses BT.601 luma for the SDR donor and HDR extension. +float bt601_luma(vec3 c) { return dot(c, vec3(0.2989030703, 0.5866198547, 0.1144770751)); } + +vec3 vanilla_tonemap(vec3 x) { + float lum_in = bt601_luma(x); + float lum_out = vanilla_curve(lum_in); + vec3 by_lum = x * div_safe(lum_out, lum_in, 0.0); + vec3 by_channel = vec3(vanilla_curve(x.r), vanilla_curve(x.g), vanilla_curve(x.b)); + float blend = clamp(lum_out, 0.0, 1.0); + return mix(by_lum, by_channel, blend * blend); +} + +vec3 extended_vanilla_tonemap(vec3 x) { + float lum_in = bt601_luma(x); + float lum_out = extended_curve(lum_in); + vec3 by_lum = x * div_safe(lum_out, lum_in, 0.0); + vec3 by_channel = extended_curve3(x); + float blend = clamp(vanilla_curve(lum_in), 0.0, 1.0); + return mix(by_lum, by_channel, blend * blend); +} + +vec2 mb_from_lms(vec3 lms) { + float t = lms.x + lms.y; + return t > 0.0 ? vec2(lms.x / t, lms.z / t) : vec2(0.0); +} + +vec3 lms_from_mb_t(vec2 mb, float t) { + return vec3(mb.x * t, (1.0 - mb.x) * t, mb.y * t); +} + +vec2 mb_white_d65() { + const vec2 xy = vec2(0.31272, 0.32903); + vec3 xyz = vec3(xy.x / xy.y, 1.0, (1.0 - xy.x - xy.y) / xy.y); + return mb_from_lms(XYZ_TO_LMS_2006 * xyz); +} + +void interval_lower_zero(float a, float b, out float lo, out float hi) { + if (abs(a) < MB_EPSILON) { + if (b >= 0.0) { + lo = -MB_INTERVAL_MAX; + hi = MB_INTERVAL_MAX; + } else { + lo = 1.0; + hi = 0.0; + } + return; + } + float t0 = -b / a; + if (a > 0.0) { + lo = t0; + hi = MB_INTERVAL_MAX; + } else { + lo = -MB_INTERVAL_MAX; + hi = t0; + } +} + +struct MBResult { + vec3 rgb; + float purity; +}; + +// Normalized MacLeod-Boynton purity solve in linear BT.2020. Purity 0 is white on the hue ray and purity 1 is the +// first RGB gamut boundary; T = L + M is held constant so the operation changes chromaticity rather than intensity. +MBResult mb_apply_bt2020(vec3 rgb, float purity_value) { + MBResult outv; + outv.rgb = rgb; + outv.purity = 0.0; + + vec3 lms = XYZ_TO_LMS_2006 * (BT2020_TO_XYZ * rgb); + float t = lms.x + lms.y; + if (t <= MB_T_MIN) return outv; + + vec2 white = mb_white_d65(); + vec2 direction = mb_from_lms(lms) - white; + if (dot(direction, direction) < MB_NEAR_WHITE_EPSILON) return outv; + + vec3 rgb_white = XYZ_TO_BT2020 * (LMS_TO_XYZ_2006 * lms_from_mb_t(white, t)); + vec3 a = rgb - rgb_white; + float t_lo = 0.0, t_hi = MB_INTERVAL_MAX, lo, hi; + + interval_lower_zero(a.r, rgb_white.r, lo, hi); t_lo = max(t_lo, lo); t_hi = min(t_hi, hi); + interval_lower_zero(a.g, rgb_white.g, lo, hi); t_lo = max(t_lo, lo); t_hi = min(t_hi, hi); + interval_lower_zero(a.b, rgb_white.b, lo, hi); t_lo = max(t_lo, lo); t_hi = min(t_hi, hi); + if (t_hi < t_lo) { + outv.rgb = max(rgb, vec3(0.0)); + return outv; + } + + float t_max = max(0.0, t_hi); + outv.purity = t_max > MB_EPSILON ? clamp(1.0 / t_max, 0.0, 1.0) : 0.0; + float t_final = clamp(purity_value, 0.0, 1.0) * t_max; + vec3 lms_final = lms_from_mb_t(white + t_final * direction, t); + outv.rgb = max(XYZ_TO_BT2020 * (LMS_TO_XYZ_2006 * lms_final), vec3(0.0)); + return outv; +} + +vec3 correct_purity(vec3 target709, vec3 reference709, float strength) { + vec3 target2020 = to_bt2020(target709); + vec3 reference2020 = to_bt2020(reference709); + float target_purity = mb_apply_bt2020(target2020, 1.0).purity; + float reference_purity = mb_apply_bt2020(reference2020, 1.0).purity; + float applied = mix(target_purity, reference_purity, clamp(strength, 0.0, 1.0)); + return to_bt709(mb_apply_bt2020(target2020, applied).rgb); +} + +// Transfer SDR donor hue and purity to the extended HDR result using the same MB construction as RenoDX TotK. +vec3 correct_hue_and_purity(vec3 target709, vec3 reference709, float hue_strength, float purity_strength) { + if (hue_strength <= 0.0 && purity_strength <= 0.0) return target709; + if (hue_strength <= 0.0) return correct_purity(target709, reference709, purity_strength); + + vec3 target2020 = to_bt2020(target709); + vec3 reference2020 = to_bt2020(reference709); + vec3 target_lms = XYZ_TO_LMS_2006 * (BT2020_TO_XYZ * target2020); + float target_t = target_lms.x + target_lms.y; + if (target_t <= MB_T_MIN) return target709; + + float target_purity = mb_apply_bt2020(target2020, 1.0).purity; + float reference_purity = mb_apply_bt2020(reference2020, 1.0).purity; + float applied_purity = mix(target_purity, reference_purity, clamp(purity_strength, 0.0, 1.0)); + + vec3 reference_lms = XYZ_TO_LMS_2006 * (BT2020_TO_XYZ * reference2020); + vec2 white = mb_white_d65(); + vec2 target_direction = mb_from_lms(target_lms) - white; + vec2 reference_direction = mb_from_lms(reference_lms) - white; + float target_len_sq = dot(target_direction, target_direction); + float reference_len_sq = dot(reference_direction, reference_direction); + + if (target_len_sq < MB_NEAR_WHITE_EPSILON && reference_len_sq < MB_NEAR_WHITE_EPSILON) + return correct_purity(target709, reference709, purity_strength); + + vec2 target_unit = target_len_sq > MB_NEAR_WHITE_EPSILON + ? target_direction * inversesqrt(target_len_sq) : vec2(0.0); + vec2 reference_unit = reference_len_sq > MB_NEAR_WHITE_EPSILON + ? reference_direction * inversesqrt(reference_len_sq) : target_unit; + if (target_len_sq <= MB_NEAR_WHITE_EPSILON) target_unit = reference_unit; + + float hue_blend = clamp(hue_strength, 0.0, 1.0); + vec2 blended_unit = mix(target_unit, reference_unit, hue_blend); + float blended_len_sq = dot(blended_unit, blended_unit); + if (blended_len_sq <= MB_NEAR_WHITE_EPSILON) { + blended_unit = hue_blend >= 0.5 ? reference_unit : target_unit; + blended_len_sq = dot(blended_unit, blended_unit); + } + blended_unit *= inversesqrt(max(blended_len_sq, MB_EPSILON)); + + float seed_len = sqrt(max(target_len_sq, 0.0)); + if (seed_len <= 1e-6) seed_len = sqrt(max(reference_len_sq, 0.0)); + seed_len = max(seed_len, 1e-6); + + vec3 seed_lms = lms_from_mb_t(white + blended_unit * seed_len, target_t); + vec3 seed2020 = XYZ_TO_BT2020 * (LMS_TO_XYZ_2006 * seed_lms); + return to_bt709(mb_apply_bt2020(seed2020, applied_purity).rgb); +} + +float hue_transfer_gate(vec3 donor) { + float hi = maxc(donor), lo = minc(donor); + float chroma = div_safe(hi - lo, hi, 0.0); + return smoothstep(0.02, 0.12, chroma); +} + +float neutwo(float x) { return x * inversesqrt(x * x + 1.0); } +float neutwo(float x, float peak) { return peak * x * inversesqrt(x * x + peak * peak); } + +float max_channel_neutwo_scale(vec3 c) { + float top = maxc(abs(c)); + return top > 0.0 ? neutwo(top) / top : 1.0; +} + +vec3 saturation_grade(vec3 c, vec4 w, vec4 g) { + float d = c.r * 0.6666667 + (c.g + c.b) * w.z - 1.0; + float grade = g.y * (1.0 - d * d) + g.x; + float m = maxc(c); + return vec3(m) + (c - vec3(m)) * grade; +} + +vec3 per_channel_neutwo_bt2020(vec3 c709, float peak) { + vec3 c = max(to_bt2020(c709), vec3(0.0)); + c = vec3(neutwo(c.r, peak), neutwo(c.g, peak), neutwo(c.b, peak)); + return to_bt709(c); +} void main() { vec3 x = min(texture(fp_t_tcb_8, uv.xy).rgb, vec3(10000.0)) + texture(fp_t_tcb_A, uv.xy).rgb; @@ -38,24 +269,20 @@ void main() { float game = support_buffer.hdr.x > 0.0 ? support_buffer.hdr.x : 1.0; float peak = support_buffer.hdr.y > 1.0 ? support_buffer.hdr.y : 1.0; - float lum = max(x.r * 0.2989 + x.g * w.x + x.b * w.y, 0.0); - float sdr = 1.0 - exp(-lum); - vec3 by_lum = lum > 0.0 ? x * (curve(lum) / lum) : x; - vec3 c = max(mix(by_lum, curve3(x), sdr * sdr), vec3(0.0)); + // Extended HDR carrier plus the original bounded SDR rendering used as RenoDX's color donor. + vec3 c = extended_vanilla_tonemap(x); + vec3 donor = clamp(vanilla_tonemap(x), vec3(0.0), vec3(1.0)); + c = correct_hue_and_purity(c, donor, HUE_STRENGTH * hue_transfer_gate(donor), PURITY_STRENGTH); - // the game's saturation grade, on the colour scaled into 0..1 by its largest channel - float s = max(maxc(c), 1.0); - vec3 n = c / s; - float m = maxc(n); - float d = n.r * 0.6666667 + (n.g + n.b) * w.z - 1.0; - float grade = g.y * (1.0 - d * d) + g.x; - c = s * ((n - m) * grade + m); + // RenoDX temporarily compresses the largest channel with neutral Neutwo while the original TotK saturation grade + // runs, then divides the compression back out. This avoids feeding the SDR-authored grade arbitrarily large HDR RGB. + float grade_scale = max_channel_neutwo_scale(c); + c = saturation_grade(c * grade_scale, w, g) / grade_scale; + + // RenoDX's default BT.709 clamp is a non-negative clamp. Final display mapping is per-channel Neutwo in BT.2020, + // which allows bright colors to converge toward white instead of preserving max-channel RGB ratios. + c = max(c, vec3(0.0)); + c = per_channel_neutwo_bt2020(c, peak); - // roll-off of the largest channel from half the peak to the peak - float top = maxc(c), knee = 0.5 * peak; - if (top > knee) { - float r = peak - knee; - c *= (knee + r * (1.0 - exp(-(top - knee) / r))) / top; - } color = vec4(max(c, vec3(0.0)) * game, 0.0); } From 22e42662e5cc14090bf70b698de102652cfb5822 Mon Sep 17 00:00:00 2001 From: Zenrap0518 Date: Mon, 2 Nov 2026 15:41:11 -0700 Subject: [PATCH 02/56] Match RenoDX default gamma correction --- runtime/shaders/hdr_tonemap.frag | 44 +++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/runtime/shaders/hdr_tonemap.frag b/runtime/shaders/hdr_tonemap.frag index 15ca96fb..bde41ea0 100644 --- a/runtime/shaders/hdr_tonemap.frag +++ b/runtime/shaders/hdr_tonemap.frag @@ -11,13 +11,15 @@ // - MacLeod-Boynton hue/purity transfer is performed through XYZ/LMS in BT.2020, using RenoDX's default 70% hue // emulation and 65% SDR blowout; // - the game's saturation grade is applied after a temporary neutral max-channel compression, then expanded back; -// - the result is constrained to non-negative BT.709 and display-mapped with per-channel Neutwo in linear BT.2020. +// - the result is constrained to non-negative BT.709 and display-mapped with per-channel Neutwo in linear BT.2020; +// - RenoDX's default 2.2 gamma correction is folded into the native linear path: the Neutwo peak is corrected before +// display mapping and the corresponding sRGB-to-gamma-2.2 appearance correction is applied after tone mapping. // The output remains linear BT.709 relative to the HUD's white (1.0), so the game's later HUD passes and the existing // HDR10 present encoder continue to work unchanged. // -// Color reconstruction and Neutwo math adapted from RenoDX (MIT), clshortfuse/renodx commit +// Color reconstruction, gamma correction and Neutwo math adapted from RenoDX (MIT), clshortfuse/renodx commit // 43c067b755a6a741f6500b2b936570f1462dcfbe, notably src/games/totk/tonemap.slang, -// src/games/totk/macleod_boynton.hlsli and src/shaders/tonemap/neutwo.hlsl. +// src/games/totk/macleod_boynton.hlsli, src/shaders/colorcorrect.hlsl and src/shaders/tonemap/neutwo.hlsl. // Bindings are those of the game's translated shader: vk_hdr.c rewrites them from the original's names. layout(location = 0) in vec4 uv; layout(location = 0) out vec4 color; @@ -34,6 +36,7 @@ layout(set = 0, binding = 4, std140) uniform C3 { vec4 v[4096]; } fp_c3; const float PIVOT = 0.18; const float HUE_STRENGTH = 0.70; const float PURITY_STRENGTH = 0.65; +const float GAMMA = 2.2; const float MB_EPSILON = 1e-20; const float MB_INTERVAL_MAX = 1e30; const float MB_NEAR_WHITE_EPSILON = 1e-14; @@ -72,6 +75,32 @@ float div_safe(float a, float b, float fallback) { return b == 0.0 ? fallback : vec3 to_bt2020(vec3 c) { return XYZ_TO_BT2020 * (BT709_TO_XYZ * c); } vec3 to_bt709(vec3 c) { return XYZ_TO_BT709 * (BT2020_TO_XYZ * c); } +// RenoDX GammaSafe(c, true, 2.2): sRGBDecode(GammaEncode(c, 2.2)). Used on the peak ratio before Neutwo. +float srgb_decode(float c) { + return c <= 0.04045 ? c / 12.92 : pow((c + 0.055) / 1.055, 2.4); +} +float gamma22_to_srgb_linear(float c) { + float a = abs(c); + float v = srgb_decode(pow(a, 1.0 / GAMMA)); + return c < 0.0 ? -v : v; +} + +// RenoDX GammaSafe(c, false, 2.2): GammaDecode(sRGBEncode(c), 2.2). In RenoDX this is paired with a gamma-2.2 +// intermediate encode/decode. The native recomp stays linear, so applying this once here gives the same linear result. +float srgb_encode(float c) { + return c <= 0.0031308 ? c * 12.92 : 1.055 * pow(c, 1.0 / 2.4) - 0.055; +} +float srgb_linear_to_gamma22_linear(float c) { + float a = abs(c); + float v = pow(srgb_encode(a), GAMMA); + return c < 0.0 ? -v : v; +} +vec3 srgb_linear_to_gamma22_linear(vec3 c) { + return vec3(srgb_linear_to_gamma22_linear(c.r), + srgb_linear_to_gamma22_linear(c.g), + srgb_linear_to_gamma22_linear(c.b)); +} + float vanilla_curve(float x) { return 1.0 - exp(-x); } float extended_curve(float x) { float y0 = vanilla_curve(PIVOT); @@ -269,6 +298,10 @@ void main() { float game = support_buffer.hdr.x > 0.0 ? support_buffer.hdr.x : 1.0; float peak = support_buffer.hdr.y > 1.0 ? support_buffer.hdr.y : 1.0; + // RenoDX's default Gamma Correction = 2.2 adjusts the peak in the opposite direction of its post-tonemap + // appearance correction. At 1000/203 this raises the Neutwo peak from about 4.926 to about 5.33. + peak = gamma22_to_srgb_linear(peak); + // Extended HDR carrier plus the original bounded SDR rendering used as RenoDX's color donor. vec3 c = extended_vanilla_tonemap(x); vec3 donor = clamp(vanilla_tonemap(x), vec3(0.0), vec3(1.0)); @@ -284,5 +317,10 @@ void main() { c = max(c, vec3(0.0)); c = per_channel_neutwo_bt2020(c, peak); + // Fold RenoDX's default 2.2 intermediate gamma correction into this native linear path. RenoDX first maps the + // linear result from an sRGB display response to a pure 2.2 response, then encodes/decodes the intermediate as 2.2; + // those latter two operations cancel, leaving this corrected linear value for HDR output. + c = srgb_linear_to_gamma22_linear(c); + color = vec4(max(c, vec3(0.0)) * game, 0.0); } From 6966cee0d45faa7468c2f1b976884cc94192b3db Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Mon, 9 Nov 2026 08:37:24 +0800 Subject: [PATCH 03/56] Bring the core frame and camera patches to game 1.1.0 --- recomp/patches-v110.txt | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/recomp/patches-v110.txt b/recomp/patches-v110.txt index c79e4cc8..456b0475 100644 --- a/recomp/patches-v110.txt +++ b/recomp/patches-v110.txt @@ -10,6 +10,8 @@ set cloth TOTK_CLOTH_REALTIME 1 set bounce TOTK_HIGHFPS_FIX 1 set output TOTK_PATCH_OUTPUT 0 set scene TOTK_PATCH_SCENE 0 +set shadow TOTK_PATCH_SHADOW 0 +set cascade TOTK_PATCH_CASCADE 0 # 60 fps: the adaptive present-interval controller (main+0x8f26c8, 1.0.0 0x8f6bec) gets the minimum interval 1. site fps60 main 90e978 6b08015f 7100055f # clamp: cmp w10, #1 (was cmp w10, w8 = minimum) @@ -66,6 +68,50 @@ site scene main cea5e0 5e21d900 @page:x9 # scvtf s0, s8 -> adrp x9, page site scene main cea5e8 bd0cc660 2d420520 # str s0, [x19, #0xcc4] -> ldp s0, s1, [x9, #16] site scene main cea5ec 5e21d921 bd0cc660 # scvtf s1, s9 -> str s0, [x19, #0xcc4] +# Equipment-switch cooldown (issue #18): the player update tests state +0x109c against FLT_EPSILON, +# while the equipment gate (main+0x7f0134) blocks changes above zero. Step every positive remainder through +# main+0xa26bb0, including (0, FLT_EPSILON], so a measured frame ratio cannot leave equipment locked. +site realtime main a20518 1e270101 1e2703e1 # fmov s1, w8 (FLT_EPSILON) -> fmov s1, wzr + +# Cursor and aim steps (MacNativeGames game_patches.c patch_cursor_speed, 363a6eb): use the same 30 Hz ratio +# already read by these updates for smoothing. x9 / s16 are scratch at the map site; x20 holds the aim clock. +set cursor TOTK_HIGHFPS_FIX 1 +site cursor main f31e80 bd400361 f94002e9 bd400930 1e300800 bd400361 # map pan s0 *= [[x23] + 8] +site cursor main 1d55f24 1e2a198c 1e2a198c bd400a90 1e30098c # vertical ability aim s12 *= [x20 + 8] +site cursor main 1d556a4 1e200923 1e200923 bd400a90 1e300863 # vertical gyro aim s3 *= [x20 + 8] + +# Camera aspect (Hor+): two camera projection updates and the two copies of the viewport projection routine. +# The camera sites were matched against 1.0.0 by instruction windows; both viewport copies match the same +# 193-word normalized window. Page +56 is set by runtime/resolution.c. Save x10 instead of assuming it dead. +set aspect TOTK_ASPECT_PATCH 0 +site aspect main cdbf30 bd414260 f81f0fea @page:x10 bd403940 f84107ea +site aspect main 1261a64 bd414260 f81f0fea @page:x10 bd403940 f84107ea +site aspect main 19c2260 1e211800 f81f0fea @page:x10 bd403940 f84107ea +site aspect main 1ed8fa4 1e211800 f81f0fea @page:x10 bd403940 f84107ea + +# Field of view: load the camera's vertical angle as before and multiply by page +60. The following projection +# setup overwrites s8 before reading it; s1 (the half-angle multiplier) stays intact. x10 is saved on the stack. +set fov TOTK_FOV_PATCH 0 +site fov main cdbef8 bd413e60 f81f0fea @page:x10 bd413e60 bd403d48 1e280800 f84107ea +site fov main 1261a2c bd413e60 f81f0fea @page:x10 bd413e60 bd403d48 1e280800 f84107ea + +# Texture pool offsets above 2 GiB (MacNativeGames game_patches.c patch_pool_offset, ca311e2d): the loader +# passes w25 to SetStorage and SetPackagedTextureData. Widen unsigned to cover the complete 32-bit pool offset. +set pooloff TOTK_POOL_OFFSET_PATCH 1 +site pooloff main 9b93a8 93407f22 2a1903e2 +site pooloff main 9b93c4 8b39c101 8b394101 + +# Sun shadow map: the size rounded here is used for width (+0x3d8), height (+0x3f8) and viewport together. +# runtime/resolution.c shadow_init supplies the fixed size at page +92; the default remains the game's size. +site shadow main d0760c 11001d6b @page:x11 b9405d6b 11001d6b + +# Sun shadow cascade parameter defaults: depth_shadow_near_0_1..3 and depth_shadow_far_0. The constructor +# stores 20, 40, 80 and 160 metres; runtime/resolution.c res_shadow_range supplies page +64..+76. +site cascade main 1157fb8 52a83408 @page:x8 b9404108 +site cascade main 1158040 52a84408 @page:x8 b9404508 +site cascade main 11580c8 52a85408 @page:x8 b9404908 +site cascade main 115814c 52a86408 @page:x8 b9404d08 + # Spin waits, from tools/spin_waits.py --exefs build/extracted/v110/exefs --patches recomp/patches-v110.txt: loops that only # another thread can end; their back-edges pass rt_spin_gate (runtime/kernel.c), TOTK_SPIN=0 keeps the core. From 89364414ea22e84bafcda8920d1bd4da097ed833 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Mon, 9 Nov 2026 08:39:10 +0800 Subject: [PATCH 04/56] Check the 1.1.0 patch contracts and document their coverage --- THIRD_PARTY_NOTICES.md | 6 +- docs/patches-v110.md | 41 ++++++++++ tests/patches_v110_check.py | 153 ++++++++++++++++++++++++++++++++++++ totk.ini.example | 2 +- 4 files changed, 199 insertions(+), 3 deletions(-) create mode 100644 docs/patches-v110.md create mode 100644 tests/patches_v110_check.py diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 289e75a6..b430cc01 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -10,8 +10,8 @@ Code copied or adapted from another project is listed here with its source, the | MacNativeGames TotK host runtime: dynamic linking, identity check, module permissions, guest memory and SVCs, threads, IPC, audio renderer, system services, RomFS and save storage, boot sequence, the NVN proc name list | https://github.com/ly05010419/MacNativeGames @ `b75be8cfa704df3701e86130c8ced268e79d6b11` (`games/totk/runtime/`, `games/totk/scripts/prepare_runtime.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `runtime/loader.c`, `runtime/memory.c`; `runtime/kernel.c`, `runtime/svc.c`, `runtime/ipc.c`, `runtime/ipc.h`, `runtime/audren.c`, `runtime/audren.h`, `runtime/audio_mixer.c`, `runtime/audio_effects.c`, `runtime/audio_effects.h`, `runtime/audio_reverb.c`, `runtime/audio_reverb.h` (SDL3 output replaces CoreAudio), `runtime/ov_system.c` (also `shared_font.c`: the BFTTF layout behind nn::pl), `runtime/ov_input.c` (also `hid_feedback.c`: vibration and six-axis handles and calls), `runtime/motion_fusion.c` (six-axis fusion of `motion_fusion.c`), `runtime/ov_media.c` (hardware Opus decoder over libopus), `runtime/swkbd_win.c` (`swkbd_host.c`: ShowKeyboardArg offsets, UTF-8/UTF-16 conversion, disabled-key filter, result codes; Win32 window replaces the macOS text bar), `runtime/ov_gfx.c`, `runtime/romfs.c`, `runtime/romfs_path.h`, `runtime/fs_host.c`, `runtime/fs.h`, `runtime/boot.c`; `runtime/gfx_window.c`; `tools/gen_nvn_procs.py`, `runtime/nvn_procs.inc` (`NVN/names.txt` and the `NVN_EXTRA` names of `totk_nvn_ext.c`) | | MacNativeGames TotK frame-rate patches: 60 fps present-interval controller, real-time frame step and its present sampling, hair and cloth clock, trampoline slow-motion check (instruction words and 1.2.1 sites), player position chain; quick-menu capture background RomFS overlay | https://github.com/ly05010419/MacNativeGames @ `ebe621de99bfc48f3c42f2d2aa73e04fbcc6eae2` (`games/totk/runtime/game_patches.c`, `game_version.h`, `world_survey.c`, `games/totk/scripts/make_romfs_patches.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `runtime/frame_rate.c`, `recomp/patches-v121.txt`, `tools/make_romfs_patches.py` | | MacNativeGames TotK 1.4.3 fade fix: the four distance / LOD and pre-actor fade sites, their instruction words and the floor of the fade step at 1 | https://github.com/ly05010419/MacNativeGames @ `3e9e7f67fdfdd3404134dcfa0f24969a9425a33f` (`games/totk/runtime/game_patches_v143.c` patch_fade_increment), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v143.txt` (set fade; the floor without flags, clz >> 5, as in pull request #78) | -| MacNativeGames TotK 1.2.1 cursor and aim steps: the map cursor, vertical Ultrahand aim and vertical gyro aim sites, their instruction words and the step scaled by the frame ratio | https://github.com/ly05010419/MacNativeGames @ `363a6eb50434387f7d623349934bcf1e910be48f` (`games/totk/runtime/game_patches.c` patch_cursor_speed), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v121.txt` (set cursor) | -| MacNativeGames TotK aspect ratio: the camera and viewport sites that hand the perspective projection its aspect ratio, and the UI layout edits for a canvas wider than 16:9 | https://github.com/ly05010419/MacNativeGames @ `933b6a0d1438de160208a0a13eb5e8d7a2cb8094` (`games/totk/runtime/aspect_patch.h`, `aspect_math.h`, `game_patches_v143.c`, `games/totk/scripts/ultrawide_layout.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v143.txt` (set aspect), `tools/ultrawide_layout.py`, `tools/make_romfs_patches.py` (--aspect) | +| MacNativeGames TotK 1.2.1 cursor and aim steps: the map cursor, vertical Ultrahand aim and vertical gyro aim sites, their instruction words and the step scaled by the frame ratio | https://github.com/ly05010419/MacNativeGames @ `363a6eb50434387f7d623349934bcf1e910be48f` (`games/totk/runtime/game_patches.c` patch_cursor_speed), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v121.txt`, `recomp/patches-v110.txt` (set cursor) | +| MacNativeGames TotK aspect ratio: the camera and viewport sites that hand the perspective projection its aspect ratio, and the UI layout edits for a canvas wider than 16:9 | https://github.com/ly05010419/MacNativeGames @ `933b6a0d1438de160208a0a13eb5e8d7a2cb8094` (`games/totk/runtime/aspect_patch.h`, `aspect_math.h`, `game_patches_v143.c`, `games/totk/scripts/ultrawide_layout.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v110.txt`, `recomp/patches-v143.txt` (set aspect), `tools/ultrawide_layout.py`, `tools/make_romfs_patches.py` (--aspect) | | MacNativeGames TotK button icons: the Xbox controller's shoulder buttons, triggers, Menu, View and d-pad drawn with letters from the game's own text fonts, the .bfotf key, the button guide's images and their block-linear layout, the resource size table raised for the archives that grew | https://github.com/ly05010419/MacNativeGames @ `933b6a0d1438de160208a0a13eb5e8d7a2cb8094` (`games/totk/scripts/make_button_icons.py`), Copyright (c) 2026 MacNativeGames contributors | MIT | `tools/button_icons.py`, `tools/make_romfs_patches.py` (--prompts) | | RenoDX TotK mod (game mod by souperman9, tonemapper by Musa, RenoDX framework by ShortFuse, RenoVK fork by Ritsu): the approach of the HDR tonemap (the game's 1 - e^-x curve kept below a pivot and continued along its tangent above it, the saturation grade applied to the colour scaled into 0..1) and the observation that the passes after the tonemap keep values above 1. No code copied; the shader is our own | https://github.com/clshortfuse/renodx @ `b6f87272ad1bfdc0e6444910a93606815944a085` (`src/games/totk/tonemap.slang`, `addon.cpp`), Copyright (c) 2025 Carlos Lopez Jr. | MIT | `runtime/shaders/hdr_tonemap.frag`, `runtime/vk_hdr.c` | | TOTK-Ultrawide, the community mod for emulators: the list of UI panes the ultrawide layout edits and the distances they move (data only, no code copied; the edit code is our own, and MacNativeGames' `ultrawide_layout.py` in the row above already carries the same values). The mod's repository URL and licence version are not recorded in this repository | TOTK-Ultrawide (community mod; URL not recorded here) | GPL (version not recorded here) | `tools/ultrawide_layout.py` (`KEEP_ROOT`, `edits`, `anim_edits`) | @@ -42,6 +42,8 @@ Code copied or adapted from another project is listed here with its source, the | Zstandard 1.5.7 (MSYS2 `mingw-w64-ucrt-x86_64-zstd`), static link | https://github.com/facebook/zstd, Copyright (c) Meta Platforms, Inc. and affiliates | BSD-3-Clause | `runtime/resolution.c` (the HeapDef table), `runtime/ov_zstd.c` (the game's zstd frames decoded on the host) | | musl `fma.c`, `fmaf.c` and `scalbn.c`, adapted into one file for the x86-64-v2 build | https://github.com/kraj/musl @ `5a56ad13e1e0790c06122978aad2a14d6b9efc1a` (mirror of https://git.musl-libc.org/cgit/musl), Copyright (c) 2005-2020 Rich Felker and contributors | MIT | `runtime/fma.c` (the correctly rounded fma/fmaf the FP lowering needs on CPUs without FMA3) | +| MacNativeGames texture pool offset fix: widen the 32-bit texture storage and packaged-data offsets unsigned | https://github.com/ly05010419/MacNativeGames @ `ca311e2d` (`games/totk/runtime/game_patches.c` patch_pool_offset), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v110.txt` (set pooloff; sites located again in 1.1.0) | + ## Compiler runtime in a source build A build with the MSYS2 UCRT64 toolchain of `docs/building.md` links these into `totk.exe`. The installer release builds with llvm-mingw instead (its row below). diff --git a/docs/patches-v110.md b/docs/patches-v110.md new file mode 100644 index 00000000..07cb0082 --- /dev/null +++ b/docs/patches-v110.md @@ -0,0 +1,41 @@ +# Game 1.1.0 patch coverage + +The built-in table is [recomp/patches-v110.txt](../recomp/patches-v110.txt). These sites were located in the local 1.1.0 main and checked against its original instruction words, rather than applying a version-wide address shift. The generator rejects a different word or an invalid spin back-edge. + +## Added coverage + +| Set | Sites added | Runtime control | +| --- | ---: | --- | +| realtime | 1 | Equipment-switch cooldown: step every positive remainder, including values below FLT_EPSILON. Follows the existing real-time clock switch. | +| cursor | 3 | Scale map panning, vertical ability aim and vertical gyro aim by the 30 Hz ratio; follows `TOTK_HIGHFPS_FIX`. | +| aspect | 4 | The two camera and two viewport projections read page +56. The resolution code enables it for non-16:9 output. | +| fov | 2 | The two camera projections multiply their vertical angle by page +60. The field-of-view setting is live; 100 leaves the original path. | +| pooloff | 2 | Widen texture-pool offsets unsigned, covering 2..4 GiB without changing offsets below 2 GiB. Enabled by default; `TOTK_POOL_OFFSET_PATCH=0` retains the original path. | +| shadow | 1 | The sun shadow map takes its fixed size from page +92 before rounding. The shadow-resolution setting enables it; `shadow_res=game` leaves the game's sizing. | +| cascade | 4 | Read the four sun shadow cascade defaults from page +64..76. Shadow range 100 leaves the original constructor. | + +The table has 12 sets and 50 instruction sites in total. Its existing 889 spin back-edges are unchanged. The new sets use the existing runtime page and settings; no new setting, allocator or renderer path is introduced. + +The camera sites were cross-checked by normalized instruction-window matching from the local 1.0.0 main. The viewport routine has two matching copies: both are patched. Other sites were checked through their data flow: the equipment timer and its gate, the map clock, the ability clock, the NVN texture storage/package calls, the shadow size publication and the cascade parameter constructor. FOV's s8 is overwritten by the next original instruction; x10 is saved. The cursor sites use the same scratch registers as their 1.2.1 counterparts. + +## Deliberately separate + +- Direct mouse: 1.1.0 continues to use stick emulation. Porting the complete camera hook set also needs the runtime layout and load-site table; matching an individual store or one camera mode is not sufficient. No partial set is enabled here. +- Fade: the four 1.4.3 sites are not presumed to exist in 1.1.0. An equivalent zero-increment path has not been established. +- Native Zstandard: the existing host bridge calls back to hard-coded 1.4.3 decoder entry points on fallback. Adding only the BL patches to 1.1.0 would be incorrect. +- Live DLSS scene sizing and game-menu mouse input retain their existing version restrictions. They are not patch-table parity work. + +## Validation + +Run with Python's numpy, lz4, capstone and unicorn dependencies and a runtime-supported Clang: + +```sh +# CC selects the Clang used by the differential harness. +python tests/patches_v110_check.py +python tests/patches_v110_check.py --cflags=-march=x86-64-v2 +python tests/patches_v110_check.py --exefs +``` + +Without ExeFS, the test uses synthetic memory and the patch table only. It compares the complete integer/SIMD register state, SP and NZCV of the lifted C and Unicorn for all 17 additions, on and off, at 30/60/120 Hz, including pool offsets immediately below and above 2 GiB and at the end of the 32-bit range. Windows test mappings respect its 64 KiB allocation granularity. With ExeFS it additionally validates every original word and spin target. Extracted images and generated C are local build artifacts, never repository content. + +These checks establish instruction and code-generation contracts. World-scene visual acceptance, texture packs allocating a pool above 2 GiB, physical gyro and comparisons of shadow quality still require gameplay checks. diff --git a/tests/patches_v110_check.py b/tests/patches_v110_check.py new file mode 100644 index 00000000..bb4e8b48 --- /dev/null +++ b/tests/patches_v110_check.py @@ -0,0 +1,153 @@ +"""Check the v110 patch contracts without game data; optionally check every site and spin against local ExeFS. + +python tests/patches_v110_check.py --exefs [--cflags=-march=x86-64-v2] +Uses the differential harness, Clang (CC) and Unicorn. Extracted bytes and generated C stay in build/. +""" +import argparse +import math +import struct +import sys +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +sys.path.insert(0, str(ROOT / 'tests' / 'diff')) +from common import BUF, BUF_SIZE, Emu, build_harness, diff_state, run_harness +import patches +from lifter import Lifter +from layout import layout +from module import Module + +# Set, offset, target register, result kind. The patch file owns the instruction words. +SITES = [ + ('realtime', 0xa20518, 1, 'zero'), + ('cursor', 0xf31e80, 0, 'map'), + ('cursor', 0x1d55f24, 12, 'aim'), + ('cursor', 0x1d556a4, 3, 'gyro'), + *[('aspect', a, 0, 'aspect') for a in (0xcdbf30, 0x1261a64, 0x19c2260, 0x1ed8fa4)], + *[('fov', a, 0, 'fov') for a in (0xcdbef8, 0x1261a2c)], + ('pooloff', 0x9b93a8, 2, 'offset'), ('pooloff', 0x9b93c4, 1, 'source'), + ('shadow', 0xd0760c, 11, 'shadow'), + *[('cascade', a, 8, 'cascade') for a in (0x1157fb8, 0x1158040, 0x11580c8, 0x115814c)], +] + + +def f32(v): + return struct.unpack('x[30]) { ' + ' '.join(i.code for i in replacement) + + ' } else { ' + original.code + ' }') + words.append((orig, repl)) + build = ROOT / 'build' + build.mkdir(exist_ok=True) + groups = {ratio: ([], []) for ratio in (1.0, 0.5, 0.25)} + page = bytearray(0x1000) + # Distinct fields reveal an accidental load from the neighboring page slot. + for off, value in ((0, 0.5), (4, 1 / 60), (56, 21 / 9), (60, 1.2), + (64, 25), (68, 50), (72, 100), (76, 200)): + struct.pack_into(' Date: Mon, 9 Nov 2026 08:44:44 +0800 Subject: [PATCH 05/56] Describe 1.1.0 field of view support and strengthen patch preservation checks --- runtime/ui_text.c | 8 ++++---- tests/patches_v110_check.py | 29 ++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/runtime/ui_text.c b/runtime/ui_text.c index fd74a07f..00afeec6 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -84,7 +84,7 @@ static const char *const text_en[UI_TEXT_COUNT] = { "bars, or stretch them over the whole picture. Applies from the next movie.", [UI_MENU_MOVIE_ASPECT_KEEP] = "Black bars", [UI_MENU_MOVIE_ASPECT_STRETCH] = "Stretch", [UI_MENU_FOV] = "Field of view", - [UI_MENU_FOV_DESC] = "How much of the world the camera shows, in percent of the game's own. Game version 1.4.3 only.", + [UI_MENU_FOV_DESC] = "How much of the world the camera shows, in percent of the game's own. Game versions 1.1.0 and 1.4.3.", [UI_MENU_SHADOW_RES] = "Shadow map size", [UI_MENU_SHADOW_RES_DESC] = "Size of the sun's shadow map. The game's own size changes with the view, down to about 400 " "near the ground, so leaf shadows look blocky and jump; a fixed size keeps them still and " @@ -561,7 +561,7 @@ static const char *const text_ru[UI_TEXT_COUNT] = { "растянуть их на всю картинку. Действует со следующего ролика.", [UI_MENU_MOVIE_ASPECT_KEEP] = "Чёрные полосы", [UI_MENU_MOVIE_ASPECT_STRETCH] = "Растянуть", [UI_MENU_FOV] = "Поле зрения", - [UI_MENU_FOV_DESC] = "Сколько мира показывает камера, в процентах от игрового. Только для версии игры 1.4.3.", + [UI_MENU_FOV_DESC] = "Сколько мира показывает камера, в процентах от игрового. Для версий игры 1.1.0 и 1.4.3.", [UI_MENU_SHADOW_RES] = "Размер карты теней", [UI_MENU_SHADOW_RES_DESC] = "Размер карты теней от солнца. Собственный размер игры меняется вместе с видом, у земли до " "примерно 400, поэтому тени листвы выглядят квадратными и дёргаются; постоянный размер делает " @@ -1336,7 +1336,7 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { [UI_MENU_OV_FMT_FSR] = "AMD FSR 1, nitidez %d%%", [UI_MENU_OV_SCALE_NONE] = "nenhuma (1:1)", [UI_MENU_OV_SCALE_BILINEAR] = "bilinear", [UI_MENU_FOV] = "Campo de visão", - [UI_MENU_FOV_DESC] = "Quanto do mundo a câmera mostra, em porcentagem do original do jogo. Só na versão 1.4.3 do " + [UI_MENU_FOV_DESC] = "Quanto do mundo a câmera mostra, em porcentagem do original do jogo. Nas versões 1.1.0 e 1.4.3 do " "jogo.", [UI_MENU_SHADOW_RES] = "Tamanho do mapa de sombras", [UI_MENU_SHADOW_RES_DESC] = "Tamanho do mapa de sombras do sol. O tamanho do jogo muda com a vista, até cerca de " @@ -1606,7 +1606,7 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { [UI_MENU_MOVIE_ASPECT_STRETCH] = "拉伸", [UI_MENU_FOV] = "视野", [UI_MENU_FOV_DESC] = "镜头能看到多大范围,以游戏自身视野的百分比表示。" - "仅限游戏版本 1.4.3。", + "支持游戏版本 1.1.0 和 1.4.3。", [UI_MENU_SHARPNESS] = "FSR 锐度", [UI_MENU_SHARPNESS_DESC] = "FSR 缩放后的锐化强度;0 为关闭。", [UI_MENU_COLOR] = "色彩", diff --git a/tests/patches_v110_check.py b/tests/patches_v110_check.py index bb4e8b48..8b8774cf 100644 --- a/tests/patches_v110_check.py +++ b/tests/patches_v110_check.py @@ -8,6 +8,7 @@ import math import struct import sys import tempfile +import zlib from pathlib import Path ROOT = Path(__file__).resolve().parents[1] @@ -45,7 +46,9 @@ def main(): ap.add_argument('--exefs', type=Path) ap.add_argument('--cflags', default='-march=x86-64-v3') args = ap.parse_args() - mods = layout(args.exefs) if args.exefs else [('main', 0x7000000000, 0x472d000)] + mods = layout(args.exefs) if args.exefs else [ + ('main', 0x7000000000, 0x472d000), ('subsdk0', 0x7004800000, 0x400000), + ('sdk', 0x7004c00000, 0x800000)] table = patches.load(ROOT / 'recomp' / 'patches-v110.txt', mods) base = mods[0][1] if args.exefs: @@ -100,10 +103,11 @@ def main(): struct.pack_into('<' + 'I' * len(code), text, pc - lo, *code) emu = Emu([(lo, text), (table.page, page)]) emu.mu.mem_write(BUF, bytes(mem)) - x = [BUF + 0x2000] * 31 - x[8] = BUF + 0x2000 + x = [0x1234567800000000 + i for i in range(31)] + for i in (8, 19, 20, 23, 27): + x[i] = BUF + 0x2000 x[25], x[30] = offset, enabled - v = [int.from_bytes(struct.pack(' Date: Mon, 9 Nov 2026 08:59:35 +0800 Subject: [PATCH 06/56] Keep the texture offset attribution in the component table --- THIRD_PARTY_NOTICES.md | 1 - 1 file changed, 1 deletion(-) diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index b430cc01..3e18c860 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -41,7 +41,6 @@ Code copied or adapted from another project is listed here with its source, the | AMD Display Library (ADL) declarations: `AdapterInfo`, `ADLSingleSensorData`, `ADLPMLogDataOutput`, the `ADL_PMLOG_*` sensor numbers and the `ADL2_*` function signatures | https://github.com/GPUOpen-LibrariesAndSDKs/display-library @ `84c881cb2136f04287eb3af12de00a9e2867aa9e` (`include/adl_structures.h`, `include/adl_defines.h`, `include/adl_sdk.h`), Copyright (c) 2016 - 2022 Advanced Micro Devices, Inc. | MIT | `runtime/perfmon.c` | | Zstandard 1.5.7 (MSYS2 `mingw-w64-ucrt-x86_64-zstd`), static link | https://github.com/facebook/zstd, Copyright (c) Meta Platforms, Inc. and affiliates | BSD-3-Clause | `runtime/resolution.c` (the HeapDef table), `runtime/ov_zstd.c` (the game's zstd frames decoded on the host) | | musl `fma.c`, `fmaf.c` and `scalbn.c`, adapted into one file for the x86-64-v2 build | https://github.com/kraj/musl @ `5a56ad13e1e0790c06122978aad2a14d6b9efc1a` (mirror of https://git.musl-libc.org/cgit/musl), Copyright (c) 2005-2020 Rich Felker and contributors | MIT | `runtime/fma.c` (the correctly rounded fma/fmaf the FP lowering needs on CPUs without FMA3) | - | MacNativeGames texture pool offset fix: widen the 32-bit texture storage and packaged-data offsets unsigned | https://github.com/ly05010419/MacNativeGames @ `ca311e2d` (`games/totk/runtime/game_patches.c` patch_pool_offset), Copyright (c) 2026 MacNativeGames contributors | MIT | `recomp/patches-v110.txt` (set pooloff; sites located again in 1.1.0) | ## Compiler runtime in a source build From 68b918933fe21c134cc7089e25634392195344e7 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Mon, 9 Nov 2026 09:13:09 +0800 Subject: [PATCH 07/56] Check every SIMD register for integer-only patch preservation --- tests/patches_v110_check.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/patches_v110_check.py b/tests/patches_v110_check.py index 8b8774cf..f0f53bfd 100644 --- a/tests/patches_v110_check.py +++ b/tests/patches_v110_check.py @@ -133,7 +133,8 @@ def main(): if name in ('aspect', 'fov'): assert ex[10] == x[10] allowed_x = {target} if kind in ('offset', 'source', 'shadow', 'cascade') else {9} if kind == 'map' else set() - allowed_v = {0, 1} if kind == 'map' else {target} + # Integer destinations do not authorize writes to the same-numbered SIMD register. + allowed_v = set() if kind in ('offset', 'source', 'shadow', 'cascade') else {0, 1} if kind == 'map' else {target} if enabled and kind in ('map', 'aim', 'gyro'): allowed_v |= {16} if kind == 'map': From bbd63f972079491cd6df811dc51eda328c6444bb Mon Sep 17 00:00:00 2001 From: jay23606 Date: Tue, 10 Nov 2026 09:24:56 -0500 Subject: [PATCH 08/56] Address review feedback --- tests/release_linux_apprun_test.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/release_linux_apprun_test.py b/tests/release_linux_apprun_test.py index 8aaa7c7f..5a5c31c0 100644 --- a/tests/release_linux_apprun_test.py +++ b/tests/release_linux_apprun_test.py @@ -41,6 +41,16 @@ with tempfile.TemporaryDirectory() as tmp: shadow.mkdir(parents=True) (shadow / '__init__.py').write_text('# stands in for the PyPI "installer" package: no gui submodule\n') + # The test only means something if this interpreter would put the user site on sys.path without AppRun's + # setting. A venv has no user site, so run it with the system Python; otherwise the shadow is never tried. + probe_env = dict(env) + probe_env.pop('PYTHONNOUSERSITE', None) + probe = subprocess.run([sys.executable, '-c', 'import sys; print(sys.argv[1] in sys.path)', str(user_site)], + env=probe_env, capture_output=True, text=True, cwd=tmp) + assert probe.stdout.strip() == 'True', ( + f'user site {user_site} is not on sys.path for {sys.executable}; run this test with the system Python, ' + 'not a venv, or it cannot catch the shadowing') + bundle = tmp / 'bundle' (bundle / 'installer').mkdir(parents=True) (bundle / 'installer' / '__init__.py').write_text('') From 2a564f648c408b5b2b8dedf3b6171d03825c2afa Mon Sep 17 00:00:00 2001 From: itaskaev2 <165683571+itaskaev2@users.noreply.github.com> Date: Tue, 10 Nov 2026 18:11:32 +0100 Subject: [PATCH 09/56] Describe climb_fix in totk.ini.example tests/settings_doc_check.py failed on v0.4.0: CLIMB_FIX is in known[] and described in neither file. It is a player setting with a menu toggle under [frame rate], so it goes next to highfps_fix; frame_rate.c turns it off without the real-time step. Co-Authored-By: Claude Opus 5.5 --- totk.ini.example | 2 ++ 1 file changed, 2 insertions(+) diff --git a/totk.ini.example b/totk.ini.example index c45a74b2..2c986cb9 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -26,6 +26,8 @@ # cloth_realtime = 1 # Fix for physics that bounce at high frame rates. # highfps_fix = 1 +# Climbing walls and ladders at full speed above 60 fps; 30 and 60 fps are unchanged. Needs realtime = 1. +# climb_fix = 1 [performance] # The keys of this section and of [diagnostics] are for testing and troubleshooting, and take effect at the next start. From 3209ea4358b43325e5c8f04dc30a517befcdd016 Mon Sep 17 00:00:00 2001 From: Tears of the SteelTemple Date: Sat, 7 Nov 2026 12:17:17 +0200 Subject: [PATCH 10/56] Implement Native NVIDIA Reflex Low Latency (VK_NV_low_latency2) - Enable VK_NV_low_latency2 and VK_KHR_present_id with present ID features - Add VkSwapchainLatencyCreateInfoNV to swapchain creation - Link present and submission IDs with standard Vulkan latency types - Insert latency markers: simulation start/end, input sample, render submit, and present - Gate all extensions and latency chains on reflex != off (RESTART setting) - Log graceful notice when Reflex is requested on unsupported hardware - Add UI menu setting and translations for en, ru, pt-BR, zh-Hans - Document reflex setting in totk.ini.example and docs/settings.md --- docs/settings.md | 1 + runtime/cfg.c | 6 +- runtime/gfx_present.c | 131 +++++++++++++++++++++++++++++++++++++++++- runtime/nvn_api_obj.c | 6 ++ runtime/ov_input.c | 3 + runtime/ui/menu.cpp | 2 + runtime/ui_text.c | 20 +++++++ runtime/ui_text.h | 1 + runtime/vk.h | 7 ++- runtime/vk_device.c | 17 +++++- runtime/vk_sync.c | 8 +++ totk.ini.example | 3 + 12 files changed, 196 insertions(+), 9 deletions(-) diff --git a/docs/settings.md b/docs/settings.md index e1163426..da5ca279 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -178,6 +178,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`, `on`, or `boost`; enables NVIDIA Reflex Low Latency (`VK_NV_low_latency2`) to reduce system input latency. Read at start. | On NVIDIA GPUs supporting the extension, coordinates simulation and presentation cadence to lower latency; `boost` keeps GPU clocks high in CPU-bound scenes. Has no effect on non-NVIDIA GPUs. | Safe | ## Scheduling and host diff --git a/runtime/cfg.c b/runtime/cfg.c index dbb73f7d..7a802afe 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -53,7 +53,7 @@ static const char *const known[] = { "ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_SCENE", "PCORE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "PREWARM_XLATE", "PROBE_MOVIE", "PROBE_MOVIE_BENCH", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_CHAINS", "PROFILE_DIR", "PROFILE_FRAMES", "PROFILE_MAIN", "PROFILE_RENDER", "PROMPTS", "PUSH_SKIP", "PUSH_STAGE", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_ASYNC", "REC_END", "REC_SPIN_US", "REEXEC", - "RENDER_SCALE", "REPLAY_ASYNC", "REPLAY_CHUNKS", "REPLAY_CHUNK_DRAWS", "REPLAY_SKEW_US", "REPLAY_STATE_CHECK", "REPLAY_WORKERS", + "RENDER_SCALE", "REPLAY_ASYNC", "REPLAY_CHUNKS", "REPLAY_CHUNK_DRAWS", "REPLAY_SKEW_US", "REPLAY_STATE_CHECK", "REPLAY_WORKERS", "REFLEX", "REPLAY_CHECK", "RESOLVE_CHECK", "RESTART_WAIT", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES", "ROMFS_PROOF_DIR", "ROMFS_VERIFY", "RSTICK_DEADZONE", "RUMBLE", "RUMBLE_CURVE", "RUMBLE_STRENGTH", "RUMBLE_TRIGGERS", "SHADER_CACHE", "SHADER_MEMO", "SHADOW_DEFER", "SHADOW_RANGE", "SHADOW_RES", "SHADOW_SCALE", "SHADOW_SNAP", "SHARED_FONTS", "SHARPNESS", "SHOTS", "SHOTS_DIR", @@ -77,7 +77,7 @@ static const struct { const char *key, *section; } sections[] = { {"COLOR_BRIGHTNESS", "display"}, {"COLOR_CONTRAST", "display"}, {"COLOR_SATURATION", "display"}, {"COLOR_GAMMA", "display"}, {"HDR", "display"}, {"HDR_PEAK_NITS", "display"}, {"HDR_GAME_NITS", "display"}, {"HDR_UI_NITS", "display"}, {"HDR_HUE", "display"}, {"SHADOW_RES", "display"}, - {"DLAA", "display"}, {"DLSS", "display"}, {"DLSS_PRESET", "display"}, {"DLSS_CHAR_MASK", "display"}, {"FXAA", "display"}, + {"DLAA", "display"}, {"DLSS", "display"}, {"DLSS_PRESET", "display"}, {"DLSS_CHAR_MASK", "display"}, {"REFLEX", "display"}, {"FXAA", "display"}, {"DEVICE_PROFILE", "display"}, {"ASSUME_FOCUS", "display"}, {"DISCORD_RPC", "discord"}, {"DISCORD_APP_ID", "discord"}, {"DISCORD_IMAGE", "discord"}, {"SHADOW_SCALE", "display"}, {"SHADOW_RANGE", "display"}, {"CONTACT_SHADOWS", "display"}, @@ -124,7 +124,7 @@ static const CfgMeta metas[] = { {"UPSCALER", "fsr", "fsr|bilinear", LIVE}, {"SHARPNESS", "80", "0..100", LIVE}, {"DLAA", "0", "0|1", RESTART}, {"DLSS", "dlaa", "dlaa|quality|balanced|performance|ultra_performance", LIVE}, {"DLSS_PRESET", "default", "default|k|j", LIVE}, - {"DLSS_CHAR_MASK", "65", "0|35|65|100", LIVE}, {"FXAA", "1", "0|1", LIVE}, + {"DLSS_CHAR_MASK", "65", "0|35|65|100", LIVE}, {"REFLEX", "off", "off|on|boost", RESTART}, {"FXAA", "1", "0|1", LIVE}, {"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 // colour adjustment (vk_color.c); the preset is the menu's, the four values are what the present uses diff --git a/runtime/gfx_present.c b/runtime/gfx_present.c index f936b721..04b389da 100644 --- a/runtime/gfx_present.c +++ b/runtime/gfx_present.c @@ -239,6 +239,8 @@ unsigned gfx_window_focus_messages(void) { return (unsigned)g_focus_msgs; } // Present path (g_pl held): a settings change (cfg_version) reaches the window thread, which applies a changed size or // fullscreen; a changed TOTK_VK_PRESENT rebuilds the swapchain at this present. +static void reflex_apply_locked(void); + static void window_settings_live(void) { static unsigned seen; static int started; @@ -254,9 +256,108 @@ static void window_settings_live(void) { if (started) plat_xchg32(&g_dirty, 1); } if (started) gfx_window_apply_settings(); + reflex_apply_locked(); started = 1; } +// ---- NVIDIA Reflex Low Latency (VK_NV_low_latency2) +static PFN_vkSetLatencySleepModeNV g_reflex_set_mode; +static PFN_vkLatencySleepNV g_reflex_sleep; +static PFN_vkSetLatencyMarkerNV g_reflex_marker; +static VkSemaphore g_reflex_sem; +static uint64_t g_reflex_val; +static uint64_t g_reflex_present_id = 1; +static int g_reflex_mode = -1; // 0=off, 1=on, 2=boost +static uint32_t g_reflex_min_us = 1; + +static int reflex_mode_from_cfg(void) { + const char *v = cfg_value("TOTK_REFLEX"); + if (!v || !strcmp(v, "off") || !strcmp(v, "0")) return 0; + if (!strcmp(v, "boost") || !strcmp(v, "2")) return 2; + return 1; +} + +static void reflex_apply_locked(void) { + VkCtx *c = vk_ctx(); + if (!c || !c->has_nv_reflex || !g_sc) return; + if (!g_reflex_set_mode) { + g_reflex_set_mode = (PFN_vkSetLatencySleepModeNV)vkGetDeviceProcAddr(c->device, "vkSetLatencySleepModeNV"); + g_reflex_sleep = (PFN_vkLatencySleepNV)vkGetDeviceProcAddr(c->device, "vkLatencySleepNV"); + g_reflex_marker = (PFN_vkSetLatencyMarkerNV)vkGetDeviceProcAddr(c->device, "vkSetLatencyMarkerNV"); + } + if (!g_reflex_set_mode) return; + if (!g_reflex_sem) { + VkSemaphoreTypeCreateInfo ti = { + .sType = VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO, + .semaphoreType = VK_SEMAPHORE_TYPE_TIMELINE, + .initialValue = 0 + }; + VkSemaphoreCreateInfo si = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, .pNext = &ti}; + if (vkCreateSemaphore(c->device, &si, NULL, &g_reflex_sem) != VK_SUCCESS) return; + } + int mode = reflex_mode_from_cfg(); + uint32_t min_us = 0; + int limit = cfg_int("TOTK_FPS_LIMIT"); + if (limit > 0) min_us = (uint32_t)(1000000 / limit); + if (mode == g_reflex_mode && min_us == g_reflex_min_us) return; + g_reflex_mode = mode; + g_reflex_min_us = min_us; + VkLatencySleepModeInfoNV mi = { + .sType = VK_STRUCTURE_TYPE_LATENCY_SLEEP_MODE_INFO_NV, + .lowLatencyMode = mode > 0 ? VK_TRUE : VK_FALSE, + .lowLatencyBoost = mode == 2 ? VK_TRUE : VK_FALSE, + .minimumIntervalUs = min_us + }; + VkResult r = g_reflex_set_mode(c->device, g_sc, &mi); + rt_log("REFLEX: NVIDIA Reflex Low Latency -> %s (minInterval=%u us, VK_NV_low_latency2=%s)", + mode == 2 ? "ON + BOOST" : mode == 1 ? "ON" : "OFF", min_us, r == VK_SUCCESS ? "OK" : "ERR"); +} + +int vk_has_reflex(void) { + VkCtx *c = vk_ctx(); + return c && c->has_nv_reflex; +} + +uint64_t vk_reflex_current_present_id(void) { + return __atomic_load_n(&g_reflex_present_id, __ATOMIC_RELAXED); +} + +void vk_reflex_marker(int marker) { + VkCtx *c = vk_ctx(); + if (!c || !c->has_nv_reflex || !g_reflex_marker || g_reflex_mode <= 0 || !g_sc) return; + plat_rmutex_lock(&g_pl); + if (g_sc && g_reflex_marker) { + uint64_t pid = __atomic_load_n(&g_reflex_present_id, __ATOMIC_RELAXED); + VkSetLatencyMarkerInfoNV mi = { + .sType = VK_STRUCTURE_TYPE_SET_LATENCY_MARKER_INFO_NV, + .presentID = pid, + .marker = (VkLatencyMarkerNV)marker + }; + g_reflex_marker(c->device, g_sc, &mi); + } + plat_rmutex_unlock(&g_pl); +} + +void vk_reflex_sleep(void) { + VkCtx *c = vk_ctx(); + if (!c || !c->has_nv_reflex || !g_reflex_sleep || !g_reflex_sem || g_reflex_mode <= 0 || !g_sc) return; + uint64_t val = __atomic_add_fetch(&g_reflex_val, 1, __ATOMIC_RELAXED); + VkLatencySleepInfoNV si = { + .sType = VK_STRUCTURE_TYPE_LATENCY_SLEEP_INFO_NV, + .signalSemaphore = g_reflex_sem, + .value = val + }; + if (g_reflex_sleep(c->device, g_sc, &si) == VK_SUCCESS) { + VkSemaphoreWaitInfo wi = { + .sType = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO, + .semaphoreCount = 1, + .pSemaphores = &g_reflex_sem, + .pValues = &val + }; + vkWaitSemaphores(c->device, &wi, 100000000ULL); + } +} + // ---- swapchain static const char *g_present_got = ""; // the TOTK_VK_PRESENT value of the mode the swapchain got; "" before one @@ -289,12 +390,25 @@ static void flip_locked(void) { if (!g_flip_on) return; g_flip_on = 0; if (!g_sc) return; - VkPresentInfoKHR pi = {.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, .waitSemaphoreCount = 1, + VkCtx *c = vk_ctx(); + uint64_t pid = 0; + VkPresentIdKHR pid_info = {0}; + if (c && c->has_nv_reflex) { + pid = __atomic_add_fetch(&g_reflex_present_id, 1, __ATOMIC_RELAXED); + pid_info.sType = VK_STRUCTURE_TYPE_PRESENT_ID_KHR; + pid_info.swapchainCount = 1; + pid_info.pPresentIds = &pid; + vk_reflex_marker(4); // VK_LATENCY_MARKER_PRESENT_START_NV + } + VkPresentInfoKHR pi = {.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, + .pNext = (c && c->has_nv_reflex) ? &pid_info : NULL, + .waitSemaphoreCount = 1, .pWaitSemaphores = &g_render_done[g_flip_idx], .swapchainCount = 1, .pSwapchains = &g_sc, .pImageIndices = &g_flip_idx}; vk_queue_lock(); - VkResult r = vkQueuePresentKHR(vk_ctx()->gfx_queue, &pi); + VkResult r = vkQueuePresentKHR(c->gfx_queue, &pi); vk_queue_unlock(); + if (c && c->has_nv_reflex) vk_reflex_marker(5); // VK_LATENCY_MARKER_PRESENT_END_NV vk_device_fault_report(r); if (r == VK_ERROR_OUT_OF_DATE_KHR || r == VK_SUBOPTIMAL_KHR) plat_xchg32(&g_dirty, 1); } @@ -338,8 +452,14 @@ static int build_swapchain(void) { vk_queue_lock(); vkDeviceWaitIdle(c->device); VkSwapchainKHR old = g_sc; + VkSwapchainLatencyCreateInfoNV sci = { + .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_LATENCY_CREATE_INFO_NV, + .latencyModeEnable = VK_TRUE + }; VkSwapchainCreateInfoKHR ci = { - .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, .surface = g_surface, .minImageCount = count, + .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, + .pNext = (c->has_nv_reflex) ? &sci : NULL, + .surface = g_surface, .minImageCount = count, .imageFormat = sf.format, .imageColorSpace = sf.colorSpace, .imageExtent = ext, .imageArrayLayers = 1, .imageUsage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, // every surface supports it (the menu overlay draws into it) @@ -800,6 +920,11 @@ void gfx_window_release_vk(void) { vk_color_release(); vk_hdr_release(); vk_contact_release(); + if (g_reflex_sem) { + vkDestroySemaphore(c->device, g_reflex_sem, NULL); + g_reflex_sem = VK_NULL_HANDLE; + } + g_reflex_mode = -1; free_capture(); free_thumbs(); for (int i = 0; i < FRAMES; i++) { diff --git a/runtime/nvn_api_obj.c b/runtime/nvn_api_obj.c index 644acc8d..22fb03dd 100644 --- a/runtime/nvn_api_obj.c +++ b/runtime/nvn_api_obj.c @@ -19,6 +19,9 @@ #include "nvn_tex.h" #include "platform/platform.h" +void vk_reflex_marker(int marker); +void vk_reflex_sleep(void); + // ---------- Descriptor pools // NVNboolean nvnTexturePoolInitialize(NVNtexturePool *tp, const NVNmemoryPool *p, ptrdiff_t offset, int n) NVN_API(nvnTexturePoolInitialize) { @@ -687,6 +690,8 @@ NVN_API(nvnWindowAcquireTexture) { sleep_until(at); perf_end(PERF_PACE, p0); } + vk_reflex_sleep(); + vk_reflex_marker(0); // VK_LATENCY_MARKER_SIMULATION_START_NV // 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) { @@ -710,6 +715,7 @@ NVN_API(nvnQueuePresentTexture) { if (o->magic != NVN_WIN_MAGIC || idx < 0 || idx >= o->ntex || idx >= 4 || !o->tex[idx]) rt_fatal("nvn: QueuePresentTexture of image %d on window %p", idx, (void *)o); o->presents++; + vk_reflex_marker(1); // VK_LATENCY_MARKER_SIMULATION_END_NV const tex_t *t = (const tex_t *)o->tex[idx]; uint64_t period = present_period(o), now = kern_now_ns(); uint64_t slot = now + pace(&o->pace, now, period); diff --git a/runtime/ov_input.c b/runtime/ov_input.c index 3cbc6cfb..ac38f9c9 100644 --- a/runtime/ov_input.c +++ b/runtime/ov_input.c @@ -17,6 +17,8 @@ #include "ov.h" #include "platform/platform.h" +void vk_reflex_marker(int marker); + typedef struct { int64_t sampling; uint64_t buttons; int32_t lx, ly, rx, ry; uint32_t attributes, pad; } NpadState; typedef struct { int64_t sampling; int32_t x, y, dx, dy, wx, wy; uint32_t buttons, attributes; } MouseState; typedef struct { int64_t sampling; uint32_t modifiers, attributes; uint64_t keys[4]; } KeyboardState; @@ -93,6 +95,7 @@ static void npad_states(Cpu *c, uint32_t want) { if (live) { s.attributes = ATTR_CONNECTED; input_poll(&s.buttons, &s.lx, &s.ly, &s.rx, &s.ry); + vk_reflex_marker(6); // VK_LATENCY_MARKER_INPUT_SAMPLE_NV } *out = s; ret_x(c, 1); diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 2bed97ed..df366614 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -694,6 +694,8 @@ static void tab_screen(float scale) { static const UiTextId chars[] = {UI_MENU_DLSS_CHARS_OFF, UI_MENU_DLSS_CHARS_LIGHT, UI_MENU_DLSS_CHARS_MEDIUM, UI_MENU_DLSS_CHARS_FULL}; opt_choice("TOTK_DLSS_CHAR_MASK", UI_MENU_DLSS_CHARS, chars, 4, UI_MENU_DLSS_CHARS_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); opt_toggle("TOTK_FXAA", UI_MENU_FXAA, UI_MENU_FXAA_DESC); rows_color(); opt_group(UI_MENU_HDR_GROUP); diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 690383b7..5b1be433 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -166,6 +166,11 @@ 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_OFF] = "Off", + [UI_MENU_REFLEX_ON] = "On", + [UI_MENU_REFLEX_BOOST] = "On + Boost", [UI_MENU_FPS_LIMIT] = "Frame rate limit", [UI_MENU_FPS_LIMIT_DESC] = "The most frames per second the game draws. Above 60 is experimental and needs Game speed " @@ -649,6 +654,11 @@ 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. On + Boost удерживает высокие частоты GPU при упоре в процессор.", + [UI_MENU_REFLEX_OFF] = "Выкл", + [UI_MENU_REFLEX_ON] = "Вкл", + [UI_MENU_REFLEX_BOOST] = "Вкл + Ускорение", [UI_MENU_FPS_LIMIT] = "Ограничение частоты кадров", [UI_MENU_FPS_LIMIT_DESC] = "Наибольшее число кадров в секунду. Выше 60 — экспериментальный режим, нужна «Скорость " @@ -1486,6 +1496,11 @@ 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. On + Boost mantém os clocks da GPU altos quando limitado pela CPU.", + [UI_MENU_REFLEX_OFF] = "Desligado", + [UI_MENU_REFLEX_ON] = "Ligado", + [UI_MENU_REFLEX_BOOST] = "Ligado + Boost", [UI_MENU_TAB_CHEATS] = "Cheats", [UI_MENU_CHEATS_NONE] = "Nenhum cheat para esta versão do jogo. Os cheats de um mod são um arquivo de cheats do " "Atmosphere na pasta cheats dele, com o nome da build do jogo: mods\\\\cheats\\%s. " @@ -2096,6 +2111,11 @@ 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_OFF] = "关", + [UI_MENU_REFLEX_ON] = "开", + [UI_MENU_REFLEX_BOOST] = "开 + 增强", [UI_MENU_TAB_CHEATS] = "金手指", [UI_MENU_CHEATS_NONE] = "此游戏版本没有金手指。模组的金手指是它的 cheats 文件夹中以游戏构建命名的 Atmosphere " "金手指文件:mods\\<模组>\\cheats\\%s。重启游戏后才会读取。对于修改游戏代码的金手指," diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 3bed8949..04093308 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -59,6 +59,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, // Game UI_MENU_FPS_LIMIT, UI_MENU_FPS_LIMIT_DESC, UI_MENU_FPS_30, UI_MENU_FPS_40, UI_MENU_FPS_45, UI_MENU_FPS_60, UI_MENU_FPS_90, diff --git a/runtime/vk.h b/runtime/vk.h index bb705ebd..23d78fe8 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -36,7 +36,8 @@ typedef struct VkCtx { has_nv_checkpoints, // VK_NV_device_diagnostic_checkpoints (TOTK_PASS_CRUMBS=1, vk_crumbs.c) 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_hdr_metadata, // VK_EXT_hdr_metadata (vk_hdr.c vk_hdr_metadata) + has_nv_reflex; // VK_NV_low_latency2 (NVIDIA Reflex Low Latency) // 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 @@ -147,6 +148,10 @@ void vk_present_blit(VkImage src, VkImageLayout layout, VkFormat fmt, int w, int int vk_fsr_record(VkCommandBuffer cb, unsigned slot, VkImage src, VkFormat fmt, int sw, int sh, const int crop[4], VkImage dst, const int out[4]); void vk_fsr_release(void); // before the device goes away +void vk_reflex_marker(int marker); +void vk_reflex_sleep(void); +int vk_has_reflex(void); +uint64_t vk_reflex_current_present_id(void); // Colour adjustment on the present (vk_color.c): with TOTK_COLOR_* away from their defaults, records a pass that writes // src's crop rectangle {x, y, w, h}, adjusted, into an RGBA16F image of that size in GENERAL and returns it (the caller // scales that one instead, crop {0, 0, w, h}); VK_NULL_HANDLE = nothing recorded. src is in GENERAL, fmt its format. diff --git a/runtime/vk_device.c b/runtime/vk_device.c index 760a3a46..6a613450 100644 --- a/runtime/vk_device.c +++ b/runtime/vk_device.c @@ -283,6 +283,7 @@ typedef struct { VkPhysicalDeviceAttachmentFeedbackLoopLayoutFeaturesEXT fbl; VkPhysicalDeviceDynamicRenderingLocalReadFeaturesKHR lr; VkPhysicalDeviceAddressBindingReportFeaturesEXT abr; + VkPhysicalDevicePresentIdFeaturesKHR pid; } FeatureChain; static int create_device(void) { @@ -290,7 +291,7 @@ static int create_device(void) { vkEnumerateDeviceExtensionProperties(g_vk.phys, NULL, &ne, NULL); VkExtensionProperties *ep = calloc(ne ? ne : 1, sizeof *ep); vkEnumerateDeviceExtensionProperties(g_vk.phys, NULL, &ne, ep); - const char *ext[48]; + const char *ext[52]; uint32_t n_ext = 0; for (size_t i = 0; i < sizeof k_required_ext / sizeof *k_required_ext; i++) ext[n_ext++] = k_required_ext[i]; @@ -334,7 +335,7 @@ static int create_device(void) { CHAIN(fbl, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ATTACHMENT_FEEDBACK_LOOP_LAYOUT_FEATURES_EXT); CHAIN(lr, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_LOCAL_READ_FEATURES_KHR); } - vk_dlaa_device_exts(ep, ne, ext, &n_ext, 40); // NGX's; the eight slots after it stay for the seven below + vk_dlaa_device_exts(ep, ne, ext, &n_ext, 40); // NGX's; the twelve slots after it stay for the nine below if (has_ext(ep, ne, VK_EXT_MEMORY_BUDGET_EXTENSION_NAME)) { g_vk.has_memory_budget = 1; ext[n_ext++] = VK_EXT_MEMORY_BUDGET_EXTENSION_NAME; } // GPU timestamps on the CPU clock (vk_sync.c): the perf line splits GPU idle time into waiting for a submission or not. if (has_ext(ep, ne, VK_KHR_CALIBRATED_TIMESTAMPS_EXTENSION_NAME)) { g_vk.has_calibrated = 2; ext[n_ext++] = VK_KHR_CALIBRATED_TIMESTAMPS_EXTENSION_NAME; } @@ -351,6 +352,18 @@ 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) + const char *rv = cfg_value("TOTK_REFLEX"); + if (rv && 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 { + 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. void **gpl_link = NULL; if (has_ext(ep, ne, VK_KHR_PIPELINE_LIBRARY_EXTENSION_NAME) && has_ext(ep, ne, VK_EXT_GRAPHICS_PIPELINE_LIBRARY_EXTENSION_NAME)) { diff --git a/runtime/vk_sync.c b/runtime/vk_sync.c index 6626e96f..40421122 100644 --- a/runtime/vk_sync.c +++ b/runtime/vk_sync.c @@ -474,12 +474,20 @@ uint64_t vk_sync_submit(const uint64_t *handles, int n) { {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO, .commandBuffer = s->cb}}; VkSemaphoreSubmitInfo sig = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO, .semaphore = c->timeline, .value = fence, .stageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT}; + VkLatencySubmissionPresentIdNV lsid = { + .sType = VK_STRUCTURE_TYPE_LATENCY_SUBMISSION_PRESENT_ID_NV, + .pNext = NULL, + .presentID = vk_reflex_current_present_id() + }; VkSubmitInfo2 si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2, + .pNext = (c->has_nv_reflex) ? &lsid : NULL, .commandBufferInfoCount = (pro ? 1u : 0u) + (recorded ? 1u : 0u), .pCommandBufferInfos = pro ? cbi : cbi + 1, .signalSemaphoreInfoCount = 1, .pSignalSemaphoreInfos = &sig}; ts_submitted(); + if (recorded && c->has_nv_reflex) vk_reflex_marker(2); // VK_LATENCY_MARKER_RENDERSUBMIT_START_NV VkResult r = rec_submit(&si); // by the recorder when it recorded the part + if (recorded && c->has_nv_reflex) vk_reflex_marker(3); // VK_LATENCY_MARKER_RENDERSUBMIT_END_NV if (r != VK_SUCCESS) { vk_device_fault_report(r); rt_fatal("vk: vkQueueSubmit2 of value %llu failed (%d)", (unsigned long long)fence, (int)r); diff --git a/totk.ini.example b/totk.ini.example index c45a74b2..b7fd8962 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -259,6 +259,9 @@ # frame before, DLSS is told to favour the current frame by this percentage (0, 35, 65 or 100; 0 off). Higher removes # more of the trails and leaves those edges a little less smooth. Changes while the game runs take effect at once. # dlss_char_mask = 65 +# NVIDIA Reflex Low Latency (NVIDIA GPUs supporting VK_NV_low_latency2): off, on, or boost. +# Reduces system input latency; boost keeps GPU clocks high in CPU-bound scenes. 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. # fxaa = 1 From c811d0e06d0a8721e87a2ac84315cc389eaa91d5 Mon Sep 17 00:00:00 2001 From: itaskaev2 <165683571+itaskaev2@users.noreply.github.com> Date: Sat, 7 Nov 2026 10:54:55 +0100 Subject: [PATCH 11/56] Carry Reflex's present ID through the recorder's submission vk_sync_submit chains a VkLatencySubmissionPresentIdNV when the device has VK_NV_low_latency2, and on dev the recorder thread (on by default except on AMD) makes that submission. rec_submit stopped the process on any pNext, so every NVIDIA GPU with the extension would have failed at its first recorded submission. The recorder now copies the present ID into its packet and chains it again in submit_run. Co-Authored-By: Claude Opus 5.5 --- runtime/vk_rec.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/runtime/vk_rec.c b/runtime/vk_rec.c index f0fa9835..ee664c29 100644 --- a/runtime/vk_rec.c +++ b/runtime/vk_rec.c @@ -318,8 +318,14 @@ int rec_end_cb(VkCommandBuffer cb, int crumb, uint64_t n) { return 1; } -// At most two command buffers and one signal: the shape vk_sync.c submits. -typedef struct { uint32_t ncb, nsig; VkCommandBufferSubmitInfo cbi[2]; VkSemaphoreSubmitInfo sig; } A_Submit; +// At most two command buffers and one signal: the shape vk_sync.c submits. The only pNext it chains is Reflex's +// VkLatencySubmissionPresentIdNV (vk_sync_submit), carried as its present ID. +typedef struct { + uint32_t ncb, nsig, has_pid; + uint64_t present_id; + VkCommandBufferSubmitInfo cbi[2]; + VkSemaphoreSubmitInfo sig; +} A_Submit; VkResult rec_submit(const VkSubmitInfo2 *si) { if (!sub_pending) { vk_queue_lock(); @@ -328,12 +334,16 @@ VkResult rec_submit(const VkSubmitInfo2 *si) { return r; } sub_pending = 0; - if (si->commandBufferInfoCount > 2 || si->signalSemaphoreInfoCount > 1 || si->waitSemaphoreInfoCount || si->pNext) + const VkBaseInStructure *nx = si->pNext; + int pid = nx && nx->sType == VK_STRUCTURE_TYPE_LATENCY_SUBMISSION_PRESENT_ID_NV && !nx->pNext; + if (si->commandBufferInfoCount > 2 || si->signalSemaphoreInfoCount > 1 || si->waitSemaphoreInfoCount || + (nx && !pid)) rt_fatal("vk_rec: a submission of %u command buffers, %u waits and %u signals the recorder cannot carry", si->commandBufferInfoCount, si->waitSemaphoreInfoCount, si->signalSemaphoreInfoCount); A_Submit *a = put(R_Submit, sizeof *a); memset(a, 0, sizeof *a); a->ncb = si->commandBufferInfoCount, a->nsig = si->signalSemaphoreInfoCount; + if (pid) a->has_pid = 1, a->present_id = ((const VkLatencySubmissionPresentIdNV *)nx)->presentID; for (uint32_t i = 0; i < a->ncb; i++) a->cbi[i] = si->pCommandBufferInfos[i]; if (a->nsig) a->sig = si->pSignalSemaphoreInfos[0]; __atomic_store_n(&q_subs, q_subs + 1, __ATOMIC_RELEASE); @@ -354,7 +364,10 @@ VkResult rec_submit(const VkSubmitInfo2 *si) { } static void submit_run(const A_Submit *a) { - VkSubmitInfo2 si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2, .commandBufferInfoCount = a->ncb, + VkLatencySubmissionPresentIdNV lsid = {.sType = VK_STRUCTURE_TYPE_LATENCY_SUBMISSION_PRESENT_ID_NV, + .presentID = a->present_id}; + VkSubmitInfo2 si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2, .pNext = a->has_pid ? &lsid : NULL, + .commandBufferInfoCount = a->ncb, .pCommandBufferInfos = a->cbi, .signalSemaphoreInfoCount = a->nsig, .pSignalSemaphoreInfos = a->nsig ? &a->sig : NULL}; vk_queue_lock(); From 41623cec85cdc1e5f19e0ac95b13558d6972d306 Mon Sep 17 00:00:00 2001 From: itaskaev2 <165683571+itaskaev2@users.noreply.github.com> Date: Sat, 7 Nov 2026 12:46:15 +0100 Subject: [PATCH 12/56] Call vkLatencySleepNV under the present lock The swapchain must be externally synchronised, and the acquire and the present use it under g_pl on the present thread while the game thread calls vk_reflex_sleep. With reflex = boost and TOTK_VK_VALIDATION=1 the validation layer reported 20 threading errors in 30 s (vkLatencySleepNV against vkAcquireNextImageKHR and vkQueuePresentKHR). The earlier head of #638 (318acd8) took the lock here; the rebase onto dev lost it. The semaphore wait stays outside. Co-Authored-By: Claude Opus 5.5 --- runtime/gfx_present.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/runtime/gfx_present.c b/runtime/gfx_present.c index 04b389da..9692afc1 100644 --- a/runtime/gfx_present.c +++ b/runtime/gfx_present.c @@ -347,7 +347,13 @@ void vk_reflex_sleep(void) { .signalSemaphore = g_reflex_sem, .value = val }; - if (g_reflex_sleep(c->device, g_sc, &si) == VK_SUCCESS) { + // vkLatencySleepNV uses the swapchain, which Vulkan wants externally synchronised with the acquire and the present + // (they run under g_pl on the present thread). The wait for the semaphore stays outside the lock. + VkResult r = VK_ERROR_INITIALIZATION_FAILED; + plat_rmutex_lock(&g_pl); + if (g_sc) r = g_reflex_sleep(c->device, g_sc, &si); + plat_rmutex_unlock(&g_pl); + if (r == VK_SUCCESS) { VkSemaphoreWaitInfo wi = { .sType = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO, .semaphoreCount = 1, From 6d6b66461bdfd1796b52cbce2f65c95148cfbf3e Mon Sep 17 00:00:00 2001 From: itaskaev2 <165683571+itaskaev2@users.noreply.github.com> Date: Tue, 10 Nov 2026 17:39:38 +0100 Subject: [PATCH 13/56] Reflex: one present ID per frame from its start to its present; mode again on a new swapchain; presentId feature The latency markers and the present carried different present IDs: g_reflex_present_id went up only in flip_locked, so frame k's simulation, input and submits had ID k and its present k+1 (and with frame_queue or replay_async frames could share one). Each frame now gets its ID once, when the game acquires its window texture (SIMULATION_START, vk_reflex_frame_begin), and carries it: INPUT_SAMPLE and SIMULATION_END take the game's current frame, a submission the frame of the thread that submits it (the game thread's, or the one the replay thread got with its ReplayItem, or the present thread's from its PresentJob), and the present the frame of its blit (PresentJob.pid -> g_flip_pid). A present without a frame ID takes the next value, as present IDs must grow on a swapchain. From the review: a new swapchain sets the sleep mode again (it starts with low latency off), Reflex is off without the presentId feature, REFLEX sorted in known[], and the ru and pt-BR descriptions name the Boost option as the menu does. TOTK_TRACE=perf logs every 600 presents the frame start to present time, and with Reflex on how many of the driver's reports (vkGetLatencyTimingsNV) came back with every marker and their simulation start to GPU render end. Co-Authored-By: Claude Opus 5.5 --- runtime/cfg.c | 4 +- runtime/gfx_present.c | 95 +++++++++++++++++++++++++++++++++++++++---- runtime/nvn_api_obj.c | 8 ++-- runtime/ov_input.c | 5 ++- runtime/ui_text.c | 4 +- runtime/vk.h | 8 +++- runtime/vk_backend.c | 19 +++++---- runtime/vk_device.c | 5 +++ runtime/vk_sync.c | 6 +-- 9 files changed, 123 insertions(+), 31 deletions(-) diff --git a/runtime/cfg.c b/runtime/cfg.c index 7a802afe..10f55b78 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -52,8 +52,8 @@ static const char *const known[] = { "MV_SURVEY", "ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_SCENE", "PCORE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "PREWARM_XLATE", "PROBE_MOVIE", "PROBE_MOVIE_BENCH", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_CHAINS", "PROFILE_DIR", "PROFILE_FRAMES", - "PROFILE_MAIN", "PROFILE_RENDER", "PROMPTS", "PUSH_SKIP", "PUSH_STAGE", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_ASYNC", "REC_END", "REC_SPIN_US", "REEXEC", - "RENDER_SCALE", "REPLAY_ASYNC", "REPLAY_CHUNKS", "REPLAY_CHUNK_DRAWS", "REPLAY_SKEW_US", "REPLAY_STATE_CHECK", "REPLAY_WORKERS", "REFLEX", + "PROFILE_MAIN", "PROFILE_RENDER", "PROMPTS", "PUSH_SKIP", "PUSH_STAGE", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_ASYNC", "REC_END", "REC_SPIN_US", "REEXEC", "REFLEX", + "RENDER_SCALE", "REPLAY_ASYNC", "REPLAY_CHUNKS", "REPLAY_CHUNK_DRAWS", "REPLAY_SKEW_US", "REPLAY_STATE_CHECK", "REPLAY_WORKERS", "REPLAY_CHECK", "RESOLVE_CHECK", "RESTART_WAIT", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES", "ROMFS_PROOF_DIR", "ROMFS_VERIFY", "RSTICK_DEADZONE", "RUMBLE", "RUMBLE_CURVE", "RUMBLE_STRENGTH", "RUMBLE_TRIGGERS", "SHADER_CACHE", "SHADER_MEMO", "SHADOW_DEFER", "SHADOW_RANGE", "SHADOW_RES", "SHADOW_SCALE", "SHADOW_SNAP", "SHARED_FONTS", "SHARPNESS", "SHOTS", "SHOTS_DIR", diff --git a/runtime/gfx_present.c b/runtime/gfx_present.c index 9692afc1..53d47e19 100644 --- a/runtime/gfx_present.c +++ b/runtime/gfx_present.c @@ -266,7 +266,16 @@ static PFN_vkLatencySleepNV g_reflex_sleep; static PFN_vkSetLatencyMarkerNV g_reflex_marker; static VkSemaphore g_reflex_sem; static uint64_t g_reflex_val; -static uint64_t g_reflex_present_id = 1; +// Present IDs (VK_KHR_present_id, VK_NV_low_latency2): each frame gets its ID once, when the game acquires its window +// texture (SIMULATION_START, vk_reflex_frame_begin), and the frame carries it to its input sample, its submissions +// (vk_reflex_submit_id: the game thread's current frame, or the frame a replay or present thread set for the work it +// does) and its present (PresentJob.pid, vk_reflex_present_frame, flip_locked), so the driver can match every marker +// of a frame to the present of that frame. +static uint64_t g_reflex_frame_next; // the last ID handed out +static uint64_t g_reflex_frame; // the frame the game simulates now +static _Thread_local uint64_t t_reflex_submit; // the frame whose work this thread submits; 0: g_reflex_frame +static uint64_t g_blit_pid, g_flip_pid; // the frame of the blit being made and of the present waiting (g_pl) +static uint64_t g_last_pid; // the last present ID presented (g_pl): present IDs only go up static int g_reflex_mode = -1; // 0=off, 1=on, 2=boost static uint32_t g_reflex_min_us = 1; @@ -318,16 +327,75 @@ int vk_has_reflex(void) { return c && c->has_nv_reflex; } -uint64_t vk_reflex_current_present_id(void) { - return __atomic_load_n(&g_reflex_present_id, __ATOMIC_RELAXED); +// TOTK_TRACE=perf, every LAT_EVERY presents: the time from a frame's start (its window texture acquired) to its +// present call on the host, with Reflex off or on, and with Reflex on the driver's own reports of the same frames +// (vkGetLatencyTimingsNV): how many came back with every marker matched to their present, and their simulation start +// to GPU render end. The frame's start is kept by its ID, so it also shows that a present carries its frame's ID. +#define LAT_RING 64 +#define LAT_EVERY 600 +static struct { uint64_t id, start_ns; } g_lat_start[LAT_RING]; +static struct { uint64_t n, ns, presents; } g_lat; +static PFN_vkGetLatencyTimingsNV g_reflex_timings; + +uint64_t vk_reflex_frame_begin(void) { + uint64_t id = __atomic_add_fetch(&g_reflex_frame_next, 1, __ATOMIC_RELAXED); + __atomic_store_n(&g_reflex_frame, id, __ATOMIC_RELAXED); + if (rt_trace & RT_TRACE_PERF) g_lat_start[id % LAT_RING].start_ns = kern_now_ns(), g_lat_start[id % LAT_RING].id = id; + return id; } -void vk_reflex_marker(int marker) { +// g_pl held, after the present of frame pid +static void latency_note(VkCtx *c, uint64_t pid) { + if (!(rt_trace & RT_TRACE_PERF) || !pid) return; + if (g_lat_start[pid % LAT_RING].id == pid) g_lat.n++, g_lat.ns += kern_now_ns() - g_lat_start[pid % LAT_RING].start_ns; + if (++g_lat.presents % LAT_EVERY) return; + char drv[200] = ""; + if (g_reflex_mode > 0 && g_sc) { + if (!g_reflex_timings) g_reflex_timings = (PFN_vkGetLatencyTimingsNV)vkGetDeviceProcAddr(c->device, "vkGetLatencyTimingsNV"); + static VkLatencyTimingsFrameReportNV rep[64]; + VkGetLatencyMarkerInfoNV gi = {.sType = VK_STRUCTURE_TYPE_GET_LATENCY_MARKER_INFO_NV}; + if (g_reflex_timings) { + g_reflex_timings(c->device, g_sc, &gi); // the count first + if (gi.timingCount > 64) gi.timingCount = 64; + for (uint32_t i = 0; i < gi.timingCount; i++) + rep[i] = (VkLatencyTimingsFrameReportNV){.sType = VK_STRUCTURE_TYPE_LATENCY_TIMINGS_FRAME_REPORT_NV}; + gi.pTimings = rep; + if (gi.timingCount) g_reflex_timings(c->device, g_sc, &gi); + uint32_t full = 0; + double sum = 0; + for (uint32_t i = 0; i < gi.timingCount; i++) { + const VkLatencyTimingsFrameReportNV *r = &rep[i]; + if (r->simStartTimeUs && r->simEndTimeUs && r->renderSubmitStartTimeUs && r->presentStartTimeUs && + r->gpuRenderEndTimeUs > r->simStartTimeUs) + full++, sum += (double)(r->gpuRenderEndTimeUs - r->simStartTimeUs); + } + snprintf(drv, sizeof drv, "; driver reports: %u of %u frames with every marker, simulation start to GPU render " + "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); + g_lat.n = g_lat.ns = 0; +} + +uint64_t vk_reflex_frame(void) { return __atomic_load_n(&g_reflex_frame, __ATOMIC_RELAXED); } + +void vk_reflex_submit_frame(uint64_t id) { t_reflex_submit = id; } + +uint64_t vk_reflex_submit_id(void) { return t_reflex_submit ? t_reflex_submit : vk_reflex_frame(); } + +// The present thread, before the blit of frame id: the present of that blit carries id. +void vk_reflex_present_frame(uint64_t id) { + plat_rmutex_lock(&g_pl); + g_blit_pid = id; + plat_rmutex_unlock(&g_pl); +} + +void vk_reflex_marker(int marker, uint64_t pid) { VkCtx *c = vk_ctx(); - if (!c || !c->has_nv_reflex || !g_reflex_marker || g_reflex_mode <= 0 || !g_sc) return; + if (!c || !c->has_nv_reflex || !g_reflex_marker || g_reflex_mode <= 0 || !g_sc || !pid) return; plat_rmutex_lock(&g_pl); if (g_sc && g_reflex_marker) { - uint64_t pid = __atomic_load_n(&g_reflex_present_id, __ATOMIC_RELAXED); VkSetLatencyMarkerInfoNV mi = { .sType = VK_STRUCTURE_TYPE_SET_LATENCY_MARKER_INFO_NV, .presentID = pid, @@ -400,11 +468,14 @@ static void flip_locked(void) { uint64_t pid = 0; VkPresentIdKHR pid_info = {0}; if (c && c->has_nv_reflex) { - pid = __atomic_add_fetch(&g_reflex_present_id, 1, __ATOMIC_RELAXED); + // The frame's own ID; a present without one (a probe, a skipped frame's neighbour) takes the next free value, + // as present IDs must grow on a swapchain + pid = g_flip_pid > g_last_pid ? g_flip_pid : g_last_pid + 1; + g_last_pid = pid; pid_info.sType = VK_STRUCTURE_TYPE_PRESENT_ID_KHR; pid_info.swapchainCount = 1; pid_info.pPresentIds = &pid; - vk_reflex_marker(4); // VK_LATENCY_MARKER_PRESENT_START_NV + vk_reflex_marker(4, pid); // VK_LATENCY_MARKER_PRESENT_START_NV } VkPresentInfoKHR pi = {.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, .pNext = (c && c->has_nv_reflex) ? &pid_info : NULL, @@ -414,7 +485,8 @@ static void flip_locked(void) { vk_queue_lock(); VkResult r = vkQueuePresentKHR(c->gfx_queue, &pi); vk_queue_unlock(); - if (c && c->has_nv_reflex) vk_reflex_marker(5); // VK_LATENCY_MARKER_PRESENT_END_NV + if (c && c->has_nv_reflex) vk_reflex_marker(5, pid); // VK_LATENCY_MARKER_PRESENT_END_NV + if (c) latency_note(c, pid ? pid : g_flip_pid); vk_device_fault_report(r); if (r == VK_ERROR_OUT_OF_DATE_KHR || r == VK_SUBOPTIMAL_KHR) plat_xchg32(&g_dirty, 1); } @@ -502,6 +574,10 @@ static int build_swapchain(void) { } free_capture(); vk_queue_unlock(); + // The Reflex sleep mode belongs to the swapchain: a new one (resize, fullscreen, out of date) starts with low + // latency off, so the mode is set on it again even though the setting did not change. + g_reflex_mode = -1; + reflex_apply_locked(); return 1; } @@ -872,6 +948,7 @@ static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w if (r == VK_SUCCESS) { g_flip_on = 1; g_flip_idx = idx; + g_flip_pid = g_blit_pid; // the frame this blit shows (vk_reflex_present_frame) if (!defer) flip_locked(); } else { vk_device_fault_report(r); diff --git a/runtime/nvn_api_obj.c b/runtime/nvn_api_obj.c index 22fb03dd..8fc698bf 100644 --- a/runtime/nvn_api_obj.c +++ b/runtime/nvn_api_obj.c @@ -19,7 +19,9 @@ #include "nvn_tex.h" #include "platform/platform.h" -void vk_reflex_marker(int marker); +void vk_reflex_marker(int marker, uint64_t present_id); +uint64_t vk_reflex_frame_begin(void); +uint64_t vk_reflex_frame(void); void vk_reflex_sleep(void); // ---------- Descriptor pools @@ -691,7 +693,7 @@ NVN_API(nvnWindowAcquireTexture) { perf_end(PERF_PACE, p0); } vk_reflex_sleep(); - vk_reflex_marker(0); // VK_LATENCY_MARKER_SIMULATION_START_NV + vk_reflex_marker(0, vk_reflex_frame_begin()); // VK_LATENCY_MARKER_SIMULATION_START_NV: a new frame and its ID // 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) { @@ -715,7 +717,7 @@ NVN_API(nvnQueuePresentTexture) { if (o->magic != NVN_WIN_MAGIC || idx < 0 || idx >= o->ntex || idx >= 4 || !o->tex[idx]) rt_fatal("nvn: QueuePresentTexture of image %d on window %p", idx, (void *)o); o->presents++; - vk_reflex_marker(1); // VK_LATENCY_MARKER_SIMULATION_END_NV + vk_reflex_marker(1, vk_reflex_frame()); // VK_LATENCY_MARKER_SIMULATION_END_NV const tex_t *t = (const tex_t *)o->tex[idx]; uint64_t period = present_period(o), now = kern_now_ns(); uint64_t slot = now + pace(&o->pace, now, period); diff --git a/runtime/ov_input.c b/runtime/ov_input.c index ac38f9c9..2a2f34a3 100644 --- a/runtime/ov_input.c +++ b/runtime/ov_input.c @@ -17,7 +17,8 @@ #include "ov.h" #include "platform/platform.h" -void vk_reflex_marker(int marker); +void vk_reflex_marker(int marker, uint64_t present_id); +uint64_t vk_reflex_frame(void); typedef struct { int64_t sampling; uint64_t buttons; int32_t lx, ly, rx, ry; uint32_t attributes, pad; } NpadState; typedef struct { int64_t sampling; int32_t x, y, dx, dy, wx, wy; uint32_t buttons, attributes; } MouseState; @@ -95,7 +96,7 @@ static void npad_states(Cpu *c, uint32_t want) { if (live) { s.attributes = ATTR_CONNECTED; input_poll(&s.buttons, &s.lx, &s.ly, &s.rx, &s.ry); - vk_reflex_marker(6); // VK_LATENCY_MARKER_INPUT_SAMPLE_NV + vk_reflex_marker(6, vk_reflex_frame()); // VK_LATENCY_MARKER_INPUT_SAMPLE_NV } *out = s; ret_x(c, 1); diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 5b1be433..bf3f45f9 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -655,7 +655,7 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [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. On + Boost удерживает высокие частоты GPU при упоре в процессор.", + [UI_MENU_REFLEX_DESC] = "Снижает задержку системы на видеокартах NVIDIA с помощью VK_NV_low_latency2. «Вкл + Ускорение» удерживает высокие частоты GPU при упоре в процессор.", [UI_MENU_REFLEX_OFF] = "Выкл", [UI_MENU_REFLEX_ON] = "Вкл", [UI_MENU_REFLEX_BOOST] = "Вкл + Ускорение", @@ -1497,7 +1497,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] = "NVIDIA Reflex Low Latency", - [UI_MENU_REFLEX_DESC] = "Reduz a latência do sistema em GPUs NVIDIA usando VK_NV_low_latency2. On + Boost mantém os clocks da GPU altos quando limitado pela CPU.", + [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_OFF] = "Desligado", [UI_MENU_REFLEX_ON] = "Ligado", [UI_MENU_REFLEX_BOOST] = "Ligado + Boost", diff --git a/runtime/vk.h b/runtime/vk.h index 23d78fe8..c1185f54 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -148,10 +148,14 @@ void vk_present_blit(VkImage src, VkImageLayout layout, VkFormat fmt, int w, int int vk_fsr_record(VkCommandBuffer cb, unsigned slot, VkImage src, VkFormat fmt, int sw, int sh, const int crop[4], VkImage dst, const int out[4]); void vk_fsr_release(void); // before the device goes away -void vk_reflex_marker(int marker); +void vk_reflex_marker(int marker, uint64_t present_id); // present_id: the frame's (vk_reflex_frame_begin) +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_submit_frame(uint64_t id); // this thread's submissions belong to frame id (0: the game's current one) +uint64_t vk_reflex_submit_id(void); +void vk_reflex_present_frame(uint64_t id); // the present thread, before the blit of frame id void vk_reflex_sleep(void); int vk_has_reflex(void); -uint64_t vk_reflex_current_present_id(void); // Colour adjustment on the present (vk_color.c): with TOTK_COLOR_* away from their defaults, records a pass that writes // src's crop rectangle {x, y, w, h}, adjusted, into an RGBA16F image of that size in GENERAL and returns it (the caller // scales that one instead, crop {0, 0, w, h}); VK_NULL_HANDLE = nothing recorded. src is in GENERAL, fmt its format. diff --git a/runtime/vk_backend.c b/runtime/vk_backend.c index cf4f4d94..26df8391 100644 --- a/runtime/vk_backend.c +++ b/runtime/vk_backend.c @@ -33,7 +33,7 @@ #define WEAK __attribute__((weak)) -typedef struct { VkImage image; VkFormat format; int w, h, has_crop, crop[4]; uint64_t frame, at, queued, value; } PresentJob; +typedef struct { VkImage image; VkFormat format; int w, h, has_crop, crop[4]; uint64_t frame, at, queued, value, pid; } PresentJob; // pid: the frame's present ID (vk_reflex_frame) static PlatMutex pl = PLAT_MUTEX_INIT; static PlatCond pcv = PLAT_COND_INIT; // job queued, job taken, job submitted @@ -60,6 +60,8 @@ static void present_main(void *arg) { plat_cond_broadcast(&pcv); plat_mutex_unlock(&pl); if (flight_on) vk_thumbs_frame(j.frame); + vk_reflex_present_frame(j.pid); // the present of this blit, and the submission after it, are the frame's + vk_reflex_submit_frame(j.pid); vk_present_blit(j.image, VK_IMAGE_LAYOUT_GENERAL, j.format, j.w, j.h, j.has_crop ? j.crop : NULL); uint64_t f = vk_sync_submit(NULL, 0); // a timeline value after the blit: deferred destruction waits for the blit too if (j.value && f != j.value) @@ -99,7 +101,7 @@ void vk_present_drain(void) { // The present after the frame count: resolves the image and hands the blit to the present thread. queued: when the game // presented; value: the timeline value queued for this present (asynchronous replay), 0 for the next one (synchronous). static void present_image(const tex_t *t, const int crop[4], uint64_t at_ns, uint64_t queued, uint64_t frame, - uint64_t value) { + uint64_t value, uint64_t pid) { static volatile int32_t n_skipped; vk_exec_frame_log(t, frame); vk_dlaa_frame(); @@ -120,7 +122,7 @@ static void present_image(const tex_t *t, const int crop[4], uint64_t at_ns, uin return; } PresentJob j = {.image = img->image, .format = img->format, .w = (int)img->width, .h = (int)img->height, .frame = frame, - .at = at_ns, .queued = queued, .value = value}; + .at = at_ns, .queued = queued, .value = value, .pid = pid}; vk_hdr_present_source(img, &j.image, &j.format); // TOTK_HDR: the float picture the game copied into it, same size if (crop) { j.has_crop = 1; @@ -144,7 +146,7 @@ static void present_image(const tex_t *t, const int crop[4], uint64_t at_ns, uin enum { RI_SUBMIT, RI_PRESENT, RI_RELEASE }; typedef struct { int kind, n, has_crop, crop[4]; - uint64_t value, submit_no, at, queued; + uint64_t value, submit_no, at, queued, pid; // pid: the game's frame when it queued the item (present ID) uint64_t *h; const tex_t *tex; // RI_RELEASE: a copy the item owns (the game may reuse the object's memory) } ReplayItem; @@ -223,6 +225,7 @@ static void replay_main(void *arg) { plat_cond_broadcast(&rcv); plat_mutex_unlock(&rl); if (it.kind == RI_SUBMIT) { + vk_reflex_submit_frame(it.pid); // the replay thread submits the frame the game was on when it queued it uint64_t f = submit_sync(it.h, it.n); if (f != it.value) rt_fatal("vk: replayed submission signalled %llu, queued as %llu", (unsigned long long)f, @@ -234,7 +237,7 @@ static void replay_main(void *arg) { free((void *)it.tex); } else { uint64_t frame = __atomic_add_fetch(&gfx_counters.frames, 1, __ATOMIC_RELAXED); - present_image(it.tex, it.has_crop ? it.crop : NULL, it.at, it.queued, frame, it.value); + present_image(it.tex, it.has_crop ? it.crop : NULL, it.at, it.queued, frame, it.value, it.pid); } plat_mutex_lock(&rl); if (it.kind != RI_RELEASE) r_value_done = it.value; @@ -345,7 +348,7 @@ static void vk_be_present(const tex_t *t, const int crop[4], uint64_t at_ns) { if (!gfx_replay_async()) { uint64_t frame = __atomic_add_fetch(&gfx_counters.frames, 1, __ATOMIC_RELAXED); perf_present(frame); // before vk_exec_frame_log, which resets the frame's exec counts the flight recorder reads - present_image(t, crop, at_ns, kern_now_ns(), frame, 0); + present_image(t, crop, at_ns, kern_now_ns(), frame, 0, vk_reflex_frame()); return; } // Frame bound: the replay thread handled the previous present before this one is queued. @@ -361,7 +364,7 @@ static void vk_be_present(const tex_t *t, const int crop[4], uint64_t at_ns) { uint64_t frame = ++game_frames; perf_present(frame); if (frame % 1800 == 0) replay_log(frame, 0); - ReplayItem it = {.kind = RI_PRESENT, .tex = t, .at = at_ns, .queued = kern_now_ns()}; + ReplayItem it = {.kind = RI_PRESENT, .tex = t, .at = at_ns, .queued = kern_now_ns(), .pid = vk_reflex_frame()}; if (crop) { it.has_crop = 1; for (int i = 0; i < 4; i++) it.crop[i] = crop[i]; @@ -408,7 +411,7 @@ static void vk_be_program_release(const prog_t *p) { replay_drain(DR_PROG_RELEAS static uint64_t vk_be_submit(const uint64_t *handles, int n) { if (!gfx_replay_async()) return submit_sync(handles, n); vk_sync_start(); - ReplayItem it = {.kind = RI_SUBMIT, .n = n, .submit_no = nvn_submit_count()}; + ReplayItem it = {.kind = RI_SUBMIT, .n = n, .submit_no = nvn_submit_count(), .pid = vk_reflex_frame()}; if (n > 0) { it.h = malloc(sizeof *it.h * (size_t)n); if (!it.h) rt_fatal("vk: out of memory (replay queue)"); diff --git a/runtime/vk_device.c b/runtime/vk_device.c index 6a613450..c7f85a17 100644 --- a/runtime/vk_device.c +++ b/runtime/vk_device.c @@ -405,6 +405,11 @@ static int create_device(void) { : !ab_want ? "off (TOTK_ADDR_REPORT=0 or no VK_EXT_debug_utils)" : "unavailable (no VK_EXT_device_address_binding_report)"); g_vk.has_buffer_device_address = c->f12.bufferDeviceAddress; + // VkPresentIdKHR on a present needs the presentId feature, not just the extension + if (g_vk.has_nv_reflex && !c->pid.presentId) { + g_vk.has_nv_reflex = 0; + rt_log("Reflex: VK_NV_low_latency2 not available (no presentId feature)"); + } g_vk.has_astc_ldr = h->textureCompressionASTC_LDR; { const char *e = cfg_get("TOTK_FEEDBACK"); diff --git a/runtime/vk_sync.c b/runtime/vk_sync.c index 40421122..f4e026b8 100644 --- a/runtime/vk_sync.c +++ b/runtime/vk_sync.c @@ -477,7 +477,7 @@ uint64_t vk_sync_submit(const uint64_t *handles, int n) { VkLatencySubmissionPresentIdNV lsid = { .sType = VK_STRUCTURE_TYPE_LATENCY_SUBMISSION_PRESENT_ID_NV, .pNext = NULL, - .presentID = vk_reflex_current_present_id() + .presentID = vk_reflex_submit_id() }; VkSubmitInfo2 si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2, .pNext = (c->has_nv_reflex) ? &lsid : NULL, @@ -485,9 +485,9 @@ uint64_t vk_sync_submit(const uint64_t *handles, int n) { .pCommandBufferInfos = pro ? cbi : cbi + 1, .signalSemaphoreInfoCount = 1, .pSignalSemaphoreInfos = &sig}; ts_submitted(); - if (recorded && c->has_nv_reflex) vk_reflex_marker(2); // VK_LATENCY_MARKER_RENDERSUBMIT_START_NV + if (recorded && c->has_nv_reflex) vk_reflex_marker(2, lsid.presentID); // VK_LATENCY_MARKER_RENDERSUBMIT_START_NV VkResult r = rec_submit(&si); // by the recorder when it recorded the part - if (recorded && c->has_nv_reflex) vk_reflex_marker(3); // VK_LATENCY_MARKER_RENDERSUBMIT_END_NV + if (recorded && c->has_nv_reflex) vk_reflex_marker(3, lsid.presentID); // VK_LATENCY_MARKER_RENDERSUBMIT_END_NV if (r != VK_SUCCESS) { vk_device_fault_report(r); rt_fatal("vk: vkQueueSubmit2 of value %llu failed (%d)", (unsigned long long)fence, (int)r); From 88cd32fddf8e8e55674140ccabefa5151c4a3153 Mon Sep 17 00:00:00 2001 From: zzs181 <49477185+zzs181@users.noreply.github.com> Date: Wed, 4 Nov 2026 12:47:52 +0800 Subject: [PATCH 14/56] Add tests/run_all.py: one entry point for the tests, each with its interpreter and needs Each test already says in its header how it wants to be run; this reads that intent into one table (.venv for the lifter, .venv-py314 for the extraction tools) and runs them all: python tests/run_all.py # the ones that need no game files python tests/run_all.py --all # also the ones that read game files or a built totk.exe A need that cannot be met here is SKIP with the reason, never a failure: a missing game dump is not a broken build. Exit is 0 when nothing failed, 1 when something did. Windows picks clang up from C:/msys64/ucrt64/bin for the tests that compile C; on any other host the PATH is left alone. No third-party imports, so this runs before any venv is trusted. --- tests/run_all.py | 189 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 tests/run_all.py diff --git a/tests/run_all.py b/tests/run_all.py new file mode 100644 index 00000000..4918a0da --- /dev/null +++ b/tests/run_all.py @@ -0,0 +1,189 @@ +"""Run every test in tests/ through one command, and say what each one needed. + +The tests were written to be run one at a time (each header says how). This keeps that layout and adds the two +things it lacked: one entry point, and a report that separates a failure from a test that could not run here. + + python tests/run_all.py # the ones that need no game files: fast, safe in a loop + python tests/run_all.py --all # also the ones that read game files or a built totk.exe + python tests/run_all.py --only ncz_test,spin_waits_test + python tests/run_all.py --list + +Each test declares its interpreter (.venv for the lifter, .venv-py314 for the extraction tools) and what it +needs. A need that cannot be met is SKIP with the reason, never a failure: a missing game dump is not a broken +build. Exit is 0 when nothing failed, 1 when something did. + +No third-party imports: this runs before any venv is trusted. +""" + +import argparse +import os +import subprocess +import sys +import time +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[1] +WIN = os.name == 'nt' +MSYS_BIN = Path(r'C:\msys64\ucrt64\bin') # clang/gcc for flags_check and excl_mt + + +def interp(venv): + """.venv / .venv-py314, falling back to this interpreter when the venv is absent.""" + d = ROOT / venv + p = d / ('Scripts/python.exe' if WIN else 'bin/python') + return p if p.exists() else Path(sys.executable) + + +# name: (venv, needs, args, why the need is there) +# needs: None | 'exefs' | 'exe' | 'embed' | 'gui' +TESTS = { + # ---- no game files, no build ---- + 'flags_check': ('.venv', None, [], ''), + 'excl_mt': ('.venv', None, [], ''), + 'pack_shader_cache_test': ('.venv', None, [], ''), + 'spin_waits_test': ('.venv', None, [], ''), + 'worktree_test': ('.venv', None, [], ''), + 'installer_test': ('.venv-py314', None, [], ''), + 'ncz_test': ('.venv-py314', None, [], ''), + 'romfs_prompts_test': ('.venv-py314', None, [], ''), + # ---- read the game or a build ---- + 'jumptables_check': ('.venv', 'exefs', ['--exefs', ''], + 'replays the modules through Unicorn; needs an unpacked exefs'), + 'mods_romfs_check': ('.venv', 'exe', ['--exe', '', '--version', 'v143'], + 'runs the built totk.exe against a mod layout'), + 'installer_e2e': ('.venv-py314', 'embed', [], + 'the release launcher runs installer on the embeddable Python'), + 'installer_gui_test': ('.venv-py314', 'gui', [], + 'drives the installer window; needs an interactive desktop'), +} + + +def load_work_dir(): + """[work] dir from config.local.toml, so a game test finds the extracted files.""" + cfg = ROOT / 'config.local.toml' + if not cfg.exists(): + return ROOT / 'build' + try: + import tomllib + with open(cfg, 'rb') as f: + d = tomllib.load(f).get('work', {}).get('dir') + return Path(d) if d else ROOT / 'build' + except Exception: + return ROOT / 'build' + + +def find_exefs(): + work = load_work_dir() + for c in (work / 'exefs-v143', work / 'extracted' / 'v143' / 'exefs', + ROOT / 'build' / 'extracted' / 'v143' / 'exefs'): + if (c / 'main').exists(): + return c + return None + + +def find_exe(): + for c in (ROOT / 'build' / 'v143' / 'totk.exe',): + if c.exists(): + return c + return None + + +def find_embed(): + for c in (ROOT / 'build' / 'py314-embed',): + if (c / ('python.exe' if WIN else 'bin/python3')).exists(): + return c + return None + + +def resolve(needs): + """(what the args take, or None when the need cannot be met here).""" + if needs is None: + return None, None + if needs == 'exefs': + p = find_exefs() + return (None, 'no unpacked exefs (run tools/extract.py)') if p is None else (str(p), None) + if needs == 'exe': + p = find_exe() + return (None, 'no built build/v143/totk.exe') if p is None else (str(p), None) + if needs == 'embed': + p = find_embed() + return (None, 'no build/py314-embed (tools/make_release.py makes it)') if p is None else (str(p), None) + if needs == 'gui': + return None, 'drives a window; run it by hand on a desktop session' + return None, f'unknown need {needs!r}' + + +def run_one(name, all_ok, timeout, verbose): + venv, needs, args, why = TESTS[name] + if not (ROOT / 'tests' / f'{name}.py').exists(): + return 'SKIP', 0.0, 'not on this branch', '' + if needs is not None and not all_ok: + return 'SKIP', 0.0, f'needs {needs}: {why} (--all)', '' + value, reason = resolve(needs) + if reason: + return 'SKIP', 0.0, reason, '' + argv = [str(interp(venv)), str(ROOT / 'tests' / f'{name}.py')] + if value: + argv += [a.replace('', value).replace('', value) for a in args] + env = dict(os.environ) + if MSYS_BIN.is_dir(): # flags_check and excl_mt compile C + env['PATH'] = str(MSYS_BIN) + os.pathsep + env.get('PATH', '') + t0 = time.time() + try: + r = subprocess.run(argv, cwd=str(ROOT), env=env, capture_output=True, + text=True, encoding='utf-8', errors='replace', timeout=timeout) + except subprocess.TimeoutExpired: + return 'FAIL', time.time() - t0, f'timed out after {timeout}s', '' + dt = time.time() - t0 + out = (r.stdout or '') + (r.stderr or '') + if r.returncode == 0: + return 'PASS', dt, '', out if verbose else '' + tail = '\n'.join(out.strip().splitlines()[-12:]) + return 'FAIL', dt, f'exit {r.returncode}', tail + + +def main(): + ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) + ap.add_argument('--all', action='store_true', help='also run the tests that read game files or a build') + ap.add_argument('--only', help='comma-separated test names') + ap.add_argument('--list', action='store_true', help='list the tests and their needs') + ap.add_argument('--timeout', type=int, default=1800, help='per test, seconds (default 1800)') + ap.add_argument('-v', '--verbose', action='store_true', help='print every test\'s output') + a = ap.parse_args() + + if a.list: + for n in TESTS: + venv, needs, _, why = TESTS[n] + print(f'{n:26} {venv:12} {needs or "-":6} {why}') + return 0 + + names = list(TESTS) + if a.only: + want = [s.strip() for s in a.only.split(',') if s.strip()] + missing = [w for w in want if w not in TESTS] + if missing: + print(f'unknown test(s): {", ".join(missing)}', file=sys.stderr) + return 2 + names = want + + print(f'{len(names)} test(s), cwd {ROOT}') + rows, failed = [], 0 + for n in names: + status, dt, note, out = run_one(n, a.all, a.timeout, a.verbose) + failed += status == 'FAIL' + rows.append((n, status, dt, note)) + line = f' {status:4} {n:26} {dt:6.1f}s' + print(line + (f' {note}' if note else '')) + if out: + print('\n'.join(' ' + s for s in out.splitlines())) + + print() + counts = {k: sum(1 for r in rows if r[1] == k) for k in ('PASS', 'FAIL', 'SKIP')} + print(f'{counts["PASS"]} passed, {counts["FAIL"]} failed, {counts["SKIP"]} skipped') + if failed: + print('failed: ' + ', '.join(r[0] for r in rows if r[1] == 'FAIL')) + return 1 if failed else 0 + + +if __name__ == '__main__': + sys.exit(main()) From 5635dd5e3a2e23aeacef2d7110e10b0b546553c5 Mon Sep 17 00:00:00 2001 From: zzs181 <49477185+zzs181@users.noreply.github.com> Date: Wed, 4 Nov 2026 18:34:08 +0800 Subject: [PATCH 15/56] Let a test need more than one thing, and find the romfs where it actually lives mods_romfs_check needs both a built totk.exe and the extracted romfs, and the romfs was hard-coded to build/extracted//romfs in two places inside the test. Needs now compose with '+' (exe+romfs) and each gets its own placeholder, the romfs is found in the extracted tree, the work dir or the GUI builder's record (build/build_gui.json), and any build/v143-*/totk.exe counts as the built exe - so the test runs on the layouts people actually build in instead of failing on a path it assumed. The test takes --romfs; its default is the old path, so running it by hand is unchanged. --- tests/mods_romfs_check.py | 18 +++++----- tests/run_all.py | 76 ++++++++++++++++++++++++++++----------- 2 files changed, 65 insertions(+), 29 deletions(-) diff --git a/tests/mods_romfs_check.py b/tests/mods_romfs_check.py index c3eb5b1b..438d0967 100644 --- a/tests/mods_romfs_check.py +++ b/tests/mods_romfs_check.py @@ -1,9 +1,9 @@ """The mods folder served as RomFS overlays (runtime/romfs.c, runtime/mods.c): load order, added files, case, Unicode. - .venv\\Scripts\\python tests\\mods_romfs_check.py --exe build\\v121-\\totk.exe --version v121 + .venv\\Scripts\\python tests\\mods_romfs_check.py --exe build\\v121-\\totk.exe --version v121 [--romfs ] Builds a mods folder in a temp directory with files of its own bytes at real RomFS paths (from -build/extracted//romfs/index.json), runs `totk.exe --probe-fs` on it and reads the `mods:` lines of the log. +build/extracted//romfs/index.json unless --romfs says otherwise), runs `totk.exe --probe-fs` on it and reads the `mods:` lines of the log. --probe-fs compares the bytes it reads through the RomFS with every overlay file, so a wrong winner fails it too. A second folder checks the merged resource size table the start writes to the profile (runtime/romfs.c restbl_overlay): a grown file's entry, an added file's, a shipped table's and another version's table's. @@ -25,8 +25,8 @@ ROOT = Path(__file__).resolve().parents[1] UNI = 'Ж мод' -def pick_paths(version): - index = json.loads((ROOT / 'build/extracted' / version / 'romfs/index.json').read_text()) +def pick_paths(version, romfs): + index = json.loads((romfs / 'index.json').read_text(encoding='utf-8')) paths = [f['path'] for f in index['files'] if 1024 <= f['size'] <= 65536] have = set(f['path'] for f in index['files']) p1 = next(p for p in paths if any(c.isalpha() for c in p.rsplit('/', 1)[-1])) @@ -83,8 +83,7 @@ def key(path): return zlib.crc32((path[:-3] if path.endswith(('.zs', '.mc')) else path).encode()) -def restbl_case(exe, version, check, tmp): - romfs = ROOT / 'build/extracted' / version / 'romfs' +def restbl_case(exe, version, romfs, check, tmp): index = json.loads((romfs / 'index.json').read_text()) files = {f['path']: f for f in index['files']} table_path = next(p for p in files if p.startswith('System/Resource/ResourceSizeTable.') and @@ -129,8 +128,11 @@ def main(): ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) ap.add_argument('--exe', type=Path, required=True) ap.add_argument('--version', choices=('v121', 'v143'), required=True) + ap.add_argument('--romfs', type=Path, + default=ROOT / 'build/extracted' / 'v143' / 'romfs', + help='the extracted romfs (its index.json names the real file paths)') args = ap.parse_args() - p1, p2, p1case = pick_paths(args.version) + p1, p2, p1case = pick_paths(args.version, args.romfs) fails = 0 def check(ok, what, log=None): @@ -169,7 +171,7 @@ def main(): check('mods: Low: 3 files served (2 replaced, 1 added), 0 overridden' in log, 'Low serves P1 and the added file', log) check('mods: Top: ' not in log.replace('mods: Top: off', ''), 'a switched-off mod serves nothing', log) - restbl_case(args.exe, args.version, check, tmp) + restbl_case(args.exe, args.version, args.romfs, check, tmp) print('mods_romfs_check:', 'FAIL' if fails else 'ok') return 1 if fails else 0 diff --git a/tests/run_all.py b/tests/run_all.py index 4918a0da..aca9cd7c 100644 --- a/tests/run_all.py +++ b/tests/run_all.py @@ -35,7 +35,7 @@ def interp(venv): # name: (venv, needs, args, why the need is there) -# needs: None | 'exefs' | 'exe' | 'embed' | 'gui' +# needs: None | needs joined by '+' (exefs | exe | romfs | embed | gui) TESTS = { # ---- no game files, no build ---- 'flags_check': ('.venv', None, [], ''), @@ -49,8 +49,8 @@ TESTS = { # ---- read the game or a build ---- 'jumptables_check': ('.venv', 'exefs', ['--exefs', ''], 'replays the modules through Unicorn; needs an unpacked exefs'), - 'mods_romfs_check': ('.venv', 'exe', ['--exe', '', '--version', 'v143'], - 'runs the built totk.exe against a mod layout'), + 'mods_romfs_check': ('.venv', 'exe+romfs', ['--exe', '', '--version', 'v143', '--romfs', ''], + 'runs the built totk.exe against a mod layout, on the extracted romfs'), 'installer_e2e': ('.venv-py314', 'embed', [], 'the release launcher runs installer on the embeddable Python'), 'installer_gui_test': ('.venv-py314', 'gui', [], @@ -82,8 +82,28 @@ def find_exefs(): def find_exe(): - for c in (ROOT / 'build' / 'v143' / 'totk.exe',): - if c.exists(): + """A built totk.exe: the plain v143 tree, else the newest variant (v143-heropath, ...).""" + if (ROOT / 'build' / 'v143' / 'totk.exe').exists(): + return ROOT / 'build' / 'v143' / 'totk.exe' + builds = sorted(ROOT.glob('build/v143-*/totk.exe'), + key=lambda p: p.stat().st_mtime, reverse=True) + return builds[0] if builds else None + + +def find_romfs(): + """The extracted romfs of v143: its index.json names the real file paths.""" + cands = [ROOT / 'build' / 'extracted' / 'v143' / 'romfs', load_work_dir() / 'romfs'] + gui = ROOT / 'build' / 'build_gui.json' # the GUI builder remembers where it built from + if gui.exists(): + try: + import json + r = json.loads(gui.read_text(encoding='utf-8')).get('romfs') + if r: + cands.append(Path(r)) + except Exception: + pass + for c in cands: + if (c / 'index.json').exists(): return c return None @@ -96,21 +116,32 @@ def find_embed(): def resolve(needs): - """(what the args take, or None when the need cannot be met here).""" + """({placeholder: what the arg takes}, or the reasons the needs cannot be met here).""" if needs is None: - return None, None - if needs == 'exefs': - p = find_exefs() - return (None, 'no unpacked exefs (run tools/extract.py)') if p is None else (str(p), None) - if needs == 'exe': - p = find_exe() - return (None, 'no built build/v143/totk.exe') if p is None else (str(p), None) - if needs == 'embed': - p = find_embed() - return (None, 'no build/py314-embed (tools/make_release.py makes it)') if p is None else (str(p), None) - if needs == 'gui': - return None, 'drives a window; run it by hand on a desktop session' - return None, f'unknown need {needs!r}' + return {}, None + vals, missing = {}, [] + for need in needs.split('+'): + if need == 'exefs': + p = find_exefs() + if p is None: missing.append('no unpacked exefs (run tools/extract.py)') + else: vals[''] = str(p) + elif need == 'exe': + p = find_exe() + if p is None: missing.append('no built build/v143/totk.exe') + else: vals[''] = str(p) + elif need == 'romfs': + p = find_romfs() + if p is None: missing.append('no extracted romfs index (run tools/extract.py)') + else: vals[''] = str(p) + elif need == 'embed': + p = find_embed() + if p is None: missing.append('no build/py314-embed (tools/make_release.py makes it)') + else: vals[''] = str(p) + elif need == 'gui': + missing.append('drives a window; run it by hand on a desktop session') + else: + return {}, f'unknown need {need!r}' + return vals, ('; '.join(missing) if missing else None) def run_one(name, all_ok, timeout, verbose): @@ -123,8 +154,11 @@ def run_one(name, all_ok, timeout, verbose): if reason: return 'SKIP', 0.0, reason, '' argv = [str(interp(venv)), str(ROOT / 'tests' / f'{name}.py')] - if value: - argv += [a.replace('', value).replace('', value) for a in args] + for a in args: # fill each placeholder with its need's value + s = a + for k, v in value.items(): + s = s.replace(k, v) + argv.append(s) env = dict(os.environ) if MSYS_BIN.is_dir(): # flags_check and excl_mt compile C env['PATH'] = str(MSYS_BIN) + os.pathsep + env.get('PATH', '') From 95052a280e2868c802ff5811d15a4e61ff01144b Mon Sep 17 00:00:00 2001 From: itaskaev2 <165683571+itaskaev2@users.noreply.github.com> Date: Fri, 6 Nov 2026 19:32:06 +0100 Subject: [PATCH 16/56] List the tests added since, and the differential tests, in tests/run_all.py The table predates exefs_patches_test and leaves out settings_doc_check, mouse_direct_check and tests/diff. A name may now name a script below tests/ (diff/simd), and a need of a compiler (cc, which mouse_direct_check passes as --cc) runs without --all, as only game files, a build, the embeddable Python and a desktop wait for it. Co-Authored-By: Claude Opus 5.5 --- tests/run_all.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/run_all.py b/tests/run_all.py index aca9cd7c..96f2a007 100644 --- a/tests/run_all.py +++ b/tests/run_all.py @@ -27,6 +27,10 @@ WIN = os.name == 'nt' MSYS_BIN = Path(r'C:\msys64\ucrt64\bin') # clang/gcc for flags_check and excl_mt +# The needs that only --all meets: game files, a build, the embeddable Python, a desktop. A compiler (cc) is not one. +GAME_NEEDS = {'exefs', 'exe', 'romfs', 'embed', 'gui'} + + def interp(venv): """.venv / .venv-py314, falling back to this interpreter when the venv is absent.""" d = ROOT / venv @@ -35,7 +39,8 @@ def interp(venv): # name: (venv, needs, args, why the need is there) -# needs: None | needs joined by '+' (exefs | exe | romfs | embed | gui) +# needs: None | needs joined by '+' (exefs | exe | romfs | embed | gui | cc) +# name: the script below tests/, without .py (diff/simd is tests/diff/simd.py) TESTS = { # ---- no game files, no build ---- 'flags_check': ('.venv', None, [], ''), @@ -46,7 +51,16 @@ TESTS = { 'installer_test': ('.venv-py314', None, [], ''), 'ncz_test': ('.venv-py314', None, [], ''), 'romfs_prompts_test': ('.venv-py314', None, [], ''), + 'exefs_patches_test': ('.venv', None, [], ''), + 'settings_doc_check': ('.venv', None, [], ''), + 'mouse_direct_check': ('.venv', 'cc', ['--cc', ''], 'compiles its checks with clang'), + 'diff/atomic': ('.venv', None, [], ''), + 'diff/simd': ('.venv', None, [], ''), # ---- read the game or a build ---- + 'diff/lift': ('.venv', 'exefs', ['--exefs', ''], + 'samples instructions from the game modules; needs an unpacked exefs'), + 'diff/func': ('.venv', 'exefs', ['--exefs', ''], + 'lifts whole functions of the game modules; needs an unpacked exefs'), 'jumptables_check': ('.venv', 'exefs', ['--exefs', ''], 'replays the modules through Unicorn; needs an unpacked exefs'), 'mods_romfs_check': ('.venv', 'exe+romfs', ['--exe', '', '--version', 'v143', '--romfs', ''], @@ -115,6 +129,16 @@ def find_embed(): return None +def find_cc(): + """clang for the tests that compile C: MSYS2 UCRT64's on Windows, else the one on PATH.""" + c = MSYS_BIN / 'clang.exe' + if WIN and c.exists(): + return c + import shutil + w = shutil.which('clang') + return Path(w) if w else None + + def resolve(needs): """({placeholder: what the arg takes}, or the reasons the needs cannot be met here).""" if needs is None: @@ -137,6 +161,10 @@ def resolve(needs): p = find_embed() if p is None: missing.append('no build/py314-embed (tools/make_release.py makes it)') else: vals[''] = str(p) + elif need == 'cc': + p = find_cc() + if p is None: missing.append('no clang (MSYS2 UCRT64 on Windows)') + else: vals[''] = str(p) elif need == 'gui': missing.append('drives a window; run it by hand on a desktop session') else: @@ -148,7 +176,7 @@ def run_one(name, all_ok, timeout, verbose): venv, needs, args, why = TESTS[name] if not (ROOT / 'tests' / f'{name}.py').exists(): return 'SKIP', 0.0, 'not on this branch', '' - if needs is not None and not all_ok: + if needs is not None and not all_ok and set(needs.split('+')) & GAME_NEEDS: return 'SKIP', 0.0, f'needs {needs}: {why} (--all)', '' value, reason = resolve(needs) if reason: @@ -188,7 +216,7 @@ def main(): if a.list: for n in TESTS: venv, needs, _, why = TESTS[n] - print(f'{n:26} {venv:12} {needs or "-":6} {why}') + print(f'{n:26} {venv:12} {needs or "-":9} {why}') return 0 names = list(TESTS) From 5956d6dd468a437b5ad21c5fe5573753039783f9 Mon Sep 17 00:00:00 2001 From: ipavlin98 Date: Tue, 10 Nov 2026 21:08:37 +0300 Subject: [PATCH 17/56] Unpack a release archive again when its pin changes instead of reusing the old archive's files --- tools/make_release.py | 8 +++++--- tools/make_release_linux.py | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tools/make_release.py b/tools/make_release.py index 5114d6e1..0f39e959 100644 --- a/tools/make_release.py +++ b/tools/make_release.py @@ -168,10 +168,12 @@ def fetch(name): def unpack(name, member_filter=None): - """Extract a pinned archive into toolchain/release-work/ (once) and return that directory.""" + """Extract a pinned archive into toolchain/release-work/ and return that directory. The stamp holds the pin's + sha256, so a bumped pin unpacks its new archive instead of reusing the old one's files.""" dest = WORK / name stamp = dest / '.unpacked' - if stamp.is_file(): + key = PINS[name][1] + if stamp.is_file() and stamp.read_text() == key: return dest shutil.rmtree(dest, ignore_errors=True) dest.mkdir(parents=True) @@ -182,7 +184,7 @@ def unpack(name, member_filter=None): else: with tarfile.open(path) as t: t.extractall(dest, filter='data') - stamp.write_text('') + stamp.write_text(key) return dest diff --git a/tools/make_release_linux.py b/tools/make_release_linux.py index 10a62204..c1bcbd9d 100644 --- a/tools/make_release_linux.py +++ b/tools/make_release_linux.py @@ -103,9 +103,11 @@ def run(cmd, **kw): def tar_extract(name, dest, members, strip=0): - """Extract only members (path prefixes inside the archive) of a pinned tarball with the system tar, once.""" + """Extract only members (path prefixes inside the archive) of a pinned tarball with the system tar. The stamp holds + the pin's sha256 and the members, so a bumped pin or a changed member list extracts again.""" stamp = dest / '.unpacked' - if stamp.is_file(): + key = '\n'.join((mr.PINS[name][1], str(strip), *members)) + if stamp.is_file() and stamp.read_text() == key: return dest shutil.rmtree(dest, ignore_errors=True) dest.mkdir(parents=True) @@ -114,7 +116,7 @@ def tar_extract(name, dest, members, strip=0): run(['tar', '-xf', path, '-C', dest, f'--strip-components={strip}', '--wildcards', '--no-wildcards-match-slash', *members]) print(f'{name}: unpacked in {time.time() - t0:.0f} s') - stamp.write_text('') + stamp.write_text(key) return dest From 9680b8e6ec8b3b2253669dc4f889a2160085fd40 Mon Sep 17 00:00:00 2001 From: itaskaev2 <165683571+itaskaev2@users.noreply.github.com> Date: Tue, 10 Nov 2026 20:13:59 +0100 Subject: [PATCH 18/56] Add grass_range: how far around the camera grass grows The game grows grass blades only inside its near grass map, a 62.5 m square around the camera drawn into 256x256 and 128x128 textures, so on open meadows the grass appears a short way in front of the player. grass_range (percent, 50 to 400, default 100) scales the map's extent, step and both textures together through a new grass patch set (1.2.1 and 1.4.3) that loads them from patch page +128..+144, and grows the HeapDef grass heap and the application pool for the larger textures. At 100 the set stays off and nothing changes. A row in the Display menu, text in all four menu languages, and totk.ini.example describe it. Co-Authored-By: Claude Opus 5.5 --- recomp/patches-v121.txt | 11 +++++++++ recomp/patches-v143.txt | 14 +++++++++++ runtime/cfg.c | 6 ++--- runtime/host.h | 2 ++ runtime/memory.c | 5 ++-- runtime/resolution.c | 53 +++++++++++++++++++++++++++++++++++++++-- runtime/romfs.c | 2 +- runtime/ui/menu.cpp | 8 +++++++ runtime/ui_text.c | 14 +++++++++++ runtime/ui_text.h | 1 + totk.ini.example | 5 ++++ 11 files changed, 113 insertions(+), 8 deletions(-) diff --git a/recomp/patches-v121.txt b/recomp/patches-v121.txt index b56baf4c..6443f062 100644 --- a/recomp/patches-v121.txt +++ b/recomp/patches-v121.txt @@ -10,6 +10,7 @@ set bounce TOTK_HIGHFPS_FIX 1 set output TOTK_PATCH_OUTPUT 0 set scene TOTK_PATCH_SCENE 0 set shadow TOTK_PATCH_SHADOW 0 +set grass TOTK_PATCH_GRASS 0 # 60 fps: the adaptive present-interval controller (main+0x8f26c8, 1.0.0 0x8f6bec) gets the minimum interval 1. site fps60 main 8f273c 6b08015f 7100055f # clamp: cmp w10, #1 (was cmp w10, w8 = minimum) @@ -1115,3 +1116,13 @@ spin sdk 3d3250 3d3270 # 9 instructions; loads # goes in just before the rounding, as the community's shadow resolution mods do (1.1.0: mov w11, #1024 over the # computation). Found by a write watch on the size field (the writer was this function, and no other). site shadow main cec22c 11001d6b @page:x11 b9405d6b 11001d6b # add w11, w11, #7 -> adrp x11, page; ldr w11, [x11, #92]; add w11, w11, #7 + +# Grass range (runtime/resolution.c res_grass_range; patches-v143.txt describes the set and the page). The near grass +# map's constructor loads its extent, step and texture sizes at main+0xfe58b4..0xfe5950, and main+0x1a30a28 sets the +# extent to 62.5 or 31.25 m, as on 1.4.3. +site grass main fe58b4 52a84f48 @page:x8 b9408108 # mov w8, #62.5 -> ldr w8, [page+128] +site grass main fe58c0 52a80f48 @page:x8 b9408508 # mov w8, #3.90625 -> ldr w8, [page+132] +site grass main fe58ec 52802002 @page:x2 b9408842 # mov w2, #0x100 -> ldr w2, [page+136] +site grass main fe5950 52801002 @page:x2 b9408c42 # mov w2, #0x80 -> ldr w2, [page+140] +site grass main 1a30a8c 52a84f48 @page:x8 b9408108 # mov w8, #62.5 -> ldr w8, [page+128] +site grass main 1a30a98 52a83f48 @page:x8 b9409108 # mov w8, #31.25 -> ldr w8, [page+144] diff --git a/recomp/patches-v143.txt b/recomp/patches-v143.txt index e8c808a7..07ef3af9 100644 --- a/recomp/patches-v143.txt +++ b/recomp/patches-v143.txt @@ -12,6 +12,7 @@ set output TOTK_PATCH_OUTPUT 0 set scene TOTK_PATCH_SCENE 0 set shadow TOTK_PATCH_SHADOW 0 set cascade TOTK_PATCH_CASCADE 0 +set grass TOTK_PATCH_GRASS 0 # 60 fps: the adaptive present-interval controller (main+0x2db174, 1.2.1 0x8f26c8) gets the minimum interval 1. site fps60 main 2db204 6b08015f 7100055f # clamp: cmp w10, #1 (was cmp w10, w8 = minimum) @@ -1102,3 +1103,16 @@ site cascade main 6fad4c 52a86408 @page:x8 b9404d08 # mov w8, #160.0 -> ldr w8 # switches the set off without the real-time step, where the page is not written. set climb TOTK_CLIMB_FIX 1 site climb main 1f497f4 1e201001 @page:x8 bd400104 1e286884 52946dc8 72a7e528 1e270102 1e241842 52828248 72a7dfe8 1e270103 1e232842 529573e8 72a7b5a8 1e270103 1f040862 1e2a3883 2f00e404 1e246863 1e261004 1f048862 1e241004 1e247842 1e226800 1e201001 1e226821 # fmov s1, #2.0 -> s2 = g(u); s0 = max(s0, s2); s1 = max(2.0, s2) + + +# Grass range (runtime/resolution.c res_grass_range switches the set on). Grass blades grow from the near grass map, a +# square texture the game draws around the camera (GrassShader.sharcb). Its constructor (main+0xa38e58) gives it a +# 62.5 m extent, a 3.90625 m step (1/16 of it) and 256x256 and 128x128 textures; main+0x206340c later sets the extent +# to 62.5 or 31.25 m. With the set on all of them come from page +128..+144, scaled together so the map keeps its +# texels per metre; resolution.c grows the grass heap of the HeapDef for the larger textures. +site grass main a38e58 52a84f48 @page:x8 b9408108 # mov w8, #62.5 -> ldr w8, [page+128] +site grass main a38e64 52a80f48 @page:x8 b9408508 # mov w8, #3.90625 -> ldr w8, [page+132] +site grass main a38e94 52802002 @page:x2 b9408842 # mov w2, #0x100 -> ldr w2, [page+136] +site grass main a38ef4 52801002 @page:x2 b9408c42 # mov w2, #0x80 -> ldr w2, [page+140] +site grass main 2063454 52a84f48 @page:x8 b9408108 # mov w8, #62.5 -> ldr w8, [page+128] +site grass main 2063460 52a83f48 @page:x8 b9409108 # mov w8, #31.25 -> ldr w8, [page+144] diff --git a/runtime/cfg.c b/runtime/cfg.c index dbb73f7d..21c41237 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -44,7 +44,7 @@ static const char *const known[] = { "DUMP_LOG", "DYNAMIC_RES", "DYN_DELTA", "EXEFS", "FEEDBACK", "FIXED_RES_PATCH", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES", "FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLUSH_SPAN", "FOV", "FOV_PATCH", "FPS60", "FPS_LIMIT", "FRAME_QUEUE", "FREEZE_IDLE", "FREE_CORES", - "FULLSCREEN", "FXAA", "GPL", "GPL_DRAW_BUILD", "GPU", "GPU_INDEX", "GPU_NAME", "HDR", "HDR_GAME_NITS", "HDR_HUE", + "FULLSCREEN", "FXAA", "GPL", "GPL_DRAW_BUILD", "GPU", "GPU_INDEX", "GPU_NAME", "GRASS_RANGE", "HDR", "HDR_GAME_NITS", "HDR_HUE", "HDR_PEAK_NITS", "HDR_UI_NITS", "HIGHFPS_FIX", "INPUT", "INPUT_RECORD", "INPUT_SCRIPT", "KSPIN_US", "LANG", "LIB_PREBUILD", "LIB_PREBUILD_KEEP", "LIB_PREBUILD_THREADS", "LOCALE", "LOD_GUARD", "LSTICK_DEADZONE", "MEMORY", "MENU_LANG", "MENU_TEST", "MEM_RESERVE_MIB", "MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_ORDER", "MODS_REBUILD", "MOTION", "MOUSE_AIM_SCALE", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOVIE_ASPECT", "MOVIE_HOST", "MOVIE_PACE", @@ -80,7 +80,7 @@ static const struct { const char *key, *section; } sections[] = { {"DLAA", "display"}, {"DLSS", "display"}, {"DLSS_PRESET", "display"}, {"DLSS_CHAR_MASK", "display"}, {"FXAA", "display"}, {"DEVICE_PROFILE", "display"}, {"ASSUME_FOCUS", "display"}, {"DISCORD_RPC", "discord"}, {"DISCORD_APP_ID", "discord"}, {"DISCORD_IMAGE", "discord"}, - {"SHADOW_SCALE", "display"}, {"SHADOW_RANGE", "display"}, {"CONTACT_SHADOWS", "display"}, + {"SHADOW_SCALE", "display"}, {"SHADOW_RANGE", "display"}, {"GRASS_RANGE", "display"}, {"CONTACT_SHADOWS", "display"}, {"PCSS", "display"}, {"MODS_DIR", "mods"}, {"MODS_ORDER", "mods"}, {"MODS_DISABLED", "mods"}, {"MODS_REBUILD", "mods"}, {"TEX_HEAP_EXTRA_MB", "mods"}, @@ -137,7 +137,7 @@ static const CfgMeta metas[] = { {"DEVICE_PROFILE", "auto", "auto|desktop|deck", RESTART}, {"SHADOW_RES", "game", "game|256|512|768|1024|1536|2048", RESTART}, {"SHADOW_SCALE", "1", "1..4", RESTART}, - {"SHADOW_RANGE", "100", "50..400", RESTART}, {"CONTACT_SHADOWS", "0", "0..100", RESTART}, + {"SHADOW_RANGE", "100", "50..400", RESTART}, {"GRASS_RANGE", "100", "50..400", RESTART}, {"CONTACT_SHADOWS", "0", "0..100", RESTART}, {"PCSS", "0", "0..200", RESTART}, // Game {"FPS_LIMIT", "60", "30|40|45|60|90|120|144|display", LIVE}, {"FPS60", "1", "0|1", LIVE}, {"FRAME_QUEUE", "0", "0|1", LIVE}, diff --git a/runtime/host.h b/runtime/host.h index eafbe333..98442f79 100644 --- a/runtime/host.h +++ b/runtime/host.h @@ -279,6 +279,8 @@ int cam_pack_build(const void *in, size_t n, const void *zsdic, size_t zsdic_n, // multiplied, malloc'd; 0 = factor 1 or cannot (logged) void cam_pack_served(void); // romfs.c serves the multiplied pack // ---- game resolution (resolution.c): TOTK_OUTPUT_RES, TOTK_RENDER_SCALE +uint64_t res_grass_heap_extra_kib(void); // TOTK_GRASS_RANGE: added to the HeapDef grass heap; 0 = none +uint64_t res_grass_heap_extra_bytes(void); // the same, added to the application pool, 2 MiB steps uint64_t res_heap_extra_bytes(void); // added to the application pool (mem_init), 2 MiB steps uint64_t res_heap_extra_kib(void); // added to the HeapDef texture heap and its parent; 0 = none uint64_t res_tex_heap_extra_bytes(void); // TOTK_TEX_HEAP_EXTRA_MB: added to the application pool and diff --git a/runtime/memory.c b/runtime/memory.c index bfe11290..078f119a 100644 --- a/runtime/memory.c +++ b/runtime/memory.c @@ -263,11 +263,12 @@ void mem_init(void) { L = (RtGuestLayout){ .aslr = {low, RT_ADDRESS_LIMIT - low}, .stack = {low + STACK_OFF, STACK_SIZE}, - .heap = {low + HEAP_OFF, HEAP_CAP + res_tex_heap_extra_bytes()}, + .heap = {low + HEAP_OFF, HEAP_CAP + res_tex_heap_extra_bytes() + res_grass_heap_extra_bytes()}, .alias = {alias, ALIAS_SIZE}, .kernel = {RT_KERNEL_BASE, RT_KERNEL_SIZE}, .hostfn = {RT_HOSTFN_BASE, RT_HOSTFN_SIZE}, - .pool = pool ? strtoull(pool, NULL, 0) : DEFAULT_POOL + res_heap_extra_bytes() + res_tex_heap_extra_bytes(), + .pool = pool ? strtoull(pool, NULL, 0) + : DEFAULT_POOL + res_heap_extra_bytes() + res_tex_heap_extra_bytes() + res_grass_heap_extra_bytes(), }; if (!L.pool) rt_fatal("memory: TOTK_APP_POOL is 0"); } diff --git a/runtime/resolution.c b/runtime/resolution.c index 36dc2b18..17d3db1e 100644 --- a/runtime/resolution.c +++ b/runtime/resolution.c @@ -243,6 +243,23 @@ static double scene_scale(void) { uint64_t res_heap_extra_bytes(void) { return ((res_heap_extra_kib() << 10) + 0x1fffff) & ~0x1fffffull; } +// TOTK_GRASS_RANGE (percent, 50 to 400; 100 = the game's): how far around the camera grass blades grow. The near grass +// map (the grass patch set, recomp/patches-v121.txt and patches-v143.txt) covers 62.5 m and draws into 256x256 and +// 128x128 textures; other values scale the extent, its step and both textures together, so the grass keeps its detail +// per metre. The larger textures come from the grass heap "草" of the HeapDef, which has no room for them (at 200 % +// without growth the game stops at start on a failed allocation), so it grows by 9318 KiB, its size in 1.4.3, times +// the textures' growth in area (k^2 - 1). +#define GRASS_HEAP_KIB 9318 +static int grass_pct(void) { + int pct = cfg_int("TOTK_GRASS_RANGE"); + return pct < 50 ? 50 : pct > 400 ? 400 : pct; +} +uint64_t res_grass_heap_extra_kib(void) { + int pct = grass_pct(); + return pct > 100 ? (uint64_t)GRASS_HEAP_KIB * (uint64_t)(pct * pct - 10000) / 10000 : 0; +} +uint64_t res_grass_heap_extra_bytes(void) { return ((res_grass_heap_extra_kib() << 10) + 0x1fffff) & ~0x1fffffull; } + // TOTK_TEX_HEAP_EXTRA_MB (0 to 4096): more room in "TextureHeap" and its parent "ゲームグラフィックス", the heap the // world's textures stream into. HD texture packs made for emulators with 8 GB of DRAM grow it by about 3.3 GiB in their // own HeapDef; without the room the game runs out and starts its panic Blood Moon over and over. The pool and the heap @@ -397,9 +414,9 @@ int res_heapdef_plain(const void *in, size_t n) { } int res_heapdef_build(const void *in, size_t n, void **out, size_t *out_n) { - uint64_t extra = res_heap_extra_kib(), tex = tex_heap_extra_kib(); + uint64_t extra = res_heap_extra_kib(), tex = tex_heap_extra_kib(), grass = res_grass_heap_extra_kib(); *out = NULL; - if (!extra && !tex) return 0; + if (!extra && !tex && !grass) return 0; Byml b; uint32_t heaps = 0; size_t dta_at = 0, gfx_at = 0; @@ -439,6 +456,17 @@ int res_heapdef_build(const void *in, size_t n, void **out, size_t *out_n) { } } } + if (grass) { + size_t at = heap_size_field(&b, heaps, "\xe8\x8d\x89"); // 草, the grass heap + if (at) { + int32_t g, g2; + memcpy(&g, b.p + at, 4); + g2 = g + (int32_t)grass; + memcpy(b.p + at, &g2, 4); + rt_log("resolution: HeapDef grass heap %d -> %d KiB (TOTK_GRASS_RANGE)", g, g2); + } else + rt_log("resolution: the HeapDef table has no grass heap; grass_range may run out of grass memory"); + } size_t cap = ZSTD_compressBound(b.n); void *z = malloc(cap); size_t zn = z ? ZSTD_compress(z, cap, b.p, b.n, 9) : 0; @@ -499,8 +527,29 @@ static void res_shadow_range(void) { rt_log("resolution: shadow cascades end at %g, %g, %g and %g m", d[0], d[1], d[2], d[3]); } +// The grass map's values on page +128..+144 (the grass patch set): extent, step, the two texture sizes, and the +// half extent main+0x206340c picks instead of the extent. Texture sizes stay multiples of 32. +static void res_grass_range(void) { + int pct = grass_pct(), set = rt_patch_set("grass"); + if (pct == 100) return; + if (set < 0) { + rt_log("resolution: this game version has no grass patch set; grass_range stays 100"); + return; + } + float k = pct / 100.0f, f[2] = {62.5f * k, 3.90625f * k}, half = 31.25f * k; + uint32_t t[2] = {(uint32_t)(256 * pct / 100 + 16) / 32 * 32, (uint32_t)(128 * pct / 100 + 16) / 32 * 32}; + uint8_t *page = rt_patch_page(); + memcpy(page + 128, f, sizeof f); + memcpy(page + 136, t, sizeof t); + memcpy(page + 144, &half, sizeof half); + rt_patch_switch(set, 1); + rt_log("resolution: grass map %g m, textures %ux%u and %ux%u (TOTK_GRASS_RANGE=%d)", f[0], t[0], t[0], t[1], t[1], + pct); +} + void res_init(void) { res_shadow_range(); + res_grass_range(); if (!bigger()) { rt_log("resolution: the game's own (output 1920x1080, scene 1600x900)"); shadow_init(rt_patch_page()); diff --git a/runtime/romfs.c b/runtime/romfs.c index 3196f7ee..c7110907 100644 --- a/runtime/romfs.c +++ b/runtime/romfs.c @@ -878,7 +878,7 @@ static void *plain_mod_heapdef(size_t *n, const char **who) { return NULL; } static void heapdef_overlay(void) { - if (!res_heap_extra_kib() && !res_tex_heap_extra_bytes()) return; + if (!res_heap_extra_kib() && !res_tex_heap_extra_bytes() && !res_grass_heap_extra_kib()) return; static const char keeps[] = "the game keeps its own resolution"; Overlay *base; size_t n; diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 2bed97ed..b36c4e80 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -552,6 +552,13 @@ static void row_shadow_range(void) { opt_choice_list("TOTK_SHADOW_RANGE", UI_MENU_SHADOW_RANGE, vals, names, 4, UI_MENU_SHADOW_RANGE_DESC); } +static void row_grass_range(void) { + static const char *const vals[] = {"50", "100", "150", "200", "300", "400"}; + static const char *const names[] = {"31 m (0.5x)", "62 m (1x)", "94 m (1.5x)", + "125 m (2x)", "188 m (3x)", "250 m (4x)"}; + opt_choice_list("TOTK_GRASS_RANGE", UI_MENU_GRASS_RANGE, vals, names, 6, UI_MENU_GRASS_RANGE_DESC); +} + static void row_gpu(void) { const char *vals[MAX_GPUS + 1], *names[MAX_GPUS + 1]; char idx[MAX_GPUS][4]; @@ -683,6 +690,7 @@ static void tab_screen(float scale) { opt_choice_list("TOTK_ANISO", UI_MENU_ANISO, aniso, aniso_names, 5, UI_MENU_ANISO_DESC); row_shadow_scale(); row_shadow_range(); + row_grass_range(); opt_slider("TOTK_PCSS", UI_MENU_PCSS, 0, 200, UI_MENU_PCSS_DESC, 10, "%.0f %%"); opt_slider("TOTK_CONTACT_SHADOWS", UI_MENU_CONTACT_SHADOWS, 0, 100, UI_MENU_CONTACT_SHADOWS_DESC, 10, "%.0f %%"); opt_toggle("TOTK_DLAA", UI_MENU_DLAA, UI_MENU_DLAA_DESC); diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 690383b7..1965a5ec 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -141,6 +141,10 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_SHADOW_RANGE_DESC] = "Moves the steps where shadows turn softer (the game's 20, 40, 80 and 160 m) further " "away. Spreads the shadow map over more ground: raise Shadow resolution with it. " "Takes effect at the next start.", + [UI_MENU_GRASS_RANGE] = "Grass range", + [UI_MENU_GRASS_RANGE_DESC] = "How far around the camera grass grows (the game's: 62.5 m). Higher keeps the " + "grass in meadows further out instead of growing it in just in front of you; lower " + "draws less of it. Takes effect at the next start.", [UI_MENU_DLAA] = "NVIDIA DLSS / DLAA", [UI_MENU_DLAA_DESC] = "NVIDIA DLSS for the 3D scene (NVIDIA RTX GPUs; " DLSS_FILE " next to " EXE_FILE "): smoother " "edges and less shimmer. The HUD is not touched. The mode below sets the resolution it works " @@ -624,6 +628,10 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_SHADOW_RANGE_DESC] = "Отодвигает границы, за которыми тени становятся мягче (в игре 20, 40, 80 и 160 м). " "Карта теней растягивается на большую площадь, поэтому вместе с этим поднимайте " "разрешение теней. Действует после перезапуска.", + [UI_MENU_GRASS_RANGE] = "Дальность травы", + [UI_MENU_GRASS_RANGE_DESC] = "Как далеко вокруг камеры растёт трава (в игре 62,5 м). Выше: трава на лугах видна " + "дальше и не вырастает прямо перед вами; ниже: травы меньше. Действует после " + "перезапуска.", [UI_MENU_DLAA] = "NVIDIA DLSS / DLAA", [UI_MENU_DLAA_DESC] = "NVIDIA DLSS для 3D-сцены (видеокарты NVIDIA RTX; " DLSS_FILE " рядом с " EXE_FILE "): ровнее " "края и меньше мерцания. Интерфейс не затрагивается. Режим ниже задаёт разрешение, с которым он " @@ -1451,6 +1459,10 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { [UI_MENU_SHADOW_RANGE_DESC] = "Afasta os degraus em que as sombras ficam mais suaves (20, 40, 80 e 160 m no " "jogo). Espalha o mapa de sombras por mais terreno: aumente a Resolução das sombras " "junto. Vale no próximo início.", + [UI_MENU_GRASS_RANGE] = "Alcance da grama", + [UI_MENU_GRASS_RANGE_DESC] = "Até onde a grama cresce ao redor da câmera (62,5 m no jogo). Mais alto mantém a " + "grama dos campos mais longe em vez de ela surgir logo à sua frente; mais baixo " + "desenha menos grama. Vale no próximo início.", [UI_MENU_CONTACT_SHADOWS] = "Sombras de contato", [UI_MENU_CONTACT_SHADOWS_DESC] = "Pequenas sombras do sol que os mapas de sombra não pegam: nos pés, sob pedras, " "na grama e em dobras. Traçadas na tela depois da iluminação. Vale no próximo " @@ -2070,6 +2082,8 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { [UI_MENU_SHADOW_SCALE_DESC] = "将太阳阴影贴图的每条边绘制为游戏 960x960 的若干倍:阴影边缘和树叶阴影更清晰。下次启动时生效。", [UI_MENU_SHADOW_RANGE] = "阴影级联范围", [UI_MENU_SHADOW_RANGE_DESC] = "把阴影变柔和的分界(游戏中为 20、40、80 和 160 米)推得更远。阴影贴图会覆盖更大的地面,请同时提高阴影分辨率。下次启动时生效。", + [UI_MENU_GRASS_RANGE] = "草地范围", + [UI_MENU_GRASS_RANGE_DESC] = "镜头周围长草的距离(游戏中为 62.5 米)。调高后草地延伸得更远,不会在你面前才长出来;调低则少画一些草。下次启动时生效。", [UI_MENU_CONTACT_SHADOWS] = "接触阴影", [UI_MENU_CONTACT_SHADOWS_DESC] = "阴影贴图遗漏的细小太阳阴影:脚下、石头下、草丛和褶皱中。在光照之后于屏幕空间追踪。下次启动时生效。", [UI_MENU_PCSS] = "柔和阴影", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 3bed8949..de5208fd 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -53,6 +53,7 @@ typedef enum { UI_MENU_HDR_UI, UI_MENU_HDR_UI_DESC, UI_MENU_HDR_HUE, UI_MENU_HDR_HUE_DESC, UI_MENU_SHADOW_SCALE, UI_MENU_SHADOW_SCALE_DESC, UI_MENU_SHADOW_RANGE, UI_MENU_SHADOW_RANGE_DESC, + UI_MENU_GRASS_RANGE, UI_MENU_GRASS_RANGE_DESC, UI_MENU_CONTACT_SHADOWS, UI_MENU_CONTACT_SHADOWS_DESC, UI_MENU_PCSS, UI_MENU_PCSS_DESC, UI_MENU_DLAA, UI_MENU_DLAA_DESC, UI_MENU_DLSS, UI_MENU_DLSS_DESC, UI_MENU_DLSS_DLAA, UI_MENU_DLSS_QUALITY, diff --git a/totk.ini.example b/totk.ini.example index c45a74b2..9845ef94 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -226,6 +226,11 @@ # Sun shadow cascade range in percent of the game's (its cascades end at 20, 40, 80 and 160 m), 50 to 400: higher moves # the steps where shadows turn softer further away, and spreads the shadow map over more ground. Read at start. # shadow_range = 100 +# How far around the camera grass grows, in percent of the game's (its near grass map covers 62.5 m), 50 to 400. +# Higher keeps the grass in meadows further out instead of growing it in a short way in front of you, and draws more of +# it; the grass map's textures grow with it, so its detail per metre stays the game's, and the grass heap grows by about +# 9 MiB times (percent / 100)^2 - 1. Lower draws less grass. Read at start. +# grass_range = 100 # Screen-space contact shadows, strength in percent (0 = off): after the game lights its scene, each pixel traces a # short way toward the sun through the depth buffer and darkens where something close blocks it, adding the small # shadows at feet, under stones and in grass that the shadow maps miss. Read at start. From 2cc0a4eaa6c5a5cb7ef6410f51be6293f113f14f Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 10 Nov 2026 14:32:15 -0500 Subject: [PATCH 19/56] Serve a mod's file named for another game version under its own name instead of leaving it out A mod file whose name carries Product. and which the RomFS lacks was counted as made for another game version and never served. The game does ask for such names: on 1.4.3 with mods on, the file trace (trace = fs) shows it opening Sound/Resource/Pack_MasterSword.Product.110.bars.zs, while its RomFS holds only the Product.140 and the unversioned file. A sound mod that ships its pack under all those names was silent here and works on a console, where LayeredFS shows the game every file of a mod. Such files are now added overlays like any other new file. Another version's resource size table is still not served and still lends its entries; the files are still counted, and the Mods tab and docs/mods.md now say they are read only when asked for by name. tests/mods_romfs_check.py gets a case for it. Not run here: the test and --probe-fs need a build and the game's files. runtime/romfs.c compiles with llvm-mingw. Co-Authored-By: Claude Fable 5.2 Claude-Session: https://claude.ai/code/session_01TgQM2zwuVagwScByEJhT8V --- docs/mods.md | 2 +- runtime/mods.h | 5 +++-- runtime/romfs.c | 16 +++++++++++++--- runtime/ui_text.c | 18 +++++++++++------- runtime/ui_text.h | 2 +- tests/mods_romfs_check.py | 4 +++- 6 files changed, 32 insertions(+), 15 deletions(-) diff --git a/docs/mods.md b/docs/mods.md index c384095f..ab2d804f 100644 --- a/docs/mods.md +++ b/docs/mods.md @@ -111,7 +111,7 @@ keeps its textures at a quarter of the size. | On the Mods tab | Why | What to do | |---|---|---| | This folder has no romfs, exefs or cheats files. | The archive was unpacked one level too deep (`mods\Mod\Mod\romfs`), or it holds no game files. | Move the folders up so `romfs` sits directly in the mod's folder. | -| ... files are made for another game version and are left out. | The mod's files carry another update's version in their names (`.Product..`). | Download the mod's release for your game update. | +| ... files carry another game version in their names. | The files are named for another update (`.Product..`) and the game's own files have no such name. They are still served under those names, as on a console, because the game sometimes asks for one; another update's resource size table is the exception and only lends its entries. | Nothing if the mod works. If it does nothing, download its release for your game update. | | Its code patches (exefs) are made for another game version. | The patch files name another update's build id. | Same: get the release for your update. | | This mod brings its own game code (a subsdk plugin or a replaced main). | Mods such as UltraCam ship compiled Switch code. The port cannot load it. | No workaround; the whole mod stays off. | | This mod patches the game code (exefs) in a way the port cannot apply. | The patch writes the game's data, not its code, or changes code in a form the port cannot build. | No workaround; the reason follows on the row. | diff --git a/runtime/mods.h b/runtime/mods.h index 345fcc2b..8992c080 100644 --- a/runtime/mods.h +++ b/runtime/mods.h @@ -30,8 +30,9 @@ typedef struct { int kind, enabled; ModProblem problem; uint32_t replaced, added, overridden; // romfs.c: files served (replacing / added), files a higher mod serves - uint32_t other_version; // files for another game version (RomFS *.Product..*, ExeFS patches - // for another build), not used + uint32_t other_version; // files named for another game version: RomFS *.Product..* the RomFS + // lacks (served under their own names; another version's size table is + // not) and ExeFS patches for another build (not used) char overridden_by[256]; // the first higher mod that took one of its files char note[256]; // MOD_EXEFS_UNSUPPORTED: why uint32_t pending, pending_key; // ExeFS patch files the build lacks; FNV-1a of their names and contents diff --git a/runtime/romfs.c b/runtime/romfs.c index 3196f7ee..5f2d1372 100644 --- a/runtime/romfs.c +++ b/runtime/romfs.c @@ -340,7 +340,8 @@ static void overlay_push(Overlay o) { } // 1 when path names a file of one game version only (Product. in a name: the resource size table, the actor -// database and other version-bound files); the RomFS lacking it means it is another version's. +// database and other version-bound files); the RomFS lacking it means it is another version's, or a name this version +// still asks for (mod_walk_cb). static int other_version(const char *path) { for (const char *p = strstr(path, ".Product."); p; p = strstr(p + 1, ".Product.")) { const char *d = p + strlen(".Product."); @@ -420,9 +421,18 @@ static int mod_walk_cb(const char *leaf, int kind, uint64_t size, void *ctx) { } uint64_t i = index_any_case(path); if (i == UINT64_MAX && other_version(path)) { - if (is_restbl(path)) shipped_add(file, w->k + 1, 1); // its entries for this mod's files still apply m->other_version++; - return 1; + // Another version's resource size table is no file this game opens; its entries for this mod's files still + // apply. + if (is_restbl(path)) { + shipped_add(file, w->k + 1, 1); + return 1; + } + // Any other file is served under its own name below, as an added file, the way LayeredFS shows a console every + // file of a mod: the game does ask for names its RomFS lacks. Measured on 1.4.3 with mods on (trace = fs): it + // opened Sound/Resource/Pack_MasterSword.Product.110.bars.zs, where its RomFS holds Product.140 and the + // unversioned file only. A sound mod that ships its pack under all those names stayed silent while this file + // was left out. } PlatFile *f = open_read(file); if (!f) { diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 690383b7..315db2d3 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -218,8 +218,9 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_MODS_CHEATS] = "Cheats: %d. Switch them on the Cheats tab.", [UI_MENU_MODS_CHEATS_FILE] = "Cheats for this game version are read at start from cheats\\%s in this mod.", [UI_MENU_MODS_BAD_NAME] = "The folder name contains |, which the mod list uses between names. Rename the folder.", - [UI_MENU_MODS_OTHER_VERSION] = "%u of its files are made for another game version and are left out. Look for a " - "version of this mod made for your game version.", + [UI_MENU_MODS_OTHER_VERSION] = "%u of its files carry another game version in their names. The game reads them only " + "where something asks for those names. If the mod does nothing, look for a version " + "of it made for your game version.", [UI_MENU_MODS_UNUSED] = "not used", [UI_MENU_MODS_FPS60] = "60 FPS patch", [UI_MENU_MODS_FPS60_DESC] = "The port's own patch for 60 frames per second. Set it with Frame rate limit on the " @@ -699,8 +700,9 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_MODS_CHEATS] = "Читов: %d. Они включаются на вкладке «Читы».", [UI_MENU_MODS_CHEATS_FILE] = "Читы для этой версии игры читаются при запуске из cheats\\%s в этом моде.", [UI_MENU_MODS_BAD_NAME] = "В имени папки есть символ |, которым список модов разделяет имена. Переименуйте папку.", - [UI_MENU_MODS_OTHER_VERSION] = "Файлов для другой версии игры: %u, они пропущены. Поищите версию этого мода для " - "вашей версии игры.", + [UI_MENU_MODS_OTHER_VERSION] = "Файлов с другой версией игры в имени: %u. Игра читает их, только когда что-то " + "запрашивает эти имена. Если мод не работает, поищите его версию для вашей версии " + "игры.", [UI_MENU_MODS_UNUSED] = "не используется", [UI_MENU_MODS_FPS60] = "Патч 60 FPS", [UI_MENU_MODS_FPS60_DESC] = "Собственный патч порта для 60 кадров в секунду. Настраивается «Ограничением частоты " @@ -1029,8 +1031,9 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { [UI_MENU_MODS_CHEATS] = "Cheats: %d. Ligue-os na aba Cheats.", [UI_MENU_MODS_CHEATS_FILE] = "Os cheats desta versão do jogo são lidos ao iniciar de cheats\\%s neste mod.", [UI_MENU_MODS_BAD_NAME] = "O nome da pasta contém |, que a lista de mods usa entre os nomes. Renomeie a pasta.", - [UI_MENU_MODS_OTHER_VERSION] = "%u dos seus arquivos são de outra versão do jogo e ficam de fora. Procure uma versão " - "deste mod feita para a sua versão do jogo.", + [UI_MENU_MODS_OTHER_VERSION] = "%u dos seus arquivos trazem outra versão do jogo no nome. O jogo só os lê quando algo " + "pede esses nomes. Se o mod não fizer nada, procure uma versão dele feita para a sua " + "versão do jogo.", [UI_MENU_MODS_UNUSED] = "não usado", [UI_MENU_MODS_FPS60] = "Patch de 60 FPS", [UI_MENU_MODS_FPS60_DESC] = "O patch do próprio port para 60 quadros por segundo. Ajuste em Limite de quadros na aba " @@ -1552,7 +1555,8 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { [UI_MENU_MODS_CHEATS] = "金手指:%d 个。在“金手指”标签页中开关。", [UI_MENU_MODS_CHEATS_FILE] = "此游戏版本的金手指在启动时从此模组的 cheats\\%s 读取。", [UI_MENU_MODS_BAD_NAME] = "文件夹名称含有 |,模组列表用它分隔名称。请重命名该文件夹。", - [UI_MENU_MODS_OTHER_VERSION] = "它有 %u 个文件是为其他游戏版本制作的,已被跳过。请寻找适用于你的游戏版本的此模组。", + [UI_MENU_MODS_OTHER_VERSION] = "它有 %u 个文件的文件名带有其他游戏版本号。只有在有内容请求这些文件名时,游戏才会读取它们。" + "如果模组不起作用,请寻找适用于你的游戏版本的此模组。", [UI_MENU_MODS_UNUSED] = "未使用", [UI_MENU_MODS_FPS60] = "60 FPS 补丁", [UI_MENU_MODS_FPS60_DESC] = "移植版自带的 60 帧补丁。在“游戏”页的帧率上限中设置。", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 3bed8949..222b6185 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -88,7 +88,7 @@ typedef enum { UI_MENU_MODS_EXEFS_OTHER, UI_MENU_MODS_EXEFS_ON, // printf: its ExeFS patch files in use UI_MENU_MODS_REPLACES_BUILTIN, // printf: its ExeFS patch files in use, the port's own patch sets they turn off - UI_MENU_MODS_OTHER_VERSION, // printf: files made for another game version, left out + UI_MENU_MODS_OTHER_VERSION, // printf: files named for another game version, read only when asked for by name UI_MENU_MODS_UNUSED, // under the switch of a mod the port cannot use UI_MENU_MODS_CHEATS, // printf: its cheats as read at start UI_MENU_MODS_CHEATS_FILE, // printf: .txt, when none were read diff --git a/tests/mods_romfs_check.py b/tests/mods_romfs_check.py index c3eb5b1b..4ae2e062 100644 --- a/tests/mods_romfs_check.py +++ b/tests/mods_romfs_check.py @@ -152,13 +152,15 @@ def main(): put(mods, UNI, p2, b'mod-G') # a file of another game version's (no RomFS has a Product.999 table): counted, never served put(mods, 'Low', 'System/Resource/ResourceSizeTable.Product.999.rsizetable.zs', b'mod-H') + # any other file named for another version: counted, and served under its name as an added file + put(mods, 'Case', 'Sound/Resource/Named.Product.999.bars', b'mod-J') put(mods, 'Lite', 'Lite/added.bin', b'mod-I', part='romfslite') # TKMM's romfslite folder code, log = run(args.exe, mods, f'Top|Low|{UNI}|Case') check(code == 0, 'probe-fs passes with five mods (served bytes equal the winners\' files)', log) for line in ('mods: Top: 2 files served (1 replaced, 1 added), 0 overridden', 'mods: Low: 1 files served (1 replaced, 0 added), 2 overridden by Top, 1 for another game version', - 'mods: Case: 0 files served (0 replaced, 0 added), 1 overridden by Top', + 'mods: Case: 1 files served (0 replaced, 1 added), 1 overridden by Top, 1 for another game version', f'mods: {UNI}: 0 files served (0 replaced, 0 added), 1 overridden by Low', 'mods: Lite: 1 files served (0 replaced, 1 added), 0 overridden'): check(line in log, line, log) From 5e6ebd8bbc31934b4c7068d87eb7b555886806c5 Mon Sep 17 00:00:00 2001 From: toadjiang Date: Mon, 9 Nov 2026 10:45:05 -0800 Subject: [PATCH 20/56] Free all DLSS size slots when the preset changes evaluate's preset_dirty loop stopped at slot 3 of the five D.sizes entries, so a preset change left the features in slots 3 and 4 created with the old model: they kept running until the slot was evicted. The loop now covers the whole array through DLSS_SIZES instead of a literal. Taken from pull request #1057 (t04dJ14n9) alone; the PR's dlss_prewarm commits are not in this change. (cherry picked from commit a76bdf5e0817be887a4db3632a4e3f4e6b592337) Co-Authored-By: Claude Opus 5.5 --- runtime/vk_dlaa.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/vk_dlaa.c b/runtime/vk_dlaa.c index 194c23b9..48af8738 100644 --- a/runtime/vk_dlaa.c +++ b/runtime/vk_dlaa.c @@ -294,6 +294,7 @@ static struct { unsigned cfg_seen; // cfg_version when preset was read uint64_t last_eval_ns; // plat_now_ns of the previous evaluation (FrameTimeDeltaInMsec) } D = {.mv_ok = -1, .cfg_seen = ~0u}; +#define DLSS_SIZES (sizeof D.sizes / sizeof D.sizes[0]) const VkTexImage *vk_dlaa_swap_img; VkImageView vk_dlaa_swap_view; @@ -949,7 +950,7 @@ static void evaluate(VkExec *ex, const VkExecTarget *dst) { VkCommandBuffer cb = ex->cb; vk_exec_barrier(ex); // what drew the scene is done (no pass is open here) if (D.preset_dirty) { // another model: features are created with it, so every size gets a new one - for (int i = 0; i < 3; i++) + for (size_t i = 0; i < DLSS_SIZES; i++) if (D.sizes[i].out) free_size(&D.sizes[i]); D.last = NULL, D.preset_dirty = 0; } From bb339a614d06525f33f98acb8eddd17e30fc80d2 Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Tue, 10 Nov 2026 23:08:43 +0300 Subject: [PATCH 21/56] Import at the top of tests/run_all.py and list cheats_vm_check json, shutil and tomllib were imported inside the functions that use them. cheats_vm_check came into dev after the table was written; it compiles runtime/cheats.c with clang like mouse_direct_check, so it takes the same cc need. Co-Authored-By: Claude Opus 5.5 --- tests/run_all.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/run_all.py b/tests/run_all.py index 96f2a007..1e218473 100644 --- a/tests/run_all.py +++ b/tests/run_all.py @@ -16,10 +16,13 @@ No third-party imports: this runs before any venv is trusted. """ import argparse +import json import os +import shutil import subprocess import sys import time +import tomllib from pathlib import Path ROOT = Path(__file__).resolve().parents[1] @@ -54,6 +57,7 @@ TESTS = { 'exefs_patches_test': ('.venv', None, [], ''), 'settings_doc_check': ('.venv', None, [], ''), 'mouse_direct_check': ('.venv', 'cc', ['--cc', ''], 'compiles its checks with clang'), + 'cheats_vm_check': ('.venv', 'cc', ['--cc', ''], 'compiles runtime/cheats.c into a harness with clang'), 'diff/atomic': ('.venv', None, [], ''), 'diff/simd': ('.venv', None, [], ''), # ---- read the game or a build ---- @@ -78,7 +82,6 @@ def load_work_dir(): if not cfg.exists(): return ROOT / 'build' try: - import tomllib with open(cfg, 'rb') as f: d = tomllib.load(f).get('work', {}).get('dir') return Path(d) if d else ROOT / 'build' @@ -110,7 +113,6 @@ def find_romfs(): gui = ROOT / 'build' / 'build_gui.json' # the GUI builder remembers where it built from if gui.exists(): try: - import json r = json.loads(gui.read_text(encoding='utf-8')).get('romfs') if r: cands.append(Path(r)) @@ -134,7 +136,6 @@ def find_cc(): c = MSYS_BIN / 'clang.exe' if WIN and c.exists(): return c - import shutil w = shutil.which('clang') return Path(w) if w else None From 7fa727bbc5b1fce70775522576aeeabcf39d539b Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Tue, 10 Nov 2026 23:24:11 +0300 Subject: [PATCH 22/56] Skip the present lock for the Reflex frame ID when nothing reads it, and declare the front end's Reflex calls in gfx.h vk_reflex_present_frame took g_pl on every present although only flip_locked's VkPresentIdKHR (Reflex) and latency_note (TOTK_TRACE=perf) read g_blit_pid. nvn_api_obj.c and ov_input.c declared vk_reflex_marker, vk_reflex_frame_begin, vk_reflex_frame and vk_reflex_sleep locally; they now come from gfx.h, the graphics layer's interface, which gfx_present.c also sees through vk.h, so a changed signature fails to compile. vk.h stays out of those two files: it brings in Vulkan, VMA and vk_rec.h's vkCmd* macros. Co-Authored-By: Claude Opus 5.5 --- runtime/gfx.h | 6 ++++++ runtime/gfx_present.c | 3 +++ runtime/nvn_api_obj.c | 5 ----- runtime/ov_input.c | 4 +--- runtime/vk.h | 4 ---- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/runtime/gfx.h b/runtime/gfx.h index 0bed28d1..2475cc57 100644 --- a/runtime/gfx.h +++ b/runtime/gfx.h @@ -24,6 +24,12 @@ uint64_t gfx_vsync_time_ns(uint64_t tick); // kern_now_ns() time double gfx_window_refresh_hz(void); // refresh rate of the window's monitor; 0 unknown int gfx_window_focused(void); int gfx_picture_rect(float out[4]); // where the last present put the picture, fractions of the swapchain (x, y, w, h); 0 before one +// NVIDIA Reflex (gfx_present.c, VK_NV_low_latency2): the NVN front end and the input service mark a frame's stages. +// The markers and the sleep return at once with Reflex off or unsupported. +void vk_reflex_marker(int marker, uint64_t present_id); // present_id: the frame's (vk_reflex_frame_begin) +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 // ---- 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 }; diff --git a/runtime/gfx_present.c b/runtime/gfx_present.c index 53d47e19..f63092e5 100644 --- a/runtime/gfx_present.c +++ b/runtime/gfx_present.c @@ -386,6 +386,9 @@ uint64_t vk_reflex_submit_id(void) { return t_reflex_submit ? t_reflex_submit : // The present thread, before the blit of frame id: the present of that blit carries id. 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; plat_rmutex_lock(&g_pl); g_blit_pid = id; plat_rmutex_unlock(&g_pl); diff --git a/runtime/nvn_api_obj.c b/runtime/nvn_api_obj.c index 8fc698bf..8500a70b 100644 --- a/runtime/nvn_api_obj.c +++ b/runtime/nvn_api_obj.c @@ -19,11 +19,6 @@ #include "nvn_tex.h" #include "platform/platform.h" -void vk_reflex_marker(int marker, uint64_t present_id); -uint64_t vk_reflex_frame_begin(void); -uint64_t vk_reflex_frame(void); -void vk_reflex_sleep(void); - // ---------- Descriptor pools // NVNboolean nvnTexturePoolInitialize(NVNtexturePool *tp, const NVNmemoryPool *p, ptrdiff_t offset, int n) NVN_API(nvnTexturePoolInitialize) { diff --git a/runtime/ov_input.c b/runtime/ov_input.c index 2a2f34a3..e56c4eb0 100644 --- a/runtime/ov_input.c +++ b/runtime/ov_input.c @@ -12,14 +12,12 @@ #include #include "cfg.h" +#include "gfx.h" #include "host.h" #include "input.h" #include "ov.h" #include "platform/platform.h" -void vk_reflex_marker(int marker, uint64_t present_id); -uint64_t vk_reflex_frame(void); - typedef struct { int64_t sampling; uint64_t buttons; int32_t lx, ly, rx, ry; uint32_t attributes, pad; } NpadState; typedef struct { int64_t sampling; int32_t x, y, dx, dy, wx, wy; uint32_t buttons, attributes; } MouseState; typedef struct { int64_t sampling; uint32_t modifiers, attributes; uint64_t keys[4]; } KeyboardState; diff --git a/runtime/vk.h b/runtime/vk.h index c1185f54..82154bb8 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -148,13 +148,9 @@ void vk_present_blit(VkImage src, VkImageLayout layout, VkFormat fmt, int w, int int vk_fsr_record(VkCommandBuffer cb, unsigned slot, VkImage src, VkFormat fmt, int sw, int sh, const int crop[4], VkImage dst, const int out[4]); void vk_fsr_release(void); // before the device goes away -void vk_reflex_marker(int marker, uint64_t present_id); // present_id: the frame's (vk_reflex_frame_begin) -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_submit_frame(uint64_t id); // this thread's submissions belong to frame id (0: the game's current one) uint64_t vk_reflex_submit_id(void); void vk_reflex_present_frame(uint64_t id); // the present thread, before the blit of frame id -void vk_reflex_sleep(void); int vk_has_reflex(void); // Colour adjustment on the present (vk_color.c): with TOTK_COLOR_* away from their defaults, records a pass that writes // src's crop rectangle {x, y, w, h}, adjusted, into an RGBA16F image of that size in GENERAL and returns it (the caller From 1becabd8f6e44af6e9cabbd7435cc21ad2e6ded8 Mon Sep 17 00:00:00 2001 From: Louis Justice Date: Tue, 10 Nov 2026 16:27:03 -0500 Subject: [PATCH 23/56] The left mouse button presses A on the Purah Pad's map instead of its binding (map_click, game 1.4.3). Co-Authored-By: Claude Opus 5.5 --- docs/controls.md | 4 ++++ runtime/cfg.c | 5 +++-- runtime/input.c | 8 ++++++++ runtime/menu_cursor.c | 3 +++ runtime/ui/menu.cpp | 1 + runtime/ui_text.c | 8 ++++++++ runtime/ui_text.h | 1 + totk.ini.example | 4 ++++ 8 files changed, 32 insertions(+), 2 deletions(-) diff --git a/docs/controls.md b/docs/controls.md index 0263fbf4..cb33dad1 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -203,6 +203,10 @@ On game 1.4.3, while one of the game's menus has its focus box (the frame the d- `runtime/menu_cursor.c` reads eui's screens at each pad read and moves the focus with the writes `eui::BoxCursorMgr::moveBoxCursor` makes, so no game code is called. `menu_cursor = 0` (`TOTK_MENU_CURSOR=0`, live; the *Mouse in the game's menus* row of the Controls tab) turns it off; `TOTK_MENU_CURSOR_LOG=1` logs every screen it reads (by default the first six), with the layout size, the node count and the hit panes it uses. +### Left click on the map + +On game 1.4.3, while the Purah Pad's map is open (found as above; the Scope is not the map), the left mouse button presses A at the map's cursor instead of the button it is bound to (Y by default). A press is A or the binding from the moment the button goes down until it is released, so a button held as the map opens or closes keeps what it pressed (`poll_merged` in `runtime/input.c`). `map_click = 0` (`TOTK_MAP_CLICK=0`, live; the *Left click on the map* row of the Controls tab) leaves the left button on its binding there. The map is found only while `menu_cursor` is on. + ## Nintendo Switch 2 controllers Windows does not present the Switch 2 Pro Controller as a gamepad SDL can open (the log says `input: no gamepad`), so it needs a bridge program that wakes it and creates a virtual gamepad. The DS4Windows fork by hbashton ([github.com/hbashton/DS4Windows](https://github.com/hbashton/DS4Windows), tested with release VIIPERRC4.5.1, a pre-release) with the output set to an emulated DualSense gives buttons, rumble, gyro and accelerometer, and reads the sticks through the controller's calibration (they rest at 0 to 2%). The game reads its virtual DualSense directly; the log then shows `input: gamepad "DualSense Wireless Controller" (rumble, gyro and accelerometer, ...)` and `input: motion sensors on`. Its release notes also list Joy-Con 2 support, which is untested here. diff --git a/runtime/cfg.c b/runtime/cfg.c index dbb73f7d..06878bcc 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -46,7 +46,7 @@ static const char *const known[] = { "FREEZE_IDLE", "FREE_CORES", "FULLSCREEN", "FXAA", "GPL", "GPL_DRAW_BUILD", "GPU", "GPU_INDEX", "GPU_NAME", "HDR", "HDR_GAME_NITS", "HDR_HUE", "HDR_PEAK_NITS", "HDR_UI_NITS", "HIGHFPS_FIX", "INPUT", "INPUT_RECORD", "INPUT_SCRIPT", "KSPIN_US", "LANG", "LIB_PREBUILD", - "LIB_PREBUILD_KEEP", "LIB_PREBUILD_THREADS", "LOCALE", "LOD_GUARD", "LSTICK_DEADZONE", "MEMORY", "MENU_LANG", "MENU_TEST", + "LIB_PREBUILD_KEEP", "LIB_PREBUILD_THREADS", "LOCALE", "LOD_GUARD", "LSTICK_DEADZONE", "MAP_CLICK", "MEMORY", "MENU_LANG", "MENU_TEST", "MEM_RESERVE_MIB", "MENU_CURSOR", "MENU_CURSOR_LOG", "MENU_TEST_DIR", "MENU_TEST_SET", "MINIMAL_LAYOUT", "MIRROR_GAP", "MODS_DIR", "MODS_DISABLED", "MODS_ORDER", "MODS_REBUILD", "MOTION", "MOUSE_AIM_SCALE", "MOUSE_MODE", "MOUSE_DIRECT_PATCH", "MOUSE_SENS", "MOVIE_ASPECT", "MOVIE_HOST", "MOVIE_PACE", "MVOBJ_ALL", "MVOBJ_BANKS", "MVOBJ_EQUAL", "MVOBJ_EXACT", "MVOBJ_EXEC", "MVOBJ_NOC4", "MVOBJ_ONLY", "MVOBJ_TIMES", "MVPREV_CHECK", "MVPREV_GROW", "MVPREV_SKIP", "MVPREV_TRUST", "MV_CHECK", "MV_SURVEY", @@ -89,7 +89,7 @@ static const struct { const char *key, *section; } sections[] = { {"MOTION", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"}, {"PAD_LAYOUT", "input"}, {"PROMPTS", "input"}, {"STICK_DEADZONE", "input"}, {"LSTICK_DEADZONE", "input"}, {"RSTICK_DEADZONE", "input"}, {"STICK_SENS", "input"}, - {"MENU_CURSOR", "input"}, {"MOUSE_MODE", "input"}, {"MOUSE_SENS", "input"}, {"MOUSE_AIM_SCALE", "input"}, {"WALK_KEY", "input"}, {"WALK_SCALE", "input"}, {"INPUT_RECORD", "input"}, + {"MENU_CURSOR", "input"}, {"MAP_CLICK", "input"}, {"MOUSE_MODE", "input"}, {"MOUSE_SENS", "input"}, {"MOUSE_AIM_SCALE", "input"}, {"WALK_KEY", "input"}, {"WALK_SCALE", "input"}, {"INPUT_RECORD", "input"}, {"BIND_A", "input"}, {"BIND_B", "input"}, {"BIND_X", "input"}, {"BIND_Y", "input"}, {"BIND_LCLICK", "input"}, {"BIND_RCLICK", "input"}, {"BIND_L", "input"}, {"BIND_R", "input"}, {"BIND_ZL", "input"}, {"BIND_ZR", "input"}, {"BIND_PLUS", "input"}, {"BIND_MINUS", "input"}, {"BIND_LEFT", "input"}, {"BIND_UP", "input"}, @@ -156,6 +156,7 @@ static const CfgMeta metas[] = { {"LSTICK_DEADZONE", "", "0..50", LIVE}, {"RSTICK_DEADZONE", "", "0..50", LIVE}, {"MOUSE_MODE", "direct", "stick|direct", LIVE}, {"MOUSE_SENS", "1", "0..10", LIVE}, {"MOUSE_AIM_SCALE", "1", "0.1..3", LIVE}, {"MENU_CURSOR", "1", "0|1", LIVE}, + {"MAP_CLICK", "1", "0|1", LIVE}, // input.c: the left mouse button is A on the Purah Pad's map {"WALK_KEY", "none", NULL, LIVE}, {"WALK_SCALE", "0.51", "0.2..0.9", LIVE}, {"MENU_LANG", "", "en|ru|pt-BR|zh-Hans", LIVE}, {"AMIIBO_DIR", "", NULL, LIVE}, diff --git a/runtime/input.c b/runtime/input.c index 6cfca650..ccf61452 100644 --- a/runtime/input.c +++ b/runtime/input.c @@ -641,6 +641,14 @@ static void poll_merged(uint64_t *buttons, int32_t *lx, int32_t *ly, int32_t *rx if (!counts || mouse_ignore[k]) down[k] = 0; } was_captured = cap; + // On the Purah Pad's map (menu_cursor.c finds it, TOTK_MAP_CLICK) the left mouse button presses A at the + // map's cursor, which the mouse moves there, instead of its binding (Y by default). A press is one or the + // other from the moment it goes down until it is released, so a button held as the map opens or closes + // keeps what it pressed. + static int click_held, click_a; + if (!down[KEY_MOUSE_L]) click_held = click_a = 0; + else if (!click_held) click_held = 1, click_a = menu_cursor_map() && cfg_bool("TOTK_MAP_CLICK"); + if (click_a) down[KEY_MOUSE_L] = 0, b |= 1ull << B_A; b |= input_map_buttons(down); int32_t k[2]; walk_get(); diff --git a/runtime/menu_cursor.c b/runtime/menu_cursor.c index a2d8e093..25bd0afc 100644 --- a/runtime/menu_cursor.c +++ b/runtime/menu_cursor.c @@ -20,6 +20,9 @@ // // Only while keyboard and mouse are the device used last (input_kbm_last): a gamepad player sees the menus unchanged. // TOTK_MENU_CURSOR (live, default 1): 0 leaves the menus to the keys and the pad. +// +// On the map input.c makes the left mouse button A (menu_cursor_map; TOTK_MAP_CLICK, live, default 1), so a click +// acts at the map's cursor. The map is found only while TOTK_MENU_CURSOR is on. #include #include #include diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 2bed97ed..5ecfa5d3 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -867,6 +867,7 @@ static void tab_controls(float scale) { opt_choice("TOTK_MOUSE_MODE", UI_MENU_MOUSE_MODE, mouse_modes, 2, UI_MENU_MOUSE_MODE_DESC); opt_slider("TOTK_MOUSE_SENS", UI_MENU_MOUSE_SENS, 0, 10, UI_MENU_MOUSE_SENS_DESC, 0.1f, "%.1f"); opt_toggle("TOTK_MENU_CURSOR", UI_MENU_MENU_CURSOR, UI_MENU_MENU_CURSOR_DESC); + opt_toggle("TOTK_MAP_CLICK", UI_MENU_MAP_CLICK, UI_MENU_MAP_CLICK_DESC); row_walk_key(); opt_slider("TOTK_WALK_SCALE", UI_MENU_WALK_SCALE, 0.2f, 0.9f, UI_MENU_WALK_SCALE_DESC, 0.01f, "%.2f"); // Analog sticks: one dead zone row per stick, falling back to TOTK_STICK_DEADZONE (both sticks) while unset. With diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 690383b7..ad1c55a9 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -283,6 +283,8 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_MOUSE_DIRECT] = "Direct", [UI_MENU_MENU_CURSOR] = "Mouse in the game's menus", [UI_MENU_MENU_CURSOR_DESC] = "In the game's own menus (title, inventory, shops, dialogue choices) the pointer shows: the item under it is selected, left click confirms, right click goes back. Only after the mouse or a key was used last, so a gamepad sees the menus unchanged (game 1.4.3).", + [UI_MENU_MAP_CLICK] = "Left click on the map", + [UI_MENU_MAP_CLICK_DESC] = "On the Purah Pad's map, the left mouse button presses A at the map's cursor instead of the button it is bound to (Y by default). Needs Mouse in the game's menus (game 1.4.3).", [UI_MENU_MOUSE_SENS] = "Mouse camera sensitivity", [UI_MENU_MOUSE_SENS_DESC] = "How fast the mouse turns the camera.", [UI_MENU_WALK_KEY] = "Walk key", @@ -763,6 +765,8 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_MOUSE_DIRECT] = "Прямое", [UI_MENU_MENU_CURSOR] = "Мышь в меню игры", [UI_MENU_MENU_CURSOR_DESC] = "В меню самой игры (заставка, инвентарь, магазины, варианты ответа) появляется указатель: пункт под ним выбирается, левый щелчок подтверждает, правый возвращает назад. Только если последними использовались мышь или клавиатура, поэтому с геймпадом меню не меняются (версия игры 1.4.3).", + [UI_MENU_MAP_CLICK] = "Левый щелчок на карте", + [UI_MENU_MAP_CLICK_DESC] = "На карте игры левая кнопка мыши нажимает A у курсора карты, а не назначенную ей кнопку (по умолчанию Y). Нужна «Мышь в меню игры» (версия игры 1.4.3).", [UI_MENU_MOUSE_SENS] = "Чувствительность мыши", [UI_MENU_MOUSE_SENS_DESC] = "Как быстро мышь поворачивает камеру.", [UI_MENU_WALK_KEY] = "Клавиша шага", @@ -1416,6 +1420,8 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { [UI_MENU_MOUSE_DIRECT] = "Direta", [UI_MENU_MENU_CURSOR] = "Mouse nos menus do jogo", [UI_MENU_MENU_CURSOR_DESC] = "Nos menus do próprio jogo (título, inventário, lojas, escolhas de diálogo) o ponteiro aparece: o item sob ele fica selecionado, o clique esquerdo confirma e o direito volta. Só depois de usar o mouse ou uma tecla por último, então com um controle os menus ficam como antes (jogo 1.4.3).", + [UI_MENU_MAP_CLICK] = "Clique esquerdo no mapa", + [UI_MENU_MAP_CLICK_DESC] = "No mapa do jogo, o botão esquerdo do mouse aperta A no cursor do mapa, em vez do botão ao qual está atribuído (Y por padrão). Requer Mouse nos menus do jogo (jogo 1.4.3).", [UI_MENU_PROMPTS_MISSING] = "faltam os arquivos dos ícones: execute a instalação de novo", [UI_MENU_PROMPTS_FAILED] = "arquivos dos ícones danificados: execute a instalação de novo", [UI_MENU_PROMPTS_RESTART] = "os ícones mudam após reiniciar", @@ -2045,6 +2051,8 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { [UI_MENU_MOUSE_DIRECT] = "直接", [UI_MENU_MENU_CURSOR] = "在游戏菜单中使用鼠标", [UI_MENU_MENU_CURSOR_DESC] = "在游戏自身的菜单中(标题、背包、商店、对话选项)显示指针:指针下的项目被选中,左键确认,右键返回。仅在最后使用的是鼠标或键盘时生效,因此使用手柄时菜单保持不变(游戏 1.4.3)。", + [UI_MENU_MAP_CLICK] = "在地图上左键单击", + [UI_MENU_MAP_CLICK_DESC] = "在游戏地图上,鼠标左键在地图光标处按下 A 键,而不是按下它所绑定的按键(默认为 Y)。需要开启“在游戏菜单中使用鼠标”(游戏 1.4.3)。", [UI_MENU_PROMPTS_MISSING] = "缺少按键提示文件:请重新运行安装程序", [UI_MENU_PROMPTS_FAILED] = "按键提示文件已损坏:请重新运行安装程序", [UI_MENU_PROMPTS_RESTART] = "按键提示重启后生效", diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 3bed8949..c077c608 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -116,6 +116,7 @@ typedef enum { UI_MENU_STICK_DEADZONE_NOW, UI_MENU_STICK_SENS, UI_MENU_STICK_SENS_DESC, UI_MENU_MOUSE_MODE, UI_MENU_MOUSE_MODE_DESC, UI_MENU_MOUSE_STICK, UI_MENU_MOUSE_DIRECT, UI_MENU_MENU_CURSOR, UI_MENU_MENU_CURSOR_DESC, + UI_MENU_MAP_CLICK, UI_MENU_MAP_CLICK_DESC, UI_MENU_MOUSE_SENS, UI_MENU_MOUSE_SENS_DESC, UI_MENU_WALK_KEY, UI_MENU_WALK_KEY_DESC, UI_MENU_WALK_KEY_TAKEN, UI_MENU_WALK_SCALE, UI_MENU_WALK_SCALE_DESC, diff --git a/totk.ini.example b/totk.ini.example index c45a74b2..1aca43cf 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -348,6 +348,10 @@ # right click is B. On the map the mouse moves the map's cursor and the scroll wheel zooms. 0 leaves the menus and # the map to the keys and the pad. Changes while the game runs. # menu_cursor = 1 +# The left mouse button on the Purah Pad's map, 1.4.3 only: it presses A at the map's cursor instead of the button it +# is bound to (Y by default). Needs menu_cursor = 1, which finds the map. 0 leaves the left button on its binding +# there. Changes while the game runs. +# map_click = 1 # Mouse camera sensitivity (0 to 10; 0 = no mouse camera and no cursor capture). With mouse_mode = direct, 1 turns the # camera 0.08 degrees per count, the same in every camera mode (about 14.3 cm a turn at 800 DPI). # mouse_sens = 1 From c2716d2e7c305c1c812f09a7bda6222750646e57 Mon Sep 17 00:00:00 2001 From: Louis Justice Date: Tue, 10 Nov 2026 18:11:38 -0500 Subject: [PATCH 24/56] The keyboard and mouse text prompts show Y as T, and the setup draws the PC prompts from totk.ini's bindings. Y has two default keys: the left mouse button, which is a menu's A while the pointer is shown, and T, which presses Y everywhere. The button font (menu guides, the dialogue log) now shows Y as its first bound key that is not a mouse button; the button guide in play and the action prompt keep the left button. The PC prompts are a setup step of their own, keyed by the bind_ lines of the install's totk.ini, so running the setup again after rebinding redraws them without preparing the shaders again. Co-Authored-By: Claude Opus 5.5 --- docs/controls.md | 5 +-- installer/gui.py | 2 +- installer/guilogic.py | 2 +- installer/steps.py | 67 ++++++++++++++++++++++++++++++++++--- installer/text/en.json | 2 ++ installer/text/pt-BR.json | 2 ++ installer/text/ru.json | 2 ++ installer/text/zh-Hans.json | 2 ++ tests/installer_test.py | 2 +- tests/romfs_prompts_test.py | 15 +++++++++ tools/button_icons.py | 23 +++++++++---- tools/make_romfs_patches.py | 15 ++++++--- 12 files changed, 118 insertions(+), 21 deletions(-) diff --git a/docs/controls.md b/docs/controls.md index 0263fbf4..0c58515e 100644 --- a/docs/controls.md +++ b/docs/controls.md @@ -65,7 +65,7 @@ At a game resolution of another shape than 16:9 the game loads `romfs-patches-xb | Switch | Prompt | |---|---| -| A, B, X, Y | E, Shift, Space, left click | +| A, B, X, Y | E, Shift, Space, left click (T in text prompts) | | L, R, ZL, ZR | Q, R, right click, F | | Plus, Minus | Tab, M | | D-pad | 1 (left), 2 (up), 3 (right), 4 (down), as a cross or the keys of the directions meant | @@ -74,7 +74,8 @@ At a game resolution of another shape than 16:9 the game loads `romfs-patches-xb - The glyphs keep the width of the game's own, so the right-aligned guides do not run into their text. A key is a rounded square with its label cut out in the game's own text fonts (Shift: an arrow over its name); a mouse button is a mouse with that button filled and the others hollow. - The button guide in play draws every button from images of the Common archive (`Nt_KeyTexA/B/X/Y/L/ZL_00`, `Nt_KeyTexLSt_00` and `_01`, the stick tilted and pressed): all of them are painted with the same icons. The letters of the action prompt's diamond are one character of the Normal font each: E, an arrow for Shift, a bar for Space, L and R for the mouse buttons. -- Like the Xbox prompts they follow the defaults and not the bindings. `--binds ` draws the first key of each `bind_` line of that file instead, for a folder made by hand. +- Y has two keys, the left mouse button and T. The button guide in play and the action prompt show the left button, which attacks there; the prompts in text (the menus' guides such as *Sort*, the dialogue log's) show T, because while a menu has the pointer the left button is that menu's A, and T presses Y everywhere (`PC_TEXT_KEYS` in `tools/button_icons.py`). With a `bind_y` line, the text prompts take its first key that is not a mouse button (its only key when all are mouse buttons). +- They follow the bindings of the install's `totk.ini` as the setup found them: its *Drawing the keyboard and mouse prompts* step passes the file as `--binds` (the first key of each `bind_` line), and the keyboard defaults without one. After a change on the Controls tab run the setup again: that step alone runs, since it is keyed by the `bind_` lines (`PcPrompts` in `installer/steps.py`). The Xbox prompts follow the defaults. - At a game resolution of another shape than 16:9 the game loads `romfs-patches-pc-x` in place of `romfs-patches-x`: the same prompts with that shape's UI layout, `make_romfs_patches.py --prompts pc --aspect x --reuse \romfs-patches-pc --out \romfs-patches-pc-x`. The setup writes one for each of the fifteen sizes it lays the UI out for, so on a display of one of those shapes the game resolution follows the display with these prompts too. At another size, without that folder, the Switch prompts stay (*off at this game resolution*). ## Window keys diff --git a/installer/gui.py b/installer/gui.py index 9c0dc1fd..cddc6530 100644 --- a/installer/gui.py +++ b/installer/gui.py @@ -619,7 +619,7 @@ class App: # ---- self test --------------------------------------------------------------------------------------------------- SAMPLE_START = {'type': 'start', 'release': 'selftest', 'mode': 'install', 'dest': 'Z:/selftest/TotK', 'log': 'D:\\log.txt', - 'steps': ['check', 'fonts', 'extract', 'lift', 'compile', 'prepare', 'dlss', 'cleanup']} + 'steps': ['check', 'fonts', 'extract', 'lift', 'compile', 'prepare', 'pc_prompts', 'dlss', 'cleanup']} SAMPLE_RUN = [ SAMPLE_START, {'type': 'plan', 'run': ['check', 'fonts', 'extract'], 'skip': {}}, diff --git a/installer/guilogic.py b/installer/guilogic.py index f17a2dc4..e46b1025 100644 --- a/installer/guilogic.py +++ b/installer/guilogic.py @@ -27,7 +27,7 @@ TEXT = Path(__file__).resolve().parent / 'text' UI_LANGUAGES = ('en', 'ru', 'pt-BR', 'zh-Hans') # what the language switch in the window's corner shows for each UI_LANGUAGE_LABELS = {'en': 'English', 'ru': 'Русский', 'pt-BR': 'Português (Brasil)', 'zh-Hans': '简体中文'} -STEP_ORDER = ('check', 'fonts', 'extract', 'lift', 'compile', 'prepare', 'dlss', 'cleanup') +STEP_ORDER = ('check', 'fonts', 'extract', 'lift', 'compile', 'prepare', 'pc_prompts', 'dlss', 'cleanup') # message parameter -> catalog id prefix of the names that replace its raw values PARAM_NAMES = {'lang': 'lang.', 'known': 'lang.', 'step': 'step.', 'input': 'param.input.'} LANG_RU = 0x19 # primary language id of Russian in a Windows LANGID diff --git a/installer/steps.py b/installer/steps.py index 49ce815d..69dcefa0 100644 --- a/installer/steps.py +++ b/installer/steps.py @@ -1098,10 +1098,10 @@ class Prepare(Step): # romfs-patches-xbox for the Nintendo pad layout, romfs-patches-xbox-label for xbox and auto (runtime/input_map.c # input_prompts_folder). Both are written on every install, so the menu choices work without another run of # the setup. Optional: when one fails, the game keeps the Switch prompts with that layout and the menu says the - # files are missing, so the setup warns once and goes on. romfs-patches-pc likewise, with keyboard and mouse - # prompts for prompts = pc. + # files are missing, so the setup warns once and goes on. The keyboard and mouse prompts are the PcPrompts + # step's: they follow totk.ini's bindings. failed = None - for style in ('xbox', 'xbox-label', 'pc'): + for style in ('xbox', 'xbox-label'): out = dest / f'romfs-patches-{style}' remove(out) code, log = run_tool(ctx, f'prepare-{style}', layout.tools / 'make_romfs_patches.py', @@ -1116,7 +1116,7 @@ class Prepare(Step): # the prompts and the screen's shape. Only the Common archive differs from romfs-patches-