Commit Graph
952 Commits
Author SHA1 Message Date
Anees Iqbal 9736d718d8 🐛 Lend a large surface's pages to the host through a run table
A VT_MESSAGE is one command on ring 0, at most 16 KiB, so it carries about
1,000 page runs: the message's own and those of each surface it lends. A
surface whose pages make more (a large frame's, its pages scattered: a 4K
frame of 10-bit samples is about 1,500 pages of 16 KiB) was refused by the
arm64e kext, which answered the guest's VideoToolbox kVTParameterErr and
sent the host nothing. A decode whose output buffers are such surfaces then
failed every frame: the host's Dbuf went unanswered and each frame was
emitted -12902. Measured on arm64 macOS 15.6.1 under TCG on a 780M host: a
4K Main 10 stream's hardware decode lost all 6 frames so, and the guest's
wallpaper video extension, a client of the service, failed the same way.

The kext now writes such a surface's runs into a run table, wired memory of
its own that it frees as it lets go of the lend, and sends the table's runs
with RGFX_VT_SURFACE_RUN_TABLE in the record's run_count instead. The host
reads the table from guest RAM as it takes the message, and refuses a table
that does not hold the surface's bytes. Each surface a message lends gets
an even share of the room the message's own runs leave.

For the guest: surfaces of any size lend. A host that predates the flag
refuses such a message as malformed, as the kext refused it before.
2026-11-16 23:02:52 -08:00
Anees Iqbal 57ef9a3cb6 🆕 Send an arm64 guest's cursor chain to the host
The arm64e kext refused layer 1's XYZ2Blend, the cursor's chain from XYZ to
the display's profile, because the display applies no chain and that one is
not the identity: WindowServer logged "Failed to set ICC matrix" at each
login and more at each switch of the profile, and the cursor showed sRGB's
colours as they are.

Where the host offers CURSOR_COLOR, the kext takes it on arm64 and takes
each block of layer 1's chain it reads (Src2XYZ's curve and matrix,
XYZ2Blend's matrix and curve) without judging it, and posts the chain at
the first swap after it changed, before that swap's cursor, as a display
engine latches a layer's colour with the flip. It posts the chain off until
it is whole and where it is the identity within 2^-14. The x86-64 kext
does not take the feature, and against a host without it layer 1 is judged
as before.

check-boot's icc check keeps its limit of one matrix line, which now stands
for layer 0's XYZ2Blend that can come a swap before its Src2XYZ.
2026-11-16 23:01:59 -08:00
Anees Iqbal 24a572fe23 🆕 Convert an arm64 guest's cursor through its colour chain
An arm64 WindowServer gives the cursor, layer 1 of the display, a colour
chain of its own: standard sRGB's curve and matrix to XYZ, then XYZ's matrix
and curve to the display's profile. Unlike layer 0's, that chain is not the
identity (0.0024 off at login, 0.25 to 0.35 after a switch to Display P3 or
Generic RGB), so a cursor shown as its pixels came showed sRGB's colours on
a P3 display, and the guest's kext had to refuse the chain's blocks, which
WindowServer logs as "Failed to set ICC matrix".

The device now offers CURSOR_COLOR (feature bit 55, every host offers it)
and takes command 10, CURSOR_COLOR: a display's cursor chain as WindowServer
set it, its curves' forms and parameters and its two matrices as f32 bits.
The host converts each cursor image through it in f64 on the CPU, each
colour once, before the screen is handed the image, so the host's cursor
callbacks and the window's drawn cursor show it converted; a new chain hands
the last image again, converted. Black and white stay exact, and a chain
that leaves every pixel as it is (curves of no form, an identity product)
is no chain and costs nothing. `on` 0 and a reset turn it off. A chain from
a guest that did not take the feature, as the x86-64 kext, is dropped.

What the host sees: FEATURES_HI offers bit 23, and cursor_glyph and
cursor_glyph_at also come when the guest sets a new chain. The guest's side
follows in the next commit.
2026-11-16 23:01:59 -08:00
Anees Iqbal 5ed8f86f59 📝 Say where the device's video runs on Windows [ci skip]
devices.md says what a Windows host's video runs on (VA-API alone, through
libva-win32 and vaon12) and what the UHD 630's driver answers; vaapi.md how
the module loads libva there and what it leaves out without dma-bufs;
backends.md and AGENTS.md's map that the VA-API module builds for Windows.
2026-11-16 22:11:27 -08:00
Anees Iqbal 4420ed055a 🆕 Serve an arm64 macOS 14 guest's VideoToolbox on the host's video
The arm64e kext published the VideoToolbox paravirtual service on macOS 15
and later, so macOS 14 guests decoded and encoded in software. An arm64
macOS 14.6.1 guest under TCG on a 780M host, given the service, decoded and
encoded H.264 and HEVC to the checks 26.6.2 passes; its VideoToolbox sends
protocol version 3 and no guest info with a session's create, which the
host takes.

rgfxVtServesRelease now serves Darwin 23 and later, every arm64 release the
kext loads on. For the guest: an arm64 macOS 14 guest on a host whose video
arm decodes H.264 or HEVC now has the service, its VideoToolbox lists the
host's decoders and encoders as hardware, and its sessions run on the host.
The native test holds the new boundary.
2026-11-16 22:09:29 -08:00
Anees Iqbal 449b122a6e 🐎 Cut no part where no encoder follows
The bundle puts a buffer's ask for its submission (SUBMITTED) last, after its
last encoder, on every buffer of a queue that presents, WindowServer's among
them. The walk cut a part at any encoder's end with an op after it, and
deal() cut chunks at an encoder's end before the stream's last op, so a cut
at the last encoder's end left a last part of framing ops alone: no GPU work,
a vkQueueSubmit of its own, and a paced walk waited to commit it. On
perfdiff's walks at 196c253bc that was 3,736 of the 31,222 parts of an Iris
Xe desk walk (1,558 of 4,680, a third, in its Safari video step) and 1,676 of
55,784 on a Radeon 780M, every one a split buffer's last part; f37e9a586,
before the walk was paced, had as many.

A part is now cut only at an encoder's end that another encoder follows
(encoder_follows), by a cut and by a deal: the ops after the last encoder go
with it into the last part, as in a buffer committed whole, so what they
signal still follows its work and nothing the guest sees changes its order.

Measured on a Radeon 780M (um790, a macOS 26.7.2 guest, walkreg's desktop
walk, two walks before and two after, interleaved: m3-max-38862 and 38864
against 38863 and 38865), in the window drag: empty parts 873 and 901 to 0,
parts 11,251 and 11,243 to 10,339 and 10,333, submissions 891 and 876/s to
805 and 813/s; presents 25.8 and 25.9/s to 25.8 and 25.7/s, and the GPU time
a present 14.9 and 15.4 ms to 14.9 and 15.7 ms at the median.
2026-11-16 21:00:30 -08:00
Anees Iqbal 4c54465962 🆕 Serve an arm64 macOS 15 guest's VideoToolbox on the host's video
The arm64e kext published the VideoToolbox paravirtual service on macOS 26
and later alone, so macOS 15 guests decoded and encoded in software. An arm64
macOS 15.6.1 guest under TCG on a 780M host, given the service, decoded and
encoded H.264 and HEVC to the checks 26.6.2 passes, its VideoToolbox running
the host's sessions as 26's does.

