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
12 changes: 11 additions & 1 deletion docs/perf/speed-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@ 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 |

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

The loop-filter row was measured at load 2.8 to 3.1 on core 11, six interleaved rounds against a
`v0.2.0` test binary; an earlier run on core 5 at load 3.2 had a noisy v0.2.0 side (7.2 to 14 ms
per frame) and is not used. Kernel speed against the scalar reference, per 16-line edge on Zen 4
(`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.

## Tried and not kept

- VP8 six-tap horizontal through the same kernel (taps padded with two zeros): 5131 against
Expand All @@ -26,4 +33,7 @@ libvpx single core, same clips (M0 protocol): 2623, 2610, 2427.
(`Image`), and the copy of `copyVP9ImageToPublic` runs only with `ByteAlignment` or
post-processing. The copy the design means is made by go-avkit/decode, and the copy/alloc stage
is 1.7 % (VP9) and 3.1 % (VP8) of the M0 profile, so F1 is worth at most that.
- Loop filter (K1) and the move of the convolution into `go-videodsp/kernels`.
- 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`.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/go-avkit/vpx

go 1.27.4

require github.com/go-videodsp/kernels v0.22.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +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=
59 changes: 59 additions & 0 deletions internal/vp9/dsp/lf_kernels_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//go:build amd64

package dsp

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

// The sixteen-line loop filters of go-videodsp/kernels (AVX2). Each reports
// whether it ran; false sends the caller to the paths it had before.

func lfKernelH4Dual(plane []uint8, s, pitch int, b0, l0, h0, b1, l1, h1 uint8) bool {
if !cpu.HasAVX2 {
return false
}
lf.VP9LpfH4Dual(plane, s, pitch, b0, l0, h0, b1, l1, h1)
return true
}

func lfKernelV4Dual(plane []uint8, s, pitch int, b0, l0, h0, b1, l1, h1 uint8) bool {
if !cpu.HasAVX2 {
return false
}
lf.VP9LpfV4Dual(plane, s, pitch, b0, l0, h0, b1, l1, h1)
return true
}

func lfKernelH8Dual(plane []uint8, s, pitch int, b0, l0, h0, b1, l1, h1 uint8) bool {
if !cpu.HasAVX2 {
return false
}
lf.VP9LpfH8Dual(plane, s, pitch, b0, l0, h0, b1, l1, h1)
return true
}

func lfKernelV8Dual(plane []uint8, s, pitch int, b0, l0, h0, b1, l1, h1 uint8) bool {
if !cpu.HasAVX2 {
return false
}
lf.VP9LpfV8Dual(plane, s, pitch, b0, l0, h0, b1, l1, h1)
return true
}

func lfKernelH16Dual(plane []uint8, s, pitch int, b, l, h uint8) bool {
if !cpu.HasAVX2 {
return false
}
lf.VP9LpfH16Dual(plane, s, pitch, b, l, h)
return true
}

func lfKernelV16Dual(plane []uint8, s, pitch int, b, l, h uint8) bool {
if !cpu.HasAVX2 {
return false
}
lf.VP9LpfV16Dual(plane, s, pitch, b, l, h)
return true
}
12 changes: 12 additions & 0 deletions internal/vp9/dsp/lf_kernels_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//go:build !amd64

package dsp

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

func lfKernelH4Dual(plane []uint8, s, pitch int, b0, l0, h0, b1, l1, h1 uint8) bool { return false }
func lfKernelV4Dual(plane []uint8, s, pitch int, b0, l0, h0, b1, l1, h1 uint8) bool { return false }
func lfKernelH8Dual(plane []uint8, s, pitch int, b0, l0, h0, b1, l1, h1 uint8) bool { return false }
func lfKernelV8Dual(plane []uint8, s, pitch int, b0, l0, h0, b1, l1, h1 uint8) bool { return false }
func lfKernelH16Dual(plane []uint8, s, pitch int, b, l, h uint8) bool { return false }
func lfKernelV16Dual(plane []uint8, s, pitch int, b, l, h uint8) bool { return false }
18 changes: 18 additions & 0 deletions internal/vp9/dsp/loopfilter_thr.go

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

22 changes: 22 additions & 0 deletions tools/portgovpx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,28 @@ var Patches = map[string][]Patch{
"\t// Changed from govpx v0.5.3, whose `v >> 32` does not compile where int is 32 bits.\n\treturn 1 << bits.Len(uint(v-1))\n"},
{"import (\n\t\"reflect\"", "import (\n\t\"math/bits\"\n\t\"reflect\""},
},
// The VP9 loop filters of the amd64 port come from go-videodsp/kernels.
"internal/vp9/dsp/loopfilter_thr.go": lfKernelPatches(),
}

// lfKernelPatches makes the six sixteen-line loop filters try the AVX2 kernels
// of go-videodsp/kernels first (internal/vp9/dsp/lf_kernels_*.go), keeping the
// code they had as the fallback.
func lfKernelPatches() []Patch {
two := "blimit0, limit0, thresh0, blimit1, limit1, thresh1"
one := "blimit, limit, thresh"
call := func(name, args string) string {
return "\tif " + name + "(plane, s, pitch, " + args + ") {\n\t\treturn\n\t}\n"
}
add := func(name, args, old string) Patch { return Patch{old, call(name, args) + old} }
return []Patch{
add("lfKernelH4Dual", two, "\tif pixel.LoopFilter(plane, s, pitch, 1, 8, int(blimit0), int(limit0), int(thresh0), 4) {\n\t\tpixel.LoopFilter(plane, s+8*1,"),
add("lfKernelV4Dual", two, "\tif pixel.LoopFilter(plane, s, 1, pitch, 8, int(blimit0), int(limit0), int(thresh0), 4) {\n\t\tpixel.LoopFilter(plane, s+8*pitch,"),
add("lfKernelH8Dual", two, "\tif blimit0 == blimit1 && limit0 == limit1 && thresh0 == thresh1 &&\n\t\tpixel.LoopFilter(plane, s, pitch, 1, 16,"),
add("lfKernelV8Dual", two, "\tif blimit0 == blimit1 && limit0 == limit1 && thresh0 == thresh1 &&\n\t\tpixel.LoopFilter(plane, s, 1, pitch, 16,"),
add("lfKernelH16Dual", one, "\tif pixel.LoopFilter(plane, s, pitch, 1, 16, int(blimit), int(limit), int(thresh), 16) {"),
add("lfKernelV16Dual", one, "\tif pixel.LoopFilter(plane, s, 1, pitch, 16, int(blimit), int(limit), int(thresh), 16) {"),
}
}

// ApplyPatches applies the patches of the source file rel to out.
Expand Down
Loading