mirror of
https://github.com/valentderah/totk-pc-recomp.git
synced 2026-11-21 04:55:56 +00:00
Hold the game's dynamic resolution at 100 % and let the scene grow past 4096 wide
The game picks a scene tier of 100, 90 or 80 % mostly from a fixed cost model made for the Switch that grows with the scene width squared, so on a wide output it drops to 80 % on any GPU: at 5120x1440 every frame drew 80 % of the scene. Patch set fixres replaces the one instruction that moves the tier's scale into the controller's result (1.2.1 main+0xcc2c00, 1.4.3 main+0x5848a8 as MacNativeGames patches it) with 1.0. The new setting dynamic_res (menu toggle, live) brings the game's stepping back and is on by default in the Steam Deck profile. The scene cap goes from 4096 to 8192 a side, so render_scale above 80 works on a 32:9 output, and the scene also stays within a DynamicTextureAllocatorMem under 2 GiB; the log says when it was made smaller. The memory selftest now maps past the real pool size instead of a fixed 4 GiB, which a larger scene grows past. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
71d8b0cc61
commit
a6c33b072c
11 files changed
+89
-15
No files matched your search
+4
-3
@@ -41,7 +41,7 @@ static const char *const known[] = {
|
||||
"BIND_ZL", "BIND_ZR", "BLOCK_VIEWS_3D", "CLOTH_REALTIME", "COLOR_BRIGHTNESS", "COLOR_CONTRAST", "COLOR_GAMMA",
|
||||
"COLOR_PRESET", "COLOR_SATURATION", "CONTACT_DEBUG", "CONTACT_SHADOWS", "CORE_DIAG", "CRIT", "CRIT_OUT",
|
||||
"DESC_TEMPLATE", "DEVICE_PROFILE", "DISCORD_APP_ID", "DISCORD_IMAGE", "DISCORD_RPC", "DLAA", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_PRESET", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR",
|
||||
"DUMP_LOG", "DYN_DELTA", "EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES",
|
||||
"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",
|
||||
@@ -71,7 +71,7 @@ static const struct { const char *key, *section; } sections[] = {
|
||||
{"REALTIME", "frame rate"}, {"CLOTH_REALTIME", "frame rate"}, {"HIGHFPS_FIX", "frame rate"},
|
||||
{"FULLSCREEN", "display"}, {"WINDOW_SIZE", "display"}, {"PERF_OVERLAY", "display"}, {"VK_PRESENT", "display"},
|
||||
{"GPU_INDEX", "display"}, {"OUTPUT_RES", "display"}, {"RENDER_SCALE", "display"}, {"UPSCALER", "display"},
|
||||
{"SHARPNESS", "display"}, {"ASPECT", "display"}, {"MOVIE_ASPECT", "display"}, {"FOV", "display"}, {"ANISO", "display"},
|
||||
{"SHARPNESS", "display"}, {"DYNAMIC_RES", "display"}, {"ASPECT", "display"}, {"MOVIE_ASPECT", "display"}, {"FOV", "display"}, {"ANISO", "display"},
|
||||
{"COLOR_PRESET", "display"},
|
||||
{"COLOR_BRIGHTNESS", "display"}, {"COLOR_CONTRAST", "display"}, {"COLOR_SATURATION", "display"},
|
||||
{"COLOR_GAMMA", "display"}, {"HDR", "display"}, {"HDR_PEAK_NITS", "display"}, {"HDR_GAME_NITS", "display"},
|
||||
@@ -119,6 +119,7 @@ static const CfgMeta metas[] = {
|
||||
{"VK_PRESENT", "mailbox", "mailbox|fifo|immediate", LIVE}, {"GPU_INDEX", "", NULL, RESTART},
|
||||
{"PERF_OVERLAY", "off", "off|fps|full", LIVE},
|
||||
{"OUTPUT_RES", "1920x1080", NULL, RESTART}, {"RENDER_SCALE", "game", "game|50|67|75|100|125|150|200", RESTART},
|
||||
{"DYNAMIC_RES", "0", "0|1", LIVE}, // resolution.c res_dynres_live
|
||||
{"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},
|
||||
@@ -285,7 +286,7 @@ int cfg_load(const char *path) {
|
||||
// Starting points to replace with measured ones (docs/tester-guide.md, Steam Deck).
|
||||
static const struct { const char *key, *value; } DECK[] = {
|
||||
{"FULLSCREEN", "1"}, {"WINDOW_SIZE", "1280x800"}, {"OUTPUT_RES", "1280x800"}, {"RENDER_SCALE", "game"},
|
||||
{"VK_PRESENT", "fifo"}, {"FPS_LIMIT", "40"},
|
||||
{"VK_PRESENT", "fifo"}, {"FPS_LIMIT", "40"}, {"DYNAMIC_RES", "1"},
|
||||
};
|
||||
static int profile = -1; // 0 none, 1 Steam Deck
|
||||
|
||||
|
||||
@@ -236,6 +236,7 @@ static void window_settings_live(void) {
|
||||
if (started && v == seen) return;
|
||||
seen = v;
|
||||
res_fov_live();
|
||||
res_dynres_live();
|
||||
const char *e = cfg_value("TOTK_VK_PRESENT");
|
||||
if (!started || strncmp(e, present, sizeof present - 1)) {
|
||||
snprintf(present, sizeof present, "%s", e);
|
||||
|
||||
@@ -282,6 +282,7 @@ int romfs_shaped_ready(unsigned w, unsigned h); // romfs-patches-<w>x
|
||||
// before fs_init)
|
||||
void res_wanted(unsigned out[2]); // the output size TOTK_OUTPUT_RES asks for
|
||||
void res_fov_live(void); // TOTK_FOV to the camera (set fov); on a settings change
|
||||
void res_dynres_live(void); // TOTK_DYNAMIC_RES to the game (set fixres); on a settings change
|
||||
// ---- code patches (patches.c) and the frame step (frame_rate.c)
|
||||
void rt_patches_init(void); // after ldr_load: switches from the environment, the patch
|
||||
// page committed; logs the sets
|
||||
|
||||
+49
-11
@@ -48,7 +48,8 @@
|
||||
#define SCENE_H 900
|
||||
#define DTA_KIB 113664u // DynamicTextureAllocatorMem, shipped
|
||||
#define TEX_HEAP_KIB 506880u // TextureHeap, shipped (1.2.1 and 1.4.3): what a mod's own HeapDef is measured against
|
||||
#define SCENE_MAX 4096 // per side, as MacNativeGames' TOTK_RENDER_RES
|
||||
#define SCENE_MAX 8192 // per side
|
||||
#define DTA_MAX_KIB 2031616u // DynamicTextureAllocatorMem grown at most to 1984 MiB, under 2 GiB (decide)
|
||||
#define SHADOW_BASE 960 // the sun shadow map's base size (its cascades: a D16 array of 4 layers)
|
||||
|
||||
static struct {
|
||||
@@ -91,12 +92,22 @@ static int dlss_dll(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
// The scene size for a share k of the output, within SCENE_MAX per side.
|
||||
static void scene_for(double k, unsigned *w, unsigned *h) {
|
||||
static uint64_t shadow_kib(void);
|
||||
|
||||
// The scene size for a share k of the output, within SCENE_MAX a side and within what a texture heap of DTA_MAX_KIB
|
||||
// holds next to the output and the shadow map (res_heap_extra_kib's growth). 1.2.1 already misplaced textures in a
|
||||
// pool past 2 GiB, where a signed 32-bit offset turns negative (recomp/patches-v121.txt, set pooloff); larger heaps
|
||||
// have not been run. Needs R.shadow. 1 when the scene was made smaller than k asks.
|
||||
static int scene_for(double k, unsigned *w, unsigned *h) {
|
||||
double sw = R.ow * k, sh = R.oh * k;
|
||||
double fit = fmin(1.0, fmin(SCENE_MAX / sw, SCENE_MAX / sh));
|
||||
double room = (double)(DTA_MAX_KIB - shadow_kib()) / DTA_KIB - 1.0 -
|
||||
fmax(0.0, (double)R.ow * R.oh / (BASE_W * BASE_H) - 1.0);
|
||||
double most = (1.0 + fmax(0.0, room)) * SCENE_W * SCENE_H; // scene pixels that fit
|
||||
if (sw * sh * fit * fit > most) fit = sqrt(most / (sw * sh));
|
||||
*w = (unsigned)(sw * fit + 0.5);
|
||||
*h = (unsigned)(sh * fit + 0.5);
|
||||
return fit < 1.0;
|
||||
}
|
||||
|
||||
// The scene's share of the output for a TOTK_DLSS mode; 0 for dlaa (the scene keeps base_k), while DLSS/DLAA is off
|
||||
@@ -168,6 +179,12 @@ static void decide(void) {
|
||||
rt_log("resolution: TOTK_RENDER_SCALE=%s is not game or a percentage 25..400; game", s);
|
||||
}
|
||||
}
|
||||
const char *sr = cfg_value("TOTK_SHADOW_RES");
|
||||
if (strcmp(sr, "game")) {
|
||||
unsigned n = (unsigned)atoi(sr);
|
||||
if (n >= 256 && n <= 4096 && !(n & 7)) R.shadow = n;
|
||||
else rt_log("resolution: TOTK_SHADOW_RES=%s is not game or a size 256..4096 (a multiple of 8); game", sr);
|
||||
}
|
||||
// A DLSS mode other than dlaa sets the scene size instead. On 1.4.3 with DLSS able to run (DLAA on, the DLL there)
|
||||
// the mode can change while the game runs (res_dlss_mode): the scene patch is then always on and the heap is sized
|
||||
// for the largest scene the modes ask for. Everyone else keeps the game's own scene size and its dynamic resolution
|
||||
@@ -178,16 +195,14 @@ static void decide(void) {
|
||||
R.dlss_k = dlss_share(m);
|
||||
if (R.dlss_k) rt_log("resolution: DLSS %s: the scene at %.0f %% of the output (render_scale ignored)", m, R.dlss_k * 100);
|
||||
double sk = R.dlss_k ? R.dlss_k : k;
|
||||
if (R.live || R.dlss_k || R.ow * sk > SCENE_MAX || R.oh * sk > SCENE_MAX) R.scene_set = 1;
|
||||
scene_for(sk, &R.sw, &R.sh);
|
||||
if (R.live || R.dlss_k) R.scene_set = 1;
|
||||
if (scene_for(sk, &R.sw, &R.sh)) {
|
||||
R.scene_set = 1;
|
||||
rt_log("resolution: a %.0fx%.0f scene is larger than the port allows (8192 a side, a texture heap under 2 GiB); "
|
||||
"%ux%u", R.ow * sk, R.oh * sk, R.sw, R.sh);
|
||||
}
|
||||
if (R.live) scene_for(fmax(k, 2.0 / 3.0), &R.hw, &R.hh);
|
||||
else R.hw = R.sw, R.hh = R.sh;
|
||||
const char *sr = cfg_value("TOTK_SHADOW_RES");
|
||||
if (strcmp(sr, "game")) {
|
||||
unsigned n = (unsigned)atoi(sr);
|
||||
if (n >= 256 && n <= 4096 && !(n & 7)) R.shadow = n;
|
||||
else rt_log("resolution: TOTK_SHADOW_RES=%s is not game or a size 256..4096 (a multiple of 8); game", sr);
|
||||
}
|
||||
}
|
||||
|
||||
// Texture heap for a sun shadow map above the base size: the four layers of 2 bytes, three maps in flight (the engine
|
||||
@@ -562,6 +577,29 @@ void res_fov_live(void) {
|
||||
rt_log("resolution: field of view %d%% of the game's", pct);
|
||||
}
|
||||
|
||||
// TOTK_DYNAMIC_RES = 0 (default) holds the game's dynamic resolution at 100 % (recomp/patches-v121.txt and
|
||||
// patches-v143.txt, set fixres), so the scene renders at the size render_scale chose. The game picks its tier (100, 90
|
||||
// or 80 %) mostly from a fixed cost model made for the Switch: one term grows with the object counts, one with
|
||||
// (scene width / 1600) squared. The GPU time it also measures (two NVN report timestamps, a frame apart) only lowers
|
||||
// that prediction when the GPU is slower than the model says, which a PC GPU never is, so the model alone decides.
|
||||
// Measured on 1.2.1: a 2867-wide scene stays at 100 %, one wider than about 2970 does not, and a 4267-wide one
|
||||
// (5120x1440 at render_scale 83) fits no tier and falls back to 80 % every frame, whatever the GPU's load. 1 lets the
|
||||
// game step again (the Steam Deck profile's default, cfg.c DECK, where the scene is far narrower). Runs on a settings
|
||||
// change (gfx_present.c window_settings_live), like res_fov_live.
|
||||
void res_dynres_live(void) {
|
||||
static int set = -2, shown = -1;
|
||||
if (set == -2) set = rt_patch_set("fixres");
|
||||
int dyn = cfg_bool("TOTK_DYNAMIC_RES");
|
||||
if (dyn == shown) return;
|
||||
shown = dyn;
|
||||
if (set < 0) {
|
||||
if (!dyn) rt_log("resolution: this game version has no fixed-resolution patch; the game keeps its dynamic resolution");
|
||||
return;
|
||||
}
|
||||
rt_patch_switch(set, !dyn);
|
||||
rt_log("resolution: dynamic resolution %s", dyn ? "the game's own (100, 90 or 80 %)" : "off: the scene stays at 100 %");
|
||||
}
|
||||
|
||||
void res_wanted(unsigned out[2]) {
|
||||
decide();
|
||||
out[0] = R.ow, out[1] = R.oh;
|
||||
|
||||
@@ -663,6 +663,7 @@ static void tab_screen(float scale) {
|
||||
opt_group(UI_MENU_GRAPHICS);
|
||||
row_output_res();
|
||||
row_render_scale();
|
||||
opt_toggle("TOTK_DYNAMIC_RES", UI_MENU_DYNAMIC_RES, UI_MENU_DYNAMIC_RES_DESC);
|
||||
row_shadow_res();
|
||||
static const UiTextId up[] = {UI_MENU_UPSCALER_FSR, UI_MENU_UPSCALER_BILINEAR};
|
||||
opt_choice("TOTK_UPSCALER", UI_MENU_UPSCALER, up, 2, UI_MENU_UPSCALER_DESC);
|
||||
|
||||
@@ -71,6 +71,8 @@ static const char *const text_en[UI_TEXT_COUNT] = {
|
||||
[UI_MENU_RENDER_SCALE_DESC] = "Size of the 3D scene relative to the game resolution; the game's FSR scales it to "
|
||||
"that size. Above 100 % smooths jagged edges (supersampling) at a high GPU cost.",
|
||||
[UI_MENU_RENDER_SCALE_GAME] = "Game (83 %)",
|
||||
[UI_MENU_DYNAMIC_RES] = "Dynamic resolution",
|
||||
[UI_MENU_DYNAMIC_RES_DESC] = "Lets the game lower the 3D scene to 90 or 80 %. It judges by an estimate made for the Switch that ignores your GPU, so wide scenes drop even on a fast PC. Off keeps the render scale.",
|
||||
[UI_MENU_UPSCALER] = "Scaling to the window",
|
||||
[UI_MENU_UPSCALER_DESC] = "How the picture is scaled when the window is larger than the game resolution. FSR keeps "
|
||||
"edges and detail sharper than bilinear.",
|
||||
@@ -545,6 +547,8 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
|
||||
[UI_MENU_RENDER_SCALE_DESC] = "Размер 3D-сцены относительно разрешения игры; FSR игры доводит её до этого размера. "
|
||||
"Выше 100 % сглаживает лесенки на краях (суперсэмплинг) ценой большой нагрузки на GPU.",
|
||||
[UI_MENU_RENDER_SCALE_GAME] = "Как в игре (83 %)",
|
||||
[UI_MENU_DYNAMIC_RES] = "Динамическое разрешение",
|
||||
[UI_MENU_DYNAMIC_RES_DESC] = "Игра снижает 3D-сцену до 90 или 80 %. Она судит по оценке для Switch, не учитывающей вашу видеокарту, поэтому широкие сцены снижаются даже на быстром ПК. Выключено: остаётся масштаб отрисовки.",
|
||||
[UI_MENU_UPSCALER] = "Масштабирование под окно",
|
||||
[UI_MENU_UPSCALER_DESC] = "Как картинка растягивается, когда окно больше разрешения игры. FSR сохраняет края и "
|
||||
"детали чётче билинейного.",
|
||||
@@ -1058,6 +1062,8 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = {
|
||||
"tamanho. Acima de 100 % suaviza bordas serrilhadas (supersampling) com alto custo de "
|
||||
"GPU.",
|
||||
[UI_MENU_RENDER_SCALE_GAME] = "Jogo (83 %)",
|
||||
[UI_MENU_DYNAMIC_RES] = "Resolução dinâmica",
|
||||
[UI_MENU_DYNAMIC_RES_DESC] = "Deixa o jogo reduzir a cena 3D para 90 ou 80 %. Ele decide por uma estimativa feita para o Switch que ignora sua GPU, então cenas largas caem mesmo num PC rápido. Desligada, mantém a escala da renderização.",
|
||||
[UI_MENU_UPSCALER] = "Escala para a janela",
|
||||
[UI_MENU_UPSCALER_DESC] = "Como a imagem é ampliada quando a janela é maior que a resolução do jogo. O FSR mantém "
|
||||
"bordas e detalhes mais nítidos que o bilinear.",
|
||||
@@ -1580,6 +1586,8 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = {
|
||||
"游戏的 FSR 会将其缩放到该尺寸。"
|
||||
"高于 100% 会平滑锯齿边缘(超采样),但 GPU 开销很高。",
|
||||
[UI_MENU_RENDER_SCALE_GAME] = "游戏(83%)",
|
||||
[UI_MENU_DYNAMIC_RES] = "动态分辨率",
|
||||
[UI_MENU_DYNAMIC_RES_DESC] = "让游戏把 3D 场景降到 90 % 或 80 %。它依据为 Switch 制定的估算,不考虑你的显卡,因此即使在高性能 PC 上宽场景也会降低。关闭时保持渲染比例。",
|
||||
[UI_MENU_UPSCALER] = "放大到窗口",
|
||||
[UI_MENU_UPSCALER_DESC] = "窗口大于游戏分辨率时画面的放大方式。"
|
||||
"FSR 比双线性更能保留边缘和细节。",
|
||||
|
||||
@@ -35,6 +35,7 @@ typedef enum {
|
||||
UI_MENU_GRAPHICS, // group heading over the resolution rows
|
||||
UI_MENU_OUTPUT_RES, UI_MENU_OUTPUT_RES_DESC,
|
||||
UI_MENU_RENDER_SCALE, UI_MENU_RENDER_SCALE_DESC, UI_MENU_RENDER_SCALE_GAME,
|
||||
UI_MENU_DYNAMIC_RES, UI_MENU_DYNAMIC_RES_DESC,
|
||||
UI_MENU_UPSCALER, UI_MENU_UPSCALER_DESC, UI_MENU_UPSCALER_FSR, UI_MENU_UPSCALER_BILINEAR,
|
||||
UI_MENU_ASPECT, UI_MENU_ASPECT_DESC, UI_MENU_ASPECT_FIT, UI_MENU_ASPECT_STRETCH,
|
||||
UI_MENU_MOVIE_ASPECT, UI_MENU_MOVIE_ASPECT_DESC, UI_MENU_MOVIE_ASPECT_KEEP, UI_MENU_MOVIE_ASPECT_STRETCH,
|
||||
|
||||
Reference in new issue
Block a user