Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions content/en/upscale.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ Against a float64 transliteration of the reference, the float32 pipeline stays w
the compiler fuses multiply-adds. The vector rows (below) are tested against the scalar code
under the same bound.

v0.25.0 makes the oracle public (`upscale/fsrref`) and measures against it: the worst error is
5.7e-6 on the oracle corpus, on the CPU and on both GPU back ends. On noise of at most 3 levels
of 255, 0.9 % of samples are outside `ErrorBound`, by up to 4.7e-3 (`TestOracleLowContrast`);
the cause is not established.

## Quality {#quality}

Measured with ffmpeg 6.1.1's `psnr` and `ssim` filters. The ground truth is a real frame,
Expand Down Expand Up @@ -54,10 +59,51 @@ portable Go 1.27 `simd` package (AVX2 and AVX-512 on amd64, NEON on arm64); it i
start-up, so the default build is unchanged. v0.23.0 gathers each source row's taps once
(not once per output pixel), computes the edge analysis once per source pixel and packs
RGBA with vectors; v0.24.0 gathers with AVX-512 permutes, converts YCbCr inline and hoists
the per-row broadcasts. It is still about 13 times slower than ffmpeg's hand-written scaler,
**an open defect**: FSR weighs 12 taps per pixel with weights that depend on the local edge,
about 17 times the arithmetic of ffmpeg's separable 7-tap lanczos, and the EASU arithmetic,
RCAS and the input conversion take most of what is left. Today `upscale` suits stills, offline work and small frames, not real-time 1080p.
the per-row broadcasts.

### Several cores, v0.25.0 {#multicore}

v0.25.0 adds `upscale.NewScaler(opt)` and `(*Scaler).Upscale(dst, src)`, which writes into a
caller-owned `*image.RGBA`. `Options.Workers` splits the frame into bands of rows, one goroutine
each (0 = `GOMAXPROCS`, at most `MaxWorkers` = 64); the bytes are the same for every worker count.
A `dst` whose buffer does not hold its rectangle, or whose stride is under a row, is refused
with `ErrDst`. With one worker a warm frame allocates nothing; with several, `-benchmem`
reports 0 allocs/op and 1 to 522 B/op, an allocation every few frames whose origin is not traced.

1280x720 YCbCr 4:2:0 to 1920x1080 RGBA, sharpness 0.2, `GOEXPERIMENT=simd` (AVX-512), Ryzen 9 7950X, Go 1.27.4,
milliseconds per frame:

| Threads | `upscale` v0.24.0 | `upscale` v0.25.0 | ffmpeg 6.1.1 lanczos |
|---|---|---|---|
| 1 | 37 | 28.7 to 29.3 | 2.77 |
| 2 | | 14.5 | |
| 4 | | 7.5 | |
| 8 | | 5.4 | 0.20 |
| 16 | | 3.6 | 0.20 |

The ffmpeg figures for several threads are coarse (a difference of about 0.1 s over 300 frames),
an order of magnitude and not a precise figure. FSR is still **10.4 times slower** than ffmpeg's
lanczos on one core and about **18 times** on 16 threads. This is the remaining gap
([go-avkit/avkit#141](https://github.com/go-avkit/avkit/issues/141)), and a CPU is not expected
to close it: a separable filter applies fixed taps along each axis, where EASU computes for
every output pixel an edge direction from twelve taps, then twelve rotated, anisotropic weights
and a division. It is still an open defect. With 16 workers a 1080p frame takes 3.6 ms, which
fits a 60 Hz frame (16.7 ms); on one core it does not.

The v0.25.0 one-core gain comes from resolving the taps once per output row, factoring the
rotation out of the twelve tap offsets and vectorising the luma and the last pixels of an RCAS row.
Sample positions are now computed in integers (`fsrref.Phase`), which costs 10 % on one core
(26.2 ms before it) for a reason not established; output pixels at positions that were on an
integer in float differ from v0.24.0.

### GPU, not released yet {#gpu}

A Vulkan compute path (module `upscale/gpu`, branch `upscale-gpu`) is not released yet and is
measured on a branch only: 5.77 to 5.87 ms per frame on a RADV NAVI32 including upload and
readback, about 2.0 ms for the dispatch alone. Metal was checked for correctness only, not timed.

Today `upscale` suits stills, offline work and small frames on one core, and 60 Hz 1080p only
with many workers.

## Reproduce {#reproduce}

Expand Down
Loading