mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 18:09:58 -04:00
Jitter DLSS's scene on Ocarina's frame, with the shading draws against the copied depth jittered too.
Jitter was off on Ocarina because with it the ground and characters went white within seconds. The cause: the game draws its depth pre-pass into the scene depth, copies it into a second image of the same size, and shades the same geometry into the light target against the copy with the depth test EQUAL. Only the draws into the first image took the jitter, so the shading draws compared unjittered depth with jittered depth, EQUAL failed on nearly every pixel, and the light target kept its clear colour. Frame dumps with and without jitter show the shading passes darkening the light target from a mean of 133 to 13 without it and leaving it at 112 with it. On Ocarina's frame every draw that projects through the camera (it binds the scene context at c3) into a D32F depth of the scene's size now takes the jitter, and full-screen passes drawn with a scene depth attached do not: the bloom composite DLSS reads would otherwise move the picture by the jitter a second time. The viewport is recorded again whenever a draw's jitter differs from the last one recorded. Jitter is on for Ocarina by default (dlaa_jitter = 0 still turns it off), and the DLAA log line counts jittered frames and draws. Checked in Hyrule Field with the camera turning: the picture's brightness matches the run without jitter (mean 33 to 63 against 35 to 60; 144 to 188 before the fix), and in 20 motion-vector checks the warp error is lowest with the jitter applied as DLSS is told it (0.032 to 0.077), against 0.076 to 0.141 with its sign flipped and 0.059 to 0.106 left out, still cameras included: the scene moves by the jitter of that frame, in render pixels. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -490,11 +490,13 @@ static struct {
|
||||
int share_off; // frames left that pick the output pass without the mode's share (vk_dlaa_pass, vk_dlaa_frame)
|
||||
// jitter (vk_dlaa_viewport)
|
||||
VkImage jdepth; // the scene depth of the last frame DLAA ran on: passes drawing with it are jittered
|
||||
uint32_t jw, jh; // its size: on Ocarina's frame the camera's draws into any D32F depth of it are (jitter_draw)
|
||||
float jx, jy; // the offset the next scene draws take, render pixels (window x right, y down)
|
||||
float ux, uy; // the offset this frame's scene draws took (DLSS and the motion vectors get these)
|
||||
uint32_t jframe;
|
||||
int jit_ok, jit_used, hold; // jitter allowed this frame / a draw used it / frames left without it
|
||||
uint64_t holds;
|
||||
uint64_t holds, jittered; // jitter holds; evaluations of a jittered scene
|
||||
uint64_t jdraws, jfixed; // draws into a scene-size depth that took the jitter / that did not (full-screen)
|
||||
// camera (vk_dlaa_draw) and motion vectors (mv_pass)
|
||||
uint64_t cam_addr; // this frame's scene camera block (vk_dlaa_draw), 0: none seen
|
||||
uint32_t cam_size, cam_vp; // its size and the offset of its view-projection rows
|
||||
@@ -1502,12 +1504,40 @@ static float halton(uint32_t i, uint32_t b) {
|
||||
return r;
|
||||
}
|
||||
|
||||
// Whether a draw takes the jitter, before DLSS ran this frame. The deferred frame: every draw into the scene depth.
|
||||
// Ocarina's frame: every draw that projects through the camera (it binds the scene context at c3, vk_dlaa_draw) into a
|
||||
// D32F depth of the scene's size, whichever image that is. Ocarina draws its depth pre-pass into the scene depth, copies
|
||||
// that depth into a second image of the same size, and then shades the same geometry into the light target against
|
||||
// the copy with the depth test EQUAL. Jittering only the draws into the first image left the shading draws unjittered
|
||||
// against jittered depth: EQUAL failed on nearly every pixel, the light target kept its clear colour, and the ground
|
||||
// and characters went white while the sky stayed right. Its full-screen passes drawn with a scene depth
|
||||
// attached (the bloom composite DLSS reads) do not take the jitter either: they read the jittered scene through their
|
||||
// own texture coordinates, and moving them too would shift the picture DLSS gets by a second offset.
|
||||
static int jitter_draw(const VkExec *ex) {
|
||||
const VkExecTarget *z = &ex->depth;
|
||||
if (!D.jit_ok || D.ended || !z->image) return 0;
|
||||
if (D.cam_size != OCAM_BLOCK) return z->image == D.jdepth;
|
||||
return z->format == VK_FORMAT_D32_SFLOAT && z->width == D.jw && z->height == D.jh &&
|
||||
ex->ubo[0][0].size == OCAM_BLOCK && ex->ubo[0][0].addr;
|
||||
}
|
||||
|
||||
void vk_dlaa_viewport(VkExec *ex, VkViewport *v) {
|
||||
if (!D.jit_ok || D.ended || !ex->depth.image || ex->depth.image != D.jdepth) return;
|
||||
ex->vp_jittered = jitter_draw(ex);
|
||||
if (!ex->vp_jittered) return;
|
||||
v->x += D.jx, v->y += D.jy;
|
||||
D.ux = D.jx, D.uy = D.jy, D.jit_used = 1;
|
||||
}
|
||||
|
||||
void vk_dlaa_jitter_check(VkExec *ex) {
|
||||
int j = jitter_draw(ex);
|
||||
if (j != ex->vp_jittered) ex->dirty |= VK_EXEC_DIRTY_VIEWPORT;
|
||||
const VkExecTarget *z = &ex->depth; // the draws into a scene-size depth, with the jitter or without
|
||||
if (D.jit_ok && !D.ended && z->image && z->format == VK_FORMAT_D32_SFLOAT && z->width == D.jw && z->height == D.jh) {
|
||||
if (j) D.jdraws++;
|
||||
else D.jfixed++;
|
||||
}
|
||||
}
|
||||
|
||||
static int scene_color(VkFormat f);
|
||||
|
||||
void vk_dlaa_draw(VkExec *ex) {
|
||||
@@ -1593,10 +1623,10 @@ static void next_jitter(uint32_t w, uint32_t ow) {
|
||||
if (phases > 72) phases = 72;
|
||||
uint32_t i = D.jframe++ % phases + 1;
|
||||
D.jx = halton(i, 2) - 0.5f, D.jy = halton(i, 3) - 0.5f;
|
||||
// Jitter only where the camera is known (vk_dlaa_draw), and not on Ocarina's frame: with it the picture went white
|
||||
// within seconds (no matter the motion vectors; without it the same frames look right), so DLSS there keeps its
|
||||
// history along the camera's motion but samples the same spot of each pixel.
|
||||
D.jit_ok = !D.hold && !nj && D.cam_size == CAM_BLOCK;
|
||||
// Jitter only where the camera is known (vk_dlaa_draw): the deferred engine's block or Ocarina's scene context. On
|
||||
// Ocarina's frame the draws that take it are the camera's into every scene-size depth (jitter_draw); taking only the
|
||||
// draws into DLSS's own depth image turned the picture white, and jitter was off there until that was found.
|
||||
D.jit_ok = !D.hold && !nj && (D.cam_size == CAM_BLOCK || D.cam_size == OCAM_BLOCK);
|
||||
}
|
||||
|
||||
// The DLSS model (NX2NAVI_DLSS_PRESET, live): default takes NVIDIA's model per mode (evaluate: K for DLAA, Quality and
|
||||
@@ -1890,21 +1920,23 @@ evaluated:
|
||||
if (vk_dlaa_hudless_wanted) hudless(cb, e, ow, oh); // frame generation keeps the HUD out of its generated frames
|
||||
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;
|
||||
D.jdepth = z->image, D.jw = z->width, D.jh = z->height;
|
||||
// for frame generation at this frame's present (vk_dlaa_fg_inputs)
|
||||
D.fg_depth = (VkFfxImage){z->image, z->format, w, h, 0};
|
||||
D.fg_mv = (VkFfxImage){e->mv, VK_FORMAT_R16G16_SFLOAT, w, h, 1};
|
||||
D.fg_depth_view = zv, D.fg_mv_view = e->mv_view;
|
||||
D.fg_jx = jx, D.fg_jy = jy, D.fg_at = D.presents, D.fg_fresh = 1;
|
||||
if (D.jit_used) D.jittered++;
|
||||
next_jitter(w, ow);
|
||||
if (++D.evals == 1 || D.evals == 300 || D.evals % 3600 == 0) // 300: one early line with the frames counted
|
||||
rt_log("dlaa: %llu frames anti-aliased (scene %ux%u, output %ux%u; %llu frames without the DLAA point, %llu with camera "
|
||||
"motion, %llu with the characters' mask, %llu without a camera, %llu jitter holds; resets: %llu size, %llu "
|
||||
"camera, %llu target; reactive mask %llu, without its copy %llu; no camera: %llu without a scene-context "
|
||||
"draw, %llu not in DLSS's submission; %llu kept with zero motion, %llu runs past %d; %llu cameras read at the "
|
||||
"draw)",
|
||||
"motion, %llu with the characters' mask, %llu without a camera, %llu jittered (%llu draws moved, %llu not), "
|
||||
"%llu jitter holds; resets: %llu size, %llu camera, %llu target; reactive mask %llu, without its copy %llu; "
|
||||
"no camera: %llu without a scene-context draw, %llu not in DLSS's submission; %llu kept with zero motion, "
|
||||
"%llu runs past %d; %llu cameras read at the draw)",
|
||||
(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.masked, (unsigned long long)D.mv_none,
|
||||
(unsigned long long)D.jittered, (unsigned long long)D.jdraws, (unsigned long long)D.jfixed,
|
||||
(unsigned long long)D.holds, (unsigned long long)D.why[0], (unsigned long long)D.why[1],
|
||||
(unsigned long long)D.why[2], (unsigned long long)R.made, (unsigned long long)R.missed,
|
||||
(unsigned long long)D.cam_none_draw, (unsigned long long)D.cam_none_snap, (unsigned long long)D.cam_kept,
|
||||
|
||||
@@ -72,6 +72,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_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.
|
||||
void vk_mvsurvey_draw(VkExec *ex);
|
||||
|
||||
@@ -71,6 +71,7 @@ typedef struct VkExec {
|
||||
// ---- fixed-function state (vk_exec.c keeps it; vk_exec_draw.c records it before draws)
|
||||
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)
|
||||
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
|
||||
|
||||
@@ -4099,6 +4099,7 @@ static int prepare_draw_ex(VkExec *ex, int prim, int32_t count, int restart, int
|
||||
vk_mvsurvey_draw(ex);
|
||||
vk_mvprev_draw(ex);
|
||||
}
|
||||
vk_dlaa_jitter_check(ex); // a draw with another jitter than the viewport recorded last records it again
|
||||
record_fixed(ex);
|
||||
repeat_stats(ex, info);
|
||||
{ // the replay's binding path is the CPU cost the frame profile needs to separate from recording
|
||||
|
||||
Reference in New Issue
Block a user