[PR #3763] [MERGED] FSR 3.1 frame interpolation, ported to WGSL (frame generation 2/3) #5202

Closed
opened 2026-11-03 05:10:56 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3763
Author: @spidercraft
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: fsr-frame-interpolation


📝 Commits (4)

  • 572c5c4 FSR 3.1 frame interpolation, ported to WGSL (frame generation 2/3)
  • c1ba8b5 cargo fmt
  • 3466915 Merge origin/main into fsr-frame-interpolation
  • 58b2c98 frame_gen: size the optical flow field as OpticalFlow sizes its vectors (div_ceil)

📊 Changes

4 files changed (+1619 additions, -7 deletions)

View changed files

📝 THIRD_PARTY_NOTICES.md (+5 -4)
📝 crates/horizon-client-render/src/gfx/frame_gen.rs (+5 -3)
➕ crates/horizon-client-render/src/gfx/frame_gen/interpolation.rs (+806 -0)
➕ crates/horizon-client-render/src/gfx/frame_gen/interpolation.wgsl (+803 -0)

📄 Description

🤖 Opened by Claude Code.

Frame generation, part 2 of 3. This PR: the frame interpolation. It is built on #3762 (the optical flow, part 1: merge it first; this branch contains it, so review this PR's own commit). Next: #3764 (the setting that runs both). Toward #2922.

What it is

AMD FidelityFX SDK 1.1.4's frame interpolation (FSR 3.1's frame generation, MIT), ported to WGSL in gfx/frame_gen/interpolation.{rs,wgsl}: the frame halfway between the previous real frame and this one. The license heads the WGSL file; THIRD_PARTY_NOTICES.md credits both ports.

Still unused by the game (#[allow(dead_code)] until part 3). Players see no change (skip-release).

How it works (ffxFrameInterpolationPrepare then ffxFrameInterpolationDispatch, same order)

  1. Prepare: dilate the depth (nearest of 3×3, reversed depth) and the motion vectors; estimate the previous frame's depth by splatting this one's along them.
  2. Setup: count the frames since the last reset or scene change.
  3. Estimate the made frame's depth; splat the game's motion vectors to the made frame's pixels (atomic maximum of packed priority and half-vector, with AMD's secondary vectors); fill the field's holes from a pyramid of it.
  4. Splat the optical flow's vectors the same way, after AMD's 3×3 weighting.
  5. Disocclusion: mask what each frame can't see from the made frame's position.
  6. Interpolate: blend the two frames along the game field, then along the optical flow, weighted by how well each one's colours match (AMD's rule: the game's vectors win unless they clearly match worse). The first 10 frames after a reset use the game's only.
  7. Inpaint the holes from a pyramid of the result; keep this frame as the next one's previous.

