Skip to content

WIP: feat(webos): PyroWave decode with true 4K60 on the video plane - #317

Draft
zampierilucas wants to merge 10 commits into
punktfunk:mainfrom
zampierilucas:pyrowave
Draft

zampierilucas wants to merge 10 commits into
punktfunk:mainfrom
zampierilucas:pyrowave

Conversation

@zampierilucas

@zampierilucas zampierilucas commented Nov 7, 2026 •

Copy link
Copy Markdown

This is a draft, it works end to end on my LG C5 but it still needs a bunch of cleanup before it's ready for review. Opening it now so the approach is visible and we can talk about the LG specific bits early.

What it does. Adds a PyroWave sink for webOS. Streams up to 1080p decode on the GPU through the hidden Vulkan driver in libmali and draw through GL. Above 1080p the client splits decoding, NEON on 3 to 4 CPU threads unpacks each frame and the GPU only runs the inverse wavelet, then frames go to LG's video plane through the photo video output (DILE_VO), so the panel gets real 3840x2160 instead of the 1080p graphics plane. Each copy into LG's buffer waits for LG's latch event, which is needed because of the tearing. On top of that the TV switches to game picture mode during a stream and puts the previous mode back afterwards, the session uses AES-GCM (this CPU has ARMv8 AES), and there's a flag to skip the start-up bitrate probe.

Why Vulkan

  • webOS ships no Vulkan loader, but libmali (Mali-G52, r46p0) has a working Vulkan 1.3 driver that only exports vk_icdGetInstanceProcAddr. The client dlopens libmali.so and uses that.
  • Mali's subgroup size is fixed at 8. Upstream's dequant assumed 16 or more and decoded garbage, fixed in Fix dequant plane offsets for subgroup sizes below 16 Themaister/pyrowave#35, plus a shuffle based iDWT for subgroup size 8.
  • Decoding always runs on Vulkan compute. GL is only used to draw at 1080p and below, and since the app sandbox has no /dev/dri and Mali can't export dma-bufs, each decoded frame is copied from Vulkan into a GL texture there. Above 1080p GL isn't involved, frames go to the video plane.

Why the photo output (libdile_photo)

  • The graphics plane is 1920x1080, so GL output gets upscaled. Real 4K only exists on the video plane.
  • NDL only feeds LG's hardware decoder compressed H.264/HEVC/AV1, not frames we already decoded.
  • DILE_VO_DisplayPicture, the output LG's photo viewer uses, takes raw 4K frames onto the video plane. It only copies chroma for NV12, needs videooutputd routing plus a compositor punch-through, and has two buffer pairs, so each copy waits for liblxv's latch event.

Why the split decoder

  • GPU only, the G52 needs 20 to 24 ms per 4K frame at 300 Mbps (about 50 fps), and the iDWT already runs at the GPU's memory bandwidth (about 1.9 GB/s of writes).
  • Above 1080p the dequant runs on the CPU (NEON, 3 to 4 threads) and the GPU only runs the iDWT, one frame behind. The dequant starts per packet while the frame arrives, leaving about 0.7 ms after the last packet.
  • 1080p keeps the all-GPU path, about 8 ms per frame.

Numbers on a C5 (Mali-G52, webOS 10.3.1), host on Fedora 44 with an RTX 5080, 4K60 at 300 Mbps holds 60 fps with about 0% loss, about 17 ms GPU and 3 ms CPU per frame, 1080p60 at 60 fps.

The honest part, this leans on undocumented LG libraries (libdile_photo, libhal_photo, liblxv), a compositor punch-through call whose signature differs from LG's header, and a luna name only dev mode apps may register. I'd like your take on whether that's something you want in the client at all, or behind a build flag, before I spend time polishing it.

Still to do before this leaves draft.

  1. Rebase onto current main and drop the vendored pyrowave-sys once the punktfunk side lands (decoder fixes for Mali, skipped frames not counted as lost, decrypt in place). The Cargo [patch] currently points at my GitHub fork of punktfunk.
  2. Replace the flag files in the app dir (lxvo-dg, no-game-picture, pyro-gl, no-abr-probe) with real settings or remove them.
  3. Strip the test and timing knobs that were only there for measuring.
  4. Split into reviewable commits (GL path, video plane, hybrid decode, game picture mode, cipher).
  5. Gate the LG library use so the client still runs on TVs where those libraries or the dev mode permission are missing.
  6. Check the packaged install keeps the settingsservice permission game picture mode needs.

