DLSS upscaling: quality, balanced and performance modes

TOTK_DLSS (dlaa|quality|balanced|performance, read at start) sets the scene to
67, 58 or 50 % of the output. DLSS then runs at the begin of the game's scaling
pass (the FXAA shader drawing the light target into the output-sized target,
before the HUD) and its result replaces that draw; the HUD is drawn afterwards
and never jittered or passed through DLSS. The jitter now ends where the scene
ends (the bloom), separately from where DLSS runs. Scaled modes add a mip bias
of log2(scale) to repeating, mipmapped material samplers.

With a scene smaller than the output, fxaa = 0 no longer skips the game's
scaling draw (it left the 3D picture out).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
DizzyMan1337andClaude Opus 5.5 committed 2026-10-31 15:33:03 +08:00
1 parent 6d181cf327
commit 2e8b4ff1b1
11 files changed
+141 -56

No files matched your search

+3 -3
View File
@@ -36,7 +36,7 @@ static const char *const known[] = {
"BIND_PLUS", "BIND_R", "BIND_RCLICK", "BIND_RIGHT", "BIND_RSTICK_DOWN", "BIND_RSTICK_LEFT", "BIND_RSTICK_RIGHT", "BIND_RSTICK_UP",
"BIND_SKIP", "BIND_STATS", "BIND_UP", "BIND_X", "BIND_Y",
"BIND_ZL", "BIND_ZR", "BLOCK_VIEWS_3D", "CLOTH_REALTIME", "CORE_DIAG", "CRIT", "CRIT_OUT", "DESC_TEMPLATE", "DLAA",
"DLAA_JITTER", "DLAA_MV", "DUMP", "DUMP_BUF", "DUMP_DIR", "DUMP_LOG",
"DLAA_JITTER", "DLAA_MV", "DLSS", "DUMP", "DUMP_BUF", "DUMP_DIR", "DUMP_LOG",
"EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES", "FLIGHT_SPIKE_MS",
"FLIGHT_THUMBS", "FPS60", "FPS_LIMIT", "FREEZE_IDLE", "FREE_CORES", "FULLSCREEN", "FXAA", "GPL", "GPL_DRAW_BUILD", "GPU",
"GPU_INDEX", "GPU_NAME", "HIGHFPS_FIX", "INPUT", "INPUT_RECORD", "INPUT_SCRIPT", "LANG", "LIB_PREBUILD",
@@ -60,7 +60,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"}, {"DLAA", "display"}, {"FXAA", "display"},
{"SHARPNESS", "display"}, {"ASPECT", "display"}, {"DLAA", "display"}, {"DLSS", "display"}, {"FXAA", "display"},
{"MENU_LANG", "language"}, {"LANG", "language"}, {"OPERATION_MODE", "language"},
{"VOLUME", "audio"},
{"MOTION", "input"}, {"RUMBLE_STRENGTH", "input"}, {"RUMBLE_CURVE", "input"}, {"RUMBLE_TRIGGERS", "input"},
@@ -95,7 +95,7 @@ static const CfgMeta metas[] = {
{"PERF_OVERLAY", "off", "off|fps|full", LIVE},
{"OUTPUT_RES", "1920x1080", NULL, RESTART}, {"RENDER_SCALE", "game", "game|50|67|75|100|125|150|200", RESTART},
{"UPSCALER", "fsr", "fsr|bilinear", LIVE}, {"SHARPNESS", "80", "0..100", LIVE},
{"DLAA", "0", "0|1", LIVE}, {"FXAA", "1", "0|1", LIVE},
{"DLAA", "0", "0|1", LIVE}, {"DLSS", "dlaa", "dlaa|quality|balanced|performance", RESTART}, {"FXAA", "1", "0|1", LIVE},
{"ASPECT", "fit", "fit|stretch", LIVE},
// Game
{"FPS_LIMIT", "60", "30|60|90|120|144|display", LIVE}, {"FPS60", "1", "0|1", LIVE},
+1
View File
@@ -240,6 +240,7 @@ int res_heapdef_build(const void *in, size_t n, void **out, size_t *out_n); //
// the grown heaps, malloc'd; 0 = cannot (logged)
void res_heapdef_served(void); // romfs.c serves the grown table
void res_init(void); // after rt_patches_init: the patch page and the sets
float res_dlss_lod_bias(void); // TOTK_DLSS upscaling: texture LOD bias (<= 0)
void res_sizes(unsigned out[2], unsigned scene[2]); // the output and scene sizes in effect (the game's own
// until res_init switched the sets on)
int res_is_16x9(unsigned w, unsigned h); // within 1% of 16:9 (the test res_init and romfs.c share)
+18 -1
View File
@@ -49,6 +49,7 @@ static struct {
int scene_set; // the scene differs from the game's 5/6 of the output
int heapdef_ok; // romfs.c serves the grown HeapDef
int on; // res_init switched the patch sets on
double dlss_k; // TOTK_DLSS quality/balanced/performance: the scene's share of the output, else 0
} R;
static void decide(void) {
@@ -67,7 +68,16 @@ static void decide(void) {
}
const char *s = cfg_value("TOTK_RENDER_SCALE");
double k = 5.0 / 6.0;
if (strcmp(s, "game")) {
const char *m = cfg_value("TOTK_DLSS"); // a DLSS mode other than dlaa sets the scene size
static const struct { const char *name; double k; } dlss[] = {
{"quality", 2.0 / 3.0}, {"balanced", 0.58}, {"performance", 0.5}};
for (int i = 0; i < 3; i++)
if (!strcmp(m, dlss[i].name)) R.dlss_k = dlss[i].k;
if (R.dlss_k) {
k = R.dlss_k;
R.scene_set = 1;
rt_log("resolution: DLSS %s: the scene at %.0f %% of the output (render_scale ignored)", m, k * 100);
} else if (strcmp(s, "game")) {
char *end;
double pct = strtod(s, &end);
if (end != s && !*end && pct >= 25 && pct <= 400) {
@@ -241,6 +251,13 @@ void res_init(void) {
scene_on ? "" : " (the game's own 5/6 of the output)", (unsigned long long)res_heap_extra_kib());
}
// DLSS upscaling: textures are sampled for the output's resolution, not the scene's (NVIDIA's DLSS guide: a mip bias
// of log2(render / output)), so their detail survives the scaling. 0 without a DLSS mode.
float res_dlss_lod_bias(void) {
decide();
return R.dlss_k ? (float)log2(R.dlss_k) : 0.0f;
}
// 16:9 within 1% (1366x768 counts): the shape the game's own layouts and camera are made for.
int res_is_16x9(unsigned w, unsigned h) {
double rel = ((double)w / h) / ((double)BASE_W / BASE_H);
+3
View File
@@ -542,6 +542,9 @@ static void tab_screen(float scale) {
static const UiTextId aspect[] = {UI_MENU_ASPECT_FIT, UI_MENU_ASPECT_STRETCH};
opt_choice("TOTK_ASPECT", UI_MENU_ASPECT, aspect, 2, UI_MENU_ASPECT_DESC);
opt_toggle("TOTK_DLAA", UI_MENU_DLAA, UI_MENU_DLAA_DESC);
static const UiTextId dlss[] = {UI_MENU_DLSS_DLAA, UI_MENU_DLSS_QUALITY, UI_MENU_DLSS_BALANCED,
UI_MENU_DLSS_PERFORMANCE};
opt_choice("TOTK_DLSS", UI_MENU_DLSS, dlss, 4, UI_MENU_DLSS_DESC);
opt_toggle("TOTK_FXAA", UI_MENU_FXAA, UI_MENU_FXAA_DESC);
opt_end();
}
+18 -6
View File
@@ -68,9 +68,15 @@ static const char *const text_en[UI_TEXT_COUNT] = {
[UI_MENU_ASPECT_FIT] = "Black bars", [UI_MENU_ASPECT_STRETCH] = "Stretch",
[UI_MENU_SHARPNESS] = "FSR sharpness",
[UI_MENU_SHARPNESS_DESC] = "Sharpening after FSR scaling; 0 turns it off.",
[UI_MENU_DLAA] = "NVIDIA DLAA",
[UI_MENU_DLAA_DESC] = "DLSS anti-aliasing of the 3D scene at its own resolution (NVIDIA RTX GPUs; nvngx_dlss.dll next to "
"totk.exe). Smoother edges and less shimmer for about 3 ms a frame.",
[UI_MENU_DLAA] = "NVIDIA DLSS / DLAA",
[UI_MENU_DLAA_DESC] = "NVIDIA DLSS for the 3D scene (NVIDIA RTX GPUs; nvngx_dlss.dll next to totk.exe): smoother edges "
"and less shimmer. The HUD is not touched. The mode below sets the resolution it works from.",
[UI_MENU_DLSS] = "DLSS mode",
[UI_MENU_DLSS_DESC] = "DLAA draws the 3D scene at full resolution. Quality, Balanced and Performance draw it at 67, 58 "
"and 50 % and let DLSS scale it up, for more frames per second; they replace the 3D render "
"scale. Takes effect after a restart.",
[UI_MENU_DLSS_DLAA] = "DLAA (native)", [UI_MENU_DLSS_QUALITY] = "Quality", [UI_MENU_DLSS_BALANCED] = "Balanced",
[UI_MENU_DLSS_PERFORMANCE] = "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.",
@@ -308,9 +314,15 @@ static const char *const text_ru[UI_TEXT_COUNT] = {
[UI_MENU_ASPECT_FIT] = "Чёрные полосы", [UI_MENU_ASPECT_STRETCH] = "Растянуть",
[UI_MENU_SHARPNESS] = "Резкость FSR",
[UI_MENU_SHARPNESS_DESC] = "Повышение резкости после масштабирования FSR; 0 выключает его.",
[UI_MENU_DLAA] = "NVIDIA DLAA",
[UI_MENU_DLAA_DESC] = "Сглаживание 3D-сцены через DLSS в её собственном разрешении (видеокарты NVIDIA RTX; nvngx_dlss.dll "
"рядом с totk.exe). Ровнее края и меньше мерцания, около 3 мс на кадр.",
[UI_MENU_DLAA] = "NVIDIA DLSS / DLAA",
[UI_MENU_DLAA_DESC] = "NVIDIA DLSS для 3D-сцены (видеокарты NVIDIA RTX; nvngx_dlss.dll рядом с totk.exe): ровнее края и "
"меньше мерцания. Интерфейс не затрагивается. Режим ниже задаёт разрешение, с которым он работает.",
[UI_MENU_DLSS] = "Режим DLSS",
[UI_MENU_DLSS_DESC] = "DLAA рисует 3D-сцену в полном разрешении. «Качество», «Баланс» и «Производительность» рисуют её "
"в 67, 58 и 50 % и масштабируют через DLSS ради большего числа кадров; они заменяют масштаб "
"3D-отрисовки. Действует после перезапуска.",
[UI_MENU_DLSS_DLAA] = "DLAA (родное)", [UI_MENU_DLSS_QUALITY] = "Качество", [UI_MENU_DLSS_BALANCED] = "Баланс",
[UI_MENU_DLSS_PERFORMANCE] = "Производительность",
[UI_MENU_FXAA] = "Сглаживание игры (FXAA)",
[UI_MENU_FXAA_DESC] = "Собственное сглаживание FXAA. Слегка размывает мелкие детали; с DLAA оно не нужно.",
+2 -1
View File
@@ -37,7 +37,8 @@ typedef enum {
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_SHARPNESS, UI_MENU_SHARPNESS_DESC,
UI_MENU_DLAA, UI_MENU_DLAA_DESC, UI_MENU_FXAA, UI_MENU_FXAA_DESC,
UI_MENU_DLAA, UI_MENU_DLAA_DESC, UI_MENU_DLSS, UI_MENU_DLSS_DESC, UI_MENU_DLSS_DLAA, UI_MENU_DLSS_QUALITY,
UI_MENU_DLSS_BALANCED, UI_MENU_DLSS_PERFORMANCE, UI_MENU_FXAA, UI_MENU_FXAA_DESC,
// Game
UI_MENU_FPS_LIMIT, UI_MENU_FPS_LIMIT_DESC, UI_MENU_FPS_30, UI_MENU_FPS_60, UI_MENU_FPS_90, UI_MENU_FPS_120,
+77 -37
View File
@@ -28,7 +28,7 @@ typedef int NgxResult; // NVSDK_NGX_Result: 1 success, 0xBAD00000 | n failures
#define NGX_OK(r) (((unsigned)(r) & 0xFFF00000u) != 0xBAD00000u)
#define NGX_VERSION_API 0x15
#define NGX_FEATURE_SUPERSAMPLING 1
#define NGX_PERFQ_DLAA 5
#define NGX_PERFQ_DLAA 5 // NVSDK_NGX_PerfQuality_Value: 0 performance, 1 balanced, 2 quality, 3 ultra performance
typedef struct NgxParam NgxParam;
typedef struct NgxHandle NgxHandle;
typedef struct { void *slot[17]; } NgxParamVtbl;
@@ -203,13 +203,21 @@ void vk_dlaa_init(void) {
// quarter of the scene starts the bloom chain, which reads it. After the bloom come the tonemap and post passes, then
// the HUD is drawn into the same target and a last pass copies it to the 8-bit output.
// So: after the G-buffer, a pass at the scene size with exactly one colour target (R11G11B10F or RGBA16F) and the D32F
// depth arms the frame with that pair; the next pass at most a quarter as wide runs DLAA on the armed target first.
// Bloom, tonemap, post and HUD then all work on the anti-aliased picture.
// depth arms the frame with that pair; the next pass at most a quarter as wide ends the scene (no jitter after it) and,
// when the scene is as wide as the output, runs DLAA on the armed target first. Bloom, tonemap, post and HUD then all
// work on the anti-aliased picture.
// Upscaling (a scene smaller than the output: TOTK_DLSS quality/balanced/performance, or the game's own 5/6): measured
// at a 960x536 scene, 1920x1080 output, the bloom and its composite write back into the light target at the scene size,
// then one full-screen draw (the FXAA shader below, which also scales) reads it into an output-sized R11G11B10F target
// with no depth, and the HUD is drawn over that target at the output size. DLSS runs at the begin of that pass: it
// reads the light target and its result is blitted into the pass's target, whose scaling draw is then skipped. The
// HUD, drawn afterwards into the same target, is never jittered nor passed through DLSS.
static struct {
VkExecTarget color, depth; // the armed pair, valid in the frame it was armed
int armed, done, gbuf; // this frame: armed on the light target, DLAA ran, the G-buffer was drawn
int ended, up; // this frame: the scene is drawn (jitter over), DLSS wrote the scaled output
struct Size { // a DLSS feature and its work images per scene size (dynamic resolution flips it)
uint32_t w, h;
uint32_t w, h, ow, oh; // render size, output size
VkImage out, mv;
VmaAllocation out_mem, mv_mem;
VkImageView out_view, mv_view;
@@ -275,13 +283,14 @@ static void free_size(struct Size *e) {
memset(e, 0, sizeof *e);
}
// The entry for a scene size: its output (RGBA16F, written by DLSS, then blitted back into the scene target) and
// motion vectors (RG16F, render pixels), both kept in GENERAL like every image of the back end. TotK's dynamic
// resolution switches between a few sizes; each keeps its feature, the least recently used goes for a new one.
static struct Size *size_for(VkCommandBuffer cb, uint32_t w, uint32_t h) {
// The entry for a scene and output size: its output (RGBA16F at the output size, written by DLSS, then blitted into
// the target) and motion vectors (RG16F at the scene size, render pixels), both kept in GENERAL like every image of the
// back end. TotK's dynamic resolution switches between a few sizes; each keeps its feature, the least recently used
// goes for a new one.
static struct Size *size_for(VkCommandBuffer cb, uint32_t w, uint32_t h, uint32_t ow, uint32_t oh) {
struct Size *e = NULL, *lru = &D.sizes[0];
for (int i = 0; i < 3; i++) {
if (D.sizes[i].w == w && D.sizes[i].h == h) return &D.sizes[i];
if (D.sizes[i].w == w && D.sizes[i].h == h && D.sizes[i].ow == ow && D.sizes[i].oh == oh) return &D.sizes[i];
if (!D.sizes[i].out && !e) e = &D.sizes[i];
if (D.sizes[i].used < lru->used) lru = &D.sizes[i];
}
@@ -291,7 +300,7 @@ static struct Size *size_for(VkCommandBuffer cb, uint32_t w, uint32_t h) {
}
VkImageUsageFlags u = VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT |
VK_IMAGE_USAGE_TRANSFER_DST_BIT;
if (!image2d(w, h, VK_FORMAT_R16G16B16A16_SFLOAT, u, &e->out, &e->out_mem, &e->out_view) ||
if (!image2d(ow, oh, VK_FORMAT_R16G16B16A16_SFLOAT, u, &e->out, &e->out_mem, &e->out_view) ||
!image2d(w, h, VK_FORMAT_R16G16_SFLOAT, u, &e->mv, &e->mv_mem, &e->mv_view))
return NULL;
VkImageMemoryBarrier2 ib[2];
@@ -308,7 +317,7 @@ static struct Size *size_for(VkCommandBuffer cb, uint32_t w, uint32_t h) {
VkDependencyInfo di = {.sType = VK_STRUCTURE_TYPE_DEPENDENCY_INFO, .imageMemoryBarrierCount = 2,
.pImageMemoryBarriers = ib};
vkCmdPipelineBarrier2(cb, &di);
e->w = w, e->h = h;
e->w = w, e->h = h, e->ow = ow, e->oh = oh;
return e;
}
@@ -435,13 +444,13 @@ static float halton(uint32_t i, uint32_t b) {
}
void vk_dlaa_viewport(VkExec *ex, VkViewport *v) {
if (!D.jit_ok || D.done || !ex->depth.image || ex->depth.image != D.jdepth) return;
if (!D.jit_ok || D.ended || !ex->depth.image || ex->depth.image != D.jdepth) return;
v->x += D.jx, v->y += D.jy;
D.ux = D.jx, D.uy = D.jy, D.jit_used = 1;
}
void vk_dlaa_draw(VkExec *ex) {
if (!dl_active() || D.done) return;
if (!dl_active() || D.ended) return;
const p_bind_buf *b = &ex->ubo[0][1]; // constant bank c4: the replay keeps user banks from c3 on
const VkExecTarget *z = &ex->depth;
if (b->size == 0x940 && b->addr && z->image && z->width >= 640 && z->format == VK_FORMAT_D32_SFLOAT &&
@@ -460,12 +469,21 @@ static void next_jitter(void) {
D.jit_ok = !D.hold && !nj;
}
static void evaluate(VkExec *ex) {
// The quality setting DLSS is created with, from the scene's share of the output width.
static int perf_quality(uint32_t w, uint32_t ow) {
if (w >= ow) return NGX_PERFQ_DLAA;
double k = (double)w / ow;
return k >= 0.66 ? 2 : k >= 0.57 ? 1 : k >= 0.49 ? 0 : 3;
}
// dst: the target DLSS's picture goes to, NULL for the light target itself (DLAA in place).
static void evaluate(VkExec *ex, const VkExecTarget *dst) {
const VkExecTarget *t = &D.color, *z = &D.depth;
uint32_t w = t->width, h = t->height;
if (!dst) dst = t;
uint32_t w = t->width, h = t->height, ow = dst->width, oh = dst->height;
VkCommandBuffer cb = ex->cb;
vk_exec_barrier(ex); // what drew the scene is done (no pass is open here)
struct Size *e = size_for(cb, w, h);
struct Size *e = size_for(cb, w, h, ow, oh);
if (!e) return dl_fail("work image creation", 0);
if (e != D.last) D.reset = 1, D.why[0]++; // another size's history is from another moment
if (!D.params && !NGX_OK(N.alloc_params(&D.params))) return dl_fail("parameter allocation", 0);
@@ -488,23 +506,23 @@ static void evaluate(VkExec *ex) {
p_setu(p, "VisibilityNodeMask", 1);
p_setu(p, "Width", w);
p_setu(p, "Height", h);
p_setu(p, "OutWidth", w);
p_setu(p, "OutHeight", h);
p_seti(p, "PerfQualityValue", NGX_PERFQ_DLAA);
p_setu(p, "OutWidth", ow);
p_setu(p, "OutHeight", oh);
p_seti(p, "PerfQualityValue", perf_quality(w, ow));
// IsHDR | MVLowRes | AutoExposure: linear scene light, motion vectors at the render size, no exposure texture
p_seti(p, "DLSS.Feature.Create.Flags", (1 << 0) | (1 << 1) | (1 << 6));
p_seti(p, "DLSS.Enable.Output.Subrects", 0);
NgxResult r = N.create(cb, NGX_FEATURE_SUPERSAMPLING, p, &e->feat);
if (!NGX_OK(r) || !e->feat) return dl_fail("DLSS feature creation", r);
D.reset = 1;
rt_log("dlaa: DLSS feature created at %ux%u (scene format %d, depth format %d)", w, h, (int)t->format,
(int)z->format);
rt_log("dlaa: DLSS feature created at %ux%u -> %ux%u, quality value %d (scene format %d, depth format %d)", w,
h, ow, oh, perf_quality(w, ow), (int)t->format, (int)z->format);
}
if (D.last_color != t->image) D.reset = 1, D.why[2]++, D.last_color = t->image;
VkImageView cv = vk_exec_target_view(t->img, t->format, VK_IMAGE_VIEW_TYPE_2D, VK_IMAGE_ASPECT_COLOR_BIT, t->level,
t->base_layer, 1, 0);
NgxResourceVK rc = res_image(cv, t->image, t->format, w, h, VK_IMAGE_ASPECT_COLOR_BIT, 0);
NgxResourceVK ro = res_image(e->out_view, e->out, VK_FORMAT_R16G16B16A16_SFLOAT, w, h, VK_IMAGE_ASPECT_COLOR_BIT, 1);
NgxResourceVK ro = res_image(e->out_view, e->out, VK_FORMAT_R16G16B16A16_SFLOAT, ow, oh, VK_IMAGE_ASPECT_COLOR_BIT, 1);
NgxResourceVK rz = res_image(zv, z->image, z->format, w, h, VK_IMAGE_ASPECT_DEPTH_BIT, 0);
NgxResourceVK rm = res_image(e->mv_view, e->mv, VK_FORMAT_R16G16_SFLOAT, w, h, VK_IMAGE_ASPECT_COLOR_BIT, 0);
p_setp(p, "Color", &rc);
@@ -527,21 +545,22 @@ static void evaluate(VkExec *ex) {
D.reset = 0;
D.last = e, e->used = D.evals + 1;
full_barrier(cb);
// the result back into the scene target, which the bloom, the post passes and the HUD read and draw over
// the result into the scene target (DLAA: the bloom, the post passes and the HUD read it and draw over it) or into
// the scaling pass's target (the HUD draws over it)
VkImageBlit b = {.srcSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, 0, 0, 1},
.srcOffsets = {{0, 0, 0}, {(int32_t)w, (int32_t)h, 1}},
.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, t->level, t->base_layer, 1},
.dstOffsets = {{0, 0, 0}, {(int32_t)w, (int32_t)h, 1}}};
vkCmdBlitImage(cb, e->out, VK_IMAGE_LAYOUT_GENERAL, t->image, VK_IMAGE_LAYOUT_GENERAL, 1, &b, VK_FILTER_NEAREST);
.srcOffsets = {{0, 0, 0}, {(int32_t)ow, (int32_t)oh, 1}},
.dstSubresource = {VK_IMAGE_ASPECT_COLOR_BIT, dst->level, dst->base_layer, 1},
.dstOffsets = {{0, 0, 0}, {(int32_t)ow, (int32_t)oh, 1}}};
vkCmdBlitImage(cb, e->out, VK_IMAGE_LAYOUT_GENERAL, dst->image, VK_IMAGE_LAYOUT_GENERAL, 1, &b, VK_FILTER_NEAREST);
full_barrier(cb);
ex->recorded += 4;
vk_exec_draw_new_cb(); // NGX bound pipelines and descriptor sets of its own: the next draw binds everything again
D.jdepth = z->image;
next_jitter();
if (++D.evals == 1 || D.evals % 3600 == 0)
rt_log("dlaa: %llu frames anti-aliased (scene %ux%u; %llu frames without the DLAA point, %llu with camera "
rt_log("dlaa: %llu frames anti-aliased (scene %ux%u, output %ux%u; %llu frames without the DLAA point, %llu with camera "
"motion, %llu without a camera, %llu jitter holds; resets: %llu size, %llu camera, %llu target)",
(unsigned long long)D.evals, w, h, (unsigned long long)D.frames_missed,
(unsigned long long)D.evals, w, h, ow, oh, (unsigned long long)D.frames_missed,
(unsigned long long)D.mv_frames, (unsigned long long)D.mv_none, (unsigned long long)D.holds,
(unsigned long long)D.why[0], (unsigned long long)D.why[1], (unsigned long long)D.why[2]);
}
@@ -568,9 +587,20 @@ void vk_dlaa_pass(VkExec *ex) {
return;
}
if (!D.armed) return;
if (!ex->pass_w || ex->pass_w * 4 > D.color.width) return;
D.done = 1;
evaluate(ex);
if (!D.ended) {
if (!ex->pass_w || ex->pass_w * 4 > D.color.width) return;
D.ended = 1;
unsigned o[2], s[2];
res_sizes(o, s);
if (D.color.width >= o[0]) D.done = 1, evaluate(ex, NULL); // DLAA in place; else wait for the scaling pass
return;
}
// the game's scaling pass: one colour target wider than the scene, no depth
if (ex->pass_ncolor == 1 && c->image && !z->image && scene_color(c->format) && c->width > D.color.width &&
c->samples <= 1 && !c->is3d) {
D.done = D.up = 1;
evaluate(ex, c);
}
}
void vk_dlaa_frame(void) {
@@ -579,7 +609,8 @@ void vk_dlaa_frame(void) {
rt_log("dlaa: %s", on ? "on" : "off");
D.on = on;
// either way the next DLAA frame starts a new history from an unjittered frame
D.reset = 1, D.cam_prev_ok = 0, D.jit_ok = D.jit_used = D.armed = D.done = D.gbuf = 0, D.hold = 0;
D.reset = 1, D.cam_prev_ok = 0, D.jit_ok = D.jit_used = D.armed = D.done = D.gbuf = D.ended = D.up = 0;
D.hold = 0;
return;
}
if (!dl_active()) return;
@@ -587,7 +618,7 @@ void vk_dlaa_frame(void) {
if (D.jit_used && !D.done) D.hold = 60, D.holds++; // jittered but not resolved: that frame shook
else if (D.hold) D.hold--;
if (!D.done) D.jit_ok = 0;
D.armed = D.done = D.jit_used = D.gbuf = 0;
D.armed = D.done = D.jit_used = D.gbuf = D.ended = D.up = 0;
D.cam_addr = 0;
}
@@ -597,7 +628,12 @@ void vk_dlaa_frame(void) {
// game's own switch, ModelSceneExtensionParam EnableFXAA, on and off). With fxaa = 0 the draws of that second pass's
// fragment shader are skipped, so the scene reaches the HUD as it was. Shaders are known by the FNV-1a hash of their
// SPIR-V, as vk_dump.c names them; a translator change gives new hashes and the switch then does nothing.
#define FXAA_FS 0xf450003ebeb3dc52ull
// With a scene smaller than the output (the game's own 5/6 render scale, or a DLSS mode) the same shader draws the
// scaled picture into the output-sized target, in a pass without the depth attachment the in-place FXAA has: there it
// is always drawn, whatever fxaa says (skipping it would leave the 3D picture out), unless DLSS already wrote that
// target this frame.
// The stock translator's hash, and the one with tools/xlate patch 0010 (PCSS, PR #89) applied.
static const uint64_t FXAA_FS[] = {0xf450003ebeb3dc52ull, 0x0a12f4bc2a9a4fbeull};
static uint64_t spirv_hash(const GfxShader *s) {
static struct { const GfxShader *s; uint64_t h; } tab[8192];
@@ -615,10 +651,14 @@ static uint64_t spirv_hash(const GfxShader *s) {
return 0; // table full: no skip
}
int vk_dlaa_skip_draw(const GfxShader *fs) {
int vk_dlaa_skip_draw(VkExec *ex, const GfxShader *fs) {
static uint64_t frame_read = ~0ull;
static int fxaa = 1;
uint64_t f = __atomic_load_n(&gfx_counters.frames, __ATOMIC_RELAXED);
if (f != frame_read) frame_read = f, fxaa = cfg_bool("TOTK_FXAA"); // once a frame: the menu switches it live
return !fxaa && fs && spirv_hash(fs) == FXAA_FS;
if (!fs) return 0;
uint64_t h = spirv_hash(fs);
if (h != FXAA_FS[0] && h != FXAA_FS[1]) return 0;
if (!ex->depth.image) return D.up; // the scaling pass
return !fxaa;
}
+3 -2
View File
@@ -18,5 +18,6 @@ void vk_dlaa_frame(void);
// the viewport of the scene's draws by the frame's jitter (vk_dlaa_viewport, when the viewport is recorded).
void vk_dlaa_draw(VkExec *ex);
void vk_dlaa_viewport(VkExec *ex, VkViewport *v);
// vk_exec_draw.c, once a draw's fragment shader is known: 1 skips the draw (the game's FXAA while TOTK_FXAA is 0).
int vk_dlaa_skip_draw(const GfxShader *fs);
// vk_exec_draw.c, once a draw's fragment shader is known: 1 skips the draw (the game's FXAA while TOTK_FXAA is 0, its
// scaling draw when DLSS wrote the scaled picture).
int vk_dlaa_skip_draw(VkExec *ex, const GfxShader *fs);
+1 -1
View File
@@ -2041,7 +2041,7 @@ static int prepare_draw(VkExec *ex, int prim, int32_t count, int restart) {
if (fs_wait) fs = shader_for(ex, NVN_STAGE_FS, &has_fs, NULL, 1);
}
if (!vs || (has_fs && !fs)) return 0;
if (vk_dlaa_skip_draw(fs)) return 0; // the game's FXAA, switched off (vk_dlaa.c)
if (vk_dlaa_skip_draw(ex, fs)) return 0; // the game's FXAA off, or its scaling replaced by DLSS (vk_dlaa.c)
uint32_t fbl = feedback_prepare(ex, fs);
VkPipeState s = ex->pipe;
s.vs = vs, s.fs = fs;
+8 -2
View File
@@ -1565,8 +1565,14 @@ static VkSampler make_sampler(VkCtx *c, const samp_par *d) {
si.maxLod = d->lod_max > 1000 ? VK_LOD_CLAMP_NONE : d->lod_max;
if (mf <= NVN_MIN_FILTER_LINEAR) si.maxLod = si.minLod + 0.25f; // not mipmapped: stay on the base level
if (si.maxLod < si.minLod) si.maxLod = si.minLod;
float lim = c->props.limits.maxSamplerLodBias;
si.mipLodBias = fmaxf(-lim, fminf(lim, d->lod_bias));
float lim = c->props.limits.maxSamplerLodBias, bias = d->lod_bias;
// DLSS upscaling (resolution.c): the scene's material textures, the filtered mipmapped ones that repeat, are
// sampled for the output's resolution; clamped ones (post effects, LUTs, the UI) keep the game's bias.
if (!d->cmp_mode && mf == NVN_MIN_FILTER_LINEAR_MIPMAP_LINEAR &&
(si.addressModeU == VK_SAMPLER_ADDRESS_MODE_REPEAT || si.addressModeU == VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT ||
si.addressModeV == VK_SAMPLER_ADDRESS_MODE_REPEAT || si.addressModeV == VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT))
bias += res_dlss_lod_bias();
si.mipLodBias = fmaxf(-lim, fminf(lim, bias));
if (d->aniso > 1) {
si.anisotropyEnable = VK_TRUE;
si.maxAnisotropy = fminf(d->aniso, c->props.limits.maxSamplerAnisotropy);