Fix the consumer's first-move SIGBUS and deallocator fatal, restore the release door, announce the tessellator's triangle order

One commit of the 4 on development-fast (0175289314..c66863112e), squashed at the user's request:
the pin reims-vgpu tested clean.

Runtime:
- A texture's first move over host pages writes back only the bytes the move changed, and only
  where the kernel says the process may write them (mach_vm_region on macOS, the maps query on
  Linux). Before, it wrote back every kept byte: a SIGBUS on read-only pages on MoltenVK, and a
  hang under QEMU, whose handler retried the store. A changed byte over pages the host cannot
  write stays as the move left it, announced (unrestored-first-move-bytes; not observed on any
  venue). WorkCounts::first_move_restored_bytes. HostMemory::new states the Linux contract that
  imported pages stay writable.
- A no-copy buffer released while a submitted command buffer's live buffers' table lists its
  pages runs its deallocator at the release when the caller gave a keep-alive, which keeps the
  pages mapped until the import is freed. Only a release without one waits and announces
  host-deallocator-delayed. Before, the keep-alive case was announced too, which the consumer
  treats as fatal.
- Memory::free_then renamed release_then: it calls no Vulkan entry point, so the release door's
  source scan holds again.
(RUNTIME_VERSION 1303.)

Translator: PrecisionNote::TessellationTriangleOrder, recorded on a pipeline drawn through the
device's tessellation stages where the tessellator is not Apple's
(DriverWorkaround::TessellatorNotMetals): a patch's triangle order, first corners and ring joins
are the device's. The emulation without tessellationShader draws Metal's order and records none.
(SEMANTICS 1740, ARTIFACT_FORMAT 420.)

Docs: API.md's catalogue, FAST-PATHS.md's known gaps, REFUSALS.md.

Verified on development-fast:
- the runtime crate and runtime_lane x3 on the RX 7900 XTX, Radeon 780M and RTX 3090 at
  0175289314 (red only on the release-door scan, then fixed and checked);
- the tessellation note's lanes on the RTX 5080 and M3 (111/111 each);
- the keep-alive lanes on the XTX and 780M (152/152 each), the 5080 and lavapipe, its new test
  failing without the fix;
- both fixes' lanes on lavapipe 197/197, RTX 5080 195/195, Iris Xe 195/195 and M3 194/194; the
  read-only test aborts with SIGBUS on the M3 without the fix;
- reims-vgpu at this tree: cold x86-64 macOS 26 boots clean on the Iris Xe and the 780M, 2711/2711
  of its tests.
Not re-blessed here: the golden hashes' profile fingerprints and tessellation cells that the new
workaround moves; the bless is on development-fast.
The tree is development-fast's at c66863112e.
This commit is contained in:
Anees Iqbal committed 2026-10-16 13:06:03 +03:00
1 parent 0175289314
commit 29d3ebb22e
31 files changed
+965 -174

No files matched your search

