[PR #3762] [MERGED] FSR 3.1 optical flow, ported to WGSL (frame generation 1/3) #5201

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/3762
Author: @spidercraft
Created: 10/29/2026
Status: ✅ Merged
Merged: 10/30/2026
Merged by: @ludovic111

Base: main ← Head: fsr-optical-flow


📝 Commits (3)

  • a917633 FSR 3.1 optical flow, ported to WGSL (frame generation 1/3)
  • 0503ee0 gfx: rustfmt's order for the frame_gen module
  • 7857967 Optical flow: AMD's notice on the Rust side too, and the SDK commit

📊 Changes

5 files changed (+1209 additions, -0 deletions)

View changed files

📝 THIRD_PARTY_NOTICES.md (+11 -0)
📝 crates/horizon-client-render/src/gfx.rs (+1 -0)
➕ crates/horizon-client-render/src/gfx/frame_gen.rs (+7 -0)
➕ crates/horizon-client-render/src/gfx/frame_gen/optical_flow.rs (+653 -0)
➕ crates/horizon-client-render/src/gfx/frame_gen/optical_flow.wgsl (+537 -0)

📄 Description

🤖 Opened by Claude Code.

Frame generation, part 1 of 3. This PR: the optical flow. Next: #3763 (the frame interpolation, built on this one), then #3764 (the setting that runs both). Each PR's branch contains the ones before it, so review this PR's own commit; merge them in order. Toward #2922.

What it is

AMD FidelityFX SDK 1.1.4's optical flow (the half of FSR 3.1 frame generation that finds how the picture moved between two frames), ported to WGSL in gfx/frame_gen/optical_flow.{rs,wgsl}. AMD's shader source is MIT; the license heads the WGSL file and THIRD_PARTY_NOTICES.md credits it. No AMD binary is used, so it runs on every GPU wgpu does.

The game doesn't use it yet: the module is #[allow(dead_code)] until part 3 wires it in. Players see no change (skip-release).

How it works (as in ffx_opticalflow.cpp)

  • Luma at the display size and 6 halvings, ping-ponged between frames.
  • A histogram of the luma in 3×3 screen regions, and its divergence from the last frame's: the scene change detection.
  • From the coarsest of 7 levels down: an 8×8 block search over ±8 pixels seeded by the level above, AMD's 3×3 filter (the vector nearest all its neighbours), and a scale to the next level.
  • Output: one vector per 8×8 block (Rg32Sint, AMD's R16G16_SINT values) and the scene change buffer (AMD's 3-texel R32_UINT).

Where it differs from AMD's, all forced by WGSL

  • Luma levels are R32Float holding AMD's 8-bit integers (WebGPU has no r8uint storage); loads truncate to the same values.
  • Wave sums and minimums are workgroup atomics; the reductions AMD leaves to a wave's lockstep have barriers.
  • SPD's single-pass luma pyramid is one dispatch per level, with the same 2×2 averages.
  • The scene change textures are storage buffers; the search reads its prediction from one texture and writes another (rg32sint can't be read_write everywhere).
  • The luma textures aren't cleared on a reset: AMD's first 6 frames after one report a scene change and no motion anyway, and rewrite them.

Checked

  • shader_validates: naga parses and validates the WGSL with no optional capabilities.
  • finds_a_shift_and_a_scene_change, on a device with WebGPU's default limits: a noise frame moved by (16, 8) pixels reads (-16, -8) in over 90% of interior blocks with no scene change; a much darker frame then sets the scene change bit and zeroes the vectors. Ran on an RTX 5090 (Vulkan, Linux); it skips without a GPU.
  • cargo clippy -p horizon-client-render --all-targets -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: 1184 lines, over the ~500 guideline: 537 are the shader port (it only works whole), about 270 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/3762 **Author:** [@spidercraft](https://github.com/spidercraft) **Created:** 10/29/2026 **Status:** ✅ Merged **Merged:** 10/30/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fsr-optical-flow` --- ### 📝 Commits (3) - [`a917633`](https://github.com/horizon-rust/horizon/commit/a91763379f4c26106576028061306fd057f52500) FSR 3.1 optical flow, ported to WGSL (frame generation 1/3) - [`0503ee0`](https://github.com/horizon-rust/horizon/commit/0503ee0cbf23a42865ca4a712c2cf950f4401705) gfx: rustfmt's order for the frame_gen module - [`7857967`](https://github.com/horizon-rust/horizon/commit/7857967863b90c257a94e4b918b062de5d441740) Optical flow: AMD's notice on the Rust side too, and the SDK commit ### 📊 Changes **5 files changed** (+1209 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `THIRD_PARTY_NOTICES.md` (+11 -0) 📝 `crates/horizon-client-render/src/gfx.rs` (+1 -0) ➕ `crates/horizon-client-render/src/gfx/frame_gen.rs` (+7 -0) ➕ `crates/horizon-client-render/src/gfx/frame_gen/optical_flow.rs` (+653 -0) ➕ `crates/horizon-client-render/src/gfx/frame_gen/optical_flow.wgsl` (+537 -0) </details> ### 📄 Description > 🤖 Opened by Claude Code. **Frame generation, part 1 of 3.** This PR: the optical flow. Next: #3763 (the frame interpolation, built on this one), then #3764 (the setting that runs both). Each PR's branch contains the ones before it, so review this PR's own commit; merge them in order. Toward #2922. ## What it is AMD FidelityFX SDK 1.1.4's optical flow (the half of FSR 3.1 frame generation that finds how the picture moved between two frames), ported to WGSL in `gfx/frame_gen/optical_flow.{rs,wgsl}`. AMD's shader source is MIT; the license heads the WGSL file and `THIRD_PARTY_NOTICES.md` credits it. No AMD binary is used, so it runs on every GPU wgpu does. The game doesn't use it yet: the module is `#[allow(dead_code)]` until part 3 wires it in. Players see no change (`skip-release`). ## How it works (as in `ffx_opticalflow.cpp`) - Luma at the display size and 6 halvings, ping-ponged between frames. - A histogram of the luma in 3×3 screen regions, and its divergence from the last frame's: the scene change detection. - From the coarsest of 7 levels down: an 8×8 block search over ±8 pixels seeded by the level above, AMD's 3×3 filter (the vector nearest all its neighbours), and a scale to the next level. - Output: one vector per 8×8 block (`Rg32Sint`, AMD's `R16G16_SINT` values) and the scene change buffer (AMD's 3-texel `R32_UINT`). ## Where it differs from AMD's, all forced by WGSL - Luma levels are `R32Float` holding AMD's 8-bit integers (WebGPU has no `r8uint` storage); loads truncate to the same values. - Wave sums and minimums are workgroup atomics; the reductions AMD leaves to a wave's lockstep have barriers. - SPD's single-pass luma pyramid is one dispatch per level, with the same 2×2 averages. - The scene change textures are storage buffers; the search reads its prediction from one texture and writes another (`rg32sint` can't be `read_write` everywhere). - The luma textures aren't cleared on a reset: AMD's first 6 frames after one report a scene change and no motion anyway, and rewrite them. ## Checked - `shader_validates`: naga parses and validates the WGSL with no optional capabilities. - `finds_a_shift_and_a_scene_change`, on a device with WebGPU's default limits: a noise frame moved by (16, 8) pixels reads (-16, -8) in over 90% of interior blocks with no scene change; a much darker frame then sets the scene change bit and zeroes the vectors. Ran on an RTX 5090 (Vulkan, Linux); it skips without a GPU. - `cargo clippy -p horizon-client-render --all-targets -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:** 1184 lines, over the ~500 guideline: 537 are the shader port (it only works whole), about 270 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#5201
No description provided.