diff --git a/runtime/vk_dlaa.c b/runtime/vk_dlaa.c index 7f5f51db..34545dfc 100644 --- a/runtime/vk_dlaa.c +++ b/runtime/vk_dlaa.c @@ -25,6 +25,7 @@ #include "cfg.h" #include "gfx.h" #include "host.h" +#include "nvn_api.h" #include "platform/platform.h" #include "vk.h" #include "vk_dlaa.h" @@ -597,6 +598,17 @@ int vk_dlaa_fg_camera(VkDlaaCamera *c) { return 1; } +// Metres in one unit of Ocarina's view space, for FSR's distance heuristics: one. Measured in Hyrule Field, the camera +// orbits Link about 4 units behind him (the nearest scene depth, 0.975, is 1 - 0.1 / 4) at about 3 units a second, and +// travels about 4.7 units a second while he runs; in centimetres (the 0.01 FSR had) he would be 4 cm from the camera. +#define VIEW_METERS 1.0f + +int vk_dlaa_ffx_camera(VkFfxCamera *c) { + if (!D.fg_cam_ok) return 0; + *c = (VkFfxCamera){D.fg_cam.fov_y, D.fg_cam.znear, D.fg_cam.zfar, VIEW_METERS}; + return 1; +} + int vk_dlaa_fg_inputs(VkFfxImage *depth, VkFfxImage *mv, float *jx, float *jy, int *reset) { if (!D.fg_fresh || D.failed) return 0; D.fg_fresh = 0; @@ -936,6 +948,49 @@ static void fg_store(float out[16], const double m[16]) { for (int r = 0; r < 4; r++) for (int k = 0; k < 4; k++) out[r * 4 + k] = (float)m[k * 4 + r]; } +// The view distance in front of the camera at which the projection P (row-major, column vectors, looking down -z) gives +// clip depth z_ndc = k: (P[10] z + P[11]) / (P[14] z + P[15]) = k, solved for z. INFINITY where no distance gives it. +static double plane_dist(const double P[16], double k) { + double den = P[10] - k * P[14]; + if (fabs(den) <= 1e-9 * (fabs(P[10]) + fabs(P[14]))) return INFINITY; + return -(k * P[15] - P[11]) / den; +} + +// What the depth buffer's 0 and 1 stand for, from the frame's projection and the device's depth mode. With NVN's +// NEAR_IS_MINUS_W (clip depth -w..w, which the pipelines keep through negativeOneToOne, vk_pipeline.c) a fragment +// stores z_ndc * 0.5 + 0.5, so 0 is z_ndc = -1; with NEAR_IS_ZERO it stores z_ndc. Both are 0..1 in the D32F target +// (the viewport's depth range, vk_exec_draw.c), and the -w..w mapping stores exactly what a 0..w projection with the +// same planes would: (f / (f - n)) (1 - n / distance), the convention DLSS, Streamline and FSR take. Ocarina's planes +// are not fixed: in Hyrule Field its z row is (-1.00001, -0.200001), near 0.1 and far about 25,000 (the view's units +// are metres), and the camera before it had far about 1,000. Taken as 0.1 and 1e8 (no far plane), a distance d reads +// as (f - n) d / (f - d): 1,000 as 1,042, 10,000 as 16,650, and the far plane's neighbourhood without bound. So the +// planes come from the projection every frame; a projection whose stored 0 is not in front of the camera keeps the last +// frame's planes. +static void proj_planes(const double P[16], VkDlaaCamera *c) { + int minus_w = nvn_depth_minus_w(); + double at0 = plane_dist(P, minus_w ? -1.0 : 0.0), at1 = plane_dist(P, 1.0); // the distances stored as 0 and 1 + int inverted = !(at0 < at1); // reversed depth: the near plane is stored as 1 + double n = inverted ? at1 : at0, f = inverted ? at0 : at1; + if (!(n > 0) || !isfinite(n)) return; + c->inverted = inverted; + c->znear = (float)n; + c->infinite = !(f < VK_DLAA_FAR_INFINITE); + c->zfar = c->infinite ? VK_DLAA_FAR_INFINITE : (float)f; + // one line at the start and whenever the planes change (the first 20 times) + static float logged_n, logged_f; + static int logged_inv = -1, lines; + if (lines < 20 && (inverted != logged_inv || fabsf(c->znear - logged_n) > 1e-4f * logged_n || + fabsf(c->zfar - logged_f) > 1e-4f * logged_f)) { + lines++, logged_inv = inverted, logged_n = c->znear, logged_f = c->zfar; + char fz[32]; + if (c->infinite) snprintf(fz, sizeof fz, "infinite"); + else snprintf(fz, sizeof fz, "%.6g", c->zfar); + rt_log("dlaa: the scene's projection: near %.6g, far %s, depth %s, clip depth %s (z row %.6g %.6g %.6g %.6g, " + "w row %.6g %.6g %.6g %.6g)", c->znear, fz, inverted ? "inverted (1 near)" : "0 near, 1 far", + minus_w ? "-w..w" : "0..w", P[8], P[9], P[10], P[11], P[12], P[13], P[14], P[15]); + } +} + static void fg_camera(const float *v, const double m[16]) { double P[16], Pi[16], mi[16]; for (int i = 0; i < 16; i++) P[i] = v[28 + i]; @@ -950,6 +1005,8 @@ static void fg_camera(const float *v, const double m[16]) { } c->fov_y = P[5] != 0 ? 2.0f * (float)atan(1.0 / fabs(P[5])) : 1.0f; c->aspect = P[0] != 0 ? (float)fabs(P[5] / P[0]) : 1.777f; + if (!(c->znear > 0)) c->znear = 0.1f, c->zfar = VK_DLAA_FAR_INFINITE, c->infinite = 1; // until a projection gives them + proj_planes(P, c); D.fg_cam_ok = 1; // NX2NAVI_MOUSE_TRACE=1 (test runs, mouse_direct.c): the camera's direction each frame static int trace = -1; @@ -1725,7 +1782,9 @@ static void evaluate(VkExec *ex, const VkExecTarget *dst) { D.last_eval_ns = now; VkFfxImage fc = {t->image, t->format, w, h, 0}, fz = {z->image, z->format, w, h, 0}, fm = {e->mv, VK_FORMAT_R16G16_SFLOAT, w, h, 1}, fo = {e->out, VK_FORMAT_R16G16B16A16_SFLOAT, ow, oh, 1}; - if (!vk_ffx_upscale(cb, &fc, &fz, &fm, &fo, jx, jy, D.reset, dt > 0 && dt < 100 ? (float)dt : 16.67f, 0)) + VkFfxCamera fcam; + if (!vk_dlaa_ffx_camera(&fcam)) memset(&fcam, 0, sizeof fcam); // no camera this frame: FSR's fixed values + if (!vk_ffx_upscale(cb, &fc, &fz, &fm, &fo, jx, jy, D.reset, dt > 0 && dt < 100 ? (float)dt : 16.67f, &fcam)) return dl_fail("FSR 3.1", 0); static int told; if (!told++) rt_log("dlaa: FSR 3.1 at %ux%u -> %ux%u (scene format %d, depth format %d)", w, h, ow, oh, @@ -2301,12 +2360,12 @@ int vk_ngxfg_evaluate(VkCommandBuffer cb, const VkNgxImage *bb, const VkNgxImage static const char *const fw[] = {"DLSSG.CameraFwdX", "DLSSG.CameraFwdY", "DLSSG.CameraFwdZ"}; for (int i = 0; i < 3; i++) p_setf(p, pos[i], c.pos[i]), p_setf(p, up[i], c.up[i]), p_setf(p, rt[i], c.right[i]), p_setf(p, fw[i], c.fwd[i]); - p_setf(p, "DLSSG.CameraNear", 0.1f); // Ocarina's projection, as vk_dlssg.c gives it - p_setf(p, "DLSSG.CameraFar", 1e8f); + p_setf(p, "DLSSG.CameraNear", c.znear); // the frame's own planes (proj_planes), as vk_dlssg.c gives them + p_setf(p, "DLSSG.CameraFar", c.zfar); p_setf(p, "DLSSG.CameraFOV", c.fov_y); p_setf(p, "DLSSG.CameraAspectRatio", c.aspect); p_setu(p, "DLSSG.ColorBuffersHDR", 0); - p_setu(p, "DLSSG.DepthInverted", 0); + p_setu(p, "DLSSG.DepthInverted", (unsigned)c.inverted); p_setu(p, "DLSSG.CameraMotionIncluded", 1); p_setu(p, "DLSSG.Reset", (unsigned)(reset || FG.reset)); p_setu(p, "DLSSG.AutomodeOverrideReset", 0); diff --git a/runtime/vk_dlaa.h b/runtime/vk_dlaa.h index b1b43c8d..b73ef7ef 100644 --- a/runtime/vk_dlaa.h +++ b/runtime/vk_dlaa.h @@ -27,10 +27,16 @@ int vk_dlaa_needs_restart(void); // the menu's upscaler cannot start in this r int vk_dlaa_fg_inputs(VkFfxImage *depth, VkFfxImage *mv, float *jx, float *jy, int *reset); // ... their views, and this frame's camera for DLSS Frame Generation (vk_dlssg.c): matrices for row vectors (v * M, the // rows stored in order), as Streamline takes them; 0 without a camera that frame. +// znear and zfar: the view distances the depth buffer holds as 0 and 1 (1 and 0 when inverted), from the frame's own +// projection and the device's depth mode (vk_dlaa.c proj_planes); with an infinite far plane (infinite) zfar is +// VK_DLAA_FAR_INFINITE, a distance no surface reaches. +#define VK_DLAA_FAR_INFINITE 1e8f typedef struct { float view_to_clip[16], clip_to_view[16], clip_to_prev_clip[16], prev_clip_to_clip[16]; float pos[3], up[3], right[3], fwd[3]; float fov_y, aspect; + float znear, zfar; + int infinite, inverted; } VkDlaaCamera; int vk_dlaa_fg_views(VkImageView *depth, VkImageView *mv); // The picture without the HUD at the size of the game's picture, in *fmt: RGBA8 UNORM bytes like it (sRGB-encoded), or @@ -39,6 +45,7 @@ int vk_dlaa_fg_views(VkImageView *depth, VkImageView *mv); extern int vk_dlaa_hudless_wanted; int vk_dlaa_fg_hudless(VkImage *img, VkImageView *view, uint32_t *w, uint32_t *h, VkFormat *fmt); int vk_dlaa_fg_camera(VkDlaaCamera *c); // ... and its temporal upscaler is AMD FSR 3.1 (NX2NAVI_TAA = fsr3) instead of DLSS +int vk_dlaa_ffx_camera(VkFfxCamera *c); // the same camera as FSR takes it (vk_ffx.h); 0 without one that frame // vk_device.c: NGX's instance and device extensions join the lists (room for max names); vk_dlaa_init after the // device exists brings NGX up and checks that DLSS is available. void vk_dlaa_instance_exts(const char **ext, uint32_t *n, uint32_t max); diff --git a/runtime/vk_dlssg.c b/runtime/vk_dlssg.c index 3851a36b..2cc68d5c 100644 --- a/runtime/vk_dlssg.c +++ b/runtime/vk_dlssg.c @@ -306,7 +306,11 @@ void vk_dlssg_frame(VkCommandBuffer cb, VkExtent2D ext) { memcpy(k.view_to_clip, c.view_to_clip, 64), memcpy(k.clip_to_view, c.clip_to_view, 64); memcpy(k.clip_to_prev_clip, c.clip_to_prev_clip, 64), memcpy(k.prev_clip_to_clip, c.prev_clip_to_clip, 64); memcpy(k.pos, c.pos, 12), memcpy(k.up, c.up, 12), memcpy(k.right, c.right, 12), memcpy(k.fwd, c.fwd, 12); - k.znear = 0.1f, k.zfar = 1e8f, k.fov_y = c.fov_y, k.aspect = c.aspect; // Ocarina's projection (vk_ffx.cpp) + // the frame's own near and far planes (vk_dlaa.c proj_planes); nx2navi_dlssg.dll tells Streamline the depth is + // not inverted, which holds for every projection the game has shown (0 near, 1 far) + k.znear = c.znear, k.zfar = c.zfar, k.fov_y = c.fov_y, k.aspect = c.aspect; + static int told; + if (c.inverted && !told++) rt_log("dlssg: the scene's depth is inverted, which Streamline is not told"); k.jitter[0] = jx, k.jitter[1] = jy; k.mv_scale[0] = 1.0f / (float)d.width, k.mv_scale[1] = 1.0f / (float)d.height; // render pixels k.reset = reset; diff --git a/runtime/vk_ffx.cpp b/runtime/vk_ffx.cpp index ce07b10f..41272894 100644 --- a/runtime/vk_ffx.cpp +++ b/runtime/vk_ffx.cpp @@ -3,9 +3,10 @@ // headers are in third_party/ffx_api (MIT); they are C++ in places, hence this file. Nothing of it runs unless the // upscaler or frame generation asks for FSR 3.1. // -// FSR 3.1 takes the same inputs vk_dlaa.c makes for DLSS: the scene's light target (linear HDR), its D32F depth -// (OpenGL-style, an infinite far plane, not inverted) and the camera motion vectors in render pixels from the current -// frame to the previous one, the convention both share, so the vectors go in unscaled. +// FSR 3.1 takes the same inputs vk_dlaa.c makes for DLSS: the scene's light target (linear HDR), its D32F depth (0 +// near, 1 far, with the near and far planes of the frame's own projection, vk_dlaa.c proj_planes) and the camera +// motion vectors in render pixels from the current frame to the previous one, the convention both share, so the +// vectors go in unscaled. #ifdef _WIN32 #include #endif @@ -191,7 +192,8 @@ Up *context_for(uint32_t w, uint32_t h, uint32_t ow, uint32_t oh) { ffxCreateContextDescUpscale d = {}; d.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE; d.header.pNext = &be.header; - d.flags = FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE | FFX_UPSCALE_ENABLE_DEPTH_INFINITE | FFX_UPSCALE_ENABLE_AUTO_EXPOSURE; + // no infinite-depth flag: the game's far plane is finite (vk_dlaa.c proj_planes) and each dispatch gives it + d.flags = FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE | FFX_UPSCALE_ENABLE_AUTO_EXPOSURE; d.maxRenderSize = {mw, mh}; d.maxUpscaleSize = {ow, oh}; d.fpMessage = message; @@ -271,7 +273,7 @@ extern "C" int vk_ffx_trim_idle(uint64_t recent) { } extern "C" int vk_ffx_upscale(VkCommandBuffer cb, const VkFfxImage *color, const VkFfxImage *depth, const VkFfxImage *mv, - const VkFfxImage *out, float jx, float jy, int reset, float dt_ms, float fov_y) { + const VkFfxImage *out, float jx, float jy, int reset, float dt_ms, const VkFfxCamera *cam) { if (!vk_ffx_load()) return 0; uint64_t now = plat_now_ns(); trim(now); @@ -280,7 +282,7 @@ extern "C" int vk_ffx_upscale(VkCommandBuffer cb, const VkFfxImage *color, const // would blend this picture with whatever that upscaler last saw. static int last; // 3 or 4: which one made the frame before if (vk_ffx_fsr4()) { - if (vk_ffx4_upscale(cb, color, depth, mv, out, jx, jy, reset || last != 4, dt_ms, fov_y)) { + if (vk_ffx4_upscale(cb, color, depth, mv, out, jx, jy, reset || last != 4, dt_ms, cam)) { if (last != 4) rt_log("ffx: the upscaler is %s", vk_ffx4_name()); last = 4; return 1; @@ -312,10 +314,11 @@ extern "C" int vk_ffx_upscale(VkCommandBuffer cb, const VkFfxImage *color, const d.frameTimeDelta = dt_ms; d.preExposure = 1.0f; d.reset = reset != 0; - d.cameraNear = 0.1f; // Ocarina's projection (vk_dlaa.c ocam_vp): near 0.1, far at infinity - d.cameraFar = 1e8f; - d.cameraFovAngleVertical = fov_y > 0 ? fov_y : 1.0f; - d.viewSpaceToMetersFactor = 0.01f; // the game's units are centimetres + // the frame's camera (vk_dlaa.c proj_planes) + d.cameraNear = cam && cam->znear > 0 ? cam->znear : 0.1f; + d.cameraFar = cam && cam->zfar > 0 ? cam->zfar : 1e8f; + d.cameraFovAngleVertical = cam && cam->fov_y > 0 ? cam->fov_y : 1.0f; + d.viewSpaceToMetersFactor = cam && cam->meters > 0 ? cam->meters : 1.0f; ffxReturnCode_t r = A.dispatch(&u->ctx, &d.header); if (r != FFX_API_RETURN_OK) { static int told; diff --git a/runtime/vk_ffx.h b/runtime/vk_ffx.h index ba11cc70..69f4954f 100644 --- a/runtime/vk_ffx.h +++ b/runtime/vk_ffx.h @@ -9,6 +9,12 @@ typedef struct { int storage; // created with VK_IMAGE_USAGE_STORAGE_BIT (FSR writes it) } VkFfxImage; +// The scene camera FSR takes, from the frame's projection (vk_dlaa.c proj_planes): the vertical field of view in +// radians, the near and far planes' view distances (far: VK_DLAA_FAR_INFINITE, 1e8, for a projection without a far +// plane) and the metres in one unit of view space. A field of 0 is not known, and FSR then gets 1 radian, 0.1, 1e8 and +// 1. +typedef struct { float fov_y, znear, zfar, meters; } VkFfxCamera; + int vk_ffx_load(void); // 1 when the library is there with its entry points (loaded once) // Whether FSR 3.1 upscaling can run in this build, for the settings menu: after vk_ffx_load ran, what it found; before, // whether the library file is there, asked once without loading it. 0 where the build has no FSR 3.1 to load. @@ -17,10 +23,10 @@ int vk_ffx_available(void); // rest below), not only an upscaler. int vk_ffx_framegen_available(void); // Records FSR 3.1 into cb: color (the scene light, render size), depth (D32F), mv (R16G16F, render pixels, current to -// previous), out (the output size, RGBA16F, storage). jx, jy: the jitter the scene took, render pixels. fov_y in -// radians (0: unknown). 0 on failure (the caller falls back as it does when DLSS fails). +// previous), out (the output size, RGBA16F, storage). jx, jy: the jitter the scene took, render pixels. cam: the +// frame's camera. 0 on failure (the caller falls back as it does when DLSS fails). int vk_ffx_upscale(VkCommandBuffer cb, const VkFfxImage *color, const VkFfxImage *depth, const VkFfxImage *mv, - const VkFfxImage *out, float jx, float jy, int reset, float dt_ms, float fov_y); + const VkFfxImage *out, float jx, float jy, int reset, float dt_ms, const VkFfxCamera *cam); void vk_ffx_release(void); // before the device goes away // FSR 3.1's contexts that no upscale used in the last `recent` calls, destroyed with the device idle (the caller waited // for it): room for an FSR 4 context whose creation failed. Their count. @@ -36,7 +42,8 @@ int vk_ffx4_available(void); // the libraries are there and list a 4.x vers // device, from any thread (0 before the device exists) const char *vk_ffx4_name(void); // "AMD FSR 4.1.2" once vk_ffx4_available found it int vk_ffx4_upscale(VkCommandBuffer cb, const VkFfxImage *color, const VkFfxImage *depth, const VkFfxImage *mv, - const VkFfxImage *out, float jx, float jy, int reset, float dt_ms, float fov_y); // as vk_ffx_upscale + const VkFfxImage *out, float jx, float jy, int reset, float dt_ms, + const VkFfxCamera *cam); // as vk_ffx_upscale void vk_ffx4_release(void); int vk_ffx4_failed(void); // it failed three times in a row: FSR 3.1 serves until vk_ffx4_retry void vk_ffx4_retry(void); // the menu chose FSR 4 again: try it anew after such failures diff --git a/runtime/vk_ffx4.cpp b/runtime/vk_ffx4.cpp index 452e895e..48b240b2 100644 --- a/runtime/vk_ffx4.cpp +++ b/runtime/vk_ffx4.cpp @@ -24,7 +24,7 @@ extern "C" { extern "C" int vk_ffx4_available(void) { return 0; } extern "C" const char *vk_ffx4_name(void) { return "AMD FSR 4"; } extern "C" int vk_ffx4_upscale(VkCommandBuffer, const VkFfxImage *, const VkFfxImage *, const VkFfxImage *, const VkFfxImage *, - float, float, int, float, float) { + float, float, int, float, const VkFfxCamera *) { return 0; } extern "C" void vk_ffx4_release(void) {} @@ -232,7 +232,7 @@ Up *create(Up *slot, uint32_t mw, uint32_t mh, uint32_t ow, uint32_t oh) { slot->desc.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_UPSCALE; slot->desc.header.pNext = &slot->backend.header; slot->desc.flags = - FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE | FFX_UPSCALE_ENABLE_DEPTH_INFINITE | FFX_UPSCALE_ENABLE_AUTO_EXPOSURE; + FFX_UPSCALE_ENABLE_HIGH_DYNAMIC_RANGE | FFX_UPSCALE_ENABLE_AUTO_EXPOSURE; // a finite far plane, as FSR 3.1's slot->desc.maxRenderSize = {mw, mh}; slot->desc.maxUpscaleSize = {ow, oh}; slot->desc.fpMessage = message; @@ -354,7 +354,7 @@ extern "C" void vk_ffx4_trim(uint64_t now_ns) { } extern "C" int vk_ffx4_upscale(VkCommandBuffer cb, const VkFfxImage *color, const VkFfxImage *depth, const VkFfxImage *mv, - const VkFfxImage *out, float jx, float jy, int reset, float dt_ms, float fov_y) { + const VkFfxImage *out, float jx, float jy, int reset, float dt_ms, const VkFfxCamera *cam) { if (!vk_ffx4_available() || g_off.load(std::memory_order_acquire)) return 0; uint64_t now = plat_now_ns(); if (g_failures && now < g_retry_ns) return 0; // FSR 3.1 serves until the next try @@ -382,10 +382,11 @@ extern "C" int vk_ffx4_upscale(VkCommandBuffer cb, const VkFfxImage *color, cons d.frameTimeDelta = dt_ms; d.preExposure = 1.0f; d.reset = reset != 0; - d.cameraNear = 0.1f; // Ocarina's projection (vk_dlaa.c ocam_vp): near 0.1, far at infinity - d.cameraFar = 1e8f; - d.cameraFovAngleVertical = fov_y > 0 ? fov_y : 1.0f; - d.viewSpaceToMetersFactor = 0.01f; // the game's units are centimetres + // the frame's camera (vk_dlaa.c proj_planes), as FSR 3.1 gets it (vk_ffx.cpp) + d.cameraNear = cam && cam->znear > 0 ? cam->znear : 0.1f; + d.cameraFar = cam && cam->zfar > 0 ? cam->zfar : 1e8f; + d.cameraFovAngleVertical = cam && cam->fov_y > 0 ? cam->fov_y : 1.0f; + d.viewSpaceToMetersFactor = cam && cam->meters > 0 ? cam->meters : 1.0f; ffxReturnCode_t r = A.dispatch(&u->ctx, &d.header); if (r != FFX_API_RETURN_OK) { static int told; diff --git a/runtime/vk_fg.cpp b/runtime/vk_fg.cpp index f1501995..3ed69bef 100644 --- a/runtime/vk_fg.cpp +++ b/runtime/vk_fg.cpp @@ -241,7 +241,8 @@ extern "C" void vk_fg_frame(VkCommandBuffer cb, VkSwapchainKHR sc, VkFormat fmt, ffxCreateContextDescFrameGeneration d = {}; d.header.type = FFX_API_CREATE_CONTEXT_DESC_TYPE_FRAMEGENERATION; d.header.pNext = &hl.header; - d.flags = FFX_FRAMEGENERATION_ENABLE_DEPTH_INFINITE | (hdr_format(fmt) ? FFX_FRAMEGENERATION_ENABLE_HIGH_DYNAMIC_RANGE : 0); + // no infinite-depth flag: the game's far plane is finite, and each preparation gives it (vk_fg_frame) + d.flags = hdr_format(fmt) ? FFX_FRAMEGENERATION_ENABLE_HIGH_DYNAMIC_RANGE : 0; d.displaySize = {ext.width, ext.height}; d.maxRenderSize = {max_render.width, max_render.height}; d.backBufferFormat = ffxApiGetSurfaceFormatVK(fmt); @@ -298,10 +299,13 @@ extern "C" void vk_fg_frame(VkCommandBuffer cb, VkSwapchainKHR sc, VkFormat fmt, double dt = last_ns ? (now - last_ns) / 1e6 : 16.67; last_ns = now; p.frameTimeDelta = dt > 0 && dt < 100 ? (float)dt : 16.67f; - p.cameraNear = 0.1f; // Ocarina's projection: near 0.1, far at infinity (vk_ffx.cpp) - p.cameraFar = 1e8f; - p.cameraFovAngleVertical = 1.0f; - p.viewSpaceToMetersFactor = 0.01f; + // the frame's camera (vk_dlaa.c proj_planes), as the upscaler gets it (vk_ffx.cpp) + VkFfxCamera cam; + if (!vk_dlaa_ffx_camera(&cam)) memset(&cam, 0, sizeof cam); + p.cameraNear = cam.znear > 0 ? cam.znear : 0.1f; + p.cameraFar = cam.zfar > 0 ? cam.zfar : 1e8f; + p.cameraFovAngleVertical = cam.fov_y > 0 ? cam.fov_y : 1.0f; + p.viewSpaceToMetersFactor = cam.meters > 0 ? cam.meters : 1.0f; p.depth = image(&depth); p.motionVectors = image(&mv); r = vk_ffx_dispatch(&F.fg, &p.header);