rgfxVtServesRelease now serves Darwin 24 and later. For the guest: an arm64
macOS 15 guest on a host whose video arm decodes H.264 or HEVC now has the
service, its VideoToolbox lists the host's decoders and encoders as
hardware, and its sessions run on the host. macOS 14 still decodes in
software. The native test holds the new boundary.
2026-11-16 20:58:27 -08:00
Anees Iqbal c163db0527 🆕 Encode an arm64 guest's VideoToolbox frames on NVENC
On an NVIDIA host the device listed no VideoToolbox encoder, so an arm64
guest's apps found no hardware encoder and encoded in software. The NVIDIA
arm now answers one encoder for each codec NVENC encodes a profile of, each
session on an NVENC encoder of its own (NvGuestEncoder):
- the guest's settings map onto NVENC's as an x86 guest's do, and Quality
  onto the same preset and tuning (speed_of), the middle where it is unset;
- a frame goes NVENC's two ways: copied by the GPU from the buffer over the
  lent surface's pages into memory NVENC reads, else read by the CPU;
- key frames are placed by the codec module's KeyFrames, NVENC's parameter
  sets go into the configuration record (Record), and no B-frames.

What changes for the guest: on an NVIDIA host, `encs` lists the H.264 and
HEVC encoders NVENC has, and VTCompressionSession's hardware encoders open
and encode there.
2026-11-16 20:19:27 -08:00
Anees Iqbal 1aec9c204e 🎨 Share the VideoToolbox encoders' parts between the video arms
The VA-API arm's guest encoder kept its source checks, its view of the
source's planes, its encoder list and its Quality conversion to itself, and
the codec module's encoder kept its configuration record inside it. NVENC's
guest encoder, next, needs each of them, and also the NVIDIA arm's GPU fill
and preset choice of its host encodes, so they move where both arms reach
them, unchanged:
- the video crate's codec::encode::record::Record: the avcC or hvcC of the
  parameter sets the hardware writes, and samples without them;
- reims-vgpu's graphics::vt_encode: the encoder list, Quality as a
  percentage, and a source frame's planes, checked, in a buffer over the
  surface's pages and in host bytes;
- the NVIDIA arm's speed_of (the preset and tuning of the device's quality)
  and Fills::encode_filled (a frame copied by the GPU, else declined).

Nothing the guest or the host observes changes.
2026-11-16 20:19:26 -08:00
Anees Iqbal 88340bffa9 🐎 Pace a walk in parts that runs far ahead of the GPU
On the Mac mini's UHD 630, a guest command buffer of 794 dispatches went to
the GPU in three parts of 22, 855 and 924 ms: a walk cut no part while work
its queue committed was incomplete, so the rest of the buffer went whole.
metal2vulkan submits every queue's work on the one VkQueue in submission
order, so the buffers committed after such walks waited up to 523 ms for
their parts, and WindowServer's frames with them. Smaller parts alone would
not help them: everything committed after the walk still waits for all its
parts.

Behind incomplete work, a walk now cuts a part once its estimated GPU time
reaches 16 ms, a refresh, the estimate being the GPU time the buffer's completed
parts took against their walk, else its queue's last such rate; and once its
walk reaches 2 ms whatever the estimate, as a compute encoder's GPU time follows
its grid, not its walk (consecutive parts of the 630's burst took 0.4 to 102
times their walk, and one part walked 16.6 ms took 642 ms). Each part boundary
costs about 0.1 ms of a long buffer on a Radeon 780M, which 4 ms parts made 2.5%
there. A walk on its queue's lane then waits after a cut while two or more of
its parts are out and their estimated GPU time is over 16 ms, or the oldest of
them was committed 16 ms ago or more, so a buffer of another queue committed
meanwhile waits for about two parts. The age covers an estimate that lags:
learnt only from parts seen complete, it put a 541-dispatch walk's parts on the
630 at 0.6 ms each, and the walk committed 22 of them within 44 ms while the GPU
took up to 164 ms for one. The wait is the lane's job's, so the lane's next
buffer walks meanwhile.

A walk is never paced once it waited for or signalled an event by an op,
since a part's completion may then hang on a buffer not yet committed; and
it goes on unpaced once a buffer of its context waits for its last commit,
at the split's gate, in the commit order, or for its tickets or range
messages, which a paced walk would otherwise hold up. A wait from its begin,
for a cache's fill or another queue's buffer, does not keep it from pacing:
what such a wait waits for is committed, or commits without waiting for the
walk once the walk goes on unpaced. A wait ends at once at a reset, the
queue's end or a failed part, and after 500 ms with none of its parts seen
complete, and the walk then goes on unpaced. Parts cut behind incomplete
work are committed unmarked, as their completions are what the walk waits
for.

On the mini, in the run of each boot's present probe that met the burst, the
longest gap between frames fell from 933 ms to 584 and 500 ms (two boots), the
probe's longest wait from 1004 ms to 517 and 434, and dropped frames from 62 to
4 and 10; the 794-dispatch buffer went in 80 and 90 parts. Its longest parts,
380 and 417 ms of GPU for 1 to 2 ms of walk, are what a frame committed behind
one still waits for: no estimate from the walk foresees them.

On a Radeon 780M, dispatch_cost's heavy shape, a buffer of 2600 dispatches, now
goes to the GPU in about 17 parts instead of 3 and takes 183.9 ms against 181.7
(medians of three runs, 1.1 to 1.4% apart in each), an accepted cost of bounding
how long a compositor's frame waits behind such a buffer. Its fluid shape and
composite_cost are level there, and so are Geekbench's Fluid Simulation and
Particle Physics (four passes each: 30.81 to 31.02 s against 30.77 to 30.92, and
22.59 to 22.73 s against 22.49 to 22.87). On the M3, over MoltenVK, whose
completions arrive late, the heavy shape takes 129.2 ms against 133.3 and the
fluid one 41 to 46 ms against 45 to 58; composite_cost is level.

Real x86 Macs make a later command buffer wait behind a long one too
(metal2vulkan's measurements: a UHD 630's tiny buffer waits 231 to 234 ms
behind another queue's 244 ms one, a Radeon Pro 5300M's 92 to 99 ms; only
the M3 runs them alongside), so this is a smoothness gain inside Metal's
envelope, not a parity fix. What the guest sees changes only in time: a
paced buffer's last part, and so its completion, comes as the GPU catches up.
2026-11-16 19:19:34 -08:00
Anees Iqbal 02e97ee449 🐎 Keep VideoToolbox's host messages off the control ring
An encode's frame at 1080p and 8 Mbit/s goes to the guest as two or more
16 KiB VT_MESSAGE events. Two of them do not fit the control completion
ring's 32 KiB at once, so an encode filled that ring about once a frame:
control-ring-full and control-ring-post-waited 592 times in an arm64 26.6.2
boot's encode bench (potluck job m3-max-38178). A full ring holds back the
display's VBLANKs and the presents' answers while the guest encodes.

