On the rt platform on Linux a decode's picture lands in its output's device
cache by the driver's video processing writing the cache in place, and where
the driver's import refuses the cache's layout, by the CPU: the frame read
back into host memory, copied into the session's staging and from there into
the cache. The guest's decoder asks its outputs of CoreVideo, which lays them
out itself (measured: at 1920x1080, rows of 1920 bytes, the luma plane at
byte 32 and the chroma at byte 2088992), and radeonsi's import refuses that
on the AMD GPUs we have: the RX 550's refuses rows below its pitch of 2048
bytes, the 780M's rows off a multiple of 256. On the RX 550 a walk's 1080p
H.264 and HEVC clips took that way for each of their 894 pictures (walk b1,
m3-max-66052).
Now the session's copier, gpu_copy's ScratchCopier, takes such a picture at
that refusal: the driver's video processing writes the picture into a
scratch of the session's, laid out as the driver's imports must be (each
plane at its dma-buf's first byte or whole rows after it, the even width's
rows at a pitch on 256), and fill's videoEncodeFill kernel copies each
plane's crop from it into the cache at the cache's own offset and pitch, as
plain words; the copy is waited for before the picture counts as landed, as
the CPU's copy is. The copier is reached only where the in-place write was
refused, for a plane in a device cache outside its surface, whatever the
GPU or its driver: every host whose import refuses the guest's rows takes it
(the RX 550 and the 780M), and none is chosen by name. It declines, so that
the CPU copies as before, a plane in the guest's pages or in a surface, a
crop that does not fill its rows in whole 32-bit words (rows of 1366 or 642
bytes), and an offset or pitch off a word.
Where the platform "makes no GPU copies" on Linux: f716a52d2a opened VA-API
on rt with no copier, and 13fb154934 kept it ("the copies make no copier,
for the same reason as before"), the reason f716a52d2a gave being only "as
no GPU copier is given". Neither, nor docs/conventions.md or lessons.md,
records a measured cost, a driver trap or a rule for it: the copier was not
built yet. This crosses no rule of the Vulkan platform's.
GPU memory stays the runtime's: the scratch is rt's, a dma-buf buffer made
through rt and exported through rt's API, one per session, zeroed by a blit
at its make. It is host-only: the guest never maps it, nothing read from it
decides anything, and the kernel's bounds come from the planes' layouts the
host computed. The driver writes it as it writes an in-place cache, the
runtime acquires it after (external_write_done), and the kernel reads only
bytes the driver wrote.
Guest-invisible: each plane's crop rows are the bytes the CPU's copy writes
and every other byte of the cache is as its fill left it, the layout the
device answers is unchanged, and the picture lands at the same point of its
decode. The ignored test
a_picture_copied_by_the_gpu_from_its_scratch_is_the_cpus_copy
compares every byte of the cache with the CPU's copy: 32 pictures of 8
streams (H.264, HEVC and HEVC Main10, 640x360 to 3840x2160) equal on the
RX 550 (m3-max-66105) and the 780M (m3-max-66127), the 1366x768 and 642x362
streams declined.
Each picture so copied counts video-pictures-gpu-copied and its crop's KiB
video-gpu-copied-kib, and a session logs its copies at its end. The fills'
test that held "the platform makes no GPU copies" now holds that the
device's fills make a copier each decode session.