af690afff29244d4e3f583a2ba01ff4a74db4921
109
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
9e27647cd2 |
🐛 Leave "AMD - " off a host GPU name that begins with AMD
The owner's request: an AMD host's x86-64 guest read its GPU as "AMD - AMD Radeon 780M Graphics (RADV PHOENIX)". The prefix now stays off where the host's name, once "Intel" and "NVIDIA" are taken out, begins with the word AMD in any case as a whole word (before the name's end or a byte that is no ASCII letter or digit). Nothing else is read: no vendor or device id. What an x86-64 guest sees: MTLDevice.name and the GPU's `model` (System Information's Chipset Model) are the host's name as it is on such a host, "AMD Radeon 780M Graphics (RADV PHOENIX)", "AMD Radeon RX 7900 XTX (RADV NAVI31)". Every other name keeps the prefix as before: "AMD - GeForce RTX 3090", "AMD - Iris(R) Xe Graphics (RPL-P)", and a name with AMD later or beginning a longer word, "AMD - Radeon (AMD) Graphics", "AMD - AMDGPU X". vendorName stays "AMD", and apps that look for "AMD" in the name still find it. arm64 guests are unchanged. The prebuilt sets are rebuilt in a later commit with the other guest changes of this batch. |
||
|
|
36655c417b |
🐛 Name the x86-64 guest's GPU "AMD - " without Intel or NVIDIA
WindowServer died while QuickTime Player played a 4K video full screen: a
user's 780M host, and measured here on a 780M (macOS 26.7.2 and 15.8.2) and on
an Iris Xe (26.7.2), each time on a walk's second clip. Read from their code,
SkyLight's compositor takes a Metal device whose name holds "Intel" for an
Intel GPU, and scales a full-screen video's YUV layer through Intel's video
pixel processor (AppleGVACore). That keeps only plugins of Intel's renderer
IDs, so with ours it has none and asserts. The naming rule gave integrated
hosts "Intel - ", and an Intel host's own name holds "Intel" under any prefix.
What an x86-64 guest sees now, on every host (the owner's rule):
- MTLDevice.name, and the GPU's `model` that System Information shows as its
Chipset Model, are "AMD - " and the host's name with "Intel" and "NVIDIA"
taken out, in any case, each with a mark directly after it ("(R)", "(TM)",
"®", "™") and one space:
- 780M: "AMD - AMD Radeon 780M Graphics (RADV PHOENIX)" (was "Intel - ...")
- Iris Xe: "AMD - Iris(R) Xe Graphics (RPL-P)" (was "Intel - Intel(R) ...")
- UHD 630: "AMD - UHD Graphics 630 (CFL GT2)", on Windows "AMD - UHD
Graphics 630"
- Arc A770: "AMD - Arc(tm) A770 Graphics (DG2)"
- RTX 3090: "AMD - GeForce RTX 3090" (was "AMD - NVIDIA GeForce RTX 3090")
- 7900 XTX and llvmpipe: unchanged, "AMD - " and the host's name
The kext's `model` was the host's name whole, and none for no name; it is
now the same name as Metal's, "AMD - reims-graphics" for no name.
- vendorName is "AMD" on every host (was "NVIDIA" or "Intel(R)" by the host
name's first word), so the GL renderer takes NVIDIA's settings on every
host, as on a 5300M, where an Intel host's guest took Intel's
(design.md, "The renderer's settings").
- SkyLight's NVIDIA name test finds nothing on an NVIDIA host either: it takes
an AMD GPU's path there (MetalTiledBacking's +0x71 now set).
The device info's `integrated` byte stays on the wire and the host still
writes it; nothing in the guest reads it now, as its docs say. arm64 guests
see what they saw. The ROM's bytes are unchanged: its record changes for the
wire header's comment alone.
Tests: serializer_tests' test_metal_names, test_vendor_names and
test_metal_answers_hold_no_vendor_word; the kext's device_name_test, now built
for the x86-64 kext's rules and, as device_name_arm64_test, the arm64e kext's.
|
||
|
|
2afc32eb6d |
🆕 Answer the guest's own CPU count for concurrent compile tasks
The guest's Metal device answered maximumConcurrentCompilationTaskCount with the host's compile threads from the device info, clamp(cores, 2, 4) = 4. A 3D modelling app's renderer starts max(2, count - 1) compile threads, so an 8-vCPU guest compiled its kernels on 3 threads. What the guest sees now: - maximumConcurrentCompilationTaskCount answers the guest's own hw.logicalcpu, at both states of shouldMaximizeConcurrentCompilation, on x86-64 and arm64e guests alike: 8 on an 8-vCPU guest and 4 on a 4-vCPU one, so the renderer's rule gives 7 threads on 8 vCPUs in a background render and an interactive launch alike. - shouldMaximizeConcurrentCompilation is the device's own: NO in each new device, then what its setter set. The setter still passes the value on to _MTLDevice's, which took every call before. Why one rule: at YES both Macs measured answer their hw.logicalcpu (the M3 Max 16; the 2019 MacBook Pro 12, on its AMD 5300M and its Intel UHD 630). At NO they differ: the MacBook Pro's GPUs answer 2 and the M3 Max its 16. Nothing documented promises a smaller count at NO, so the device takes the wider answer at both. One query binary, built in m3-max-64460, read both Macs: m3-max-64461 (M3 Max, macOS 27.0.1) and m3-max-64462 (MacBook Pro, macOS 26.7.1). The base's setter and its encodings were read in m3-max-64488. The host is unchanged: the device info still carries its compile threads in the same slot, which the bundle no longer reads, so the wire, the option ROM and the kexts keep their layout. Both guest sets are rebuilt. |
||
|
|
bd18665fef |
🆕 Name the x86-64 guest's Metal device by the host GPU's type
An x86-64 guest's MTLDevice.name is now the host GPU's name, whole, after a prefix: "Intel - " where the host's Vulkan driver reports the physical device's type as INTEGRATED_GPU, and "AMD - " for every other type (discrete, virtual, CPU, other). An RTX 3090 now reads "AMD - NVIDIA GeForce RTX 3090", a Radeon 780M "Intel - AMD Radeon 780M Graphics (RADV PHOENIX)" and llvmpipe "AMD - llvmpipe ...". The rule reads the device type alone, with no list of vendors, drivers or devices. The name keeps its spaces as the driver gives them, and an empty name reads "AMD - reims-graphics" or "Intel - reims-graphics". A 3D modelling app chooses its GPU by a vendor word in the device's name (Intel, AMD, Apple), and on a host GPU of another vendor it listed only the CPU (walk m3-max-61607). What stays: arm64 guests' name; the Metal device's vendor and family names, by which the GL renderer picks its settings; and System Information's Chipset Model, the kext's IOPCIDevice model, which stays the host's name, whole. The device info carries the type in its byte at 0x453, reserved and zero before, now `integrated`: 1 for INTEGRATED_GPU. Its layout and wire version stay, and a host older than the field writes 0, which reads as not integrated. The firmware's record and both prebuilt sets follow the header and the bundle; the option ROM's bytes are unchanged. |
||
|
|
f73865a7d8 |
🐛 Give a destroyed object's ids back after the buffers before it
The host's runtime keeps a destroyed object for the command buffers committed before its destroy, but a new object made with the old one's resource id or at its GPU address takes them at once. A buffer still running there then read the new object in place of the old one. What a destroy gives back now waits until the host has completed every command buffer the process committed before the object was let go, a failed buffer included: its resource id and GPU address, its heap's bytes, its region and pool blocks, its pages and its ICB slots (RgfxRetireGate in RgfxSerializer.hpp). Every RgfxSerializer::destroy `after` goes through the gate, stamped at the call. A command buffer takes a serial at its commit and gives it back at its completion, or at its dealloc where no completion came. makeAliasable still gives a heap range back at once. What the guest sees: ids and ranges are reused later than before. A texture made while a buffer committed before another texture's release is in flight takes a different resource id. A new buffer's address and a heap's usedSize can differ the same way. With nothing in flight, everything goes back at once as before. Under the game step's -r, no id is reused before frame f+3. The serialiser's end, the context's, runs whatever still waits and logs once the most that waited at once. A guest context ends only with its process, so a new peak is also logged at each power of two from 64. guest/prebuilt and guest/prebuilt-arm64e are rebuilt from these sources. |
||
|
|
9c211e49a3 |
✅ Run the held-create race tests on fair-share mutexes
The two race tests of 21e637db25 passed against the two-hold code they guard: on libpthread's default mutex policy the committing thread took the held messages' mutex again before the thread waiting on it, so the window between the holds was never met. Each now runs in a child of its binary on the fair-share policy (PTHREAD_MUTEX_DEFAULT_POLICY=1, rgfxRunFairShare), where an unlocked mutex goes to its waiter, and checks that the child has it. The protocol test's kext now refuses a held destroy, as a post that took every held message leaves the old check a lock-free answer that waits for nothing. Against the sources before the fix both fail, the serializer's at postHeldCreates and the protocol's at the buffer missing from its ring; on the fixed tree `make -C guest test` passes. The trap is in docs/lessons.md. The bundle's tests are not among the sets' sources, so the sets stay as built. |
||
|
|
1c422925a4 |
🐛 Fail a commit only for a held create the kext refused
A command buffer whose commit posts the control ring's held messages first
failed with MTLCommandBufferErrorInternal ("an object made before it never
reached the device") when another thread held a create between the post of the
held messages and the check of what stayed held. The check took a second hold
of the held messages, saw the other thread's create, which no post had been
asked to take yet, and counted it as refused. A sample app that makes textures
on other threads while one thread commits met it in four walks since 11-14,
the check's first day, on Intel, NVIDIA and AMD hosts alike.
The commit's post with its publish (RgfxRingWriter::flushPublishing) and
RgfxSerializer::postHeldCreates now tell whether a held create was refused in
the post's own hold. A create another thread holds after that is posted later:
the buffer, whose commit began before it was made, cannot name it.
For the guest: such a command buffer is posted and completes, where it failed.
A buffer behind a create the kext did refuse still fails as before. The tests
hold a create on another thread while the kext takes the held messages.
|
||
|
|
a8e2347d24 |
✅ Name the sole-holder test's remapped address its own
The file-pages test named the second mapping of its sole-holder memory `second`, the name the same scope's copy-on-write case gives its source buffer, so the test did not compile. |
||
|
|
83c4898877 |
🆕 Name a sole holder's anonymous memory unchanging
The bundle now names read-only anonymous memory unchanging where its maximum
protection has no write, the kernel answers it SM_PRIVATE at a shadow depth of
0, and mach_vm_page_info's VM_PAGE_INFO_BASIC answers its object's count as 1
at depth 0 with the region's object id (kRgfxAnonymousPrivate). The kext takes
such a block (kRgfxPagesSoleHolder, 1 << 3, where it sets
kRgfxKextFeatureSoleHolderPages, 1 << 20) and marks its SURFACE_PAGES
RGFX_SURFACE_PAGES_UNCHANGING without COPY_ON_WRITE, so the host reads its
pages once, as the view is imported. On P2's guest (macOS 26.7.2, the Windows
mini) the 4K block over such memory was copied whole at each commit that used
it.
A wire holds no reference, so the count leaves out wires for writing taken
while the memory was writable. The kext knows its own: it refuses the block
(kIOReturnNotPermitted) where, once its pages are wired, a writable block of
its own in the table or an in-place surface block covers a page of them, or a
block of writable memory is being made (writableMakes), and the bundle then
asks a read-only block, why RGFX_PAGES_WHY_REFUSED. The check sorts the
block's runs and walks every writable wire's segments under contextLock, once
per such make. What is left is a write another driver started before the app
removed write for good, still landing after the make.
The clause is on for every guest kernel, with no release gate. The facts it
rests on, read in xnu's published source at each tag from macOS 11.0.1 to
26.5, osfmk/vm/ lines:
xnu- cnt pid rid fake prot upl clamp iopl walk id
7195.50.7.100.1 19154 19264 14459 19126 6172 6459 17037 9030 14915 1209
7195.60.75 19074 19184 14406 19046 6156 6459 16984 9030 14862 1209
7195.81.3 19074 19184 14413 19046 6157 6459 16984 9030 14869 1209
7195.101.1 19119 19229 14290 19091 5915 6457 17020 9010 14749 1190
7195.121.3 19158 19268 14329 19130 5916 6457 17059 9010 14788 1190
7195.141.2 19158 19268 14329 19130 5916 6517 17059 9070 14788 1190
8019.41.5 19330 19440 14493 19302 6007 6551 17227 9137 14952 1190
8019.61.5 19330 19440 14493 19302 6007 6551 17227 9137 14952 1190
8019.80.24 19330 19440 14493 19302 6007 6551 17227 9137 14952 1190
8020.101.4 19330 19440 14501 19302 6003 6543 17247 9143 14960 1188
8020.121.3 18885 18995 14245 18857 5918 6541 16960 9131 14704 1168
8020.140.41 18945 19055 14305 18917 5909 6542 17019 9135 14771 1168
8792.41.9 19527 19637 14780 19499 5939 6701 17519 9294 15246 1166
8792.61.2 19538 19648 14791 19510 5939 6753 17530 9346 15257 1167
8792.81.2 19538 19648 14791 19510 5939 6753 17530 9346 15257 1167
8796.101.5 19669 19779 14872 19641 5926 6750 17650 9273 15338 1164
8796.121.2 19669 19779 14872 19641 5926 6750 17650 9273 15338 1164
8796.141.3 19738 19848 14911 19710 5940 6774 17695 9297 15377 1164
10002.1.13 19897 20007 15074 19869 6032 6791 17854 9316 15540 1163
10002.41.9 19910 20020 15087 19882 6032 6771 17867 9296 15553 1165
10002.61.3 19910 20020 15087 19882 6032 6771 17867 9296 15553 1167
10002.81.5 20023 20133 15121 19995 6041 6771 17980 9296 15587 1167
10063.101.15 20254 20364 15180 20226 6098 6774 18210 9299 15646 1355
10063.121.3 20357 20467 15247 20329 6123 6774 18308 9299 15714 1355
10063.141.1 20359 20469 15249 20331 6125 6774 18310 9299 15716 1355
11215.1.10 20139 20249 14984 20111 5692 6843 18096 8188 15442 771i
11215.41.3 20139 20249 14984 20111 5692 6843 18096 8188 15442 771i
11215.61.5 20501 20611 15230 20472 5759 6817 18384 8162 15693 765i
11215.81.4 20507 20617 15236 20478 5765 6817 18390 8162 15699 765i
11417.101.15 20646 20756 15393 20617 5804 6766 18487 8111 15856 765i
11417.121.6 20694 20804 15441 20665 5843 6781 18535 8129 15904 766i
11417.140.69 20703 20813 15449 20674 5841 6777 18546 8124 15913 766i
12377.1.9 20960 21070 15518 20931 5974 6988 18734 8331 16004 776i
12377.41.6 22004 22114 16433 21975 6174 7198 19709 8562 16933 807i
12377.61.12 22037 22147 16463 22008 6204 7203 19742 8567 16963 808i
12377.81.4 22109 22219 16534 22080 6275 7209 19813 8573 17034 808i
12377.101.15 18688 18805 13571 18677 5743 7659 16128 8765 14068 824i
12377.121.6 18686 18803 13569 18675 5722 7659 16126 8765 14066 824i
cnt vm_map.c, vm_map_page_range_info_internal: the top object's count,
less the query's own reference to 12377.81.4, read before it after
pid there: the id, VM_KERNEL_ADDRPERM to 10063.101.15, ADDRHASH after
rid vm_map.c, vm_map_region_recurse_64: the region's id, VM_OBJECT_ID
id vm_object.h (i: vm_object_internal.h): VM_OBJECT_ID, the low 32 bits
of pid's macro in each tag
fake vm_map_page_range_info_internal: a footprint query's count of 1 and
an id of no object (task_self_region_footprint)
prot vm_map.c, vm_map_protect (its preflight from 12377.101.15): no
protection the maximum lacks
upl vm_pageout.c, vm_map_create_upl: no write UPL where the entry's
protection lacks write; from 12377.1.9 through vme_allows_upl_write,
whose test is at 6786, 6986, 6991, 6997, 7413 and 7413
clamp vm_map.c, vm_map_remap_extract: a share's maximum is the source's at
most, which memory entries take through vm_map_copy_extract
iopl vm_pageout.c, vm_object_iopl_request: the UPL keeps the object with
no reference of its own
walk vm_map.c, vm_map_region_walk: the count less one while paging, so
the share mode alone leaves it in doubt
Later releases are checked by test: guest/bundle/tools/sole_holder_probe.c,
which the lane gate's info phase (item sole-holder) and Ambrosia's
check-boot.sh (check sole-holder) run on each guest they boot, reads the count
as 2 with a memory entry or a second mapping holding the memory and 1 once it
goes, sees a footprint query answered otherwise, the kext's writable wire of
memory whose maximum lacks write refused, a sole holder's block made, and
refused while a writable block of the kext's covers it. A release where it
fails is a red leg. The kext's tests cover the wiring and the runs' sort and
search, and the bundle's a sole holder's block named and refused.
|
||
|
|
d03fa634dc |
🐛 Name anonymous memory unchanging only with a copy pending
Anonymous memory read SM_PRIVATE is not provably unchanging: the region walk takes one from the object's reference count while paging on it is in progress (osfmk/vm/vm_map.c:16002-16005), and a wire holds no reference (vm_object_iopl_request, osfmk/vm/vm_pageout.c:8331; upl_destroy, 5683-5685), so a driver's wire for writing taken while the memory was writable, our own kext's for a writable block among them, still writes its pages after the maximum protection lost write, under a count of one. A once-made copy would then be wrong for the block's life. Such memory is read-only again, why not a file, and its blocks are copied whole at each commit as before. What stays unchanging is SM_COW at shadow depth 0, with no write in the maximum protection, which is sound against wires too (xnu main as read on 2026-11-20): - such a pending copy is vm_object_copy_quickly's of an object whose copy strategy is still symmetric (osfmk/vm/vm_object.c:3586-3605), and a wire makes its object's strategy a delayed copy (vm_pageout.c:8404-8423), so the object was not wired before the copy; - a wire through either side after it resolves that side's pending copy first, shadowing it (vm_map_create_upl, vm_pageout.c:7140-7188), as a write fault does (vm_map_lookup_and_lock_object, vm_map.c:14866-14897) and a share does (vm_map_remap_extract, vm_map.c:18314-18396), so the other side's writes and wires land in a copy of its own. What the host sees: blocks of anonymous memory SM_PRIVATE no longer carry RGFX_SURFACE_PAGES_UNCHANGING; those with a copy pending carry it with RGFX_SURFACE_PAGES_COPY_ON_WRITE. The bundle's classification line drops the private clause. The tests hold both. |
||
|
|
cc05db2728 |
✨ Name read-only anonymous memory of a process's own unchanging
A no-copy buffer over anonymous memory the process mapped read-only, with no write in its maximum protection, was a read-only block not unchanging (why 1, not a file): the host copied its pages whole into its copy at every commit that used it. On the Windows host's 4K desktop that is a 4K block of ImageIO's (share mode SM_PRIVATE, ref 1, shadow depth 0), 7.93 ms and 31,007 KiB a present. The bundle now names two share modes of such memory unchanging, read from xnu's main as of 2026-11-20 (osfmk/vm/vm_map.c's vm_map_region_walk, 16088-16098; the modes' values osfmk/mach/vm_region.h:129-130): - SM_PRIVATE, the object held by the region alone; a share of it takes no protection past its maximum (vm_map.c:18037-18058, 18733-18734), and VM_PROT_COPY maps a copy in its place (vm_map.c:5832-5905); - SM_COW at shadow depth 0, a copy pending on the region's own object (vm_object.c:3586-3605; vm_map.c:12727, 14046, 18604), where the other side's writes go to a copy of its own (vm_map.c:14866-14897, 18314-18396), marked copy-on-write. A depth of 1 or more, and every other mode, stays neither, why not a file. SM_PRIVATE's one doubt is documented: the walk takes one from the object's reference count while it pages (vm_map.c:16002-16005). What the host sees: such blocks now carry RGFX_SURFACE_PAGES_UNCHANGING (and _COPY_ON_WRITE for the pending copy), so the host reads their pages once, as the view is made, instead of at every commit; the GPU's writes there are dropped as before. The bundle's classification line counts the two new clauses. The wire, kext and host docs say so. |
||
|
|
5260a14032 |
🔥 Copy read-only memory whole at each commit, with no compare
A copy of read-only memory kept a base, compared every page with it at each commit that used it, and at completion compared again to drop the GPU's writes. The owner's rule is no compare-and-skip on read-only copies: memory that is not provably unchanging is copied whole at each commit that uses it. What the guest sees: the GPU's writes to read-only memory are still dropped, as Metal's are, but now at the next commit that uses the memory, when its bytes are written into the range again, not at the completion of the command buffer that wrote them. A command buffer that writes read-only memory still in flight when another commit uses it has those writes overwritten. The writable memory and the writable shadows keep their merge, unchanged. On the host (rt, copied.rs): a dropping copy keeps no base, copies all of its pages at each commit, does nothing at completion, and no longer holds its command buffer's handlers back. Counted for each kind (writable, read-only, unchanging): rt-copied-*-commits, the bytes (writable-compared-bytes, read-only-copied-bytes, and restored-bytes, as before) and rt-copied-*-sync-ns, and the read-only commits and bytes by the block's why (rt-copied-read-only-why-N-*), which the surface pages' import hands the copy. In the bundle (RgfxMemoryShadow): a read-only shadow keeps no agreed copy and is copied whole at each sync. The process's commits, write-backs, bytes and time for each kind are logged as "RGFX: memory shadows, totals" within a minute of a change. |
||
|
|
318864dca5 |
🆕 Read once the file pages no guest process can ever write
Read-only memory under a no-copy buffer lies over a copy on rt wherever the GPU cannot import it as it is, and every commit that uses the copy compared all of its pages with their base. Much of that memory is a file's pages on the guest's read-only system volume, which nothing can change while the buffer lives, so the compare buys nothing there. What the guest sees: the device offers feature bit 31, UNCHANGING_PAGES, with READ_ONLY_PAGES, and the kext takes it (kext feature 1 << 19). At a no-copy buffer's make over read-only memory, the bundle asks the guest's kernel once whether the range is one file-backed region whose maximum protection has no write (a shared mapping, or a private one whose maximum was lowered), whose every page is the file's own, on a volume mounted read-only (proc_pidinfo's fsid against getfsstat; no path is opened). Such a block is the app's own memory, as before, marked RGFX_SURFACE_PAGES_UNCHANGING (and _COPY_ON_WRITE); the kext's wire of a private mapping makes the process's copy, as a Mac's does. Any other read-only block carries why not in its flags' bits 8 to 11, which the host only counts. What the host does: an unchanging block's copy is filled once, as its view is made, never compared at a commit, and written again whole at the completions of the command buffers that can write it, which drops the GPU's writes as before. The views' summary counts the other read-only blocks by why, and each texture over one (read-only-pages-textures-why-N, with one line per format, size and why). A private mapping whose maximum protection still has write is not provably unchanging, since its process could raise its protection and write its copy: it stays a plain read-only block, why "writable max protection". |
||
|
|
0f8bba3c2c |
🆕 Make no-copy buffers at the host's address where blocks answer first
Where the device took IMPORT_ADDRESSES_LATER, a pages block is answered before its view is imported, with no GPU address, so the bundle cannot place the buffers over it at the view's address as it made them. It now lets the host place them: - a buffer over such a block goes in BUFFER_OVER_PAGES at gpu_address 0, which the host places at the view's address plus the buffer's offset; no address of the process's is picked for it; - a Shared one asks its address of the host (PAGES_BUFFER_ADDRESS) at its first gpuAddress read, the argument encoder's and a texture over it included, and keeps the answer; a read with no answer is 0 and asks again; - a Managed one, where the host makes Managed buffers at their copy's address (MANAGED_AT_COPY), asks its copy's address as it is made. What the guest sees: on metal2vulkan-rt's platform, newBufferWithBytesNoCopy: returns without waiting for the block's import, and the first read of the buffer's gpuAddress waits for it instead. The addresses are the host's, as they were where the block's answer carried one; on the default platform nothing changes. |
||
|
|
7fff9ed966 |
✅ Check only live Private picks for a shared span
The threaded pick test's 2000 picks of 32 KiB spans are 62.5 MiB, which go round several of the guest's new 16 MiB blocks, so a span freed by one thread is picked again by another. The test held every pick, freed ones included, and failed on the re-pick. It now checks that no two live picks share a span, that every pick lies in a block taken, and that the picks took more than one block. |
||
|
|
ac8fd0a663 |
🆕 Take 16 MiB Private blocks, and one of its own for a longer pick
The bundle asked the kext for Private blocks of 256 MiB. On metal2vulkan-rt each was an allocation of the driver's in the take: on NVIDIA's driver about 0.08 ms a MiB with the device's other calls held, 21 ms for 256 MiB. It now asks for 16 MiB (kPrivateBlockBytes), rt's allocation unit, which rt's block maker makes ahead of need, so a take is a range of an allocation already made. A pick whose span and alignment are more than 16 MiB takes a block of its own: their length rounded up to 64 KiB, holding that pick alone, at the block's first aligned byte. It goes back to the host with the pick's free. On a 780M desktop boot, 4 of 77 Private objects were longer than 16 MiB (32 MiB each), 250 MiB in all. What the host observes: PRIVATE_TAKE asks for 16 MiB or one object's span rather than 256 MiB, and a context holds more, shorter blocks, an own block given back at its object's free. What the guest observes: its Private objects' gpuAddress values lie in those blocks. Picks, refusals and gives are otherwise as before. The tests that held 256 MiB blocks now hold 16 MiB ones and the own block. docs/graphics-kext/design.md says so. |
||
|
|
f13f992e49 |
🆕 Let the guest place a Managed buffer at its CPU copy's address
On a GPU that shares the CPU's memory a Managed buffer is its bytes, so its GPU address is its CPU copy's. The guest's bundle picked it an address of its own, in a Private block, which metal2vulkan-rt cannot keep for a buffer that lies over the copy's bytes: rt made the buffer at the copy's address, while the guest's pointers held the pick, and each pick held a Private take. Feature bit 63, MANAGED_AT_COPY, names the other form: where the guest took it, a MANAGED_BUFFER_CREATE's gpu_address is its CPU copy's, the guest takes no address for the buffer, and the address goes back with the copy. Both kexts carry the bit, the bundle's serializer, slabs and no-copy buffers post the copy's address, and the device tells its host the features the driver took as it becomes ready (Host::driver_ready), before any message, so the host's decoder can read the creates in that form. No host offers the bit in this commit, so nothing changes for a guest. The wire header changes, so the ROM's record and the guest's prebuilt sets are rebuilt in their own commit. |
||
|
|
f4ae62647f |
🐛 Pick a heap outside Private blocks at its own alignment, as before
Guest-visible against f180bde6f only: a device heap picked in the context's own range (no Private block source, or a take refused) lies where any pick there does again, at the alignment asked and the 32 KiB granule, not at a multiple of 256 KiB. Against development, only heaps in Private blocks move: they start at a multiple of 256 KiB from their block's first byte. The 256 KiB serves rt's binding of a heap's textures at their offset in a Private block's memory; a heap outside the blocks is a block of its own on rt and binds at its own base, so the pad bought nothing there, and it broke test_addresses_reused_after_destroy: a freed heap's span joined the pad's free bytes below it, so the next pick of that span lay below the heap's old address. allocPrivateAddress takes the block-only alignment as `blockAlign` in place of a flag, and falls back to allocAddress at the caller's alignment. |
||
|
|
97808c8997 |
🐛 Pin Private heaps at 256 KiB from their block's first byte
Guest-visible: a device heap the bundle pins in a Private block now starts at a multiple of 256 KiB from that block's first byte, on both platforms, where it started at the next 32 KiB granule. Heaps' gpuAddress values move; no other pick does, and no wire field changes. metal2vulkan-rt binds a heap's texture at the heap's offset in its block's memory plus the texture's offset, and refuses one whose place there is off the image's alignment, though Metal's rule (the offset a multiple of heapTextureSizeAndAlign's align) places it. With heaps on the 32 KiB granule every texture whose image asks 64 KiB or more (the 780M, Iris Xe, the XTX) could land off it: pl8rt counted 85 such refusals in one boot, and the window overview's thumbnails stayed grey. 256 KiB is the largest image alignment measured on the hosts' GPUs (a multisample target on an RX 7900 XTX) and the current runtime's own heap base alignment. The pick counts from the block's first byte, not from 0, because the block's address is aligned only to the host's 64 KiB while its memory starts at a multiple of 2 MiB on rt. Where no block is held the heap lies at a multiple of 256 KiB in the context's range. The leading gap stays in the block's free list, so later smaller picks reuse it once picks wrap. |
||
|
|
66370e18be |
🆕 Place no-copy buffers at the address the host gives their block
On metal2vulkan-rt a no-copy buffer's GPU address is the device address of the host's import of its pages, which only the host knows, so a guest pick cannot match it. Where the kext and the device both took IMPORT_ADDRESSES, the bundle asks PagesBlock for its third output, the GPU address the host gave the block's view, and makes each BUFFER_OVER_PAGES over the block there plus the pointer's offset in its page, with no pick of its own and none given back at its destroy. What the guest sees changes: a no-copy Shared buffer over writable memory the kext wires answers a gpuAddress in [2^43, 2^44) on the Vulkan platform (at its pages' import on rt) instead of a pick in the context's range, and two no-copy buffers over the same bytes, which join one block, answer the same gpuAddress. A Managed no-copy buffer's own address stays its GPU copy's pick; only its CPU copy, the Shared buffer over the pages, moves. Read-only memory, copied memory and blocks given no address keep their picks, and a guest without the bit sees nothing change. design.md gains the "Import addresses" paragraph, PagesBlock's third output and the kext's bit 18. |
||
|
|
a75f372539 |
🆕 Place Private objects in the Private blocks the host gives
This change is visible to the guest. Where the kext and the device both took PRIVATE_BLOCKS, these objects now get their gpuAddress inside blocks the host gives the context, rather than in the context's own range in [2^46, 2^47): - Private buffers; - heaps that are not Shared, and the buffers in them; - Managed buffers, whose GPU copies are what the address names. On the Vulkan platform those addresses lie in [2^44, 2^45). On metal2vulkan-rt's device they are the Vulkan device addresses of the host's memory, which is the reason for the move. Shared buffers, the pool's heaps and no-copy buffers keep their addresses. How the bundle picks inside its blocks: - Picks are next fit through the blocks, on the same span and granule rules as the context's range. - A block is taken from the kext when none has room: 256 MiB, or the pick's span and alignment rounded up to 64 KiB where that is more. 256 MiB is rt's pooled block, and it keeps a freed span from being picked again soon after its destroy. - Free ranges never join across blocks, so no pick spans two of them. - One empty block is kept for the next picks. Any further empty block is given back after the last object's destroy has been posted. - Where the host refuses a take, the bundle picks in the context's range as before and logs the first refusal. The serializer tests cover picks in blocks, a block of its own for a large pick, giving back and keeping, blocks side by side, refusal and threads. docs/graphics-kext/design.md gains "Private blocks" and the two selectors. |
||
|
|
8447199fee |
🆕 Note a no-copy buffer's identity the first time it escapes
The host reads a no-copy buffer's bytes in place. The guest's Metal can hand that buffer's identity to the app, or write it where the GPU reads, with no message naming the buffer, and from then on the GPU may reach the buffer through memory alone. The host had no way to know which buffers that happened to. This commit adds a note for it, so the host can tell them apart. The note is RGFX_CMD_BUFFER_ESCAPED (0x23b), RgfxBufferEscaped of 32 bytes: the buffer's object id and the act, one of GPU_ADDRESS, ARGUMENT_ENCODER, RESOURCE_ID and RESIDENCY_SET. The device offers it as RGFX_FEATURE_BUFFER_ESCAPED (bit 56), and both kexts carry it. The submit gate takes it in a batch, like a Managed range's write: unwaited, a fixed size, naming no block and making no object. The bundle marks each covered buffer as it is made (_rgfxEscape, set by rgfxOwesEscapeNote) where the host took the feature. The first of these acts in the buffer's life posts the note, before the act returns: - a read of the buffer's gpuAddress; - an argument encoder's setBuffer(s) of it, or setTexture(s) of a texture or view over it; - a read of such a texture's or view's gpuResourceID; - the buffer, or such a texture, joining a residency set. Every later act is one relaxed load. Wire order holds the note ahead of any command buffer that could use the identity. The note goes on ring 0, posted or held in the serialiser to go before the next commit's messages, and the device carries out a command buffer only after every ring-0 message its process posted before it. Across threads, the act's slow path posts the note under the buffer's lock and then clears the mark with a release store. Every commit takes an acquire fence before it posts, so a commit after an act that found the mark clear posts after the note. The covered buffers are the app's no-copy buffers over its own pages (BUFFER_OVER_PAGES, writable or read-only, bit 24) and over bytes already in a block of the process (BUFFER_OVER_HOST_MEMORY). Managed buffers, heaps over pages, IOSurface shadows and buffers placed in a slab's heap (BUFFER_AT_OFFSET) are not covered. A slab buffer made with an address of its own is covered too: a Shared buffer past 2 MiB over a slab of the process's own pages, a device buffer, or a no-copy buffer's shadow (RgfxSlabSource::Made's ownsAddress). It reaches the host as the same BUFFER_OVER_PAGES or BUFFER_OVER_HOST_MEMORY message as an app's no-copy buffer, and the host takes every such message alike. Leaving slab buffers out would leave the host unable to read the mark as "this buffer's identity never left". The host marks the buffer's entry escaped, once for its life, and a later note changes nothing. A note for an object that is not such a buffer is a bad reference. A note for an object whose create the host refused is dropped, as any naming of one is. Escapes are counted in the degradation counts line and in the recorder's stats (`counted <code> <n>` lines), with no new stream records: - buffer-escaped-gpu-address, -argument-encoder, -resource-id and -residency-set, by the act that noted the escape; - buffer-escaped-read-only-pages, the escaped buffers over a copy of their pages; - no-copy-buffers, every no-copy buffer made, of which the escapes are a share. Each act's first escape is also logged at info. This changes nothing the guest observes. No one waits for the note, it has no reply, and the mark changes no answer, object, address or command. Both prebuilt sets and the option ROM's record are rebuilt from these sources. The ROM's bytes do not change: its record changes only by the wire header's hash. |
||
|
|
191daab32a |
🐛 Send a render pipeline's tessellation state and call stack depths
A guest's render pipeline drew its patches with Metal's default tessellation state, whatever its descriptor set: power-of-two partitions, a maximum factor of 16, no factor scale, constant factors per patch and clockwise output. The bundle never sent the seven tessellation fields, so the device never saw them. For the same reason the device never saw maxVertexCallStackDepth or maxFragmentCallStackDepth, and created every pipeline with a depth of 1. The bundle now reads each of these properties and sends it. Each tessellation field travels as Metal's raw value, and tessellationFactorScaleEnabled as a new flag, RGFX_RENDER_PIPELINE_TESSELLATION_FACTOR_SCALE (bit 8). The depths are read only where the descriptor answers their selectors (macOS 12 and later); older guests send 1. The decoder passes every value through FullRenderPipelineDesc to the runtime's RenderPipelineDescriptor. A state equal to Metal's defaults becomes the runtime's `None`, so a pipeline that sets nothing is created exactly as before. A raw value the runtime has no enumerator for dies at the send, as every other enumerated field does. The recorder's tag-13 map carries the values as three keys after privateState: `tessellation`, `maxVertexCallStackDepth` and `maxFragmentCallStackDepth`. Guests now see patches tessellated with the partition mode, maximum factor, factor scale, step function, winding and control point index type that their pipeline sets. They also see pipelines created with the call stack depths they asked for. The tessellation fields and the call stack depths share this commit because they share one wire record. RgfxRenderPipelineCreate grows from 464 to 496 bytes, with eight u32s appended at offset 464, and both prebuilt sets and the option ROM's record are rebuilt from these sources. The ROM's bytes do not change. |
||
|
|
61084eab14 |
🆕 Tell the host which bytes of a new Managed buffer read zero
On a GPU without unified memory the runtime makes a Managed buffer's GPU copy by copying all of its CPU copy over the link as the buffer is made. Most of those bytes are zeros the guest never wrote: on the RX 7900 XTX, Geekbench 7.1 Metal's making copies carried ~4.5 GB beyond what the guest marked written, up to ~0.94 s of GPU time (one 131 ms job copied six new buffers' 631 MB, 12 MB of it written). The guest knows which bytes read zero; the host cannot. What changes for the guest and the host: - MANAGED_BUFFER_CREATE takes a tail, RgfxManagedBufferZero at byte 56 (RGFX_MANAGED_BUFFER_ZERO_OFFSET): its CPU copy reads zero from zero_from to the length as the create is posted. The bundle sends it with every create: 0 for a buffer made with no bytes, whose slab range take() zeroed; the length, which says nothing, for one made with bytes or over the app's own memory. The kext's SubmitBatch takes the create at its new size, 64 bytes. - The host passes a zero_from below the length to the platform (BufferDesc::zero_from), and the Vulkan platform to the runtime (HostMemory::with_zero_from): the GPU copy starts with zeros the GPU writes there, rather than with those bytes copied in. A guest write there reaches the GPU copy by a didModifyRange:, as on a Mac's discrete GPU, whose GPU copy is made at the buffer's making; before, a write made before the host took the create reached it too. A GPU that shares the CPU's memory keeps one copy, unchanged, and a create without the tail (an older guest's) is copied in whole, as before. An older host reads the create and ignores the tail. Tests: the decoder passes the tail's offset and none without it or at the length; the platform's zero bytes are the device's on a GPU of its own memory; the serialiser, the slabs and the device buffers send each make path's value. Both guest sets and the ROM's record are rebuilt in the next commit. |
||
|
|
15df01ce67 |
🐎 Arm the held destroys' timer after a delivery's waiters go
A command buffer's delivery releases what the buffer kept before it lets its waiters go, as Metal does, and the destroys those releases hold armed their 1 ms timer there: a dispatch_after, whose kevent wakes the dispatch manager's thread. In a guest ktrace of Geekbench's Metal Super Resolution on the 780M host that arm took the release 16.9 us p50 (30.2 p90) of each delivery on the completion queue, between the app's handler and the wait's return. The delivery now holds the arm (RgfxRingLaterArms) until its waiters are let go: the destroys go as before, the timer from the end of the delivery. |
||
|
|
14c2c18e8c |
🆕 Stamp each command buffer with the guest's clock (GUEST_TIMES)
The host sees a command buffer only once a queue's thread takes it off its ring, so the app's encode and the buffer's way to the host show as one span with nothing pending on the host. This adds the guest's stamps that split it, a diagnostic. What changes for the guest: - The device offers a new feature bit, RGFX_FEATURE_GUEST_TIMES (bit 44, FEATURES_HI bit 12), and DRIVER_FEATURES takes it. The kext carries it. - Where the device's word holds it, the bundle starts each command buffer's stream with a new op, RGFX_OP_GUEST_TIMES (0x000e, 32 bytes): the guest's clock as the buffer was made, as its commit was entered, and as its message went on its ring. The last is written under the ring's lock, after the copy and before producer is published; for a buffer in a block, into the block. - After each VBLANK's reading of HOST_TIME the kext writes ring 0's new header fields: guest_clock_offset_ns (0x18), then guest_clock_bound_ns (0x20) with release, split out of reserved bytes. The host zeroes both as it initialises a ring. - The decoder walks the op as a no-op, so it changes nothing a buffer does, and a host that did not offer the bit never sees it. Old guest sets carry no bit, send no op and leave the fields 0. The header is regenerated, both guest sets are rebuilt from the same sources, and the option ROM's record takes the header's new hash; the ROM's bytes are unchanged. The tests cover the op's and fields' layout (the header test, the kext's vblank clock test), the bit's negotiation (the kext's features test, the peer and memory-map tests), the stamps (the bundle's serializer and shell tests) and the walk (a cmdbuf test, and the fuzz's streams). The host's reading of the stamps is the next commit. |
||
|
|
15801990cd |
🐎 Ring an asking buffer's doorbell apart from the rest
The host can take a queue's doorbell with no exit to its process only where the write needs nothing of it but a wake, and a write of the ring's id alone could be a buffer that asks for its CB_SUBMITTED, which the host answers inside the write. Where the device offers DOORBELL_ASKS, the kext takes it and the bundle writes an asking buffer's doorbell with the ring's id and RGFX_DOORBELL_ASKS (bit 0), every other doorbell with the id alone. On a host that does not offer it the bundle writes the id alone, as before. The kext writes what the bundle hands its doorbell call, so it needs nothing more than the bit in its carried features. Tested by the kext's features test and the bundle's test_ring_doorbell_asks_where_the_device_takes_them. |
||
|
|
7c9c37a4f6 |
✅ Hold the guest tests' timing checks under load
Batch 42's guest test (job m3-max-25789) failed under the M3's load at serializer_tests.cpp's CHECK(ending.calls.empty()): with setBatch's timer at 1 ms, a test thread held off a CPU for 1 ms after postLater let the timer post before the writer's end. It is the class of the room-record test's failure: a check that holds only while a thread runs within a time window. The other guest test sites of it, found by reading every sleep, clock read and timer delay in the bundle's and the kext's tests: - serializer_tests, test_held_destroys, the writer's end: a run counts only where the look at the calls comes within the timer's 1 ms from before the post; runs repeat, up to 50, until one does. The calls are read under the log's lock, as the timer's thread writes them. - serializer_tests, test_ring_post_waits_for_room: the post's time, checked to be at least 15 ms, was counted from after the host's thread started its 20 ms; it is now counted from before, so a late start of this thread no longer shortens it. - queue_tests, test_submitted_waits_for_the_buffers_before: the same for the 40 ms the wait must last, against the thread that commits after 50 ms. - shell_tests, test_submitted_at_the_doorbell_wakes_no_thread: the completion thread's late wake came 400 ms after the doorbell, and the test checked the call took under 200 ms and the record was still untaken. The wake now waits for the test to let it go (or 5 s), so the test checks the call returned before the wake and the record untaken, with no window. Each keeps what it checks. The rest hold under any delay: lower bounds counted from before what they wait for, negative checks of work nothing lets run, and bounded waits of seconds. |
||
|
|
ba1cf087e8 |
✅ Count the room-record test's runs only inside the backstop
test_ring_post_waits_for_the_room_record checked that a post still waited 3 ms after the host took room with no record, and that the record ended the wait within 15 ms. The wait's backstop ends it 20 ms after it began (RgfxRingWriter.cpp's kRoomBackstopUs), and under the load of batch 41's check (job m3-max-25671) the test's threads were held off a CPU long enough for the backstop to come first: CHECK(!posted) failed, where the test passed alone (25724). The post's own look after it stores the flag could also find the host's take when its thread was held between the two, as the test took room once it saw the flag. The test now takes room only after the post rang the doorbell, which it does once that look found no room, so from then on only the record or the backstop ends the wait. A run counts only where it ends inside the backstop from before its post began: the record alone can then have ended its post, which was still waiting when looked at 3 ms after the take. Runs repeat, up to 50, until one counts. A post the record does not wake never counts, and one that does not wait fails the run that counts. |
||
|
|
8430562098 |
🐎 Hold textures, views and Managed creates with the destroys
A texture's create (TEXTURE_CREATE), a view's (TEXTURE_VIEW), a Managed
texture's and buffer's (MANAGED_TEXTURE_CREATE, MANAGED_BUFFER_CREATE) and a
Managed buffer's modified range (BUFFER_DID_MODIFY_RANGE) are messages no one
waits for, each its own Submit call: on the RX 7900 XTX host 8 to 13 us each,
812 of them and 8.8 ms a Vision process. SubmitBatch now takes them too, each
of its one size, checked as Submit checks it, a create for a context closed
since its check destroyed behind it (rgfxSubmitBatchSize). None names a block,
which spans_test keeps. The bundle holds them with the destroys and the
heap-placed buffers (RgfxSerializer::postUnwaited), in their order, posted
before anything else the process posts or asks of the kext and before any
command buffer it commits. A texture over an IOSurface still goes at once, as
a present of the surface waits for it, and so do the creates that name a block.
This changes what the guest sees under transport exhaustion only (the control
ring full for 5 s, or the device stopped), as
|
||
|
|
88b34b304a |
🐎 Hash library keys in 256 KiB pieces on the guest's cores
A library's content key was one SHA-256 over its bytes past the bitcode
section: 2.9 to 6.2 MB for the MPS and Espresso libraries a Vision request
loads, hashed by CommonCrypto at 567 MB/s on a guest core (the RTX 3090 host's
guest, with or without the CPU's SHA extensions, which CommonCrypto does not
use), 30 ms of every process's newLibraryWithURL. The key is now
"rgfx-library-v2": SHA-256 of the prefix and of each 256 KiB piece's SHA-256,
in order, and the bundle hashes the pieces at once (dispatch_apply_f); the key
of a library's whole bytes, new on this branch, takes the same form
("rgfx-library-whole-v2"). The host computes both the same way, and both
sides' tests pin the same digests, a multi-piece library's among them.
wire.h is regenerated from wire.rs's new definition, so the ROM's record moves
(its bytes stay the same). An older guest set on this host keys its libraries
the old way: the host then vouches for none of them, so they are made in each
process, uncached, as before the cache. The host's persisted pipeline records,
keyed by their libraries' keys, go cold once.
Measured with the previous commit (rts2 against rts4, RTX 3090 host, load 3.4
and 3.0): newLibraryWithURL, 18 loads, 49.0 -> 18.3 ms in the first process,
44.5 -> 18.0 ms in the second; the three default.metallib loads that hash MPS's
and Espresso's libraries 7.3, 15.5 and 12.0 ms -> 2.8, 4.9 and 3.8 ms.
|
||
|
|
a6210a27d7 |
🐎 Key the libraries the host cannot vouch for by their bytes
The host keeps a library under its content key only where it checked every function's HASH tag against its bitcode. Core Image's libraries fail that check: all 232 functions of ci_stdlib share one module whose HASH is no SHA-256 of it. So ci_stdlib and ci_filters were made again in every process, twice each in a Vision process (1.5 and 2.5 to 3.7 ms a load on the RTX 3090 host), and their bytes crossed each time. The host now keeps such a library of at most 4 MiB under the key of its whole bytes, SHA-256 of "rgfx-library-whole-v1" and them, which it computes from the bytes it stores, so no guest can bind other bytes to it; the bundle asks for that key after a miss on the content key. No wire change: LIBRARY_LOOKUP takes either key. Measured with the next commit (rts2 against rts4, RTX 3090 host, load 3.4 and 3.0): the libraries' uploads (LIBRARY with a region) 5 calls and 8.0 ms -> 1 and 0.2 ms in the first process, 4 and 4.7 ms -> none in the second; the first process's second loads of ci_stdlib and ci_filters 1.53 and 3.82 ms -> 0.24 and 0.20 ms. |
||
|
|
628b03fb37 |
🐎 Hold heap-placed buffers with the destroys around them
A heap's buffer at an offset (BUFFER_AT_OFFSET, each small buffer of a slab) is
a create no one waits for, and cost its own kext call: 3079 a Vision process,
12 to 15 us each, 40 to 48 ms a process on the RTX 3090 host, between the
destroys, which broke each held run of destroys into one call of about 11.
SubmitBatch now takes BUFFER_AT_OFFSET too, of its one size, checked as Submit
checks it, and a buffer made for a context that closed since its check is
destroyed behind it, as Submit does (RgfxSubmitGate's rgfxSubmitBatchSize;
spans_test checks no message the batch takes names a block). The bundle holds
each buffer with the destroys, in their order, and a command buffer's commit
posts what is held before the buffer goes on its ring, as the host reads a
command buffer after the control ring's messages posted before it.
This changes what the guest sees under transport exhaustion only (the control
ring full for 5 s, or the device stopped):
- before, the buffer's create was refused there and the buffer was nil; now
it is answered as made, held, as Metal makes objects on a GPU that is gone;
- before, a command buffer committed on a stopped device was never answered,
and the run hung at its wait; now a commit that finds a buffer still held
fails the command buffer, unposted, with MTLCommandBufferErrorInternal
("Discarded (victim of GPU error/recovery)"), the host's own recovery error,
as the buffer may name it;
- the next post retries what is held and is refused where it is refused
again, and a buffer that needs the held gone to make room is refused at
once, holding nothing more.
Tested by serializer_tests' test_held_buffers and protocol_tests'
test_commit_behind_an_untaken_buffer_fails.
Measured, Vision cold request, RTX 3090 host (rts2, the destroys held,
against rts4, this commit and the next two; load 3.4 and 3.0): destroys and
heap-placed buffers together 62.0 -> 17.6 ms in the first process (3079
buffers and 294 destroy calls become 688 SubmitBatch calls), 51.6 -> 16.1 ms
in the second.
|
||
|
|
7e8ea3c46f |
🐎 Post a process's destroys in one kext call
Each destroy cost the guest a trip into the kext, and a post that found the host's control thread asleep a doorbell's exit too: 14 us a destroy in a Vision request on the RTX 3090 host, 3415 destroys and 68 to 70 ms a process, in runs an app lets go back to back. The kext now carries SubmitBatch (selector 5, feature bit 1 << 1): the bundle holds each destroy (RgfxRingWriter::postLater) and posts what it holds in one call of at most 4096 bytes, before anything else the process posts or asks of the kext (every IOConnectCall goes through rgfxKextConn, which posts the held first), once the held fill a call, or 1 ms after the first held. The kext checks each as Submit checks one, all before it posts any, puts the runs on the ring under one hold of its lock with one doorbell at most, and ends a queue's as Submit does. A texture over an IOSurface goes at once: a present of the surface waits for its destroy. What an object lay over goes back as its destroy is held, as it went back once the destroy was posted: whatever takes it again is posted after the destroy, so the host drops the object first, and every answer the guest reads (a heap's usedSize, a new object's GPU address and resource id) is the one it read before (shell_tests' test_held_destroys_change_nothing_seen). Where the kext stops taking them (control ring full 5 s, or the device stopped), the rest stay held; the next post retries them under its own bound and is refused only where they are refused again. The one difference, under that exhaustion only: what the held destroys lay over has gone back, so a heap's usedSize read during a 5 s stall of ring 0 reads lower than before (design.md, "Destroys go together"). Measured, Vision cold request, RTX 3090 host (rts1 against rts2, load 3.6 and 3.4): destroys 69.6 -> 18.6 ms in the first process, 67.7 -> 14.7 ms in the second; all kext calls 216 -> 162 and 188 -> 135 ms. |
||
|
|
34efdc631a |
🐎 Ring a walking queue's doorbell only for a buffer that asks
While a queue's service thread walked a buffer on its own thread, it marked the ring as it marks it before it sleeps, so the guest rang the queue's doorbell for every buffer it published meanwhile: a VM exit that answered nothing for a buffer that does not ask for its CB_SUBMITTED, in two of three commits of a back-to-back run on a 26.7.2 guest (11.9 µs a doorbell on a 780M host). The thread now marks the ring walking (consumer_idle 2, RGFX_CONSUMER_WALKING), for which the bundle rings only for a command buffer whose last op is its ask, which the doorbell's write may answer; the thread takes the rest after the walk, as before. A bundle that rings only for 1 rings for none during a walk, and its asking buffer is answered at that take. What the guest sees: consumer_idle reads 2 during a walk, where it read 1. Measured with commit_split, before and after in one job each, cold boots of 26.7.2 on um870 (m3-max-23492, m3-max-23493): - RTX 3090: a back-to-back commit 15.8 -> 2.2 µs (median), doorbells 0.57 -> 0.30 a commit, 22.5 -> 20.2 µs a buffer over 100,000 buffers; a commit's CPU time in encode_probe's cb.commit 19.6-21.2 -> 15.3-15.7 µs. - Radeon 780M: 44.5-46.5 -> 44.7-45.3 µs a buffer, bound by the host's submits; doorbells 0.66 -> 0.54 a commit, the rest of them posts that wait for room; cb.commit's CPU time 19.6-20.2 -> 18.4-18.9 µs. An idle queue's single commit rings as before (16.4-17.4 µs on both). |
||
|
|
ecf693f1bf |
🐎 Build a large command buffer's message off its block
A message too large for half its queue's ring was built in a block of the queue's pool once it outgrew the ring, and grew from block to block. The block is write-combined where the kext maps it so, and on an AMD host, which applies the guest's memory type, a write-combined store still pending stalls the encoding thread's next locked instruction until it drains. Every retain and release on that thread, the app's and ours, paid it: on a 26.7.2 guest of a Ryzen host (RTX 3090), encode_probe's setRenderPipelineState took 108 ns a call in a 10000-call buffer against 21.6 ns in a 400-call one, which stays on the builder's heap, and a setVertexBuffer between a CFRetain and a CFRelease 103 ns against 17.1 ns. Growing from block to block also read the old block back, uncached. The message is now built in the builder's own buffer whatever its size, which grows to the queue's guess as it outgrows the ring, and the commit copies it once, whole, into a block from the block's start. The host reads the same COMMAND_BUFFER bytes; only where the message lies in its block changes. The tests that held the old placement change with it. |
||
|
|
a5c9010efc |
🆕 Answer each format's own minimum linear texture alignment
The device answered minimumLinearTextureAlignmentForPixelFormat: with linearTextureAlignmentBytes, the largest of every format's, for each format. On a host GPU whose linear images ask more of larger texels that is too much for the smaller ones: a Radeon RX 550 answers 256 bytes for texels of 1 to 4 bytes, 512 for 8 and 1024 for 16, and Geekbench's MPSImageGaussianBlur source, an RGBA8Unorm texture over a buffer with rows of 7680 bytes, was nil against 1024. What the guest observes changes: - each format answer of the device info carries the runtime's alignment of that format in its last two bytes (0x3e, `linear_alignment`, which were zero): 0 where the runtime has none (compressed, depth and stencil formats) or one past 65535; - the bundle answers minimumLinearTextureAlignmentForPixelFormat: with the format's own, and with linearTextureAlignmentBytes where the blob has none, so the video output planes align to R8/RG8/R16/RG16's own answers too; - linearTextureAlignmentBytes and deviceLinearTextureAlignmentBytes stay the largest of every format's. |
||
|
|
50be7d4a9a |
🆕 Carry compute dynamic libraries to the host
An x86-64 guest's device made no dynamic library: newDynamicLibrary:error: and newDynamicLibraryWithURL:error: were RGFX_UNSUPPORTED, so a kernel linked against a dynamic library could not be made. The platform makes them and links them (the commit before), and nothing carried them from the guest. What changes for the guest: the device offers feature bit 40, DYNAMIC_LIBRARIES (FEATURES_HI bit 8), on every host, and the kext takes it. Where taken, ring 0 carries DYNAMIC_LIBRARY_CREATE (0x239: the dynamic library's ObjId and its library's), answered by COMPLETE with its status, and a COMPUTE_PIPELINE_CREATE ends with a run of RgfxPipelineLibrary records (library_count, where reserved_5c was): each a dynamic library, preloaded where it has no install name, else the library that install name loads. The bundle's RgfxDynamicLibrary answers its library's install name and writes its bytes to a file URL; newDynamicLibraryWithURL: reads the file in the guest's process with the AMD Radeon Pro 5300M's and the Intel UHD Graphics 630's answers (measured, macOS 26.7.1, oracle_urls and oracle_fnptr: a nil URL, bytes that are no metallib, a library that is not dynamic, a missing file). Metal reads the file each install name of a library made from a file names when it creates a pipeline, and none of a library made of bytes or of source (measured, both Macs, oracle_fnptr: the linked kernel's file makes its pipeline, and the same bytes through newLibraryWithData: are refused). The bundle reads them then too: every name the kernel's library, its linked functions' libraries and these dynamic libraries name, from the executable's directory, the loading library's or an absolute path, each sent by name. A name that loads nothing, or that a library of no file names, refuses the pipeline with the 5300M's CompilerError 2, beside a preloaded library or not, so the host is never left to read a file of its own. A dynamic library's install name is read from its metallib's HDYN NAME tag. Render stages carry none. A compile of source whose options name dynamic libraries reads each through the private member airData, the one message Metal sends it (measured, both Macs): the bundle's dynamic library answers its library's bytes, as Metal's answers its file's, where it ended the guest's process with an unrecognized selector before. The caller owns the answer, as it owns Metal's, which is a new object at each call: the compile releases it, and an unowned answer ended the guest's process with SIGSEGV after the compile. supportsDynamicLibraries stays no in this commit; a later one answers it once the guest's sets carry this bundle. supportsRenderDynamicLibraries stays no, as the 5300M answers it. The host knows bit 40 (KNOWN_FEATURES); the tests that probed an unknown bit at 40 probe 41. The decoder's tests make dynamic libraries on the fake platform and pass a run's libraries to the creator; the serializer's, the shell's (the linkage reader, the routing and airData, a pipeline's loads and refusals), the kext's and the members register's tests cover the guest's side, and design.md describes the messages. |
||
|
|
149fc57c85 |
✅ Hold the join test's first memory as the kext does
test_region_pages_join_over_remapped_memory failed now and then at its check that new memory mapped over the first (VM_FLAGS_OVERWRITE) has another identity than the first (rgfxPagesIdentity). The identity is the memory's vm_object's id, which a new object can take once the old one is freed, and the test's fake block source holds nothing of the first memory, so the overwrite freed it. Production does not: the kext wires a pages block's memory (its IOMemoryDescriptor's prepare), which keeps the first memory's object alive while the block is held. Measured in a macOS 26.7.2 guest of our device on an Iris Xe, 200 overwrites each: with a no-copy buffer over the first memory alive, the new memory's identity was the old one's in 0; with no buffer, in 198. So the join cannot be fooled by a recycled id while the block it would join is held, and the identity needs no change. The test now holds a memory entry of the first memory to the end, as the kext's wiring does, with a comment saying why. Measured on macOS 27.0.1 (the M3 Max), 5000 overwrites each: the identity was the old one's in 0 with the entry held, and in 717 without it. |
||
|
|
019d941b54 |
🆕 Carry compute function pointers to the host
An x86-64 guest's device made no function handle or visible function table: the bundle's members were RGFX_UNSUPPORTED and the device info held supportsFunctionPointers at no, so an app took its fallback. The platform makes them for a compute pipeline (the commit before), and nothing carried them from the guest to it. What changes for the guest: the device offers feature bit 39, FUNCTION_POINTERS (FEATURES_HI bit 7), on every host, and the kext takes it. Where taken, ring 0 carries FUNCTION_HANDLE_CREATE (0x236: the handle's ObjId, the pipeline state's, and its function as an RgfxLinkedFunction) and FUNCTION_TABLE_CREATE (0x237: the table's ObjId, the state's and its entry count), each answered by FUNCTION_POINTER_STATE (0x40c: the status, and a table's gpuResourceID, allocatedSize and resourceOptions), and FUNCTION_TABLE_SET (0x238: a range of a table's entries, 0 a nil entry), which is not answered and is carried out before any command buffer the process posts after it. A compute pass binds a table at a buffer index (RGFX_OP_COMPUTE_SET_VISIBLE_FUNCTION_TABLE, 0x201e) or a range of them (0x201f), and an argument buffer holds a table by its gpuResourceID. The bundle's RgfxFunctionHandle and RgfxVisibleFunctionTable answer from the host's state; a handle of a function the state does not link is nil, as Metal's is (RGFX_STATUS_NOT_FOUND), and gpuResourceID of a handle and functionHandleWithName: raise the unrecognized selector the AMD Radeon Pro 5300M and the Intel UHD Graphics 630 raise (measured, macOS 26.7.1). A table's allocatedSize and resourceOptions are the host's table's, inside the two Macs' answers. A render pipeline's handles and tables stay unsupported, with Metal's error. supportsFunctionPointers stays no in this commit: the next one answers it. The host knows bit 39 (KNOWN_FEATURES), so a driver's write of it is taken. The decoder's tests make handles and tables on the fake platform and call through them on the Vulkan platform; the serializer's, the shell's, the kext's and the members register's tests cover the guest's side, and design.md describes the messages. |
||
|
|
f5030a5f78 |
🆕 Carry rasterization rate maps to the host
The x86-64 guest's device made no rate map: newRasterizationRateMapWithDescriptor: was RGFX_UNSUPPORTED, and the device info held the layer count at 0, so an app that asks for a rate map (Apple's Modern Rendering sample among them) took its path without one. The platform makes rate maps (metal2vulkan's runtime compiles Apple's map, rate_map.rs there), and nothing carried one from the guest to it. What changes for the guest: the device offers feature bit 38, RATE_MAPS (FEATURES_HI bit 6), on every host, and the kext takes it. Where taken, ring 0 carries RATE_MAP_CREATE (0x233) and RATE_MAP_RESET (0x234), both RgfxRateMapCreate (the map's obj_id, the screen size, the private mutability where set, and the layers' RgfxRateMapLayer records with their samples), answered by RATE_MAP_STATE (0x40a: the map's screen size, granularity, layer count, mutability and parameter data's size and alignment), and RATE_MAP_QUERY (0x235), answered by RATE_MAP_ANSWER (0x40b): a layer's physical size, a coordinate mapped either way, or a copy of the parameter data, which the platform writes where a buffer of the sender's lies before it answers. A render pass names its map after its other records (RGFX_PASS_FLAG_RATE_MAP, RgfxRenderPassRateMap). The kext admits the three messages, waits for their answers, and destroys a create it timed out on. The bundle's map (RgfxRasterizationRateMap) answers the host's state, asks the host each answer that takes an argument, copies into a Shared buffer of ours in place and into any other through a scratch buffer of its own, answers the SPI's mutability, minFactor, resetUsingDescriptor: and formattedDescription: (the words of Metal's base map, measured on the AMD Radeon Pro 5300M), and ends the process where Metal's map does: at a copy into a Private buffer, and at a coordinate map the host refuses (a map of no layers or of an empty screen, a Mutable map not yet reset). The layer counts stay 0 in this commit: supportsRasterizationRateMapWithLayerCount: answers no until the device info answers the platform's. The core platform's map gains screenSize, which the state answers. New tests: the decoder's create, reset, queries and copy (decode/rate_map.rs, on the fake and on Vulkan), a pass's map (cmdbuf.rs), the header's checks of the new names, the kext's feature, gate and reply types, and the bundle's messages (serializer_tests), map (shell_tests, its two deaths among them) and pass record (protocol_tests). |
||
|
|
276e4ea3d3 |
🐛 Join a pages block only over the memory it was given for
|
||
|
|
fe9a056b7b |
🐛 Carry each sampler's LOD bias and reduction mode to the host
A guest's samplers lost lodBias and reductionMode (macOS 26) on the way to the host: SAMPLER_CREATE's extension, RgfxSamplerCreateExt, was on the wire, but the bundle never sent it and new_sampler never read it, so every sampler was made at bias 0 with weighted-average reduction. The guest's state cache already keyed on both, so two descriptors that differed only there were two guest samplers of one host shape. The bundle now sends the extension with every create, on the posted and the asked route. new_sampler sets the platform's reduction mode and its new LOD bias from it, and leaves both unset for a create without one, which keeps Metal's defaults. What the guest sees changes: a sampler of minimum or maximum reduction samples that way, as Metal's does. The runtime's sampler descriptor holds no bias yet, so a non-zero bias still samples at 0, and is now relayed as inexact-sampler-lod-bias, with an accuracy-ledger row, until the runtime takes one. The header follows wire.rs's doc, the ROM's record that header (its bytes are unchanged), and both guest sets are built again from these sources. |
||
|
|
b22535736b |
🐛 Answer Metal's 16 for both IOSurface alignments again
Since |
||
|
|
fedd9e8410 |
🐛 Make no-copy Managed buffers over app pages Managed on the host
A no-copy Managed buffer over writable app pages was one copy on every host:
the bundle sent its BUFFER_OVER_PAGES with Shared storage, and its
didModifyRange: and a blit's synchronize of it, or of a texture over it, sent
nothing (
|
||
|
|
00268441aa |
🐛 Lay no-copy buffers over the same bytes in one pages block
Each no-copy buffer over the app's own pages took a pages block of its own, so two buffers over the same bytes had two host views of the same pages, and where the views' gate refuses their import (a buffer of scattered guest pages at the stock vm.max_map_count on NVIDIA), the runtime made a copy and a snapshot for each. Apple's OpenCL makes such buffers: a Shared no-copy buffer over its staging pages at each clEnqueueWriteBuffer, the same pages each time, while the one before still lives. On the RTX 5080 host, each 256 MiB of them cost QEMU 512 MiB more Rss per write. The region now gives a block asked for the same bytes, writability and join again while it is joinable, so such buffers lie in one view and one copy, as on a Mac they lie in the same pages. A block stays joinable until each buffer over it has gone for the app, so a block is never joined over memory the app freed and took again at the same address, and it goes back to the kext once the host has dropped every buffer over it. A buffer of Metal's private bit 24, which the host's runtime takes as read-only memory, joins only its own kind. Nothing changes for the guest: each buffer keeps its object, GPU address and contents. Tests: the region's joins and their release order, two no-copy buffers over one block in the bundle, and the host's one view under two buffers. |
||
|
|
18b642dab8 |
🐛 Pass the host's IOSurface texture alignments to the guest
The guest's Metal device left iosurfaceTextureAlignmentBytes and iosurfaceReadOnlyTextureAlignmentBytes to the IOGPU base, which answers 16 from its own state, so the host's answer in the device info never reached the guest. CoreAnimation rounds the rows of its backing stores' IOSurfaces to iosurfaceTextureAlignmentBytes (to no less than 64 bytes) and names them to IOSurface, which keeps them. On RADV, which takes a linear image in place only at rows a multiple of 256 bytes, those 64- and 128-byte rows are the runtime's shadows. In a macOS 11.7.11 guest on a Radeon 780M, 1399 textures were shadows for their pitch over a cold boot and a 15 s Safari scroll, and 11 with the device answering 512. The device now answers both from the device info, which carries the Vulkan platform's answers. What the guest observes: since pin 37 the runtime answers the device's linear row alignment there, so on RADV (GFX9 to 11) the guest now sees 256 where it saw the base's 16, and CoreAnimation's backing stores take rows the host's GPU takes in place; on other GPUs it sees that GPU's linear row alignment. The device-info doc said an IOSurface's rows follow none of the device's answers; it now says which answers they follow. |
||
|
|
93a1c790d0 |
🐛 Number the user client's calls where every web sandbox allows them
On macOS 12, Safari's web content process may call only the external methods its sandbox lists on an IOAccelerator connection: 0-13, 15-18, 22-24, 28-31, 40, 42, 48, 256-265, 267, 268 and 512 in every Safari from 15.1 to 17.6. Its sandbox refused Features (0x10f) before the kext saw it, and the bundle went on without the kext's features: it took 64-id chunks where the kext granted 16, and the host refused the textures past each chunk's first 16 ids (BadResourceId), so pages drew without their body and text. Under Safari 15 and 16, SurfaceBlockRelease (0x10a) and SurfaceRetire (0x10d) were refused too. macOS 11, and 13 and later, list no numbers. What the guest sees: - New selector numbers, selector map 1: Features 3, PagesBlock 4, TakeAnswers 7, SurfaceBlockRelease 8, SurfaceRetire 9, and a shared event port's Export 10 and Import 11. 1, 5 and 6 stay reserved, 2 is given to none, and the rest keep their numbers. No number of map 0 takes a new meaning, so a bundle or kext of map 0 is refused, not misrouted. - Features answers a third word, the selector map, and keeps its number in every map. A bundle that meets another map has no Metal device. - ResourceIds answers the chunk's size after its first id, and the bundle takes its chunks at that size. - Where the bundle's setup left a stubbed device (no features, the device info unread or of another version, the context or the user client not opened) or returned silently (the IOGPU base declined), the process has no Metal device, with a log line that says why. A host's video caps of another version still leave the device without video codecs, now logged. user_client_words_test holds the sandbox's set, checks every selector and the kext's routing against it, and checks that every IOConnectCall*Method in the bundle's sources names one of them. design.md's registry gives map 1 and what map 0 was. The kext set is built again. |
||
|
|
a5988ff35e |
✨ Answer the x86 Macs' feature profile, 10002, from macOS 13 on
What changes for the guest: the device's featureProfile is 10002 where it was the host's, 10 on every host so far, wherever the guest's Metal has the MTLArchitecture class (macOS 13 and later), on every host. Where it lacks the class (macOS 11 and 12) the device still answers 10001. Both x86 Macs of the oracle answer 10002 under macOS 26.7.1 (the Radeon Pro 5300M and the UHD 630), and the guest's Metal keys its limits, families and feature queries on the profile. 10 was the M3 Max's, kept only because macOS 26's WindowServer, under 10002, asks for tiled textures of 6 and 7 levels over a buffer, which the device answered nil; the host makes those now (the two commits before), and 26.7.2 composes its desktop under 10002 with them. The answer is made in one place, RgfxFeatureProfile.hpp, which no longer takes the host's profile: the bundle stops reading it from the device info, whose field the host still fills with its Metal device's or the M3 Max's. The profile's unit test, which held the host's answer from macOS 13 on, holds 10002 there and 10001 below; the guest's kext set is built again with it. |
||
|
|
d507d7f650 |
🐛 Answer a feature profile macOS 12's Metal has limits for
macOS 12's Metal keys every limit of a device on its feature profile and has none for the M3 Max's 10, which the device answered on every guest: it left the limits 0 and ended WindowServer at device creation, so 12.x guests never reached a desktop (launchd gave up after 14 runs). The device now answers the host's profile only where the guest's Metal knows it, told by what that Metal has: the MTLArchitecture class, which macOS 13 and later have (13.7.8, 14.8.9 and 26.7.2 boot with 10). Elsewhere (macOS 11 and 12) it answers 10001, as 12's drivers for the 5300M and the UHD 630 do. 26 keeps 10 rather than the x86 Macs' 10002: under 10002 its WindowServer still asks for a mipmapped tiled texture over a buffer, which the device refuses (dgpu-oracle.md, Q11, rechecked). What changes for the guest: featureProfile on macOS 11 and 12 is 10001; on 13 to 26 it is unchanged. |