Skip to main content

nvenc_negotiate

Function nvenc_negotiate 

Source
fn nvenc_negotiate(lib: &NvencLibrary)
Expand description

Resolve the process-wide NVENC API version once, by probing the driver newest-first and remembering the highest version it accepts.

The bundled nv-codec-headers are NVENC 13.0 (pinned), so a current driver negotiates 13.0 natively while older drivers down-negotiate through 12.x / 11.x to the 10.0 floor (~R445). The compiled struct layouts are the 13.0 ones, handed to older drivers with the tail their own layouts run longer (Negotiated); only the version words change per negotiated version (via the NvStruct::rev table), so each struct is stamped with the exact word the negotiated SDK defined. Steps:

  1. Cap the search by the driver’s max: query get_max_version when present, then optionally lower it further from PIXELFLUX_NVENC_MAX_API (e.g. "11.0") for testing / pinning. A cap of 0 means unknown, and probing then relies on create_instance acceptance alone.
  2. Probe candidates newest-first (pinned, 12.1, 12.0, 11.1, 11.0, 10.0), skipping any above the cap. Each probe stamps an NV_ENCODE_API_FUNCTION_LIST with that version’s word and calls create_instance.
  3. Require the whole encode path, not just a success code: the session opener plus nvEncInitializeEncoder, nvEncGetEncodePresetConfigEx, nvEncEncodePicture, and nvEncLockBitstream must all be non-null, because a driver can accept the function-list word yet leave newer entry points null. The first fully-populated version wins.
  4. Fall back to pinned if nothing qualifies. Stored in NVENC_NEG_VER, set-once.