Where it differs from AMD's

  • Motion vectors: Horizon has no motion vector buffer, so prepare computes the camera's from the depth and this frame's unjittered clip space to the last (the TAA reprojection), with the jitter removed. What moves on its own relies on the optical flow. (FSR3's prepare takes the game's vectors instead.)
  • Textures AMD updates with image atomics (vector fields, estimated depths) are storage buffers of atomic<u32>; WGSL has no image atomics.
  • Both SPD pyramids are a pass per level, with AMD's reductions, and each has its own texture (AMD aliases one).
  • The interpolation writes one rgba16float texture and the inpainting another (rgba16float can't be read_write everywhere).
  • f16 packing of the vector fields is integer arithmetic: pack2x16float needs a capability some GPUs lack.
  • No HUD-less pass, no distortion field, the whole screen as the interpolation rect, SDR input (Horizon's swapchain values), inverted finite depth.
  • Places where AMD divides by zero and relies on the hardware's max(0, NaN) = 0 are guarded up front, with the same result.

Checked

On a device with WebGPU's default limits, RTX 5090 (Vulkan, Linux); the GPU tests skip without a GPU:

  • shader_validates: naga validates the WGSL with no optional capabilities.
  • moves_the_view_halfway_with_the_camera: frames of a camera panning 16 pixels a frame; the made frame's error against the true halfway frame is under a quarter of either real frame's.
  • moves_what_the_optical_flow_follows_halfway: a still camera and a picture moving (16, 8); the optical flow carries the made frame halfway, error under a third of either real frame's (where the still camera's two colours happen to match, AMD's rule keeps the game's vectors, as designed).
  • Part 1's tests still pass; clippy (-D warnings) and rustfmt clean. tools/pr_ready.py wasn't run on this branch; part 3 lists what the whole stack was tested with.

Size: about 1620 lines, over the ~500 guideline: 803 are the shader port (it only works whole), about 220 are tests.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/3763 **Author:** [@spidercraft](https://github.com/spidercraft) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fsr-frame-interpolation` --- ### 📝 Commits (4) - [`572c5c4`](https://github.com/horizon-rust/horizon/commit/572c5c46640fb98f8495a3f3551b4bc97a39efe4) FSR 3.1 frame interpolation, ported to WGSL (frame generation 2/3) - [`c1ba8b5`](https://github.com/horizon-rust/horizon/commit/c1ba8b5e66da253ce757c9f1fb21a66031e56aee) cargo fmt - [`3466915`](https://github.com/horizon-rust/horizon/commit/3466915d7738917935e90715184e3aeab5e0f9ce) Merge origin/main into fsr-frame-interpolation - [`58b2c98`](https://github.com/horizon-rust/horizon/commit/58b2c98d35e4ea011d2ea0758f3229edd3097bff) frame_gen: size the optical flow field as OpticalFlow sizes its vectors (div_ceil) ### 📊 Changes **4 files changed** (+1619 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `THIRD_PARTY_NOTICES.md` (+5 -4) 📝 `crates/horizon-client-render/src/gfx/frame_gen.rs` (+5 -3) ➕ `crates/horizon-client-render/src/gfx/frame_gen/interpolation.rs` (+806 -0) ➕ `crates/horizon-client-render/src/gfx/frame_gen/interpolation.wgsl` (+803 -0) </details> ### 📄 Description > 🤖 Opened by Claude Code. **Frame generation, part 2 of 3.** This PR: the frame interpolation. It is built on #3762 (the optical flow, part 1: merge it first; this branch contains it, so review this PR's own commit). Next: #3764 (the setting that runs both). Toward #2922. ## What it is AMD FidelityFX SDK 1.1.4's frame interpolation (FSR 3.1's frame generation, MIT), ported to WGSL in `gfx/frame_gen/interpolation.{rs,wgsl}`: the frame halfway between the previous real frame and this one. The license heads the WGSL file; `THIRD_PARTY_NOTICES.md` credits both ports. Still unused by the game (`#[allow(dead_code)]` until part 3). Players see no change (`skip-release`). ## How it works (`ffxFrameInterpolationPrepare` then `ffxFrameInterpolationDispatch`, same order) 1. **Prepare:** dilate the depth (nearest of 3×3, reversed depth) and the motion vectors; estimate the previous frame's depth by splatting this one's along them. 2. **Setup:** count the frames since the last reset or scene change. 3. Estimate the made frame's depth; splat the game's motion vectors to the made frame's pixels (atomic maximum of packed priority and half-vector, with AMD's secondary vectors); fill the field's holes from a pyramid of it. 4. Splat the optical flow's vectors the same way, after AMD's 3×3 weighting. 5. **Disocclusion:** mask what each frame can't see from the made frame's position. 6. **Interpolate:** blend the two frames along the game field, then along the optical flow, weighted by how well each one's colours match (AMD's rule: the game's vectors win unless they clearly match worse). The first 10 frames after a reset use the game's only. 7. **Inpaint** the holes from a pyramid of the result; keep this frame as the next one's previous. ## Where it differs from AMD's - **Motion vectors:** Horizon has no motion vector buffer, so `prepare` computes the camera's from the depth and this frame's unjittered clip space to the last (the TAA reprojection), with the jitter removed. What moves on its own relies on the optical flow. (FSR3's prepare takes the game's vectors instead.) - Textures AMD updates with image atomics (vector fields, estimated depths) are storage buffers of `atomic<u32>`; WGSL has no image atomics. - Both SPD pyramids are a pass per level, with AMD's reductions, and each has its own texture (AMD aliases one). - The interpolation writes one `rgba16float` texture and the inpainting another (`rgba16float` can't be `read_write` everywhere). - f16 packing of the vector fields is integer arithmetic: `pack2x16float` needs a capability some GPUs lack. - No HUD-less pass, no distortion field, the whole screen as the interpolation rect, SDR input (Horizon's swapchain values), inverted finite depth. - Places where AMD divides by zero and relies on the hardware's `max(0, NaN) = 0` are guarded up front, with the same result. ## Checked On a device with WebGPU's default limits, RTX 5090 (Vulkan, Linux); the GPU tests skip without a GPU: - `shader_validates`: naga validates the WGSL with no optional capabilities. - `moves_the_view_halfway_with_the_camera`: frames of a camera panning 16 pixels a frame; the made frame's error against the true halfway frame is under a quarter of either real frame's. - `moves_what_the_optical_flow_follows_halfway`: a still camera and a picture moving (16, 8); the optical flow carries the made frame halfway, error under a third of either real frame's (where the still camera's two colours happen to match, AMD's rule keeps the game's vectors, as designed). - Part 1's tests still pass; clippy (`-D warnings`) and rustfmt clean. `tools/pr_ready.py` wasn't run on this branch; part 3 lists what the whole stack was tested with. **Size:** about 1620 lines, over the ~500 guideline: 803 are the shader port (it only works whole), about 220 are tests. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:10:56 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#5202
No description provided.