A guest that drops a frame's access unit and has the same frame coded again
had no way to say so: each encode was a new frame of the stream, coded after
the dropped one and predicting from it. macOS's HEVC encoder plug-in does that
over its data rate limit, at a higher QP, and the stream broke: gaps in its
order counts and VideoToolbox decode errors -17694 on 151 and 166 of 300
frames (macOS 26.7.2 guest, RX 7900 XTX host, m3-max-77530).
What the guest and host observe now:
- the wire: an encode op's flag RGFX_VIDEO_ENCODE_IN_PLACE codes the frame in
place of the session's last one, from the references the last one was
coded from, with its order count and frame_index, at the QP the settings
give now; the caps' RgfxVideoEncodeCaps::flags gains
RGFX_VIDEO_ENCODE_CAP_IN_PLACE where the host does so (zero from an older
host);
- VA-API: every encode entry has the flag. The VA crate's encoder holds its
last picture back from the accelerator's stream (Accelerator::keep) until
the next frame or a flush, and codes a frame in place again into the same
reconstructed surface (Encoder::encode_in_place); a stream without B
pictures or our hard limit, which is every one the x86-64 guest makes;
- NVENC: the flag where NVENC answers NV_ENC_CAPS_DISABLE_ENC_STATE_ADVANCE
for every profile of the codec and a session of it with a state buffer
codes a frame, the frame again in place and a frame after it at the
device's start (checked_in_place); a driver that refuses either leaves it
off. Such a session codes each frame without advancing NVENC's state and
takes the state after it (nvEncRestoreEncoderState) as the next frame
comes (NvencEncoder::new_in_place);
- a frame that cannot be coded in place fails (RGFX_VIDEO_ENCODE_FAILED):
with no frame to replace, with B pictures, with the VA crate's hard limit,
of another frame_index, or asking a keyframe in place of a frame that is
not one. No later frame predicts from the dropped one: on VA-API the next
is an IDR picture, on NVENC it is coded from the state before the dropped
one.
A frame without the flag is coded as before; the VA crate keeps its last
picture one frame later, which nothing outside it observes. No guest sends
the flag yet: the x86-64 guest's HEVC route, next, does.
Tests: the codec encoder's frames in place (the stream is the one without the
retry but for its QP; twice in a row; after and of an IDR picture; each
refusal, after which the next frame is an IDR picture), the session handing
the flag to its backend, each arm's caps flag, and on the hardware, frames in
place decoding back on the driver's own decoder (RX 7900 XTX, radeonsi,
m3-max-77595) and on NVDEC above 35 dB (RTX 2080, m3-max-77597; RTX 3090,
m3-max-77618), and the device-start check leaving no NVENC session on its GPU,
which runs alone (.config/nextest.toml): it adds a median of 61.9 ms on the
RTX 2080 and 56.9 ms on the RTX 3090, five checks each.