diff --git a/docs/perf/speed-log.md b/docs/perf/speed-log.md index 4da62da..ada66fd 100644 --- a/docs/perf/speed-log.md +++ b/docs/perf/speed-log.md @@ -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 @@ -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`. diff --git a/go.mod b/go.mod index 2540e10..0e93cc7 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/go-avkit/vpx go 1.27.4 + +require github.com/go-videodsp/kernels v0.22.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..f39949f --- /dev/null +++ b/go.sum @@ -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= diff --git a/internal/vp9/dsp/lf_kernels_amd64.go b/internal/vp9/dsp/lf_kernels_amd64.go new file mode 100644 index 0000000..1314d56 --- /dev/null +++ b/internal/vp9/dsp/lf_kernels_amd64.go @@ -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 +} diff --git a/internal/vp9/dsp/lf_kernels_other.go b/internal/vp9/dsp/lf_kernels_other.go new file mode 100644 index 0000000..82c6a68 --- /dev/null +++ b/internal/vp9/dsp/lf_kernels_other.go @@ -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 } diff --git a/internal/vp9/dsp/loopfilter_thr.go b/internal/vp9/dsp/loopfilter_thr.go index fea78c9..b039a5d 100644 --- a/internal/vp9/dsp/loopfilter_thr.go +++ b/internal/vp9/dsp/loopfilter_thr.go @@ -33,6 +33,9 @@ func vpxLpfVertical4(plane []uint8, s, pitch int, blimit, limit, thresh uint8) { func vpxLpfHorizontal4Dual(plane []uint8, s, pitch int, blimit0, limit0, thresh0, blimit1, limit1, thresh1 uint8, ) { + if lfKernelH4Dual(plane, s, pitch, blimit0, limit0, thresh0, blimit1, limit1, thresh1) { + return + } if pixel.LoopFilter(plane, s, pitch, 1, 8, int(blimit0), int(limit0), int(thresh0), 4) { pixel.LoopFilter(plane, s+8*1, pitch, 1, 8, int(blimit1), int(limit1), int(thresh1), 4) return @@ -44,6 +47,9 @@ func vpxLpfHorizontal4Dual(plane []uint8, s, pitch int, func vpxLpfVertical4Dual(plane []uint8, s, pitch int, blimit0, limit0, thresh0, blimit1, limit1, thresh1 uint8, ) { + if lfKernelV4Dual(plane, s, pitch, blimit0, limit0, thresh0, blimit1, limit1, thresh1) { + return + } if pixel.LoopFilter(plane, s, 1, pitch, 8, int(blimit0), int(limit0), int(thresh0), 4) { pixel.LoopFilter(plane, s+8*pitch, 1, pitch, 8, int(blimit1), int(limit1), int(thresh1), 4) return @@ -71,6 +77,9 @@ func vpxLpfVertical8(plane []uint8, s, pitch int, blimit, limit, thresh uint8) { func vpxLpfHorizontal8Dual(plane []uint8, s, pitch int, blimit0, limit0, thresh0, blimit1, limit1, thresh1 uint8, ) { + if lfKernelH8Dual(plane, s, pitch, blimit0, limit0, thresh0, blimit1, limit1, thresh1) { + return + } if blimit0 == blimit1 && limit0 == limit1 && thresh0 == thresh1 && pixel.LoopFilter(plane, s, pitch, 1, 16, int(blimit0), int(limit0), int(thresh0), 8) { return @@ -86,6 +95,9 @@ func vpxLpfHorizontal8Dual(plane []uint8, s, pitch int, func vpxLpfVertical8Dual(plane []uint8, s, pitch int, blimit0, limit0, thresh0, blimit1, limit1, thresh1 uint8, ) { + if lfKernelV8Dual(plane, s, pitch, blimit0, limit0, thresh0, blimit1, limit1, thresh1) { + return + } if blimit0 == blimit1 && limit0 == limit1 && thresh0 == thresh1 && pixel.LoopFilter(plane, s, 1, pitch, 16, int(blimit0), int(limit0), int(thresh0), 8) { return @@ -107,6 +119,9 @@ func vpxLpfHorizontal16(plane []uint8, s, pitch int, blimit, limit, thresh uint8 } func vpxLpfHorizontal16Dual(plane []uint8, s, pitch int, blimit, limit, thresh uint8) { + if lfKernelH16Dual(plane, s, pitch, blimit, limit, thresh) { + return + } if pixel.LoopFilter(plane, s, pitch, 1, 16, int(blimit), int(limit), int(thresh), 16) { return } @@ -123,6 +138,9 @@ func vpxLpfVertical16(plane []uint8, s, pitch int, blimit, limit, thresh uint8) } func vpxLpfVertical16Dual(plane []uint8, s, pitch int, blimit, limit, thresh uint8) { + if lfKernelV16Dual(plane, s, pitch, blimit, limit, thresh) { + return + } if pixel.LoopFilter(plane, s, 1, pitch, 16, int(blimit), int(limit), int(thresh), 16) { return } diff --git a/tools/portgovpx/main.go b/tools/portgovpx/main.go index d973993..f8f50ae 100644 --- a/tools/portgovpx/main.go +++ b/tools/portgovpx/main.go @@ -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.