diff --git a/README.md b/README.md index 567e69f..0c6abc8 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docs/perf/speed-log.md b/docs/perf/speed-log.md index d6e11dd..df5dd8e 100644 --- a/docs/perf/speed-log.md +++ b/docs/perf/speed-log.md @@ -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. @@ -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 @@ -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 diff --git a/go.mod b/go.mod index 6647365..d9c46b5 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 2bb80d3..98f24f1 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/vp8/decoder/lf_kernels_amd64.go b/internal/vp8/decoder/lf_kernels_amd64.go new file mode 100644 index 0000000..6208cdf --- /dev/null +++ b/internal/vp8/decoder/lf_kernels_amd64.go @@ -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 diff --git a/internal/vp8/decoder/lf_kernels_other.go b/internal/vp8/decoder/lf_kernels_other.go new file mode 100644 index 0000000..f776e3e --- /dev/null +++ b/internal/vp8/decoder/lf_kernels_other.go @@ -0,0 +1,6 @@ +//go:build !amd64 + +package decoder + +// Without the AVX2 kernels the fused macroblock paths stay. +const lfKernels = false diff --git a/internal/vp8/decoder/loopfilter.go b/internal/vp8/decoder/loopfilter.go index 1cf31eb..ccc0b95 100644 --- a/internal/vp8/decoder/loopfilter.go +++ b/internal/vp8/decoder/loopfilter.go @@ -168,7 +168,7 @@ func applyNormalLoopFilterMB(img *common.Image, row int, col int, yOff int, uOff } } } else { - fusedV = macroInternalLoopFilter && col > 0 && !skipLF && pixel.LoopFilterMacroInternal16(img.Y[yOff-4:], 1, img.YStride, int(mblim), int(blim), int(lim), int(hev)) + fusedV = macroInternalLoopFilter && !lfKernels && col > 0 && !skipLF && pixel.LoopFilterMacroInternal16(img.Y[yOff-4:], 1, img.YStride, int(mblim), int(blim), int(lim), int(hev)) } if col > 0 { if !fusedV { @@ -193,7 +193,7 @@ func applyNormalLoopFilterMB(img *common.Image, row int, col int, yOff int, uOff } } } else { - fusedH = macroInternalLoopFilter && row > 0 && !skipLF && pixel.LoopFilterMacroInternal16(img.Y[yOff-4*img.YStride:], img.YStride, 1, int(mblim), int(blim), int(lim), int(hev)) + fusedH = macroInternalLoopFilter && !lfKernels && row > 0 && !skipLF && pixel.LoopFilterMacroInternal16(img.Y[yOff-4*img.YStride:], img.YStride, 1, int(mblim), int(blim), int(lim), int(hev)) } if row > 0 { if !fusedH { diff --git a/internal/vp8/dsp/kernels_amd64.go b/internal/vp8/dsp/kernels_amd64.go new file mode 100644 index 0000000..3e031ce --- /dev/null +++ b/internal/vp8/dsp/kernels_amd64.go @@ -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 +} diff --git a/internal/vp8/dsp/kernels_other.go b/internal/vp8/dsp/kernels_other.go new file mode 100644 index 0000000..a50d6e7 --- /dev/null +++ b/internal/vp8/dsp/kernels_other.go @@ -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 +} diff --git a/internal/vp8/dsp/loopfilter_dispatch_other.go b/internal/vp8/dsp/loopfilter_dispatch_other.go index c3d1da4..012d97f 100644 --- a/internal/vp8/dsp/loopfilter_dispatch_other.go +++ b/internal/vp8/dsp/loopfilter_dispatch_other.go @@ -15,6 +15,9 @@ import "github.com/go-avkit/vpx/internal/pixel" // Pure-Go fallback for VP8 loop-filter apply paths (libvpx v1.16.0 baseline). func loopFilterHorizontalEdgeDispatch(s []byte, stride int, blimit, limit, thresh byte, count int) { + if lfKernelInnerH(s, stride, blimit, limit, thresh, count) { + return + } if pixel.LoopFilter(s, 4*stride, stride, 1, count*8, int(blimit), int(limit), int(thresh), 4) { return } @@ -23,6 +26,9 @@ func loopFilterHorizontalEdgeDispatch(s []byte, stride int, blimit, limit, thres } func loopFilterHorizontalEdgesYDispatch(s []byte, stride int, blimit, limit, thresh byte) { + if lfKernelInnerEdgesYH(s, stride, blimit, limit, thresh) { + return + } if pixel.LoopFilterInternal16(s, stride, 1, int(blimit), int(limit), int(thresh)) { return } @@ -32,6 +38,9 @@ func loopFilterHorizontalEdgesYDispatch(s []byte, stride int, blimit, limit, thr } func loopFilterVerticalEdgeDispatch(s []byte, stride int, blimit, limit, thresh byte, count int) { + if lfKernelInnerV(s, stride, blimit, limit, thresh, count) { + return + } if pixel.LoopFilter(s, 4*1, 1, stride, count*8, int(blimit), int(limit), int(thresh), 4) { return } @@ -40,6 +49,9 @@ func loopFilterVerticalEdgeDispatch(s []byte, stride int, blimit, limit, thresh } func loopFilterVerticalEdgesYDispatch(s []byte, stride int, blimit, limit, thresh byte) { + if lfKernelInnerEdgesYV(s, stride, blimit, limit, thresh) { + return + } if pixel.LoopFilterInternal16(s, 1, stride, int(blimit), int(limit), int(thresh)) { return } @@ -49,6 +61,9 @@ func loopFilterVerticalEdgesYDispatch(s []byte, stride int, blimit, limit, thres } func loopFilterHorizontalEdgeUVDispatch(u []byte, v []byte, stride int, blimit, limit, thresh byte) { + if lfKernelInnerUVH(u, v, stride, blimit, limit, thresh) { + return + } if pixel.LoopFilterUV8(u, v, stride, 1, int(blimit), int(limit), int(thresh), 4) { return } @@ -57,6 +72,9 @@ func loopFilterHorizontalEdgeUVDispatch(u []byte, v []byte, stride int, blimit, } func loopFilterVerticalEdgeUVDispatch(u []byte, v []byte, stride int, blimit, limit, thresh byte) { + if lfKernelInnerUVV(u, v, stride, blimit, limit, thresh) { + return + } if pixel.LoopFilterUV8(u, v, 1, stride, int(blimit), int(limit), int(thresh), 4) { return } @@ -65,6 +83,9 @@ func loopFilterVerticalEdgeUVDispatch(u []byte, v []byte, stride int, blimit, li } func mbLoopFilterHorizontalEdgeDispatch(s []byte, stride int, blimit, limit, thresh byte, count int) { + if lfKernelMBH(s, stride, blimit, limit, thresh, count) { + return + } if pixel.LoopFilter(s, 4*stride, stride, 1, count*8, int(blimit), int(limit), int(thresh), 6) { return } @@ -73,6 +94,9 @@ func mbLoopFilterHorizontalEdgeDispatch(s []byte, stride int, blimit, limit, thr } func mbLoopFilterVerticalEdgeDispatch(s []byte, stride int, blimit, limit, thresh byte, count int) { + if lfKernelMBV(s, stride, blimit, limit, thresh, count) { + return + } if pixel.LoopFilter(s, 4*1, 1, stride, count*8, int(blimit), int(limit), int(thresh), 6) { return } @@ -81,6 +105,9 @@ func mbLoopFilterVerticalEdgeDispatch(s []byte, stride int, blimit, limit, thres } func mbLoopFilterHorizontalEdgeUVDispatch(u []byte, v []byte, stride int, blimit, limit, thresh byte) { + if lfKernelMBUVH(u, v, stride, blimit, limit, thresh) { + return + } if pixel.LoopFilterUV8(u, v, stride, 1, int(blimit), int(limit), int(thresh), 6) { return } @@ -89,6 +116,9 @@ func mbLoopFilterHorizontalEdgeUVDispatch(u []byte, v []byte, stride int, blimit } func mbLoopFilterVerticalEdgeUVDispatch(u []byte, v []byte, stride int, blimit, limit, thresh byte) { + if lfKernelMBUVV(u, v, stride, blimit, limit, thresh) { + return + } if pixel.LoopFilterUV8(u, v, 1, stride, int(blimit), int(limit), int(thresh), 6) { return } @@ -97,6 +127,9 @@ func mbLoopFilterVerticalEdgeUVDispatch(u []byte, v []byte, stride int, blimit, } func loopFilterSimpleHorizontalEdgeDispatch(s []byte, stride int, blimit byte) { + if lfKernelSimpleH(s, stride, blimit) { + return + } if pixel.LoopFilterSimpleHorizontal16(s, stride, blimit) { return } @@ -108,6 +141,9 @@ func loopFilterSimpleHorizontalEdgeDispatch(s []byte, stride int, blimit byte) { } func loopFilterSimpleVerticalEdgeDispatch(s []byte, stride int, blimit byte) { + if lfKernelSimpleV(s, stride, blimit) { + return + } if pixel.LoopFilterSimpleVertical16(s, stride, blimit) { return } diff --git a/internal/vp8/dsp/subpixel.go b/internal/vp8/dsp/subpixel.go index 7ee1410..57ef686 100644 --- a/internal/vp8/dsp/subpixel.go +++ b/internal/vp8/dsp/subpixel.go @@ -18,14 +18,23 @@ import ( ) func BilinearPredict4x4(src []byte, srcStride int, xoffset int, yoffset int, dst []byte, dstStride int) { + if bilinearKernel(src, srcStride, xoffset, yoffset, dst, dstStride, 4, 4) { + return + } bilinearPredict(src, srcStride, xoffset, yoffset, dst, dstStride, 4, 4) } func BilinearPredict8x4(src []byte, srcStride int, xoffset int, yoffset int, dst []byte, dstStride int) { + if bilinearKernel(src, srcStride, xoffset, yoffset, dst, dstStride, 8, 4) { + return + } bilinearPredict(src, srcStride, xoffset, yoffset, dst, dstStride, 8, 4) } func BilinearPredict8x8(src []byte, srcStride int, xoffset int, yoffset int, dst []byte, dstStride int) { + if bilinearKernel(src, srcStride, xoffset, yoffset, dst, dstStride, 8, 8) { + return + } if bilinearPredict8x8Maybe(src, srcStride, xoffset, yoffset, dst, dstStride) { return } @@ -39,6 +48,10 @@ func BilinearPredict8x8Pair( dst0 []byte, dst0Stride int, dst1 []byte, dst1Stride int, ) { + if bilinearKernel(src0, src0Stride, xoffset, yoffset, dst0, dst0Stride, 8, 8) && + bilinearKernel(src1, src1Stride, xoffset, yoffset, dst1, dst1Stride, 8, 8) { + return + } h := tables.BilinearFilters[xoffset] v := tables.BilinearFilters[yoffset] if pixel.FilterBilinear2DPair8x8(src0, src0Stride, src1, src1Stride, dst0, dst0Stride, dst1, dst1Stride, @@ -50,6 +63,9 @@ func BilinearPredict8x8Pair( } func BilinearPredict16x16(src []byte, srcStride int, xoffset int, yoffset int, dst []byte, dstStride int) { + if bilinearKernel(src, srcStride, xoffset, yoffset, dst, dstStride, 16, 16) { + return + } if bilinearPredict16x16Maybe(src, srcStride, xoffset, yoffset, dst, dstStride) { return } @@ -60,6 +76,9 @@ func BilinearPredict16x16(src []byte, srcStride int, xoffset int, yoffset int, d // prediction origin so the six filter taps are addressable with positive // indexes. func SixTapPredict4x4(src []byte, srcStride int, xoffset int, yoffset int, dst []byte, dstStride int) { + if sixTapKernel(src, srcStride, xoffset, yoffset, dst, dstStride, 4, 4) { + return + } if xoffset|yoffset == 0 { copyCentralBlock(src, srcStride, dst, dstStride, 4, 4) return @@ -71,6 +90,9 @@ func SixTapPredict4x4(src []byte, srcStride int, xoffset int, yoffset int, dst [ } func SixTapPredict8x4(src []byte, srcStride int, xoffset int, yoffset int, dst []byte, dstStride int) { + if sixTapKernel(src, srcStride, xoffset, yoffset, dst, dstStride, 8, 4) { + return + } if xoffset|yoffset == 0 { copyCentralBlock(src, srcStride, dst, dstStride, 8, 4) return @@ -82,6 +104,9 @@ func SixTapPredict8x4(src []byte, srcStride int, xoffset int, yoffset int, dst [ } func SixTapPredict8x8(src []byte, srcStride int, xoffset int, yoffset int, dst []byte, dstStride int) { + if sixTapKernel(src, srcStride, xoffset, yoffset, dst, dstStride, 8, 8) { + return + } if xoffset|yoffset == 0 { copyCentralBlock(src, srcStride, dst, dstStride, 8, 8) return @@ -99,6 +124,10 @@ func SixTapPredict8x8Pair( dst0 []byte, dst0Stride int, dst1 []byte, dst1Stride int, ) { + if sixTapKernel(src0, src0Stride, xoffset, yoffset, dst0, dst0Stride, 8, 8) && + sixTapKernel(src1, src1Stride, xoffset, yoffset, dst1, dst1Stride, 8, 8) { + return + } if xoffset|yoffset == 0 { copyCentralBlock(src0, src0Stride, dst0, dst0Stride, 8, 8) copyCentralBlock(src1, src1Stride, dst1, dst1Stride, 8, 8) @@ -112,6 +141,9 @@ func SixTapPredict8x8Pair( } func SixTapPredict16x16(src []byte, srcStride int, xoffset int, yoffset int, dst []byte, dstStride int) { + if sixTapKernel(src, srcStride, xoffset, yoffset, dst, dstStride, 16, 16) { + return + } if xoffset|yoffset == 0 { copyCentralBlock(src, srcStride, dst, dstStride, 16, 16) return diff --git a/tools/portgovpx/main.go b/tools/portgovpx/main.go index 749dddc..7c9fc3b 100644 --- a/tools/portgovpx/main.go +++ b/tools/portgovpx/main.go @@ -425,6 +425,74 @@ var Patches = map[string][]Patch{ "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(), + // The VP8 loop filters and sub-pixel predictors of the amd64 port come from the same module. + "internal/vp8/dsp/loopfilter_dispatch_other.go": vp8LFKernelPatches(), + "internal/vp8/dsp/subpixel.go": vp8MCKernelPatches(), + // Where the kernels run, the per-edge calls replace the fused macroblock paths of internal/pixel + // (internal/vp8/decoder/lf_kernels_*.go), which measured slower than the kernels. + "internal/vp8/decoder/loopfilter.go": { + {"fusedV = macroInternalLoopFilter && col > 0", "fusedV = macroInternalLoopFilter && !lfKernels && col > 0"}, + {"fusedH = macroInternalLoopFilter && row > 0", "fusedH = macroInternalLoopFilter && !lfKernels && row > 0"}, + }, +} + +// vp8LFKernelPatches makes the twelve VP8 loop-filter dispatch functions try +// the AVX2 kernels of go-videodsp/kernels first (internal/vp8/dsp/kernels_*.go), +// keeping the code they had as the fallback. +func vp8LFKernelPatches() []Patch { + const ( + edge = "(s []byte, stride int, blimit, limit, thresh byte, count int) {\n" + edges = "(s []byte, stride int, blimit, limit, thresh byte) {\n" + uv = "(u []byte, v []byte, stride int, blimit, limit, thresh byte) {\n" + simp = "(s []byte, stride int, blimit byte) {\n" + ) + add := func(fn, sig, kernel, args string) Patch { + old := "func " + fn + "Dispatch" + sig + return Patch{old, old + "\tif " + kernel + "(" + args + ") {\n\t\treturn\n\t}\n"} + } + return []Patch{ + add("loopFilterHorizontalEdge", edge, "lfKernelInnerH", "s, stride, blimit, limit, thresh, count"), + add("loopFilterHorizontalEdgesY", edges, "lfKernelInnerEdgesYH", "s, stride, blimit, limit, thresh"), + add("loopFilterVerticalEdge", edge, "lfKernelInnerV", "s, stride, blimit, limit, thresh, count"), + add("loopFilterVerticalEdgesY", edges, "lfKernelInnerEdgesYV", "s, stride, blimit, limit, thresh"), + add("loopFilterHorizontalEdgeUV", uv, "lfKernelInnerUVH", "u, v, stride, blimit, limit, thresh"), + add("loopFilterVerticalEdgeUV", uv, "lfKernelInnerUVV", "u, v, stride, blimit, limit, thresh"), + add("mbLoopFilterHorizontalEdge", edge, "lfKernelMBH", "s, stride, blimit, limit, thresh, count"), + add("mbLoopFilterVerticalEdge", edge, "lfKernelMBV", "s, stride, blimit, limit, thresh, count"), + add("mbLoopFilterHorizontalEdgeUV", uv, "lfKernelMBUVH", "u, v, stride, blimit, limit, thresh"), + add("mbLoopFilterVerticalEdgeUV", uv, "lfKernelMBUVV", "u, v, stride, blimit, limit, thresh"), + add("loopFilterSimpleHorizontalEdge", simp, "lfKernelSimpleH", "s, stride, blimit"), + add("loopFilterSimpleVerticalEdge", simp, "lfKernelSimpleV", "s, stride, blimit"), + } +} + +// vp8MCKernelPatches makes the exported six-tap and bilinear predictors try +// the AVX2 kernels of go-videodsp/kernels first, keeping the code they had as +// the fallback. +func vp8MCKernelPatches() []Patch { + const sig = "(src []byte, srcStride int, xoffset int, yoffset int, dst []byte, dstStride int) {\n" + one := func(fn, kernel string, w, h int) Patch { + old := "func " + fn + sig + call := fmt.Sprintf("\tif %s(src, srcStride, xoffset, yoffset, dst, dstStride, %d, %d) {\n\t\treturn\n\t}\n", kernel, w, h) + return Patch{old, old + call} + } + pair := func(old, kernel string) Patch { + call := "\tif " + kernel + "(src0, src0Stride, xoffset, yoffset, dst0, dst0Stride, 8, 8) &&\n\t\t" + + kernel + "(src1, src1Stride, xoffset, yoffset, dst1, dst1Stride, 8, 8) {\n\t\treturn\n\t}\n" + return Patch{old, call + old} + } + return []Patch{ + one("BilinearPredict4x4", "bilinearKernel", 4, 4), + one("BilinearPredict8x4", "bilinearKernel", 8, 4), + one("BilinearPredict8x8", "bilinearKernel", 8, 8), + one("BilinearPredict16x16", "bilinearKernel", 16, 16), + one("SixTapPredict4x4", "sixTapKernel", 4, 4), + one("SixTapPredict8x4", "sixTapKernel", 8, 4), + one("SixTapPredict8x8", "sixTapKernel", 8, 8), + one("SixTapPredict16x16", "sixTapKernel", 16, 16), + pair("\th := tables.BilinearFilters[xoffset]\n\tv := tables.BilinearFilters[yoffset]\n\tif pixel.FilterBilinear2DPair8x8(", "bilinearKernel"), + pair("\tif xoffset|yoffset == 0 {\n\t\tcopyCentralBlock(src0, src0Stride,", "sixTapKernel"), + } } // convKernelPatches makes the four one-direction convolutions try the AVX2