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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ Changes from govpx v0.5.3 (each is also noted in the file): `internal/vpx/buffer
rounds up to a power of two with `math/bits`, because govpx's `v >> 32` does not compile
for 32-bit targets.

Since v0.3.0 the amd64 hot loops come from
[go-videodsp/kernels](https://github.com/go-videodsp/kernels) (AVX2, chosen at run time by
`cpu.HasAVX2`, the previous code as the fallback): the VP9 loop filters and 8-tap convolutions, and
since v0.5.0 the VP8 loop filters and six-tap/bilinear predictors. On a Ryzen 9 7950X, one core,
crowd_run 1080p, VP8 decodes in 3437 µs per frame against 4942 for v0.4.0 (1.44x); the table is in
[docs/perf/speed-log.md](docs/perf/speed-log.md).

## Tests

- `LIBVPX_VECTORS_DIR=DIR go test ./...` decodes libvpx's 376 decoder vectors and
Expand Down
13 changes: 12 additions & 1 deletion docs/perf/speed-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ crowd_run 1080p 300-frame clips, median µs per frame.
| 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 |
| VP8 loop filters, AVX2 (`go-videodsp/kernels` v0.24.0 `lf`: inner, macroblock and simple edges, 16 luma lines or 2 x 8 chroma lines per call; they replace the fused macroblock paths of `internal/pixel`) | not affected | not affected | 4327 (1.142x, v0.4.0 4942 in the same run) |
| VP8 six-tap and bilinear prediction, AVX2 (`go-videodsp/kernels` v0.25.0 `mc`: widths 4, 8, 16) | not affected | not affected | 3437 (1.438x, v0.4.0 4942) |

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

Expand All @@ -26,6 +28,15 @@ Zen 4 (`go-videodsp/kernels` `docs/bench/vp9-conv-zen4-avx2.txt`): H and V 2.5x
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.

The two VP8 rows were measured on core 11 at load 3 to 4, seven interleaved rounds of the
`v0.4.0` test binary, the loop-filter-only build and the full build, `BenchmarkDecodeClip` on the
VP8 crowd_run clip (best of seven: 4926, 4321, 3427). The loop filters take 615 µs off a frame and
the predictors a further 890 µs; the vector tests pass 376/376 with and without
`GOEXPERIMENT=simd`, 0 and 4 threads. VP9 on its 1-tile clip is unchanged (2463 against 2482 µs, noise). The VP8 decoder is now about 1.5
times libvpx's 2281 µs per frame. Not wired: the simple-filter fused paths of the decoder
(`pixel.LoopFilterSimple*`) still run first, as the clip uses the normal filter and the two were
not compared.

## Tried and not kept

- VP8 six-tap horizontal through the same kernel (taps padded with two zeros): 5131 against
Expand All @@ -43,7 +54,7 @@ pass and the two averaging forms are new. The split of the gain between them was
is 1.7 % (VP9) and 3.1 % (VP8) of the M0 profile, so F1 is worth at most that.
- 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.
kernels are an open issue in `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
Expand Down
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.23.0
require github.com/go-videodsp/kernels v0.25.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.23.0 h1:VoDJQSOTnHef9ZAWPy/BgZ9LYZLNSn3O86CCVTjJnCU=
github.com/go-videodsp/kernels v0.23.0/go.mod h1:+nQCn5NvYhjT8DtUqSplgir5dB4D66rqiGd8R3fimBE=
github.com/go-videodsp/kernels v0.25.0 h1:vXHqqShm+MDgwGG+eI2rXFK07l9T9x1yn90HDRZ8ByY=
github.com/go-videodsp/kernels v0.25.0/go.mod h1:+nQCn5NvYhjT8DtUqSplgir5dB4D66rqiGd8R3fimBE=
10 changes: 10 additions & 0 deletions internal/vp8/decoder/lf_kernels_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//go:build amd64

package decoder

import "github.com/go-videodsp/kernels/cpu"

// lfKernels is true where the loop-filter edges of internal/vp8/dsp run the
// AVX2 kernels of go-videodsp/kernels, which the per-edge calls use in place of
// the fused macroblock paths of internal/pixel.
var lfKernels = cpu.HasAVX2
6 changes: 6 additions & 0 deletions internal/vp8/decoder/lf_kernels_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//go:build !amd64

package decoder

// Without the AVX2 kernels the fused macroblock paths stay.
const lfKernels = false
4 changes: 2 additions & 2 deletions internal/vp8/decoder/loopfilter.go

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

138 changes: 138 additions & 0 deletions internal/vp8/dsp/kernels_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
//go:build amd64

package dsp

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

// The VP8 loop filters (lf.VP8*) and sub-pixel predictors (mc.VP8*) of
// go-videodsp/kernels, AVX2. Each function reports whether it ran; false sends
// the caller to the paths it had before. The kernels filter sixteen luma lines
// or two times eight chroma lines per call, so a luma edge of count 2 is the
// only one they take; s starts at p3 of the edge (p1 for the simple filter), as
// the dispatch functions of loopfilter_dispatch_other.go expect.

func lfKernelInnerH(s []byte, stride int, blimit, limit, thresh byte, count int) bool {
if !cpu.HasAVX2 || count != 2 {
return false
}
lf.VP8LoopFilterH(s, 4*stride, stride, blimit, limit, thresh)
return true
}

func lfKernelInnerV(s []byte, stride int, blimit, limit, thresh byte, count int) bool {
if !cpu.HasAVX2 || count != 2 {
return false
}
lf.VP8LoopFilterV(s, 4, stride, blimit, limit, thresh)
return true
}