Feature bit 54, VT_RING, which the device offers wherever its host offers
VT_MESSAGES and the arm64e kext takes with it, moves those messages into
the VideoToolbox ring: a 2 MiB ring at region offset 0x20000, in the room
between the control completion ring's span and the guest's allocations,
which the kexts already map with the control rings. It is the device's
memory, so the kext wires none of the guest's RAM for it and frees nothing
at the service's stop or its unload. Each message there is followed on the
control completion ring by a 24-byte VT_RING event (0x40f) carrying the
ring's count through it. The kext takes the ring through that count as it
takes the event, so the messages keep their place among the control
ring's events. A message that finds the ring full goes onto the control
completion ring as before, after the VT_RINGs of the messages ahead of it,
and the spell is counted as vt-ring-full. A guest or host without the bit
gets VT_MESSAGE events as before.

What the guest observes: the feature bit offered with VT_MESSAGES, and the
host's messages in the VideoToolbox ring with VT_RING events instead of
VT_MESSAGE events, in the same order.
2026-11-16 18:48:18 -08:00
Anees Iqbal f37e9a586a 📝 Read a Windows host's event log in record order [ci skip]
The Mac mini's 11-15 outage during a recovery boot read as a hard hang
followed by a planned upgrade, from records filtered by time stamp. Those
records were the install night's, stamped from the firmware clock 8 hours
ahead before Windows first synced its time. In record order the log shows a
sleep, a wake and a power-button shutdown, and two recovery boots on today's
tree ran clean.
2026-11-16 18:25:39 -08:00
Anees Iqbal 3c60f57f72 🐛 Drop a bad UPLOADS_WRITTEN record, and run its buffer
065432241 failed a command buffer at its begin where a record of its
UPLOADS_WRITTEN named no Managed buffer, or bytes past one. A buffer answered
CB_SUBMITTED at its doorbell has posted its CB_SUBMITTED and CB_SCHEDULED by
then, so it failed with them where a buffer its queue's thread took failed
without them: the fuzz caught it
(an_answer_at_the_doorbell_keeps_the_order_of_a_take, case 11 of the
default seed).

The record is dropped now, logged once, as the host drops a
BUFFER_DID_MODIFY_RANGE it refuses, and the buffer runs and completes as it
would behind that message, the same whether or not it was answered at its
doorbell. The records beside it are carried out. Only a guest that names an
object its bundle never made a chunk of sees the difference.
2026-11-16 17:45:04 -08:00
Anees Iqbal a4a91ef8e2 🆕 Name a command buffer's set*Bytes extents in its own stream
On a discrete GPU the bundle's set*Bytes chunks are Managed, and each
commit told the host the bytes written in each with a
BUFFER_DID_MODIFY_RANGE on ring 0 ahead of the buffer. That cost a
one-dispatch command buffer 41 to 44 us of commit-to-wait on the RX 7900
XTX and RTX 3090 hosts. Traced on the XTX, the held message's timer and the
kext call that posts it added 11 to 12 us each before the host took the
buffer, and the buffer then waited 18 to 26 us at the gate for the context
lane that carried the range out.

UPLOADS_WRITTEN (feature bit 53, FEATURES_HI bit 21) lets the buffer's own
stream carry them: op 0x000f, before the first encoder, as many
RgfxUploadWritten records (buffer, bytes from its start) as its length
holds. The host carries each out as the platform's didModifyRange: as it
begins the buffer, before its commit; a record that names no Managed
buffer, or bytes past one, fails the buffer, and none of its records is
carried out. Every host offers the bit and both kexts take it. The bundle
names the bytes there where its chunks are Managed, and sends the range
messages as before where the host did not offer it.

The guest sees the same results: the same bytes reach the GPU's copy before
the buffer's work. The host takes those ranges from the buffer, and ring 0
carries no range message for them.
2026-11-16 17:45:04 -08:00
Anees Iqbal 240881885e 🐎 Copy set*Bytes data into a discrete GPU's memory at commit
On a Mac with a discrete GPU, Metal's driver copies setBytes: data into
the GPU's own memory: on the AMD Radeon Pro 5300M it read at 1.00x of a
Private buffer. A Shared buffer read over the bus came in at 1.05x at
4 KiB, and up to 1.5x at 64 KiB on a dependent chain (constant-read probe,
macOS 26.7.1). Our bundle put those bytes in Shared upload chunks in guest
RAM, so on a discrete host the GPU read every one of them over PCIe.

Where the device answers hasUnifiedMemory NO (the identity flag that also
makes the host keep two copies of a Managed buffer), a queue's upload
chunks are now Managed buffers. The arena notes how far each chunk's runs
filled it as the runs end. At each commit it sends a didModifyRange: of
each chunk's written extent, which goes on the control ring ahead of the
command buffer. The host's Managed path then copies that range into the
GPU's copy before the buffer's commands. A chunk still goes back to its
pool only once the host has completed its buffer, so a later buffer never
rewrites bytes an earlier one is still reading.

What changes for the host on such a device: the chunks' creates carry
Managed storage, and each commit that used set*Bytes is preceded by one
BUFFER_DID_MODIFY_RANGE per chunk it used. Hosts whose GPU shares the
CPU's memory see no change.
2026-11-16 17:45:04 -08:00
Anees Iqbal b448dbe667 🐎 Fill NVENC's input on the GPU
The NVIDIA arm read each encode source as host bytes and copied it with the
CPU into an NVENC input buffer; a source in a device cache went through a
staging copy first. The runtime device's GPU now copies the source's planes,
where they lie, into an exportable buffer that CUDA imports and NVENC
registers as input (nvEncRegisterResource, a CUDA device pointer, mapped for
each frame and unmapped once its bitstream is locked), as the VA-API arm
fills its input surfaces (cee727b5e). A frame whose copy is declined is
uploaded as before, with the reason logged once a session; a session whose
input CUDA or NVENC refuses uploads from then on.

NVENC codes the same bytes either way: the new hardware test
each_frame_filled_by_the_gpu_encodes_as_uploaded compares every access
unit of H.264 High and HEVC Main at 1080p, from pages and from a device
cache. The guest sees the same results sooner: on um870's RTX 3090,
VideoToolbox's H.264 encode of 300 frames went from 88.7 to 156.5 fps at
1080p (6 Mbit/s) and from 24.6 to 40.5 fps at 2160p (30 Mbit/s), each
stream byte-identical in size and in PSNR against the source.
2026-11-16 17:24:39 -08:00
Anees Iqbal 4abaf91c85 🐎 Fill a VideoToolbox encode's input surface on the GPU
An arm64 guest's VideoToolbox encoder read each source frame through the host's
view of the IOSurface's pages, and the VA crate's encoder uploaded it by the
CPU. The runtime device's GPU now copies the frame's two planes, in place, from
a Shared buffer over the surface's pages (LentViews::buffer_over, kept with the
session's view of the surface) into an input surface of the encoder's, as an
x86 guest's frames are filled (cee727b5e). Where the device makes no such
buffer, or the copy is declined, the frame is uploaded by the CPU as before,
said once a session; an input surface whose fill failed on the GPU stays out of
the encoder's pool.

