ScheduleCommands held one lock across every context's list, so while the
driver made the first textures over a new output surface of one session
(which wait for the host: on the Radeon 780M about 10 ms a surface, 17 of
them as playback starts), every other session of the process waited too.
With three AVPlayers in one process the guest's first decodes ran in
lockstep, one session at a time, and the start of three players took
800-870 ms to their clocks against 183-217 ms on a native Mac.
Each context now holds a lock of its own across its list, so its pictures
still reach its session in AppleGVA's order while other contexts' lists go
on.
The host refuses an H.264 picture of a coded size outside its caps once the
picture reaches it, and AppleGVA's H.264 decoder hears of no failure after its
create, so such a stream reached the client as undecoded frames. CreateContexts
names the coded size, so the driver refuses the context there, as it does a
context whose host session cannot be opened: the client's session create fails,
and VideoToolbox turns to its software decoder for a client that allows it.
HEVC is left as it was: AppleGVA reports its pictures' refusals.
For the guest: such a stream's VTDecompressionSessionCreate fails where it
decoded nothing.
The check scheduled it on a session that had sent its parameter sets, so the
picture went without them and lands() took it for a wrong send. A fresh session
sends them, as the check expects.
checkHostVerdict and checkH264SpsLayouts read g_verdict and g_waits outside
the stubs' namespace, where the last commit left them unseen, and the driver
tests' build failed. They now sit beside g_work.
AppleGVA's decode flow takes every query of a decode for its completion
and reads no status or error from it (read from its code on macOS
26.7.1); the one failure it reports to VideoToolbox is a failed
schedule. The driver answered a query of a decode the host was still
running as running and never looked at its token again, so a host
failure that came after the query was lost: the guest got the untouched
surface as a decoded frame and no error. Only a failure the host had
already reported at the query failed the session's next schedule, two
pictures late.
Now the schedule of an HEVC picture waits for the host's verdict on it,
out of the lock that orders the sessions' pictures, and fails where the
host failed it. What changes for the guest: an HEVC decode's
ScheduleCommands returns once the host has decoded the picture, and a
picture the host fails gets kVTVideoDecoderMalfunctionErr itself, from
that frame on, instead of two frames later or never. H.264 is unchanged:
AppleGVA's H.264 pipelines keep no decode's result, so its schedule waits
for no verdict (docs/video/bugs.md D25, now H.264's alone).
The tests that held the deferred failure (failsLaterSchedule,
queryReport) change with it, and checkHostVerdict drives the schedule
through a host that fails one picture.
An HEVC picture that the host refuses was sent anyway, and the refusal came
back only at the host. AppleGVA takes such a picture, and the one after it,
for decoded (D25), so VideoToolbox delivered two wrong frames before
-12911. The refused pictures were: one whose coded size was outside the
caps; one whose PPS had a tile column narrower than the host decodes; and one
whose current reference sets held more pictures than the caps'
max_references, as kvz-720p-ref15's tenth picture does.
The driver now checks each picture against its HEVC decode entry and the
entry's decode caps before it sends it (hevcTaken). It reads NumPicTotalCurr
from the first slice segment's header (h265::currentReferences): its own
short-term set or the SPS's, with prediction, and its long-term pictures.
It works out the PPS's narrowest tile column with 6.5.1's layout
(h265::narrowestTileColumn). A picture that fails the check fails its
schedule. VideoToolbox reports kVTVideoDecoderMalfunctionErr for that frame
and every one after it, where it used to deliver two wrong frames. A bound
of 0 refuses nothing, and a header the driver cannot read leaves the verdict
to the host. kvz-720p-ref15 now decodes 9 frames and then fails, as it does
on an M3's VideoToolbox. H.264 gets no such check: AppleGVA's H.264 decoder
delivers a picture whose schedule failed.
The kext set is built again with the bundle.
On macOS 11 every H.264 picture above AppleGVA's size floor decoded to an
all-zero frame. AppleGVA 11 (108.7.2) parses the SPS header in H.264's
older syntax: four constraint flags, then one field for the four bits after
them. Later releases hold six flags and two reserved bits there. So in 11's
parsed SPS every field from level_idc on sits 8 bytes earlier than the
driver's Sps. The driver read the record as Sps and sent the host an SPS
with the wrong level, reference count and size. The host refused it
("max_num_ref_frames is out of range", then "PPS 0 has not been received"
for each picture after), and AppleGVA's H.264 decoder reports no failure,
so the guest got untouched frames with errors=0.
The record does not say its layout, so the driver now takes, once a
session, the one layout in which the record describes the picture
(chooseSpsLayout). The checks are ones a misplaced record cannot pass by
chance:
- profile_idc and level_idc are values H.264 defines;
- the SPS's seq_parameter_set_id is its PPS's;
- the coded size is the one the output surface's size rounds up to, in
whole macroblocks (of a field pair where frame_mbs_only_flag is 0).
A record that fits no layout, or both, is refused and logged. So is a later
picture of the session that does not fit the session's layout. Nothing is
guessed. The four header bits of 11's field come back as
constraint_set4_flag, constraint_set5_flag and the reserved bits, and the
SPS written holds them as the stream did.
The layouts were measured on the guest (780M host, 2026-11-08) from a
640x480 x264 stream's records. 11.7.11 holds level_idc at 0x1c, the size at
0x820 and 0x824 and max_num_ref_frames at 0x818; 12.7.6, 13.7.8 and 26.7.2
hold them where Sps does. This matches AppleGVA 108.7.2's own reads (read
from its code). The parsed PPS has one layout on all four releases.
Tests: each of the seven x264 streams is read back whole from records of
both layouts, and only in its own, at its shown size and its coded size but
not a macroblock smaller, and not against a PPS of another SPS. The four
header bits are written back. A record that fits no layout and one that
fits both are refused. A driver session keeps the layout its first picture
showed, and refuses the other layout, a record of neither and a surface too
narrow, sending nothing of them to the host.
The driver searched AppleGVA's HEVC frame record for its surface's
description from +0x70 to +0xa0, and macOS 11.7.10 and 11.7.11 keep it at
+0x70, the window's first start: an 11 release whose record began one field
lower would have had every HEVC picture refused. Measured since: 4-byte
fields from +0x70 on 11.7.10 and 11.7.11, from +0x78 on 12.7.6 and from
+0x80 on 13.7.8; 8-byte fields from +0x80 on 14.8.9 and from +0x88 on 15.8.2
and 26.7.2. The description moves 8 bytes a release from 11 to 13.
The window now starts at +0x60, two 8-byte steps below 11's start, for the
11 releases before 11.7.10, which no base boots. In the frame words read on
11.7.11, 12.7.6, 13.7.8, 14.8.9, 15.8.2 and 26.7.2 (from +0x60 to +0xdc), no
start and width in the wider window but each release's own reads the
surface's width, height and pixel format, so no measured record becomes
ambiguous. The tests now cover every measured layout and the window's new
ends.
What changes for the guest: an HEVC frame record whose description starts
from +0x60 to +0x6c lands its picture instead of being refused; on every
release measured the surface found is the one it was.
An HEVC decode names its output surface only in AppleGVA's own frame
record, and the driver read the surface's id at the frame's +0x88, where
macOS 26 keeps it. Every release measured describes the surface with the
same fields, its id, a size, its width, its height, a pitch, 8 bytes and its
pixel format, but where they start and how wide each is differ: macOS
26.7.2's are 8 bytes each from +0x88, 14.8.9's 8 bytes each from +0x80 and
13.7.8's 4 bytes each from +0x80. On 13 and 14 every HEVC picture went to
the host with no output and was refused: VideoToolbox answered -12911 for
each, the HEIC desktop picture stayed black on 13, 14's video wallpaper
logged "VideoPlayerLayer failed to create decoded pixel buffer", and our
decode tool decoded no HEVC frame (its H.264 frames, whose output comes on
the command, matched).
The driver now searches for the layout instead of listing the releases':
every start from +0x70 to +0xa0 in steps of 4, with fields of 4 or 8
bytes, where the id names a live surface whose width, height and pixel
format the description itself gives. The first picture of a session whose
frame describes its surface in exactly one layout shows the session's
layout, which the session keeps, so the search runs once a session. A
picture whose frame describes no surface, one in more than one layout, or
none in its session's layout, is refused before it reaches the host,
logging which.
What changes for the guest: on macOS 13 and 14 HEVC decodes, HEIC images
and the desktop picture and video wallpaper among them, land in their
surfaces instead of failing; on 26 the surface is the one it was.
Where the host answers a codec's in-place layout, GetPixelBufferInfo asks
AppleGVA for planes of the coded rows (the frame's height rounded up to the
host's granularity, chroma half) at a pitch and alignment that are
multiples of the host's, as AMD's driver on a Mac answers (rows of whole
macroblocks, 256-byte pitches). A decode of a frame of its own then tells
the host, in output_rows, the rows the surface's pages hold for its planes,
so the host may write the whole coded picture there with no copy. A zero
layout (an older host, or one that copies) leaves the answers as they
were.
Core Animation draws an HEIF grid through VideoToolbox's tile decoder, which
has AppleGVA decode every HEVC tile straight into one canvas surface. The
driver landed each tile at the canvas's origin, so a grid showed its last
tile's pixels top left and the rest of the canvas empty (Freeform's welcome
view; ca.heic.grid's mean 108 against the oracles' 5.3).
AppleGVA names the tile's place at P+0x58 and P+0x5c of the picture's
parameters (measured on the RTX 5080 host for grids of 2, 12 and 32 tiles;
0 for frames of their own). The driver now sends the place and the
picture's crop, and the channel lands the picture through textures over
each plane from that place, which RgfxIOSurfaceTexture makes at an offset
in the plane's view. A tile of the last column or row of a canvas of no
whole number of tiles goes with an SPS whose conformance window crops it to
the canvas, as the canvas's planes, and the device's copy of them, hold the
canvas alone.
The tile parameter now answers the place's alignment across from the
device's plane alignment, and H.264 a canvas row of 0: its pictures name no
place the driver knows, so AppleGVA starts no tile decoder for it.
GetContextParameter answered success for AppleGVA's tile parameter (0xb)
whenever it could not fill it, and wrote nothing. That happened with no
decoder of the codec on the host, which covers a process with no device
of ours and caps without the codec. It also happened for a codec or
function the driver has no decoder for, and for a list entry with no
record. AppleGVA then handed up whatever the caller's buffer held, and
CMPhoto divides by its alignments. The sweep's imageio.heic died that
way, of SIGFPE in CMPhotoDecompressionContainerCreateImageForIndex: a
divq by the width alignment, 0, at CMPhoto+0xc88eb, on the msi 5080
host's 5d7e04c6c image, from before the parameter was filled.
The tile parameter is now written whole or refused with kUnsupported, as
GetDriverParameter refuses what it cannot answer. A parameter the driver
does not know is still success with its record as it came, as AMD's
driver answers it. Every other getter already writes its whole answer or
returns an error.
video_driver_tests checks the refusals and that each record stays as it
came. On the driver before, it fails at the first case, H.264 with no host
decoder.
The tile parameter, the bitstream alignments and the pixel layouts the video
driver answered were AMD's driver's values, or a pick between the two dGPU
oracles' (725bd2bb0). The oracles answer for their own hardware, so each answer
is now what the host's decoder needs and does, from what the guest reads of it:
its video caps on the wire and the device's linear texture alignments.
- Tile parameter: a tile is a picture the host decodes, of the coded sizes its
caps take (min_size, max_size), and it lands in a frame of its own, cropped
to that frame's origin, which VideoToolbox lays in the canvas (measured on
the RTX 5080 host: a 4096x4096 image's 64 tiles of 512 went through four
512x512 frames). So a tile's place in the canvas needs whole chroma samples
alone, 2 by 2 in 4:2:0 (was 32 by 2), and the canvas row is at most the
widest the host writes, its largest width in samples of its widest format
(was 4096 bytes). The least and largest tile are the caps' sizes (were AMD's
and Intel's).
- Bitstream alignments: the decoder's own (bitstream_alignment, from its
minBitstreamBufferOffsetAlignment and size alignment), was 256.
- Pixel layouts: as the host's copy lands a picture, its crop at each plane's
origin: luma of the frame's size and chroma of half in whole pairs, with no
padding (heights were padded to 16, an odd frame's chroma short a column),
each plane's first byte and one pitch for both at the larger of the device's
linear texture alignment for the planes' formats and the 4 bytes the copy
takes (was 256).
video_driver_tests checks each answer against a stand-in host's caps and
device alignment.
CreateDriver answered every call with the same handle, and the bitstream
pools were the process's, by AppleGVA's pool type. AMD's driver keeps them per
driver, each CreateDriver a context of its own, and frees a pool allocated
again in that driver alone. Here a second decoder in a process, as an HEVC
stream with alpha decodes in VTDecoderXPCService, or a session made while
another's is still out, freed the buffers the first was still writing access
units in; mmap could then hand the same pages to the second. The sweep's
video.hevcalpha.generator failed at frame 15 with -11821, beside a
VTDecoderXPCService crash in AppleGVA's HEVC decoder zeroing memory at an
unmapped address (lane-gate's boot of 5d7e04c6c).
Each CreateDriver now makes a driver with pools of its own, which a context
names its pictures' buffers in, and DeleteDriver frees them; a handle no
CreateDriver made is refused. video_driver_tests checks that two drivers' pools
of one type stay apart and mapped, through a reallocation and a delete, and
fails on the driver before (two drivers shared a handle).
An HEIC decode reaches the HEVC decoder through VideoToolbox's tile decoder
session, which AppleGVA starts from the decoder's tile parameter
(GetContextParameter, entry 13, parameter 0xb). The driver answered entry 13
success with nothing written, so the tile alignments AppleGVA hands up stayed
0, and CMPhoto, above it, divided by them: ImageIO's HEIC decode died of SIGFPE
in CMPhotoDecompressionContainerCreateImageForIndex (measured on the RTX 5080
host), and the sweep stopped at imageio.heic.
Entry 13 now answers the tile parameter of each decoder. The two dGPU oracles
answer it differently (macOS 26.7.1):
AMD Radeon Pro 5300M, HEVC: 32, 2, 4096, 64, 64, 4096, 4320
AMD Radeon Pro 5300M, H.264: 32, 2, 4096, 64, 64, 4096, 2304
Intel UHD 630, HEVC: 128, 64, 131072, 16, 16, 8192, 8192
(width and height alignment, largest canvas row in bytes, least tile width and
height, largest tile width and height). Each field is the bound both allow,
held to the pictures the host's decoder takes: the alignments, canvas and
largest tile AMD's, the least tile Intel's 16 or the host's least, the largest
no more than the host's. A tile decodes into a frame of its own, of its size,
which VideoToolbox lays in the canvas (measured: a 4096x4096 image's 64 tiles
went through four 512x512 frames), so the canvas asks nothing of the host. A
parameter the driver does not know is answered as AMD's driver answers it:
success, the record as it came.
The other answers AppleGVA may divide by are made whole too: all six
bitstream alignments (five were 0), and a pixel layout refused, its record
untouched, for a frame under 2 samples a side, rather than a chroma plane of
none. video_driver_tests checks that none of these is 0 and fails on the
driver before.
Measured on the RTX 5080 host with the fixed bundle: HEIC images of 512,
1024 and 4096 square (gridded), made in the guest and on a Mac, decode within
4 of their source in every 64x64 block; a 6016x6016 desktop picture decodes;
the sweep's imageio.heic and imageio.heic.alpha pass, and h264.reader too.
Where CreateContexts could not open a later context's host session, it
deleted the contexts it had made before it without closing their sessions or
taking them out of the live ones. The sessions leaked on the host, and the
next FreePixelBufferPool walked the deleted contexts. Both paths now delete
a context the same way: its session closed and out of the live ones, and no
token naming it.
video_driver_tests drives the driver's entry points as AppleGVA calls them,
over a stand-in for the host's sessions: a create whose second session is
refused, DeleteContexts, and a decode the driver cannot send, which fails its
schedule. The first check fails on the old cleanup.