Commit Graph
846 Commits
Author SHA1 Message Date
Anees Iqbal 8bd103fc8e Record RADV's extrapolated perspective reads at a sample or offset as the device's answer
On the Radeon 780M (RADV, Mesa 26.2.6) runtime_lane::pull_model_interpolation read 1700
values off Metal's, up to about 1.0 in lane 3. The lowered pm_offset is straight-line code (a
uniform offset, its move and clamp, InterpolateAtOffset per input), so no control flow is at
fault. Every miss is a perspective input's read at a sample or an offset; the no-perspective
inputs' same reads were Metal's. A model with the lane's own geometry gives the driver's form:
the pixel center's value extrapolated along the quad's coarse derivatives,
f(center) + (f(tr) - f(tl)) * dx + (f(bl) - f(tl)) * dy. It reproduced all 52 one-sample offset
misses within 0.004 and all 1061 four-sample sample and sample_id misses within 0.005, where the
fine-derivative form was up to 0.98 off. Metal's value plus that form's error (first-order less
exact) matched each of RADV's within 0.2 of the lane's device bound.

Vulkan states no precision for interpolation, so under rule 1 the device's interpolation is the
answer: no form computes it otherwise. The fix records it.
- DriverWorkaround::PerspectiveReadsExtrapolated, a measured row keyed on RADV
  (driver_facts::DEFECTS, no vendor), as InterpolationNeedsTheWholeQuad is.
- PrecisionNote::ExtrapolatedInterpolation (extrapolated-interpolation). stage_io::plan records
  it structurally: an interpolant with the perspective qualifier read at a sample or an offset,
  or a perspective sample-qualified varying a looping function reads at each pass's sample
  (InterpolateAtSample), on a profile with that fact. A no-perspective read, the pixel-center
  form (offset 0), a center or centroid read and an absent interpolant record nothing.
- The pull-model lane: on such a device each perspective lane read at a sample or an offset is
  held to the device bound of Metal's value plus the extrapolation's error, computed from the
  lane's geometry (extrapolation_error), and the pipelines that read so, and those alone, must
  record the note.
- The engine tests over every committed profile assert the note where the RADV profile reads a
  perspective interpolant at a sample or offset, and nowhere else: pm_linear, a new fixture
  function reading the no-perspective interpolant alone at a sample and an offset, must not
  record it. The coverage-loop test asserts it for the looped perspective varyings on RADV.
- docs/API.md's device-interpolation entry and docs/FAST-PATHS.md's row no longer cover RADV's
  sample and offset reads with the 1.5e-4 figure. The new entry and row state the form and the
  measured size.