What the guest sees: the same samples, byte for byte
(a_guest_encoders_frames_filled_by_the_gpu_code_as_read_by_the_cpu, on the
780M's radeonsi, m3-max-38046; in the boots below, the same bytes for each
stream), at a higher rate. A macOS 26.6.2 guest under TCG on the 780M, 120
frames at 1080p and 8 Mbit/s, two runs each: H.264 45.5 and 47.8 fps before,
49.6 and 49.0 after; HEVC 52.9 and 51.9 before, 57.9 and 57.2 after
(m3-max-38122, m3-max-38178). Each fill took 0.14 ms of GPU time.
2026-11-16 16:41:54 -08:00
Anees Iqbal c088a6625b 🐛 List the VideoToolbox encoders by Apple's hardware encoder IDs
The encoder list named this host's encoders by IDs of their own
(reims-vgpu-video.videoencoder.avc), which the guest registered as
paravirtualized:<ID> and never opened. On a macOS 26.6.2 guest on the 780M, a
compression session that requires a hardware encoder failed with
kVTInvalidSessionErr, one that allows one got a software encoder, and no +enc
reached the host (m3-max-37910).

The guest's own two paravirtual encoders, the hardware encoders its apps get
(VTVPParavirtualizedH264VideoEncoder and its HEVC twin), open the registered
encoder of Apple's AVE ID, com.apple.videotoolbox.videoencoder.ave.avc or
.ave.hevc, and send that ID as ,cid (read from VideoToolbox's code on macOS
27). The list now names each encoder by that ID, and a create takes that ID or
none, and refuses this host's former IDs.

What the guest sees: `encs` entries whose CMClassImplementationID is Apple's
AVE encoder's; nothing else in the entries changes.
2026-11-16 16:39:02 -08:00
Anees Iqbal 34d3a85a72 🆕 List VA-API's encoders to an arm64 guest's VideoToolbox
An arm64 guest's VideoToolbox now finds a hardware encoder for each codec the
host's VA-API driver encodes a profile of: `encs` lists
reims-vgpu-video.videoencoder.avc and .hevc, which the guest registers as
paravirtualized and hardware-accelerated, and a create of one (by that ID, by
Apple's hardware encoder's, which the guest's own paravirtual encoders send,
or by none) starts an encoder session instead of being refused with
kVTCouldNotFindVideoEncoderErr.

Each session's encoder is the arm's GuestEncoder: on VA-API, the VA crate's
VideoEncoder, made from the settings the session's properties make, `Quality`
onto the driver's quality levels as the device's `quality` maps. Each source
frame is read from the host's view of the IOSurface the guest lent with its
`efrm` (vt.rs's VtEncoderBackend, through the decoders' kept views) and
uploaded; the session emits the samples and lets go of the surface. A change
of the bitrate, frame rate or key-frame interval reaches the encoder from the
next frame; one that makes a new sequence makes a new encoder before the first
frame and is refused after it.

The device's features are unchanged: VT_MESSAGES is still offered where a
decoder is listed, and the arm64e kext still serves macOS 26 and later alone.
2026-11-16 16:39:02 -08:00
Anees Iqbal 2af666bd33 🐛 Build a Windows install outside paths with spaces
A Windows user's folder can hold a space (C:\Users\First Last), and QEMU's
configure refuses a source or build directory with one ("main directory
cannot contain spaces nor colons"). With the library fixed, a user's install
would stop there next: install-ctl.sh builds QEMU in ~/.cache/reims-ctl, in
that folder. With the checkout in the folder too, as install.ps1 clones by
default, sdl3-sys stops first: it finds no SDL3, as a space splits the -L
path of the pkg-config file it reads. Both measured on the mini with a profile
named "Test User". No alias keeps the space out: meson takes realpath of its
directories, which turns an 8.3 short name back into the long one, and a volume
can have no short names (the mini's P: has none).

install.ps1 now clones into C:\reims-vgpu where the user's folder has a space,
saying so, and stops on a -Checkout with one. install-ctl.sh on Windows builds
and stages QEMU in the target directory where the cache directory has a space,
and stops before any download or build on a checkout or CARGO_TARGET_DIR with
one, naming the folder to use.
2026-11-16 16:36:48 -08:00
Anees Iqbal bd239b6ddf 🐛 Build every C and C++ part of a Windows install with clang
A user's install of development on Windows stopped in sdl3-sys's CMake build:
their environment's CC named Visual Studio's cl.exe, cc-rs gave the build
MSVC's C flags (and clang's C++ flags, CXX being unset), and CMake, which
reads CC itself where the cmake crate names no compiler, took cl.exe. Its test
compile failed once MSYS2 had turned /nologo into C:/msys64/nologo. Visual
Studio's install alone does not do it: cc-rs takes cl.exe from it for MSVC
targets only, and our hosts set no CC, so no run of ours met it.

install-ctl.sh on Windows now sets CC, CXX and AR, their per-target forms that
cc-rs takes first, and CMake's generator, to CLANG64's clang, clang++, llvm-ar
and MSYS Makefiles, for cargo's build scripts, CMake, QEMU's configure and
meson alike. The generator is the one the cmake crate chose with none set, and
CLANG64's ar is llvm-ar, so a host without those variables builds as before.
2026-11-16 16:36:48 -08:00
Anees Iqbal 8807df2aa4 🐛 Write CRLF text files out again in Windows checkouts made before
A checkout Git for Windows made before .gitattributes holds every text file
with CRLF line ends (its installer sets core.autocrlf=true), and git does not
write a file again where a later checkout leaves it unchanged: .gitattributes
has it compare the file as LF, so it finds nothing to do. A clone at
core.autocrlf=true moved to the commit that added .gitattributes kept all 1730
text files CRLF, and the build would have failed on the .metal sources' hashes
as before.

install-ctl.sh on Windows now writes each text file whose working copy differs
from its commit only in its line ends out again from the commit, after the
update and before any build, and keeps a file with changes of its own.
2026-11-16 16:36:48 -08:00
Anees Iqbal bff80707cb ⬆️ Offer no TSC deadline timer where WHPX's Hyper-V refuses it
vendor/qemu moves from e8ae598e to f56d36ff: c3704402 and f56d36ff.

On an AMD host Hyper-V refuses WHvX64RegisterTscDeadline while its CPUID
offers the TSC deadline timer, and a macOS guest that arms that timer waited
for interrupts that never came: the VM booted only with -tsc-deadline added
to vm.toml's cpu_flags by hand, which 9db299bdb's docs/qemu.md said reims-ctl
did not do. From c3704402 WHPX asks Hyper-V for the register at its init,
of a vCPU made for the question, and where it is refused offers the guest no
TSC deadline timer: the CPU model's tsc-deadline is filtered out as any
feature the host lacks, with check's warning, and the guest arms the local
APIC's timer. It follows Hyper-V's answer, not the host's vendor. On such a
host the guest's CPUID loses the tsc-deadline bit; where Hyper-V takes the
register, as on the Mac mini 2018, nothing changes. The AMD side is read from
code and pull request #15's report, not run here.

f56d36ff corrects 40257041's comment on the SYSENTER MSRs: QEMU's copy of
their 64 bits answers only a read that faults as well, until the vCPU's next
full register read, and a read Hyper-V answers itself gives the low 32.
docs/qemu.md's table and its AMD host notes now say so, and that only each
vCPU's reset sets the TSC deadline register, where 9db299bdb said every
register sync logged its refusal.
2026-11-16 16:30:29 -08:00
Anees Iqbal 5c6beb0131 🐛 Destroy the retired swapchains before a create with none to hand over
A refused vkCreateSwapchainKHR, or a refused wrap of the new swapchain's
images, retires the old swapchain all the same, and the remake keeps it among
the retired until its last present is known complete. Vulkan keeps a retired
swapchain associated with its surface until it is destroyed, and refuses a
create with no oldSwapchain while the window has a swapchain
(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR; read from the specification of
vkCreateSwapchainKHR and VkSwapchainCreateInfoKHR, not seen on a host). So
the next remake, with no current swapchain to hand over, was refused for as
long as the retired one lived; on a device without present fences, with
nothing new presented, nothing ever made its presents known complete, and
the window kept its last frame for good, as 245a1ebb6's refusal before the
create did. This is the other half of that class, found in review.

A remake with no current swapchain to hand over now destroys the retired
ones first, waiting for their presents as the swapchain's end does
(end_retired, which Drop now calls too). It runs only after a refused create,
since every other remake hands a current swapchain over.
a_make_after_a_refused_create_ends_the_retired_swapchains_first runs it in
the model window system. docs/lessons.md's entry for 245a1ebb6 says so.
2026-11-16 16:30:23 -08:00
Anees Iqbal 38640a5e54 🐛 Answer gpuCoreCount on an x86-64 guest as the x86 Macs: not at all
Neither x86 Mac's Metal device responds to gpuCoreCount: the AMD Radeon
Pro 5300M's and the Intel UHD 630's answer respondsToSelector: NO under
macOS 26.7.1 (oracle_caps, m3-max-37201 and 37202). The bundle has
answered it on every guest since f692b4de0, from the M3 Max's answer,
the one device it was measured on then.

What the guest now sees: an x86-64 guest's device does not respond to
gpuCoreCount, and a call raises an unrecognized selector, as on the
x86 Macs, where it answered the host's count (a GPU's CUs or SMs, 0 on
Intel). An arm64 guest's device, an Apple GPU's, answers the host's
count as before.
2026-11-16 15:57:15 -08:00
Anees Iqbal 15a0a5228b 🐎 Give a UMA GPU's surface caches half its memory budget
On a GPU that shares the CPU's memory every IOSurface device cache fitted
the deferred blocks' budget, a quarter of the GPU's memory budget at the
device's start. On a Radeon 780M with an 8 GiB guest that is 1385 MiB, and
Safari's and a WebGL page's surfaces went past it (454 blocks): those late
surfaces lay in place in the guest's pages, and the WebGL page's frames
fell from 33.0 to 24.6 a second, below development's 32.6. With no bound
the caches held 1762 MiB at most and the frames ran at 33.0 (jobs
m3-max-38032, 38033 and 38034).

