bedaa0c4cf97d00a3522b38d3287ea8e86025f0d
61
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
5c1dd4f2e1 |
📝 Say where a rebound doorbell page drops its old routes
The device drops the routes on a doorbell page of its old context's queues when a DOORBELL_PAGE_BIND write binds the page to another context, on the host's thread that writes the register. The module doc still said such a route stayed until its queue ended, and neither it, the host trait's unroute_doorbell nor docs/api.md named the register write among the calls that drop a route on the caller's thread, where the host must not wait for a lock it holds around the call. |
||
|
|
18a87b6026 |
🆕 Give the device doorbell pages in BAR 4
A guest's single commit costs 5.4 us against 2.9-3.1 on a native Mac, and about 1.5 us of it is the bundle's call into the kext to write DOORBELL. The device now has a BAR 4 of 256 doorbell pages of 16 KiB, which a guest binds to its contexts through DOORBELL_PAGE_BIND (0x040, `page | context << 8`) where it took DOORBELL_PAGES (feature bit 46). A page is its context's own DOORBELL: a write of a ring's id at its first byte wakes that ring where it is one of the context's queues', and is answered at the doorbell as there when it asks. Every other write is dropped and counted, logged once per kind: at an unbound page or another offset (`unbound`), or of ring 0 or another context's ring (`foreign`). Reads answer 0. A reset unbinds every page. A queue of a context with a page is routed on the page's doorbell (`route_doorbell_page`), and on DOORBELL otherwise. A page bound to another context drops the routes on it of its old context's queues, so the host wakes no ring at a page but its context's. What the host and guest see: - the C API: `rvg_graphics_device_doorbell_write`, the config's `doorbell_pages` (third version) and the callbacks' `route_doorbell_page` (third version), whose thread docs/api.md section 5 names; - FEATURES_HI bit 14 is offered only where the host sets `doorbell_pages`; - QEMU's reims-graphics-pci (b4771167) maps BAR 4 and offers the pages; - a guest that does not take the bit, or a host that does not offer it, has every doorbell on DOORBELL as before: the bind is ignored and every BAR 4 write dropped (`without_doorbell_pages_the_doorbells_are_the_register_s`). The wire header's change rewrites the option ROM's record; its bytes are the same. |
||
|
|
95843e7838 |
✅ Prove a route waiting for the host's lock holds up nothing
QEMU applies a doorbell route under the BQL before route_doorbell returns, so a ring-0 thread may wait for the BQL inside the device. That is safe only if the device calls the route functions holding no lock of its own, and no device function a host calls under the BQL waits for a thread inside one. The device module's doc now names each call site and what it holds: a QUEUE_CREATE, OBJECT_DESTROY or CONTEXT_CLOSE on the context's lane (a ring-0 thread or the control thread) after the queues' table and the ended rings are let go, and a reset on the resetting thread after it let go of ring 0, the display, the completion ring, the table and the ended rings. QEMU's registers are lockless, and its reset holds the BQL, which its route function sees. What a host calls under its lock waits at most for the control thread's display message, a ring's take or post, or the table; the last device's release waits for the threads at most 5 s. the_host_s_lock_held_around_its_calls_while_a_route_waits_for_it_holds_up_nothing gives the test host a stand-in BQL its route functions take: while a create's route waits for it, the thread holding it reads and writes the registers, rings ring 0's and the queue's doorbells and resets the device, and a watchdog ends the process if any call never returns. The route the create took goes once the lock is let go. The C API and api.md name the control thread among route_doorbell's threads, and design.md says which hosts offer DOORBELL_ASKS. |
||
|
|
28250f0bed |
🐎 Route plain queue doorbells to KVM where the guest asks apart
Every command queue doorbell write exited to QEMU and ran the library on the guest's vCPU, though only a buffer that asks for its CB_SUBMITTED can be answered there; the rest need only the queue's thread woken. Measured on the Radeon 780M host, a doorbell QEMU takes as an ioeventfd costs the guest 8.9 us and one run through the library 13.4 us, of a 17.1 us commit. The device offers DOORBELL_ASKS (feature bit 43, FEATURES_HI bit 11): a guest that takes it writes an asking buffer's doorbell with the ring's id and RGFX_DOORBELL_ASKS (bit 0), and every other doorbell with the id alone. The device then answers at the doorbell only an asking write, and gives each queue an eventfd its thread sleeps on, which it hands the host with the ring's id (route_doorbell, a new C API callback at the end of RvgGraphicsCallbacks, its second version). QEMU adds it as an ioeventfd matching the id exactly, so KVM wakes the queue's thread in the kernel and the vCPU goes back to the guest with no exit; the asking write matches no route and reaches the library as before. A guest without the bit sees nothing new: every doorbell is answered as before, and no queue is routed. The device routes at most 128 queues (KVM holds 1000 devices on its MMIO bus, and QEMU ends the VM where KVM refuses one); a queue past them, or one the host refuses, keeps its doorbell on the write, logged once per kind and counted. A route goes as its queue ends, before the destroy, close or reset is answered, and QEMU drops it under the BQL before the callback returns, so a queue made again over the same ring gets every write. The thread drains the eventfd and walks its ring on each wake, so coalesced writes take every buffer in ring order. QEMU's side is vendor/qemu d81bcaac. The guest's side, the ROM's record and both guest sets follow. |
||
|
|
73b79f7e61 |
🐛 Quit a VM whose display read waits for a GPU that stopped answering
QEMU's quit hung for good after NVIDIA's Xid 109 (a context switch timeout) in Apple's Modern Rendering sample, on an RTX 2080 and an RTX 3090: a screendump's read of the display waited for its draw on the GPU, which never finished, and the teardown at the quit waited for the read under the BQL (thread_pool_free), so QMP's and HMP's quit both needed SIGKILL. vendor/qemu 32a9f9a9 waits for the read at most 5 s, the bound the library's release of its last device waits for its own threads, and past it keeps the device to the exit, as a VM whose shutdown pauses it does. What the host sees: such a quit now ends; a quit with no read under way, or one that ends in time, is as before. docs/qemu.md says what was measured, including that a pending screendump holds every QMP monitor while HMP, the vCPUs and the guest go on, and docs/api.md the quit that keeps its device. |
||
|
|
fab4be5201 |
🆕 Show black while the guest's display sleeps
A Mac's display goes dark when the OS puts it to sleep (Energy Saver's timer, pmset displaysleepnow) and lights with the desktop at its wake. The device kept showing the last frame instead, so a sleeping guest looked frozen. What changes for the guest: the device offers DISPLAY_POWER (FEATURES bit 37) on every host, and a guest that takes it sends SET_DISPLAY_POWER (command 8, a 24-byte RgfxSetDisplayPower of display and on, answered COMPLETE), a display command the control thread carries out. A reset turns the panel on. Nothing else the guest sees changes: presents are taken and answered, VBLANKs go on, and modes and the cursor's image stay. What changes for the host: while the panel is off, the device's window and rvg_graphics_device_read_display (QEMU's console and screendump) show black, and cursor_show tells the host the cursor does not show; at the wake both show what the guest shows again. The display callbacks' order now covers the display power commands (docs/api.md). QEMU's reims-graphics-pci needs no change: its console reads the display through read_display. The tests that pinned the offered feature words and the backlog's display command range take the new bit and command. The option ROM is built from the wire header, so its record takes the header's new hash; the ROM's bytes are unchanged (sha256 749434f8...). |
||
|
|
7f44053438 |
🐛 Answer a shared-memory GPU's working set from the guest's RAM
On a host GPU that shares the CPU's memory, the device answered recommendedMaxWorkingSetSize with the platform's device-local memory, a share of the host's RAM, which can be more than the guest's: guests of 8 GiB were told 11864629248 bytes on a Radeon 780M and 24950464512 on an Iris Xe. No Mac answers more than its RAM: a Mac's GPU that shares its memory answers a share of it, from an Intel UHD 630's 0.023 (macOS 26.7.1) to an Apple M3 Max's 0.81 (macOS 27.0.1). What the guest sees now: - On a GPU that shares the CPU's memory (a Radeon 780M, an Iris Xe, an Apple GPU under MoltenVK), x86-64 and arm64 guests alike: the working set is three quarters of the RAM the host maps for the device, rounded down to 16 KiB, or the platform's answer where that is less; about 6 GiB for a guest of 8 GiB. maxBufferLength follows it by its rule (three quarters of the working set, about 4.5 GiB), and so does the kext's VRAM,totalMB (the working set in MiB). - On a GPU of its own memory (an RTX 3090 or 5080, an RX 7900 XTX), and where the host passes no memory map: the platform's answer, as before, the card's own memory, as an AMD Radeon Pro 5300M answers its own 4 GiB less 16 MiB. The RAM is the sum of the memory map's ranges, so no C API value is added: q35's map leaves out the 384 KiB below 1 MiB, and vmapple's under HVF adds its firmware's 1 MiB and config's 64 KiB, both well inside Apple's range. On an Iris Xe, a macOS 14.8.9 guest told 24950464512, 5726617600, 4278190080 or 1610612736 bytes did the same work over a cold boot and a Safari scroll: the runtime's blocks, the page's frames and the presents. |
||
|
|
56acf05064 |
🐛 Let go of the GPU device at the last graphics device's release
The C API's release ended a device's threads without waiting for them, and the library kept its GPU device to the process's end; QEMU never released its device at all, as it unrealizes nothing at its exit. A process that exits with the runtime's device live can end with SIGSEGV inside NVIDIA's driver (the commit before). What the host now observes: - rvg_graphics_device_release of the process's last graphics device waits, at most 5 s, for that device's threads, its objects and their GPU work to let go of the GPU device, then lets go of every GPU device the library keeps: the runtime's device is torn down on the releasing thread before the release returns (GraphicsDevice::let_go_of_gpu, LET_GO_BOUND). - A device callback still running holds that wait up; one that waits for a lock the host holds around the release, for the whole 5 s. Past them the library keeps its GPU devices for the process, as before, and logs a warning naming what still held them. - A device created after the let-go runs on a new GPU device, whose numbering starts again. A release while another device lives waits for nothing, as before. - QEMU tears its device down as it quits, once vm_shutdown stopped the VM for good, with BAR 2 disabled first (vendor/qemu's reims-graphics-pci.c). None of its callbacks takes the BQL, which it holds there. A VM whose shutdown action pauses it, or that was stopped before the quit, keeps its device to the exit as before. A new test (on_vulkan_the_let_go_waits_for_a_callback_blocked_on_the_...) blocks raise_interrupt on a lock the releasing thread holds: the let-go returns at its bound naming the ended decoder, and lets go once the lock goes. The header, docs/api.md and QEMU's side change together. |
||
|
|
df8f36bc9b |
🐛 Answer a device the host's driver refuses as no device
A Vulkan device the host's driver refused at its make (VK_ERROR_INITIALIZATION_FAILED and the other Vulkan failures, its memory run out, or its device lost) ended the process at MTLCreateSystemDefaultDevice() with a fatal line. It is the same class as a host with no Vulkan device, which the library already answers: the platform makes none, and the graphics device's create refuses. Measured on an RTX 2080 behind a Thunderbolt 3 link (driver 620.70.06), whose BAR1 is 256 MiB: each device maps 67 MiB of it, and 8 processes making a device at once had 4 to 6 of them refused with -3 (NVRM: "dmaAllocMapping_GM107: can't alloc VA space for mapping"). The refusals come from makes that race: with other processes' live devices holding 245 of BAR1's 256 MiB, or seven devices of 16 queues each, a QEMU's device was still made, taking about 5 MiB. A QEMU whose device the driver refused died at its realize. What the host observes: rvg_graphics_device_create answers RVG_ERR_HOST_RESOURCES where the driver refuses the device, as it does where the host has no device, instead of the process dying; the library logs an error line naming the refusal first. RVG_ERR_HOST_RESOURCES's message, which QEMU's realize error prints, now reads "the host refused memory, a pipe, a thread or a GPU device", and the header and docs/api.md name the GPU device among its causes. The guest sees nothing: no device is realized either way. No degradation kind changes. |
||
|
|
cd6b7bb2bf |
🐛 Answer framebuffer read to an arm64 guest as its host GPU can
arm64 guests drew WindowServer's menu bar, and some widgets, 100% black. CoreAnimation compiles framebuffer fetch into its generic shader by isFramebufferReadSupported, and that shader blends against the fetched destination whatever the answer. The device answered no to every guest, so the destination was the AIR's NaN. Metal on the M3 Max writes the same NaN for that pipeline and its buffers, so the translation was right; the answer was not one an Apple silicon Mac gives. The x86 Macs split on it (AMD 5300M no, Intel UHD 630 yes, measured again today), and x86 guests keep the AMD answer, which keeps their frameworks off the platform's costly fetch. So the answer now follows the guest: - The C API's RvgGraphicsDeviceConfig gains guest_arch (RvgGuestArch: RVG_GUEST_ARCH_X86_64 0, RVG_GUEST_ARCH_ARM64 1), its second version: a host built before it, whose struct_size ends before the field, serves an x86-64 guest; any other value is RVG_ERR_INVALID_ARGUMENT. The Rust API's GraphicsConfig gains GuestArch alike. - The device-info blob answers isFramebufferReadSupported with the platform's answer for an arm64 guest (yes on MoltenVK, RADV, ANV and NVIDIA, which fetch through the pixel interlock), and no for an x86-64 guest as before. What the guest sees: an arm64 guest's MTLDevice answers isFramebufferReadSupported yes where the host GPU fetches, once the host names the guest arm64 (QEMU, next commit). An x86-64 guest's blob is byte for byte what it was. On ANV and NVIDIA a pipeline that fetches an attachment of a format the runtime does not fetch there (R8/RG8 sRGB, and on NVIDIA the packed 16-bit formats and RGB9E5) is answered nil, relayed. |
||
|
|
031e0e8ca3 |
🐛 Hold the process's exit until the library's GPU steps end
A process exits on one thread, which runs the exit handlers and the loaded libraries' destructors while every other thread goes on. A thread of the library's inside a driver then ends the process: on the RTX 5080 test processes ended with SIGSEGV inside libnvidia-glvkspirv after their tests passed, and the awake thread's touches segfaulted 79 times in six minutes before it got a gate of its own. The runtime's guard covers only the runtime's own threads, and the platform keeps its devices for the process, so dropping them is no way out. So the awake thread's gate becomes the library's: reims_vgpu_vulkan::exit_gate. Each job of the library's threads that may call a driver is a step of it: every reims-vgpu entry (the C API's calls, the device's callbacks, the jobs of lanes, compile threads and surface workers), each compile (a making), a window's frame, a video picture landed or frame encoded, and each call of the video crate's threads, through a new Runtime::exit_step. An exit handler, registered at each device's adoption, as a compile pool starts, after each making and at each power of two of a thread's steps, closes the gate and waits for the steps in progress on other threads, 2 s at most, or 60 s while a compile is among them, as the runtime's guard waits for its makings. A step begun after it ran parks its thread for good, except on the exiting thread. What the host sees: an exit (QEMU's quit, a test process's end) now waits for the library's GPU work in progress, bounded as above, where it could end the process with a signal; a library thread or a call of the host's that would begin work after the exit began parks. docs/api.md says so. Nothing the guest sees changes. Tests: a child process that exits mid-compile with a second compile queued (the first ends, the second never runs), the gate's own exit children, and the awake thread's exit test on the shared gate. |
||
|
|
5a4418c894 |
📝 Say that core is the Vulkan crate's module [ci skip]
reims-vgpu-core is folded into reims-vgpu-vulkan, so the docs, the manifests' comments and the crate descriptions that named the crate name its module now: the crate lists and graph, seven crates, core's files under crates/reims-vgpu-vulkan/src/core, the testkit feature, and what the x86-64 leg runs. The design note that put the decoder in core says where it is, reims-vgpu's graphics::decode, and the path of a deleted file goes. The kache measurement keeps the crate's name, as it was measured then. |
||
|
|
6fb33ecd27 |
🎨 Rename the reims-graphics crate to reims-vgpu-graphics
The crate that holds the reims-graphics device's wire and transport now carries the library's prefix, as reims-vgpu-video does: its directory is crates/reims-vgpu-graphics, its package reims-vgpu-graphics, and its Rust path and log target reims_vgpu_graphics. The guest's, the option ROM's and Ambrosia's Makefiles include the wire header from the new directory, and the prebuilt records name it there. Nothing changes for the guest or the host. The device keeps its name (reims-graphics, QEMU's reims-graphics-pci, PCI 1234:5247), and the wire header keeps its file name and RGFX_ symbols. The C API header is unchanged, and the prebuilt kexts and option ROM are byte-identical; only the records' paths and source hashes move. A log filter names the crate's lines by its new target (REIMS_VGPU_LOG=info,reims_vgpu_graphics=trace), a diagnostic. |
||
|
|
acd9919a93 |
📝 Say the library runs on the Vulkan platform alone [ci skip]
The Metal platform is gone (the commit before): AGENTS.md, README.md and the docs now say the library carries out the guest's calls on the Vulkan platform, on Linux and on a Mac over MoltenVK for development and tests; that the display's shaders live in the Vulkan crate; that `cargo xtask dist` writes target/dist-vulkan on every OS; and that the tests of the Vulkan platform compare with Metal's recorded answers. architecture.md's section 4.6 describes the answer layer and the macOS message layer in place of the metal crate's. conventions.md keeps "core changes as little as the Vulkan and Linux work allows" without its reason, the Metal product. |
||
|
|
a0dc2e80ff |
🔥 Draw the scanout at each refresh, without the host's dirty log
The display showed the guest's scanout again at a refresh only where the host's dirty log said the guest wrote it (scanout_written, QEMU's log over BAR 2's allocations). The scanout shows only at boot and in recovery, and the owner takes its full cost for the simplicity (2026-11-07): the callback, RvgGraphicsScanoutWrittenFn and RvgGraphicsCallbacks' scanout_written, are gone from the C API, with reims-vgpu's ScanoutWrittenFn and reims-graphics' Host::scanout_written. Each refresh while the guest has a scanout now asks the screen to show it again (Screen::present). The window draws it only while it shows the scanout: while a presented surface shows, a refresh draws nothing, and the guest's presents alone draw, as before, so an accelerated desktop's refreshes cost no frame (a 4K window at 120 Hz would otherwise copy about 4 GB/s for nothing). For the host: RvgGraphicsCallbacks loses its scanout_written field, so the cursor callbacks after it move up one pointer; QEMU's reims-graphics-pci no longer sets it (the commit before). For the guest: the boot and recovery screens show what the guest wrote by the next refresh, as before. Window::frames_asked counts the frames a window is asked for, which the new tests read: a refresh draws the scanout while no surface shows, and nothing while one does. |
||
|
|
d4a4431911 |
📝 Describe the architecture and the C API of our device [ci skip]
architecture.md and api.md described Apple's paravirtualized device: its tasks, FIFOs, displays, frames, IOSurface and video devices, suspend and resume, isolated tasks, the suite's runner and QEMU's apple-gfx. api.md now specifies the C API there is, the graphics device's ten functions, with its threads and locks in section 5, which the header cites. architecture.md describes the crates and the device as they are, keeping the section and decision numbers code cites; the numbers of what went are retired, not reused. |
||
|
|
4f5d1d5069 |
⬆️ Build on metal2vulkan fa07d59e81's runtime
Pin moves 17 and 18 in one: metal2vulkan development 6b4b4b0692..fa07d59e81 (220 commits), RUNTIME_VERSION 1807, SEMANTICS_VERSION 1990, ARTIFACT_FORMAT_VERSION 492. What changes for the guest and the host: - Guest RAM on a dma-buf device is a few long chunks, none made ahead, idle ones released; no making or copy waits for a chunk's import. On the 780M the first object over an unimported chunk took 665-692 ms and now 1-2 ms, and a gather's encode about 660 ms and now 23-38 ms. - On Linux the process's exit waits within a bound for the runtime's work, then runs the earlier exit handlers (QEMU's exit notifiers among them). - A colour attachment stored DontCare stores as the driver stores it by default, announced dont-care-store, and keeps its earlier texels, as Apple's GPU leaves them, under REIMS_VGPU_EXACT=dont_care_colors. - Off macOS, the GPU's writes to no-copy memory made with Metal's private option bit 24 are dropped through a copy, as Metal drops them. - Twenty formats Metal makes and the runtime refused, its one-plane YCbCr formats, the padded 10- and 12-bit display formats and transfer twins among them, are made for copies alone; every read, write and render of one stays refused. - A 2D or 2D-array texture over a buffer whose texels run past its length is made, its tail the runtime's own. - Mesh pipelines with maxVertexAmplificationCount above 1 are made, and their amplified draws refused. - ARGB8Unorm destination alpha is blended in the shader where no Vulkan state gives Metal's blend; an executed command's unstrided buffer reads at stride 2^32-1, as Metal reads it. - Encoding costs less per draw: attachment memory worked out once a layout version, host-byte uses kept in the encoder, per-thread argument-table stamps, a bind memo. No degradation kind is added or removed, so answer.rs places nothing new. Cargo.lock is unchanged: the runtime's dependencies are the same, and the lock keeps its metal2vulkan source lines stripped. RuntimeGap:: IndirectCommandUnstridedBuffer, which this tree never named, is gone. Adapted here: - The Linux remap test and the remap docs read Device:: pointer_imports_follow_their_address, in place of the removed DriverFact:: PointerImportsFollowTheirAddress. - REIMS_VGPU_EXACT names dont_care_colors, selecting DontCareColorPolicy:: Kept (platform.rs, docs/api.md, an accuracy-ledger row). - The texture-gap tests take RGB10A8_2P (624), a format the runtime still refuses, since 501 is now made for copies alone. - The MoltenVK tests take the copies-only formats: the formats-the-runtime- lacks test drops 501 and holds the two-plane RGB10A8 family (624-627); a new test makes and copies the nine one-plane formats at every creator as Metal does; the legacy-heap comparison leaves those nine out. Two ignored tests and two accuracy-ledger entries record the runtime's gaps there, asked of metal2vulkan: a kernel's read of one reads zeros, and in a heap its texels are tiled where Metal lays plain rows. Checked on the Mac (MoltenVK), the 780M (RADV, the whole workspace) and the RTX 5080, and the merged tree on um870's 780M with a video decode boot. The Iris Xe leg is still to run: its host stopped answering before the run ended, and the leg runs when the host is back, with any failure fixed forward. |
||
|
|
99bfd0583f |
🐛 Build the library on Linux without the vulkan feature
On Linux the Vulkan platform is the library's only one, yet reims-vgpu and reims-vgpu-c refused to build without their `vulkan` features (a compile_error!), and the code behind it did not compile either: a default-feature Linux build of the package failed. A crate that does not build in a feature setting is a failure, so the platform is now unconditional on Linux. - reims-vgpu's new build script sets `cfg(vulkan_platform)` on Linux, and on macOS with the `vulkan` feature, declared for check-cfg. Every `feature = "vulkan"` gate in the crate is that cfg; the gates of "macOS or the feature", true on every target the library builds for, are gone. - The Vulkan platform's dependencies are not optional on Linux; on macOS they stay the feature's, optional, so the Mac's default build is as before. - reims-vgpu-c makes every handle on VulkanPlatform on Linux whatever its features; the compile_error!s go. Behaviour is unchanged on both OSes: on macOS every cfg answers as the feature did, and on Linux as the builds with the feature did. The docs and comments that said Linux needs the feature say it no longer does. |
||
|
|
89c76816fc |
🆕 Tell the graphics device's host the guest's cursor
The library kept the guest's SET_CURSOR and MOVE_CURSOR for its own window and told the host nothing of them, so QEMU's console never had a cursor for reims-graphics-pci: a VM on the reims-vgpu graphics option shown through QEMU's own displays (SPICE, VNC, GTK, D-Bus) had none, though the pointer moved the guest's, where apple-gfx's displays draw one. RvgGraphicsCallbacks grows cursor_glyph, cursor_show and cursor_move, the display's own callback types, and rvg_graphics_device_cursor_position reads where the guest put its cursor's hot spot. The device queues them onto the display thread in the order its control thread took the guest's commands and its resets, so they run as a display's do and never inside a call of the host's, a reset's included. The glyph is the straight-alpha RGBA the window takes; the cursor shows once the guest has an image while it shows its cursor. A host built against the first version passes 40 bytes and is told nothing. The guest sees nothing of it, and the window is unchanged. |
||
|
|
8970ba8391 |
🐎 Answer a landed download on its ring-0 doorbell's thread
A CPU lock of a surface whose pages already hold its device cache (a decoder's output whose early copy has landed, or a cache nothing wrote) still waited for the control thread to wake and take its SURFACE_DOWNLOAD: p50 95.4 us from the doorbell to the COMPLETE on the 5080 (decode-perf), most of it the idle core's wake. A DOORBELL write of ring 0 through mmio_write_taking now takes ring 0's next message on the writing thread and answers it there, where it is a SURFACE_DOWNLOAD the host has carried out already (Host::surface_downloaded, new, default false), the control thread sleeps with every answer of what it took posted (Submit::asleep, set and cleared under the ring's lock), the block's lane has nothing left and the control completion ring has room. Every lock is tried, the message is copied onto the stack, and nothing is allocated or freed. The host's answer is the caches' own (downloaded_now): true only where its download would answer at once with nothing to copy and nothing to wait for, keeping the download's counts as it does. The interrupt is raised with no lock held. In every other case the control thread takes the download as before. What changes for the host: a ring-0 DOORBELL write through rvg_graphics_device_mmio_write_taking may now post a COMPLETE and call raise_interrupt inside the call, as a queue's doorbell write already may (the header, docs/api.md). The guest sees its answer sooner; its order among ring 0's answers is as the control thread gives it. QEMU 22ae1fd1 takes ring 0's doorbell with an ioeventfd, so under QEMU nothing changes until reims-graphics-pci sends that write through _mmio_write_taking too. Tests: a_landed_download_is_answered_on_its_doorbell_s_thread and a_doorbell_s_thread_leaves_a_download_the_control_thread_must_take (reims-graphics), a_landed_download_s_answer_at_its_doorbell_allocates_nothing (reims-vgpu). a_landed_download_s_doorbell_to_its_answer now measures both writes, in turns over five rounds each. Car 14's stack: device.rs keeps both new methods beside each other, c14-submit-path's mark_idle and mark_awake (a queue's ring, efd360f45) and this commit's download_on_doorbell (ring 0); ring_taking sends ring 0 to download_on_doorbell and a queue's ring to answer_on_doorbell, as before. |
||
|
|
6bfd19641b |
🐎 Serve ring 0's lanes on shared threads kept 10 s
Each of ring 0's lanes (a context's, the presents', a block's) had a thread of its own, made as a message came to a lane with none and gone once the lane had had none for 1 s. So every new surface's block made a thread for its first SURFACE_PAGES, and so did every lane's message after a pause of a second. A thread's start may map a 2 MiB stack and its end unmap one, writes of the process's memory map that a vCPU's page fault waits behind: car 12's B1 counted 345 graphics threads made in 30 s of a WindowServer probe, and a vCPU sat 30 ms or more in a fault while one of them was in munmap of 0x201000 bytes, inside an 81 ms frame (msi RTX 5080; measured). Ring 0's threads, reims-vgpu.graphics-ring0-<i>, now serve the lanes. A lane handed a message while it has no thread is given the thread that went idle last, or one made for it where none waits, and keeps it until it has no message left; the thread then waits for the next lane and goes once it has waited 10 s (reims_graphics::keep, new: KEEP, and a clock the tests move). A lane with nothing to do holds no thread, so the device holds as many threads as it had lanes busy at once in the last 10 s, whichever contexts and blocks they were. A lane with a message is never refused a thread, so the waits the lanes' order relies on still end. Measured on the M3 Max with ring_0_s_threads_under_a_windowserver_probe_s_and_a_game_s_wakes, which replays 30 s of B1's rates (presents at 60 Hz, ten contexts' messages at gaps of 1.1 to 3 s, a new block's pages every 150 ms and again 1.5 s later) and of a game's, wakes made up to their kinds, which make more threads without it than the boots counted: ring 0's threads made in each 10 s went from 177, 183 and 181 to 3, 2 and 0 under the probe's wakes, and those ended from 158, 183 and 185 to 0, 0 and 1; under the game's, made from 14, 11 and 10 to 2, 0 and 0, and ended from 10, 11 and 11 to none. A synchronous create's round trip (a_sync_create_s_round_trip, release, three runs each with this change and without, alternating, on the M3 Max under other builds' load): after a pause of 1.2 s, 64 to 171 us at the median against 116 to 353 us without, where the pause ended the lane's thread; back to back, 13.6 to 16.4 us against 10.3 to 13.9; behind four creates it does not wait for, 10.6 to 12.8 us against 11.7 to 12.5. What this adds to a message for a lane that had emptied is a lane record made again and the hand-over of a waiting thread through its own condvar, where the lane's own thread was woken before. For the host: the callbacks the lanes make (raise_interrupt among them) run on reims-vgpu.graphics-ring0-<i> in place of reims-vgpu.graphics-context-<n>, reims-vgpu.graphics-presents and reims-vgpu.graphics-block-<offset>. Thread names are diagnostics (docs/api.md); the header's comment, api.md and design.md name the new ones. The guest sees only timing. Tests, on the test clock: a_steady_load_s_lanes_are_served_by_one_thread_through_its_pauses (30 messages of three contexts, each after 2 s, on one thread; it goes after 10 s with none), a_burst_s_other_threads_go_once_they_have_waited_keep (three busy lanes' threads, then one lane at a time: the two others go 10 s after the burst, the one serving stays) and the_device_s_end_ends_the_threads_that_wait_for_a_lane. The tests that named a lane's thread now check it is one of ring 0's; an_idle_lane_goes_while_another_context_s_is_busy, whose lane thread no longer exists, is gone. ring_0_s_threads_under_a_windowserver_probe_s_and_a_game_s_wakes is the measurement, run by hand on macOS. |
||
|
|
ed70015809 |
🐛 Answer nil where the runtime refuses an object for a gap
On the Vulkan platform, a runtime refusal at a creator for a gap of its own
or of the device's (Unsupported, but by a GPU family or a device Metal
itself refuses it on; NotImplemented; AppleOnly; a compile's Unsupported)
ended the process at the creator, where Metal makes the object. A Flutter
app's BGRA10_XR render pipeline on an RTX 5060 Ti took a macOS guest down
this way (Unsupported { feature: Format, needs: NotImplemented }).
Behaviour change, for the guest and the host: by default the creator now
answers nil, a pipeline state or a library creator with the runtime's
refusal as its NSError, so core's nil-without-error death never fires;
textures, views, buffers, heaps, functions, sampler and depth-stencil states,
argument encoders, indirect command buffers and rate maps answer nil. Apple's
guest framework then fails the work that names the object, as where Metal
answers nil: what was a VM going down is that exec faulting. In strict mode
(REIMS_VGPU_STRICT=1) each still dies at its selector with the same line.
This keeps the owner's rule on runtime gaps: the gap stays visible, relayed
as the new kind inexact-refused-create (the first of its kind writes a line
naming the refusal and the descriptor's formats, each one is counted) and a
death in strict mode, and it is handed to metal2vulkan. Nothing here makes
the missing feature. A lost device, a Vulkan failure, no memory, an answer
the runtime cannot prove and every other refusal still die at the creator.
The library's own pipelines and shader library are unchanged.
The kind is placed in every_inexact_kind_is_placed_once, the placement test
of this platform's own kinds, which also checks its code is no runtime
kind's. The accuracy ledger lists it.
|
||
|
|
a562b48c14 |
🆕 Read the graphics display back, and show it in QEMU's console
reims-graphics-pci's QEMU console carried input only, so QMP's screendump was always an empty 640x480 image: the login-clock, desktop and lane-gate checks had no way to see the guest's frame once WindowServer presents IOSurfaces, which live in the host's device caches, not in the scanout. For the host: rvg_graphics_device_read_display, the C API's 57th function (additive), reads what the display shows now into the host's buffer: the scanout or the presented IOSurface, through the display's colour, drawn as the window draws it into a texture of the display's mode, BGRA8 rows of width * 4 bytes, black where the guest shows nothing. It gives the mode's size whatever it answers, so a NULL buffer asks it, and waits only for its own draw on the GPU, on a queue of its own. QEMU (vendor/qemu 70a9a466) calls it from the console's gfx_update on a thread of its pool, so the console, QEMU's displays and screendump show the guest's frame. For the guest: nothing. The read answers no present (the window's draw does, through ScanoutDraw::encode, now over encode_shown), tells the guest no mode, and holds a presented surface's block only while its draw reads it, as the window's draw does. A device with no window keeps the guest's scanout in a screen of its own for the reads, offering the same 1920 x 1080 at 60 Hz as before. |
||
|
|
c9b243ff80 |
📝 Say what reims-graphics-pci calls and what its BAR 2 needs [ci skip]
QEMU's reims-graphics-pci writes every register through rvg_graphics_device_mmio_write_taking, so a queue's doorbell may answer its next command buffer on the vCPU; docs/api.md said it called everything but that function. Its BAR 2 is the library's 1 GiB region, with the guest's allocations from 0x400000, where the docs still said 256 MiB and 0x20000, and a 1 GiB BAR needs the machine's max-ram-below-4g=1G, which docs/qemu.md never named: reims-ctl does not add the device, so whoever adds it needs the option too. |
||
|
|
859625a1f5 |
🐛 Keep the graphics display's scanout across a reset
A reset of the reims-graphics device (STATUS 0, or the host's reset) blanked the display: the screen was told there was no scanout, and the window kept its last frame. The kext's start resets the device to take it, and where the start fails after that (the device lists no usable display, IOFramebuffer's start fails) it resets it again on the way out. The OS then draws into the firmware's framebuffer, but the firmware's scanout was gone. The host's window stayed on the boot screen, and nothing the guest drew after that reached it. What the host sees now: a reset leaves the display's scanout as the last SET_SCANOUT set it. A GPU's display engine does the same across a reset of its driver. The screen is told nothing at the reset, and each refresh shows the guest's writes there as before, until the guest sets another scanout or blanks it. A reset while the display pipe shows a surface shows the kept scanout in its place. The guest sees no change: nothing it reads names the scanout. The tests cover the failure after the take on the device and through the window's sink on the testkit's platform. In the crate's tests the window asks the host for no screen, so on Linux they start no UI thread. |
||
|
|
2204e4a7dc |
📝 Name the closes' worker among raise_interrupt's threads [ci skip]
Since the close-cost change, a context's close lets go of its objects on the closes' worker, reims-vgpu.graphics-closes-<i>, and drops the close's drain there. Where its command buffers had already finished, the drain's answers run on that thread: the close's answer, the waiting posts and raise_interrupt. Releases chained behind the drain answer there too. The header promises raise_interrupt only on the threads it names, and this one was missing from the list. It is added to the C API's list, the Rust API's and docs/api.md's. The names list in api.md also gains graphics-video-<i>, the video sessions' worker, which raises nothing. cargo xtask header rewrote the header. |
||
|
|
ff0a952a2b |
🎨 Name the event-waits thread in the reims-vgpu scheme
Every other thread of the library's is named reims-vgpu.<role>, so a sample or a crash log groups it with its device; the watcher of command buffers waiting for shared events was still rgfx-event-waits. It is now reims-vgpu.graphics-event-waits, and docs/api.md's list of thread names has it with the graphics device's others. Thread names are diagnostics (docs/api.md), so nothing a guest or host sees changes. |
||
|
|
f892111aa6 |
🐎 Give each surface block and process a worker turn of its own
The surface worker and the ICB worker were one thread each, so one block's slow view (9000 mappings of a 3840x2400 layer took up to 478 ms on the msi 5080 host) held every other block's SURFACE_PAGES behind it, and one process's ICB creates every other process's. Each worker is now a pool of at most four threads, made as a job finds none waiting and gone after 1 s idle, that runs one key's jobs one at a time in the order handed over and different keys' at once. The surface worker's key is the block (its SURFACE_PAGES, its BUFFER_OVER_PAGES handed over, its release's drops, a buffer over its view at its destroy); the ICB worker's is the buffer's context. A key's job wakes one waiting thread, a ready key that finds every thread busy is counted, and a job runs where it is handed over where no thread can be started. No job waits for another key's job, so the cap cannot deadlock: a BUFFER_OVER_PAGES waits only for its own block's SURFACE_PAGES, which ran before it, and SURFACE_PAGES jobs wait for nothing. A debug build checks it in Unsettled::wait. The one order the single thread gave that nothing needs: two BUFFER_OVER_PAGES of one context on different blocks are made in either order, which no answer orders; the context's later messages still wait for both. The threads are named <name>-<i>, which docs/api.md, the header's comment and reims-vgpu's callbacks doc now say. Beside K blocks that each run 25 ms jobs back to back, another block's job starts after its hand-off in 0.015 ms at the median for K of 1 or 2, 5 to 6 ms for 4 and 35 to 38 ms for 8, where one thread took 24, 115 to 117 and 241 ms (another_blocks_job_beside_busy_blocks, release build, M3 Max, two alternated runs each at load averages of 28 to 52). |
||
|
|
05d23288a2 |
🆕 Carry each block's pages and downloads on a lane of its own
A block's SURFACE_PAGES rode its context's ring-0 lane and its SURFACE_DOWNLOAD ran on the control thread. The kext's hand-over of a surface's put-off pages is a SURFACE_PAGES for the surface's maker, posted from another process's CPU lock or from the release thread, and followed by a download or a release without waiting for its answer. On the maker's lane it sat behind the maker's unrelated messages, or behind a lane held by a maker that had closed, and the download on the control thread could go first. Every SURFACE_PAGES and SURFACE_DOWNLOAD now goes to the lane of the block it names, in ring order, whatever its flags or context. What reads what that lane makes of the block waits for it through its position: a buffer or heap over a pages block, a buffer over a surface's pages, and a release. A context's later messages and command buffers still wait for its SURFACE_PAGES, and a SURFACE_PAGES waits for its context's earlier makes over the same block. So the only order dropped is a SURFACE_PAGES waiting for its context's messages that do not name its block. A SURFACE_PAGES also no longer clears a block's holders, so a release after a hand-over still waits for the other holders' lanes. The lanes' module doc lists every message that names a block by offset and what orders it. What the guest sees: answers to a block's pages and downloads may come before those of messages its maker posted earlier on other lanes. The kext matches answers by seqno. The fuzz now generates every block-naming kind against held block lanes. |
||
|
|
17f6d6cf47 |
📝 Name every thread that raises a graphics interrupt [ci skip]
raise_interrupt's thread list named the control, refresh, queue, compile and ring-0 lane threads and the platform's handler thread, but not three threads of reims-vgpu's that post on the control completion ring. Counted by thread in two boots of 75 processes on the RTX 5080 host (car 8's image, before and after ring 0's lanes), the control ring's interrupt was also raised on a command queue's lane threads (reims-vgpu.graphics-lane-<id>, 84 and 62 times), the surface worker (reims-vgpu.graphics-surfaces, 4196 and 4284) and the ICB worker (reims-vgpu.icb-create, once each). The header's comment, docs/api.md and reims-vgpu's own doc now name them. |
||
|
|
4f666851e4 |
🐎 Carry each process's ring-0 messages out on a lane of its own
Ring 0's control thread carried out every guest process's control messages in ring order, so one slow message, a pipeline compile of tens of ms or a large buffer's make, held every other process's command buffers behind it: their queues wait until the control thread has carried out what they name. The control thread now takes each message and hands the lifecycle messages of a context to that context's lane (`reims-vgpu.graphics-context-<n>`) and PRESENT_SURFACE to the presents' lane (`reims-vgpu.graphics-presents`). Each lane carries its messages out in ring order, made on demand and ended after a second idle. A message waits on the lanes only where an order crosses processes: a present for the creates and destroys of its surface's textures and the closes of contexts that hold one, a block's release for its former holders, a scanout grant for every other context, a resource-ID chunk for its previous holder's close, and a context's first message for every close not yet carried out. A queue's gate also waits for its own context's lane to carry out the messages it names. Each lane's thread waits on a wake of its own: it is woken for its own messages and, where its next message waits for other lanes, as they carry theirs out. With one wake for every lane, a boot of 75 processes on the RTX 5080 host woke every lane at each message any lane took or carried out, so no lane ever went idle, and command buffers waited 1 ms or more for ring 0 1610 times (3266 ms in all) against 428 (1064 ms) on the control thread alone; beside 75 idle lanes a context's burst of 200 messages took 16 to 59 ms at the median against under 1 ms beside none. Display commands stay on the control thread, held, and a reset still drops what no lane has begun, after the lanes' begun messages return. The host's raise_interrupt may now run on a lane, which the header and docs/api.md say (an additive change to the thread list). |
||
|
|
5bde808250 |
🐎 Answer a command buffer on its doorbell's vCPU
A guest write to a command queue's DOORBELL can now answer the buffer at the head of that queue's ring, if it comes through rvg_graphics_device_mmio_write_taking. The answer posts the buffer's CB_SUBMITTED and raises the queue's vector on the writing vCPU, before the queue's thread wakes. The buffer stays on the ring. The queue's thread then takes it as it takes any other, without waiting for ring 0 again. The vCPU only tries locks, and never waits, loops or allocates: the message is copied onto its stack, at most 16 KiB. Any try that misses leaves the buffer to the queue's thread, as before: a lock held elsewhere, ring 0 not yet carried out as far as the buffer waits for, or a buffer that uses a device cache, waits for an event or sits behind a held buffer. The answer takes the buffer's lane turn and its ticket in the commit order together. The begin uses them in place of its own, so queue, commit and ring-0 order are those of an answer at the take. What the guest sees: CB_SUBMITTED of such a buffer arrives inside the doorbell write. A platform refusal of a buffer answered there fails the buffer in its turn, after the answer, as one answered at its take does. Tests: - a counting allocator holds the vCPU path to no allocation; - a reset between the answer and the begin lets the answer go; - a refused make after an answer fails in turn; - the decoder fuzz checks that queue and commit order match the worker-only path; - the device checks that an answered buffer waits for no later ring-0 message. |
||
|
|
55cdab6483 |
⬆️ Build on metal2vulkan e71efbe0e9's runtime
metal2vulkan e71efbe0e9 is c8a0481cf8 plus three stacks (RUNTIME 1747): - Command queues share VkQueues where the device's own check finds the GPU idles at each switch between queues (the 5080), with an unshared form for a queue that must never wait behind another's long command buffer: new_command_queue_unshared. The graphics lane's WindowServer queues (RGFX_QUEUE_UNSHARED) now take it through unshared_queue, which made the plain queue until the runtime had one; on a device that shares no VkQueue it is the queue every create makes. The runtime's exact answers keep every queue on its own VkQueue, so REIMS_VGPU_EXACT gains queue_sharing (QueueSharingPolicy::PerQueue), with its accuracy-ledger row; docs/api.md now also lists extended_range_blits there. - Noted textures' pattern reads and writes are logged once each, with no allocation per draw. - A command buffer joins its ended encoders' resources into its residency where its work reads them, not as each encoder ends (end_call with 4096 resident: 205 to 7.2 us on the RTX 5080); a sampler state's creation prunes the live states' map only once it has doubled (1.97 to 0.56 us at 1000 live, 16.75 to 0.48 us at 10000, on the M3 Max); a commit counts its buffers' host imports in place, and the translator's spec_key makes its lists once. |
||
|
|
da9c930aaf |
🐛 Drop every object the guest made at a device reset
A reset (the framebuffer's STATUS 0, and QEMU's reset of the device at a
reboot inside one QEMU run) put the rings and the display back, but told the
host nothing: the decoder kept every texture, heap, buffer, pipeline, library,
surface view (with its lease on guest RAM and its imports), device cache and
managed copy, and the region kept every block grant. A rebooted guest then met
its own leaked objects: the next boot's WindowServer had its buffer pins
refused by Metal's space ("refused the pin: Held { requested:
400000008000.., held: 400000008000 }"), and its command buffers faulted by
the thousand.
After a reset the device now looks new, as a real device does after a function
reset. Every queue ends and is fenced, no block is any process's, and the host
is told on the control thread (Host::device_reset), before the thread takes
anything published after the reset. The decoder drops every context's objects
as a close does, each in a refusal scope, lowest context first, and with them
the surface views, the device caches (uncopied: the pages are the rebooted
guest's), the library cache, the presents waiting, the pipelines compiling and
the shown surface. Nothing begun before the reset reaches the guest after it:
a poster carries the reset count its work began at, a queue made before the
reset hands the host nothing more (not even its destroy, which the reset
stands for), and a compile begun before it stores nothing.
What the guest observes after a reset: the ids it picks, the texture resource
ids and pinned GPU addresses it uses, and the samplers' ids it is handed are
free as on a new device; a library lookup misses; no answer or event of work
from before the reset arrives.
|
||
|
|
0600467702 |
⬆️ Ring a queue's doorbell with the plain write in QEMU
QEMU 67cc08ad takes reims-graphics-pci's command queue doorbells through rvg_graphics_device_mmio_write again, so the queue's thread takes its command buffers and the vCPU only wakes it. The library keeps _mmio_write_taking, additive and now unused by QEMU. The take on the vCPU did not pay on msi's x86-64 guest. 86% of the compositor queue's doorbells found ring 0 behind and fell back to the queue's thread, so the frame's command buffer was rarely taken inline. WindowServer's composite (CLTD, its CompositeLayersToDestination call's wall time) was a wash at the tip, mean 555 us with the take against 621 without and p50 442 against 435, and the take cost the vCPU about 15 us a doorbell at the p50. Its tail was jemalloc's decay purge, madvise calls of up to 340 us run on the vCPU inside the take's allocations. A cold boot of the x86-64 guest on msi with this QEMU reached the desktop and dragged a window with no fatal or ERROR line; CLTD measured mean 407 us, p50 396, p99 613. docs/qemu.md and docs/api.md say what QEMU calls again. |
||
|
|
38b6912e60 |
📝 Say which locks a graphics raise_interrupt may run under
The header, api.md section 5, the Rust API's GraphicsCallbacks and the device's Host doc said raise_interrupt runs with no lock of the library's held. It does not: on a queue's service thread it runs under the queue's claim on its next message, and some events are posted, and their vector raised, under locks of the library's: - the decoder's lock, at a command buffer's CB_SUBMITTED posted as the buffer is taken, on its queue's thread or inside rvg_graphics_device_mmio_write_taking, and, with the download's answer slot, at a SURFACE_DOWNLOAD answered at once; - a command buffer's CB_SUBMITTED latch, wherever that is posted, which keeps it once and ahead of the buffer's other records; - the presents' queue, at a present answered at once with no window. Moving those raises out from under the locks would delay the CB_SUBMITTED the guest's commitAndWaitUntilSubmitted waits for, or break its order. What a host relies on still holds: no function of the graphics device takes any of them, and rvg_graphics_device_mmio_write_taking only tries the claim and the decoder's lock. So the docs now say that: the library calls raise_interrupt with no lock held that a function it may call waits for, directly or through a thread of the library's, so it may call them at once, and it may still wait for a lock the host holds while it calls the device. api.md section 5 and GraphicsCallbacks name the locks. Two doc errors of the inline take's commits go with it: the Host doc still said no callback runs inside a call of the host's, though Device::mmio_write_taking calls take_command_buffer and may raise there, and GraphicsCallbacks did not name the host's own thread inside mmio_write_taking. A raise_interrupt doc line ran past 100 columns. |
||
|
|
0ee908e0a8 |
⬆️ Point vendor/qemu at reims-graphics-pci's taking doorbell
QEMU f2c7e2a5 sends the vCPU's BAR 0 writes of reims-graphics-pci to rvg_graphics_device_mmio_write_taking. A DOORBELL write of a command queue's ring can then take the queue's next command buffer on the vCPU, post its CB_SUBMITTED and raise the interrupt there, through the irqfd under KVM or the BH elsewhere. The control ring's doorbell still goes to the ioeventfd, and reads are unchanged. Measured on msi under KVM in one boot, the same guest under window-drag load, with the take switched on and off every 20 s (the first 5 s of each window left out; 60 s on, 51 s off): - WindowServer's commit to its wake in commitAndWaitUntilSubmitted fell to 173 us on average, from 218 (p50 168, from 185; p99 440, against 402); - its CA::Layer::commit_transaction-to-display (CLTD) fell to 384 us on average, from 434 (p50 376, from 400; p99 667, against 654). Every 20 s window with the take on beat both windows next to it; - the vCPU took 32% of all doorbell writes, and 62% of the buffers that ask for their CB_SUBMITTED. The rest went to the queue's thread: 2731 because a ring-0 message published before them was not carried out yet, 23 because a lock was held. The 6608 buffers that ask for no CB_SUBMITTED were left too; - a take cost the vCPU 14 us at the p50 and 31 us at the p99, 274 us at most, and a plain doorbell write 2 us. A vCPU-posted CB_SUBMITTED reached the ring 10.7 us after the doorbell, against 199 us for one the queue's thread posted; - the control thread waited for the decoder at 20.6% of its locks, from 15.3%, for 38.2 ms a second in all, from 36.8. 2204 of those waits were behind a take's carried lock. The queue's thread never waited for it. A boot of the plain build (no measurement) reached the desktop and dragged at 59.6 composites a second, with CLTD averaging 369 us and no fatal, ERROR or WARN line in the host log. docs/qemu.md and docs/api.md now say which BAR 0 call QEMU makes, and how the interrupt is sent since 36deb281. |
||
|
|
46324049a2 |
🐎 Take a command buffer on its doorbell's thread
rvg_graphics_device_mmio_write_taking is rvg_graphics_device_mmio_write, except that a DOORBELL write of a command queue's ring first offers the queue's next COMMAND_BUFFER to the host on the writing thread. Under QEMU that thread is the guest's vCPU. Where the buffer asks for its CB_SUBMITTED and nothing need be waited for, the vCPU takes it: it makes the buffer's command buffer, posts its CB_SUBMITTED onto the queue's completion ring and raises the queue's vector. It then hands the rest to the queue's service thread, which walks and commits the buffer before it takes anything more of the queue's. The guest's commitAndWaitUntilSubmitted no longer waits for that thread to wake, which costs about 85 us on msi's host, the exit of an idle CPU from its deep C-state. Nothing on the vCPU waits. Every lock the take needs is tried: the queue's claim, which its service thread holds from its take of a message to the hand-over; the queue's submission ring; the control submission ring; the compile table; and the decoder. Where any is held, the buffer stays on the ring and the write wakes the queue's thread, as rvg_graphics_device_mmio_write does. It also stays there where: - a ring-0 message published before it is not carried out yet; - it waits for an event, or a buffer before it holds its queue; - a pipeline it names is compiling; - a device cache it uses wants a fill, or a wait for one; - its queue holds 48 command buffers made and not completed (the platform's commandBuffer waits at 64); - it does not ask for its CB_SUBMITTED. The CB_SUBMITTED's post on the vCPU waits for nothing either. Where the completion ring is busy or full, the service thread posts it before the walk, where the post is today. The decoder's lock is taken on the vCPU and let go on the service thread after the commit. So every message the guest sends after it sees the CB_SUBMITTED is carried out after the buffer's commit, as it is today. Class: FREE. Only the thread that posts a buffer's CB_SUBMITTED and its timing change. Each queue's events keep its order: the vCPU takes only while the service thread holds none of the queue's messages, and the service thread carries out what the vCPU took before it takes the next. The interrupt still follows its ring write on the same thread. The C API gains the function, additively: the header and api.md list it, and section 5 names the calling thread for raise_interrupt inside it, which must not wait for a lock the host holds while it calls the function. rvg_graphics_device_mmio_write and its "Calls back: never" are unchanged, and so are the pins (re-recorded, no difference). The decoder's lock crosses threads through parking_lot's arc_lock and send_guard. |
||
|
|
b3db450e0a |
📝 Name every thread the graphics raise_interrupt arrives on
api.md section 5, the header's RvgGraphicsRaiseFn and the device's Host doc named only the control and refresh threads. The interrupt is raised on whichever thread posts the event it is for, so it also arrives on a command queue's service thread (an early CB_SUBMITTED), a pipeline compile's thread (a reflection) and the platform's thread that runs a command buffer's scheduled or completed handler. The thread-name list gains the queue and compile threads. Comments and docs only. [ci skip] |
||
|
|
0b798d10f7 |
🐎 Take no dirty source on the graphics device
This reverts 71d7ba107 (Give the graphics device the host's dirty source), 8f1b8b02e (Resolve an import's pages once per range for the dirty log) and 67edfb6ee (its test's fix), and points vendor/qemu at 926401c49, which reverts reims-graphics-pci's dirty source on its branch. With the source, the runtime asked the guest pages behind each IOSurface's import at each command buffer's reports and watches, and the graphics device's thread resolved them through the backing table and the registry, under locks the runtime's queue threads also took. On the msi's RTX 5080, the same guest under window-drag load, the host with the source against the host without it, back to back: - the decode and commit of a command buffer took 5.2-7.3 ms, against 0.33-0.51 ms; - WindowServer composited 27-30 times a second, against 40-45, and its CompositeLayersToDestination averaged 9.65 ms, against 3.24 ms; - QEMU used 122% of a core, against 89%. The copies the source saved, an IOSurface's shadow copied in whole at each use on a discrete GPU, are what the device cache of IOSurfaces replaces. RvgGraphicsDeviceConfig is at its second version again; the third was never in development. |
||
|
|
2705249327 |
🐎 Give the graphics device the host's dirty source
WindowServer composites into an IOSurface the GPU now draws in place over its guest pages. On the Vulkan platform the runtime keeps a render target over host pages as a shadow, copied in before each use: with no dirty source each copy in was the whole surface, 37 MB at 3840x2400, every composite. RvgGraphicsDeviceConfig's third version takes the host's dirty source, as RvgDeviceConfig does, and the device keeps the same harvest and log over the guest's RAM, so the runtime copies again only the pages the guest wrote. The log is closed while the host's reset runs, as a device's is under its host's lock. |
||
|
|
abf6571d4f |
🆕 Let the GPU use an IOSurface's own guest pages in place
WindowServer's composites spent most of their CPU copying IOSurfaces: each GPU view of a surface was a copy of its pages in the region, uploaded at newTexture and written back after every command buffer (55 GB per 10 s on the fix-1 boot, 83% of WindowServer's samples in memmove). With the guest RAM's map in its config (RvgGraphicsDeviceConfig v2, gated by struct_size), the graphics device offers RGFX_FEATURE_SURFACE_PAGES. The kext then names a surface's page runs with SURFACE_PAGES, and the decoder makes one view of them in guest RAM, through core's range mappings, and buffers over it for BUFFER_OVER_SURFACE_PAGES. The runs must lie in guest RAM, be page aligned and sum to the length; else that surface alone is refused and stays a copy. Views are cached by their runs (32 views, 1 GiB), since WindowServer makes a surface's block again about every frame; the map is fixed at create and nothing removes guest RAM under it. |
||
|
|
15eee48dbc |
⬆️ Build on metal2vulkan 45b3427434's runtime
metal2vulkan 45b3427434 is 4ba981e668 plus two things the guest's Metal reaches. Its encoder draws setLineWidth:'s every width as Metal does (the M3 Max, macOS 27.0.1): floor(16 width) / 16 clamped to [0, 16], width 0 as 1/16, by the device's own lines or a band of two triangles over each segment. What neither draws at the width (on MoltenVK, which has no wide lines, a triangle's edges in fill mode Lines and a mesh draw's lines) it draws by the device's lines at the nearest width they draw, 1 pixel there, announcing it. A draw of too few vertices for one primitive draws nothing, as Metal's. And binary functions linked into a pipeline give plain Metal's answers: a direct call to a function only binaryFunctions holds fails as an unresolved call, a function in both lists is made, and one not compiled to a binary fails with Metal's code 2. The Vulkan platform drew every line 1 pixel wide after another width, and relayed it (inexact-line-width), or died in strict mode. It now sends the width to the runtime's encoder, and the relay kind is gone. A new Metal-twin test draws lines and line strips at widths 1, 3, 2.5 and 0 pixel for pixel as the Metal platform does on MoltenVK. Its first vertex is white: the flat vertices' first colour is the clear's black, which hid the line it provokes. Two tests that died at a draw after a line width now leave what such a draw draws to the runtime's tests. The runtime announces two new kinds, placed with the kinds that die: relayed by default, a death in strict mode. device-wide-lines: a device's own wide lines that are not Metal's parallelogram (a strict device's rectangle, lines Vulkan does not state as parallelograms, a width off its granularity), the runtime's default. lines-at-nearest-width: lines drawn at another width than Metal's, where neither route draws it. REIMS_VGPU_EXACT's new name wide_lines takes the runtime's WideLinePolicy::Exact, the band over Metal's parallelogram, on a device with tessellationShader. The accuracy ledger lists the trade in place of the 1-pixel row. A pipeline whose function calls a visible function that only binaryFunctions holds now answers the guest Metal's code 3, where it was made. The Metal-twin test of linked functions drops that exception, and adds a function in binaryFunctions alone and in both lists, compiled to a binary and not. It makes the binary copy after the cases of the function made by name: while the copy lives Metal answers one object for both, of options 1 (measured on the M3 Max, macOS 27.0.1), so the cases after it linked the binary where they named the plain function. |
||
|
|
59df0ffbb5 |
🆕 Add the reims-graphics device to the C API
QEMU drives devices through the C API, so the graphics device gets seven functions there: create and release, the region QEMU maps as BAR 2, BAR 0's reads and writes, the doorbell file QEMU's ioeventfd fills, and the bus reset. Its two callbacks raise the MSI-X vector and ask QEMU's dirty log whether the guest wrote the scanout. Both run on the device's threads with no lock of the library's held, so QEMU may take the BQL inside them, and no function waits for those threads. The additions are strictly additive (docs/api.md section 1): new functions, types and constants, and status 17, RVG_ERR_HOST_RESOURCES, for a host that refuses the region's memory, a pipe or a thread. The C harness calls each new function and drives one GET_DISPLAYS through the region to its interrupt. |
||
|
|
c3aac4c217 |
⬆️ Build on metal2vulkan 0a1851164d's runtime
Move the runtime from eeb7934025 to 0a1851164d, six commits of metal2vulkan's development. What changes for the guest: - A draw, compute dispatch or tile dispatch whose pipeline the driver is still making 4.5 s after its command buffer's commit runs nothing, and the command buffer runs on (PipelineWaitPolicy::Bounded, the runtime's default, announced draw-dropped-still-making or dispatch-dropped-still-making). A state's creation likewise returns after 4.5 s with its predicted pipeline still being made. Before, a cold compile (11.59 s on an M2 Pro's MoltenVK boot) held the command buffer past the guest's 10 s check of its FIFO. - A draw whose pipeline the driver failed to make after the draw returned runs nothing, and the command buffer runs on (draw-dropped-unmade), where it failed before. - A no-copy buffer, heap or buffer rebind whose import fails (out of memory, or a driver out of mappings) is made over a copy of the pages in the device's own memory (copied-host-pages), where the call was refused before. - Nothing else in the span moves what a guest observes. On NVIDIA's driver on the RTX 5080 Laptop GPU, the 2.2 to 3.7 ms stall the driver spends in every 1,024th signalling submit of a queue is taken by empty submits while the queue is idle, not by a batch. A discrete GPU zeroes new buffers by a fill. A warm render state is linked from its recorded stages. The shader cache is keyed by its translator, so a runtime-only change no longer turns it cold. The four kinds are placed in DIES: by default each is relayed and counted, and in strict mode it ends the process, where a difference the guest can see does. Unplaced, they fail every_degradation_kind_is_placed_once. A strict process, every test of this crate among them, waits for each pipeline until it is made (PipelineWaitPolicy::Exact), so a slow compile under the check's load never dies there as a dropped draw. REIMS_VGPU_EXACT names the same exact form as pipeline_waits, and the accuracy ledger records the fast form's bound. A no-copy buffer over host memory with a page not mapped, or mapped without read access, is answered nil before the runtime is asked, as Metal answers it, where development asked the runtime and answered nil at its refusal. At 0a1851164d a placed buffer the runtime refuses keeps its range held, so the next buffer Metal places at that address met a conflict and died (measured on the M3 Max: no_copy_buffers_over_pages_without_access_are_nil_as_metals). Those pages are the only refusal there answered without dying, so nothing else meets the held range. metal2vulkan has the report. The import gate the runtime now takes (HostMemory::with_import_gate) is wired in the next commit. |
||
|
|
12765ee8ae |
🐎 Copy again only the guest pages written since the last copy
Where the Vulkan runtime keeps copies of guest memory in GPU memory (a
discrete GPU's, and an iGPU's whose driver cannot use the guest's pages in
place), it copied each one whole at each use, as nothing told it which pages
the guest wrote. Under KVM the host now gives the device a dirty source, and
the runtime copies only the row bands of the pages written since its copy.
- Core keeps the dirty log: a stamp per watched 4 KiB guest page (8 bytes),
read without a lock, fed by the harvests and by the library's own writes
into guest RAM (every GuestPtr write, the IOSurface byte copies, the video
decoders' lends), each stamped after its bytes land, so a copy racing a
write takes the page again. With no log a write costs one relaxed load.
Waits are bounded (about 4 ms) and refuse at once while the device resets,
pauses, stops or suspends; an answer the log cannot give is a whole copy,
never a missed write.
- The C API, additively: RvgDeviceConfig's fourth version (72 bytes) carries
an RvgDirtySource: the KVM VM's fd and four callbacks (start, flush_vcpus,
for_each_slot, take_host_writes), and rvg_dirty_slot, which for_each_slot
calls for each logged slot. The device's thread reims-vgpu.dirty
runs each harvest: the vCPUs' page-modification logs flushed where PML is
on, one KVM_GET_DIRTY_LOG and one KVM_CLEAR_DIRTY_LOG of exactly the
watched pages written per slot, then QEMU's own DMA. QEMU's side is 154
lines (vendor/qemu 01650c7f08).
- The Vulkan platform answers the runtime's DirtyPages per import, in the
import's offsets, and leaves a shadow's own copy back out of its next copy
in (REIMS_VGPU_DIRTY_WRITERS=0 counts it). The EFI framebuffer is never
logged, so the firmware's presents never start the KVM log.
- REIMS_VGPU_DIRTY_PAGE_TRACKING=0 turns the source off.
- The runtime moves from metal2vulkan 0db5825a60 to eeb7934025, its release
with the dirty-band copies, the discrete GPU's device copies of sampled
textures and one wait per log per submission. It also fixes the MoltenVK
failure the owner hit on the M3 Max with a macOS 26 guest ("Vulkan failure
-3 (the pipeline of draw 0 of the command buffer's render encoder 0)" after
a 4K HEVC decode): Core Animation's fragment that samples the in-place
Y'CbCr texture in a loop had its push field's uvec4[2] materialized with an
OpCopyObject, whose SPIRV-Cross copy Metal's compiler refused; 751c861c15
copies it element by element. And it takes the device's native forms: its
own depth bias on every depth format, its store of an extended-range,
padded 10-bit or bfloat attachment's untouched texels, a half colour output
declared 16-bit where the device enables storageInputOutput16, and its own
Y'CbCr conversion for 4:2:2 twins and planes read in place. Its semantics go
from 1907 to 1911, so every cached shader compiles again on the first boot.
- With the runtime's unused-bits load pass and its capture replay gone, a
pass that loads and stores such an attachment keeps the bytes its draws do
not write, and each draw announces extended-range-bits-kept; the
unreached-tiles-rewritten kind is gone. The Vulkan platform's answer table,
its tests of the extended-range formats and its docs follow, and the test of
the captured reach goes with the machinery.
Measured on an RTX 5080 Laptop GPU with an x86-64 macOS 26 guest
(docs/qemu.md, "Linux hosts: the dirty source"): a window drag at 3840x2160
went from 18.0 to 26.1 fps with 439 MB a frame host to GPU, from 938; at
1680x1050 the drag stays at about 56 fps with 98 MB a frame, from 182, and
SM use 46%, from 65%. Pixels are unchanged. Nothing changes on macOS, nor
where the runtime uses the guest's pages in place.
|
||
|
|
c8ec271abc |
⬆️ Build on metal2vulkan 0db5825a60's runtime
Move the runtime from a759d0e88f to 0db5825a60, metal2vulkan's development re-cut into one commit per work packet (tree 22aab1ece6, the same as its linear history's d0f1b87e2e, which is the public repository's development; 0db5825a60 is not on it yet). Runtime version 1648 to 1681, semantics 1907, artifact format 475; its runtime sources pinned as 4314cee1. Every cached artifact and plan is made again. What changes for the guest: - Answers come from one macOS release, 27.0.1, on every host. MoltenVK on a macOS host of another release answers as 27.0.1 too. MetalLevel, the metal_level of DeviceOptions and DeviceProperties, and the degradations metal-level-below-host, metal-level-not-macos and mipmaps-as-apple-m4 are gone, and so is our side of the levels: the OS's METAL_LEVEL, the level-dependent answers of format_info, the deaths on a host whose release the runtime did not measure, and Inexact::MetalLevel (the same adaptation as development-performance's e47f89760). - The device's own arithmetic and value answers are the contract, with a precision note where they can differ from Metal's (the owner's native-arithmetic rule): BC and sRGB texels, half precision, fast-math grouping, maths functions, sampler details and pixel samplers, two-plane YCbCr (the device's Y'CbCr sampler), clears and fills, multisample resolves, mipmaps (the device's blit chain) and vertex conversions. The runtime's exact emulations of these are deleted, so REIMS_VGPU_EXACT loses sampling, ycbcr_filter, float_maths, texel_conversion, vertex_normalized, half_rounding, nan_and_min_max, rounding_order, half_blend, half_texel_bits, multisample_depth_twin, decoded_texels, tile_store and resolve: such a name now writes the stderr line and changes nothing. It keeps batch_order and host_page_textures and gains half_chains (each half operation of a fast-math chain rounded on a device without shaderFloat16). docs/api.md and the accuracy ledger say so; the ledger lists the deleted forms' bounds as the device's own answers. - Degradations: 17 kinds retired, which leave DIES, NATIVE_RELAYED and the relayed lists. DevicePackConversion, DeviceVertexConversion and DeviceAlphaCoverage, notes of the device's own maths, vertex input and coverage, join DIES and NATIVE_RELAYED, as the other device-maths notes are placed. DeviceFilteredMipmaps, announced on every device, MoltenVK included, is relayed, never a death. None of them is in DIES_BY_DEFAULT, so by default nothing new ends the process. - The read-only store mask is gone: on macOS a read-only view drops the store, as Metal does; off macOS, GPU writes into read-only memory land (the runtime's known gap). set-past-layout-support is announced at every bind past the driver's support. Tests: the YCbCr comparisons and the resolve test run on the platform's own device, as the exact-form devices are gone (device_with_policy and device_with_ycbcr_filter with them); the mipmap tests no longer check the retired tie kind. Checked: - on the M3 Max: rustfmt and the three clippy passes cargo xtask check makes (all features, the tested features without the defaults, and x86_64-unknown-linux-gnu), clean; - the Vulkan crate on gem10's RX 7900 XTX and Radeon 780M, 432 of 432 each; - reims-vgpu's and the C API's video and scaler tests on the XTX, the 780M and msi's RTX 5080 Laptop GPU, 50 of 50 each. Failing, not fixed, at the owner's word (strict mode is not a concern): - the Vulkan crate on the RTX 5080, 429 of 432: three encode_render tests read a channel one code off the byte they assert (0x7f where 0x80), the device's own colour conversion; - reims-vgpu-vulkan's and reims-vgpu's 898 tests on MoltenVK, 796 passing: 102 fail, 57 of them the YCbCr comparisons with Metal, most dying in strict mode at the device notes MoltenVK now announces where the exact forms answered before (device-nan-encoding, native-half-conversion), the rest comparing Metal's exact bits. Not run: the rest of cargo xtask check (core, the Metal, window and video crates, the header) and the suite, which the runtime does not reach; no boot. |
||
|
|
aaec87ae4f |
⬆️ Build on metal2vulkan a759d0e88f's runtime
Move the runtime from f6a96b7da8 to a759d0e88f, the tip of metal2vulkan's development (runtime version 1643 to 1648; its runtime sources pinned as abac6049). metal2vulkan's gate on a759d0e88f was still running when this was committed; the owner chose not to wait for it. What changes for the guest: - A 2D texture over host pages whose usage only samples or reads it is a linear image over the pages, with no shadow and no copy in at each command buffer's first use, on a device whose startup check passes: on that device, an image's first move keeps every byte while the CPU writes beside it, checked for pointer imports, fresh pages and dma-bufs each, and kept in the shader cache by driver and runtime version. Vulkan does not promise that move (an image over imported memory starts UNDEFINED), so this relies on the driver, by the owner's ruling of 2026-10-26. REIMS_VGPU_EXACT gains `host_page_textures`, which keeps every such texture a shadow, as before, and `all` names it; the accuracy ledger and docs/api.md say so. Render targets, written textures and two-plane YCbCr surfaces keep their shadows. - A memoryless texture bound at a texture slot is taken, as plain Metal takes it, where the runtime refused the setter and this platform died there (an RX 580 user's guest, at setFragmentTextures:withRange:). A command whose function uses the slot, a useResource of it or a blit of it fails the command buffer with MTLCommandBufferErrorInvalidResource (9) from the Metal submission that holds it, as Metal's GPU does (measured by metal2vulkan on the M3 Max). This platform passes the new CommandBufferError::InvalidResource to core as one of Metal's failures: the fourteenth it lists. A memoryless texture's CPU reads and writes move nothing, and its views are nil, as on Metal. - new_texture_with_vk_image takes IdPlacement::Outside; nothing here passes it yet, so the window's swapchain images still take texture IDs. - Nothing else in the span moves what a guest computes or observes: the in-place check's dma-buf pages come from cached memory, and the rest is counts, docs, tests and the sources pins. The public surface gains CommandBufferError::InvalidResource, DevicePolicy::host_page_textures and its HostPageTexturePolicy, and WorkCounts' in-place and shadow-cause counts. No Degradation, RuntimeGap, refusal or notice kind moved, so DIES and the relayed kinds stand. Device info, GPU families and feature queries answer as before. The Vulkan platform ends the process at one site fewer: the memoryless binding. docs/video/bugs.md says what the pin carries for B73: the in-place textures and the counts that tell them from the shadows that stay. New tests, of the memoryless binding, on every platform: a_memoryless_texture_at_a_fragment_slot_fails_only_a_draw_that_uses_it; and on the Mac, memoryless_slots_fail_as_metals, which measured Metal's lines (macOS 27.0.1): a draw whose function ignores the slot completes; one that samples it fails the command buffer with code 9, the blit before its pass run and neither its clear nor the blit after it, the signal after them not firing. Checked, every test passing in its full run: - on the M3 Max (macOS 27.0.1): rustfmt, the three clippy passes cargo xtask check makes (the Mac's, its tested features', and x86_64-unknown-linux-gnu's), and the 900 tests of reims-vgpu-vulkan and reims-vgpu on MoltenVK; - the Vulkan crate's 434 tests and reims-vgpu's and the C API's 50 video and scaler tests on gem10's RX 7900 XTX and Radeon 780M, with no amdgpu reset. The RTX 5080 Laptop GPU's run was skipped at the owner's word: the GPU was busy with the owner's VM. Only those crates link the runtime, so the rest of cargo xtask check (core's tests, under Rosetta too, the Metal, window and video crates, and the header) and the suite, which drives the C API on the Metal platform, do not reach the change and were not run. |
||
|
|
95644d758d |
🆕 Add the VideoToolbox and M2 scaler devices to the library and QEMU
A macOS guest hands its VideoToolbox sessions, and its
IOSurfaceAccelerator's scaling and conversion, to the host through two
virtio-PCI devices, 106b:1a03 and 106b:1a0b, as Virtualization.framework
gives them. The library gains their host side, VideoDevice and
ScalerDevice over core's host session and scaler, and QEMU their
transports, apple-videotoolbox-pci and apple-m2scaler-pci, with no
properties of their own.
The library picks each device's backend itself and logs why, on the GPU
apple-gfx-pci's device runs on, taken from the runtime's identity of it:
NVDEC and NVENC on an NVIDIA GPU, else VA-API on its render node, and
VideoToolbox on macOS. The scaler device exists on every host and refuses
its features where it cannot transform; a guest message over 16 MiB is
answered -12904 unread.
For the host: the C API gains rvg_video_device_* and rvg_scaler_device_*,
additively. For the guest: a VM given the devices has the host's video
decode, encode and scaling.
Source: c5b409362 375acb462 8be7593eb fbbeebfb2 e3d5616a4 60d08c4f4 c4c476643
fe105edcb 36a6a82c6 ee2b1ca71 d7d5cfede b15f40717 a07ffd70b bfe6b8338
7433026a9 0030b24a7 64497f931 76acbacc7 3bf366e81 6d3b97a59 fa5b4aafc
401e0b727 1af53ce1a 0fa52d070 ce6eab571 33b40ae4a 82beaf64a ef26f02e1
08bb763c4 5ff2dd73f 62e19c8ef ce406ddb2 fd92f66c4 52fba93c9 e179dc0bd
b5f40ad74 d01bbdc9e 950a7e024 601c23067 9857b1fc8 b427bebfb 55a1d96e7
a0243edfc ef54c395f c23c83073 bc6fcdaa7 1b783baca
|
||
|
|
d527b7257c |
⬆️ Build on metal2vulkan 6c9cad047a's runtime
Move the runtime from 6b67bd44af to 6c9cad047a (runtime version 1520 to 1643), through dc80eb2bd4, 67c64f99d8 and 27935d575e, and hold three tests to the runtime's answers at the pin. For the guest: - a draw whose state's reflection the runtime could not finish asks per slot what a function may store through, where every read-only object counted as written and a user's Linux guest died in kept_write; - a detach in a completed handler of an object the last submission used answers YES, Metal's answer once the use retired; - shareable padded 10-bit formats are made in Private storage, and the packed ones answer nil and 0 bytes, as Metal's; - a command encoded again at a replace no longer writes the pages it was encoded over; - a shadowed texture copied back by a dispatch stores wide texels whole. The runtime's identity of the GPU device, which the video devices use to find their GPU, comes with this pin. Source: 7ad52b99b 0e37d329c cb582881c 94d2b0ef6 5ee2d000e 221176d06 051c64ebb |