diff --git a/docs/releases/v0.9.2.md b/docs/releases/v0.9.2.md index db2c82ea..06961feb 100644 --- a/docs/releases/v0.9.2.md +++ b/docs/releases/v0.9.2.md @@ -1,23 +1,29 @@ ## Fixed +- **FSR and DLSS showed a blocky, shaking picture with the HUD hidden.** The upscaler's picture was put where the + game draws its HUD. With the HUD off the game skips that step, and the frame's last step then drew the game's own + plainly scaled scene over it: the screen showed the scene at its render size (a third of the picture at Ultra + Performance) in visible blocks, shaking by up to one render pixel from frame to frame, with a white line along the + bottom or right edge in about half the frames, while the upscaler's work was thrown away. Native AA was affected + as well as the scaling modes. The upscaler now runs where the game's own upscaler does, HUD or not. On a save with + the HUD off at FSR 4 Ultra Performance: fine detail is back, the picture moves 0.02 pixels between screenshots of a + still view instead of jumping by 3, and no screenshot has the white line (half had it). - **A crash after switching FSR modes.** One FSR context served every mode, with another render size at each switch, and the first frame after a switch from Quality to Native AA could end the game inside AMD's driver. Each render size now gets a context of its own, as AMD's own sample makes them, and the one before goes a few frames later (a mode switch takes about 50 ms more); with dynamic resolution on, one context made for changing sizes takes every step. -- **The light line at the bottom or right edge with FSR or DLSS, still seen in some frames.** The scene's outermost - rows and columns are now filled from the ones next to them in every frame the upscaler gets, not only after the - scene moved up or to the left. -- **A blocky picture for a moment whenever the camera swung quickly with FSR or DLSS.** A fast swing of the camera - around Link (11 to 18 degrees a frame) was taken for a cut to a new view, and the upscaler threw away what it had - built up at every frame of the swing; at Ultra Performance that showed the scene at a third of the picture's size. - Only a jump of the camera or a turn of 30 degrees or more in one frame counts as a cut now. +- **Bright patches along the bottom edge over water, and a light line at the edge, with FSR or DLSS.** To let the + upscaler build a smoother picture the scene is drawn moved by a fraction of a pixel, and AMD's driver then leaves + the last row or column undrawn. Those are now filled from their neighbours as soon as each step of the scene is + drawn, before the water, the bloom or the upscaler read them. +- **A new start for the upscaler at every frame of a quick camera swing.** A fast swing of the camera around Link (11 + to 18 degrees a frame) was taken for a cut to a new view. Only a jump of the camera or a turn of 30 degrees or more + in one frame counts as a cut now. ## Known issues -- At FSR's and DLSS's smaller modes, Link and other characters look coarser while they move: the upscaler gets only - the camera's motion for them, not their own, so it can keep less of what it built up there. -- Over water, a bright line can still show at the very bottom of the picture now and then with FSR or DLSS: the water - reads the scene before its last row is filled. +- At FSR's and DLSS's smaller modes, Link and other characters look a little coarser while they move: the upscaler + gets only the camera's motion for them, not their own. - Ultra Performance gains little frame rate over Quality with FSR 4. Most of a frame is the replay of the game's draws on the CPU, which does not shrink with the render size, and FSR 4 itself takes 3.1 ms of the GPU's time at Ultra Performance and 3.9 ms at Native AA on a Radeon RX 7900 XT (FSR 3.1: 0.5 ms). Measured standing in Hyrule Field at diff --git a/runtime/cfg.c b/runtime/cfg.c index ee9169f3..4e4cec2b 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -44,7 +44,7 @@ static const char *const known[] = { "BIND_SKIP", "BIND_STATS", "BIND_UP", "BIND_X", "BIND_Y", "BIND_ZL", "BIND_ZR", "BLOCK_VIEWS_3D", "CACHE_DIE", "CLOTH_REALTIME", "COLOR_BRIGHTNESS", "COMPUTE_KEEP", "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_CAM_KEEP", "DLAA_CUT", "DLSS_IDLE_FREE", "DLAA_EDGE_FILL", "FFX_DEBUG", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TARGET_KEEP", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_PRESET", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR", + "DESC_TEMPLATE", "DEVICE_PROFILE", "DISCORD_APP_ID", "DISCORD_IMAGE", "DISCORD_RPC", "DLAA", "DLAA_CAM_KEEP", "DLAA_CUT", "DLSS_IDLE_FREE", "DLAA_EDGE_FILL", "DLAA_AT_UPSCALER", "FFX_DEBUG", "DLAA_JITTER", "DLAA_MV", "DLAA_MASKDEBUG", "DLAA_MVDEBUG", "DLAA_OBJMV", "DLAA_SURVEY", "DLAA_TARGET_KEEP", "DLAA_TIMES", "DLSS", "DLSS_CHAR_MASK", "DLSS_PRESET", "DLSS_REACTIVE", "DUMP", "DUMP_BUF", "DUMP_DIR", "DUMP_LOG", "DUMP_RAW", "DUMP_SHADERS", "DUMP_FILE", "DS3", "LOG_CS_BINDS", "LOG_TEX_FLAGS", "LOG_MESH", "MESH", "POOL", "NATIVE_TENSOR", "LOG_RCOND", "LOG_RT_SIZES", "DUMP_WHITE", "DUMP_AFTER", "DUMP_MOVIE", "SUBMIT_FINISH", "ACQUIRE_WAIT", "CRASH_FILTER_GUARD", "CS_FALLBACK", "EXEFS", "FEEDBACK", "FIX_C0", "FIX_ZERO", "FLIGHT", "FLIGHT_AT", "FLIGHT_DIR", "FLIGHT_FRAMES", "GPU_TIMELINE", "FFX_PIPE_CACHE", "FLIGHT_SPIKE_MS", "FLIGHT_THUMBS", "FLIGHT_EVERY", "FLUSH_SPAN", "FLUSH_UPLOAD", "FOG_CULL", "FOLIAGE_SHADOW_CULL", "FOLIAGE_SHADOW_VRS", "FOV", "FOV_PATCH", "FG_HUDLESS_SHOW", "FG_MULT", "FPS60", "FPS_LIMIT", "FRAMEGEN", "FRAMEGEN_MULTIPLIER", "FREEZE_IDLE", "FREEZE_ASYNC", "FREEZE_BUDGET_US", "FREE_CORES", "FULLSCREEN", "FXAA", "GAME_ASPECT", "GAME_RES", "GPA", "GPA_EMPTY", "GPA_TWIN", "GPA_TWIN_MAX_KB", "MIRROR_CAPTURE_KB", "WB_SKIP_MB", "GPL", "GPL_DRAW_BUILD", "GPL_FEEDBACK", "PIPE_AHEAD", "PIPE_FAST_WORKERS", "PIPE_FRAME_WAIT_MS", "PIPE_LINK_DRAW_MS", "PIPE_SKIP_STEADY", "PROG_LEAD", "GPU", "GPU_INDEX", "GPU_PASSES", "GPU_NAME", "HDR", diff --git a/runtime/vk_dlaa.c b/runtime/vk_dlaa.c index 040db9be..0aaabd79 100644 --- a/runtime/vk_dlaa.c +++ b/runtime/vk_dlaa.c @@ -1575,6 +1575,7 @@ static int jitter_draw(const VkExec *ex) { void vk_dlaa_viewport(VkExec *ex, VkViewport *v) { ex->vp_jittered = jitter_draw(ex); if (!ex->vp_jittered) return; + ex->pass_jit = 1; v->x += D.jx, v->y += D.jy; D.ux = D.jx, D.uy = D.jy, D.jit_used = 1; } @@ -1820,48 +1821,72 @@ static void release_kept(const struct Size *making, int all) { making->w, making->h, all ? "after a release" : "larger inputs"); } -// The scene's outer columns and rows in a jittered frame. The jitter moves the scene's viewport by under half a pixel -// (vk_dlaa_viewport), which keeps every pixel centre inside it, yet on an RX 7900 XT (AMD's Windows driver) the draws of -// a viewport moved left left the last column out, and of one moved up the last row: the driver evidently limits drawing -// to the whole pixels inside the viewport. In a frame dump (NX2NAVI_DUMP, Hyrule Field, 3416x1440, FSR 4 Native AA) the -// depth's last row kept its clear value through every scene pass and the light target held the fog's colour there, -// which the upscaler blended into a light line along the bottom and right edges of the picture that flickered with the -// jitter; with NX2NAVI_DLAA_JITTER=0, and without DLSS or FSR, there was no line. Before DLSS or FSR reads the scene, the -// outermost column and row on each side of the light target and of the depth (which the motion vectors are made from) -// are filled from the ones next to them, in every jittered frame: filled only after a jitter to the left or up, the line -// stayed gone in every test run, yet a player's clip at Ultra Performance with HDR still showed the sky's colour in the -// last row of about half the frames, and another driver may round the near edge instead. A copied edge costs nothing -// visible: one render pixel at the picture's border, which the upscaler blends with its history. -// NX2NAVI_DLAA_EDGE_FILL=0 (test): not filled. -static void edge_fill(VkCommandBuffer cb, const VkExecTarget *t, const VkExecTarget *z, int jittered) { +// The outer columns and rows of what a jittered pass draws into. The jitter moves the scene's viewport by under half a +// pixel (vk_dlaa_viewport), which keeps every pixel centre inside it, yet on an RX 7900 XT (AMD's Windows driver) the draws +// of a viewport moved left left the last column out, and of one moved up the last row: the driver evidently limits +// drawing to the whole pixels inside the viewport. Those pixels keep what was there before the pass: in a frame dump +// (NX2NAVI_DUMP, Hyrule Field) the depth's last row kept its clear value through every scene pass and the light target the +// sky's colour, and in a village the light target's clear colour, white. With NX2NAVI_DLAA_JITTER=0, and without DLSS or +// FSR, every row is drawn. +// So when a pass that took the jitter ends (vk_exec.c vk_exec_pass_end), the outermost row and column on each side of +// its colour targets and its depth are filled from the ones next to them, before anything reads them. Filling only the +// armed pair right before the upscaler read it (evaluate, which still does it for a target a dispatch wrote) was too +// late for whatever reads the scene in between: water reads the scene behind it and showed bright patches along the +// bottom in a fifth of the shots of a run through a stream (none with the jitter off), and the bloom and the +// anti-aliasing pass read the row too. (The white line in a player's clips had a second cause, the upscaler's picture +// never reaching the screen with the HUD hidden: vk_dlaa_upscaler.) +// A copied edge is one render pixel at the picture's border, which the upscaler blends with its history. +// NX2NAVI_DLAA_EDGE_FILL: 1 (default) at each jittered pass's end and before the upscaler; 2 only before the upscaler (as +// 0.9.1 did, for comparison); 0 not at all. +static int edge_fill_mode(void) { static int on = -1; if (on < 0) on = rt_knob("DLAA_EDGE_FILL", "1"); - uint32_t w = t->width, h = t->height; - if (!on || !jittered || w < 3 || h < 3) return; + return on; +} + +// One image's border from the texels next to it, in one copy: the columns and rows without their ends, then the four +// corners from their diagonal neighbours. Every source is inside the border and every destination on it, so no region +// reads what another writes. The image is in GENERAL and nothing is still drawing into it. +static void edge_copy(VkCommandBuffer cb, const VkExecTarget *g, VkImageAspectFlags aspect) { + int32_t w = (int32_t)g->width, h = (int32_t)g->height; + if (w < 4 || h < 4) return; + const VkImageSubresourceLayers sl = {aspect, g->level, g->base_layer, 1}; +#define EDGE(sx, sy, dx, dy, ew, eh) \ + {.srcSubresource = sl, .srcOffset = {sx, sy, 0}, .dstSubresource = sl, .dstOffset = {dx, dy, 0}, \ + .extent = {(uint32_t)(ew), (uint32_t)(eh), 1}} + const VkImageCopy r[8] = {EDGE(1, 1, 0, 1, 1, h - 2), EDGE(w - 2, 1, w - 1, 1, 1, h - 2), + EDGE(1, 1, 1, 0, w - 2, 1), EDGE(1, h - 2, 1, h - 1, w - 2, 1), + EDGE(1, 1, 0, 0, 1, 1), EDGE(w - 2, 1, w - 1, 0, 1, 1), + EDGE(1, h - 2, 0, h - 1, 1, 1), EDGE(w - 2, h - 2, w - 1, h - 1, 1, 1)}; +#undef EDGE + vkCmdCopyImage(cb, g->image, VK_IMAGE_LAYOUT_GENERAL, g->image, VK_IMAGE_LAYOUT_GENERAL, 8, r); +} + +static int edge_target(const VkExecTarget *g) { return g->image && g->samples <= 1 && !g->is3d && !g->blocks; } + +void vk_dlaa_pass_end(VkExec *ex) { + if (!ex->pass_jit) return; + ex->pass_jit = 0; + if (edge_fill_mode() != 1) return; + int any = edge_target(&ex->depth) && (ex->depth.aspect & VK_IMAGE_ASPECT_DEPTH_BIT); + for (uint32_t i = 0; i < ex->pass_ncolor && i < 8; i++) any |= edge_target(&ex->color[i]); + if (!any) return; static int told; - if (!told++) rt_log("dlaa: the scene's outer columns and rows are filled from the ones next to them in each jittered frame"); - // the columns first, then the rows over the whole width, so the corners come from the filled columns - for (int pass = 0; pass < 2; pass++) { - VkImageCopy r[2][2]; // [image][side] - for (int side = 0; side < 2; side++) { - int32_t end = pass ? (int32_t)h - 1 : (int32_t)w - 1, at = side ? end : 0, next = side ? end - 1 : 1; - VkOffset3D from = pass ? (VkOffset3D){0, next, 0} : (VkOffset3D){next, 0, 0}; - VkOffset3D to = pass ? (VkOffset3D){0, at, 0} : (VkOffset3D){at, 0, 0}; - VkExtent3D ext = pass ? (VkExtent3D){w, 1, 1} : (VkExtent3D){1, h, 1}; - for (int i = 0; i < 2; i++) { - const VkExecTarget *g = i ? z : t; - VkImageAspectFlags a = i ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT; - r[i][side] = (VkImageCopy){.srcSubresource = {a, g->level, g->base_layer, 1}, .srcOffset = from, - .dstSubresource = {a, g->level, g->base_layer, 1}, .dstOffset = to, .extent = ext}; - } - } - for (int i = 0; i < 2; i++) { - const VkExecTarget *g = i ? z : t; - if (g->image && g->width == w && g->height == h) - vkCmdCopyImage(cb, g->image, VK_IMAGE_LAYOUT_GENERAL, g->image, VK_IMAGE_LAYOUT_GENERAL, 2, r[i]); - } - full_barrier(cb); - } + if (!told++) rt_log("dlaa: the outer rows and columns of each jittered pass's targets are filled from the ones next to them"); + vk_exec_barrier(ex); // the pass's draws are done, and its targets are in GENERAL + for (uint32_t i = 0; i < ex->pass_ncolor && i < 8; i++) + if (edge_target(&ex->color[i])) edge_copy(ex->cb, &ex->color[i], VK_IMAGE_ASPECT_COLOR_BIT), ex->recorded++; + if (edge_target(&ex->depth) && (ex->depth.aspect & VK_IMAGE_ASPECT_DEPTH_BIT)) + edge_copy(ex->cb, &ex->depth, VK_IMAGE_ASPECT_DEPTH_BIT), ex->recorded++; +} + +// Before the upscaler reads the armed pair (evaluate): once more, for a light target a dispatch wrote after its last +// pass. The pair is at level 0 of the scene's size. +static void edge_fill(VkCommandBuffer cb, const VkExecTarget *t, const VkExecTarget *z, int jittered) { + if (!edge_fill_mode() || !jittered) return; + if (edge_target(t)) edge_copy(cb, t, VK_IMAGE_ASPECT_COLOR_BIT); + if (edge_target(z) && z->width == t->width && z->height == t->height) edge_copy(cb, z, VK_IMAGE_ASPECT_DEPTH_BIT); + full_barrier(cb); } // Set when the scene the upscaler runs on has another size than the last one; vk_dlaa_resized_take reads it. @@ -2145,6 +2170,37 @@ static int output_target(VkFormat f) { return srgb8(f) || vk_hdr_native_picture( double wide_dlss_share(void); // widescreen.c: the DLSS mode's share of the picture (1 DLAA), 0 off +// Ocarina's own upscaler is the place for DLSS or FSR: its stand-in (vk_exec_draw.c untranslated_dispatch_fallback) has +// just scaled the scene into the image the rest of the frame shows, and the upscaler's picture goes over it there. +// Until this hook the upscaler ran at the pass after it (vk_dlaa_pass below), which was taken for the pass the HUD is +// drawn into, the stand-in's output image as its target. With the HUD hidden the game draws no such pass: the next pass +// is the frame's last, which encodes the stand-in's image into the 8-bit output. DLSS's or FSR's picture was then +// written into that 8-bit target and the last draw drew the stand-in's picture over it: the screen showed the +// jittered scene at its render size, scaled with a plain filter. On a player's save with the HUD off that was every +// frame: blocks of render pixels, a picture that shook with the jitter by up to one render pixel, the undrawn edge +// row in white, and the upscaler's cost for nothing; with the HUD on (every test save until then) the same settings +// gave the upscaler's picture. Found by dumping the same frame of both saves (NX2NAVI_DUMP): three HUD passes before the +// last one in one, none in the other. +// The image is the stand-in's output when it has the light target's format and the scene's shape and is no smaller +// than the scene (the movie network's and other tensor programs' outputs are RGBA8 or smaller). A frame without the +// dispatch (NX2NAVI_CS_FALLBACK=0, another engine) still ends at vk_dlaa_pass. NX2NAVI_DLAA_AT_UPSCALER=0 (test): as before. +void vk_dlaa_upscaler(VkExec *ex, VkImage out, VkFormat fmt, uint32_t w, uint32_t h) { + static int on = -1; + if (on < 0) on = rt_knob("DLAA_AT_UPSCALER", "1"); + if (!on || !dl_active() || !D.armed || D.done || D.gbuf || !out || fmt != VK_FORMAT_B10G11R11_UFLOAT_PACK32) return; + uint32_t sw = D.color.width, sh = D.color.height; + if (w < sw || h < sh || out == D.color.image) return; + if ((double)w * sh > 1.03 * (double)h * sw || (double)h * sw > 1.03 * (double)w * sh) return; // not the scene's shape + static int told; + if (!told++) + rt_log("dlaa: the upscaler runs where the game's own does: scene %ux%u into its %ux%u output", sw, sh, w, h); + VkExecTarget dst = {.image = out, .format = fmt, .aspect = VK_IMAGE_ASPECT_COLOR_BIT, .layers = 1, .width = w, + .height = h, .samples = 1}; + vk_exec_hook_turn(); // as in vk_dlaa_pass: the replay workers' draws read the jitter and its end + D.ended = D.done = D.up = 1; + evaluate(ex, &dst); +} + void vk_dlaa_pass(VkExec *ex) { const VkExecTarget *c = &ex->color[0], *z = &ex->depth; if (!dl_active()) return; diff --git a/runtime/vk_dlaa.h b/runtime/vk_dlaa.h index 7f769894..d150e472 100644 --- a/runtime/vk_dlaa.h +++ b/runtime/vk_dlaa.h @@ -65,6 +65,9 @@ int64_t vk_dlaa_vram(void); // frame (vk_dlaa_frame). typedef struct VkExec VkExec; void vk_dlaa_pass(VkExec *ex); +// vk_exec_draw.c untranslated_dispatch_fallback, after the stand-in of the game's own upscaler wrote its output image +// (in GENERAL, of format fmt and w x h): DLSS or FSR runs there on the armed scene and its picture goes over it. +void vk_dlaa_upscaler(VkExec *ex, VkImage out, VkFormat fmt, uint32_t w, uint32_t h); void vk_dlaa_frame(void); // 1 once, at the present of the first frame whose scene has a new size after a setting changed (vk_dlaa.c). int vk_dlaa_resized_take(void); @@ -72,6 +75,7 @@ int vk_dlaa_resized_take(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); +void vk_dlaa_pass_end(VkExec *ex); // vk_exec.c, a pass just ended: the edges of a jittered pass's targets are filled void vk_dlaa_jitter_check(VkExec *ex); // before each draw's fixed state: records the viewport again where its jitter changes // vk_mvsurvey.c (NX2NAVI_MV_SURVEY): notes the uniform blocks of each scene draw, beside vk_dlaa_draw; each present // compares them with the previous frames' and logs a summary now and then. diff --git a/runtime/vk_exec.c b/runtime/vk_exec.c index 7e139eff..9dcbb025 100644 --- a/runtime/vk_exec.c +++ b/runtime/vk_exec.c @@ -911,6 +911,7 @@ void vk_exec_pass_end(VkExec *ex) { vk_texture_gpu_written(ex->depth.tex), tfr_note(&ft, stamp); } if (lk) plat_mutex_unlock(&tfr_lock); + vk_dlaa_pass_end(ex); // a jittered pass left its targets' outer rows or columns undrawn } VkCommandBuffer vk_exec_inline_begin(int *reopen) { diff --git a/runtime/vk_exec.h b/runtime/vk_exec.h index 47fa8696..b09a4092 100644 --- a/runtime/vk_exec.h +++ b/runtime/vk_exec.h @@ -74,6 +74,7 @@ typedef struct VkExec { float vp[16][6]; // OP_VIEWPORTS: x, y, w, h, near, far int has_vp; // a viewport was set; else the render area int vp_jittered; // the viewport recorded last took the DLAA jitter (vk_dlaa.c vk_dlaa_viewport) + int pass_jit; // a viewport of the pass open now took it: its targets' edges are filled at its end (vk_dlaa_pass_end) p_scissor scissor; // OP_SCISSOR (scissor 0) int has_scissor; // a scissor was set; else unbounded float depth_range[2]; // OP_DEPTH_RANGE: overrides the viewports' near and far diff --git a/runtime/vk_exec_draw.c b/runtime/vk_exec_draw.c index 0c588229..d3b04b8d 100644 --- a/runtime/vk_exec_draw.c +++ b/runtime/vk_exec_draw.c @@ -6289,6 +6289,7 @@ static void untranslated_dispatch_fallback(VkExec *ex) { } ex->recorded++; vk_exec_barrier(ex); + vk_dlaa_upscaler(ex, di, df, dw, dh); // the scene upscaler's output: DLSS's or FSR's picture goes there (vk_dlaa.c) } static void op_dispatch(VkExec *ex, const p_dispatch *d) {