+28 -5
View File
@@ -176,8 +176,11 @@ first move, made by the next submission that may reach it (any command buffer's,
submission of a host call on the texture, or `Texture::vk_image`), keeps the bytes the image is
bound to, through the host: before that submission, once every submission made before it on each
queue completed, the runtime reads them through the host pointer, submits the move alone and waits
for it, and writes them back, every one; no GPU command writes them, and no byte outside them is
touched (`WorkCounts::first_move_keeps`, `first_move_kept_bytes`). The submission waits for that,
for it, and writes back the bytes the move changed, so none is stored where it changed none (pages
the process cannot write stay untouched); no GPU command writes them, and no byte outside them is
touched (`WorkCounts::first_move_keeps`, `first_move_kept_bytes`, `first_move_restored_bytes`).
Changed bytes on pages the process no longer maps writable keep the move's values, announced
(`unrestored-first-move-bytes`). The submission waits for that,
`commit` never. A rebind's new image keeps its new pages' bytes the same way. An image
over a dma-buf of its own pages keeps them through its acquire from `VK_QUEUE_FAMILY_FOREIGN_EXT`,
and a linear image of the runtime's own memory through its move from `PREINITIALIZED`.
@@ -445,7 +448,8 @@ let pipeline = device.compile_render_pipeline(&descriptor, &Budget::standard())?
Its `stages` are a synthesized vertex and tessellation control stage, the function as the
evaluation stage, and the fragment stage. It draws patches only (`DrawCall::Patches` or
`PatchesIndirect`), with the factors from a tessellation factor buffer.
`PatchesIndirect`), with the factors from a tessellation factor buffer. The device's tessellator
orders the triangles (`PrecisionNote::TessellationTriangleOrder` where it is not Apple's).
On a device without `tessellationShader` the pipeline is an emulation with no tessellation stage:
the function is its vertex stage (`TRIANGLE_LIST`), and `graphics.emulated_tessellation` states
@@ -1795,12 +1799,14 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound.
Vulkan frees no memory that submitted commands may still use (`VUID-vkFreeMemory-memory-00677`),
so the pages stay: with no keep-alive (`KeepAlive`), while a command buffer submitted before a
texture over them was released may still read that texture through its resource ID (its image
holds the import); with or without one, while a command buffer whose commands may reach the buffer
holds the import); with no keep-alive, while a command buffer whose commands may reach the buffer
unnamed holds a table of the live buffers that lists it (its first submission's and its host
steps', until it completes; one a rebind encoded again before its first submission, until then);
with no keep-alive on MoltenVK (`RuntimeDriverDefect::FreedAddressMemoryFailsPendingWork`), while
the batches submitted before the import's memory went are in flight, as MoltenVK fails pending work
that reads device addresses where such memory is freed.
that reads device addresses where such memory is freed. With a keep-alive the deallocator runs at
the release, as Metal's, and the import keeps the keep-alive, which keeps the pages mapped, until
it is freed: not announced.
Cost: the deallocator runs once every such command buffer lets go of the pages, or those batches
complete, where Metal's runs at the release; the pages stay mapped until then.
- `metal2vulkan-degrade-misplaced-notice` (performance). `MisplacedNotice`: In a build without debug
@@ -1878,6 +1884,14 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound.
draw counted by a `Counting` visibility result whose fragment function writes more than one color
attachment, on ANV (`RuntimeDriverDefect::OcclusionCountPerColorOutput`). Cost: the result is
Metal's count multiplied by the colors the draw writes; a `Boolean` result is Metal's.
- `metal2vulkan-degrade-unrestored-first-move-bytes` (precision). `UnrestoredFirstMoveBytes`: A
texture's first move over a no-copy buffer's host pages changed bytes the host kept across it, on
pages the process maps without write permission when the host writes them back: on Linux, pages
made read-only after the buffer was made (Linux refuses read-only pages at the import); on macOS
also pages read-only from the start, which Metal reads (a GPU write into them fails its command
buffer). Not observed on RADV, which fails the command buffers submitted after a page of an
import loses write permission (`HostMemory::new`). Cost: those bytes keep what the image's move
from `UNDEFINED` wrote, where Metal's texture leaves its pages as they were.
- `metal2vulkan-degrade-f16-fma-double-rounding` (precision). `PrecisionNote::F16FmaDoubleRounding`:
Widened half fma rounds twice.
- `metal2vulkan-degrade-f16-int-conv-double-rounding` (precision).
@@ -1946,6 +1960,15 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound.
`PrecisionNote::TessellationFactorInstance`: A tessellation pipeline whose factor step function is
per instance reads instance `i`'s factors at `i · instanceStride`, `i` counting the draw's base
instance as `[[instance_id]]` does.
- `metal2vulkan-degrade-tessellation-triangle-order` (precision).
`PrecisionNote::TessellationTriangleOrder`: A tessellation pipeline drawn through the device's
tessellation stages (a device with `tessellationShader`) whose tessellator is not Apple's (every
driver but MoltenVK on an Apple GPU, `DriverWorkaround::TessellatorNotMetals`): the device's
tessellator orders each patch's triangles, picks each one's first corner, and joins the patch's
rings where Vulkan leaves that to the implementation. The domain points are Metal's; a flat
varying, a value interpolated across another triangulation, and the order a patch's triangles
blend in may differ. A device without `tessellationShader` draws Metal's order through the
emulation (`emulated-tessellation-draws`) and records none.
- `metal2vulkan-degrade-fp8-value` (precision). `PrecisionNote::Fp8Value`: An 8-bit float converts
to an integer from the format's documented value with Metal's saturating float-to-integer rule,
where Metal's device here answers otherwise: Metal on Apple M3 compiles these reads but extends