Merge pull request #1087 into task/pr1087

This commit is contained in:
Valiantsin Dzerakh committed 2026-11-11 13:20:43 +03:00
commit 873fc64b41
11 files changed
+113 -8

No files matched your search

+3 -3
View File
@@ -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", "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",
@@ -80,7 +80,7 @@ static const struct { const char *key, *section; } sections[] = {
{"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"},
{"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},
+2
View File
@@ -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
+3 -2
View File
@@ -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");
}
+51 -2
View File
@@ -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());
+1 -1
View File
@@ -888,7 +888,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;
+8
View File
@@ -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);
+14
View File
@@ -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 "
@@ -634,6 +638,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 "): ровнее "
"края и меньше мерцания. Интерфейс не затрагивается. Режим ниже задаёт разрешение, с которым он "
@@ -1476,6 +1484,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 "
@@ -2105,6 +2117,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] = "柔和阴影",
+1
View File
@@ -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,