fix(video): move AV1 planar conversion onto Metal - #456
Conversation
|
Thank you for digging into this, and for a writeup that made the branch easy to read. The fallback design, the session-scoped disable and the format policy are careful work, and the two pixel-buffer-pool findings buried in it are real (more on those below). The premise does not survive measurement, though, so it is worth settling that before the device retest. Benchmarked on an M1 (macOS 26.5.2), 3840x2160, 60 warm iterations, comparing what
At 23.976 fps the conversion this PR removes costs 0.9 % of one core. It cannot be a measurable share of a 464 % process reading, so what is burning the CPU in NuvioTVOS #40 is dav1d decoding 4K AV1, not the conversion that follows it. And the replacement is the more expensive path: roughly 10x the CPU and 20x the wall time of The shape that would pay is the one that deletes the upload instead of adding it: a custom For the underlying report, the measurement worth taking on the device is dav1d itself. A Time Profiler capture on the Apple TV will attribute the 464 % honestly, and Two pieces of this branch are worth having regardless of the Metal path, and I would happily take them as their own PR:
Two notes for the record, since they are divergences from Leaving this open as a draft rather than closing it, in case the zero-copy direction is interesting. The benchmark is a small test target addition and easy to share if it helps. |
|
Thanks so much for the detailed benchmark, profiling breakdown, and insights. That makes total sense—the planar conversion is only ~0.9% of a core, so the 400%+ CPU is indeed overwhelmingly dav1d software decoding 4K AV1 frames on devices lacking hardware AV1 decode in VideoToolbox. Closing this PR and deleting the branch. We'll split the 10-bit pool latching and bit-depth pool keying fixes into a separate, clean PR. If you have any recommendations or thoughts on dav1d configuration (e.g. |
Summary
Moves AetherEngine's common AV1 planar 4:2:0 conversion from CPU
sws_scaleto a small Metal compute path while preserving the existing CVPixelBuffer andSampleBufferRendererpipeline.This was found through NuvioTVOS #40. On an Apple TV 4K running tvOS 26.6, a 3840x2160 23.976 fps AV1 MKV with TrueHD 5.1 routed through dav1d software decode, measured about 464% process CPU, and held a 0.0 s display cushion. The same source played smoothly in Stremio's KSPlayer pipeline. Aether's software decoder was performing a second full-frame planar YUV -> NV12/P010 CPU conversion after dav1d.
Implementation
MetalYUVConverterfor AV1YUV420P,YUVJ420P, andYUV420P10LE.sws_scalefor unsupported layouts, invalid/negative strides, missing Metal, texture/shader failures, or GPU command failures.Tests
swift test --filter MetalYUVConversionPolicyTestsswift test: 2,415 tests in 329 suites passed.Device verification status
The original high-CPU failure was captured on Apple TV 4K / tvOS 26.6. The converter and exact output were exercised on a macOS Metal device, and the tvOS targets compile and link, but the affected source still needs a post-change physical Apple TV performance retest. Opening as draft for that device validation and maintainer feedback.