Trying it yourself

If you're crazy enough to try this, these are all the pieces still in flight.

- Vulkan PyroWave decoder via the Mali driver's built-in Vulkan ICD
- 1080p and below: decode, upload to GL; streams larger than the display
  decode at half resolution on the GL path (file pyro-gl forces it)
- above 1080p: full-resolution decode, NV12 to the video plane through
  DILE_VO, videooutputd and compositor punch-through; GL window stays
  transparent with the stats overlay on top
- decode thread keeps up to two frames in flight, newest frame only
- colour range follows the stream; autostream launch parameter
- overlay: PyroWave decode timings, no GPU estimate

Cargo [patch] points at local punktfunk worktrees (webos-console) and a
vendored pyrowave-sys; replace with upstream revisions before merging.

Signed-off-by: Lucas Zampieri <lcasmz54@gmail.com>
… in the app dir

Signed-off-by: Lucas Zampieri <lcasmz54@gmail.com>
…) every 10 s

Signed-off-by: Lucas Zampieri <lcasmz54@gmail.com>
- streams above 1080p use CPU dequant on 4 threads (nice -10) and GPU
  iDWT; 1080p keeps the GPU path
- AES-GCM session cipher (aws-lc, ARMv8 AES); no longer advertise
  ChaCha20
- decode pacing estimate learns only from frames queued behind another
- cpu dequant timing line

LG C5 live, testsrc2 4K60: 60 fps with 0 loss at 230/260/300 Mbps caps.

Signed-off-by: Lucas Zampieri <lcasmz54@gmail.com>
- set LG's VO frame rate to 60 and copy each frame only after LG reports
  the previous picture latched (lxvo_read_info DISP event), so the HAL's
  two buffer pairs are never overwritten while on screen; on by default,
  `lxvo-dg` in the app dir overrides (flags lag timeout, "0" disables)
- switch the TV picture mode to "game" for the length of a stream and
  restore the previous mode on stream end, exit, or next launch after a
  crash; `no-game-picture` in the app dir disables it

Signed-off-by: Lucas Zampieri <lcasmz54@gmail.com>
…cal paths

Signed-off-by: Lucas Zampieri <lcasmz54@gmail.com>
Each data shard the core reassembler reports is queued per frame and
dequantized on the existing dequant threads while the rest of the frame
is still on the wire; a pending frame always decodes first. On by default,
an empty no-early-dq file in the app dir turns it off. Adds a
'pyrowave last>decoded' stage line. LG C5, 4K60 300 Mbps: last packet to
decoded 23.2 -> 21.0 ms, capture to decoded 42.8 -> 41.2 ms, fps
unchanged, client CPU ~145% -> ~170% of one core.

Takes the core change from the fork at 19b9360e.

Signed-off-by: Lucas Zampieri <lcasmz54@gmail.com>
…process

pf_vo_close left lx_k at the old session's frame count, and lx_base is
only re-read when lx_k is 0, so after a reconnect the gate compared the
new session against the old one: every frame waited out the 25 ms timeout
(~33 ms per DisplayPicture, ~30 fps) or never waited (tearing) until the
app was relaunched. Reset lx_k on close, start the DISP event thread only
once instead of one more per open, and sleep instead of spinning when its
descriptor is gone.

Signed-off-by: Lucas Zampieri <lcasmz54@gmail.com>
…d copy

The client carried its own 154k-line copy of pyrowave-sys only for the Mali
decoder changes, an armv7 FPU flag and FP16 math. All three now live in
the punktfunk fork's pyrowave-sys (fp16-math feature), so the [patch]
takes it from there like the other punktfunk crates and the copy goes.

Signed-off-by: Lucas Zampieri <lcasmz54@gmail.com>
…s are patches

The Mali, hybrid and early dequant changes now sit in pyrowave-sys as
patches 0014-0016 on top of upstream PyroWave, the same way punktfunk
carries its own. The source tree is unchanged. Also commits the
THIRD-PARTY-NOTICES.txt the build regenerated after dropping the
vendored copy.

Signed-off-by: Lucas Zampieri <lcasmz54@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant