Files
reims-vgpu/docs/video
Anees Iqbal ff96c37f07 🐎 Make a decode session's surfaces as its pictures need them
A VA-API decode session made its surface pool up front, its DPB, the picture
and two spare, at the stream's coded size, and gave them to its context as
render targets. A session whose pictures land in the device's caches decodes
only its references into surfaces of its own, so it held surfaces no picture
used.

The pool now starts empty and the context is made with no render targets. The
pool makes a surface when a picture is to be decoded into one of its own and
none is free, up to 48, and lends the one freed last first. A kept context's
shape no longer holds a surface count. Mesa's vlVaCreateContext reads no
render target (read from code, Mesa 26.2.4), and surface::lazy's tests check
the decision off the GPU and, on it, that streams of the driver's own encoder
decode to the same pictures with surfaces made as needed as made up front.

Measured with the process's DRM fdinfo, 8 surfaces at 1080p NV12, 4K NV12 and
4K P010:
- radeonsi (Mesa 26.2.6; Radeon 780M, m3-max-64940; RX 7900 XTX, -64945) makes
  no buffer until a surface's first use: +0.0 MiB once made, then 31, 108 and
  203 MiB on the 780M (41, 144, 279 on the XTX) once each held an image. Nothing
  changes there.
- iHD 26.3.5 (Iris Xe, m3-max-64988) makes each surface's buffer object at its
  full size when the surface is made, +28, +96 and +192 MiB drm-total, and
  backs none of it until first use (drm-resident +0.0). A session no longer
  holds the objects of surfaces it never decodes into.
- On Windows each surface made is a committed D3D12 resource
  (CreateCommittedResource in d3d12.rs's shared_texture, read from code), which
  allocates when it is made: a session whose pictures land in caches no longer
  holds its spare surfaces' memory there. Not measured.

A make takes 0.001 ms or less on radeonsi and 0.004 ms on iHD. The first
access unit, which holds the config, context and first surfaces, took the same
time either way within the runs' spread on all three GPUs (H.264 1080p on the
XTX 12.95 ms as needed, 13.18 up front), with two or three surfaces made as
needed against five up front.

Nothing changes for the guest: the device's answers, the pictures and their
order are the same.
2026-11-21 14:07:25 -08:00
..