Skip to content
Merged
Show file tree
Hide file tree
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
17 changes: 16 additions & 1 deletion docs/perf/speed-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ crowd_run 1080p 300-frame clips, median µs per frame.
| v0.1.0 (M0) | 7210 | 7581 | 4969 |
| horizontal 8-tap with VPMADDUBSW (from govpx 43f826d8) | 6944 (1.038x) | 7304 (1.038x) | 4961 (1.002x) |
| VP9 loop filters, AVX2 (`go-videodsp/kernels` v0.22.0: 4, 8 and 16 wide, H and V, Dual edges) | 6090 (1.172x, v0.2.0 7136 in the same run) | 6151 (1.167x, v0.2.0 7180) | not run, VP8 does not use it |
| VP9 8-tap convolution, AVX2 (`go-videodsp/kernels` v0.23.0 `mc`: horizontal, vertical, and their averaging forms; the 2-D paths run through them) | 5332 (1.181x, v0.3.0 6296 in the same run) | 5373 (1.182x, v0.3.0 6351) | not run, VP8 does not use it |

libvpx single core, same clips (M0 protocol): 2623, 2610, 2427.

Expand All @@ -18,6 +19,13 @@ per frame) and is not used. Kernel speed against the scalar reference, per 16-li
(`go-videodsp/kernels` `docs/bench/vp9-lf-zen4-avx2.txt`): H4 8.5x, V4 5.8x, H8 7.7x, V8 5.5x,
H16 7.8x, V16 5.4x. The decoder is still about 2.3 times libvpx's time per frame.

The convolution row was measured on core 14 at load 2.0 to 2.6, six interleaved rounds against the
`v0.3.0` test binary, `BenchmarkDecodeClip`. Kernel speed against the scalar reference per block on
Zen 4 (`go-videodsp/kernels` `docs/bench/vp9-conv-zen4-avx2.txt`): H and V 2.5x (4x4), 8x (8x8),
24x (16x16), 67x (32x32), 88x (64x64); 2-D 64x64 61x. The 752 libvpx vectors (both test
functions) pass. The horizontal kernel is tried before the `VPMADDUBSW` one of M1; the vertical
pass and the two averaging forms are new. The split of the gain between them was not measured.

## Tried and not kept

- VP8 six-tap horizontal through the same kernel (taps padded with two zeros): 5131 against
Expand All @@ -36,4 +44,11 @@ H16 7.8x, V16 5.4x. The decoder is still about 2.3 times libvpx's time per frame
- Loop filter (K1), the parts left: the single-edge `Thr` entry points (`vpxLpf*4/8/16`, one 8-line
edge) and the high-bit-depth paths still use the scalar or `pixel.LoopFilter` code; the NEON
kernels are an open issue in `go-videodsp/kernels`. The VP8 filters are untouched.
- The move of the convolution into `go-videodsp/kernels`.
- Convolution, the parts left: the fused 2-D kernel `mc.VP9Convolve8` and `mc.VP9Convolve8Avg` is
not wired (their 71x64 stack intermediate is zeroed on every call, which costs about as much as
the passes at 4x4 and 8x8; the decoder's separate horizontal and vertical passes through its
pooled scratch already run the kernels). Fusing the averaging into the vertical pass of the
2-D average (horizontal into the scratch, `mc.VP9Convolve8AvgV` into dst, instead of the 2-D
result then `VpxConvolveAvg`) was tried and measured 1.004x on the 1-tile clip, under the 5 %
bar, and not kept. Widths other than 4, 8, 16 and the multiples of 32, filter rows the
exactness proof rejects, and non-unit steps keep the old code. NEON kernels: go-videodsp/kernels#42.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/go-avkit/vpx

go 1.27.4

require github.com/go-videodsp/kernels v0.22.0
require github.com/go-videodsp/kernels v0.23.0
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/go-videodsp/kernels v0.22.0 h1:YXfSOwzjUb0xsoG4SpS3kYXsJ/r5bcr1JEVG6wLLkq4=
github.com/go-videodsp/kernels v0.22.0/go.mod h1:+nQCn5NvYhjT8DtUqSplgir5dB4D66rqiGd8R3fimBE=
github.com/go-videodsp/kernels v0.23.0 h1:VoDJQSOTnHef9ZAWPy/BgZ9LYZLNSn3O86CCVTjJnCU=
github.com/go-videodsp/kernels v0.23.0/go.mod h1:+nQCn5NvYhjT8DtUqSplgir5dB4D66rqiGd8R3fimBE=
48 changes: 48 additions & 0 deletions internal/vp9/dsp/conv_kernels_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//go:build amd64

package dsp

import (
"github.com/go-videodsp/kernels/cpu"
"github.com/go-videodsp/kernels/mc"
)

// The step-16 8-tap convolutions of go-videodsp/kernels (AVX2). Each reports
// whether it ran; false sends the caller to the paths it had before. src[off]
// is the first-tap sample of the first output. The kernels take the widths 4,
// 8, 16 and the multiples of 32, and the filters they can prove exact (not the
// full-sample row, whose 128 does not fit a signed byte).

