A kept decoder served a new session of its format only with surfaces
enough, so a guest's 400x258 HEVC thumbnail, which asks for 8, still made
its decoder in its first session (cuvidCreateDecoder, 43 ms on an RTX 3090)
while the wallpaper's 1024x1024 decoder of 5 surfaces was kept
(m3-max-83451).
A kept 4:2:0 decoder at 8 or 10 bits with fewer surfaces than asked is now
taken and reconfigured to the asked count with the asked size, before its
first decode (Made::fit). NVIDIA's headers document that a reconfiguration
may raise the count: dynlink_nvcuvid.h of ffnvcodec-headers 13.1.15.0,
lines 505-507, on CUVIDPARSERPARAMS::bMemoryOptimize, "use
cuvidReconfigureDecoder() to increase the decode surfaces if needed (perf
may get impacted)", quoted at the take. A reconfiguration NVDEC refuses
destroys the kept decoder and makes one with the asked surfaces, so no
picture is decoded on the old count; a test fails the reconfiguration and
counts the make. The take left out a kept decoder of another GPU by
counting its surfaces as none, which a decoder that adds surfaces would
take; it now leaves it out by its GPU (pick_on_gpu), with a test.
VP9 is left out (adds_surfaces), decided before the take: on an RTX 3090
with driver 620.70.06, a kept VP9 decoder made with 2 surfaces and
reconfigured to the 11 a libvpx stream asks, cuvidReconfigureDecoder
returning success, refused the stream's second sample, a superframe whose
frames take surfaces 1 and 2, with CUDA_ERROR_INVALID_VALUE, where a
decoder made for the stream decodes it (m3-max-83719). VP9 takes only a
kept decoder with surfaces enough, as do monochrome, 4:2:2, 4:4:4 and 12
bits of their own size (D32); a test keeps a 2-surface VP9 decoder and
checks that the stream makes its own and decodes to libvpx's frames.
Measured on an RTX 3090, driver 620.70.06 (m3-max-83840; the same tests pass
on this tree, m3-max-84002): a kept 1024x1024 decoder made with 2 surfaces,
raised to as many as the stream asks, decodes H.264 High, HEVC Main and Main
10 and AV1 streams, every picture held until no surface is free (14, 8 and
8, and 17 each for SVT-AV1's streams at 8 and 10 bits), to the pictures of a
decoder made for them, and is taken for 400x272 with 8 surfaces in 3.4-4.1
ms, its reconfiguration included, against 10.8-12.4 ms for one made. A
400x258 HEVC stream's first picture, from its decoder's start through its
decode and read-back, took 7.1-7.4 ms on a kept 1024x1024 decoder raised
from 5 surfaces, 6.9-7.2 ms on one with surfaces enough and 14.1-15.0 ms on
one made (m3-max-83971, a probe).
What the guest sees: a session of a new size and more surfaces than the
kept decoder of its format has starts without a decoder made. In a macOS
26.7.2 guest's boot with this change's first form, whose HEVC take is this
one (m3-max-83913), the thumbnail's first session, 25.8 s after the GPU's
last work, took the kept 1024x1024 decoder of 5 surfaces and raised it to
8: its first decode call took 11.7 ms (cuvidReconfigureDecoder 11.66 ms)
against 42.8-43.4 ms with cuvidCreateDecoder (m3-max-83275, m3-max-83451),
but its first picture's map took 31.6 ms against under 1 ms, and the
session ended 101.5 ms after its make, against 77.7 and 98.6 ms. A later
session of that boot, 26.7 s after the last work, made and reconfigured
nothing and still took 30.4 ms to land its first picture: after such an
idle the first landing pays about 30 ms unless a make came before it.
(cherry picked from commit 1703dc3b211ade4276049fc1f3a4a066525dde68)