fix(encode/windows): clear the Windows Phase 4 backlog — NVENC sticky state, QSV HDR + ABR
arch / build-publish (push) Failing after 5m39s
ci / web (push) Successful in 1m2s
ci / docs-site (push) Successful in 1m3s
android / android (push) Successful in 11m50s
decky / build-publish (push) Successful in 21s
docker / build-push (--build-arg FEDORA_VERSION=44, ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora44-rpm) (push) Successful in 10s
docker / build-push (., web/Dockerfile, punktfunk-web) (push) Successful in 9s
docker / build-push (ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora-rpm) (push) Successful in 9s
ci / bench (push) Successful in 6m25s
docker / build-push (ci, ci/rust-ci.Dockerfile, punktfunk-rust-ci) (push) Successful in 13s
docker / build-push (docs-site, docs-site/Dockerfile, punktfunk-docs) (push) Successful in 12s
ci / rust-arm64 (push) Successful in 10m5s
docker / build-push (ci, ci/rust-ci-noble.Dockerfile, punktfunk-rust-ci-noble) (push) Successful in 5m22s
deb / build-publish-client-arm64 (push) Successful in 9m34s
deb / build-publish (push) Successful in 10m58s
docker / deploy-docs (push) Successful in 12s
deb / build-publish-host (push) Successful in 11m51s
docker / build-push-arm64cross (push) Successful in 6m20s
apple / swift (push) Successful in 5m22s
ci / rust (push) Successful in 22m30s
rpm / build-publish (44, fedora-44, punktfunk-fedora44-rpm) (push) Successful in 15m2s
windows-host / package (push) Successful in 10m48s
rpm / build-publish (43, bazzite, punktfunk-fedora-rpm) (push) Successful in 19m13s
apple / screenshots (push) Canceled after 16m50s
arch / build-publish (push) Failing after 5m39s
ci / web (push) Successful in 1m2s
ci / docs-site (push) Successful in 1m3s
android / android (push) Successful in 11m50s
decky / build-publish (push) Successful in 21s
docker / build-push (--build-arg FEDORA_VERSION=44, ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora44-rpm) (push) Successful in 10s
docker / build-push (., web/Dockerfile, punktfunk-web) (push) Successful in 9s
docker / build-push (ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora-rpm) (push) Successful in 9s
ci / bench (push) Successful in 6m25s
docker / build-push (ci, ci/rust-ci.Dockerfile, punktfunk-rust-ci) (push) Successful in 13s
docker / build-push (docs-site, docs-site/Dockerfile, punktfunk-docs) (push) Successful in 12s
ci / rust-arm64 (push) Successful in 10m5s
docker / build-push (ci, ci/rust-ci-noble.Dockerfile, punktfunk-rust-ci-noble) (push) Successful in 5m22s
deb / build-publish-client-arm64 (push) Successful in 9m34s
deb / build-publish (push) Successful in 10m58s
docker / deploy-docs (push) Successful in 12s
deb / build-publish-host (push) Successful in 11m51s
docker / build-push-arm64cross (push) Successful in 6m20s
apple / swift (push) Successful in 5m22s
ci / rust (push) Successful in 22m30s
rpm / build-publish (44, fedora-44, punktfunk-fedora44-rpm) (push) Successful in 15m2s
windows-host / package (push) Successful in 10m48s
rpm / build-publish (43, bazzite, punktfunk-fedora-rpm) (push) Successful in 19m13s
apple / screenshots (push) Canceled after 16m50s
Four items, gated on the RTX box (.173, all 7 Windows legs) and the Linux docker gate, with
the QSV HDR one proven by an A/B on real Intel silicon (.42, UHD 750).
WP4.1 — Windows NVENC sticky state. Both halves were the same mistake: a single field doing
duty as both "what the session negotiated" and "what this session can actually do", so the
first downgrade destroyed the negotiation.
- `query_caps` clears `self.hdr` on a GPU without 10-bit encode, but `submit` re-derives the
requested HDR state from every frame's pixel format and compared it against that cleared
value. On such a GPU a P010 capturer therefore reported "HDR changed" on EVERY FRAME and
tore down and rebuilt the whole encode session each time. The trigger now compares against
`hdr_requested`, and the downgrade is latched in `hdr_unsupported` so it is remembered
(and warned once) instead of rediscovered per init.
- One subsampled-YUV frame cleared `chroma_444` permanently, so 4:4:4 never returned when
the capturer went back to RGB. The negotiation now lives in `chroma_444_requested` and the
effective value is recomputed at every init; the per-session downgrade still happens and
is still reported honestly through `caps()`, it just is not destructive any more.
WP4.3(a) — QSV HDR mastering luminance was divided by 10,000. The old comment justified it as
"VPL wants whole cd/m²", which is true of the VIDEO-PROCESSING unit but not the encode path:
the runtime passes the value straight into the ITU-T H.265 Annex D mastering-display SEI,
whose unit is 0.0001 cd/m². Verified end to end on Intel UHD 750 by dumping the bitstream and
reading SEI 137 with trace_headers, before and after:
before: max_display_mastering_luminance = 1000 (0.1 nits)
after: max_display_mastering_luminance = 10000000 (1000 nits)
with `min` (500 = 0.05 nits) and both content-light-level fields unchanged. That asymmetry —
a correct min beside a 10,000x-low max — was the original tell.
WP4.3(b) — `reconfigure_bitrate` never re-read `BufferSizeInKB`, so an ABR step-up could hand
the runtime an AU buffer sized for the old, lower bitrate. Fixed in both places it was broken:
re-read the driver's answer via `GetVideoParam` after the `Reset` (mirroring `init_encode`),
AND stop `take_bs` recycling pooled buffers without checking their capacity — the pool would
otherwise keep serving short buffers even once `bs_bytes` was correct.
WP7.8 — the `PUNKTFUNK_QSV_FFMPEG` half, finally landable now that a Windows gate exists (it
sits behind `#[cfg(feature = "qsv")]`, so nothing in a Linux-only matrix compiles it — it was
deliberately held back for exactly that reason). Trimmed like its siblings, and kept
case-insensitive: the knob already accepted `TRUE`, and the bare house `matches!` would have
silently dropped that spelling.
Phase 4 of the audit is now complete, and WP7.8 with it.
Verified: Windows gate on .173 — clippy -D warnings at nvenc,amf-qsv,qsv (host + pf-encode
--all-targets), amf-qsv without qsv, qsv alone, no-features, `cargo test --features qsv`
(34 passed), rustfmt. Linux docker gate L1-L4 green. On-glass: the QSV A/B above on .42.
Owed: NVENC sticky-state on-glass on .173 (needs a live 10-bit-capable capture toggle).
This commit is contained in:
@@ -519,9 +519,20 @@ fn build_params(cfg: &EncodeConfig) -> ParamSet {
|
||||
}
|
||||
b.WhitePointX = m.white_point[0];
|
||||
b.WhitePointY = m.white_point[1];
|
||||
// Units diverge on the max: VPL wants whole cd/m² (HdrMeta carries 0.0001 cd/m²); the
|
||||
// min is 0.0001 cd/m² on both sides.
|
||||
b.MaxDisplayMasteringLuminance = m.max_display_mastering_luminance / 10_000;
|
||||
// BOTH luminance fields are 0.0001 cd/m² here — do NOT scale the max.
|
||||
//
|
||||
// The `/10_000` this used to carry followed the VPL header's *video-processing* unit
|
||||
// (whole cd/m², which is right for VPP), but on the ENCODE path the runtime passes these
|
||||
// straight into the ITU-T H.265 Annex D mastering-display SEI, whose unit is 0.0001 cd/m².
|
||||
// Dividing therefore under-reported peak brightness by 10,000x. Confirmed in a real
|
||||
// bitstream on Intel UHD 750 (2026-07-25): SEI 137 carried
|
||||
// max_display_mastering_luminance = 1000, i.e. **0.1 nits** for a 1000-nit display, while
|
||||
// the undivided min = 500 (0.05 nits) was correct — the asymmetry was the tell. A client
|
||||
// tone-mapping against 0.1 nits crushes the image.
|
||||
//
|
||||
// Unscaled also matches every sibling: `MinDisplayMasteringLuminance` right below,
|
||||
// `pf_frame::hdr::hevc_mastering_display_sei`, and the AMF backend.
|
||||
b.MaxDisplayMasteringLuminance = m.max_display_mastering_luminance;
|
||||
b.MinDisplayMasteringLuminance = m.min_display_mastering_luminance;
|
||||
b
|
||||
});
|
||||
@@ -690,13 +701,17 @@ impl Inner {
|
||||
}
|
||||
|
||||
fn take_bs(&mut self) -> Box<BsBuf> {
|
||||
match self.bs_pool.pop() {
|
||||
Some(mut b) => {
|
||||
// Pooled buffers were sized by whatever `bs_bytes` was when they were allocated. A bitrate
|
||||
// retarget raises the driver's worst-case AU size, so a recycled buffer can be SMALLER than
|
||||
// the current requirement — hand those back to the allocator instead of letting the runtime
|
||||
// write an AU into a short buffer.
|
||||
while let Some(mut b) = self.bs_pool.pop() {
|
||||
if b.mfx.MaxLength as usize >= self.bs_bytes {
|
||||
b.recycle();
|
||||
b
|
||||
return b;
|
||||
}
|
||||
None => BsBuf::new(self.bs_bytes),
|
||||
}
|
||||
BsBuf::new(self.bs_bytes)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1583,6 +1598,38 @@ impl Encoder for QsvEncoder {
|
||||
self.bitrate_bps = old;
|
||||
return false;
|
||||
}
|
||||
// Re-read the driver's worst-case AU size. `Reset` re-derives `BufferSizeInKB` from the new
|
||||
// rate, and a step-up can raise it well above what `init_encode` computed — leaving
|
||||
// `bs_bytes` (and every buffer already in the pool) sized for the OLD, lower bitrate. This
|
||||
// mirrors `init_encode`, which asks the same question post-Init; `take_bs` drops any pooled
|
||||
// buffer that is now too small.
|
||||
// SAFETY: `session` is live on this thread and drained above; `got` and its (empty) ext
|
||||
// chain outlive the synchronous call.
|
||||
let refreshed = unsafe {
|
||||
let mut got: vpl::mfxVideoParam = std::mem::zeroed();
|
||||
let sts = vpl::MFXVideoENCODE_GetVideoParam(session, &mut got);
|
||||
(sts >= vpl::MFX_ERR_NONE).then(|| {
|
||||
let m = &mut got.__bindgen_anon_1.mfx;
|
||||
let mult = m.BRCParamMultiplier.max(1) as usize;
|
||||
let kb = enc_of(m).BufferSizeInKB as usize;
|
||||
(kb * mult * 1000).max(256 * 1024)
|
||||
})
|
||||
};
|
||||
match (refreshed, self.inner.as_mut()) {
|
||||
(Some(bytes), Some(inner)) if bytes > inner.bs_bytes => {
|
||||
tracing::debug!(
|
||||
old_bytes = inner.bs_bytes,
|
||||
new_bytes = bytes,
|
||||
mbps = bps / 1_000_000,
|
||||
"QSV retarget raised the worst-case AU size — resizing the bitstream pool"
|
||||
);
|
||||
inner.bs_bytes = bytes;
|
||||
}
|
||||
(None, _) => tracing::warn!(
|
||||
"QSV retarget: GetVideoParam failed, keeping the previous AU buffer size"
|
||||
),
|
||||
_ => {}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user