func convKernelWidth(w int) bool { return w == 4 || w == 8 || w == 16 || (w > 0 && w%32 == 0) }

func convKernelH(src []byte, ss int, dst []byte, ds int, taps *[8]int16, off, w, h int) bool {
if !cpu.HasAVX2 || !convKernelWidth(w) || taps[3] == 128 {
return false
}
mc.VP9Convolve8H(dst, ds, src, off, ss, taps, w, h)
return true
}

func convKernelV(src []byte, ss int, dst []byte, ds int, taps *[8]int16, off, w, h int) bool {
if !cpu.HasAVX2 || !convKernelWidth(w) || taps[3] == 128 {
return false
}
mc.VP9Convolve8V(dst, ds, src, off, ss, taps, w, h)
return true
}

func convKernelAvgH(src []byte, ss int, dst []byte, ds int, taps *[8]int16, off, w, h int) bool {
if !cpu.HasAVX2 || !convKernelWidth(w) || taps[3] == 128 {
return false
}
mc.VP9Convolve8AvgH(dst, ds, src, off, ss, taps, w, h)
return true
}

func convKernelAvgV(src []byte, ss int, dst []byte, ds int, taps *[8]int16, off, w, h int) bool {
if !cpu.HasAVX2 || !convKernelWidth(w) || taps[3] == 128 {
return false
}
mc.VP9Convolve8AvgV(dst, ds, src, off, ss, taps, w, h)
return true
}
18 changes: 18 additions & 0 deletions internal/vp9/dsp/conv_kernels_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//go:build !amd64

package dsp

// Without the AVX2 kernels the callers keep the paths they had before.

func convKernelH(src []byte, ss int, dst []byte, ds int, taps *[8]int16, off, w, h int) bool {
return false
}
func convKernelV(src []byte, ss int, dst []byte, ds int, taps *[8]int16, off, w, h int) bool {
return false
}
func convKernelAvgH(src []byte, ss int, dst []byte, ds int, taps *[8]int16, off, w, h int) bool {
return false
}
func convKernelAvgV(src []byte, ss int, dst []byte, ds int, taps *[8]int16, off, w, h int) bool {
return false
}
18 changes: 18 additions & 0 deletions internal/vp9/dsp/convolve.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions tools/portgovpx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,39 @@ var Patches = map[string][]Patch{
},
// The VP9 loop filters of the amd64 port come from go-videodsp/kernels.
"internal/vp9/dsp/loopfilter_thr.go": lfKernelPatches(),
// The step-16 8-tap convolutions of the amd64 port come from the same module.
"internal/vp9/dsp/convolve.go": convKernelPatches(),
}

// convKernelPatches makes the four one-direction convolutions try the AVX2
// kernels of go-videodsp/kernels first (internal/vp9/dsp/conv_kernels_*.go),
// keeping the code they had as the fallback. The 2-D forms go through them.
func convKernelPatches() []Patch {
const (
posH = "base := srcOffset - 3 + (x0Q4 >> 4)"
posV = "base := srcOffset + (y0Q4>>4)*srcStride - 3*srcStride"
)
// call is the kernel try, at the depth of the body of the step-16 branch.
call := func(name, filters, q4 string) string {
return "\t\tif " + name + "(src, srcStride, dst, dstStride, &" + filters + "[" + q4 + "&15], base, w, h) {\n\t\t\treturn\n\t\t}\n"
}
// before puts the try in front of the pixel.Filter line the branch ends with.
before := func(name, filters, q4, stride string) Patch {
old := "\t\tpixel.Filter(src[base:], srcStride, dst, dstStride, w, h, " + stride + ", " + filters + "[" + q4 + "&15][:])\n"
return Patch{old, call(name, filters, q4) + old}
}
// avg gives the averaging form, which had no step-16 branch, one.
avg := func(fn, name, filters, q4, pos string) Patch {
old := "func " + fn + "(src []byte, srcStride int, dst []byte, dstStride int,\n\t" + filters +
" *[tables.SubpelShifts][tables.SubpelTaps]int16,\n\t" + q4[:1] + "0Q4, " + q4[:1] + "StepQ4, w, h, srcOffset int,\n) {\n"
return Patch{old, old + "\tif " + q4[:1] + "StepQ4 == 16 && h > 0 {\n\t\t" + pos + "\n" + call(name, filters, q4) + "\t}\n"}
}
return []Patch{
before("convKernelH", "xFilters", "x0Q4", "1"),
before("convKernelV", "yFilters", "y0Q4", "srcStride"),
avg("convolveAvgHoriz", "convKernelAvgH", "xFilters", "x0Q4", posH),
avg("convolveAvgVert", "convKernelAvgV", "yFilters", "y0Q4", posV),
}
}

// lfKernelPatches makes the six sixteen-line loop filters try the AVX2 kernels
Expand Down
Loading