The caches now fit half of the budget, twice the deferred blocks', which
stay at a quarter, so the DEFERRED_BUDGET registers read as before. The
budget is read past the guest's RAM, which QEMU preallocates, so the caches
stay bounded on a small host.
2026-11-16 15:41:08 -08:00
Anees Iqbal 701d70218c 📝 Say that every host caches each surface the kext caches [ci skip]
Decided 14 and the feature bits now say what the device answers since
4cd77f6aa. A host whose GPU shares the CPU's memory offers SURFACE_CACHE
and SURFACE_DEFERRED, as a Mac on an Intel GPU keeps its own copy of each
IOSurface (the UHD 630's lock, fill and memory numbers, jobs m3-max-37817
and 37822), within the caches' budget. No host offers
SURFACE_CACHE_REFUSED now, and the decoder's module docs and the video
device doc say so.
2026-11-16 15:41:08 -08:00
Anees Iqbal e9a494d34b 🆕 Lay out the archive's functions in a committed link order on Linux
On the desktop, the device's lanes walk WindowServer's command buffers at
about 120 us per render encoder on a Zen 4 host, and the walk is bound by
instruction fetch: the code it runs is spread over far more 4 KiB pages
than the L2 iTLB holds. Placing that code in the order lld's call-graph
clustering gives it, from a profile of the desktop, makes the walk faster.

Linux's dist now reads crates/reims-vgpu-c/link-order.txt, the library's
functions one a line as GNU nm -C prints them without crate
disambiguators, and in the objcopy call that localizes the archive's object
renames each listed function's section to .text.sorted.NNNNNN in the
list's order. GNU ld's default script sorts those by name ahead of the
rest of .text, so make qemu and install-ctl.sh's QEMU get the order with
the compiler's default linker; a linker that does not sort them keeps the
order it had. dist prints how many of the list's functions it placed: a
function no longer in the archive is skipped, so a stale list loses speed
and never fails the build. The list survives a metal2vulkan pin move,
whose crates change only their disambiguators.

cargo xtask link-order BINARY CALL_GRAPH (Linux) writes the list from a
QEMU lld linked with --call-graph-ordering-file, after this tree's dist;
docs/development.md, "The link order", says how to refresh it. With no
list the archive is as before.
2026-11-16 15:33:06 -08:00
Anees Iqbal bb4474c601 🆕 Decode VideoToolbox's paravirtual sessions on NVDEC, offering bit 52
An arm64 guest's VideoToolbox now decodes H.264 and HEVC on an NVIDIA host's
GPU, as it does on VA-API. The NVIDIA arm answers a GuestDecoder for each codec
NVDEC decodes: a decoder of whole access units of its own, whose picture lands
in the IOSurface the kext lent, laid out as the kext read it and checked
against its memory (GuestTarget). The GPU writes it there, one cuMemcpy2D a
plane into the view of the surface's pages registered with CUDA, as it writes
an x86-64 guest's output pages; where CUDA refuses the view, the picture is
read back and copied by the CPU, each reason logged once a decoder. NVIDIA's
errors reach VideoToolbox as bad data, unsupported or a malfunction.

What changes for the guest: on an NVIDIA host, where NVDEC decodes H.264 or
HEVC, the device offers VT_MESSAGES, and a macOS 26 or 27 arm64 guest's
VideoToolbox lists our decoders as hardware (VTIsHardwareDecodeSupported is
true for avc1, and for hvc1 where NVDEC decodes HEVC) and decodes on them.
Before, an NVIDIA host offered no bit 52 and listed no decoder, so they
decoded in software. An x86-64 guest takes no bit 52, as before.
2026-11-16 14:51:32 -08:00
Anees Iqbal 09a9f8867a 🔀 Merge GitHub's development (pull request #159)
Brings in pull request #159, for a Windows host on an AMD CPU: 245a1ebb6
keeps the window's swapchain when its remake refuses before the create, and
9db299bdb takes vendor/qemu's 40257041, which keeps an Intel guest's MSRs
that Hyper-V refuses on an AMD host. A merge commit by the owner's one-time
exception (2026-11-16).