- SEMANTICS_VERSION 2000 (the RADV profile's pull-model and looping modules gain a note),
  ARTIFACT_FORMAT_VERSION 497 (the codec gains the note), api_signatures blessed. The refusal
  surface regenerated with no change.

The fixture's AIR companions for pm_linear come in the next commit, from the regen script on the
M3. The golden tables and the air_input snapshot are re-blessed on development.

(cherry picked from commit f4eb92a9bc4c099f9020fde2c2da40580514ec20)
2026-11-09 00:16:01 -08:00
Anees Iqbal ad451a5334 Scheduler: a held group never waits behind another queue's submission handlers
What. A pass that ends with batches held for one kernel submission keeps them held while their
VkQueue runs two or more earlier submissions (Group::keeps). It now sends them instead where a
submission handler the thread runs once its passes end (scheduler::round) is of a command
buffer of another logical queue (Metal command queue) than a batch held:
scheduler::holds_back_another_queue, over the round's handler list and the batches held with
their logical queues. The handlers of the held batches' own queue still keep the group held.
CommandBufferShared::logical_queue reads a command buffer's queue identity for it.

Why. A submission handler runs on the scheduler thread, and a held batch's handlers run as it
is held, before its group goes to the driver. Where two command queues share one VkQueue on a
driver that merges, a batch of one queue held and kept behind running work, and a batch of the
other queue with a handler that waits for the first one's completion joined the group: the
group stayed held until the handler returned, so the handler waited for work its own return let
go (the deallocator lane test on the Iris Xe hit it once, its handler waiting 60 s). Metal does
not do that: on an M3 Max under macOS 27.0.1 (probe cross_queue_handler_waits), a command
buffer's completed handler reached another queue's scheduled or completed handler that waited for
it in each of 30 runs, 7.6 to 9.3 ms after the wait began, b committed before a included. On one
queue it never did (the 5 s bound in each of 10 runs): Metal runs one queue's handlers one at a
time, so the runtime keeps the group there and promises nothing more than Metal.

Cost: a group mixing two queues' batches is no longer kept past a pass in which a submission
handler of one of them runs; it goes then, the batch that joined last included, in one
submission. Measured on a lane (frame_costs_over_imports, the guest's shape) in the runs that
verify this commit.

Docs: group.rs ("Kept while its queue runs earlier work", Group::keeps),
CommandBuffer::add_submission_handler ("Keep it short"), the runtime README's handler entry,
and FAST-PATHS.md's grouped-submission row.

Verified: cargo fmt. Build, clippy and runs (the previous commit's test, without and with this
change; the deallocator lane test as it was) are potluck jobs on the Iris Xe and the XTX.

(cherry picked from commit 8d04b2d15d3cb745363428fdc9acbbb9ca2eb868)
(cherry picked from commit 2cbd8a970905d931b7be39c92fbdd18d6024f62a)
2026-11-08 23:56:34 -08:00
Anees Iqbal f11ad530fe blit fill: a multisampled 32-bit float depth's samples clamp into [0, 1] where the device's do
On Iris Xe (ANV, RPL-P), which lacks VK_EXT_depth_range_unrestricted, the sample_fills case
d32-wide-4 fills a 4-sample Depth32Float texture with 33221100 77665544 bbaa9988 ffeeddcc and
reads back 33221100 3f800000 00000000 00000000. A multisampled fill writes each sample's bits
into an R32_UINT scratch image and copies it into the depth image (maintenance8's colour-to-depth
vkCmdCopyImage on ANV), and Vulkan writes undefined values there for a depth outside [0, 1]: ANV
stores the NaN as 0. restricted-depth-upload, announced once per device on an earlier case,
promises a clamp, a NaN 1.0, that no step made. replace_region and the buffer-copy route clamp
before the copy (depth_clamp.rs); the multisampled fill did not.

sample_fill now clamps each sample's depth word on the CPU (bind::clamped_depth) where the
texture clamps depth uploads, announces restricted-depth-upload for the fill, and counts it in
WorkCounts::depth_uploads_clamped, as replace_region does. A device with the extension writes
the bits as before. The docs of depth_clamp.rs, the counter, the degradation and docs/API.md's
entry name the fill.

The lane: the probe recorded d32-wide-4's digest (9c5b7be066d1c9fc) alone. depth_lines rebuilds
a byte-filled Depth32Float case's lines from the fill rule; the_recorded_lines_are_the_probes
holds the rebuild to that digest and to the recorded d32-4 and d32-2 lines. A Depth32Float case
on a device that announced restricted-depth-upload passes where it holds Metal's lines with every
word through clamped_depth, the fill counted (SAMPLE-FILLS-CLAMPED). Expected on Iris:
33221100 3f800000 00000000 3f800000. The metal.txt fixture, and so the conformance recordings'
input digest, is unchanged.

Verified offline: the rebuilt d32-wide-4 and d32-4 lines hash to the probe's 9c5b7be066d1c9fc
and 2098b9445cd43b96. Device runs (Iris, lavapipe, M3) are reported with the tip.

(cherry picked from commit b3f0f2ba7e176fa1972cb89982f6404375ffd169)
2026-11-08 22:48:29 -08:00
Anees Iqbal c1a825d748 Volume resolves: RADV writes a 3D image's first plane, so resolve through a scratch copied into the planes
On a Radeon 780M (RADV, Phoenix) a 4x multisampled RGBA8Unorm attachment resolved into depth plane
3 of a 4x4x4 volume, through the 2D view of the plane that resolve::destination attaches, wrote
plane 0 instead (the volume's first byte held the resolve; view_attachments, three runs at each of
two commits, ownpixel's job). Drawing into the same kind of view writes its plane there, and the
usage is valid: a 2D view of a 3D image made 2D_ARRAY_COMPATIBLE "can be used as a framebuffer
attachment that refers only to the specified range of slices" (VkImageSubresourceRange), and of a
resolve attachment Vulkan refuses only a 3D view (VUID-VkRenderingAttachmentInfo-resolveImageView-
12471). MoltenVK on the M3 Max writes each named plane (a_resolve_writes_the_volume_plane_it_names).

RuntimeDriverDefect::VolumeResolveFirstPlane names it, on every RADV GPU until a probe finds one
clean (driver_defects.rs, the table's rule). There a color resolve into a 3D texture's planes past
its first, or into more than one, goes into a scratch image of the pass's layers (Destination::
attach), whose layers ResolveCopies copies into the planes after the pass: one region whose depth is
the layers, from the resolve's first plane (VUID-VkCopyImageInfo2-srcImage-01791, dstImage-04444).
The scratch's copy into a 3D texture was not built before (render_pass::not_2d refused it); it is
now, but for a level reaching past the attachment, whose clear would be of the planes alone, which
stays NotImplemented(Render). Announced as resolve-scratch, its reason naming the defect; the
catalogue and the variant's docs say so. The device's own resolve still averages: the copy moves
its result unchanged.

Tests: tests::driver_defects lists the defect for every committed RADV profile;
runtime_lane::view_attachments::a_resolve_writes_the_volume_plane_it_names fails without the
change on the 780M (to be run with the runtime before it and after, on the 780M and the XTX).
docs/REFUSALS.md regenerated: unchanged.

(cherry picked from commit dcffee430897a499f47155664a8549a248b8a8ad)
(cherry picked from commit 707ef3439b2ca3c5f81f967a1322470da47c0d77)
2026-11-08 22:48:23 -08:00
Anees Iqbal de5a77cc06 Wide lines: no device's own lines are taken as Metal's parallelogram
RADV fails wide_lines_draw_metal_s_parallelograms and its exact-answers twin at the lane's
"scattered lines width 2.5, fragments" map, 628 pixels where Metal's has 622: on the Radeon RX
7900 XTX (homelab-gem10-1, m3-max-10724) and on the 780M (homelab-um870-1, its only GPU,
m3-max-10773), at this branch's base and at development alike. The runtime took RADV's lines as
Metal's there, unannounced: RADV is the one driver of the committed profiles stating non-strict
parallelogram lines (strictLines unset, nonStrictWideLinesUseParallelogram set), and 2.5 lies on
its 1/8 granularity above 1, so the route was the device's lines under both policies.

Cause, measured: a probe on the XTX (m3-max-10800, a scratch branch, never merged) drew each of
the 48 scattered lines alone and printed its pixels. 21 of them lie a row or a column off Metal's
parallelogram at an end: one more past the first vertex, one fewer before the last. A model of
Metal's rule (endpoints on the 1/256 subpixel grid, the parallelogram whose minor-axis edges are
w' long through them, the ends not extended, pixel centres by the top-left rule) reproduces
Metal's map pixel for pixel; the XTX's ends fit no constant shift of it. Vulkan leaves where a
non-strict wide line's ends fall to the implementation, and no driver is measured to place them
as Metal does.

Change: the device route has no exact form any more (render/line_width.rs route). Every draw the
device's own lines take is announced device-wide-lines, the notice naming "parallelograms, whose
ends and endpoints' snap the driver places as it draws them" where the width is on the grid above
1, and under WideLinePolicy::Exact (exact_answers) the band draws it wherever the device has
tessellationShader. On RADV, widths above 1 on the 1/8 grid move from silent device lines to
announced device lines under the default, and to the band under exact answers. No other profile
changes route: lavapipe and NVIDIA (strict) and ANV (not stated as parallelograms) were announced
already.

Tests: the runtime's route table reads A or B where it read E for the three RADV profiles (Cell::
Exact removed). The validation lane drops LineFacts::draws_as_metal, and asserts per case that
the draws of the device's own lines announce device-wide-lines one for one, which fails without
this change on RADV (width 2.5 drawn by the device's lines with no notice); the edges test
asserts the notice at each device-line draw.

Docs: render/line_width.rs's module docs, DeviceWideLines' rustdoc and docs/API.md's entry and
policy text, WideLinePolicy's and DevicePolicy::wide_lines' docs, the runtime README's route table
(its "exactly Metal's" row folded into the announced one), docs/FAST-PATHS.md's row (no device's
lines are taken as Metal's; the cost adds a row or a column at an end), docs/RUNTIME-PORTING.md's
SetLineWidth row. The announced cost string is unchanged.

Notices: one device-wide-lines per device (once per kind, unless announce_each names it) on a
RADV run that draws wide lines only at widths above 1 on the 1/8 grid, where it announced
nothing; a run that already drew a width below 1 or off the grid announced it already.

Needs the runtime-sources pin and a RUNTIME_VERSION (the orchestrator's numbers).

Verified: cargo fmt. The XTX, 780M, lavapipe and M3 runs follow through potluck.
(cherry picked from commit be88ae03f199d5a485abcc546d0d52b181290e7b)
2026-11-08 22:45:29 -08:00
Anees Iqbal aef1b019f4 Lines at the nearest width go on the device's granularity grid, never 0
With the refused band's lines through pixel centres (the commit before), RADV on gem10's RX 7900 XTX (NAVI31; the 780M, PHOENIX, on um870 reads the same, job 10773)
drew nothing at round 0 of a_refused_band_draws_at_the_nearest_width (m3-max-10559), where Metal
draws 23 pixels (its probe's 'horizontal y=16.5 x 4.5 to 27.5 width 0'). The nearest route
handed the driver w' = 1/16 for Metal's width 0, clamped into lineWidthRange [0, 8] alone. RADV's
lineWidthGranularity is 1/8 from 0, so 1/16 is a tie between 0 and 1/8, and Vulkan lets the
driver take either ("the nearest supported width"): a line of width 0 covers no pixel centre.
ANV's grid is 1/128, which holds 1/16, so ANV draws it as it is.

The nearest width is now on the device's grid: clamped into the range, then the nearer step of
lineWidthGranularity from the range's bottom (a tie the wider), and never 0 where the range starts
at 0 (render/line_width.rs drawn_width). So RADV draws Metal's width 0 at 1/8, and ANV still at
1/16. The runtime's route test and the validation lane's LineFacts::nearest mirror the rule; the
module docs, the runtime README's table, docs/API.md's lines-at-nearest-width entry and the
kind's rustdoc say it. The announced cost is unchanged.

Needs the runtime-sources pin and a RUNTIME_VERSION (the orchestrator's number).

Verified: cargo fmt. RADV, lavapipe, the M3 and the Iris lanes follow through potluck.

(cherry picked from commit c20de3da6e, message corrected: the run it cites (m3-max-10559) took the XTX, its MESA_VK_DEVICE_SELECT lacking the "!")
2026-11-08 22:17:31 -08:00
Anees Iqbal 81abe49dad Attached reads of the levels before the attached one read the texture's own image
A draw's sampled slot of a texture its render pass instance renders at level k (counted from the
texture's own first level) took the texture's usage shadow, a whole copy of every level, even
where its reads reach only levels before k. Such a slot now binds the texture's own image
through a view of its levels 0..k, the same first level, so an explicit level of detail selects
the same level, and names those levels in its uses (`binding::NarrowedSlots`): no copy is taken
for it. The copy would hold the same texels: nothing the instance does writes those levels
where the texture is an image of its own the bind reads in place (not sparse, no decoded twin,
the sampled usage), no attachment of the instance is at them, no earlier draw wrote them since
the instance's last barrier (a draw after one records into a new instance), and no write of the
draw's own meets them (else every narrowed slot of the draw takes its copy, its uses made
again). Which levels a read reaches is the translator's fact (`StageModule::level_reads`)
through the samplers the draw binds: level-count and level-of-detail queries, computed fetch
levels and samples without a sampler-bounded level keep the copy.

A draw rebound works its narrowed slots out again and is rebound only where they are its kept
draw's; a draw again binds as its kept draw did.

WorkCounts: attached_read_slots_below becomes attached_read_slots_apart (the own image cannot
serve them), attached_read_slots_written (something writes those levels) and
attached_read_slots_narrowed.

Verified: cargo fmt only; the build, clippy, a device test of an explicit read of level k - 1
while level k is attached and the touched suites follow as potluck jobs.

(cherry picked from commit 7ba814a2e2f419643c2f9e68b9768709658cbe94)
2026-11-08 21:48:37 -08:00
Anees Iqbal 5ed5e47ae5 DriverFact::ColorClearTakesEitherCode on RADV on the Radeon RX 550 (Polaris 12), as measured
runtime_lane::color_fills::plain_color_fills_are_the_device_s_clear failed on the RX 550 (um790,
RADV POLARIS12, Mesa 26.2.6, job m3-max-10655 at 90c9936538): 186 plain fills differed from
Metal's past what they announce, 93 colour fills of 11 formats, each in a texel of a level and in
a whole 1 x 1 slice: RGB10A2Unorm and BGR10A2Unorm 24 each, RGBA8Snorm 9, RGBX8Snorm 7,
RGBA8Unorm, BGRA8Unorm and ARGB8Unorm 6 each, RGBX8Unorm 5, RG8Snorm 3, RG8Unorm 2, A8Unorm 1.
Every differing channel stored the code below the nearest, a code from Metal's, off the
midpoint: 8-bit scaled values 0.50 to 0.58 past their lower code (RG8Unorm's 0.515986, 131.58
codes, stored 131 where Metal stores 132), 10-bit ones 0.51 to 0.87 past (0.549235, 561.87 codes,
stored 561). None was announced: the runtime announces a clear off a midpoint only on a driver
that takes either code (clear_value::rounds_apart).

The cause: the device's clear cuts the colour to a half toward zero, then rounds to the code.
That model gives every one of the 270 channels of those 93 fills (offline, from the job's
lines), and the same lane's R16Float clears store the half cut toward zero (0.001 as 0x1418,
Metal's 0x1419), RG16Float and RG11B10Float alike, already announced there. A half's cut is under
half a 10-bit code, so the stored code is one of the two nearest: Vulkan's "one of the two ...
closest" allows it, the device's native conversion. The row records it as the 5080's and ANV's
do, keyed to RADV, AMD's vendorID and the RX 550's deviceID (0x699f, AMD_RX_550), so the runtime
announces device-color-conversion for a clear or plain fill of a normalized channel anywhere off
a whole code there.

The fact's doc gives the measurement; docs/API.md's clear entry names RADV on the RX 550. No
committed profile is of the RX 550, so no profile's facts move.

Verified: the model offline over the 10655 lines. The RX 550 color_fills lane and the suites
follow through potluck.

(cherry picked from commit e3455e70e245184ce96777a64e4a166c73400625)
2026-11-08 21:42:16 -08:00
Anees Iqbal f0628b75eb The levels each texture slot reads, and the attached-read slots counted by them
The translator states, for each texture slot of a stage, the levels of its bound view its
reads reach (`StageModule::level_reads`, `spirv::requirements::level_reads`): whether some
read may reach any level, the highest constant level a fetch, size query or gather names
(through the fetch lowering's `UMin(c, levels - 1)` containment too), and its samples by
sampler, with the highest constant explicit level of detail and whether one is computed.
`SampledLevels::level` answers the highest level such samples reach through a bound
sampler (`SamplerLevels::of` a `vk::SamplerDesc`: its LOD clamps, bias and mip mode), and
`LevelReads::highest_level` the slot's.

The runtime counts, at each draw that takes every step and reads through copies, every slot
whose sampled binding presents a texture an attachment of the instance renders
(`WorkCounts::attached_read_slots`), split by how its reads meet the lowest attached level:
one level, the first level attached, any level, reaching it, or below it. The samplers are
those the draw binds (the bind's own descriptor for a runtime sampler, the layout's
immutable sampler for a constexpr one). No draw binds or copies otherwise: this names the
shape of the usage shadow the attached reads of mipmapped textures take, ahead of serving
the "below" slots through a view of fewer levels.

SEMANTICS_VERSION 1998 and ARTIFACT_FORMAT_VERSION 495: the artifacts carry the new fact.
api_surface and api_signatures name the new public types and fields.

Verified: cargo fmt only so far; the build, clippy and tests run as potluck jobs next.
(cherry picked from commit 89855203ad1b8b9b3695f313b3cdb34688993840)
2026-11-08 21:15:12 -08:00
Anees Iqbal e67c617756 Visibility past an early-tests mask: announced where the device may count after the mask
runtime_lane::sample_coverage::the_sample_coverage_applies_after_the_fragment_function fails on
the Iris Xe (ANV, RPL-P) at its three early-tests draws: a full-screen draw of coverage 0.3
under psc_early counts 0 of 256 samples at 1 sample, 80 of 512 at 2 and 140 of 1024 at 4
(iris-B at 6cb37f2c86), where Metal counts every sample the early tests pass and masks the
colors alone. Its colors and depths are Metal's. The translator applies Metal's private masks
under early tests in the fragment function's SampleMask output, which Vulkan orders after
sample counting only where the device states earlyFragmentMultisampleCoverageAfterSampleCounting
(VkPhysicalDeviceMaintenance5Properties). ANV's capture on the Iris Xe of RPL-P states false;
RADV on the 780M, NVIDIA's on the RTX 5080 Laptop GPU, lavapipe and MoltenVK on the M3 Max
state true.

- metal2vulkan: Limits::early_fragment_multisample_coverage_after_sample_counting, read from the
  maintenance5 structure (false without the extension), and
  GraphicsState::writes_sample_mask, the fragment function's SampleMaskOut builtin (its own
  [[sample_mask]] return or the private masks it applies). SEMANTICS_VERSION 1998,
  ARTIFACT_FORMAT_VERSION 495 (a new encoded field).
- metal2vulkan-runtime: a draw under a visibility result (Counting or Boolean) whose fragment
  function declares early tests and writes its sample mask, on a device without the property,
  runs announced as Degradation::VisibilityPastEarlyMask
  (metal2vulkan-degrade-visibility-past-early-mask) and is counted in
  WorkCounts::draws_counted_past_early_masks. Keyed to the documented property alone, never to
  a driver or vendor.
- No structural form keeps Metal's count at no cost to uncounted draws: the colors' masks are
  the SampleMask output or a discard, both fragment operations such a device may count after, so
  only a second draw of each counted draw without the mask would count as Metal does. The
  announcement is the proportionate answer.
- The lane: on a device without the property, the early draw's colors and depths are still
  Metal's, its count at most Metal's, the draw counted once and the kind announced; elsewhere the
  count is Metal's and nothing is announced.
- docs/API.md's catalogue entry, docs/FAST-PATHS.md's device-gap row, visibility.rs's module docs,
  the api_signatures rows, and validation's limit bound (Execution). docs/REFUSALS.md
  regenerates unchanged.

Not done here: the runtime-sources pin and RUNTIME_VERSION (the orchestrator's number), and the
golden tables, which development re-blesses.

Verified: cargo fmt; the device description test reads the property from RADV's and ANV's
captures. Builds, lint and lanes follow through potluck.

(cherry picked from commit 4aa2896af563c41fec7d8129f15fb86b5dc4e418)
2026-11-08 20:41:07 -08:00
Anees Iqbal 553a7dfeb3 half_read_nans: a sampled 32-bit float NaN or denormal is the device's under device-texel-conversion
What the device does: ANV on the Iris Xe (Mesa 26.2.6) hands back every NaN
of an R32Float, RG32Float or RGBA32Float texel as 0xffc00000 in a nearest
sample, through a constexpr sampler or a runtime one, and every denormal as a
zero of its sign. Metal hands back the stored bits. Reads, texture-buffer
reads, argument-held reads and gathers on ANV hand back the stored words.
Iris run m3-max-10431: 224 sampled lanes, every one a NaN as 0xffc00000 or a
denormal as a zero of its sign, and no other difference.

Why the old expectation was wrong: on a device whose texture unit is not
Metal's (no VkProperty::MetalSampler), a float-result access hands back the
device's own conversion of the texel, recorded as
PrecisionNote::DeviceTexelConversion. That is rule 1's native sampling. The
note's recorded bound and the lane covered a 32-bit float texel's NaN and
denormal only in a gather (NVIDIA), plus a denormal in a nearest sample
(RADV). ANV's samples are the same native behaviour, measured.

So:
- PrecisionNote::DeviceTexelConversion's recorded bound (artifact.rs) and its
  docs/API.md entry now name a 32-bit float texel's NaN in a nearest sample
  as the device's encoding, with ANV's measurement beside RADV's denormals.
- The lane takes a NaN of the device's encoding and a denormal flushed to a
  zero of its sign in a sample, as it did in a gather. It now also asserts the
  notice: where the texture unit is not Metal's, each sample dispatch's
  executed stage (CommandBuffer::executions) records DeviceTexelConversion,
  and the device announces device-texel-conversion.

Verified: the Iris run follows.
(cherry picked from commit d759e0fb4b264508f32ee069b9945e9c7f39fa34)
2026-11-08 20:16:04 -08:00
Anees Iqbal 7be13179cc DriverFact::ColorClearTakesEitherCode on ANV on the Iris Xe of RPL-P, as measured
runtime_lane::color_fills::plain_color_fills_are_the_device_s_clear failed on the Iris Xe (ms01,
job m3-max-10408 at 67b66645ab): "4 plain fills differ from Metal's past what they announce",
each the colour (0.0845, -5e-324, 0.8793, 1e300) into RGB10A2Unorm and BGR10A2Unorm, in a texel
of a level and in a whole 1 x 1 slice: the 10-bit channel of 0.8793 (899.51 codes) stored 899
(RGB10A2Unorm f8300056 against Metal's f8400056, BGR10A2Unorm c5600383 against c5600384), off
a midpoint, which the runtime announces only on a driver that takes either code
(clear_value::rounds_apart). Beside them 3,827 texels of 38 formats and placements stood a code
apart at ties, announced. And ANV's load-operation clear takes its code by the image: 0.1 in an
8-bit unorm channel (25.5 codes) stores 0x1a in a private optimal image and 0x19 in a linear
image in place over host pages or in a shadow listing an unsigned-integer view format
(pitched_surfaces, no_copy_textures; the lanes' previous commit). Vulkan allows either code
("one of the two unsigned binary integer values ... closest"), so this is the device's native
conversion: the row records it as the RTX 5080 Laptop's row does, keyed to the measured driver,
vendor and deviceID (0xa7a0), and the runtime then announces device-color-conversion for a clear
or plain fill of a normalized channel anywhere off a whole code there.

The fact's doc gives the measurement; docs/API.md's device-color-conversion entry names ANV;
the committed profile's facts test (device::tests::driver_facts) lists it for
intel-irisxe-rplp-anv. The profile's fingerprint moves with its facts, so the golden tables
follow on development.

Verified: cargo fmt. The Iris color_fills and lane modules, the Linux suites and lint, and the M3
follow through potluck.

(cherry picked from commit 385c9c6357cd5eb8d0e6deb579533fcad45b5472)
2026-11-08 20:08:34 -08:00
Anees Iqbal 57c21dc6bb Draws unlike their kept draw only in their own arguments are rebound with them
In reims' pin-26 glass walk, 69,981 of 70,882 draws unlike their kept draw differed only in
their arguments (draws_unlike_kept_arguments_alone, all of them in the index offset), and each
took every step. Such a draw, of something to draw, now goes to the rebound path
(render/draw_again/rebound.rs), whatever its tables' stamps, and works out again each step that
reads its arguments:

- its route, which reads them only through whether the draw may make a primitive
  (line_width::draws_primitives): the draw goes on only where that is the kept draw's;
- its commands' Vulkan draw, index overrun, BaseVertexInstance push fields and index buffer use,
  through a new BindingPlan::redraw_apart_into, which answers Ok(false) where the plan reads the
  arguments some other way (a stage's argument or root table, a mesh, patch or de-indexed draw)
  or a fixed-function vertex buffer's fetch window moves with them;
- its pulled attributes' reach (check_vertex_reach, as before, now of the new draw);
- its index buffer's use, patched in place as a moved slot's use is
  (binding::patch_command_uses), so a moved, narrowed draw checks, notes and gathers it with
  the moved slots' uses;
- its index buffer's bind (IndexBind::of of the new source), recorded where the record holds
  another, with its new draw; the kept draw takes its arguments, index source and draw.

A stop at one of those steps is counted (WorkCounts::draws_rebind_stopped_arguments) and the
draw takes every step; a rebound one is counted in draws_rebound_arguments. A draw of other
arguments that draws nothing still takes every step and is counted unlike, as before. The
draw-again debug check covers the new form: the kept draw it compares is the kept draw with the
new arguments, and the rebound check now compares the recording's Vulkan draw and index buffer
bind as well as its draw state.

New public items: BindingPlan::redraw_apart_into (docs/API.md), WorkCounts::draws_rebound_arguments
and draws_rebind_stopped_arguments (api_signatures blessed). Tests: the translator's
draws_of_other_arguments_redraw_what_every_step_writes holds redraw_apart_into to every step's
commands (first index, count, base vertex, a robust overrun) and to Ok(false) where a window
moves, for another kind, index type or buffer, and a de-indexed plan, and to every step's error
past a multiview limit; the runtime's draws_of_another_first_index_alone_are_rebound_with_their_pixels
draws each rectangle by its first index alone, then by its base vertex alone, rebound, with the
commands, state commands and pixels of the same draws taking every step; the unlike-count test
now holds one draw rebound with other counts, one stopped at its route and one of nothing.

(cherry picked from commit ab3e5002bbd6bf8dde7c2761bf7d12ab4461b555)
2026-11-08 20:04:26 -08:00
Anees Iqbal e22f367533 HOWTO section 7: the RX 550's missing extension as listed, not by generation
6ff21171d8's message said RADV enables VK_EXT_image_drm_format_modifier
on GFX9 and later only; that was inferred, not measured. Measured
(m3-max-10378, vulkaninfo on um790, Mesa 26.2.6): the RX 550 (POLARIS12)
lists VK_EXT_external_memory_dma_buf and VK_EXT_queue_family_foreign but
no VK_EXT_image_drm_format_modifier; the 780M (PHOENIX) and lavapipe
list all three. The line now says that. Doc only.

(cherry picked from commit 617becef4f0d68a14d0ff85ce0b15c5e07f81e0a)
2026-11-08 18:30:28 -08:00
Anees Iqbal 006d43ecb0 HOWTO section 7: the RX 550's dma-buf planes are shadows for want of VK_EXT_image_drm_format_modifier
RADV enables VK_EXT_image_drm_format_modifier on GFX9 and later only, so
the RX 550 (POLARIS12) has no DRM_FORMAT_MOD_LINEAR image to import a
dma-buf export's memory into: its dma-buf planes stay announced
shadows. Doc only.

(cherry picked from commit 6ff21171d8d228d1e22bdb072b65f67c85784187)
2026-11-08 18:30:28 -08:00
Anees Iqbal 7b29073f8c A dma-buf export's texture goes in place through its own dma-buf where no image binds in the memory
On RADV the runtime's memory exported as a dma-buf takes no image of a
texture's: the format query takes the dma-buf handle type for no
linear image, and its DRM_FORMAT_MOD_LINEAR image requires a dedicated
allocation (VUID-vkBindImageMemory-image-01445), so the 780M's VA-API
frames' planes were announced shadows (m3-max-10261, 10304). Binding
an image naming another handle type there is no way out: the layer
checks each type of the memory's export set against the bound image
(VUID-VkExportMemoryAllocateInfo-handleTypes-09860, m3-max-10339).

As the last step before the shadow, on any device that does it, the
texture's image is the runtime's route for images over dma-bufs
(Device::dma_buf_image): a DRM_FORMAT_MOD_LINEAR image whose explicit
plane lies at the texels' offset in the memory with Metal's pitches,
bound to a dedicated import of that memory's own dma-buf:

- dma_buf.rs: explicit_plane_image (shared with dma_buf_image_unbound),
  exported_dma_buf_image_unbound (the format query with DMA_BUF
  importable, the driver's layout, the image's memory within the
  memory and of its type) and bind_exported_dma_buf_image:
  vkGetMemoryFdKHR(DMA_BUF) of the memory (Device::dma_buf_of, as
  export_memory_dma_buf makes one), vkGetMemoryFdPropertiesKHR, the
  dedicated import at the image's size (01433; the import's type is
  among the image's, 02989; bound at offset 0, 02628), of the memory's
  own type. Vulkan imports a payload into the instance that exported it
  (VkImportMemoryFdInfoKHR, fd-00668). import_dma_buf hands the driver
  a duplicate and closes ours either way. The import is a DmaBufPages
  of no source (of_exported), freed after the image, live in
  WorkCounts::dma_buf_image_memories_live; each image is counted in the
  new WorkCounts::exported_dma_buf_images.
- texture.rs: exported_dma_buf_alias, after alias_unbound's refusal of
  the image in the memory (a shared block's, or a buffer's dedicated
  allocation): only for the runtime's dma-buf exports, only on a
  refusal (a pending or failed verdict stands), under the device's
  check of that memory; the image must hold exactly Metal's texels to
  the buffer's end (linear_plan::aliases). alias_image binds it
  (exported_dma_buf_texture_image: the buffer's memory held, the first
  move acquiring from VK_QUEUE_FAMILY_FOREIGN_EXT into GENERAL as an
  image over dma-buf pages does), alias_image_made answers it unbound.
  Devices whose image binds in the memory (ANV, lavapipe) keep that
  path unchanged.
- in_place_check.rs: the ExportedDmaBuf class takes a dma-buf's
  dedicated allocation too, and its textures take this route wherever
  the image in the memory is refused, so its verdicts (reads: a CPU
  write through the buffer's mapping read through the import's image;
  writes and renders the other way) measure it. CHECK_VERSION 13 -> 14:
  13's records kept ExportedDmaBuf Unchecked as a cause that lasts.

Test: exported_textures'
a_dma_buf_export_s_planes_go_in_place_through_its_own_dma_buf_where_no_image_binds_in_it
asks the device itself (the format query and the image's dedicated
requirement) whether a plane's image binds in the memory; where none
does and the device makes DRM_FORMAT_MOD_LINEAR images, each plane must
be in place through the import (counted) or a CheckFailed shadow, never
Unchecked; the buffer's export is a dma-buf (fdinfo exp_name); one
import live per such image, none once the textures go; no VUID. The
NV12 test reads such an image's memory plane (09433). The RX 550
enables no VK_EXT_image_drm_format_modifier: its planes stay announced
shadows.

Docs: API.md's shadow rule, HOWTO section 7, the runtime README, the
module docs.

Verification follows: the 780M, the RX 550, lavapipe and the Iris Xe
under the layer, then the 5080 through an entry.

(cherry picked from commit c2e90e2321937067d38cebc5b342f651a638b064)
2026-11-08 18:30:28 -08:00
Anees Iqbal 5ebe1d32aa Revert the dual dma-buf export and the opaque-descriptor naming
Reverts 1acb4f1fbf, 07d9fcac79, 6a6523d2bf, 4a13dfe5bc and 239d8ff9bb
as one fix-forward commit; the tree is b4331408bd's again.

An image naming an opaque file descriptor in a block exported as
DMA_BUF | OPAQUE_FD went in place on the RX 550 (m3-max-10339 at
239d8ff9bb), but the validation layer reported
VUID-VkExportMemoryAllocateInfo-handleTypes-09860 at each bind: it asks
vkGetPhysicalDeviceImageFormatProperties2 for the bound image with each
handle type of the memory's export set, and RADV supports no dma-buf
linear image. Its DRM_FORMAT_MOD_LINEAR dma-buf image requires a
dedicated allocation. So no image in a shared block exported as a
dma-buf is clean under the layer there, whatever else the block
exports, and the block goes back to exporting the dma-buf alone, with
no opaque naming and no counter of it. The next commit takes the
DmaBuf route instead: the block's own dma-buf, imported as memory
dedicated to the texture's image.

(cherry picked from commit af8bda811b4ba9a7816965d2f3bf1fd710d1e40e)
2026-11-08 18:30:28 -08:00
Anees Iqbal 0b1dd0fc36 An image over a dma-buf block names a type the block is exported as, with no image-side compatibility test
On the 780M (m3-max-10304 at 07d9fcac79) the image naming an opaque
file descriptor over a block exported as DMA_BUF | OPAQUE_FD was
refused only by the image-side compatibility test this branch added:
RADV's format query lists compatibleHandleTypes 0x1 (the opaque type
alone) for its opaque linear images. That test was stricter than
Vulkan:

- VUID-VkExportMemoryAllocateInfo-handleTypes-09860: the export set's
  bits must be compatible "as reported by ...
  VkExternalImageFormatProperties, or VkExternalBufferProperties"; the
  buffer query answers them so (FdExport::new).
- VUID-VkImageCreateInfo-pNext-00990: an image's handleTypes lie in its
  own compatibleHandleTypes; the image names one type.
- VUID-vkBindImageMemory-memory-02728: the memory's export set includes
  one of the image's types.

So the test goes (LinearRefusal::Incompatible and
ModifierMemory::shared_with with it). What stays, per handle type the
image names: the format query reports it EXPORTABLE, not
DEDICATED_ONLY; the image made requires no dedicated allocation
(VkMemoryDedicatedRequirements); its memoryTypeBits take the block's
type and its alignment is met at the texels' offset (alias_unbound_in's
aliases check); and the in-place check measures that exact image, under
the layer, before a texture takes it. The VUIDs are cited where the
export set (FdExport::new) and the image's handle type (alias_unbound)
are decided. Docs follow: API.md's shadow rule, HOWTO section 7, the
in_place.rs module doc.

Verification: the 780M, the RX 550, lavapipe and the Iris Xe next, then
the 5080 through an entry.

(cherry picked from commit 239d8ff9bbd4477d784f4ccc815ebf8af53dcad0)
2026-11-08 18:30:28 -08:00
Anees Iqbal 6d5c7b8e92 A dma-buf block's images name an opaque file descriptor where the device takes no dma-buf image in a shared block
On the 780M (RADV PHOENIX) the runtime's memory exported as dma-bufs
kept every texture a shadow: the device's image format query refuses
the dma-buf handle type to a plain linear image and takes it for a
DRM_FORMAT_MOD_LINEAR image only in a dedicated allocation, so the
in-place check of that memory made no image and its verdicts stayed
Unchecked (m3-max-10261). RADV takes an opaque file descriptor for the
same images in a shared block (the opaque-descriptor planes are in
place there, alignment 256).

The remedy, decided from documented queries alone:

- exported_memory.rs: FdExport::new asks
  vkGetPhysicalDeviceExternalBufferProperties for the dma-buf and the
  opaque handle types with the runtime's buffer usage. Where the
  dma-buf's compatible types hold the opaque one, and the opaque one is
  exportable, not DEDICATED_ONLY, and compatible with both, a shared
  block of dma-bufs is allocated exportable as DMA_BUF | OPAQUE_FD
  (Memory::export_dma_bufs_as). Elsewhere, and for a buffer's dedicated
  allocation, it stays the dma-buf alone. The buffer still names the
  dma-buf type (VUID-vkBindBufferMemory-memory-02726 needs one in
  common) and export_memory_dma_buf is unchanged: vkGetMemoryFdKHR of
  the dma-buf type, a dma-buf of the same memory.
- memory.rs: Exported carries the export set beside the handle type;
  bound_memory answers the set.
- texture.rs: alias_unbound tries the image naming the dma-buf type,
  then, where the block exports both, the one naming the opaque type,
  each through the same linear-then-DRM_FORMAT_MOD_LINEAR route
  (alias_unbound_in). An image takes a handle type only where
  vkGetPhysicalDeviceImageFormatProperties2 with that type reports it
  exportable, not DEDICATED_ONLY, and lists every type the block is
  exported as among its compatible types (external_image_limits,
  modifier_image_limits; LinearRefusal::Incompatible). Where neither
  takes it, the shadow and its notice name both refusals.
- in_place.rs: the class follows the memory (ExportedDmaBuf for any
  block of dma-bufs); the check's own textures go through the same
  route, so its verdicts are of the image a texture names.
  CHECK_VERSION 13 -> 14: 13's records kept ExportedDmaBuf Unchecked as
  a cause that lasts.
- WorkCounts::exported_dma_buf_images_named_opaque_fd counts the images
  that name the opaque type over a dma-buf block (api_signatures.tsv).

Test: exported_textures'
a_dma_buf_block_s_planes_name_an_opaque_fd_where_its_images_take_no_dma_buf_in_a_shared_block
asks the buffer and image queries itself, apart from the runtime: it
asserts the block's export set matches the buffer queries, the
buffer's export is a dma-buf (fdinfo exp_name), and, where the block
exports both and the dma-buf type takes no image of the plane's format
in a shared block, each plane is in place naming the opaque type
(counted) or a shadow of a byte the check found changed, never
Unchecked; no VUID under the layer. Without the change it fails on
RADV: the block exports the dma-buf alone where the buffer queries
answer both.

Docs: API.md's shadow rule, HOWTO section 7, the runtime README and the
module docs.

Verification: to run on the 780M, the RX 550 and lavapipe, then the
5080 through an entry.

(cherry picked from commit 1acb4f1fbf1fd4df8fcee2948417dcc089909fe4)
2026-11-08 18:30:27 -08:00
Anees Iqbal 04f1587445 Snapshot refusals: say which clause leaves an own-pixel slot out, and count unreadable splits by it
WorkCounts::reading_draws_split_unreadable_own_pixel counted draws whose
own-pixel slot no snapshot serves without saying why: its one logged reason
lumps a branch, a sample, a derivative, a store and a function that writes
memory. On the guest compositor's 780M walk it is 23,031 draws (23,463
before f922125bb1's demote guard), so the guard served another shape, and
which clause refuses decides the next step. Counts and interface facts
only; which slots qualify is unchanged.

Translator: spirv::requirements::snapshot keeps one reach mask per clause
and states each slot left out with every clause that holds for it
(StageInterface::snapshot_refusals, StageModule::snapshot_refusals, the new
public pipeline::SnapshotRefusal): Branch, Derivative, Sample,
GroupOperation, Store, Atomic, ImageWrite, UndefinedOperand, WritesMemory,
Interlock, Coherent, Other (a slot past 127, values that do not settle, a
ray query, a mesh output count, an unmatched call, the entry's returned
value). The walk now runs also in a function that writes memory or a module
with an interlock or coherent resource, so such a slot is stated with the
per-value clauses too; its slots stay left out as before. A snapshot variant
judges none. ARTIFACT_FORMAT_VERSION 494 (two encoded fields, one enum),
SEMANTICS_VERSION 1996 (a new interface fact).

Runtime: a draw split for UnreadableOwnPixel is counted once under each
clause that leaves out any of its unreadable attached slots
(WorkCounts::reading_draws_split_unreadable_own_pixel_{branch, derivative,
sample, group_operation, store, atomic, image_write, undefined_operand,
writes_memory, interlock, coherent, other}), and the log names the clauses,
once a device per set.

Tests:
- spirv::requirements::snapshot::tests::only_values_no_helper_can_pass_on_qualify:
  every sink states its one clause, with new sinks for a quad swap, a
  storage-buffer store, an atomic, an image write and a coherent image.
- spirv::requirements::snapshot::tests::a_slot_left_out_by_the_function_or_its_index_says_so:
  WritesMemory alone and beside a derivative; slot 200 Other beside slot 0
  qualifying.
- pipeline::compile::tests::the_interface_states_why_a_slot_takes_no_snapshot:
  owned fixture sd_read_discarding on the 780M's profile states none, and
  Branch alone with shaderDemoteToHelperInvocation withheld; tob_read none;
  the render pipeline's fragment stage the same.
- runtime_lane::snapshot_reads::a_reader_that_ends_itself_by_its_texel_takes_the_split_for_its_branch
  (device): the discarding reader with demote withheld: 3 * FILL, two
  splits, two unreadable own-pixel splits, both under branch alone.

api_signatures blessed (26 records); api_surface row for SnapshotRefusal;
docs/API.md's snapshot reads name snapshot_refusals.

(cherry picked from commit 4412816cc23ede42b266ad4d2c62465711853d83)
2026-11-08 18:29:23 -08:00
Anees Iqbal 733108b25d fresh_contents: the Depth32Float rows' zeroed-pattern declarations are held by the row test
The family's declaration test held every allowance to the notices site or
the fresh value declaration, so the two Depth32Float rows' unchecked fresh
site under fresh-pattern-zeroed (55df5fa64b) failed it. The test now names
that declaration, counts the texture row's three extra allowances and the
pattern row's two, and checks no other row carries it.
docs/CONFORMANCE-COVERAGE.md is regenerated
(python3 -I scripts/conformance-coverage/coverage.py): fresh_contents now
loosens one measured value.

Verified: both failed in the conformance suite on gem10 (job 10312); the
rerun follows.

(cherry picked from commit 184d622fa578658947c19dd19df29ff160a91b9b)
2026-11-08 18:15:24 -08:00
Anees Iqbal 12f7267750 Depth comparisons record RestrictedDepthRange on every device without VK_EXT_depth_range_unrestricted, MoltenVK included
Without the extension Vulkan gives a depth image no value outside
[0, 1]: a copy may take none (VUID-vkCmdCopyBufferToImage-pRegions-07931),
and a render write is clamped to the viewport's depth range. MoltenVK's
driver was measured to keep such values
(DriverFact::DepthImageKeepsValuesOutsideUnitRange), and its depth
comparisons required that property in place of the note; the owner's
rule is never to rely on undocumented Vulkan behaviour, so the fact
follows the extension and nothing else. With the extension a comparison
records nothing already, so the fact, the
VkProperty::DepthImageKeepsValuesOutsideUnitRange it derived and the
texture plan's kept_depth_range are removed: depth_comparison records
RestrictedDepthRange wherever the extension is not enabled (ANV, RADV,
MoltenVK), a precision note, logged and never fatal.

SEMANTICS_VERSION 1995: MoltenVK's comparing stages record the note and
no longer require the property. The codec drops the variant by name (no
format bump: a removed variant's tag stays unused). docs/API.md's
restricted-depth-range entry, FAST-PATHS rows 79 and 80, the note's and
the measurement table's docs, engine_depth_range's test (the note on
MoltenVK too, no module requiring the extension), driver_facts' MoltenVK
row and api_signatures (three variants) follow. The compare-clamp lane
predicts restricted-depth-range by the extension alone again.

Verification follows in the lane jobs; the golden tables and the
authored compile census are re-blessed on development.

(cherry picked from commit 90d231de945294c8428c05f79946f09bbb426819)
2026-11-08 18:15:23 -08:00
Anees Iqbal afb53192f7 Depth uploads clamp on every device without VK_EXT_depth_range_unrestricted, MoltenVK included
Vulkan takes no copied depth outside [0, 1] without the extension
(VUID-vkCmdCopyBufferToImage-pRegions-07931), and a driver measured to
keep one (DriverFact::DepthImageKeepsValuesOutsideUnitRange, MoltenVK's)
does not make the copy valid: the owner's rule is never to rely on
undocumented Vulkan behaviour. MoltenVK 1.4.2 does not expose the
extension, so ImageFacts::depth_clamps is now the extension's absence
alone: MoltenVK's uploads (replace_region, blits from buffers, copies from
colour textures, a heap's tiled copy in) clamp as ANV's do and announce
restricted-depth-upload. The fact stays for the translator's depth
comparisons (lower/texture/slot.rs depth_comparison, through
VkProperty::DepthImageKeepsValuesOutsideUnitRange) and for the validation
executor's own raw copies (candidate/platform/compute.rs).

The lanes follow the rule (degrade_notices::clamps_depth_uploads, the
heap lanes, texture_blits::depth_images_keep_what_their_drivers_claim,
which checks the clamp where the device lacks the extension, and
buffer_depth_samples). The combined-format blit lane counts apart the
GPU-assisted check's reports at offsets off a depth's 4 bytes: layer
1.4.363 reads a D32_SFLOAT_S8_UINT depth aspect's buffer at 5 bytes a
texel, where the spec lays it out as D32_SFLOAT's.

Verification: Iris, lavapipe and the M3 lanes follow in their jobs.
(cherry picked from commit 6dfbc9c0dd0b4b3690ce2824d16fb561afc51047)
2026-11-08 18:15:23 -08:00
Anees Iqbal 460a608d1b Depth uploads clamp into [0, 1] on devices that take no other: replace_region, blits from buffers, copies from colour textures
On a device without VK_EXT_depth_range_unrestricted whose driver is not
measured to keep a depth outside [0, 1] (ImageFacts::depth_clamps, ANV on
the Iris Xe), a copy into a D32_SFLOAT or D32_SFLOAT_S8_UINT depth plane
took Metal's bytes as they are, which breaks
VUID-vkCmdCopyBufferToImage-pRegions-07931 for any value outside
[0, 1]. The heap's tiled copy-in already clamped (TiledLevelMove::
clamps_depth); every other upload now goes through the same clamp, on
the bits: a NaN of either sign 1.0, -0.0 kept, other negatives 0, above
1.0 (+inf too) 1.0, the rest as they are, no denormal flushed.

- Translator: bind::clamped_depth (the CPU rule) and
  bind::depth_clamp_module (DepthClampModule), an in-place clamp over a
  buffer's words in the extended-canonical kernel's shape (first, width,
  row and image pitches). The tiled kernel's clamp now shares the module's
  SPIR-V helper.
- Runtime, depth_clamp.rs: clamps_depth (one test of format, aspect and
  device facts, which heap_tiled now uses too), the CPU clamp of packed
  bytes, and BlitCommandEncoder::clamp_depths / clamped_depth_copies: one
  dispatch a region (split into images or rows past the device's storage
  range or workgroup counts), each its own command so the tracker orders
  it between the copies.
- replace_region clamps the packed bytes on the CPU before any route (a
  host copy, the staging queue, a submission), so no depth image holds a
  value outside [0, 1] that a later copy of its texels moves on.
- A blit from a buffer into such a depth copies the regions' bytes into a
  scratch buffer, clamps them and copies from there; a plan that stages
  its rows clamps its staging buffer in place; a copy from a colour
  texture through the encoder's scratch clamps the scratch before the
  copy into the depth.
- WorkCounts::depth_uploads_clamped counts each clamp.
- restricted-depth-upload stays announced where it was; its doc, the
  replace_region message, docs/API.md, the blit and replace_region docs
  and the FAST-PATHS device-gap row say the upload clamps.
- MoltenVK (DepthImageKeepsValuesOutsideUnitRange) and devices with the
  extension are untouched.

Lanes, runtime_lane::depth_upload_clamps, under the validation layer's
GPU-assisted buffer-copy check: replace_region, a blit from a buffer (as
it is, through its plan's staging at an offset of 2, and into
Depth32Float_Stencil8's depth) and a copy from an R32Float texture, each
checking no VUID-07931, the clamp counted, and each texel read back
clamped (or as written where the device keeps it). The heap lane now
shares the lanes' device and message checks. Unit tests: the clamp rule,
the kernel under the interpreter, the region splitting, the CPU clamp.

api_signatures blessed (+16), api_surface table updated; REFUSALS.md
unchanged on regeneration.

Verified: not yet (Iris, lavapipe and Linux clippy are queued).
(cherry picked from commit a63c3646dd5e3fad8b24e387c4adb0f94d635ac9)
2026-11-08 18:15:22 -08:00
Anees Iqbal 85465062e2 HOWTO section 7: where a texture over an exported frame's plane lies in place
Names the rule the runtime applies to each plane's linear image (the
plain one first, else DRM_FORMAT_MOD_LINEAR), made for the export's
handle type: the image format query takes that handle type, not in a
dedicated allocation alone; the plane's byte in the memory is a multiple
of vkGetImageMemoryRequirements' alignment; vkGetImageSubresourceLayout
answers offset 0 and the plane's row pitch, its size fitting; and the
device's in-place check of that exported memory passed. The shadow's
causes otherwise, and the measured alignments for a 3840x2160 NV12
frame: 64 on lavapipe (m3-max-10165), 256 on the RX 550 under RADV with
opaque descriptors (m3-max-10151), whose dma-buf planes are shadows.

(cherry picked from commit 15affc37f6910f8ea7bababe1bcb5c69d5ae7d5c)
2026-11-08 17:00:48 -08:00
Anees Iqbal 098eec639b API.md: when a texture over exported memory is a shadow
The shadowed-texture list in section 10 gains the exported-memory causes the handle-type fix introduced: the check of that exported memory not passed (pending ones move in place), the image format query refusing the handle type but in a dedicated allocation, and a buffer's dedicated allocation.

(cherry picked from commit cd993135eca08d877b7b55a3c0570df86df7510f)
2026-11-08 17:00:48 -08:00
Anees Iqbal 99453e91d8 Images bound over exported memory name its handle type; a check class per export handle
A texture over an exportable buffer (exported_memory.rs) was a PREINITIALIZED linear
image, or a DRM_FORMAT_MOD_LINEAR one, with no VkExternalMemoryImageCreateInfo, bound in
memory allocated with VkExportMemoryAllocateInfo: VUID-vkBindImageMemory-memory-02728
("it must include at least one of the handles set in
VkExternalMemoryImageCreateInfo::handleTypes"). RADV and NVIDIA tolerate it; the layer
does not.

What changed:
- memory.rs: Memory::bound_memory reads a placement's own record (the block's export,
  import, own pages or read-only view, a guest RAM chunk's handle, a dma-buf import) and
  answers the handle type an image bound there names: none for memory of no export, the
  export's handle for a shared exported block, HOST_ALLOCATION or DMA_BUF for imports, and
  no image for a buffer's dedicated allocation (VUID-vkBindImageMemory-memory-10926) or the
  caller's memory. Buffer::bound_memory answers it for a buffer (a heap buffer's, its heap's).
- texture.rs alias_unbound decides the image from that record, not the route: over exported
  memory the device's linear image made for the handle type (external_linear_image, the
  former host_linear_image generalized), else the DRM_FORMAT_MOD_LINEAR one made for it
  (ModifierMemory::Exported). Either is made UNDEFINED (VUID-VkImageCreateInfo-pNext-01443),
  so its first move may discard the bytes, which only the device's check may vouch for.
- in_place.rs: two check classes, PagesClass::ExportedFd and ExportedDmaBuf. Their buffer
  is an exportable Shared buffer of that handle type in a shared block; their textures take
  the product's image. A texture over exported memory takes its image where the policy and
  those verdicts pass for its accesses; before them it is a CheckPending shadow that moves
  in place at the next quiet commit, as over the pooled memory (storage_form.rs now moves
  any class over the runtime's own memory). No LinearCost bound there: another API writes
  those bytes.
- The image format query (VkPhysicalDeviceExternalImageFormatInfo) must answer the handle
  type exportable (importable for imports) without DEDICATED_ONLY, for the linear and the
  DRM_FORMAT_MOD_LINEAR image alike; else the texture is a shadow, its notice naming the
  query's refusal. A dedicated allocation keeps the shadow, its notice naming 10926.
- ycbcr_planes.rs: the two-plane image is PREINITIALIZED with no handle type, so it takes
  only memory whose record says no export or import (KeptTexels::Memory elsewhere).
- in_place::CHECK_VERSION 12 -> 13: the record holds two more classes, so every driver's
  check runs once more.

Checked and unchanged: heap.rs's images (heaps are never exported; over host pages they are
HOST_ALLOCATION images, over a copy in device memory a shadow or an Own linear image), the
in-place images over host pages and copies (HOST_ALLOCATION over imports, Own over device
copies), and the runtime's own images in Holds::Images/Buffers blocks.

The placement rule (in_place.rs, "The runtime's exported memory"): per texture (per plane),
the texels' offset in the memory (the buffer's first byte, or its aligned_byte, at a
multiple of 256 there, plus the texture's offset) must be a multiple of
VkMemoryRequirements::alignment from vkGetImageMemoryRequirements for the image made for the
handle type of the texture's format, extent and usage; vkGetImageSubresourceLayout of its
first subresource must answer offset 0 and Metal's rowPitch; its size must stay inside the
buffer. The linear image first, then the DRM_FORMAT_MOD_LINEAR one with its own alignment.

Test: tests/exported_textures.rs, an NV12 picture's R8 3840x2160 and RG8 1920x1080 planes at
32 and 8294432 of an exportable buffer laid with aligned_byte(32), opaque fd and dma-buf,
Private and Shared, under the validation layer: a shadow first, both moved in place after
settle_in_place_checks, readback equal, in place at once after, no layer message.
dma_buf_export settles the checks before its plane textures. Not yet run: this commit is
for the build and the device runs.

(cherry picked from commit 40872fbb4748cbd228c06c27dc0cd63ca2d0a5ec)
2026-11-08 17:00:47 -08:00
Anees Iqbal 3f69d1af77 No-copy buffers and heaps whose pointer the device refuses, with no dma-buf source, are copies
On RADV (amdgpu userptr takes anonymous private pages only) a no-copy buffer over shared memory,
a memfd mapping among it (QEMU's memory-backend-memfd,share=on guest RAM), made with no source of
dma-bufs of its pages, was refused (Unsupported, HostMemory), where Metal makes a no-copy buffer
over any page. Device::buffer_over_host_memory now makes it over a copy of the pages instead
(copied.rs), announced (copied-host-pages, its detail naming the device's refusal) and counted
(WorkCounts::copied_host_buffers_device_refused, of copied_host_buffers_made). A no-copy heap's own
buffer takes the same path. The import with a source is unchanged: the source is still called
first, and a copy follows its failure only as before. A rebind to such memory without a source is
still refused (its own import path), as HOWTO section 6 now says.

Docs: the runtime README, HOWTO sections 6 and Copied host buffers, HostMemory::new,
Device::imports_shared_host_pointers, the copied-host-pages catalogue entry and copied.rs's opening.
docs/REFUSALS.md regenerated (unchanged: the refusal stays where pages cannot be read).

Test: tests::copied_device::copied_buffer_is_made_over_shared_memory_whose_pointer_the_device_refuses
(Linux): where the device refuses shared memory's pointer, the buffer is a copy, announced and
counted as the device's refusal, with every copy's coherence; elsewhere an import.

(cherry picked from commit 0e07fff15b79cf0fdcf4f09a2836c7075db266a3)
2026-11-08 15:58:08 -08:00
Anees Iqbal ee3f269fa3 Heap depth textures: the copy in clamps a 32-bit float depth into [0, 1] where the device takes no other
A heap's 32-bit float depth texture whose shadow copies the heap's bytes
into its image went through vkCmdCopyBufferToImage with whatever float the
bytes held. On a device without VK_EXT_depth_range_unrestricted that is
invalid usage for a value outside [0, 1]
(VUID-vkCmdCopyBufferToImage-pRegions-07931); ANV stored it clamped, and
the runtime only announced it (restricted-depth-upload).

The tiled texel kernel (metal2vulkan::bind) now clamps a level's elements
on the way into the tight buffer where the level says so:
- TiledLevelMove::clamps_depth, set with TiledLevelMove::clamping_depth;
- the shape's level record grows to 14 words;
- the clamp compares the word's bits, so no denormal is flushed: a
  negative value becomes 0.0, one above 1.0 (and +inf) becomes 1.0, a NaN
  of either sign becomes 1.0 (as nan_clear.rs clears a NaN depth), and
  -0.0 and every value inside [0, 1] keep their bits;
- the move back is unchanged.
HeapTiledCopies::new takes the image's format and marks the 4-byte depth
planes' levels of a D32_SFLOAT or D32_SFLOAT_S8_UINT image where
ImageFacts::depth_clamps holds: exactly where restricted-depth-upload is
announced. MoltenVK, whose driver is measured to keep such values
(DriverFact::DepthImageKeepsValuesOutsideUnitRange), keeps its copies as
they were. The clamp is the device's own answer, so the notice stays and
its text now says the copy in clamps.

Tests:
- bind::tiled_texels::tests::clamped_depths_move_into_the_image_inside_0_1,
  run through the CPU interpreter;
- lane heap_textures::a_heap_depth_texture_s_copy_in_takes_no_depth_outside_0_1,
  which turns on the layer's GPU-assisted buffer-copy check
  (gpuav_buffer_copies), asserts no VUID-07931 message, and checks a blit
  reads the clamped values where the device clamps, else the bytes as
  they are.

Docs:
- the restricted-depth-upload declaration, docs/API.md's catalogue and its
  docs/FAST-PATHS.md device-gap row say the copy in clamps;
- docs/FAST-PATHS.md's known gaps gain one entry: a heap texture Metal
  keeps uncompressed lies in its driver's layout where its image fits
  Metal's answer (heap-texture-untiled-layout);
- api_signatures.tsv is blessed for the two new public items.

Verification in the tip report.

(cherry picked from commit de683c02ce08d337e8281dd752c2519f863bbe39)
2026-11-08 15:41:19 -08:00
Anees Iqbal ddb5440aad An exported buffer's announced external write lets go of its shadows' standings
A texture over an exportable Private buffer whose rows no image holds (a decoder's pitch) reads it
through a shadow, and a shadow over a tracked Private buffer the runtime made stands across
command buffers (shadow_standing.rs): a later command buffer's first copy in moves nothing while
no batch wrote the buffer or the image. Another API's writes through an import of the buffer's
memory are no batch's, and Buffer::external_write_done only noted the acquire, so once such a
texture had copied in, every later external write was missed: each of reims' NVDEC pool
surfaces on the 5080 kept showing its first picture.

external_write_done now counts a write of the buffer's key against every standing recorded on
it (Standings::written_apart, LetGo::TruthWritten), so the next command buffer's first copy in of
each shadow over the bytes moves what the other API wrote. Standings stay otherwise: the
contract already says the device reads another API's writes only once the caller announces them
("What the other API writes there is the device's to read once the caller says so", "Call it
once after each of the other API's writes"), so a write made without the call keeps no new claim
on a standing, and an exported buffer's shadows keep standing between announced writes (one
copy in per write, not one per command buffer). The runtime README, HOWTO and the module docs say
what the call does for a texture's shadow.

tests::exported_memory::a_shadow_over_an_exported_buffer_reads_each_announced_write: a second
VkDevice fills the buffer through an import of its opaque descriptor (released to
VK_QUEUE_FAMILY_EXTERNAL), three values in turn, each followed by external_write_done and two
reads of a padded-row texture through a kernel: the first must read the write and copy in, the
second must read it again with the image standing.

Verification: to follow (clippy x3, the lane and the standing tests on lavapipe and the 780M, a
negative control without the let-go).

(cherry picked from commit 542237e45fe706a39d5cd9e39f861f792c4c2996)
2026-11-08 15:24:26 -08:00
Anees Iqbal 0cadcbae8c Copies over RAM the device refuses always stage through the CPU; its chunks are not faulted in
On a device that refuses pointers to shared memory (RADV) and a RAM of shared
memory with no dma-buf source, a gather was staged through the CPU while the
device's thread had not yet tried the chunk. Once the thread's import was
refused (`tried`), the same gather went to CopyTake::Waits, imported the chunk
itself and was refused as Unsupported(HostMemory). So a copy Metal takes
succeeded or failed depending on when it came. The first-fill bench's steady
fills failed so on a Radeon 780M. A gather after a staged scatter into the
chunk was refused the same way: the scatter set `scattered`, so written_over
kept the gather off the CPU's path. And the thread faulted each 64 MiB chunk
in before an import the device refuses whatever the pages hold.

Now the plan records the refusal (Plan::shared_refused: no source, a range of
shared memory, and the device answers imports_shared_host_pointers false,
asked once at the use). Each chunk of shared memory under it is
ChunkSlot::refused, known from the use on. copy_take answers ThroughCpu for a
refused chunk whether or not the thread ran or tried it. written_over ignores
a copy's write into a refused chunk, which only a staged scatter's CPU drain
makes, in a host step before any later copy's. import_ahead faults no refused
chunk in (it still tries the import, which is refused at once). Chunks it does
fault in are counted: WorkCounts::host_ram_chunks_faulted_ahead.

Tests:
- copies_over_shared_ram_move_their_bytes_after_the_thread_reached_its_chunk:
  gather, scatter, gather over a shared memfd RAM after the thread reached its
  chunk. On a refusing device all three stage and move the right bytes.
- the_ahead_thread_faults_in_only_chunks_the_device_may_import: 0 chunks
  faulted in where the device refuses, and at least the chunks imported ahead
  where it imports (Linux).

(cherry picked from commit 590a07faf1468b162333f479a0f857aa71a353a3)
2026-11-08 14:48:32 -08:00
Anees Iqbal 4b277a28d1 A RAM's use, dropped, waits for its device thread: no page is read after it
The device's thread for a guest RAM (import_ahead, listed_chunks) upgraded the
RAM and faulted a chunk in by reading its pages (read_volatile, since
259be5d3c5) with no hold the use's end waited for. A consumer that dropped
the use and its RAM and then unmapped the pages, as a VMM's teardown does,
had the thread read an unmapped page: SIGSEGV in a consumer's test on an RTX
5080, and in our contended bench on a Radeon 780M (12 of 12 runs before the
bench's keep-alive fix).

Now HostRamUse keeps the thread's JoinHandle. Its drop sets the use's end
(Wake::ended), wakes the thread and joins it. fault_in checks the flag before
each 2 MiB step, and both threads check it at each look and between the
fault-in and the import. So the drop waits at most one step of reads or one
import under way, and once it returns the runtime reads, faults in and imports
no page of the RAM. An import a buffer or a pending command buffer holds still
keeps its pages until the keep-alive goes, as before. The fault_in SAFETY
comment now names what keeps the pages mapped.

Test: a_use_s_drop_waits_out_the_thread_so_its_pages_may_be_unmapped_at_once
makes 32 rounds over a fresh 64 MiB memfd mapped shared, with a keep-alive
that does not unmap. Each round uses the RAM, drops the use 0 to 4.8 ms
later, drops the RAM and unmaps at once. It checks that each round's
keep-alive went before the unmap and that every chunk was freed.

(cherry picked from commit 0c18e1898fc5a9ce50eb5bd7508dd171c01e3093)
2026-11-08 14:09:07 -08:00
Anees Iqbal 8b664a27a2 Shadow log names every shadow a texture makes; never-stood copies in split by what kept the end from standing
The walk's unskipped copies in are all of a 3648x2038 surface that never
stood, and the shadow log, which named only a texture over a buffer's bytes,
never named it. Two instruments to find out which shadow it is and why no
command buffer's end leaves it standing:

- METAL2VULKAN_LOG_SHADOWS now names each shadow a device makes of a
  texture: a usage shadow (a binding beyond its usage, an attached read, a
  YCbCr texture's writes), with what the texture's own image is (an aliasing
  image over the bytes with or without the feedback loop usage, a shadow, or
  an image of its own); a rotated texture's image of its stored frame and its
  twin; a two-plane extended-range texture's image; a depth or stencil
  texture's tiled twin over a surface plane; and a YCbCr texture's converted
  image and render shadow. A line's truth is the buffer's bytes or the
  texture's own image.
- WorkCounts::shadow_texels_never_stood_{unmet, not_current, dropped,
  partial, end} split shadow_texels_unskipped_never_stood by what last kept a
  command buffer's end from leaving the image standing
  (shadow_standing::Missed): no end met it, an encoder ended with its image
  not holding the truth, what the command buffer carried let it go, the end
  held it in part or stale, or the end records no standing. Each shadow that
  may stand keeps the last one; off the counts it changes nothing.

Verified: cargo fmt only so far; the checks run as a potluck job.
shadow_standing_device now asserts the five sum to never_stood and that a
first read's never-stood texels are all unmet.

(cherry picked from commit 1dd2a2ee2b9c39a2ba7aaeea3e3ad7906fd035f9)
2026-11-08 13:46:25 -08:00
Anees Iqbal dae9923446 Heap refit docs: which textures an image in place serves, and what the shadows of Metal's tiles cost
HeapTextureHostTransfer and HeapTextureLinear (and docs/API.md's catalogue)
say the refit takes an image of host-transfer usage only for a texture Metal
compresses or whose layout is not modelled, and of one Metal keeps
uncompressed only a linear image whose every element lies where Metal's tiles
place it. docs/FAST-PATHS.md's costs record the shadow of Metal's tiles kept
for every other such texture, with the 1x1 shadow's GPU time measured on the
Iris Xe at RUNTIME_VERSION 1909 (35.9 us against 8.1 us a frame); the
compositor's 3x3 to 10x10 shapes are not measured apart.

(cherry picked from commit dc30f3c6c8768ab3780bad861bba9db1ad9f4b84)
2026-11-08 13:32:36 -08:00
Anees Iqbal ec94c62dce heap depth textures: a merge's keep holds the heap's bytes, not the image's
A 2-slice Depth32Float 64x64 x2 multisample texture in a Shared placement heap
on ANV (Iris Xe, RPL-P, Mesa 26.2.6) lost the samples a blit wrote into one
slice: 16384 of 16384 were off Metal's tiles after the merge back, while a
read straight from the image matched. The heap's bytes held 0xee before the
blit. The copy in hands the image 0xeeeeeeee, a float outside [0, 1], which
Vulkan leaves undefined in a depth image without
VK_EXT_depth_range_unrestricted, and ANV stores 0.0. The merge's keep was
moved out of the image (only drivers announced drawn-depth-copy kept the
heap's bytes), so it held 0.0, and the merge kept the heap's 0xee in every
byte of a written sample that equals 0.0's: a probe found 9155 0xee bytes
left in the slice, the 9134 zero bytes of the samples plus 21 sample bytes
that are 0xee, and no sample whole.

Now a heap's tiled texture with a depth aspect, of any sample count, keeps
the heap's bytes: the staging buffer its copy in filled where the keep
follows it (WorkCounts::shadow_keeps_from_staging), else the heap's bytes
themselves, and plans no moves out of the image for the keep. Every byte a
command wrote is merged whatever the copy in changed; a value the copy in
changed in a texel no command wrote is written back as stored, as a copy back
writes it.

That clamp is the device's: a heap's 32-bit float depth texture whose shadow
copies the heap's bytes into its image now announces restricted-depth-upload
as it is made, on a device without VK_EXT_depth_range_unrestricted whose
driver is not measured to keep such a value (ANV; not MoltenVK, NVIDIA or
lavapipe with the extension). Its declaration, docs/API.md's catalogue and a
device-gap row in docs/FAST-PATHS.md say so.

The measured drawn-depth-copy flag a multisample texture held for its keep
is gone with its one reader; the announcement at making stays.

heap_multisample_textures_keep_their_samples_in_metal_s_tiles now also
checks, for each counted 32-bit float depth texture, restricted-depth-upload
as it is made where the device clamps, and that a blit into one slice or
aspect keeps from staging. Verification in the tip report.

(cherry picked from commit 688e1dcc00ff67979833fdcbaf2f5484057e18a6)
2026-11-08 13:16:59 -08:00
Anees Iqbal e106dbf2c7 FAST-PATHS: the 780M's later clips at one budget for its heaps made no allocation and took 122 and 119 ms
m3-max-9499 at 9bc836c2e9 on um790's Radeon 780M alone (RADV PHOENIX,
MESA_VK_DEVICE_SELECT 1002:15bf!): tests::clip_bursts' later clips made
0 and 0 allocations (16 in the first) in 121.5 and 119.2 ms, against 4
each and 237/245 ms with the placements in the system heap and a budget
per heap, and 132/126 ms with them device-local. The bullet said the
unified budget keeps every block; it now carries the measurement.

(cherry picked from commit f2e2063f1ff7050d7eeefd6ecdc26ace0c4bc29c)
2026-11-08 13:02:13 -08:00
Anees Iqbal 6be762136b Memory: with unified memory the heaps keep one budget of empty blocks
With the UMA placement, a Radeon 780M's Private placements take its
5.53 GiB system heap, whose eighth (707 MiB) kept all but 3 of a video
clip's 16 blocks: each later clip made 4 again (tests::clip_bursts,
m3-max-9454: [4, 4]) and took 237/245 ms to make against 132/126 ms with
the placements device-local (m3-max-9448). With unified memory every heap
is the same memory: the budget is now an eighth of all the heaps, at most
KEPT_EMPTY_BYTES, and the empty blocks of every heap count against it, so
the 780M keeps 2 GiB as one budget where it kept 707 MiB and 1414 MiB
apart (2.1 GiB in all). Devices without unified memory keep a budget per
heap as before.

Tests: tests::memory::unified_memory_keeps_one_budget_for_its_heaps (the
780M's heaps, a discrete card's, one heap). FAST-PATHS: the kept-memory
row's 780M figures, and the UMA row's clip-burst cost.

Verified: not yet run; lavapipe and the 780M follow as potluck jobs.
(cherry picked from commit 9bc836c2e9cac4b43b86380e4c53ee3a02133214)
2026-11-08 13:02:13 -08:00
Anees Iqbal 40a634d351 FAST-PATHS: unified memory's Private placements in the system heap first, and what they cost
The 780M runs before and after the placement (m3-max-9103 at the base,
m3-max-9157 at the change, um790, RADV PHOENIX): copies of 256 MiB at
23.9/28.8 GB/s device-local against 28.5/29.0 GB/s in the system heap's
type; a 259-tile scroll beside 1 GiB of another allocation's local memory
at median frames 1.31/1.29 ms before and 1.87/1.30 ms after (frames 300
and 600), alone 2.87/4.87 ms before and 1.33/1.31 ms after; no
amdgpu_bo_move eviction traced in either. Recorded under the costs of
matching Metal: no cost measured, no switch, not announced.

(cherry picked from commit 3d1f49072ca66c9976835da4df54773f50a7f283)
2026-11-08 13:02:13 -08:00
Anees Iqbal 80b581bee2 Dma-buf export: README, HOWTO, the API table and REFUSALS.md
The runtime README lists exported_as, export_memory_dma_buf and
external_write_done beside the opaque-fd export; HOWTO gains a section on
memory another API writes (a decoder's DRM_PRIME_2 frame), the old
section 7 now 8. The API signatures table is re-blessed for MemoryExport,
BufferDescriptor::exported_as, with_exported_as, the two Buffer calls,
Problem::ExportedNoCopy and RuntimeGap::DmaBufExport, and REFUSALS.md is
regenerated with the new gap's reach (none: a runtime extension).

(cherry picked from commit 3988f9ec5921e8962708ce7735937c44836361a1)
2026-11-08 13:02:12 -08:00
Anees Iqbal 259be5d3c5 host RAM: fault in a VMM's shared memory by reads, not under the memory map lock
What: the import-ahead thread's fault_in now reads each page of a chunk where
every mapping over it is shared memory of base pages (a memfd, as QEMU maps a
guest's RAM), as PROCMAP_QUERY answers (vma_flags SHARED, vma_page_size the
host's page). A read fault on such a mapping allocates the page and maps it
writable, changing no byte, and since Linux 6.7 runs under the mapping's own
lock, so it holds no mmap_lock. Private memory, hugetlbfs (whose fault past
its pool is SIGBUS) and kernels without PROCMAP_QUERY (before 6.11) keep
MADV_POPULATE_WRITE in 2 MiB steps. host_memory.rs's PROCMAP_QUERY call is
factored into mapping_at, shared by queried_permitted and the new
shared_base_pages.

Why: in a consumer's guest boot on the RTX 5080 laptop, seven slow pipeline
compiles had no thread in an NVIDIA ioctl; their threads sat in an mmap_lock
convoy (vCPUs in get_user_pages, mprotect from heap growth, mmap/munmap in D),
and the one kernel-stack dump that caught the reader found m2v-host-ram in
MADV_POPULATE_WRITE. MADV_POPULATE holds mmap_lock read for each 2 MiB step,
which under reclaim and compaction takes milliseconds, and a waiting writer
queues every later reader behind it.

How verified so far: a C probe on um870 (Linux 7.3.1, 4 GiB memfd under
MADV_HUGEPAGE, a thread calling mprotect every 0.2 ms, two mapping, touching
and unmapping 4 MiB every 0.5 ms): populate in 2 MiB steps took 202-541 ms
with the longest mprotect 4.8-10.1 ms (four runs); per-page reads took
239-247 ms with the longest mprotect 0.40-0.52 ms (two runs), and the write
pass after them faulted no page en masse. New unit tests: the choice of way
(shared memfd by reads, private and a span over both by the advice), and that
a fault-in by reads leaves every page resident, writable (a write pass faults
nothing) and every byte unchanged. cargo fmt only; clippy, the tests and the
5080 before/after run follow as potluck jobs.

(cherry picked from commit e571995af620272b12bb3083a5c59fbf8b844e39)
2026-11-08 12:39:37 -08:00
Anees Iqbal 7fbbac9536 Heap textures: an image that fits Metal's answer lies in place before a shadow
A single-sample colour heap texture whose image of the route the device
first took (ANV's compressed optimal image under the default
HeapCompressionPolicy, say) takes more bytes or a coarser alignment of the
heap than Metal's answer was a shadow of the heap's bytes in Metal's tiles,
copied in before each command buffer's first use and back after each
writing encoder. The owner's rule keeps a shadow as a correctness fallback
only: where the device makes an image that fits the answer in the heap's
memory, the texture now lies there in place, its optimal image of
host-transfer usage first, else its linear image
(Device::fitting_heap_image), announced heap-texture-host-transfer or
heap-texture-linear with the making's facts and what the first image took.

Unverified: built and measured on ms01's Iris Xe in the commits that follow.
(cherry picked from commit c1a996cd53f74d0afa130dd867ab42499c2b758f)
2026-11-08 12:19:41 -08:00
Anees Iqbal 6ef13920d0 Shadow causes for a walk: why a private truth's first copy in moved, and a log of each shadow made
The 780M's glass composites copy large Private IOSurface planes in each command buffer: walk 9286
counted 41.07 M texels first copied in per composite, 37.70 M of them over images an earlier
command buffer left standing, yet only 3 copies in a composite were decided against a standing
(2 skipped) of 84 shadow copies. No count said where the rest were decided, nor why each shadow
over those planes takes no image over the bytes.

- WorkCounts::shadow_texels_unskipped_*: every encoder's first copy in of a Private (or
  Memoryless) buffer's bytes, an IOSurface plane's among them, that moved its texels, by where it
  was decided (shadow_standing::Unskipped): unstanding (its shadow never stands: untracked, a
  heap's, the caller's memory, its VkBuffer handed out, writes dropped), between_instances (a held
  render pass's copies between its instances, inline_splits, which no submission decides),
  after_encoder_writes, recorded_whole (predicated laying, no new VkCommandBuffer),
  command_buffer (at submission: its command buffer reaches unnamed memory or an earlier encoder
  wrote the truth or image), let_go (at submission: the standing let go). With
  shadow_texels_skipped_by_standing they sum to shadow_texels_first_copied_in_private_buffers +
  _private_surfaces. And, but for unstanding, by what the standing held then (shadow_standing::
  LetGo, Standings::let_go): stood, never_stood, unnamed_since, truth_written, image_written; for
  those decided as the encoder records them, by the batches submitted so far.
- METAL2VULKAN_LOG_SHADOWS (default-off diagnostic, shadow_log.rs): one line per shadow a device
  makes of a texture over a buffer's bytes: the call (new_texture_with_iosurface_plane for a
  plane's), format, size, levels, usage, the buffer's storage mode, length and object ID, the
  texels' offset and row pitch, and the reason its shadowed-texture notice gives (announced once
  a device). Two textures over the same bytes name the same object ID and offset.
- Standings::stands is folded into let_go; submit.rs's gate answers where it was decided.
- Tests: shadow_standing_device checks both sums in every leg, and the first read's copy in is
  let_go/never_stood, the read after another queue's fill let_go/truth_written, a read after its
  own command buffer's fill command_buffer, a read once the VkBuffer was handed out unstanding.
- Docs: shadow_standing.rs, WorkCounts, docs/API.md (the log), env_vars REGISTRY; the artifact
  test's note on the variables the runtime reads. api_signatures blessed.

No behaviour changes: counts and a default-off log only. RUNTIME_VERSION not bumped (main's).

Verified: cargo fmt; builds and tests run as potluck jobs after this commit.
(cherry picked from commit a82491daf4a24ad57845c6e0f62bd53946dc22f8)
2026-11-08 12:18:18 -08:00
Anees Iqbal 8e1383b1b6 In-place check: an unchecked verdict whose cause lasts is kept; one that may pass is checked again
The previous commit kept every unchecked verdict out of the record, so a driver that truly
lacks what a class needs (an extension, a feature, an import, a format or an image of the
shape, such as lavapipe's DmaBuf and Pooled rows-in-lines, which RuntimeDriverDefect::
ExplicitPlaneRowsPastHeight refuses) would be checked again by every device. Such a cause is
fixed for the driver's identity, as stable as a passed or failed verdict, so it is kept; only an
unchecked verdict from a cause that can change between runs is kept unmeasured and checked
again.

- in_place_check::Unmade: the reason the check made no pages, pass or image, and whether its
  cause lasts. ClassPages::make, ExportedPages::make and Round::NotMade carry it.
  Lasting: no host import (VK_EXT_external_memory_host), no dma-buf images, export only as a
  dedicated allocation, no host-visible coherent type, no DRM_FORMAT_MOD_LINEAR images, and a
  placement answer the image's making decides before it binds (Refused Rows, Image, Pitch,
  Placement, DmaBuf; another route of the shape), and an error that is the device's gap or
  Metal's refusal (Error::Unsupported, Error::Invalid).
  May pass: pages, memory or mappings not made, an export failing, a no-copy buffer copied or
  imported otherwise on a device that imports host memory, an answer in place that only the
  bind refused (the dma-buf's import), detached or sourceless pages, the writer thread not
  started, a first move, pass or kernel's stores failing, the kernel's buffers refused, any
  other error (out of memory, a lost device, a Vulkan failure, the runtime's own gap).
- check_class answers, by row ends, whether an unchecked verdict met a cause that may pass;
  run writes those verdicts pending in the record and the rest as given. encode writes the
  verdicts as given; decode reads every verdict byte (unchecked among them).
- Notes say which cause it was, "(a cause that lasts, kept)" or "(a cause that may pass,
  checked again)": the first of each kind per class and access.
- CHECK_VERSION stays 12 (the bump the previous commit made, not landed): a record of 11 may
  hold unchecked verdicts whose cause may pass, which no device takes now.
- Tests: an_unchecked_verdict_is_checked_again_where_its_cause_may_pass_and_kept_where_it_lasts
  (device test, replacing the previous one: the pointer class's failed import is noted as a
  cause that may pass and checked again by the next device; every measured verdict is recalled,
  each unchecked one recalled unchecked or checked again; on a driver with
  ExplicitPlaneRowsPastHeight the DmaBuf reads of rows inside lines are recalled unchecked).
  The record round trip holds passed, failed, unchecked and pending verdicts. The in-place
  textures lane's record test takes measured <= recalled <= VERDICTS.
  narrow_writes_device and freed_memory read only the report's verdict lines, not the notes
  after them (20 narrow lines counted where 16 were due on lavapipe, job 9303).
- Docs: in_place.rs, in_place_check.rs, WorkCounts::in_place_checks_recalled,
  settle_in_place_checks, docs/API.md, docs/FAST-PATHS.md (the in-place row).

Verified: cargo fmt; builds and tests run as potluck jobs after this commit.
(cherry picked from commit b420f97f56237fc0bf153691e9ac7e5a8e923386)
2026-11-08 12:15:38 -08:00
Anees Iqbal aa188702ad In-place check: an unchecked verdict is no measurement, kept unmeasured and checked again
On the Iris Xe (ANV) reims' arm-s boots made 890 shadows over guest RAM imported as dma-bufs,
every one "the device's check made no image over host pages imported as dma-bufs" (Unchecked),
small ShaderRead textures at offset 0 on whole pages among them, where a fresh check of the
same driver passes the class's reads (aafecf768a, job 7667). The record kept every verdict the
check gave, Unchecked among them, and every later device of that driver and check version
recalled it and checked nothing: a refusal of the class's pages (or of its rounds' images) in
one process, a transient one or one of that device's setup, answered for every boot after.
And the check kept no reason for it: the class's pages and rounds that made no image returned
unchecked with no note.

- in_place::encode writes an unchecked verdict as unmeasured (a pending verdict's byte);
  decode reads that back pending and refuses an unchecked byte (never written).
  recall_in_place_checks recalls the measured verdicts (passed or failed, counted as recalled)
  and settles only where none is pending: the first texture that asks a pending one starts the
  check, which runs only the classes and accesses still pending, and its record replaces the
  old one.
- CHECK_VERSION 12: a record of 11 may hold unchecked verdicts as answers, which no device now
  takes; reims' stale records are dropped by it.
- Reasons, noted in the check's report after the verdicts: ClassPages::make answers why it made
  no pages (each step of ExportedPages::make for the dma-buf class: no host import, no dma-buf
  images, an export only as a dedicated allocation, no host-visible coherent type, the
  allocation, map or export failing; a no-copy buffer refused, copied, or imported otherwise),
  and a round that made no image says why (its making's error, the placement's answer for a
  texture not in place, its first move or pass failing), the first per class and access.
- Tests: a_class_whose_pages_the_check_could_not_make_is_checked_again_by_the_next_device
  (device test: the pointer class's first import fails, so its reads are Unchecked and noted; the
  next device of the cache recalls every measured verdict, finds those reads pending, checks
  them again; the device after recalls them). Before this change the second device recalled the
  reads as Unchecked. The record round trip reads unchecked back pending; the in-place textures
  lane's record test recalls the measured verdicts and checks the rest again.
- Docs: in_place.rs, in_place_check.rs, WorkCounts::in_place_checks_recalled,
  settle_in_place_checks, docs/API.md, docs/FAST-PATHS.md (the in-place row).

Verified: cargo fmt; builds and tests run as potluck jobs after this commit.
(cherry picked from commit 29f3114ca990382776e795f35ea9b81f8345399a)
2026-11-08 12:15:38 -08:00
Anees Iqbal a3fb1283e6 FAST-PATHS: the first clip's allocations stay open, with their cause and why no block is made ahead
(cherry picked from commit 4d2833ae3d662006101e3be98bfba4c7da58603e)
2026-11-08 11:49:37 -08:00
Anees Iqbal 186d327fe7 Memory: kept blocks past their quiet period go within a second at the next creation call; FAST-PATHS records the kept memory
A kept empty block was looked at only when a release came in its own pool, so a
pool whose resources stopped coming and going kept its blocks, up to its heap's
budget, until its next release. The device's creation calls (keep_room) now
also free every pool's kept blocks past KEPT_EMPTY_FOR, at most once every
KEPT_SWEEP_EVERY (1 s): the memory is held at most about 11 s past a working
set's dip wherever the program still makes resources.

docs/FAST-PATHS.md, known gaps: the NVIDIA memory block row, with the bound
(an eighth of a heap, at most 2 GiB, 10 s), what it holds per device, why it
has no switch (no answer of Metal's changes), and the RTX 5080 measurement of
tests::clip_bursts (poolwait-burst, NVIDIA 615.71.09, two runs each): clips 2
and 3 took 41 and 40 allocations and 89 to 102 ms with 2 to 5 commits held
1 ms or more (longest 8.8 to 9.4 ms) before, none and 64 to 71 ms with no
commit held (longest 0.39 to 0.67 ms) after; a first clip 44 allocations
before, 16 after.

Not yet built: the sweep builds and runs next on lavapipe.

(cherry picked from commit b31e221ee4cfba1861320e8c674a01ea83614013)
2026-11-08 11:49:37 -08:00
Anees Iqbal 1c14b4b44a Staged gathers take their staging at their host step, not on the calling thread
A gather staged through the CPU (31e642ecc2) took its region of the
command buffer's arena on the encoding thread. A region over 32 KiB is a
chunk of its own: fresh pages imported by pointer on NVIDIA, about 2.3 ms
plus 0.25 ms/MiB, and more where the import thread allocates at the same
time. On the RTX 5080 the contended fill bench's first call took
52.8 ms, of which checks, pieces and the staging decision were 0.3 ms.

The gather is now a Deferred::GatherStage whose batch's host step does
all of its work: it takes the region, fills it by the CPU from the
pages, and records the vkCmdCopyBuffer into the buffer at the copy's
place. Like the staged scatter's GPU copy, it is recorded at its step
(records_at_its_step). Its uses are noted at the call. It still waits
for the work before it where the GPU may write the pages
(Deferred::steps_after_the_gpu_now, read by step_waits).

StagedFill becomes StagedGather. The command buffer's staged list,
staged_unfilled, fill_staged and State::next_encoder go: segments
carry it all now.

A rebind's encoding again replaces a staged gather's segment with a copy
through the imports: Segment::records_again and splice_replay take it
(recorded_by_an_encoding_again). So an encoder with a staged gather
keeps its log, as before.

Tests (host_ram_copy_device, device tests):
- Every staged copy test asserts that the encoding took no staging of
  the arena (Uploads::bytes below the copy's bytes).
- a_rebind_before_the_first_submission_encodes_a_staged_gather_s_encoder_again:
  a staged gather and a fill of a no-copy buffer over a page outside the
  RAM, in one encoder behind an event wait. The buffer is rebound after
  the commit. The command buffer completes with no error, the encoder
  encoded again once, the fill lands in the new page, and the gather's
  bytes are in its buffer.

Not yet verified; the gem10 checks follow this commit.

(cherry picked from commit 0f60b71653f9f7dfe9eaba18976c21eb75dd696d)
2026-11-08 11:44:50 -08:00
Anees Iqbal 0d65ab5579 Staged scatters: a first scatter into guest RAM makes no import or memory on the calling thread
A copy_to_host_ram over a chunk not yet imported used to import on the
encoding thread. With 16 ranges or fewer it imported those ranges alone
(each import about 2.3 ms on NVIDIA, its pages pinned). With more, it
imported the whole chunk or waited for its import. A clip switch's
block release (a device cache scattered to fresh guest pages) paid this
on the guest's command thread.

Such a scatter is now staged through the CPU, on devices whose thread
imports ahead (plans other than Plan::listed), as gathers are since
31e642ecc2. It leaves its work to two host steps, as two new Deferred
kinds:
- ScatterStage: the host step of the copy's batch waits for no GPU
  work (Deferred::records_at_its_step, which Segment::needs_step and
  known_summary take). It takes a region of the command buffer's arena
  and records one vkCmdCopyBuffer of the bytes the runs cover into it,
  at the copy's place in the encoder. The region's memory is made on
  neither the encoding nor the committing thread (commit_and_submit).
- ScatterDrain: gpu_written, so the rest goes in a part and batch of
  its own. Its host step waits until every VkQueue completed what was
  submitted before it, then copies each run's bytes from the region
  into the pages in run order (a host byte named twice keeps the
  later's), before that batch is submitted. So the pages hold the bytes
  once the command buffer completed, and every later command sees them.
The buffer's read is noted where the GPU copy lies. The chunk keys'
writes are noted at the start of the drain's part, so hazard tracking
orders later readers of those host bytes after the CPU's write, and
the RAM's log hears of them as of a copy through the imports. Each
chunk is taken and asked of the import thread, as a staged gather's is.

An encoder that holds a staged scatter keeps no replay log
(Unlogged::Segments). A rebind before first submission of a buffer
over host pages that the same encoder named fails that submission
with EncodedUseRebound. The HOWTO says so.

Counted:
- WorkCounts::host_ram_scatters_staged
- WorkCounts::host_ram_staged_drain_nanos
Upload::copy_out reads a region back.
host_ram_block_release_bench prints both.

Tests (host_ram_copy_device, device tests):
- a_first_scatter_over_chunks_the_thread_imports_is_in_its_pages_once_it_completes:
  40 single pages over two chunks not imported, one page named twice,
  from a Private buffer the GPU wrote just before in the same encoder.
  At encode: staged 1, no run import, no chunk imported by a copy, no
  import wait. At completion: the pages hold the bytes (the later's for
  the page named twice), the page beside them is untouched, and a
  buffer over one page reads them in a later encoder and in another
  queue's command buffer committed after.
- a_first_scatter_of_few_ranges_imports_nothing_on_the_encoding_thread:
  four pages over two chunks, which the old path imported as ranges
  alone. At encode: no run import made. The thread then imports exactly
  the two chunks, and the next scatter goes through their imports.
- The window test's scatter past the window is now staged: no copy
  import, the thread imports its chunk.

Not yet verified; the gem10 checks follow this commit.

(cherry picked from commit 93965ee58ed9b238084696fa80b910745d6dc281)
2026-11-08 11:12:40 -08:00
Anees Iqbal 6f702cb76a docs/API.md: an exit mid-making, the difference left
What: the accepted differences' "Process exit" names what the exit hook's registrar leaves: a
making on the program's own thread, which the exit does not wait for, and destructors the
driver's compiler registered in the last 2 ms before the exit (or past the registrar's 16384
registrations), which can run beside the compile, where Metal compiles in another process.

Why: the registrar (RUNTIME_VERSION 1899) closed the rest of exit_guard's hole for makings on the
runtime's threads; what is still open is a consumer-visible difference, and one such exit (a
consumer's making thread left running) ended its process with SIGSEGV inside NVIDIA's SPIR-V
compiler on the RTX 5080.

How verified: docs only; the figures are exit_guard's MAKING_INTERVAL and MAKING_REGISTRATIONS.

(cherry picked from commit 5f1846a295017a2244fde27cdd2ed3db97bdb9cb)
2026-11-08 09:58:54 -08:00
Anees Iqbal 48cfac5cb3 HostRam lists kept: the docs say the lists outlive their copies, with same-host numbers
HOWTO, the runtime README and FAST-PATHS still said a copy's lists were
freed with its command buffer and that every copy pays its lists'
imports. They now say each list is kept past its copy for the copies of
the same pages after it (at most 64 MiB and 16 lists, released once no
copy took one for 2 s), and they give the numbers.

The numbers come from tests/host_ram_listed_bench.rs on the Radeon 780M
of one host (um790, RADV, kernel 7.3.1). The kept tip was run with a
timing probe that never lands, then again with the bound sabotaged to
(0, 0), which keeps nothing, back to back. Medians are commit to
completion, then encode:
- A 5 MiB device cache filled again: 0.37 to 0.43 ms and 0.2 to 0.4 ms,
  against 3.0 to 3.2 ms and 0.7 to 1.0 ms with no list kept. Over an
  imported chunk it takes 0.37 to 0.40 ms and 0.12 to 0.14 ms.
- A surface-shaped tile's download after its fill: 0.53 to 0.60 ms,
  against 4.0 to 4.2 ms.
- A scattered tile's download: 0.46 to 0.50 ms, against 0.98 to 1.04 ms.
- A copy that imports pays the lookup through the kept lists: 48 to
  63 us for a surface tile, 250 to 290 us for 1,800 scattered runs
  against 16 lists.
- The scroll's 24 visible tiles pass the 64 MiB bound (about nine
  tiles), so a third to a half of their repeated fills took a kept list.
- Residency is the same with and without kept lists: 4028 of 8192 MiB,
  and 8300 of 16384 MiB.

(cherry picked from commit ee030ba7ed497aeb4bf0c92653cc33078e987379)
2026-11-08 09:42:35 -08:00