func lfKernelMBH(s []byte, stride int, blimit, limit, thresh byte, count int) bool {
if !cpu.HasAVX2 || count != 2 {
return false
}
lf.VP8MBLoopFilterH(s, 4*stride, stride, blimit, limit, thresh)
return true
}

func lfKernelMBV(s []byte, stride int, blimit, limit, thresh byte, count int) bool {
if !cpu.HasAVX2 || count != 2 {
return false
}
lf.VP8MBLoopFilterV(s, 4, stride, blimit, limit, thresh)
return true
}

// The three inner luma edges of a macroblock, at 4, 8 and 12 samples.

func lfKernelInnerEdgesYH(s []byte, stride int, blimit, limit, thresh byte) bool {
if !cpu.HasAVX2 {
return false
}
lf.VP8LoopFilterH(s, 4*stride, stride, blimit, limit, thresh)
lf.VP8LoopFilterH(s, 8*stride, stride, blimit, limit, thresh)
lf.VP8LoopFilterH(s, 12*stride, stride, blimit, limit, thresh)
return true
}

func lfKernelInnerEdgesYV(s []byte, stride int, blimit, limit, thresh byte) bool {
if !cpu.HasAVX2 {
return false
}
lf.VP8LoopFilterV(s, 4, stride, blimit, limit, thresh)
lf.VP8LoopFilterV(s, 8, stride, blimit, limit, thresh)
lf.VP8LoopFilterV(s, 12, stride, blimit, limit, thresh)
return true
}

func lfKernelInnerUVH(u, v []byte, stride int, blimit, limit, thresh byte) bool {
if !cpu.HasAVX2 {
return false
}
lf.VP8LoopFilterUVH(u, v, 4*stride, 4*stride, stride, blimit, limit, thresh)
return true
}

func lfKernelInnerUVV(u, v []byte, stride int, blimit, limit, thresh byte) bool {
if !cpu.HasAVX2 {
return false
}
lf.VP8LoopFilterUVV(u, v, 4, 4, stride, blimit, limit, thresh)
return true
}

func lfKernelMBUVH(u, v []byte, stride int, blimit, limit, thresh byte) bool {
if !cpu.HasAVX2 {
return false
}
lf.VP8MBLoopFilterUVH(u, v, 4*stride, 4*stride, stride, blimit, limit, thresh)
return true
}

func lfKernelMBUVV(u, v []byte, stride int, blimit, limit, thresh byte) bool {
if !cpu.HasAVX2 {
return false
}
lf.VP8MBLoopFilterUVV(u, v, 4, 4, stride, blimit, limit, thresh)
return true
}

func lfKernelSimpleH(s []byte, stride int, blimit byte) bool {
if !cpu.HasAVX2 {
return false
}
lf.VP8SimpleFilterH(s, 2*stride, stride, blimit)
return true
}

func lfKernelSimpleV(s []byte, stride int, blimit byte) bool {
if !cpu.HasAVX2 {
return false
}
lf.VP8SimpleFilterV(s, 2, stride, blimit)
return true
}

// sixTapKernel is the six-tap predictor of a w x h block; src starts two rows
// and two columns before the block, as for SixTapPredict16x16.
func sixTapKernel(src []byte, srcStride, xoffset, yoffset int, dst []byte, dstStride, w, h int) bool {
if !cpu.HasAVX2 {
return false
}
mc.VP8SixTap(dst, dstStride, src, 2*srcStride+2, srcStride, xoffset, yoffset, w, h)
return true
}

// bilinearKernel is the bilinear predictor of a w x h block; src starts at the
// block.
func bilinearKernel(src []byte, srcStride, xoffset, yoffset int, dst []byte, dstStride, w, h int) bool {
if !cpu.HasAVX2 {
return false
}
mc.VP8Bilinear(dst, dstStride, src, 0, srcStride, xoffset, yoffset, w, h)
return true
}
29 changes: 29 additions & 0 deletions internal/vp8/dsp/kernels_other.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//go:build !amd64

package dsp

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

func lfKernelInnerH(s []byte, stride int, blimit, limit, thresh byte, count int) bool { return false }
func lfKernelInnerV(s []byte, stride int, blimit, limit, thresh byte, count int) bool { return false }
func lfKernelMBH(s []byte, stride int, blimit, limit, thresh byte, count int) bool { return false }
func lfKernelMBV(s []byte, stride int, blimit, limit, thresh byte, count int) bool { return false }

func lfKernelInnerEdgesYH(s []byte, stride int, blimit, limit, thresh byte) bool { return false }
func lfKernelInnerEdgesYV(s []byte, stride int, blimit, limit, thresh byte) bool { return false }

func lfKernelInnerUVH(u, v []byte, stride int, blimit, limit, thresh byte) bool { return false }
func lfKernelInnerUVV(u, v []byte, stride int, blimit, limit, thresh byte) bool { return false }
func lfKernelMBUVH(u, v []byte, stride int, blimit, limit, thresh byte) bool { return false }
func lfKernelMBUVV(u, v []byte, stride int, blimit, limit, thresh byte) bool { return false }

func lfKernelSimpleH(s []byte, stride int, blimit byte) bool { return false }
func lfKernelSimpleV(s []byte, stride int, blimit byte) bool { return false }

func sixTapKernel(src []byte, srcStride, xoffset, yoffset int, dst []byte, dstStride, w, h int) bool {
return false
}

func bilinearKernel(src []byte, srcStride, xoffset, yoffset int, dst []byte, dstStride, w, h int) bool {
return false
}
36 changes: 36 additions & 0 deletions internal/vp8/dsp/loopfilter_dispatch_other.go

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

Loading
Loading