vendor/qemu moves to e8ae598e, the merge of this branch's 500d30fb with
GitHub's steelbrain/reims-vgpu-rebase-2 (5970afb4, pull request #15), so it
holds both WHPX changes. swapchain.rs, docs/lessons.md and docs/qemu.md
merged without conflicts.
2026-11-16 14:47:00 -08:00
Anees Iqbal 193583164f 🆕 Answer VideoToolbox's encoder sessions on an encoder backend
The host's side of VideoToolbox's paravirtual protocol gains encoder sessions
(`+enc`), the half C2's VA-API backend encodes on:
- the properties a guest's compression session sets (`esup`, `ecop`, `eset`,
  `emul`), in the shape Apple's hardware encoder answers them, made into the
  codec's EncoderSettings on a 90 kHz clock;
- `esta`, which opens the backend's encoder at the frames' size, rounded down
  to even, and asks for video-range source buffers (`Epba`);
- `efrm`, which encodes the frame's lent surface and holds it until the frame
  is both encoded and emitted; `ecfr` and `einv`;
- emission: `Efds` for each new configuration record, then `Eemt` with a
  sample buffer of the guest's own times, in 16 KiB fragments.

What the decoder and encoder sessions share (the session's handle, its thread
and queue, the host's requests) moves out of decoder.rs into session.rs.
SampleBuffer gains a writer that its reader reads back.

Nothing changes for the guest: the encoder list names encoders only for a host
given an encoder backend, the device gives none, so `encs` still lists none
and `+enc` is still refused with kVTCouldNotFindVideoEncoderErr.
2026-11-16 13:56:00 -08:00
Anees Iqbal d3c65ecd83 🐛 Encode QEMU's screendumps off the BQL
vendor/qemu moves to 500d30fb: QMP's and HMP's screendump copy the console's
surface under the BQL, then encode and write the copy on a thread of the
pool with the BQL let go. Encoded under the BQL, a PNG of 2880x1620 held it
about 120 ms on the Mac mini 2018 (a busy desktop's up to 1.7 s). A vCPU
that touched another device's MMIO, which takes the BQL, waited as long, and
an on-screen app's frames with it. That happened even with the device's
interrupts and doorbells off the BQL (the two commits before this): a
present_probe run lost 116.7-157.9 ms at its screendump in 4 of 5 runs, and
a build that logged the BQL's waits found a vCPU waiting 127 ms at another
device's register (0x806492b4) while the present loop stalled 133-283 ms.

For the host, a screendump's file is the same: the frame the console's
update left, now copied before the BQL is let go. reims-ctl's terminal
viewer, which takes PPM screendumps, no longer holds the guest's vCPUs while
each is written. docs/qemu.md says so and corrects the measured numbers of
the commit before this, which were 2 runs that missed the wait.
2026-11-16 13:54:20 -08:00
Anees Iqbal 0db91636f3 🐛 Let WHPX's vCPUs ring the device's doorbells without the BQL
The commit before this sent the device's interrupts off QEMU's main loop on
WHPX. It left the gap: a QMP screendump in PNG still cost an on-screen app
116.6-133.7 ms of frames on the Mac mini 2018 (UHD 630), against 128-148 ms
before. The vCPUs were the ones waiting. WHPX's vCPU loop took the BQL
before each run of a vCPU, so a vCPU that exited to the device's lockless
BARs, to ring a doorbell, waited the 111-123 ms png_save held it. A build
that logged those waits measured them at every screendump, while 8191 of
8192 interrupts went out directly.

vendor/qemu 0fdbf381: with kernel-irqchip and no interrupt request pending,
whpx_vcpu_pre_run skips its locked section, as kvm_arch_pre_run does with
KVM's in-kernel irqchip. With both commits, the probe's gap max at the
screendump is 33.7-34.0 ms, 60.0 fps and 0 dropped, the same as KVM's on
ms01's Iris Xe (33.3-33.7 ms). What the guest sees is the same interrupts
and the same MMIO answers, with no wait while QEMU's main loop is held.
2026-11-16 13:54:20 -08:00
Anees Iqbal 7aac6f4f97 🐛 Raise the device's interrupts on WHPX without QEMU's main loop
On Windows the device sent every interrupt through a BH in QEMU's main loop,
since WHPX has no irqfds. A QMP screendump in PNG of the 2880x1620 display
held the main loop about 120 ms in png_save. For that long the guest took no
completion and an on-screen app's nextDrawable blocked: a 117-145 ms gap
(7 refreshes) in all 6 present_probe runs on the Mac mini 2018 (winbench,
11-15). The same screendump under KVM, where the irqfd injects the
interrupt, cost no frame on ms01's Iris Xe (6 of 6 runs, gap max 33.3-33.7
ms, m3-max-37378).

vendor/qemu 243971f2: on WHPX with the hypervisor's APIC the raising thread
requests the vector's MSI from the hypervisor itself, with no BQL, keeping
the BH for a masked vector, disabled MSI-X and a refused request. What the
guest sees is the same interrupt, sent sooner when the main loop is held.
2026-11-16 13:54:20 -08:00
NailecMC 245a1ebb66 🐛 Keep the window's swapchain when its remake refuses before the create
The remake retired the old swapchain whether or not the new one was made,
and the make can refuse before vkCreateSwapchainKHR, where the window's
surface has no pixels for now. Vulkan was never handed the old one, so it
stayed the window's, and each later remake, with no current swapchain to
pass as oldSwapchain, made one beside it, which Windows refuses while the
old one lives (VK_ERROR_NATIVE_WINDOW_IN_USE_KHR). On a Ryzen 5 5600G host
with an RTX 3060 the window kept the macOS installer's last frame from the
guest's reboot on, while QMP's screendumps followed the guest, and drew
nothing on a minimize and restore; the log held the one refusal a refusing
swapchain logs.

A make refused before the create now leaves the old swapchain the current
one, stale, so the next remake hands it over; one refused by the create or
the wrap of its images retires it, as before. No unit test reaches the
swapchain without a window system, and the fix is not yet checked on a
VM boot; docs/lessons.md records the trap.
2026-11-16 22:46:46 +01:00
NailecMC 9db299bdba ⬆️ Take WHPX's MSRs of an Intel guest on an AMD host
A macOS guest under WHPX on a Ryzen 5 5600G stopped at the Apple logo with
no progress bar: Hyper-V on an AMD host answers with #GP the kernel's write
of a 64-bit address to IA32_SYSENTER_EIP and its read of IA32_MISC_ENABLE,
and the kernel panicked before its console was up. vendor/qemu's 40257041
intercepts such a #GP by default where the host is not Intel's and keeps
those MSRs as KVM does for an Intel guest on AMD. The guest then reached
Recovery, installed macOS 26 and reached Setup Assistant on that host.

docs/qemu.md records the commit, the panics, and the TSC deadline timer
Hyper-V gives such a guest no register for, which the VM's CPU flags drop
for now (-tsc-deadline).
2026-11-16 22:46:39 +01:00
Anees Iqbal 0bef142272 🆕 Decode VideoToolbox's paravirtual sessions on VA-API, offering bit 52
An arm64 guest's VideoToolbox now decodes H.264 and HEVC on the host's GPU.
The host offers VT_MESSAGES where VideoToolbox's paravirtual path lists a
decoder: where the video arm lands decodes in the surfaces the guest lends,
on VA-API. Each decoder session decodes on a GuestDecoder of the arm, through
the VA crate's decoders, and lands its picture in the lent IOSurface through
a view of its guest RAM pages: written there by the driver's video
processing where its import check takes the surface's layout, else read back
and copied by the CPU. A session keeps the views of the last eight surfaces
it landed in.

What changes for the guest: on a VA-API host, a macOS 26 or 27 arm64 guest's
VideoToolbox lists our decoders as hardware (VTIsHardwareDecodeSupported is
true for avc1 and hvc1) and decodes on them. The arm64e kext publishes the
service on macOS 26 and later alone, so macOS 14 and 15 decode in software
as before. Before it lends a surface, the kext takes a read-write CPU lock of
it and lets it go, as a process would: the surface's seed moves, and a
device cache of it is filled from its pages again at its next use, once the
host's picture is there. An NVIDIA host, whose arm lands no such decode yet,
offers no bit 52 and lists no decoder; an x86-64 guest takes no bit 52.
2026-11-16 13:31:30 -08:00
Anees Iqbal 74869d936c 🐛 Answer the device's compile of a visible function as the x86 Macs
macOS 12 and 13 guests' iconservicesagent and com.apple.dock.extra send
the device's private compileVisibleFunction:withDescriptor:error: at
start-up, from Metal's own link of Core Image's kernels, and the bundle
answered it unsupported while supportsFunctionPointers answers YES (17
boots of 11-15/16). Both x86 Macs answer each of its three forms with no
error for any function and descriptor, keep the function in the archive
of the archive form, and call the handler form's one-argument handler
with nil on the caller's thread (oracle_binfn, macOS 26.7.1, Q47).

What the guest now sees, where the host makes function pointers:
- the three compile forms answer as the Macs do and compile nothing,
  as the host compiles a binary function where a pipeline links it;
  the archive form keeps the function as addFunctionWithDescriptor:
  keeps it, and the handler runs before the call returns;
- newComputePipelineStateWithAdditionalBinaryFunctions:error: answers
  the pipeline itself, as the AMD 5300M's does (the Intel 630 makes
  another; the Macs diverge), where it answered nil and an error;
