Repository navigation
Conversation
porkloin
marked this pull request as ready for review
November 19, 2026 20:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently, the encoder's bitstream buffer takes the first host-visible, coherent memory type. On RADV that's uncached, write-combined memory, and the CPU copies every encoded frame out of it slowly: at 4K120 on an RX 7900 XTX the copy takes 0.5–0.7 ms per frame, and over 3 ms while the GPU is also decoding.
This PR prefers a cached memory type for buffers the encoder writes into (
VIDEO_ENCODE_DST). Other buffers, and devices without a coherent cached type, keep the current choice. The copy drops to about 0.1 ms, and Moonshine's capture-to-send latency falls 7–12% on an RX 7900 XTX, with GPU encode time unchanged.TL;DR: does the same thing as 878db34 (the fix for #59), but for encode instead of decode.
Testing
pixelforge's tests
RX 7900 XTX (Mesa 26.2.7): 65 passed, 12 skipped, 2 failed. RX 9070 XT: 65 passed, 13 skipped, 1 failed. The failures,
rate_control_changeson both androundtrip_h265_top_quality_levelon the RX 7900 XTX, happen the same way on main.cargo fmtandclippy -D warningsare clean.Integration testing in Moonshine
pixelforge's tests don't measure latency, so both builds (this branch caf6dfd, main efa5780) were built into Moonshine 934c5c5 and streamed with moonshine-test-headless, which streams a test app to a headless Moonlight client on the same machine and records Moonshine's timing for every frame. The apps were vkcube and framestamp, a full-motion test pattern whose frames the client checks against the expected image. Each codec streamed for 20 s, 3 times per build.
RX 7900 XTX (RDNA3). 3840x2160 at 120 fps and 113 Mb/s, and 1920x1080 at 60 fps and 20 Mb/s. Host latency p50 (capture to packets sent), framestamp:
vkcube moved the same way (−6.8% to −12.2%). GPU encode time was identical; from encode finished to frame copied out took 480–740 µs on main and 70–130 µs here at 4K120, and 220–300 µs against 63–81 µs at 1080p60. When the client decodes on the same GPU, as in the harness output below, host latency p99 at 4K120 fell from 8.32 ms to 5.77 ms.
RX 9070 XT (RDNA4). 5 streams per codec. Against main at 1080p60 (vkcube), host latency p50 fell 4.3% for H.264 and 6.3% for HEVC, with GPU encode time within 1%. At 4K120 H.264 it was compared with an SSE4.1 streaming-load copy from the same buffer (5–7.5% faster than main on this GPU), in two runs in opposite order: the two matched, GPU encode 5866 µs against 5870 µs p50 in the second.
Not tested: NVIDIA and Intel. Problems there are unlikely: a driver without a host-visible, coherent and cached type for this buffer gets the current memory type, and the GPU's writes into cached memory cost nothing measurable on either AMD card.
Harness output
The full moonshine-test-headless summaries for the RX 7900 XTX runs above, one per mode. Their report cards come from streams the client also decodes, so their host latency is higher than in the table.
pixelforge caf6dfd vs main efa5780, in Moonshine 934c5c5 · 3840x2160 at 120 fps
Hardware
Stream
Report card
pixelforge caf6dfd vs main efa5780, in Moonshine 934c5c5 · 1920x1080 at 60 fps
Stream
Report card
Results produced by moonshine-test-headless. Results file attached.
To run the same test on your hardware:
podman container runlabel run ghcr.io/porkloin/moonshine-test-headless -- \ --pixelforge porkloin@bitstream-host-cached --baseline --iterations 3 \ --app vkcube --app framestamp-full --mode 4k120 --mode 1080p60To view the attached results:
podman container runlabel run ghcr.io/porkloin/moonshine-test-headless:view \ path/to/results-compact-no-traces.tar.gz