feat(host): native AMF SDK encoder for Windows AMD — drop libavcodec
apple / swift (push) Successful in 1m26s
ci / rust (push) Failing after 38s
ci / web (push) Successful in 52s
windows-host / package (push) Successful in 7m26s
apple / screenshots (push) Successful in 6m8s
decky / build-publish (push) Successful in 13s
android / android (push) Successful in 4m58s
arch / build-publish (push) Successful in 5m31s
ci / docs-site (push) Successful in 1m1s
deb / build-publish (push) Successful in 3m20s
docker / build-push (--build-arg FEDORA_VERSION=44, ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora44-rpm) (push) Successful in 5s
docker / build-push (., web/Dockerfile, punktfunk-web) (push) Successful in 5s
docker / build-push (ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora-rpm) (push) Successful in 4s
docker / build-push (ci, ci/rust-ci.Dockerfile, punktfunk-rust-ci) (push) Successful in 6s
docker / build-push (docs-site, docs-site/Dockerfile, punktfunk-docs) (push) Successful in 4s
ci / bench (push) Successful in 4m52s
rpm / build-publish (43, bazzite, punktfunk-fedora-rpm) (push) Successful in 10m11s
docker / deploy-docs (push) Successful in 18s
rpm / build-publish (44, fedora-44, punktfunk-fedora44-rpm) (push) Successful in 10m11s
apple / swift (push) Successful in 1m26s
ci / rust (push) Failing after 38s
ci / web (push) Successful in 52s
windows-host / package (push) Successful in 7m26s
apple / screenshots (push) Successful in 6m8s
decky / build-publish (push) Successful in 13s
android / android (push) Successful in 4m58s
arch / build-publish (push) Successful in 5m31s
ci / docs-site (push) Successful in 1m1s
deb / build-publish (push) Successful in 3m20s
docker / build-push (--build-arg FEDORA_VERSION=44, ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora44-rpm) (push) Successful in 5s
docker / build-push (., web/Dockerfile, punktfunk-web) (push) Successful in 5s
docker / build-push (ci, ci/fedora-rpm.Dockerfile, punktfunk-fedora-rpm) (push) Successful in 4s
docker / build-push (ci, ci/rust-ci.Dockerfile, punktfunk-rust-ci) (push) Successful in 6s
docker / build-push (docs-site, docs-site/Dockerfile, punktfunk-docs) (push) Successful in 4s
ci / bench (push) Successful in 4m52s
rpm / build-publish (43, bazzite, punktfunk-fedora-rpm) (push) Successful in 10m11s
docker / deploy-docs (push) Successful in 18s
rpm / build-publish (44, fedora-44, punktfunk-fedora44-rpm) (push) Successful in 10m11s
Direct-SDK AMF encoder (encode/windows/amf.rs), the AMD analogue of the direct-NVENC path, replacing the libavcodec *_amf dispatch. C-vtable FFI pinned to AMF headers v1.4.36, runtime-loaded from the driver's amfrt64.dll (no build feature, no new dependency) exactly as NVENC loads its DLL. - AVC/HEVC (SDR NV12 + 10-bit HDR P010) and AV1 (RDNA3+, probed); a bounded poll retires the libavcodec ~2-frame output hold; native in-place reset(). - Intra-refresh wave (PUNKTFUNK_INTRA_REFRESH), in-band HDR mastering/CLL metadata (*InHDRMetadata -> HEVC SEI / AV1 OBU), and a native codec probe feeding the GameStream advertisement (windows_backend_is_ffmpeg -> windows_backend_is_probed). - AMD dispatch / advertisement / 4:4:4 are native-only; the libavcodec AMF fallback and the PUNKTFUNK_AMF_FFMPEG hatch are removed. FFmpeg serves QSV only (its AMF path retained solely as the latency A/B comparator). - Overload back-pressure: submit bounds in-flight surfaces below the input ring, draining finished AUs (buffered for poll, FIFO-preserved) to free a slot and retry on AMF_INPUT_FULL instead of tearing the encoder down and forcing an IDR; this also closes a latent ring-overwrite corruption seen under load on-glass. Validated on the lab Ryzen iGPU (AMF runtime 1.4.37): HEVC/AVC across a native reset, HEVC Main10 mastering+CLL SEIs byte-verified, intra-refresh accepted, a backpressure burst FIFO-clean, and end-to-end via the macOS client. Measured §5.2 latency A/B: native encode_us p50 ~5 ms (0.31 frame periods) vs libavcodec ~17 ms (1.01). 4:4:4 stays unsupported (VCN hardware limit). Live-gated tests skip cleanly on non-AMD boxes. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -546,17 +546,40 @@ fn open_video_backend(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
backend @ (WindowsBackend::Amf | WindowsBackend::Qsv) => {
|
WindowsBackend::Amf => {
|
||||||
// AMD AMF / Intel QSV via libavcodec (the Windows analogue of the Linux VAAPI path).
|
// AMD: the native AMF SDK encoder, unconditionally (design/native-amf-encoder.md
|
||||||
|
// Phase 3). The libavcodec AMF fallback and the `PUNKTFUNK_AMF_FFMPEG` hatch were
|
||||||
|
// removed once the native path was validated — two permanently-maintained AMF
|
||||||
|
// paths double the driver-matrix burden, and the one kept "for safety" is exactly
|
||||||
|
// the one with the wedge/latency pathology. No build feature: amfrt64.dll resolves
|
||||||
|
// at runtime like NVENC's DLL. A missing/ancient runtime fails HERE with the
|
||||||
|
// "install/update the AMD driver" message `AmfEncoder::open` raises (§6), rather
|
||||||
|
// than silently degrading — FFmpeg now serves QSV only.
|
||||||
|
amf::AmfEncoder::open(
|
||||||
|
codec,
|
||||||
|
format,
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
fps,
|
||||||
|
bitrate_bps,
|
||||||
|
bit_depth,
|
||||||
|
chroma,
|
||||||
|
)
|
||||||
|
.map(|e| Box::new(e) as Box<dyn Encoder>)
|
||||||
|
.map_err(|e| {
|
||||||
|
e.context(
|
||||||
|
"native AMF encode failed to open (update the AMD driver / amfrt64.dll \
|
||||||
|
runtime)",
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
WindowsBackend::Qsv => {
|
||||||
|
// Intel QSV via libavcodec (stays on FFmpeg — design/native-amf-encoder.md §2:
|
||||||
|
// async_depth=1 + low_power VDEnc is already near the hardware latency floor).
|
||||||
#[cfg(feature = "amf-qsv")]
|
#[cfg(feature = "amf-qsv")]
|
||||||
{
|
{
|
||||||
let vendor = if matches!(backend, WindowsBackend::Amf) {
|
|
||||||
ffmpeg_win::WinVendor::Amf
|
|
||||||
} else {
|
|
||||||
ffmpeg_win::WinVendor::Qsv
|
|
||||||
};
|
|
||||||
ffmpeg_win::FfmpegWinEncoder::open(
|
ffmpeg_win::FfmpegWinEncoder::open(
|
||||||
vendor,
|
ffmpeg_win::WinVendor::Qsv,
|
||||||
codec,
|
codec,
|
||||||
format,
|
format,
|
||||||
width,
|
width,
|
||||||
@@ -570,11 +593,10 @@ fn open_video_backend(
|
|||||||
}
|
}
|
||||||
#[cfg(not(feature = "amf-qsv"))]
|
#[cfg(not(feature = "amf-qsv"))]
|
||||||
{
|
{
|
||||||
let _ = backend;
|
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"AMD/Intel (AMF/QSV) encode requested/detected but this host was built \
|
"Intel (QSV) encode requested/detected but this host was built without \
|
||||||
without it — rebuild with `--features amf-qsv` (needs ffmpeg-next + a \
|
it — rebuild with `--features amf-qsv` (needs ffmpeg-next + a FFMPEG_DIR \
|
||||||
FFMPEG_DIR with the AMF/QSV encoders at build time)"
|
with the QSV encoders at build time)"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -785,14 +807,13 @@ pub fn can_encode_444(codec: Codec) -> bool {
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowsBackend::Amf | WindowsBackend::Qsv => {
|
// AMD: native AMF never encodes 4:4:4 — VCN hardware limit, permanent, no probe
|
||||||
|
// needed (design/native-amf-encoder.md §3.5, Phase 3).
|
||||||
|
WindowsBackend::Amf => false,
|
||||||
|
WindowsBackend::Qsv => {
|
||||||
#[cfg(feature = "amf-qsv")]
|
#[cfg(feature = "amf-qsv")]
|
||||||
{
|
{
|
||||||
let vendor = match windows_resolved_backend() {
|
ffmpeg_win::probe_can_encode_444(ffmpeg_win::WinVendor::Qsv, codec)
|
||||||
WindowsBackend::Qsv => ffmpeg_win::WinVendor::Qsv,
|
|
||||||
_ => ffmpeg_win::WinVendor::Amf,
|
|
||||||
};
|
|
||||||
ffmpeg_win::probe_can_encode_444(vendor, codec)
|
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "amf-qsv"))]
|
#[cfg(not(feature = "amf-qsv"))]
|
||||||
{
|
{
|
||||||
@@ -859,16 +880,18 @@ pub(crate) fn windows_resolved_backend() -> WindowsBackend {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// True if the active Windows backend is the libavcodec AMF/QSV path (so the codec advertisement
|
/// True if the active Windows backend's codec advertisement comes from a **real GPU probe**
|
||||||
/// consults a real GPU probe rather than the NVENC static superset). Always false when the
|
/// ([`windows_codec_support`]) rather than the NVENC static superset. AMF always qualifies — the
|
||||||
/// `amf-qsv` feature is off — there's then no ffmpeg backend to probe.
|
/// native factory probe (`amf::probe_can_encode`) needs no build feature — while QSV still needs
|
||||||
|
/// the `amf-qsv` (libavcodec) build. Formerly `windows_backend_is_ffmpeg`, renamed when the
|
||||||
|
/// native AMF probe replaced the ffmpeg open-probe (design/native-amf-encoder.md §4, Phase 2).
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
pub fn windows_backend_is_ffmpeg() -> bool {
|
pub fn windows_backend_is_probed() -> bool {
|
||||||
cfg!(feature = "amf-qsv")
|
match windows_resolved_backend() {
|
||||||
&& matches!(
|
WindowsBackend::Amf => true,
|
||||||
windows_resolved_backend(),
|
WindowsBackend::Qsv => cfg!(feature = "amf-qsv"),
|
||||||
WindowsBackend::Amf | WindowsBackend::Qsv
|
WindowsBackend::Nvenc | WindowsBackend::Software => false,
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Detect the encode-GPU vendor from the **selected render adapter** ([`crate::gpu::selected_gpu`]:
|
/// Detect the encode-GPU vendor from the **selected render adapter** ([`crate::gpu::selected_gpu`]:
|
||||||
@@ -897,32 +920,55 @@ fn windows_gpu_vendor() -> Option<GpuVendor> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Probe the active Windows AMF/QSV backend for its encodable codecs (opens a tiny encoder per
|
/// Probe the active Windows AMF/QSV backend for its encodable codecs (cached **per (backend,
|
||||||
/// codec; cached **per (backend, selected GPU)** — a web-console preference change re-probes on the
|
/// selected GPU)** — a web-console preference change re-probes on the newly selected adapter
|
||||||
/// newly selected adapter instead of serving the old GPU's answer for the process lifetime).
|
/// instead of serving the old GPU's answer for the process lifetime). Mirrors
|
||||||
/// Mirrors [`vaapi_codec_support`]; called only when [`windows_backend_is_ffmpeg`] is true. AV1 is
|
/// [`vaapi_codec_support`]; called only when [`windows_backend_is_probed`] is true. AV1 is narrow
|
||||||
/// narrow (AMD RDNA3+, Intel Arc/Xe2+), so it must be probed, not assumed.
|
/// (AMD RDNA3+, Intel Arc/Xe2+), so it must be probed, not assumed.
|
||||||
#[cfg(all(target_os = "windows", feature = "amf-qsv"))]
|
///
|
||||||
|
/// Mirrors the session dispatch (design/native-amf-encoder.md Phase 3): **AMD advertises from the
|
||||||
|
/// native AMF factory probe alone** (`amf::probe_can_encode`, on the selected adapter — the same
|
||||||
|
/// path the session opens, so the advertisement can never claim a codec the session can't emit);
|
||||||
|
/// **Intel/QSV uses the libavcodec probe** (all-`false` without the `amf-qsv` feature, matching a
|
||||||
|
/// build that cannot open QSV at all).
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
pub fn windows_codec_support() -> CodecSupport {
|
pub fn windows_codec_support() -> CodecSupport {
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::{Mutex, OnceLock};
|
use std::sync::{Mutex, OnceLock};
|
||||||
static CACHE: OnceLock<Mutex<HashMap<String, CodecSupport>>> = OnceLock::new();
|
static CACHE: OnceLock<Mutex<HashMap<String, CodecSupport>>> = OnceLock::new();
|
||||||
let vendor = match windows_resolved_backend() {
|
let backend = windows_resolved_backend();
|
||||||
WindowsBackend::Qsv => ffmpeg_win::WinVendor::Qsv,
|
let key = format!("{backend:?}:{}", crate::gpu::selection_key());
|
||||||
_ => ffmpeg_win::WinVendor::Amf,
|
|
||||||
};
|
|
||||||
let key = format!("{vendor:?}:{}", crate::gpu::selection_key());
|
|
||||||
let cache = CACHE.get_or_init(|| Mutex::new(HashMap::new()));
|
let cache = CACHE.get_or_init(|| Mutex::new(HashMap::new()));
|
||||||
if let Some(c) = cache.lock().unwrap().get(&key) {
|
if let Some(c) = cache.lock().unwrap().get(&key) {
|
||||||
return *c;
|
return *c;
|
||||||
}
|
}
|
||||||
|
let probe_one = |codec: Codec| -> bool {
|
||||||
|
match backend {
|
||||||
|
// AMD: the native factory probe is authoritative — it opens exactly the component the
|
||||||
|
// session will, so the advertisement matches what the encoder can emit by construction.
|
||||||
|
WindowsBackend::Amf => amf::probe_can_encode(codec),
|
||||||
|
WindowsBackend::Qsv => {
|
||||||
|
#[cfg(feature = "amf-qsv")]
|
||||||
|
{
|
||||||
|
ffmpeg_win::probe_can_encode(ffmpeg_win::WinVendor::Qsv, codec)
|
||||||
|
}
|
||||||
|
#[cfg(not(feature = "amf-qsv"))]
|
||||||
|
{
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Callers gate on `windows_backend_is_probed` — defensively answer "nothing probed"
|
||||||
|
// (the advertisement then falls back to the static superset).
|
||||||
|
WindowsBackend::Nvenc | WindowsBackend::Software => false,
|
||||||
|
}
|
||||||
|
};
|
||||||
let caps = CodecSupport {
|
let caps = CodecSupport {
|
||||||
h264: ffmpeg_win::probe_can_encode(vendor, Codec::H264),
|
h264: probe_one(Codec::H264),
|
||||||
h265: ffmpeg_win::probe_can_encode(vendor, Codec::H265),
|
h265: probe_one(Codec::H265),
|
||||||
av1: ffmpeg_win::probe_can_encode(vendor, Codec::Av1),
|
av1: probe_one(Codec::Av1),
|
||||||
};
|
};
|
||||||
tracing::info!(
|
tracing::info!(
|
||||||
backend = ?vendor,
|
?backend,
|
||||||
h264 = caps.h264,
|
h264 = caps.h264,
|
||||||
h265 = caps.h265,
|
h265 = caps.h265,
|
||||||
av1 = caps.av1,
|
av1 = caps.av1,
|
||||||
@@ -933,8 +979,14 @@ pub fn windows_codec_support() -> CodecSupport {
|
|||||||
caps
|
caps
|
||||||
}
|
}
|
||||||
|
|
||||||
// Goal-1 stage 6: GPU/CPU encoders confined to `encode/windows/` (NVENC, AMF/QSV ffmpeg, software) and
|
// Goal-1 stage 6: GPU/CPU encoders confined to `encode/windows/` (NVENC, native AMF, AMF/QSV
|
||||||
// `encode/linux/` (NVENC/CUDA + VAAPI); `#[path]` keeps the `crate::encode::*` module names flat.
|
// ffmpeg, software) and `encode/linux/` (NVENC/CUDA + VAAPI); `#[path]` keeps the
|
||||||
|
// `crate::encode::*` module names flat.
|
||||||
|
// Native AMF (direct SDK, design/native-amf-encoder.md): compiled unconditionally on Windows —
|
||||||
|
// no build feature, the driver-installed amfrt64.dll resolves at runtime like NVENC's DLL.
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
#[path = "encode/windows/amf.rs"]
|
||||||
|
mod amf;
|
||||||
#[cfg(all(target_os = "windows", feature = "amf-qsv"))]
|
#[cfg(all(target_os = "windows", feature = "amf-qsv"))]
|
||||||
#[path = "encode/windows/ffmpeg_win.rs"]
|
#[path = "encode/windows/ffmpeg_win.rs"]
|
||||||
mod ffmpeg_win;
|
mod ffmpeg_win;
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -1,8 +1,15 @@
|
|||||||
//! AMD **AMF** and Intel **QSV** hardware encode on Windows via `ffmpeg-next` — the Windows
|
//! Intel **QSV** (and, retained-but-no-longer-dispatched, AMD **AMF**) hardware encode on Windows
|
||||||
//! analogue of the Linux [`super::vaapi`] backend (one libavcodec backend per vendor, selected by
|
//! via `ffmpeg-next` — the Windows analogue of the Linux [`super::vaapi`] backend (one libavcodec
|
||||||
//! encoder name: `*_amf` / `*_qsv`). This is the sibling of the direct-SDK [`super::nvenc`] path
|
//! backend per vendor, selected by encoder name: `*_qsv` / `*_amf`). Sibling of the direct-SDK
|
||||||
//! behind the shared [`Encoder`] trait, selected in [`super::open_video`] (NVIDIA → NVENC,
|
//! [`super::nvenc`] path behind the shared [`Encoder`] trait.
|
||||||
//! AMD → AMF, Intel → QSV).
|
//!
|
||||||
|
//! **Dispatch (design/native-amf-encoder.md Phase 3):** [`super::open_video`] routes AMD to the
|
||||||
|
//! direct-SDK [`super::amf`] encoder, not this module — the libavcodec AMF wrapper's ~2-frame
|
||||||
|
//! output hold and its silent-wedge failure mode are exactly why the native path exists. So in
|
||||||
|
//! production this file serves **QSV only**. The `WinVendor::Amf` machinery is kept (not deleted)
|
||||||
|
//! because it is the comparator in the native-vs-libavcodec latency A/B (`amf::tests::
|
||||||
|
//! amf_latency_ab_bench`), and excising it would churn the shared, Intel-unvalidated QSV code for
|
||||||
|
//! no production benefit. Treat every `WinVendor::Amf` arm below as benchmark-only.
|
||||||
//!
|
//!
|
||||||
//! The capturer hands a `FramePayload::D3d11` texture (NV12/P010 from the D3D11 video processor, or
|
//! The capturer hands a `FramePayload::D3d11` texture (NV12/P010 from the D3D11 video processor, or
|
||||||
//! BGRA/Rgb10a2 as a fallback) on the capturer's own `ID3D11Device`. Two input paths, chosen lazily
|
//! BGRA/Rgb10a2 as a fallback) on the capturer's own `ID3D11Device`. Two input paths, chosen lazily
|
||||||
|
|||||||
@@ -77,9 +77,10 @@ fn base_codec_mode_support() -> u32 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Windows AMD/Intel (AMF/QSV): advertise only what the GPU actually encodes (AV1 is narrow, an
|
// Windows AMD/Intel (AMF/QSV): advertise only what the GPU actually encodes (AV1 is narrow, an
|
||||||
// old iGPU might lack HEVC). NVENC and the GPU-less software path keep the static superset.
|
// old iGPU might lack HEVC). AMF probes natively (no build feature needed); QSV needs the
|
||||||
#[cfg(all(target_os = "windows", feature = "amf-qsv"))]
|
// libavcodec build. NVENC and the GPU-less software path keep the static superset.
|
||||||
if crate::encode::windows_backend_is_ffmpeg() {
|
#[cfg(target_os = "windows")]
|
||||||
|
if crate::encode::windows_backend_is_probed() {
|
||||||
if let Some(m) = probed_mask(crate::encode::windows_codec_support()) {
|
if let Some(m) = probed_mask(crate::encode::windows_codec_support()) {
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
@@ -91,7 +92,7 @@ fn base_codec_mode_support() -> u32 {
|
|||||||
/// or `None` if the probe found nothing — meaning the GPU wasn't usable at probe time (GPU-less CI,
|
/// or `None` if the probe found nothing — meaning the GPU wasn't usable at probe time (GPU-less CI,
|
||||||
/// a misconfigured/wrong-vendor host), NOT that it encodes zero codecs; the caller then advertises
|
/// a misconfigured/wrong-vendor host), NOT that it encodes zero codecs; the caller then advertises
|
||||||
/// the static superset (pre-probe behaviour) rather than claiming nothing.
|
/// the static superset (pre-probe behaviour) rather than claiming nothing.
|
||||||
#[cfg(any(target_os = "linux", all(target_os = "windows", feature = "amf-qsv")))]
|
#[cfg(any(target_os = "linux", target_os = "windows"))]
|
||||||
fn probed_mask(caps: crate::encode::CodecSupport) -> Option<u32> {
|
fn probed_mask(caps: crate::encode::CodecSupport) -> Option<u32> {
|
||||||
use super::{SCM_AV1_MAIN8, SCM_H264, SCM_HEVC};
|
use super::{SCM_AV1_MAIN8, SCM_H264, SCM_HEVC};
|
||||||
let mut m = 0;
|
let mut m = 0;
|
||||||
|
|||||||
@@ -1,11 +1,28 @@
|
|||||||
# Native AMF encoder — handoff design
|
# Native AMF encoder — handoff design
|
||||||
|
|
||||||
> **Status: PROPOSED (handoff, 2026-07-06).** Design + decision record for replacing the
|
> **Status: PHASES 1 + 2 + 3 IMPLEMENTED (2026-07-06).** `encode/windows/amf.rs` ships the
|
||||||
> libavcodec `*_amf` path with a direct AMF SDK encoder on Windows AMD
|
> direct-SDK encoder per §3 — FFI pinned to AMF headers v1.4.36, bounded poll, native `reset()`.
|
||||||
> (`encode/windows/amf.rs`, the AMD analogue of the direct-SDK `encode/windows/nvenc.rs`).
|
> Phase 2: **AV1** (open-time probe gate; per-codec enum divergences honored — AV1 swaps the
|
||||||
> Written for an implementer without prior context; every in-repo seam is named. Companion
|
> ULL/LL usage values and uses GOP=0 + FORCE_FRAME_TYPE_KEY=1), **intra-refresh**
|
||||||
> context: the encode-stall watchdog + `Encoder::reset()` (punktfunk1.rs / encode.rs, shipped
|
> (`PUNKTFUNK_INTRA_REFRESH` opt-in mirroring Linux NVENC; `caps().intra_refresh` reflects the
|
||||||
> 2026-07-06) and the AMF/QSV backend module docs in `encode/windows/ffmpeg_win.rs`.
|
> driver's actual acceptance), **in-band HDR mastering/CLL metadata** (`*InHDRMetadata` host
|
||||||
|
> buffer; HEVC + AV1), and the **native codec probe**. Phase 3: **the ffmpeg-AMF dispatch
|
||||||
|
> fallback + `PUNKTFUNK_AMF_FFMPEG` hatch are deleted** — AMD dispatch / codec advertisement /
|
||||||
|
> 4:4:4 answer are native-only; FFmpeg serves QSV only (`ffmpeg_win.rs`'s AMF machinery is kept
|
||||||
|
> solely as the A/B comparator). `windows_backend_is_ffmpeg` → `windows_backend_is_probed`. **The
|
||||||
|
> §7 field-silence gate on Phase 3 was pre-empted on explicit direction** — see the §7 gate note
|
||||||
|
> for what that costs (VP-format-fallback now fails the session; AMFVideoConverter is the owed
|
||||||
|
> native fix).
|
||||||
|
> Live-validated on the lab Ryzen iGPU (VCN 3): AVC + HEVC batches across a native in-place reset
|
||||||
|
> (Annex-B IDR contract, FIFO pairing); HEVC Main10 P010 with the mastering + CLL prefix SEIs
|
||||||
|
> **confirmed present in the encoded IDR**; intra-refresh property accepted on both codecs; probe
|
||||||
|
> honestly answers h264/h265=true, av1=false on this RDNA2 part. The **§5.2 latency A/B is
|
||||||
|
> measured** (`amf_latency_ab_bench`, 1080p60 HEVC): native `encode_us` p50 **5.18 ms (0.31 frame
|
||||||
|
> periods)** vs libavcodec-AMF **16.9 ms (1.01)** — 3.3× lower, the frame-hold gone. Owed: §5.3
|
||||||
|
> on-glass session behaviors + soak (macOS-client on-glass test in progress), and field
|
||||||
|
> validation on ≥2 VCN generations (AV1/RDNA3 has no lab hardware).
|
||||||
|
> Companion context: the encode-stall watchdog + `Encoder::reset()` (punktfunk1.rs / encode.rs,
|
||||||
|
> shipped 2026-07-06) and the QSV backend module docs in `encode/windows/ffmpeg_win.rs`.
|
||||||
|
|
||||||
## 1. Why (measured, not speculative)
|
## 1. Why (measured, not speculative)
|
||||||
|
|
||||||
@@ -142,8 +159,21 @@ log-and-continue, not fatal — availability varies by VCN generation/driver.
|
|||||||
|
|
||||||
### 3.5 Error + stall semantics (interplay with the 2026-07-06 watchdog)
|
### 3.5 Error + stall semantics (interplay with the 2026-07-06 watchdog)
|
||||||
|
|
||||||
- `SubmitInput` → `AMF_INPUT_FULL`: return `Err` from `submit` — the session loop's
|
- `SubmitInput` → `AMF_INPUT_FULL`: **back-pressure, NOT a wedge — drain and retry, do not
|
||||||
submit-failure path runs the bounded in-place reset. Any other non-OK result: `Err`.
|
reset.** (Original prescription "return `Err` → in-place reset" was **wrong**, disproven
|
||||||
|
on-glass 2026-07-06: at throughput-ceiling loads — 5120x1440@240 P010 on the lab iGPU —
|
||||||
|
`INPUT_FULL` → reset → forced IDR → a bigger keyframe → worse overload → a ~320 ms
|
||||||
|
reset/IDR cascade, strictly worse than the libavcodec path's 16-deep input queue riding it
|
||||||
|
out as latency. The log showed dozens of `submit failed … AMF_INPUT_FULL … rebuilt in place`
|
||||||
|
and **zero** watchdog stalls.) The shipped handling: `submit` bounds in-flight surfaces below
|
||||||
|
the input ring depth (`pending.len() < RING`) by draining finished AUs (buffered in a `ready`
|
||||||
|
deque for `poll`, FIFO-preserved) to free a slot *before* reusing it, and treats a stray
|
||||||
|
`INPUT_FULL` from `SubmitInput` the same way (drain + retry the surface). Only a drain that
|
||||||
|
makes NO progress for a bounded budget (`INPUT_DRAIN_BUDGET`, 200 ms — well under the
|
||||||
|
session watchdog's ~2 s) is a genuine wedge that escalates to `Err` → the in-place reset. This
|
||||||
|
also closed a **latent corruption**: the old path let in-flight grow to AMF's internal input
|
||||||
|
queue limit (16) against a ring of 4, so surfaces referenced ring slots already overwritten —
|
||||||
|
the reset masked it. Any other non-OK `SubmitInput` result: `Err`.
|
||||||
- `QueryOutput` → `AMF_REPEAT`: keep spinning within the poll budget, then `Ok(None)`.
|
- `QueryOutput` → `AMF_REPEAT`: keep spinning within the poll budget, then `Ok(None)`.
|
||||||
`AMF_EOF`: `Ok(None)` after flush. Anything else: `Err` (the loop's poll-error path
|
`AMF_EOF`: `Ok(None)` after flush. Anything else: `Err` (the loop's poll-error path
|
||||||
resets).
|
resets).
|
||||||
@@ -189,13 +219,27 @@ Baseline first, on the ffmpeg path (already deployed 2026-07-06 with the watchdo
|
|||||||
long session on the iGPU with `PUNKTFUNK_PERF=1`, record `wait_us_p50/p99`,
|
long session on the iGPU with `PUNKTFUNK_PERF=1`, record `wait_us_p50/p99`,
|
||||||
`encode_us`, client-measured latency, and whether the watchdog ever fires. Then per phase:
|
`encode_us`, client-measured latency, and whether the watchdog ever fires. Then per phase:
|
||||||
|
|
||||||
1. Open/probe smoke per codec (AVC, HEVC, HEVC-10) on the iGPU.
|
1. Open/probe smoke per codec (AVC, HEVC, HEVC-10) on the iGPU. **DONE** — the gated live
|
||||||
|
tests in `amf.rs` (`amf_encode_live_smoke` AVC+HEVC+AV1-probe, `amf_hdr_encode_live_smoke`,
|
||||||
|
`amf_native_probe_live`, `amf_intra_refresh_property_live`) pass on the lab Ryzen iGPU
|
||||||
|
(VCN3/RDNA2): both codecs across a native `reset()`, HEVC Main10 IDR carrying the
|
||||||
|
mastering(137)+CLL(144) SEIs byte-verified, intra-refresh property accepted, probe honestly
|
||||||
|
`h264/h265=true, av1=false`.
|
||||||
2. A/B the encode latency: expect `encode_us` p50 ~2 frame periods → ≤ 1 frame period
|
2. A/B the encode latency: expect `encode_us` p50 ~2 frame periods → ≤ 1 frame period
|
||||||
(see §3.3 for why `wait_us` is the wrong metric on the ffmpeg side); client
|
(see §3.3 for why `wait_us` is the wrong metric on the ffmpeg side). **MEASURED**
|
||||||
capture→glass p50 drops by ~30 ms at 60 Hz / ~17 ms at 120 Hz. Zero-copy baseline for
|
2026-07-06 by the gated `amf_latency_ab_bench` (`PUNKTFUNK_AMF_BENCH=1`, 1080p60 HEVC,
|
||||||
the input side already measured 2026-07-06 on the lab iGPU (1080p120 HDR P010):
|
180 paced frames, same D3D11 NV12 input to both encoders, lab iGPU, debug build):
|
||||||
`submit_us` p50 2.7–2.9 ms (system readback) → **0.26 ms** (zero-copy D3D11), p99
|
native `encode_us` p50 **5.18 ms (0.31 frame periods)** / p99 5.81 ms vs libavcodec-AMF
|
||||||
6.6 ms → 0.5 ms.
|
p50 **16.9 ms (1.01 frame periods)** / p99 17.5 ms — **3.3× lower, ~11.7 ms/frame saved**,
|
||||||
|
and the native path is decisively sub-frame (the ~2-frame hold that used to live in
|
||||||
|
`encode_us` is gone). Note the ffmpeg baseline came in at ~1 frame period, not the ~2 this
|
||||||
|
plan projected: the shipping ffmpeg config already sets AMF `latency=true` (a ~1-frame
|
||||||
|
hold), so the realized win is 3.3× / ~12 ms rather than the ~30 ms projected against an
|
||||||
|
un-tuned 2-frame baseline; direction and sub-frame collapse are exactly as §3.3 described.
|
||||||
|
Release builds should show a lower native number still (debug charges host-side
|
||||||
|
surface-create + copy-submit into the 5.18 ms). Zero-copy baseline for the input side
|
||||||
|
already measured 2026-07-06 on the lab iGPU (1080p120 HDR P010): `submit_us` p50 2.7–2.9 ms
|
||||||
|
(system readback) → **0.26 ms** (zero-copy D3D11), p99 6.6 ms → 0.5 ms.
|
||||||
3. Behavior: IDR on connect; mode switch mid-stream; HDR session (PQ VUI + 0xCE
|
3. Behavior: IDR on connect; mode switch mid-stream; HDR session (PQ VUI + 0xCE
|
||||||
convergence); client keyframe-request recovery; encoder `reset()` under an injected
|
convergence); client keyframe-request recovery; encoder `reset()` under an injected
|
||||||
failure; ≥30 min soak for the freeze class (watchdog log line
|
failure; ≥30 min soak for the freeze class (watchdog log line
|
||||||
@@ -221,8 +265,23 @@ long session on the iGPU with `PUNKTFUNK_PERF=1`, record `wait_us_p50/p99`,
|
|||||||
|
|
||||||
## 7. Phasing
|
## 7. Phasing
|
||||||
|
|
||||||
| Phase | Scope | Exit criterion |
|
| Phase | Scope | Exit criterion | Status |
|
||||||
| --- | --- | --- |
|
| --- | --- | --- | --- |
|
||||||
| 1 | FFI layer + AVC/HEVC (SDR + 10-bit HDR), bounded poll, native `reset()`, dispatch with ffmpeg fallback + `PUNKTFUNK_AMF_FFMPEG` hatch | §5.2–5.3 pass on the lab iGPU |
|
| 1 | FFI layer + AVC/HEVC (SDR + 10-bit HDR), bounded poll, native `reset()`, dispatch with ffmpeg fallback + `PUNKTFUNK_AMF_FFMPEG` hatch | §5.2–5.3 pass on the lab iGPU | **DONE** 2026-07-06 (§5.2 measured; §5.3 on-glass in progress) |
|
||||||
| 2 | Intra-refresh (`caps().intra_refresh`), in-band HDR SEI (`supports_hdr_metadata`), AV1, native codec probe | field-validated on ≥2 VCN generations |
|
| 2 | Intra-refresh (`caps().intra_refresh`), in-band HDR SEI (`supports_hdr_metadata`), AV1, native codec probe | field-validated on ≥2 VCN generations | **CODE DONE** 2026-07-06 (lab VCN3 only; AV1/RDNA3 + 2nd VCN gen still owed) |
|
||||||
| 3 | Delete the ffmpeg-AMF dispatch arm + hatch; FFmpeg remains QSV-only | one release of field silence on the fallback label |
|
| 3 | Delete the ffmpeg-AMF dispatch arm + hatch; FFmpeg remains QSV-only | one release of field silence on the fallback label | **DONE** 2026-07-06 — see the gate note below |
|
||||||
|
|
||||||
|
**Phase 3 gate note (honesty):** the stated exit criterion (one release of field silence on the
|
||||||
|
fallback label) was **NOT met** — Phase 3 was cut the same day the native path was written, on
|
||||||
|
explicit direction, alongside a live macOS-client on-glass test. What Phase 3 removed: the
|
||||||
|
`WindowsBackend::Amf` libavcodec fallback arm, the `PUNKTFUNK_AMF_FFMPEG` hatch, and the
|
||||||
|
AMF→ffmpeg routes in `windows_codec_support` / `can_encode_444`. AMD dispatch, codec
|
||||||
|
advertisement, and the 4:4:4 answer are all native-only now; FFmpeg (`ffmpeg_win.rs`) is reached
|
||||||
|
only for QSV in production (its `WinVendor::Amf` machinery is retained solely as the
|
||||||
|
`amf_latency_ab_bench` comparator, not deleted — excising it would churn the Intel-unvalidated
|
||||||
|
QSV code for no gain). **Residual risk this pre-emption carries:** with the ffmpeg readback path
|
||||||
|
gone, an AMD box whose capturer can't produce video-processor NV12/P010 (falls back to
|
||||||
|
Bgra/Rgb10a2, or hands DDA CPU frames) now **fails the session** instead of degrading — the
|
||||||
|
design's answer is the native AMFVideoConverter front-end (§3.2), owed if that fallback is ever
|
||||||
|
seen in the field. Not observed on lab hardware (the VP yields NV12/P010). Reverting Phase 3 is a
|
||||||
|
small, localized diff if field data turns up trouble.
|
||||||
|
|||||||
Reference in New Issue
Block a user