- the device's functionHandleWithFunction: and its resource-index form
  raise an unrecognized selector, as both Macs' devices do, where they
  answered nil.
Where the host makes none, each answers the unsupported error as before.
2026-11-16 12:56:26 -08:00
Anees Iqbal 35b54bfff8 🆕 Lend VideoToolbox's IOSurfaces to the host until its rels
A decoder session writes each picture into a buffer the guest's VideoToolbox
lends with its message. The arm64e kext's service now looks up each IOSurface
ID a send names in the client's task, holds the surface with its memory
wired, and carries it in the VT_MESSAGE as an RgfxVtSurface record (the
lend's name, the surface's ID, pixel format, size and two planes) and the
runs of its pages. It lets go of a lend when the host's rels names it, of a
message's lends at once where the message never reached the ring, and of
every lend at its stop.

The device reads each record with its runs and checks that the record's lend
is the one the message names. reims-vgpu hands the lent surfaces to the
paravirtual host, which lets go of them where no session takes the message,
and sends their rels itself where the message's runs lie outside guest RAM.

The host still offers no VT_MESSAGES, so no guest sends any: nothing changes
for a guest or the host until a backend lands in the lent pages.
2026-11-16 12:47:35 -08:00
Anees Iqbal 1e0e76ab3f 📝 Say what reads VideoToolbox's messages, not where they were [ci skip]
Item 17 of the design pointed at an old doc at a tag for the list of
VideoToolbox's paravirtual messages. The doc now says what carries them and
what reads them on the host: the device's rings and reims_vgpu_video's
paravirt module.
2026-11-16 12:47:35 -08:00
Anees Iqbal 1cd119ce1a 🆕 Run VideoToolbox decoder sessions over a backend on the host
The paravirtual route's second piece: the host's side of a guest decoder's
session, so that a backend over the host's video arm can serve VideoToolbox's
decodes next. reims_vgpu_video::paravirt gains:

- decoder: a `+dec` session on a thread of its own. dsta starts it once from
  the format description's avcC or hvcC, refusing 3-byte NAL unit lengths and
  H.264 field pictures, and sends Dpba first; dfrm asks the guest for a buffer
  (Dbuf), has the backend decode the sample's access unit into the surface it
  lends, emits the frame (Demt) and lets go of the surface (rels), Dfub
  naming a buffer left unused; the guest's replies go straight to the request
  that waits for them. dsup, dcop, dset, dcan, dinv and the rest are answered.
- image_description and sample_buffer: readers of the =fds and =sbf
  parameters, with the serializer's known keys; plist reads binary property
  lists within bounds of ours.
- Host::with_backend, under which a create of a listed codec opens a session,
  and a close ends it.

Nothing changes for a guest: the device's host makes its Host without a
backend, so every create is still refused, and no host offers VT_MESSAGES.
2026-11-16 12:47:35 -08:00
Anees Iqbal 2d7ce10ea0 🆕 Add the VT_MESSAGE op and the arm64e kext's VideoToolbox service
An arm64 guest's VideoToolbox runs its codecs in a guest only where it finds
an AppleVideoToolboxParavirtualizationDriver service: it then sends the host
side `vtpv` messages, and lists and runs the host's decoders as hardware ones.
This is the first slice of that route (design.md, "Decided", 17).

The device gains feature bit 52, VT_MESSAGES: ring 0's VT_MESSAGE carries a
message in guest RAM runs to the host, and the control completion ring's
VT_STATUS answers it and VT_MESSAGE brings the host's messages back. The
arm64e kext publishes the service under display 0's framebuffer where the
guest took the bit and the host's caps list a decoder, with the user client
of Apple's kext's five selectors, read from its 15.0.0 build. The host's side
is reims_vgpu_video::paravirt: it answers the decoder list and each codec's
capabilities from the decoders the caps list, an empty encoder and motion
estimation list, and refuses session creates for now.

No host offers the bit yet: the host's caps code turns it on with decode
sessions, the next slice, so guests see nothing new. The x86 kext is
unchanged, and the option ROM's bytes too; its record takes the new header.
2026-11-16 12:47:35 -08:00
Anees Iqbal 5707aa1c08 🐎 Cut no part while work the queue committed is incomplete
Every part a walk cuts is a submission to the driver and a job of its
scheduler, and a part cut while the queue still has work out starts no sooner
for it: on the RX 7900 XTX, Geekbench 7 cut 1,437 parts for Particle Physics'
111 buffers and 2,631 for Fluid Simulation's 882, 1,256 and 1,703 of those cuts
behind a part not yet seen complete, where the host's own Vulkan pass ran 111
and 882 jobs. On the Iris Xe, WindowServer's frames took 8.96 parts a buffer,
22,155 of 25,856 cuts behind incomplete work.

A queue now counts its command buffers committed and not seen complete
(QueueCounts::out; a place joins it at its commit and leaves it with its
completion handler). A walk cuts a part only while that count is 0, and goes
on into the part it is in otherwise; a buffer whose walk starts behind such
work is dealt in two chunks, one a thread, rather than a chunk each 4 KiB.

What the guest sees is unchanged: the same work in the same order on the
queue, the same events and read-backs in their parts, one CB_COMPLETE per
buffer after its last part. A buffer's parts are fewer and longer, so its
GPU span has fewer gaps. The cut tests keep their cuts through a test knob
(set_cut_behind_work); a_walk_cuts_no_part_while_work_its_queue_committed_is_out
tests the rule.
2026-11-16 12:30:43 -08:00
Anees Iqbal ee7c8627bd 📝 Say which encoders arm64 macOS 26 lists as hardware [ci skip]
The docs said an arm64 guest lists no hardware encoder and refuses a session
requiring one -12908, as measured on arm64 macOS 27.0.1. Arm64 macOS 26 under
TCG lists Apple's own AVE encoders (ave.avc, ave.hevc) as hardware and fails
such a session -12903, with the arm64e set before H.264 encode and after
(m3-max-37133, m3-max-36944): the OS's own answer, with no encoder behind them
in a VM. devices.md and design.md now say so.
2026-11-16 12:10:32 -08:00
Anees Iqbal 156596754e 🐛 Feed AppleGVA's rate control the access unit's bits
An H.264 stream the guest encoded on the host came out at about 83% of the
average bitrate asked: 6.6 Mbit/s for 8 Mbit/s at 1080p, 25.9 for 30 at 2160p.
AppleGVA's rate control reads a word of the length record the driver fills,
at +0x3c, whose name nothing states; the driver wrote only the access unit's
length in bits at +0x6c, so with 0 there AppleGVA kept one QP a session.

The driver now writes the access unit's bits at +0x3c too. What the guest
sees: AppleGVA moves its QP each frame toward the session's average bitrate,
as on an AMD Mac. On a macOS 26.7.2 guest on an Iris Xe host (m3-max-37343):

  asked                    came out   per second over 10 s
  8 Mbit/s 1080p, 120 f    8.42
  4 Mbit/s 1080p, 120 f    4.22
  6 Mbit/s 1080p, 300 f    6.17       7.11, then 5.87 to 6.25
  30 Mbit/s 2160p, 300 f   30.44      35.37, then 29.07 to 30.24

A Radeon Pro 5300M Mac's streams came out at 100% to 104% of the asked. Of
each word from +0x04 to +0x68 written alone, only +0x3c moved the QP; of the
values tried there (the bits, the bytes, the QP, 1), the bits came closest to
the asked bitrate (m3-max-36997, m3-max-37146).

The driver's checks gain +0x3c's bits on a published frame and 0 on a failed
one.
2026-11-16 12:10:32 -08:00
Anees Iqbal 7338abf05a 🐎 Grow a class's chunked slabs to 16 MiB, buffers to 4 MiB in them
Each slab of the process's own pages is a pages block the host maps as a
view of its own and imports once, and RADV and ANV on i915 list every
live import in every kernel submission. A class's slabs stopped at 2 MiB
and every buffer past 1 MiB took a slab of its own, so a process with
many large buffers held as many imports. Where the kext gives chunks, a
class's slabs now grow, doubling, to 16 MiB (256 chunks, one dma-buf at
udmabuf's stock limits), each one heap, and a buffer of up to 4 MiB lies
in them; the region's slabs, and slabs of plain pages, keep their 2 MiB.
A class's slab past 2 MiB is never plain pages: where the kext gives no
chunks it is the region's, of 2 MiB at most.
2026-11-16 11:41:25 -08:00
Anees Iqbal bf31c11cf9 🐎 Mark a command buffer's parts but its last to join the next
A guest command buffer the walk cuts into parts went to the GPU as one
kernel submission a part: on the Iris Xe's animation page a waited buffer
took about 11.6 vkQueueSubmit calls of about 180 us each on ANV. Nothing
observes a part's completion but its own handler, which notes its GPU times
and error for the last part's record and lets its place among its queue's
command buffers go; the last part carries every record, ticket and signal
the guest sees.

So each part but the last is marked to join the next one's completion
(CommandBuffer::set_completion_joins_next), and the runtime may send up to
four of a queue's parts found ready together, and the part behind them, in
one submission. Never marked: the last part; a part that waits for or
signals an event, by an op or from the buffer's begin (a device cache's fill,
another queue's buffer in the surface order); and a part the platform keeps
whole, whose commit is the whole's. The guest still sees its command buffer
complete at its last part's own end, with the same GPU times and the first
failed part's error.

Tests: a_buffer_s_parts_but_its_last_join_the_next_completion_unless_they_
signal and a_first_part_that_waits_from_its_begin_is_not_marked; the dealt
and kept-whole tests check which parts are marked.
2026-11-16 11:41:25 -08:00
Anees Iqbal 60d64cc47d 📝 Say a crossing holds a hidden cursor's pointer for the second [ci skip]
The window's doc of tell_pointer still said the device holds a crossing's
positions for up to 100 ms; it is a second since the hold became the arm64e
kext's longest crossing. The design now says what that means for a cursor
the guest keeps hidden: it never shows on the pointer's display, so its
crossing holds the positions the whole second, while a captured game, which
drives the guest's mouse, is not held.
2026-11-16 11:25:19 -08:00
Anees Iqbal feff9bb156 🐛 Hold a crossing's pointer for as long as the guest's crossing
A crossing held the pointer's positions over the new display back from the
guest's tablet until the guest's cursor showed there, for 100 ms at most.
An arm64 guest under TCG had not shown it on display 1 100 ms after the
POINTER_OVER while the pointer went on over display 1's window: the
positions handed on then were scaled over display 0, where the cursor was,
and left it at their mirror there for good (macOS 26.6.2 at two displays,
potluck job m3-max-37089). The arm64e kext's crossing takes up to four posts
250 ms apart.

What changes for the host: CROSSING_HOLD_NS is a second, so a crossing
holds the positions until the guest's cursor shows on the pointer's display,
for a second at most; a position whose buttons changed still goes on at
once. x86-64 crossings, under a millisecond, and arm64 ones under HVF, under
40 ms, end the hold as before. The kext keeps its 100 ms bound for a
landing that may show the tablet's move, which still holds for a position
whose buttons changed; its comments and the design say so. features.md's
crossing entry says a second.
2026-11-16 11:25:01 -08:00
Anees Iqbal bd284b98aa 🐛 Tell a missed crossing anew once the pointer is back
The device told a crossing onto a display once, until the guest's cursor
showed there. A crossing the guest did not carry out stayed told, so later
crossings onto that display were never told. On 15.6.1 under TCG
(m3-max-36608), a crossing onto display 1 that the kext missed left the
next uncaptured crossings and the captured drag onto display 1 untold. The
tablet put the cursor at the pointer's spot on display 0. The window began
driving the guest's mouse 130 ms into the drag, because the stale crossing
was minutes old and the crossing's hide counted from it.

Now a pointer over the cursor's display ends a told crossing and drops one
still owed, so the next move over the other display is told anew. Each
re-entry gives the guest a fresh POINTER_OVER for display 1, and the hide's
second counts from that one.
2026-11-16 11:25:01 -08:00