Commit Graph
224 Commits
Author SHA1 Message Date
Anees Iqbal 48ec97832d Take new textures' pattern reads at the commit, in commit order, not as encoded
What: a command buffer now logs its commands' reads and writes of noted new textures
(`fresh_unwritten.rs`'s FreshLog: pass loads, clears, resolves, blit writes and reads, shader
reads, and a pass's load of a signed-depth pattern) in encode order, and its commit replays the
log against the device's record under one lock, before the scheduler sees it, announcing
`fresh-pattern-zeroed`, `device-nan-encoding` (a fresh texture's converted NaNs) and
`signed-depth-test` (a loaded signed-NaN depth pattern) there. A command buffer dropped
uncommitted takes nothing; a refused commit's log is discarded. With no noted texture a command
reads one flag and logs nothing, and a commit reads it once.

Why: the record followed encode order, so a queue's command buffers encoded out of commit order
(the consumer's host encodes one queue on several threads, then commits in order) announced a
read Metal never makes (a load after a committed-earlier clear, encoded first: a precision note
the consumer makes fatal) and missed one it makes (a load before a committed-later clear, encoded
after it: the texture read zero where Metal reads its pattern, unannounced). Metal runs a queue's
command buffers in commit order.

Tests: runtime_lane::parallel_encodes::a_fresh_texture_s_pattern_notice_follows_the_commit_order
runs two command buffers of depth-only passes (4-sample and single-sample Depth32Float,
clear-then-load and load-then-clear) serially and with the later-committed one encoded whole
first on another thread, and requires the same notices both ways and Metal's reads of the
pattern. Before the fix it failed on the M3 Max (MoltenVK 1.4.2): 1 notice instead of 0, and 0
instead of 1. The same module's a_shadowed_texture_keeps_each_command_buffer_s_bytes (a texture
over a Private buffer at 48-byte rows, eight command buffers on four threads) checks every
copy and read against its own command buffer's words and prints the copies in.

Docs: fresh_unwritten.rs's Observed and Order bullets, the FreshPatternZeroed and SignedDepthTest
declarations, docs/API.md's catalogue entries.

Verified on the M3 Max under --cfg m2v_gpu: the new test passes; so do runtime_lane's
fresh_writes, fresh_contents, depth_denormals, degrade_notices, made_at_creation, texture_blits,
renders, sample_copies, nan_resolves, buffer_depth_samples, compressed_blits, color_fills,
color_writes, cross_class_storage and half_* modules, and the runtime's tests::fresh_unwritten
and tests::heap_tiled (118 tests); degradation_catalogue passes. clippy -D warnings clean for the
runtime crate (plain).

(cherry picked from commit 95d7bdf6dc8c6e411114b2d9a8203ea1e4970168)
2026-11-02 23:52:36 -08:00
Anees Iqbal 91cdb80938 Say what a YCbCr twin's half sample through a runtime sampler slot rounds to: measured toward zero
What: PrecisionNote::HalfTexelConversion's doc, its docs/API.md catalogue entry, docs/FAST-PATHS.md's
texel-conversion row and the comment where select.rs records the note said a two-plane YCbCr
texture on the grid 8192, sampled through a runtime sampler slot whose word reads one texel,
rounds that texel's step to nearest even. It is the device's rounding of the step's float, and
on MoltenVK 1.4.2 over the Apple M3 Max that is toward zero: runtime_lane::ycbcr_textures'
srgb_twins_read_what_metal_reads measured 8,409 channels of the _sRGB twins over six surfaces and
three matrices, each within one half ulp of Metal's ties-away step (lane commit 196bdf8135). The
docs now say so, and that other Apple GPUs are unmeasured. FAST-PATHS' row had said the field keeps
Metal's ties away in every one-texel sample; it now names the runtime sampler slot's exception.

Docs only: no behaviour, translation or recorded output changes.

(cherry picked from commit 0cb807cc9d0af60d7ceebbbd536d396ab43e3a00)
2026-11-02 17:43:39 -08:00
Anees Iqbal 4837c93ca4 Announce decoded-texel-precision at the decoded twin's first read, not at its texture's making
What: a decoded twin whose texels are not Metal's decode exactly (an ASTC LDR form's 8-bit codes,
an EAC 11-bit format's 16-bit codes, a 4:2:2 texture's device conversion) announced
decoded-texel-precision where its texture was made, though only a sampled view reads the twin:
copies, blits, fills and CPU accesses move the carrier's blocks. A consumer that makes notes fatal
died on a test that only fills a BGRG422 texture and on one that checks the runtime's fills.

How: the twin carries what a read of it announces (TwinRead, made with the twin and with an ASTC
carrier's second twin). It is announced, once per device, where a command may first read it:
- Texture::bound_view, a command's sampled binding of the texture or a view of it: the set-0 slot
  path (slot_view, draws, dispatches, tile dispatches) and a heap entry a command names
  (binding.rs);
- heap_sets::bind, the first command that binds a heap set holding the twin's view, named or not
  (each set keeps its twins by resource ID beside its shadows);
- a twin's placement into a heap set whose shared version a command buffer that bound it and has
  not completed still holds, or whose own version an uncommitted command buffer bound
  (SetEntry::twin), announced once whatever announce_each says, as a submission may place it on a
  runtime thread.
Placing the view in a heap set uses Texture::held_view, which announces nothing.
carried-decoded-twin (performance) is still announced where the texture is made.

Docs: degradation.rs's contract, docs/API.md's catalogue entry and docs/FAST-PATHS.md's ASTC and
4:2:2 rows say where it is announced; texture/decoded_twin.rs's and heap_sets.rs's module docs gain
the reads. Lanes: texture_fills and texture_blits' mipmaps no longer expect the note at making
(twins_carried keeps its carried half alone). Conformance: the allowances of cases that read no
twin (texture-fills, chroma-pair copies, texture-pairs-usage-crossings, format footprints) no
longer name decoded-texel-precision; the reads' and samples' keep it.

Test: tests::twin_reads walks every route on a device of its own (ASTC_4x2_LDR on every device,
BGRG422 and GBGR422 where the device converts them): made, written by replace_region and blits,
filled, copied and read back announces no decoded-texel-precision; the route's first read
(slot read, sample, gather, a view's read, a heap read named and unnamed) announces it once; a
twin placed in a set a pending command buffer bound announces as it is made; an ASTC sRGB twin
announces nothing and its LDR view's second twin announces at the view's first read.

Verified at this commit: tests::twin_reads (3 tests) and ycbcr_device's 4:2:2 test pass on this M3
Max (MoltenVK 1.4.2, --cfg m2v_gpu), walking ASTC4x2LDR, BGRG422 and GBGR422.

(cherry picked from commit 37f72d3ffb402ad9afae9571489edbf2b8157442)
2026-11-02 17:43:39 -08:00
Anees Iqbal 763965c854 Record a texture write's NaN encoding only where its stored NaN is not measured to be Metal's
reims-vgpu treats precision notes as fatal on Apple GPUs. A kernel's write of halves into a
32-bit float or RG11B10Float texture died with DeviceNanEncoding, and through NativeNanEncoding,
on the M3 Max where the stored bytes are Metal's; a write of a constant texel with no NaN died
the same way on every device.

What:
- A new DriverDeviation::MetalSmallFloatNans (VkProperty::MetalSmallFloatNans), taken by the
  APPLE9 MoltenVK row alone: the device stores a float's or a half's NaN written to a
  B10G11R11_UFLOAT_PACK32 storage image as Metal does.
- half_write_nans (a half texel's write) classifies the slot's storage choice: a 16-bit float
  format takes MetalHalfTexelWrites as before, a 32-bit float one MetalNanMoves (the widened
  half's bits are Metal's 0x7fc00000), the packed small float one MetalSmallFloatNans; a taken
  deviation drops the note and requires its property. A slot declared without a format (every
  float storage choice on MoltenVK and lavapipe) records the note under the bound format's class
  (a SpecializedNote of BoundTexelFormat), one clause per class the profile does not cover, so
  the runtime announces it only when such a texture is bound.
- half_storage_facts (a float texel's write) drops the small-float note the same way.
- A texture write of a constant texel none of whose lanes is a NaN records neither note.
- A new module side table, stored_texels, records each texture-family write's texel (kept
  through edit.rs's retain and the roll pass's check). narrow::moves_unfolded no longer counts a
  widened half's store as such a texel as an escape: the write's own DeviceNanEncoding accounts
  for its stored NaN under the format it stores.

Verified on this M3 Max, byte for byte against plain Metal (an MSL probe): a float4 write of
33,792 words (16,446 NaNs) and a half4 write of all 65,536 halves (2,046 NaNs) into RG11B10Float,
RGBA32Float, RG32Float and R32Float store Metal's bytes; into R16Float and RGBA16Float a half
NaN's payload differs (the device stores 0x7e00), so those keep the note.
- runtime_lane::half_write_nans on MoltenVK: half writes into rgba32f, r32f and rg11b10f announce
  nothing and 0 texels differ; rgba16f announces device-nan-encoding (2,045 NaNs differ). Without
  note_stored_texel the lane fails ("write r32f: ... native-nan-encoding true").
- New core tests: a_half_texel_write_s_nan_into_wide_and_small_float_images_is_metal_s_where_
  measured (declared and formatless choices on moltenvk-m3 with and without each deviation, and
  lavapipe; the bound-class clauses evaluated per format) and a_constant_texel_without_a_nan_
  records_no_nan_encoding (zero and 0x7e00 constants, every committed profile); the existing
  device-nan-encoding and half-storage-notes tests follow the deviations. Each fails with its
  change disabled (the NaN test forced true; the stored-texel exemption removed).
- Notes of every public fixture on moltenvk-m3, lavapipe and nvidia-rtx5080-laptop before and
  after: DeviceNanEncoding leaves 65 moltenvk-m3 rows and 6 rows on each other profile (constant
  texels), 17 formatless rows per profile go from unconditional to specialized by bound format,
  58 moltenvk-m3 rows lose their small-float clause, NativeNanEncoding leaves 11 moltenvk-m3 rows,
  and no row gains a note. Consumer AIR on moltenvk-m3: DeviceNanEncoding 33 entries to 21,
  NativeNanEncoding 9 to 5.

Docs: API.md (device-nan-encoding and native-nan-encoding exemptions), HOWTO.md, the
PrecisionNote, VkProperty and deviation rustdoc, the driver-facts measurement record.
api_signatures gains the two variants. The versions bumped in the previous commit cover this one.

(cherry picked from commit 05d96c61107989813c186961087ee70d573cf876)
2026-11-02 16:41:46 -08:00
Anees Iqbal 217cc233f5 Carve MoltenVK on the M3 Max's identity out of NativeHalfConversion for measured conversions
reims-vgpu treats precision notes as fatal on Apple GPUs; NativeHalfConversion was its largest
group of Mac-only failures (37 tests). The note says a half rounded through the device's
conversion to 16 bits and back may differ from Metal's. On the M3 Max (MoltenVK 1.4.2, macOS
27.0.1), MoltenVK writes OpFConvert to 16 bits as MSL half(x), which is Metal's half(float), and
Metal's compiler folds the conversion of an image instruction's float texel into the access.

What: a new DriverDeviation::MetalHalfConversion (VkProperty::MetalHalfConversion), taken by the
APPLE9 MoltenVK row alone. Where the profile takes it:
- narrow::round_measured rounds a float the function holds (an AIR fptrunc or air.convert from
  float, through resize) by the conversion pair and records the pair's narrowing in a new module
  side table, measured_roundings (kept through edit.rs's retain and the roll pass's check);
- narrow::rounds_unmeasured finds any other conversion pair: one neither recorded nor of a texel
  an image read, fetch, sample or gather hands back (directly, through a composite extract, or
  through a parameter every call passes such a texel);
- the compile records NativeHalfConversion only where such an unmeasured pair exists, and
  otherwise requires the property.
A half operation or function computed in float and rounded keeps the note: Metal's half tanh
answers 7 of the 65,536 halves otherwise than the conversion of its float tanh. exp, sqrt and a
reciprocal on half matched, but they are functions, not the conversion, so they stay noted.

Verified on this M3 Max, word for word against plain Metal (an MSL probe, fast and safe math):
- the conversion of a float loaded (425,216 words), of a sum, product and quotient (144,896
  pairs each), of an fma (123,648) and of an integer's quotient (190,208): 0 words differ;
- the half result of read, nearest sample at the centre, linear sample a quarter texel off and
  gather of every texel of ten formats (RGBA32Float, RGBA16Float, RGBA8Unorm and its sRGB twin,
  RGBA8Snorm, RGBA16Unorm, RGBA16Snorm, RGB10A2Unorm, RG11B10Float, RGB9E5Float): 0 differ.
- New lane runtime_lane::half_conversions on MoltenVK: load, sum, product and fma kernels carry
  no note and 0 of 253,958 lanes per kernel differ from the half model; the half tanh kernel
  keeps the note. With measured_conversion forced false the lane fails.
- New core test half_conversions_are_metals_where_measured: the four forms lose the note and
  require the property on moltenvk-m3 with the deviation, keep it without the deviation, and the
  half tanh keeps it on both; it fails with the carve disabled.
- Notes of every public fixture on moltenvk-m3, lavapipe and nvidia-rtx5080-laptop before and
  after: NativeHalfConversion leaves 58 moltenvk-m3 rows, and no row gains a note. Consumer AIR on
  moltenvk-m3: 23 entries noted before, 2 after (a heap texture's held half read).

Docs: API.md (native-half-conversion exemption), HOWTO.md, the PrecisionNote, VkProperty and
deviation rustdoc, the driver-facts measurement record. SEMANTICS_VERSION 1949 and
ARTIFACT_FORMAT_VERSION 484 (new VkProperty variants in the codec); these bumps cover the rest of
this branch. api_signatures gains the two variants.

(cherry picked from commit 266f7cd26327e408d9cd1f0d6ea5ba33e49e10b3)
2026-11-02 16:41:46 -08:00
Anees Iqbal 4b194d24af Write Metal's encoding through compressed BGRA10_XR blits under an exact-answers switch
What: a new DevicePolicy switch, `extended_range_blits` (ExtendedRangeBlitPolicy::Kept, the
default, and ::Canonical, which `exact_answers()` selects). Under Canonical a blit or fill through a
BGRA10_XR or BGRA10_XR_sRGB texture Metal keeps losslessly compressed writes Metal's canonical
encoding: each 16-bit field's low six bits cleared and, for a blit, the alpha code clamped to
[384, 894].
- bind::extended_canonical_module, a compute kernel that rewrites a texel range's words in place
  (bind/extended_canonical.rs, with extended_range_canonical as its reference and interpreter
  tests); the runtime owns it as OwnedModule::ExtendedCanonical.
- The runtime (extended_canonical.rs): after a blit into such a texture, or out of one into another
  texture of the format, the written regions go out to a scratch buffer, one dispatch per region
  rewrites them, and they go back; after a blit out of one into a buffer, or into a texture over a
  buffer's bytes, one dispatch rewrites the words in place at the layout's rows. A fill's texel is
  encoded before it is written (fills clear the low bits alone: Metal's fill keeps alpha codes 4
  and 1023 on the M3 Max under 27.0.1). A buffer the device cannot bind (offset or pitch off 4,
  past maxStorageBufferRange) or a texture over a buffer whose rows share bytes keeps the bytes and
  announces extended-range-bits-kept, as under Kept. Under Canonical the note is not announced for
  the blits it makes exact.
- copy_from_buffer_to_texture's body moved into buffer_into_texture, which a fill's row copies call
  with Writer::Fill (so a fill announces its own wording and is never rewritten as a blit).

Why: Metal's GPU blits through the compression rewrite these bits (measured on the M3 Max under
macOS 27.0.1, plain Metal, xr_matrix: compression iff allowGPUOptimizedContents, shorter side >= 16,
neither ShaderWrite nor PixelFormatView usage; every storage mode alike; CPU copies keep the bytes;
fills clear the low six bits only). The device's copy keeps the bytes. It is the runtime's choice,
not a native answer (no device arithmetic is involved: a copy's bytes), so per rule 1 the fast form
stays the default and the exact form is the switch.

Ledger: FAST-PATHS row (fast defaults), API.md section 1 bullet and the extended-range-bits-kept
catalogue entry, the Degradation doc, the conformance Policy doc. Known gaps: the 28 rows of
compressed-blits-bgra10xr and -srgb (7 sites x 2 formats x Apple M3 Max and llvmpipe) dropped:
under the suite's exact policy those sites now hold Metal's bytes.
RUNTIME_VERSION 1728 -> 1731 (a run under the exact policy writes other bytes).

Also fixes forward a clippy needless borrow in engine_arith's pack test (7a99b93af2).

Verified (M3 Max, macOS 27.0.1, MoltenVK 1.4.2; and lavapipe in scripts/linux-gate, arm64,
LLVM 21.1.8 128 bits):
- runtime_lane::compressed_blits on MoltenVK: both tests pass; the new
  extended_range_blits_write_metal_s_encoding_under_the_canonical_policy checks every direction,
  level 3 into padded rows, Shared CPU/blit mixes, texture to texture both ways, a fill of a
  compressed and a plain texture, and a copy into a texture over a buffer with padded rows, under
  both values (Canonical: Metal's bytes and no notice; Kept: the bytes and the notice once).
- conformance replay of the four compressed-blits cases on MoltenVK: exit 0, the ledger as
  edited (bgra10xr and -srgb `announced` only for staged-texture-copy/shadowed-texture).
- the full `conformance replay --cpu` on lavapipe at 68074019a3 and at this change: the only
  difference is the 14 llvmpipe sites of the two XR cases, which no longer diverge (divergent
  244 -> 242, exact 458 -> 460); the 265 other ledger mismatches of that arm64 venue are the same
  at both (it is not CI's amd64 lavapipe).
- 154 touched validation lanes on MoltenVK (blits, fills, extended-range, NaN, pack, padded,
  rotated, no-copy, two-plane heap): 143 passed, 10 failed, 1 ignored; the same 10 fail with the
  same messages and the same differing texels at 68074019a3 (pre-existing).

(cherry picked from commit 612ff50b86bc29515b158d9b2596b14a45431467)
2026-11-02 13:13:17 -08:00
Anees Iqbal 452c17aa2c Carve MoltenVK on the M3 Max's identity out of DevicePackConversion for the measured forms
reims-vgpu treats precision notes as fatal on Apple GPUs. On the M3 Max (MoltenVK 1.4.2, macOS
27.0.1) the module's air.pack/air.unpack of rgb565 in float, and in half of unorm4x8, snorm4x8,
unorm.rgb10a2 and unorm.rgb565 (both ways) and unorm2x16 and snorm2x16 (packed), answer Metal's
words, so DevicePackConversion was recorded where nothing differs.

What: DriverDeviation::MetalPackConversions (VkProperty::MetalPackConversions), taken by the
APPLE9 MoltenVK row alone. Where taken, select_pack records no note for a form
lower::arith::pack::measured names and the module requires the property
(ArithPlan::metal_packs). The lowering is unchanged on every profile. Kept noted, with the inputs
that differ (probe over the same inputs, fast and precise math): the sRGB format (85,511 of
3,083,776 float packs, 3,286 of 65,536 half packs, every unpack), unorm.rgb10a2 in float (9,163
of 131,072 unpacked words, 1,257 packed floats), the half unpacks of unorm2x16/snorm2x16 (8
lanes: our float quotient rounded twice), and snorm.rgb10a2 (unmeasured).

Docs: Metal's float rgb565 measured to round the product to float first (the exact-product model
misses 55 of the tie set) and to unpack by the float reciprocal; the artifact rustdoc and API.md
said Metal rounds the exact product and divides correctly rounded for every format, now
qualified for rgb565 in float.

Verified (all on this M3 Max):
- Plain Metal running runtime_lane::pack_conversions' own AIR (12 kernels: every code of every
  field, every half in every channel, 68,672 float words incl. 33 around each 5/6-bit tie):
  the lane's model matches Metal in every word.
- runtime_lane::pack_conversions on MoltenVK: no kernel records the note, 0 inputs differ.
- tests::engine_arith::pack_conversions_are_metals_where_measured: all 32 normalized forms on
  lavapipe and moltenvk-m3 (note and property per form); it fails without the deviation row
  (its takes == moltenvk-m3 assertion) and without the select_pack change (the note).
- Focused core run (engine_arith, driver_facts, fast_paths, golden, api_signatures, pack,
  engine_tile, engine_texture): 197 passed.

Also: drops an unused binding the NaN-moves commit left in engine_native_half. The NaN-moves
commit's message gives SEMANTICS_VERSION 1946; since the rebase onto 68074019a3 it is 1948
(ARTIFACT_FORMAT_VERSION 483), which covers this commit too. FAST-PATHS row for air.pack updated.
api_signatures blessed (two variants); golden hashes re-blessed (the moltenvk-m3 profile).

(cherry picked from commit b344f5e515e5b1c586877ca45fedead512ea0ad2)
2026-11-02 13:13:17 -08:00
Anees Iqbal 3e28f68331 Carve MoltenVK on the M3 Max's identity out of NativeNanEncoding for NaN moves
reims-vgpu treats precision notes as fatal on Apple GPUs; NativeNanEncoding was its largest
group of Mac-only failures. Measured on the M3 Max (MoltenVK 1.4.2, macOS 27.0.1), the device's
widening of a half to float, its narrowing back, and float fneg/fabs and half fabs answer
Metal's NaN bits, so the note was recorded where nothing differs.

What: a new DriverDeviation::MetalNanMoves (VkProperty::MetalNanMoves), taken by the APPLE9
MoltenVK row alone. Where taken:
- a float fneg or fabs records no NativeNanEncoding and the module requires the property
  (SPIRV-Cross writes -x and abs(x), Metal's own operators on the same operand);
- a half's widening to float (fpext, air.convert) and a half fabs, and a module's reads and
  encodes of a half's bits, record no note and require the property, but only where the module
  moves its halves through the registers as measured. narrow::moves_unfolded keeps the note
  where a widened half is stored anywhere but a buffer, workgroup memory or a function's float
  variable, passes through a call, return, group, atomic or image operation, has its bits read
  (a bitcast that is not stored, frexp/modf/ldexp: the frexp routines stay noted), or where the
  module holds a float NaN constant other than 0x7fc00000.
- A half fneg stays noted on every profile: the measured shapes matched only because the
  driver's compiler moved the negation onto the half.

By construction: MoltenVK's MSL writes float(as_type<half>(x)) and half(f); Metal's compiler
folds half(float(h)) across selects, phis and a function's local float variable, so moved
halves keep their bits as Metal's do.

Verified (all runs on this M3 Max):
- Plain Metal running the lane's own AIR (8 kernels; every one of the 65,536 half patterns,
  98,368 float words including 65,536 structured NaNs) matches the lane's model in every word.
- runtime_lane::nan_moves on MoltenVK: the note is absent from every kernel but the half fneg,
  and 0 lanes differ from Metal in all 8 kernels.
- Earlier MSL probe, fast and precise math: the same equalities over 262,144 float words.
- New core tests: half_moves_are_metals_only_where_the_device_folds_them (a payload NaN
  constant keeps the note), the frexp negative control in engine_metal_routines,
  float_sign_operations and the class C/D NaN tests with a moves argument, and the driver-facts
  lists.
- Core nextest (metal2vulkan, air, runtime, devtools, --all-features): 4,989 passed.

Docs: API.md (native-nan-encoding exemption), HOWTO.md, the PrecisionNote and deviation rustdoc.
SEMANTICS_VERSION 1946, ARTIFACT_FORMAT_VERSION 483 (a new VkProperty in the codec); these
bumps cover the rest of this branch. api_signatures blessed (two variants); the moltenvk-m3
profile's golden hash re-blessed.

(cherry picked from commit 93ae66b6ddb46b4d0d3db1944a4b043c40911592)
(Note on the development copy: this message names SEMANTICS_VERSION 1946; the commit sets 1948, after a rebase.)
2026-11-02 13:13:17 -08:00
Anees Iqbal b0bed82331 Record a pixel sample's centre denormals only where its centre can run
ed08da17f6's pixel-sampler fix recorded PrecisionNote::DeviceDenormals
unconditionally for every texel-centre position, TexelBySpec and
TexelByWord included. Those two are the runtime slot's and the argument
buffer's samples, whose centre `floor(x) + 0.5` sits behind the
NearestPixelSampler specialization or the table word's test: code that
no normalized state reaches. So every stage that samples through a
runtime or argument-buffer sampler, normalized ones included, gained an
unconditional DeviceDenormals at making, which a host that refuses any
precision note on an Apple GPU dies of (cubic stages died of it before
reaching their own BicubicFilterArithmetic, which is unchanged).

The note is real where the centre runs. Measured on the M3 Max with a
21x13 texture and clamp-to-zero and white-border states, at x = -2^-149,
-2^-140 and -2^-127: Metal's nearest pixel sampler reads texel -1 (the
border), MoltenVK's `floor` flushes the subnormal to -0 and reads texel
0. It shows through every centre form: a constexpr nearest sample with
an offset (UnnormalizedTexel), a constexpr edge fetch with an offset, a
constexpr nearest array sample (Texel), a runtime slot under a nearest
pixel state (TexelBySpec) and an argument buffer under one
(TexelByWord). The shader keeps the device's floor (owner's rule 1).

centre_denormals now gives the note per form:
- a constexpr sampler's Texel or UnnormalizedTexel centre, and a fetch
  under an offset: unconditional, as before;
- a runtime slot's TexelBySpec: only under NearestPixelSampler == 1,
  which is 0 for every normalized state; a runtime slot's Texel (an
  integer texture): only where its word has the pixel bit;
- an argument buffer's TexelByWord: none of its own;
  ArgumentPixelSamplerScaling, which the runtime announces only while a
  pixel state lives, records it (its doc now says so).

Tests:
- tests::engine_sampler::normalized_and_cubic_stages_record_no_note_
  their_states_cannot_run (moltenvk-m3) holds the unconditional notes of
  the sampling, handle, argument-buffer, pixel-argument and cubic
  fixtures (plain and the cubic variant under normalized and pixel
  words) to 9f5776bf31's, and checks every specialized DeviceDenormals
  clause tests the nearest-pixel constant or the pixel bit. It fails on
  ed08da17f6's select.rs (DeviceDenormals among the unconditional notes).
- runtime_pixel_accesses_hand_the_device_the_scaled_coordinate now
  checks the nearest kernels' one specialized DeviceDenormals entry and
  that the gather has none.
- runtime_lane::pixel_edges::normalized_states_announce_no_pixel_note
  dispatches the slot and argument-buffer kernels under normalized
  nearest and linear states and asserts no DeviceDenormals or pixel
  note, then a nearest pixel state and asserts DeviceDenormals (slot)
  and ArgumentPixelSamplerScaling (argument buffer). On ed08da17f6 it
  fails on the Apple M3 Max with DeviceDenormals under normalized states.

docs/API.md (device-denormals, argument-pixel-sampler-scaling) and the
DeviceDenormals row of docs/FAST-PATHS.md state the per-form rule and
the measurement. SEMANTICS_VERSION 1947: an artifact's notes changed.

Verified before this commit on MoltenVK (M3 Max, under maclock and
memcap): runtime_lane::pixel_samplers, pixel_edges (the new test
included) and pixel_downscales, 8 of 8; sampler translator tests 121.
The full checks follow on this tree.

(cherry picked from commit 382e940c470becee8cfdf560f2f1284ce2844599)
2026-11-02 11:36:44 -08:00
Anees Iqbal 575ac2b103 Read a pixel-coordinate sample's texel as Metal's sampler does
A `coord::pixel` sampler handed the device the coordinate divided by the texture's size. At a
texel edge whose quotient is inexact the device's normalized sampler read the texel before it:
on the consumer's 258x258 matrix 28 of 1042 nearest clamp-to-zero and clamp-to-border cells on
MoltenVK and up to 500 on an RTX 5080. Metal reads `floor(x)` for nearest and quantizes `x - 0.5`
to its 1/256 grid for linear filters and gathers.

Now, decided from the sampler's state and the access's structure:

- A constexpr pixel sampler that Vulkan's unnormalized sampler can state (one filter, no mip
  filter or anisotropy, clamp to edge, zero or border; a 1D or 2D non-array image, no comparison,
  no status read) samples and gathers through the device's own unnormalized sampler at the
  coordinate itself, on a view of level 0 (`CombinedSampler::unnormalized`,
  `SamplerDesc::unnormalized`). A linear sample's or gather's constant offset folds into the
  coordinate; a nearest sample's offset is applied to its texel's centre (`floor(x) + 0.5 + k`).
- A constexpr nearest pixel sampler the unnormalized form cannot take (an array, a mirror mode)
  samples at its texel's centre over the size, `(floor(x) + 0.5) / N`, which the device's
  normalized sampler reads as that texel exactly.
- A runtime slot's sampler takes the centre where a new pipeline constant,
  `SpecKey::NearestPixelSampler`, says the bound state is a nearest pixel sampler (1 only for
  those, so normalized states make no new pipeline); an argument buffer's sampler tests its word
  (`SamplerWord::nearest_pixel`, which replaces `exact_fetch`).
- Linear samples and gathers through runtime or argument-buffer samplers, arrays and 3D,
  comparisons, level queries and status reads keep the scaled coordinate and its note: their
  state is unknown where the shader is made, or Vulkan's unnormalized sampler forbids them.

`PixelSamplerScaling` is now recorded only where a scaled form remains; `DeviceDenormals` where
a centre's `floor` may read a subnormal coordinate as the device does. The pixel_samplers lane
also asserts Metal's answer for every constexpr and nearest configuration on MetalSampler devices.
The conformance case declares `pixel-sampler-scaling` for its linear cases alone, and the
llvmpipe ledger rows follow the run: two `rgba16f-nearest-mirror` rows are gone (Metal's answer
now), seven take the new digests. `SEMANTICS_VERSION` 1945, `ARTIFACT_FORMAT_VERSION` 482. No
`RUNTIME_VERSION` bump: an unchanged artifact (no unnormalized sampler, no new constant) binds and
runs as before.

The new fixture `px_edges` (own MSL, through regen-air-fixtures) samples every form at texel and
block edges, quarter offsets and each border colour on three NPOT sizes, and the new
`runtime_lane::pixel_edges` holds each nearest cell to the CPU's `floor` rule on every device and
every probe to Metal's digests on MetalSampler devices. Fixture comments in `sampling` and
`sampling_completion` no longer say the coordinate is scaled (their AIR bodies are unchanged).

Verified on the M3 Max under MoltenVK 1.4.2: the consumer's matrix compared with Metal's
results, 0 differing cells on every kernel and size (28 of 1042 before on three kernels);
lavapipe 0 before and after; `runtime_lane::pixel_edges`, `pixel_samplers` and `pixel_downscales`
pass; conformance replay of the 23 pixel cases holds the ledger on MoltenVK; on arm64 lavapipe
the whole set's replay departs from the parent's ledger, beyond what the parent's own replay
does, at exactly the nine rows edited here (the answers are the report's own). Core suite 4988
passed; validation suite under `--cfg m2v_gpu` passes the new and pixel tests, its other failures
fail the same on the parent commit; conformance 1007 passed; goldens, hashes and inventory
blessed. Release translation of every px_edges and px_samplers kernel on four profiles: slowest
0.08 s, largest peak 6 MB.

(cherry picked from commit 888ad9bae9f0aaaf769360740e1dd16817245ca4)
2026-11-02 10:03:17 -08:00
Anees Iqbal 253dedccc3 Drop ASTC attachments from passes and bind a neutral at ASTC storage slots
What: on every device and for every ASTC form (LDR, sRGB, HDR, every footprint, in its own block
or in a carrier):
- a render pass drops an ASTC color attachment that resolves nothing (`render_pass::layout`): it
  loads, clears and stores nothing into it, its level's extent still bounds the pass, and the
  pass's other attachments run as they would. No notice: that is Metal's answer.
- a draw or dispatch binding an ASTC texture at a storage slot binds the slot's neutral
  (`PlanDiagnostic::AstcStorageNeutral`): its writes leave the blocks as they were, its reads
  answer zero. The runtime announces the new `astc-storage-neutral` (precision) once, catalogued
  in docs/API.md, its lane site `ASTC_STORAGE`.
A render pipeline of an ASTC color attachment stays refused (Metal ends the process), as do a
resolve of an ASTC attachment (unmeasured), 1D and multisampled textures and another footprint's
view.

Why: the runtime answers plain Metal, not its validation layer. Plain Metal (an M3 Max under
macOS 27.0.1, probe `astc_passes_writes_footprints`) completes such a pass for every load and
store action, with a draw and without, leaving the blocks unchanged and the other attachment as
without it; it completes a kernel's `write` and `read_write` and stores bytes no format defines
into the blocks (`read_write` reads their decode). No Vulkan format of a block is an attachment's
or a storage image's, so the pass drop is exact and the neutral differs, announced.

Tests that fail before: the translator's `a_stand_in_compile_is_the_compile_of_its_formats_bind_
and_no_other` (every ASTC format at a storage slot plans the neutral with the diagnostic); the
runtime's `degradation_sites` closure (a lane site for the kind); the lane's
`runtime_lane::astc_passes_and_writes`: every one of the 48 ASTC formats at color 0 of four
passes (clear and store, load and draw, dontcare both and draw, clear and draw) with an RGBA8
color 1: the blocks unchanged and color 1 the pass's without the attachment (192 passes); a
pipeline of an ASTC attachment refused; every format bound to `write` and `read_write` kernels:
blocks and texels unchanged, `astc-storage-neutral` announced once.

Verified: MoltenVK lane on the M3 Max, `runtime_lane::astc*` 9 of 9 (192 passes, 96 dispatches);
runtime touched tests.

(cherry picked from commit 68a296589040b208634abd7b8dfa6ce938cf8c96)
2026-11-02 02:17:10 -08:00
Anees Iqbal e972337dd8 Hold ASTC's 4x2 and 8x4 footprints in a carrier with a decoded twin
What: the six ASTC formats of Apple's 4x2 and 8x4 footprints (LDR, sRGB, HDR), which no Vulkan
format holds, are made on every device as the other ASTC formats are on a device without ASTC:
their blocks in the 16-byte carrier (BC7, BC3, BC2, BC5, ETC2 or EAC; one ASTC block over 4 x 4
carrier texels whatever its footprint), their reads through a decoded twin of 8-bit codes (LDR,
sRGB) or halves (HDR). `AstcDecode::of` takes every footprint from `metal::format::block_extent`;
the format table maps them decoded-only (no direct format); the footprint module answers 26
formats now, and the heap size query takes the modelled ASTC block layout for them. Copies map
regions in blocks (`copy_plan::block_bytes`), a partial last block as Metal rounds it.

Why: plain Metal makes every such texture (2D, 2D array, cube, 3D; Shared and Private; read,
write, render-target usage) and copies them in whole blocks, the last ending at the level's edge
(probe `astc_passes_writes_footprints`). The orchestrator's brief suggested an uncompressed
16-byte-texel carrier; the existing compressed carrier already holds any 16-byte block per 4 x 4
carrier texels, so it serves every footprint with the decode passes, CPU decodes, second twins
and copy paths the other ASTC formats use, with no new image kind.

Tests that fail before: the translator's format tests (`astc_4x2_and_8x4_are_named_and_read_
through_their_twin`, counts and twins), the decode digests of 4x2 and 8x4 against Metal's
(`astc_decode` tests, HDR coverage), the runtime's image-plan, heap and pixel-format tests, and
the lane: `runtime_lane::astc_textures` and `astc_hdr_textures` now take every footprint (32 LDR
and sRGB, 16 HDR), the round trip at every level and slice 4x2 and 8x4 (partial blocks at 37x23
and 29), the colour-space views 4x2 and 8x4. The conformance case
`format-footprints-astc-4x2-and-8x4` now makes and round-trips them: its ledger row (the refusal)
is gone and it declares the three notices the carrier announces.

Verified: translator and runtime touched suites; MoltenVK lane (`runtime_lane::astc*`, 9 of 9 on
the M3 Max); conformance replay on MoltenVK of the footprint case and the ASTC cases, compliant
(the footprint case announced, every byte Metal's); lavapipe replay: every byte Metal's, the
notices undeclared before this commit's declaration.

(cherry picked from commit 2a8dd25c6b9d4cc62ff79816fa61d984969b3c22)
2026-11-02 02:17:10 -08:00
Anees Iqbal 1210972f03 Hold multisampled word-format textures in their word's format
Metal makes 2- and 4-sample textures of R8Unorm_sRGB (11), A1BGR5Unorm
(41), ABGR4Unorm (42) and RGB9E5Float (93) for every usage, memoryless
included (our probe msaa_word_formats.m, M3 Max, macOS 27.0.1). The RTX
5080 samples these formats but renders none, so Vulkan states one
sample for their images and the runtime refused each at creation
(TextureSampleCount, FramebufferColorSampleCount(4)).

What changes:
- image_plan::word_samples: where the device samples the format, renders
  it at no count and renders the word's format (R8_UINT, R16_UINT,
  R32_UINT), a multisampled texture's image is the word's format,
  mutable to the format's sampled view (and an 8-bit sRGB format's UNORM
  twin, for its resolve). Every sample holds Metal's word by
  construction: the existing word lowering writes it, clears write
  Metal's clear word, reads decode through the format's view, copies are
  bitwise. Shader writes stay unavailable (Metal writes no multisampled
  texture from a function). A device that renders the format keeps its
  native image.
- The resolve of such an attachment is the crate-owned one: Metal's for
  RGB9E5Float and 8-bit sRGB, a near-equivalent within one code for the
  packed formats, announced as the new Degradation::WordResolve
  (word-resolve). The NotImplemented(Format) refusal of word resolves in
  resolve.rs is gone; an attachment that takes neither input attachment
  usage nor the copy is still refused.
- DeviceOptions::withheld_attachment_formats (doc hidden, a test hook):
  a device made with formats' color attachments withheld, so the word
  path runs on MoltenVK, which renders all four.
- RUNTIME_VERSION 1721. Docs: API.md (word bullets, the multisampled
  word paragraph, the word-resolve catalogue entry), FAST-PATHS known
  gaps (word resolves no longer refused), word.rs, image_plan.rs and
  resolve.rs module docs; runtime-sources pin recomputed.

Routes over the committed profiles (tests::word_samples, pinned): the
word for all four formats at 2 and 4 on NVIDIA's three profiles, for
R8Unorm_sRGB and RGB9E5Float on ANV's four, and RGB9E5Float at 4 on the
gate's lavapipe; native on MoltenVK and RADV; refused where the word's
format renders one sample or the textures take no such count
(swiftshader, lavapipe's profile, the floors).

Verified:
- cargo nextest run -p metal2vulkan-runtime --all-features: 1188 pass
  (the three word_samples planning tests among them).
- Device lane runtime_lane::word_samples_msaa on the M3 Max through
  MoltenVK (--cfg m2v_gpu, maclock), new owned fixture wsm_samples: the
  device as it is (each format natively) and with the four attachments
  withheld (each held in its word, printed per format). On the word path
  every stored sample is Metal's word (all 32 or 64 per shape), reads
  decode them, the sRGB and RGB9E5 resolves are Metal's in every pixel,
  the packed resolves within a code (7-9 of 16 pixels exact after a
  draw, 13-16 after a load), a packed blend's words Metal's in every
  sample. word-resolve and shader-resolve announced. Negative control:
  with word_samples disabled the lane fails.
- clippy -D warnings (default and --cfg m2v_gpu), rustdoc -D warnings,
  private intra-doc links at their ceilings, refusal_surface --check,
  api_signatures --bless (DeviceOptions field, Degradation::WordResolve
  added), METAL-COVERAGE and CONFORMANCE-COVERAGE --check current.

Not in this change: the golden tables for the new fixture
(golden_hashes, the engine inventory, the air_input printout) are
re-blessed on development. Blends of an 8-bit sRGB or RGB9E5Float word
stay refused as the device lacking the format, as they are at one
sample.

(cherry picked from commit ad8b94cd840f3d0bf4bb9552904fbdf2f253b9af)
2026-11-02 01:32:20 -08:00
Anees Iqbal 7130d5d6e7 Make ASTC HDR textures where Metal makes them: native, else a carrier with a twin of halves
Metal on an M3 Max (macOS 27.0.1) makes every 2D ASTC HDR texture
(MTLPixelFormat 222-236) with read, write and render-target usage; the
runtime refused them on every device without the Vulkan SFLOAT block
(the RTX 5080 among them) as a format it cannot hold.

- Translator: bind::AstcDecode decodes the HDR profile, written from
  the Khronos Data Format Specification's ASTC chapter (new hdr.rs):
  HDR endpoint modes 2, 3, 7, 11, 14 and 15, the LNS-to-half mapping,
  LDR modes and void-extent blocks in an HDR texture, and the HDR
  void extent, on the CPU and in the GPU decode kernel (kernel/hdr.rs).
  Where the probe showed Metal's own answer it is the one taken: an
  LDR channel in the HDR profile is C/65536 truncated to a half (1 for
  65535); a void extent's NaN halves read as the quiet NaN; an error
  block reads NaN in every channel. Public API: AstcDecode gains `hdr`,
  AstcTexels gains `Half` (R16G16B16A16_SFLOAT), AstcDecode::form picks
  a profile's compact form, and AstcDecode::texel_bytes is now a method
  (a consumer calling AstcDecode::texel_bytes(texels) writes
  decode.texel_bytes(texels)); api_signatures.tsv blessed.
- Format table: each ASTC HDR format takes its ASTC_*_SFLOAT_BLOCK
  where the device holds it (the device's decode, rule 1), else
  FormatEmulation::Decoded over R16G16B16A16_SFLOAT.
- Runtime: such a texture is the existing carrier (its 16-byte blocks,
  which copies and getBytes move unchanged) and a decoded twin of
  Metal's halves, exact, kept in step by the same GPU and CPU decodes;
  a new texture's twin starts at the error block's NaN. Notices:
  carried-decoded-twin and cpu-block-decode, as for ASTC LDR; no
  decoded-texel-precision (the halves are Metal's). A view in another
  profile (an HDR texture's LDR or sRGB view, or the reverse) is
  refused on a carrier (Feature::TextureView, as another footprint
  is); render passes into one and kernel writes of one stay refused
  typed (the Vulkan formats take neither), where Metal's validation
  stops each.
- Docs: API.md's carried-decoded-twin entry, FAST-PATHS known gaps,
  module docs of bind::astc_decode, astc.rs and decoded_twin.rs.
- Conformance: the 42 ASTC cases now name the twin notices for HDR rows
  too, and the decoder cross-check holds Metal's recorded HDR reads.

Versions: RUNTIME_VERSION 1720 (an HDR texture is now made and read
where it was refused). No SEMANTICS_VERSION or ARTIFACT_FORMAT_VERSION
bump: translation output is unchanged (the Decoded candidate admits
sampling usages only, so no pipeline's format answer moves) and no
encoded artifact carries AstcDecode. Runtime-sources pin recomputed.

Verified:
- CPU decode bit-exact against Metal for 2048 seeded blocks of each of
  the fourteen footprints (every endpoint mode, partitions, dual plane,
  void extents, error blocks), as float and half reads and nearest
  samples (probe `reads`), checked by per-footprint digests and a
  66-block fixture of Metal's float bits (bind::astc_decode::tests::hdr);
  the GPU kernel equals the CPU decode on every texel; the kernels are
  valid on every committed profile; the conformance suite's recorded
  astc-*-hdr reads equal the decoder's.
- Plans: moltenvk-m3 native for all 14; nvidia-rtx5080-laptop,
  lavapipe, amd-780m-radv and intel-arl-anv in a carrier
  (runtime tests::image_plan).
- conformance replay of the 42 ASTC cases on lavapipe (linux-gate,
  --cpu): the 14 HDR rows `announced` (texels exact, carried-decoded-
  twin and cpu-block-decode fired), exit 0; on MoltenVK the 14 HDR rows
  `exact` with no notice.
- Touched tests in metal2vulkan, metal2vulkan-runtime,
  metal2vulkan-conformance; clippy (plain and --cfg m2v_gpu);
  refusal_surface --check, both coverage docs current; private
  intra-doc link loop at its ceilings.

(cherry picked from commit eb6828adddde978fab87dc7d05ea1a2a55738008)
2026-11-02 01:09:01 -08:00
Anees Iqbal ef7a8d6f08 Lower Metal's pull-model interpolation (interpolant inputs)
A fragment function reading an `interpolant<T, P>` input through
interpolate_at_center, _centroid, _sample or _offset was refused as invalid
input (the AIR key air.interpolation_function was unknown), so a guest whose
device answers supportsPullModelInterpolation could not run one.

AIR: the key marks a fragment input `Sampling::Interpolant`, a device-space
handle (`AbiHandle::Interpolant`); `air.interpolate_{center,centroid,sample,
offset}_{perspective,no_perspective}.{f16,f32 x1..4}` parse as
`AirIntrinsic::Interpolate`, decided from the intrinsic family and the
metadata ABI, never names.

Lowering: the interpolant is a float Input variable of its form (NoPerspective
where not perspective), read only through its calls:
- center: as a center varying is read (its pixel-center form at more than
  one sample where the device has one);
- centroid / sample / offset: GLSL.std.450 InterpolateAtCentroid,
  InterpolateAtSample (index & (SampleCount - 1), Metal's i mod n) and
  InterpolateAtOffset (offset moved to the device's origin and NClamped to
  [minInterpolationOffset, maxInterpolationOffset], which Vulkan requires).
  These need sampleRateShading (and MoltenVK's portability member): without
  them the function is refused Unsupported(PullModelInterpolation).
- MoltenVK's SPIRV-Cross hands InterpolateAtOffset(v) to Metal as
  interpolate_at_offset(v + 7/16): such a device gets the new
  VkProperty::InterpolateAtOffsetFromSevenSixteenths and the module moves
  the offset by 7/16 (a module annotation picks the property).
- An interpolant used any other way (a select of two) stays
  NotImplemented(PullModelInterpolation); on RADV
  (InterpolationNeedsTheWholeQuad) a sample or offset read after a discard
  or outside the first block is refused; lavapipe refuses a multisampled
  centroid read as it refuses a centroid varying.
- GraphicsState::interpolates_at_sample states a fragment stage that reads
  at a sample (Vulkan takes no InterpolateAtSample with custom sample
  locations); Sampling::Interpolant carries center/centroid/sample.

Metal measured on the M3 Max, macOS 27.0.1, with the new probe
probes/pull_model_interpolation.m over the owned fixture
pull_model_interpolants (cases origin, grid, samples, centroid, lane): an
offset is read from the pixel's corner as given, no range, no grid, NaN for
a non-finite one; sample i reads i mod n at Vulkan's standard positions;
centroid is the center when the pixel is covered whole, else the lowest
covered sample. The offset's range and grid are the device's:
PrecisionNote::DeviceInterpolationOffset (validation: Recorded), in
docs/API.md's catalogue and FAST-PATHS.md's device gaps; a centroid read
notes MultisamplePosition as a centroid varying does.

Verified: tests::engine_pull_model (309 pipelines over every committed
profile at 1 and 4 samples: instructions, mask's planned SampleCount,
origin, NClamp, note, property, L3; refusals on vk12-floor, RADV after a
discard, lavapipe centroid at 4x; pm_selected refused everywhere),
engine_multisample, engine_fragment, engine_coverage_loop, fast_paths,
api_tests, codec and cache tests, metal2vulkan-air abi/intrinsics tests and
api_surface; runtime degradation and catalogue tests; clippy all features.
Before: every pull_model_interpolants function failed InvalidInput
(Abi(UnknownKey)). Goldens: only new rows and the moltenvk-m3 profile hash
moved (its new property); inventory 24 new rows, 0 moved cells.

SEMANTICS_VERSION 1941 (refusals became translations), ARTIFACT_FORMAT_VERSION
481 (IoSampling, PrecisionNote, VkProperty and GraphicsState encodings).

(cherry picked from commit 70e01b4bd6f8a0d1421ae07ed710714fb4ce985b)
2026-11-01 23:38:39 -08:00
Anees Iqbal 6f8ec46671 Draw a draw whose own band the translator refuses at the nearest width
A draw whose own band variant the translator refuses where the state's
first band compiled (a varying or push data the draw's variant adds, such
as a shader-side depth test's window depth and depth range, past
maxTessellationEvaluationOutputComponents or maxPushConstantsSize) was
refused with the translator's Unsupported(WideLines). Only its later
draws took the nearest width. That breaks the owner's rule that an
accuracy note is logged and never fatal: the draw can run at the nearest
width.

The draw now takes the nearest width, announced as a state's refusal is
(lines-at-nearest-width, the translator's refusal the reason). The
refusal is still kept per state and primitive (GraphicsState::refuse_band,
two answers a state). A draw's variant key follows from its bind shape,
and its route sets that shape, so a per-key memo would need the shape
before the route. Recording a draw factors what its lines' route decides
(the route, provoking vertex, listed strip, private form, settings) into
RenderLowering::routed_draw and a RoutedDraw. draw_resident settles in a
loop. Where the settle answers the translator's refusal of the draw's band
(LineRoute::refused), it marks the state's primitive refused and routes
the draw again. Routed again it draws no band of the primitive, so it
settles once more at most. settle_draw hands that refusal back to the
caller before its snapshot and shadow retries, as before.

Docs: line_width.rs, the runtime README, FAST-PATHS's known gap, API.md's
and degradation.rs's lines-at-nearest-width (no refusal named any more).
REFUSALS.md does not move (refusal_surface --check passes): the
translator's refusal stays. RUNTIME_VERSION 1717 (a refusal became an
announced draw); runtime sources re-pinned.

Verified: the new pure test
a_draw_whose_band_the_translator_refuses_takes_the_nearest_width covers
every committed profile under both policies, lines and edges, widths 0 to
16. Each band route takes either refusal (not implemented, and the
evaluation-output limit) as its primitive's. Routed again, it is the
nearest width with the refusal as the reason, or the device's lines, and
never a band. A non-WideLines refusal or a runtime gap stands. It does
not compile against be2d725fdb, which had no such decision. A negative
control that drops the decision for lines fails it ("amd-780m-radv,
Device, Lines at 0: left None, right Some(Lines)"). Runtime line_width
tests 4/4 pass. Also clean: clippy with all features and with
--cfg m2v_gpu, refusal_surface --check, the runtime-sources pin test.
Not run: the GPU lane. No draw on MoltenVK reaches this cheaply: the base
key's band and a draw's differ only by shader-side tests' additions or
push data. The orchestrator's gate covers the restructured draw path.

(Carried to development from steelbrain/reims-graphics-kext 06f08298fd.)
2026-11-01 21:26:24 -08:00
Anees Iqbal b3d483fd72 Draw triangles' wide edges as bands, and refused bands at the nearest width
Metal draws a triangle in fill mode Lines at a width other than 1 as its
three edges, each the line parallelogram, facing as the triangle does and
culled by it, its flat inputs from the provoking vertex (the probe's
`edges` case, committed with the lane before this). The runtime drew
those edges with the device's lines, at the nearest width they draw (1
pixel on MoltenVK), announced.

Translator: the band variant takes a primitive (`BandPrimitive`, in
`VariantKey::line_band`, `LineBandState::primitive`, `BindState` and
`BindShape::line_band`). A triangle's patch is its three vertices in the
quad domain at outer levels (11, 1, 6, 1) and inner levels (3, 2): the
inner ring degenerates to a segment, so the spec's deterministic fans
from its two vertices cover the u = 0 and u = 1 edges, and the
evaluation stage places those fans' vertices at the corners of the
edges' parallelograms (from the vertex of the largest w, which never
moves at the near plane), every other triangle degenerate. The band
faces as the triangle (the sign of its homogeneous determinant, a
zero-area one back) by turning the minor axis, so the draw's own cull
mode, front face and depth bias apply. `LineBandState::PATCH_CONTROL_POINTS`
gives way to `BandPrimitive::patch_control_points`. A pure test checks
the fan tables against the spec's triangulation: every triangle is
degenerate or one of the nine that cover the parallelograms once, and
each winds as a line's band, turned by the facing.

Runtime: a triangle's edges (lists, strips, fans, Metal's private
triangle types) route as lines do: the device's lines where they draw
the width, else the band, on every device with tessellationShader;
strips are listed, the last provoking vertex read from the list led by
it. The band's depth bias is the device's per band triangle: announced
(new `Degradation::WideEdgeDepthBias`) under a slope factor or a
constant over a float depth. A pipeline state whose band variant the
translator refuses (barycentric weights, a selected slice or viewport,
synthesized geometry, multiview, too many outputs) now draws its lines
and edges at the nearest width, announced with the refusal as the
reason, instead of failing the draw: the state's first band compiles
the variant of its base key and remembers a refusal per primitive
(`Unrouted::Refused`). Mesh draws and tessellated patches keep the
nearest width. Docs: line_width.rs, band.rs, the runtime README,
FAST-PATHS (row and known gap), API.md (band variant, catalogue),
REFUSALS.md regenerated; api_signatures blessed (BandPrimitive added,
LineBandState::PATCH_CONTROL_POINTS removed, the three line_band fields
now carry the primitive). SEMANTICS_VERSION 1940, RUNTIME_VERSION 1716;
runtime sources re-pinned.

Verified (M3 Max, MoltenVK, --cfg m2v_gpu, maclock and memcap):
runtime_lane::line_widths 7/7 pass under both policies; 148 cases, 145
drawn as Metal's pixel for pixel, 28 of the 31 wide edge cases (facing,
culling, zero-area, strips, flat IDs and primitive IDs at both provoking
modes, depth across an edge, 4 samples), the other 3 the depth-bias edge
cases, announced (two differ from Metal, by slope and by exponent; the
uniform-depth one matches); 93 draws as bands, 0 at the nearest width.
Before this commit the same lane failed 4 of 7 (31 edge cases at the
nearest width, refused bands refused). Also: engine_line_band and the
band's fan tests, golden_hashes_match_the_table and the engine inventory
parts unchanged (no bless), runtime line_width tests (the route table
for lines and edges on every profile under both policies, refused rows),
api_surface, api_signatures, refusal_surface --check, clippy with all
features and with --cfg m2v_gpu, rustdoc with -D warnings.

(Carried to development from steelbrain/reims-graphics-kext be2d725fdb.)
2026-11-01 21:26:24 -08:00
Anees Iqbal 9ccc90d246 Draw at the nearest width what neither line route draws; draw nothing for no primitive
The consumer (reims-vgpu, whose guest process ends at any refusal) measured
two problems with setLineWidth: on an M3 Max over MoltenVK:

1. A draw of no complete primitive was refused. After setLineWidth 2 in fill
   mode Lines, Triangle or TriangleStrip draws of 1 or 2 vertices or indices
   returned NotImplemented(WideLines), where Metal draws nothing. drawn()
   ignored the draw's count. It now takes whether the draw may draw a
   primitive (line_width::draws_primitives: a direct draw whose vertices or
   indices complete none of its type's primitives, RewriteProgram::capacity,
   draws none; an indirect draw's count is the GPU's and keeps its route, as
   do patch and mesh draws), and such a draw is Plain. The shape memo keys
   on it beside the assembly, so a later whole draw does not reuse its
   settings.

2. Every remaining refusal refused a draw that can run. LineRoute gains
   Nearest { width, why }: the device's own lines at the width nearest
   Metal's they draw (w' clamped into lineWidthRange where the device
   enables wideLines, else 1), announced once per device (unless
   announce_each) as the new Degradation::LinesAtNearestWidth
   (lines-at-nearest-width, precision), whose reason names why and both
   widths, and counted in WorkCounts::nearest_width_line_draws. It takes a
   triangle's edges in fill mode Lines and mesh lines the device's lines do
   not draw (Unbanded), lines on a device without tessellationShader
   (Untessellated, formerly Unsupported needing it), an amplified band
   (Amplified), and every wide line in a rate-mapped pass (RateMapped) or of
   an execution's command (Executed: ShapeInputs::executes, the replay's
   lowering), whose width Metal's answer is not measured for. route() is
   infallible now; Device carries whether it differs. The replay's and the
   commit precompile's refusals go: an execution's command draws the
   nearest width and the precompile makes its pipeline; the GPU form still
   leaves such a pass to the host step, which draws and announces it.

RuntimeGap::WideLines stays for the one refusal left: a strip's band whose
list of segments the runtime cannot draw (ListGap::WideLines, as for the
provoking vertex's lists). The band variant's own refusals in the
translator (pipeline::link::band) are unchanged.

Not a speed-for-accuracy switch: the fallback for capability not built, so
no DevicePolicy switch.

Verified: cargo nextest run -p metal2vulkan-runtime -E 'test(/line_width/)'
(3 passed): each_device_routes_each_width_as_its_lines_allow now expects
the nearest width (checked against lineWidthRange) in every former refusal
cell, and rate-mapped and executed draws at the nearest width; the new
a_draw_of_no_complete_primitive_draws_nothing covers every line, triangle
and private type, direct and indexed, 1 and 3 instances, both fill modes,
on four profiles under both policies. Negative control: with drawn()
ignoring the count it fails (left: Lines, right: Nothing).

(Carried to development from steelbrain/reims-graphics-kext 5eecc33ca1.)
2026-11-01 21:26:23 -08:00
Anees Iqbal 3c1f56b63b Resolve no visible-function reference against binary functions
Metal resolves a visible-function reference against MTLLinkedFunctions'
`functions` and `privateFunctions`, never `binaryFunctions`, whose functions
only a visible-function table reaches: on this M3 Max under macOS 27.0.1
(binary_function_linking.m) a direct call to a function only binaryFunctions
holds fails the creation, plain and under validation ("unresolved visible
function reference"), from the stage's function and from a linked function
alike, while a table calls it. Two different functions of one name, one in
each list, are made: the call calls the one of `functions`, and a table holds
both, each handle calling its own definition.

The compile layer resolved references against every list, so it linked what
Metal refuses and saw two such functions as ambiguous. Now
`LinkedList::resolves_references` is `functions` and `private_functions`;
`linked_modules` reaches a table's functions by key rather than by name, and
each `LinkedName` says whether a reference resolves to it
(`resolves_references`, a new field of metal2vulkan-air's public struct), which
canonicalization's stub resolution reads. A reference only a binary function
names is `NeedsInput(LinkedFunction)`, the answer for any unresolved one.

The owned fixture `linked_other_functions` (compiled by
scripts/regen-air-fixtures) defines `linked_scale` and `table_add` with other
bodies, for the two-of-one-name shapes. SEMANTICS_VERSION 1937: the same key
now compiles otherwise (a binary-only reference refuses).

Verified: the AIR link tests, `engine_linking::a_reference_resolves_to_no_
binary_function` (interpreter: the call calls the `functions` one from either
module; a binary-only call and a binary-only nested call refuse) and
`engine_tables::a_table_holds_a_binary_function_of_another_s_name`
(interpreter: alternating own and other `table_add` through one table) pass;
with the stub filter removed, the link test and the engine_linking test fail.
API signatures blessed (one new field).

(Carried to development from steelbrain/reims-graphics-kext 64bd644d0b.)
2026-11-01 21:26:21 -08:00
Anees Iqbal eb41a55e82 Draw every width Apple's setLineWidth: takes, as Metal draws it
RenderCommandEncoder::set_line_width refused every width but 1
(AppleOnly::LineWidth). Measured on the Apple M3 Max under macOS 27.0.1
(probes/line_widths.m): each encoder starts at 1 and the width holds
across draws and pipeline states; Metal draws w' = floor(16 w) / 16
clamped to [0, 16] (NaN and negatives as 0, infinity as 16); at w' = 1
its ordinary diamond-exit lines; at every other w' Vulkan's non-strict
parallelogram (major axis the larger extent, x on a tie; minor-axis
edges through the endpoints, w' long and centred; ends not extended;
centres inside, top-left ties; the width not rounded); at 0 exactly the
pixel centres on the segment; one parallelogram per strip segment with
no joins; triangles in fill mode Lines draw their edges so; at 4
samples every width is the parallelogram at the sample positions.

The runtime (render/line_width.rs) keeps the quantized width in the
encoder state and routes each draw at w' != 1:
- the device's own lines (lineWidth w', no Bresenham mode) where it
  enables wideLines and w' lies in lineWidthRange above 0: exact where
  strictLines is unset, nonStrictWideLinesUseParallelogram set, w' > 1
  and on lineWidthGranularity; elsewhere announced device-wide-lines
  under the default DevicePolicy::wide_lines = WideLinePolicy::Device,
  and the band under WideLinePolicy::Exact (exact_answers() selects it);
- the pipeline's band variant otherwise (no wideLines, MoltenVK among
  them; w' outside the range; w' = 0 at half a width of
  2^-subPixelPrecisionBits): cull none, the band's front face, fill
  mode, a PATCH_LIST of two points, viewport 0's half extent pushed
  with the half width; strips and loops listed as their segments
  (ListGap::WideLines), flat inputs under the last provoking vertex
  read from the list led by the last vertex, which covers the same
  pixels.
Refused: Unsupported(WideLines) needing tessellationShader where neither
route draws a line; NotImplemented(RuntimeGap::WideLines) for a
triangle's edges or a mesh draw's lines the device's lines do not draw,
an amplified band, a rate-mapped pass and an execution's commands.
Counted: WorkCounts::device_wide_line_draws, line_band_draws.

The lane test runtime_lane::line_widths draws the probe's cases through
owned fixtures and compares every pixel with Metal's answers
(line_widths_m3_max.txt, the probe's output), checks each wide draw took
a route, and that every fragment is front-facing; its site WIDE_LINES
holds the new kind in the lane's degrade-notice closure.

Docs: FAST-PATHS.md's row for wide_lines and a known-gap bullet (edges
and mesh lines on devices without wideLines, near-plane cuts, band
fragments' inputs uncompared, width 1 on multisampled targets off
MoltenVK); API.md's policy bullet and degrade catalogue; the runtime
README's Line widths; RUNTIME-PORTING's row; REFUSALS.md regenerated
(reach rows for feature and gap WideLines, apple LineWidth gone).
Validation: the line limits the device description gained describe
execution and are not compared in a profile's subset check; the
generator's CORE_PROPERTIES and roadmap-2022's m2v_layer_presentation
state them at the reader's absent values; opened_chains reblessed (one
member more, wide_lines, on every device with it); golden_hashes'
profile fingerprints reblessed (no output cell moved); api_signatures
and api_surface name WideLinePolicy and LineBandState.

RUNTIME_VERSION 1712; the runtime-sources pin rewritten.

Verified on the M3 Max under MoltenVK 1.4.2 through maclock with the
validation layer: runtime_lane::line_widths, 4 tests pass. Default and
exact policies each: 102 cases, 100 matched pixel for pixel, 2 refused
(the two fill-mode Lines cases at width 4, NotImplemented(WideLines)),
0 announced; 46 draws took the band, 0 the device's lines (MoltenVK has
no wideLines). a_band_needs_tessellation (tessellationShader withheld:
width 0 refused needing it, width 2 refused, width 1 matches) and
the_lane_s_maps_tell_the_widths_apart pass. Negative control: the band
widened by 1/16 of a pixel fails both runs at LANE lines 0.5. Also
cargo clippy --workspace --all-targets --all-features -D warnings, plain
and with --cfg m2v_gpu; nextest of metal2vulkan, -air, -runtime and
-devtools (4954 run, the one failure the missing lane site, now
declared), of metal2vulkan-validation (the failures the profile rules,
chains and pin fixed here, rerun green) and of metal2vulkan-conformance
(1007 pass). Not run: lavapipe, RADV, ANV and NVIDIA lanes, which take
the device route.

(Carried to development from steelbrain/reims-graphics-kext b16d03150c.)
2026-11-01 21:26:20 -08:00
Anees Iqbal 14dc4c5f2e Draw a line wider than the device's lines as a band of two triangles
Metal draws a line under Apple's setLineWidth: at a width other than 1 as
the parallelogram Vulkan's non-strict wide lines may be (major axis the
larger framebuffer extent, minor-axis edges through the endpoints, centred,
w long). Devices without wideLines (MoltenVK among them) or whose wide
lines are strict or not parallelograms cannot draw it with their own lines.

A render pipeline's band variant (VariantKey::line_band) adds two
synthesized stages after the vertex stage (pipeline::link::band): a
tessellation control stage that copies each of a line's two vertices and
writes every level 1 in the quad domain, and an evaluation stage that
places each corner at its endpoint moved across the segment by half the
width in framebuffer pixels along the minor axis, taken to clip space
through Vulkan viewport 0's half extent, which the draw pushes
(PushField::LineBand, BindState::line_band, its own 16-byte aligned push
range). Ends behind w = 2^-20 are clipped first; smooth varyings and clip
distances follow their endpoint, flat and integer ones take the first
control point's. GraphicsState::line_band (LineBandState) states the
consumer's contract: PATCH_LIST of two control points, no culling, its
front face, the push offset.

The device description gains what chooses the route: VkFeature::WideLines,
and the limits lineWidthRange, lineWidthGranularity, strictLines,
nonStrictWideLinesUseParallelogram (VK_KHR_maintenance5) and
subPixelPrecisionBits, read from Khronos profile JSON and from ash. The
verifier and requirement rules take the per-vertex arrays of tessellation
control inputs and outputs and evaluation inputs, and TessLevelOuter and
TessLevelInner as arrays. ARTIFACT_FORMAT_VERSION 480 for the new encoded
fields (VariantKey, GraphicsState, LineBandState, PushField, VkFeature).

Verified: cargo build --workspace --all-features --all-targets; nextest
tests::engine_line_band (the band variant on every committed profile with
tessellationShader validates in spirv-val and requirements, draws
PATCH_LIST with its own push range; flat varyings take the first control
point; without tessellationShader it is refused needing it; barycentric
reads are not implemented) and the tessellation push_offset tests pass.

(Carried to development from steelbrain/reims-graphics-kext 19814d7bb3.)
2026-11-01 21:26:20 -08:00
Anees Iqbal 59209afdf7 Link stitched functions: read a linked module's signature as the entry's
A pipeline linking a function Metal's stitcher made was refused,
`Unsupported { feature: Linking, needs: NotImplemented }` at the call
(stitch_caller, block 0, instruction 5, symbol "fused"), because
link::plan refused every linked module that carries an !air.signature.
Each module of a stitched library carries one, of kind
air.stitching_modules_signature: it records the graph the function was
made from and the stitchable modules' digests, while the module's own
code (the graph's nodes inlined into the stitched function) is what
runs. The entry side already read a signature that way and refused only
a linked-constants module that still declares function constants, which
has no reading.

The rule is now one function, canon::unread_signature, which both the
entry's specialization and the linked module's plan use: a stitched
module and a linked-constants module that declares no constant link like
any other module; a linked-constants module that still declares one is
refused at the surviving call as before. The dynamic-library export
check, which blocks any signature, is unchanged: a stitched library is
an executable library and cannot be a dynamic one.

Verified: link_tests::a_linked_module_s_signature_is_read_as_the_entry_s
(replacing the test that held the old refusal) passes, and fails with
the old gate restored. Against the stitched library the probe dumped on
the M3 (not committed), the old gate reproduces the consumer's refusal
exactly, and with this change both stitched functions link, privately
or not, and compute 20 and 25 on the SPIR-V interpreter.

(Carried to development from steelbrain/reims-graphics-kext 3ebc1a708a.)
2026-11-01 21:26:19 -08:00
Anees Iqbal e54a2c12aa Refuse a pipeline of an unspecialized function that declares constants
Since functions whose constants are left undefined compile (a2e34a9d2f),
the runtime made a pipeline state of a function made by
newFunctionWithName: whose function declares function constants. Plain
Metal ends its process there, at every creator's descriptor validation
(probes/undefined_function_constant_values.m, new cases <how>:<shape>,
on the M3 Max under macOS 27.0.1, MTL_DEBUG_LAYER unset, exit 134):
"Compute Pipeline Descriptor Validation / function ko cannot be used to
build a pipeline state. Use newFunctionWithName:constantValues:... to get
the specialized function"; the render and mesh creators name
vertexFunction, fragmentFunction, objectFunction and meshFunction, and
the tile creator says "without setting constant values first". It does
so for an optional constant read only where is_function_constant_defined
says (ko) and for a constant that only gates arguments (kg). Made: a
function made by name that declares none (kn, plain, tile-plain,
mesh-plain), and every shape made with constant values that hold none or
by newFunctionWithDescriptor: without them (each then answers an empty
functionConstantsDictionary; ko stored 7, kn 9).

- metal2vulkan: FunctionDescriptor gains `specialized` (false by default,
  a function made by name; a descriptor with constant values is
  specialized whatever it says) and with_specialized, and
  needs_specialization(budget, entries) answers whether Metal makes no
  state of the stage: not specialized and a non-empty
  functionConstantsDictionary. A module function's constants are read
  through the StageEntries' module decodes (constants_dictionary_with),
  which the stage's compile copies, so the check decodes nothing the
  compile does not. The compile itself is unchanged.
- metal2vulkan-runtime: Function::function_descriptor marks the stage
  specialized where the function was made with constant values or by
  descriptor. pipeline/unspecialized.rs refuses before anything is
  compiled, Invalid with the new Problem::UnspecializedFunction { stage,
  name }: compute and tile states (of_kernel), render states (vertex,
  fragment) and mesh states (object, mesh, fragment). A linked function
  keeps its own rule (LinkProblem::UnresolvedConstant).
- Pipeline records carry the stage's specialized flag, RECORD_FORMAT 3:
  without it every specialized stage's record read back unspecialized
  and went unrecorded.
- The owned fixture engine/unspecialized_stage_functions (the probe's
  shapes at every stage); its golden rows, inventory and printout are
  new rows only (11 functions by 2 forms in each table).
- docs/API.md ("Function constants"), the FunctionConstantValues and
  creators' docs, the runtime README, docs/REFUSALS.md regenerated, the
  signatures blessed (FunctionDescriptor.specialized, with_specialized,
  needs_specialization, Problem::UnspecializedFunction).

Verified:
- metal2vulkan tests::engine_unspecialized 2/2 (every declaring function
  of the fixture needs specialization made by name, no free one does,
  and the eleven answers read one module decode, (1, 10); specialized or
  valued, none does, decoding nothing).
- On MoltenVK (M3 Max) through maclock, --cfg m2v_gpu:
  runtime_lane::unspecialized_functions 3/3 (by name: guarded and gate
  kernels, vertex, fragment, tile, mesh and object refused; free kernel
  stores 9; plain render state made; empty-valued and descriptor-made
  guarded kernels store 7, gate kernels made, render states made; tile
  and mesh states of them not refused as unspecialized) and
  runtime_lane::linked_functions 2/2.
- metal2vulkan-runtime suite 1177/1177; tests::warm_record 4/4.
- metal2vulkan and metal2vulkan-air: 3748 of 3753 before blessing, the 5
  failures the new fixture's table rows; after blessing they and the
  signature and surface tests pass.
- Negative controls: needs_specialization answering false fails
  engine_unspecialized's by-name test; function_descriptor without the
  specialized flag fails all three lane tests (the empty-valued and
  descriptor-made functions refused); the stage flag removed from the
  record's writes and reads fails the four warm_record tests.

(Carried to development from steelbrain/reims-graphics-kext 116efd0dfe.)
2026-11-01 21:26:18 -08:00
Anees Iqbal 6a41f826c8 Document linked-function names and constants; lane test on the device
docs/API.md section 3 states the rule: a reference resolves by
LinkedFunction::name (the specialized name, else the function's own), a
linked module with constants is specialized with the function's values, a
specialized function reads an unvalued constant as undefined, and an
unspecialized one (newFunctionWithName:) that reaches a constant is refused
with LinkProblem::UnresolvedConstant. Section 10 adds the zero read of a
linked function's unvalued constant to the accepted differences. The runtime
README says how a stage links visible functions and by which name.

The probe's header records its 19 cases as measured on the M3 Max under macOS
27.0.1 (26A434), MTL_DEBUG_LAYER unset, one case a process through maclock:
the four of the brief (specialized 16, plain and other unresolved custom_fn,
both 16) and the constant shapes (newFunctionWithName: reaching the constant,
guarded or not, fails "cannot lower module with unresolved function
constants"; plain_fn links; every specialized form links, unvalued reads
storing nothing).

runtime_lane::linked_functions runs both through the runtime: names answered,
16 at word 0 with every word 3x + 1, plain and another_fn needing custom_fn,
both 16; derived 6x, guarded 3x and x - 1, plain_fn x + 2, base_fn unvalued 1;
by name: base_fn and guarded_fn refused UnresolvedConstant, plain_fn 7,
constantValues 3 16, empty values and a descriptor without values link.
tests::pipeline gains the duplicate-name check by link name: one function
under its own and a specialized name is no repeat, two under one specialized
name are.

Verified: on this M3 Max, MoltenVK, through maclock and memcap (6 GiB),
RUSTFLAGS='--cfg m2v_gpu' cargo nextest run -p metal2vulkan-validation
--all-features -E 'test(/runtime_lane::linked_functions::/)': 2/2 passed.
cargo nextest run -p metal2vulkan-runtime --all-features -E
'test(/tests::pipeline::/)': 5/5 passed.

(Carried to development from steelbrain/reims-graphics-kext 228cf1424c.)
2026-11-01 21:26:17 -08:00
Anees Iqbal b4a3540c9d Keep a Core Image kernel library's HASH as read instead of verifying it
Core Image's own kernel libraries (ci_stdlib, ci_filters, ci_raw: file
type 1, extern functions over one module) were refused as
Container(HashMismatch), so Library::from_metallib, the runtime's
new_library_with_data and the command line ("FALLBACK (input not read)")
refused what Metal reads, in every process that uses Core Image. The
function table, metadata, extended header (HDYN, UUID) and shared module
were all in the shape the reader already takes; only the HASH check
failed.

What the HASH is, measured with libraries written from scratch under
Xcode 27.2's toolchain (metal -fcikernel, metallib -cikernel) on an M3
Max under macOS 27.0.1:
- metallib -cikernel writes one HASH for every function. For some modules
  it is the SHA-256 of the module it writes (the two-kernel library the
  file-type-1 support was first measured with, kernels with short
  loops); for others it is not, e.g. one kernel with a three-iteration
  loop of sin and cos. Not the digest of the input .air, of the stream
  without the wrapper, of the module without its zero padding or with
  other padding, or of the module round-tripped through metal-opt.
  metallib is deterministic, and feeding the written module back through
  it gives the same module and the same HASH. What it is a digest of is
  not known, so it is not interpreted.
- Metal checks no HASH: the new probe
  (crates/metal2vulkan-conformance/probes/metallib_function_hashes.m)
  loads an executable library and a Core Image kernel library with one
  bit of every HASH flipped exactly as written (the kernel's pipeline
  stores 1,4,7,10 both ways), and the Core Image library whose HASH is
  not its module's digest as well.

So a Core Image kernel library's HASH is read as 32 bytes, once, present
(as before), kept as read in LibraryFunction::raw_tags, and each
function's content key (LibraryFunction::hash, FunctionInfo::air_hash)
is its module's SHA-256, computed once for the shared range. Every other
library's HASH stays verified (HashMismatch), which is stricter than
Metal; docs/API.md says so.

The same probe found that Metal's externFunctionNames order is not the
reverse of the table's in general: a two-kernel library (tint, shift)
answers it, but a four-kernel library written from scratch, libraries of
10 to 200 kernels and Core Image's own answer the same names in an order
that is neither the table's, its reverse, nor sorted. The runtime keeps
the reverse; Library::extern_function_names' doc now says the order
differs from Metal's (doc only).

No cache version moves: a type-1 library whose HASH matched keeps the
same content key, and one whose HASH did not was refused before. No
translation output changes. The runtime-sources pin moves for the doc
comment in the runtime's library.rs (no behaviour): re-pinned to
d000eb23746160492052af4ff3e62bb81ab598b44fc8684b3cf36105d2c67026.

Verified (M3 Max, macOS 27.0.1):
- New test container::tests::a_core_image_library_hash_is_kept_as_read:
  a synthetic type-1 library of three extern functions over one module
  whose HASH is not the module's SHA-256 parses, each function's hash is
  the module's digest and its HASH is kept raw; one whose HASH is the
  digest reads the same; a missing, duplicate or 31-byte HASH is still
  MissingTag, DuplicateTag, BadTag; the same table as a dynamic library
  is HashMismatch. Negative control: with the exception disabled
  (every library verified) the test fails (HashMismatch at parse), the
  other 18 container tests pass.
- cargo nextest -p metal2vulkan-air --all-features: 482 passed.
- Locally only, nothing of it committed: Core Image's ci_stdlib,
  ci_filters, ci_raw (and ci_stdlib_h) now read through the command line
  and through the runtime on MoltenVK: each lists only extern functions
  (as many as its table holds), function_names empty, every name made by
  new_extern_function_with_name and new_function_with_name with
  FunctionType::Extern, a sample of six per library refused as a compute
  pipeline (Compile, EntryNotFound), as Metal answers; Metal's own answers
  for the same files through the probe agree (type executable, no
  function names, the same count of extern names, functionType 4 for
  each).
- metal2vulkan core_image_libraries and api_signatures (3), the
  validation runtime-sources guard after the re-pin: pass. clippy
  --workspace --all-targets --all-features -D warnings, plain and under
  --cfg m2v_gpu (own target): clean. rustdoc -D warnings for the three
  published crates: clean.
- Not run: the other suites, the device tests, golden tables (no
  translation output changes), a corpus census. Core Image's link of
  these extern functions into ciKernelMain was not reached locally:
  rendering ten built-in filters did not go through Metal's image-filter
  link calls on this Mac.

(Carried to development from steelbrain/reims-graphics-kext 2d3259adbf.)
2026-11-01 21:26:16 -08:00
Anees Iqbal 9c80a4957b Compile functions whose function constants are left undefined
A function constant the request leaves unset no longer refuses the pipeline
with NeedsInput(FunctionConstant). Metal makes that pipeline, optional or
required: is_function_constant_defined is false, arguments gated on the
constant (negated or not) are absent, and its reads vary from read to read
(probes/undefined_function_constant_values.m on the M3 Max, macOS 27.0.1:
u + 3 read 0, u * 7 + 1 read 1, u == 0 ? 111 : 222 read 222, b ? 5 : 6 read
5). WindowServer's QuartzCore pipelines leave optional constants unset
(fixed_vert_lpf_gen without constant 53), so the desktop could not draw.

SCCP's lattice is now flat, the undefined value one more value beside the
constants:
- a value computed from an undefined constant alone stays undefined, and a
  pure instruction computing one becomes its type's zero (an address keeps
  naming the constant's global);
- a branch on one takes its false way (a rewrite only where no other way
  was opened), and a select its false arm;
- an and with zero, an or with all ones and a mul by zero are that
  constant whatever the undefined operand holds, in SCCP and in the static
  initializer, so QuartzCore's generic || (...) is true with generic set;
- an operation that also reads a run's value, and a PHI (an undefined
  entry merges as overdefined), keep what the run computes, so a defined
  way keeps its value and a loop counting from the constant still counts.
The entry-block refusal and its inliner gate are gone. Entry gains
undefined_reads, the undefined constants the specialized body reads,
which validation's case checker uses where it used the refusal to prove
an omitted constant unread.

Removed: MissingInput::FunctionConstant (metal2vulkan-air),
RuntimeInput::FunctionConstant (metal2vulkan), the command line's
--constant hint. docs/API.md lists the reads under accepted differences.
SEMANTICS_VERSION 1932. The golden tables and the engine inventory move
only the 532 cells (28 rows by 19 profiles) that were the refusal; each is
now ok.

Verified: metal2vulkan-air 481/481, with negative controls (absorbing rule
off: the two new and/or tests fail; the PHI mapping off: the loop test
fails); the core suites; clippy (all features, --cfg m2v_gpu); the
command line on the M3's QuartzCore library: fixed_vert_lpf_gen with
reims's values (0 and 1 true, 3 = 0) and the whole pipeline with
fixed_frag_lpf_cpf translate and pass spirv-val on moltenvk-m3,
nvidia-rtx5080-laptop and intel-uhd770-rpls-anv, with generic true
keeping the texture-matrix path (521 lines of SPIR-V against 290); every
fixed_* pair and backdrop_capture_compute_tile_* with no constants
translates but the _spc vertex functions, which ask for a vertex
descriptor.
2026-10-31 05:34:42 +02:00
Anees Iqbal 245b51ef7a Read NVIDIA's 10-bit two-plane codes through Metal's arithmetic, and judge the YCbCr lanes by the device's bounds
On the RTX 5080 Laptop GPU (NVIDIA 615.71.09, Linux), development failed 27 of the YCbCr
validation tests (runtime_lane::ycbcr_textures 22, ycbcr_minify 2, ycbcr_in_place 2,
dma_buf_imports' YCbCr test).

Bisect on the 5080, each step built on its own, with the filters
test(/runtime_lane::ycbcr/) | test(/dma_buf_imports::a_ycbcr/):
- cdf59197cc and d4412c9c95: 46 of 46.
- 70068f7cc0 (device colour writes; b7a62be64b, its parent, not split off): both
  ycbcr_minify tests. Their RGBA8 draw is now the device's colour conversion
  (device-color-conversion), so Metal's hash cannot hold.
- 78ed264c90's packet, which deleted the exact YCbCr filter and exact texel conversion
  (78ed264c90 alone does not build; 3c129f4d6f fails 16; 6e0e108d01 re-judges some lanes).
  2ec1f9fdc8 fails 7: the minify samples, 10-bit codes, 10-bit linear samples held to Metal's
  rounded step, and one in-place linear check.
- a1f1677174 (the device's own Y'CbCr conversion on discrete GPUs) takes it to 27.
None of this is from the current round.

Causes and fixes:
- Product: NVIDIA's conversion of G10X6_B10X6R10X6_2PLANE_{420,422,444}_UNORM_3PACK16 reads
  each word's six unused low bits. Vulkan says those bits do not take part: the format holds
  "a 10-bit G component in the top 10 bits of each 16-bit word ... with the bottom 6 bits of
  each word unused", and with image and view formats the same, "these bits will be unused by
  format conversion". Measured on the 5080: within 0.0001/2048 of Vulkan's conversion where
  the low bits are 0, and up to 6.43/2048 off where they are random. Those random-bit reads lie
  within 0.034/2048 of the word read as the code with six bits of fraction. NVIDIA now takes the
  TenBitCodesReadAsWords row (as lavapipe and RADV do), so a 10-bit two-plane texture converts
  through Metal's arithmetic there. Its 8-bit layouts keep the device's conversion. Nothing is
  refused. RUNTIME_VERSION 1708.
- NVIDIA widens a 10-bit UNORM code (the codes image's A2B10G10R10_UNORM_PACK32) by replicating
  its bits to 16: (c << 6 | c >> 4) / 65535. That lies within 0.0144 of a code of c / 1023
  (1.41e-5 absolute, inside Vulkan's "accurate to about 1 part in 10^5" for computation outside
  shaders). It is recorded in PrecisionNote::DeviceTexelConversion's bound, the runtime's
  catalogue, docs/API.md and the ledger row. The lanes' code checks accept that form exactly,
  within one f32 ulp, and still name the code.
- The lanes were never calibrated for textures the device converts itself (8-bit 4:2:0 and
  4:2:2 here). Where WorkCounts::ycbcr_device_conversions moves, a lane now holds each texel to
  Vulkan's conversion within the device's bound (ycbcr_device_reads), a code-reading texture
  to the nearest codes of its reconstruction, and expects ycbcr-filter-not-exact once.
  Elsewhere it still holds Metal's steps exactly.
- With the exact filter deleted, a kept image's linear sample on a natively sampling device is
  the device's filter. The lanes held it to Metal's rounded step within 0.5 codes. Metal's step
  rounds each tap's term, and NVIDIA's sub-texel snapping ("Sub-texel values calculated during
  image sampling will snap to these locations") moves the sum by a 1/256 step of the taps'
  difference. So the filter is now held to the texels' weighted sum within one code, the bound
  the DeviceSampling note records for a linear filter, scaled by the taps' spread where it
  passes 1 (sRGB twins' linear values past [0, 1]). The 5080 lay up to 0.548 codes off. The
  DeviceSampling note records its 0.56 against Metal's sum over 10-bit and packed textures.
- ycbcr_minify on such a device compares the bands, the grid and the draw bit for bit with the
  same kernels and draw over an RGBA16Float texture of the read() texels, whose hash is still
  Metal's. In-place and Metal-sampler devices keep Metal's hashes.
- tests::ycbcr_device: a code-reading format's ties may round either way, within half a code.

Verified on the tree of this commit:
- msi-laptop, RTX 5080 Laptop GPU, NVIDIA 615.71.09, --cfg m2v_gpu, NVIDIA ICD:
  metal2vulkan-validation test(/runtime_lane::ycbcr/) | test(/dma_buf_imports::a_ycbcr/)
  46 of 46 (every one of the 27 included); metal2vulkan-runtime test(/ycbcr|chroma|
  driver_defects/) 16 of 16. The device-converted reads lay within 0.0337/2048 of Vulkan's.
  The minify twin comparisons ran (14 outputs).
- This M3 Max, MoltenVK 1.4.2, macOS 27.0.1, under memcap and maclock, test(/ycbcr/) over
  the runtime and validation crates: 50 of 51. The failure,
  a_ycbcr_sample_through_an_unmeasured_filter_is_announced ("anisotropic through
  Constexpr(...): left None, right Some(1)" for YCbCrFilterNotExact), predates this change
  (same at daf1bf625f).
- A check that fails without the fix: before the row, the 5080 failed
  textures_over_any_surface_read_what_metal_reads,
  four_two_two_and_four_four_four_textures_read_what_metal_reads,
  four_two_two_and_four_four_four_views_read_their_twins_texels and
  a_four_four_four_texture_s_writes_store_metal_s_codes (10-bit reads past the device's
  0.04/2048 bound). The row alone made them pass there.
- clippy --workspace --all-targets --all-features -D warnings, plain and --cfg m2v_gpu; rustdoc
  -D warnings for metal2vulkan and the runtime; host tests of driver_defects, fast_paths, the
  degradation catalogue, api_signatures, api_surface and the refusal surface: 115 passed.
Not run: lavapipe and RADV (no venue here). They are expected to pass: their runtime paths are
unchanged, and the lanes' checks there are as before or wider (a kept image's filter is held to
the weighted sum within one code, where it was held to Metal's step within 0.5).
The runtime-sources pin is left to the landing.

One work packet, landed as 2 commits on archive/development-linear-2026-10-29: 1df2fc38d8, then f4f88dad89 (the re-pin).
2026-10-29 15:43:56 +02:00
Anees Iqbal 8d75695ead Answer per buffer whether a no-copy buffer's bytes are imported in place or copied
A no-copy buffer whose import the caller's gate refuses, or whose admitted import fails, is
made over a copy of its pages (copied.rs), announced once per device. A consumer that probes
whether an import worked could only read a WorkCounts::copied_host_buffers_made delta, which
races with buffers other threads make on the same device. A per-buffer answer cannot.

What:
- Buffer::host_backing(&self) -> Option<HostBacking>, a runtime extension (Metal has none: a
  no-copy buffer's bytes are always the caller's pages there). HostBacking is #[non_exhaustive]:
  ImportedByPointer, ImportedAsDmaBuf, InHostRam (bound in a guest RAM's chunk), Copied
  (the copied-host-pages degradation) and Detached. None for a buffer over no host memory of
  the caller's; a buffer placed in a no-copy heap answers its heap's. The answer is where the
  bytes lie now, so it changes only at a rebind (which may move between an import and a copy)
  or a detach. It reads the import's shape and its copy registration alone: no page read, no
  import exposed (unlike gpu_address).
- buffer::Shape records whether the bytes are bound in a RAM chunk (Placement::over_ram_chunk,
  a 6-line accessor in memory.rs), so the answer needs no read of the import's objects.
- Buffer::copied (crate-internal) now reads host_backing, so the runtime's own decisions and the
  public answer cannot disagree.
- Docs: the runtime README's runtime extensions, HOWTO's copied host buffers section, the
  copied-host-pages declaration and its docs/API.md catalogue entry name the query.
  api_signatures.tsv re-blessed: 7 records added, none changed or removed. The metal2vulkan
  api_surface table does not cover the runtime, so it is unchanged. RUNTIME_VERSION unchanged: a
  pure query, nothing the runtime does with an artifact moved.

Verified on this M3 Max (MoltenVK 1.4.2, macOS 27.0.1), --cfg m2v_gpu, under memcap and maclock:
- copied_device: host_backing_answers_what_the_gpu_uses_for_a_buffer_s_bytes (own buffer and own
  heap's buffer None; pointer import ImportedByPointer; gate-refused Copied; a no-copy heap's
  buffer its heap's, then Copied after the heap's gate-refused rebind; Detached after a detach;
  ImportedByPointer after rebinding) and host_backing_follows_a_rebind_between_an_import_and_a_copy
  (import, gate-refused copy, import, failed-import copy, each read back on the GPU); every copied
  test's lies_in_a_copy asserts Copied; host_ram_device asserts InHostRam for chunk-bound buffers
  and rebinds, and Copied for a refused rebind onto two runs.
- The host-memory filter (copied|rebind|host_import|in_place|heap|detach|host_ram|host_aliases|
  host_residency|stand_in|host_backing): 148 passed, 0 failed, no device skipped.
- Negative controls: forcing Copied and InHostRam to answer ImportedByPointer (the internal
  copied kept right) failed 10 tests; forcing Detached to answer None failed the new test.
- clippy -D warnings plain and --cfg m2v_gpu; rustdoc -D warnings for the runtime; the
  api_signatures, api_surface and degradation catalogue tests; refusal surface and Metal
  coverage checks current.
Not run: ImportedAsDmaBuf on a device (the dma-buf import is a Linux path; nothing here ran it).

One work packet, landed as 2 commits on archive/development-linear-2026-10-29: 31b81906af, then 27ba200e86 (the re-pin).
2026-10-29 15:43:56 +02:00
Anees Iqbal d4fa99a14c Make a state's predicted key in its general form, every texture class drawn at once
Ports dev-perf 7028c0d92a onto development. On a device that samples
through Metal's own texture unit (MoltenVK) a texture slot a function
converts to `half` declares `SpecKey::PlainHalfTexels` and
`SpecKey::UnmeasuredTexels`, each with an arm that serves every bound
class exactly (0: the class routine; 0: no instruction reads it). A
state's creation predicts no texture bound, so a draw binding an
unmeasured class (BC4 to BC7, the linear ASTC formats among them) keyed
apart from the one pipeline the creation made, compiled its own at the
draw, and its command buffer waited for it (past the commit bound the
draw is dropped).

The residual form becomes the general form (`render/residual.rs`):
RangeAtBindOffset, PlainHalfTexels and UnmeasuredTexels at 0. A state's
creation makes its predicted key's general form, waited as before, and
where the predicted key differs hands the predicted key itself to the
pool right after, at the rank nothing waits for, not waited for. A draw
whose own key is not made takes the general form at once while its own
is made, as the residual form did. graphics_pipeline_now and
made_or_make now say whether the pipeline is the key's own, so a made-now
draw that took the general form keeps nothing in its encoder's memo.

Adapted to development (development wins):
- Development's native half-texel rounding (ae70850097, not on dev-perf)
  made every class but a YCbCr field on the grid 8192 plain, so the
  16-bit normalized and 32-bit float classes now key as predicted. That is
  why the 10-28 attempt saw other counts: dev-perf's lane changes expected
  an RGBA16Unorm draw to take the general form (it takes the predicted key
  on development), and its general_form_drawn test's first positioned
  RGBA16Unorm draw made its own (PlainHalfTexels 1) key, so the RGBA8Unorm
  draws found that made and took no general form (0 of 2). The lane test
  now guards the idea with a BC4RUnorm draw (an unmeasured class).
- ce02b68f23 (general_form_drawn) is not ported: on development no
  made-now draw path reaches a made general form. A positioned key's
  general form is never made (no base-variant class keys PlainHalfTexels
  0); a state for indirect command buffers refuses a fragment function
  with a direct texture argument (Metal: "Fragment shader cannot be used
  with indirect command buffers", seen on the M3); rerouted draws run the
  extended shadow's variant. The own-flag change stays, unguarded by a
  device test.
- No dev-perf measurement is quoted: its GPU-time and creation figures
  were taken with another plain-class set and are not re-measured here.
  The pipeline-creation bench is gone from development and not restored.
- pipeline_creation's pooled-making count (draw(1), f5cfcc4f3c) holds
  under the general form: the format draws take the predicted key or,
  while the pool still makes it, the general form, neither pooled.

Lane tests: made_at_creation's half-reading creations settle the pool
and expect 2 makings on Metal-sampler devices (1 elsewhere); new
a_draw_of_an_unmeasured_class_takes_the_general_form_its_creation_made;
ycbcr_textures' creation-made test settles the pool before counting.
Unit tests tests::general_form. Docs: residual.rs, predicted.rs,
API.md's general-form bullet, WorkCounts::residual_form_* docs.
RUNTIME_VERSION 1702 -> 1703.

Verified on this Mac (Apple M3 Max, MoltenVK 1.4.2), --cfg m2v_gpu,
under maclock and memcap: 212 device tests of the modules that count
pipeline makings (made_at_creation, pipeline_creation, ycbcr_textures,
creation_times, draw_work, framebuffer_fetch, kept_variants, restart,
runtime_data lanes; creation_prediction_kinds, creation_split,
deferred_calls, descriptor_key_*, draw_shape_notices, render_*,
tile_pending, tile_rebind_making_wait, twin_flights,
uniform_bind_offsets, pipeline_wait_order, dispatch_pending,
pool_room_creations, rebind_making_wait, pending_rebind, general_form):
211 pass; the one failure,
ycbcr_textures::a_ycbcr_sample_through_an_unmeasured_filter_is_announced,
is recorded failing on development before this change. Sabotage: with
the creation making the predicted key alone, 3 made_at_creation tests
FAIL (1 creation making vs 2); with the draw looking up the residual
form in place of the general form, the BC4 test FAILS ((0,0,0) vs
(1,1,1): no general form drawn); restored, PASS. Unit and check tests
205/205 (general_form, fast_paths, catalogue, degradation,
api_signatures, api_surface, profile). Clippy -D warnings plain and
--cfg m2v_gpu (workspace, all targets, all features) and rustdoc
-D warnings clean.

Conformance replay on the M3: case verdicts identical to development's tip
over four passes each. One cost over (render-then-sample-magnified-nearest,
pipelines_per_pipeline_state 4 vs 2) appeared in one of four passes, never
at the baseline; run alone, both read 4 over 2 states.

RUNTIME_VERSION renumbered at landing: 1706.

One work packet, landed as 2 commits on archive/development-linear-2026-10-29: 5c51f5b0f9, then a9f25c50bb (the re-pin).
2026-10-29 15:43:56 +02:00
Anees Iqbal 97116bb420 Keep pages the kernel cannot pin from NVIDIA's driver, and copy them as a failed import is copied
On NVIDIA's driver (615.71.09, RTX 5080 Laptop), a failed host-pointer
import of pages the kernel cannot pin breaks the process's later
host-visible allocations. The consumer's device-creation probe hit this, so
no guest RAM chunk imported afterwards. The runtime now asks the kernel
first on that driver, refuses such pages itself with the answer Vulkan
requires, and never hands them to the driver. The object then goes its
other ways: the dma-buf source, else a copy.

Cause, measured on msi's 5080 through runtime device tests that logged each
call's VkResult and errno, the fd table and the process's maps:
- The consumer's probe makes no dma-buf import on NVIDIA. Its 1025-page view
  is past udmabuf's list_limit, so its source refuses. What fails is the
  runtime's import of the view's pointer, a VM_PFNMAP mapping of a udmabuf:
  vkGetMemoryHostPointerPropertiesEXT succeeds (types 2 and 3), then
  vkAllocateMemory answers ERROR_OUT_OF_DEVICE_MEMORY on both.
- After that, vkAllocateMemory answers ERROR_OUT_OF_DEVICE_MEMORY to every
  host-pointer import measured:
  - memfd pages from 8 KiB to 8 MiB at any offset;
  - anonymous pages;
  - RAM 512 MiB away;
  - 40 retries over 3 s;
  - a second VkDevice.
  It also fails a plain 64 KiB host-visible allocation. Device-local
  allocations still work. The chunk import fails in vkAllocateMemory, not
  in the properties query or the requirements check.
- Not the cause: a failed udmabuf import itself (the next 8 chunk imports
  bind, and NVIDIA closes the handed clone: F_GETFD EBADF), the properties
  query alone, mapping a udmabuf, address reuse, the fd table, VmPin/VmLck,
  the kernel log.

Vulkan (vkspec 1.4.366, 11.2.6): such a restriction "must fail the memory
import operation with the error code VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR";
and (Return Codes) "VK_ERROR_OUT_OF_*_MEMORY errors do not modify any
currently existing Vulkan objects."

Fix:
- RuntimeDriverDefect::UnpinnablePagesBreakHostMemory (NVIDIA_PROPRIETARY,
  no GPU probed clean, per the defect table's rule).
- On such a device, Device::refuse_unpinnable runs before a no-copy
  object's, heap's or rebind's own import and before a guest RAM chunk's
  import. It walks the mappings over the pages (PROCMAP_QUERY, or the maps
  lines before Linux 6.11) and reads one byte of each through
  process_vm_readv. The kernel refuses a whole VM_IO/VM_PFNMAP mapping, so
  one read per mapping answers for all its pages.
- Pages it cannot pin get its own Unsupported/HostMemory refusal naming the
  defect. That refusal sends the object to the dma-buf source; with none,
  or where the source's import fails, the object is a copy, announced as
  copied-host-pages and counted as a failed import. This holds for buffers,
  heaps and rebinds. A RAM chunk over such pages is not imported, and the
  objects over it end in the copy. Pages not mapped readable keep their
  refusal. The new refusal reaches a caller only where pages remapped after
  their first import are imported again (docs/REFUSALS.md regenerated).
- Counted: WorkCounts::host_imports_unpinnable.
- Every other driver, and every OS but Linux, asks nothing and keeps its
  path.
- Docs: driver_defects.rs (the measurement), FAST-PATHS known gaps, HOWTO
  section 6 and its copy causes, the runtime README, copied.rs,
  CopiedHostPages and its API.md entry.
- RUNTIME_VERSION 1704.

Verified:
- RTX 5080 Laptop, NVIDIA 615.71.09, --cfg m2v_gpu: the runtime filter
  host_ram_device|copied_device|rebind|dma_buf|host_residency|
  driver_defects|host_memory|host_import|copied passes 97/97 on the
  committed tree.
  - New: a_chunk_is_imported_after_a_refused_import_of_a_dma_buf_mapping
    failed without the fix ((0, 0) where (1, 2) is expected) and passes
    with it.
  - New: pages_refused_before_the_driver_with_no_source_are_copied: a
    buffer, a heap and a rebind over a udmabuf mapping with no gate and no
    source give 3 refusals before the driver and 3 copies. The GPU reads
    the right bytes, and a chunk then imports with 2 buffers bound.
- The consumer's repro, with its device probe in front
  (os::linux::host_ram::tests::a_buffer_over_one_run_of_the_ram_is_bound_in_its_chunk,
  built from a read-only copy of their 2cb3c8f91): passes. It fails against
  development 2e2e238346.
- M3 Max, MoltenVK 1.4.2: the same filter 83/83; runtime unit tests 1161;
  API, refusal-surface and fast-paths tests 34; rustdoc -D warnings clean.
  Clippy -D warnings is clean on the Mac (plain and --cfg m2v_gpu) and on
  msi (plain and --cfg m2v_gpu).

Left: RADV and ANV refuse such pages themselves, so an object there with no
source is still refused (not run there). A failed chunk import is not kept,
so the kernel is asked again for each object over that chunk (cost not
measured).

Lane commits: ws/chunkfix-lane (a2420020ea, a56fa43f2b).

One work packet, landed as 2 commits on archive/development-linear-2026-10-29: a0a1ea79d4, then 22fa5003db (the re-pin).
2026-10-29 15:43:55 +02:00
Anees Iqbal 44eaa09898 Copies of read-only pages drop the GPU's writes; the gate is asked before write permission
The consumer's 4K boot on the RTX 5080 (NVIDIA 615.71.09) died at a buffer rebind onto 12 KiB of
read-only pages (`replaceBackingWithRanges:readOnly:`) with `OutOfMemory(Device)`, its gate having
refused the pages.

Cause: on Linux the runtime asked the pages' write permission before the caller's gate. Read-only
pages with a dma-buf source were sent to the source (by_pointer cleared), and the gate, asked only
for pages imported by pointer, was skipped. NVIDIA 615's import of the source's dma-bufs fails with
VK_ERROR_OUT_OF_DEVICE_MEMORY, and that failure was answered as the call's error, where a failed
pointer import takes the copy. The copy path itself never ran. Reproduced on the 5080: a buffer's
rebind, a heap's rebind and a no-copy buffer over read-only pages under a refusing gate each
answered OutOfMemory(Device). On macOS the gate was asked and the copy made, and the copy's
merge-back then wrote the read-only pages: SIGBUS in all three.

Fix:
- The gate is asked before the write permission, at a no-copy buffer's or heap's making and at a
  rebind. Pages it refuses, and bytes moved in their page, are a copy, their permission unasked;
  only pages imported have it asked.
- An admitted import of the caller's dma-bufs that fails (out of memory, another Vulkan error)
  takes the copy too, as the pointer's import did: the gate's documented contract.
- A copy of pages the process cannot write drops the GPU's writes (copied.rs), as Metal drops them
  for read-only memory (read_only_view.rs). The copy asks the system as it is made
  (`mapped_writable`: PROCMAP_QUERY on Linux, mach_vm_region on macOS). At each completion, every
  byte the GPU changed in the copy takes back the byte the pages and the copy last agreed on, and
  nothing is written to the pages. Later commands of the same batch read the write back; a later
  command buffer reads the pages' bytes. CPU writes through another mapping are copied in at each
  commit as before.
- The copied-host-pages detail says so; read-only-pages-written is not announced over a copy.

Changes beyond the consumer's case: gate-refused pages and moved-bytes copies no longer ask the
kernel for write permission (no host_mappings_queried for them). Read-only pages with no source
under a refusing gate are a copy instead of Unsupported.

WorkCounts::copied_dropped_bytes (new). RUNTIME_VERSION 1703. api_signatures.tsv blessed;
REFUSALS.md regenerated, unchanged. Docs: HOWTO (copied host buffers), API.md (copied-host-pages,
read-only-pages-written), FAST-PATHS (the read-only-memory known gap now excepts copies),
ImportGate, HostMemory::new, new_buffer_with_bytes_no_copy, Buffer::rebind_bytes_no_copy, the two
Degradation declarations, copied.rs module docs.

Tests:
- Device, copied_device:
  - a no-copy buffer, a buffer's rebind and a heap's rebind over read-only pages under a refusing
    gate, the consumer's form: a read-only shared mapping, a dma-buf source on Linux;
  - checked in each: the gate asked once with the pages, the source never called, a copy that
    reads the bytes and a CPU write through the writable mapping;
  - a blit fill completes with the pages unchanged, nothing merged back, copied_dropped_bytes the
    fill's changed bytes, and a later command buffer reading the pages' bytes;
  - Linux: the rebind under an admitting gate whose dma-buf import fails is a degraded copy that
    drops the writes.
- Unit: restore, merge_back of an unwritable copy, mapped_writable (Linux and macOS).
- Negative controls:
  - the three refusing-gate tests on the unfixed runtime: RTX 5080 3/3 fail with
    OutOfMemory(Device) at the call; M3 Max 3/3 die with SIGBUS;
  - the admitted test with only the source-failure copy arm removed: the 5080 fails with
    OutOfMemory(Device).

Verified:
- RTX 5080 Laptop, NVIDIA 615.71.09 (msi; four holds, each under a minute): runtime
  copied_device|rebind|host_ram_device|tests::copied::|can_be_written 52/52 at the final tree. The
  admitted test's copy path ran (its line printed).
- M3 Max, MoltenVK 1.4.2, --cfg m2v_gpu under maclock and memcap: the same filter 49/49 (the
  admitted test is Linux-only).
- Mac: degradation_catalogue, copied and host_memory unit tests with api_surface and
  published_crates 37/37; api_signatures and fast_paths 16/16; clippy --workspace --all-targets
  --all-features, plain and --cfg m2v_gpu, clean; rustdoc -D warnings for the runtime clean.
- msi: clippy -p metal2vulkan-runtime --all-targets --all-features --cfg m2v_gpu clean.
- Not run: the validation suites. The runtime-sources pin is left for landing.

One work packet, landed as 2 commits on archive/development-linear-2026-10-29: 5012056c31, then 6385d650b9 (the re-pin).
2026-10-29 15:43:55 +02:00
Anees Iqbal c0617d796e Rebinds take the copy where the gate refuses: heaps, images in place, moved bytes, one-run chunks
The NVIDIA RAM route's rebind part, with RunResolver's doc saying a rebind asks it.

One work packet, landed as 4 commits on archive/development-linear-2026-10-29, in order:

* Rebinds take the copy where the gate refuses: heaps, images in place, moved bytes, one-run chunks (c0e37e8984)

The NVIDIA RAM route's rebind part (consumer spec, part 4). A buffer's rebind
with an image in place over it, and a heap's rebind, now take the copy of the
new pages (copied_pages) where the caller's gate refuses their import or the
admitted import fails, instead of refusing NotImplemented(RebindTextures) or
failing the call. Heap rebinds ask the gate like any import. A buffer's
rebind to bytes at another offset in their page, under a texture planned at
the old offset, takes a copy laid out at the old offset (the gate unasked:
nothing is imported) instead of refusing.

- The copy's memory, where images will bind in it, holds the window's whole
  pages from a multiple of the import's unit. The heap's textures bound to
  its bytes and the images in place over the buffer are made again over the
  copy: in memory the device allocates, as linear images that start
  PREINITIALIZED, whose first move keeps the copy's bytes (Vulkan: "the
  transition away from this layout will preserve that data").
- Where images in place ride on the copy, it lies in fresh pages the runtime
  maps and imports by pointer (Device::fresh_page_buffer), and each image is
  made as over the caller's pages for host allocations, under the device's
  in-place check for fresh pages (PagesClass::Fresh, else RebindTextures).
  On the RTX 5080 the driver's own linear image does not lie at Metal's
  256-byte pitch, so the first form still refused there.
- The run resolver at rebind (ram1's route_runs and bind_in_chunk): asked once
  with the new window, on the calling thread with no runtime lock held,
  before the gate. One run inside one chunk binds in the chunk's import (no
  import, no gate); any other answer takes the gate, then the import or the
  copy. The runs are kept with the new pages, copies included; bytes moved
  in their page are never chunk-bound.
- Metal's rebind order is unchanged: the pending check runs before the gate,
  and committed-not-submitted command buffers are encoded again over the
  copy.
- RebindTextures stays, for a device that makes no image over the copy at the
  texels' pitch, memory type or alignment, and for drops-writes buffers
  (option bit 24) whose bytes moved.

WorkCounts (new): copied_rebind_pages_moved (a third cause within
copied_host_buffers_made) and copied_rebind_images_made. No new Error
variant. heap_raw_image takes (memory, at) and a memory-type check.
RUNTIME_VERSION 1702.

Docs: HOWTO copied host buffers and guest RAM, API.md copied-host-pages,
FAST-PATHS (the heap and in-place rebind exception removed from the known
gap), the runtime README, ImportGate, HostMemory::with_runs and
with_import_gate, rebind.rs, copied.rs module docs, RebindTextures;
REFUSALS.md and api_signatures.tsv regenerated.

Verified:
- RTX 5080 Laptop, NVIDIA 615.71.09 (msi, one hold): runtime
  copied_device|host_ram_device|rebind|in_place 48/48; the image over the
  copy is made (copied_rebind_images_made asserted 1) in the gate-refused,
  moved and ordering tests. Validation rebinds|dma_buf_imports 28/30: the two
  failures (ycbcr planes over chunks "off the grid", dma-buf in place "one
  run") also fail at development 2cfd8d6ef9 on the same GPU.
- M3 Max, MoltenVK 1.4.2, --cfg m2v_gpu under maclock: runtime host-memory
  filter 157/157; validation rebinds|dma_buf|copied|no_copy|host_memory
  75/75; at the final tip copied_device|host_ram_device|rebind 40/40. Here
  textures over buffers are shadows, so only the heap image over the copy
  runs (1 per heap test).
- 7 new device tests: gate-refused buffer rebind with a texture over it,
  moved bytes, heap rebind gate-refused and import-failed, ordering with a
  held and an uncommitted command buffer, resolver at rebind (one run binds
  in the chunk; two runs go gate then copy).
- Focused non-device tests 76/76; clippy plain and --cfg m2v_gpu clean;
  rustdoc -D warnings clean for the runtime.
- Not covered by one venue: both images over a copy at once.

Lane commits: ws/ram3-lane (d3945d0d9d, 7a114b599e, b93a6c1eac, 8b9fa5fb46).

* Re-pin the runtime sources at the landing tip (7f76090454)

* Say that a rebind asks the run resolver, as c0e37e8984 made it (8dcba47435)

RunResolver's doc still said a rebind to new pages does not ask it. Since
c0e37e8984 a buffer's or heap's rebind asks it once with the new window,
before the gate, except where the bytes moved in their page under a
texture, which take a copy without asking (with_runs' and
Buffer::rebind_bytes_no_copy's docs already say so). Doc only.

* Re-pin the runtime sources at the landing tip (17896b4366)
2026-10-29 15:43:55 +02:00
Anees Iqbal 7d1323ebcc Convert extended-range, padded and bfloat texels by the device's arithmetic
A read is float(c - 384) times the f32 nearest 1/510 (a padded code's float(c)
times 1/1023), a write RoundEven(clamp(v)*510)+384 (padded *1023), an sRGB
twin's colour the MSL transfer by the device's Pow on the magnitude, a half
result the device's narrowing, a bfloat code its bit shift with NaNs as
computed. Metal's correctly rounded quotients, exact-product rounding, ties-away
half rounding and its extended/padded sRGB tables leave the shader path:
extended_range/table.rs, R10X6_SRGB_DECODE_STEPS, round_exact_product(_lanes)
and the plan's table fields are deleted. Each such module records
DevicePackConversion; FAST-PATHS' air.pack row and API.md's catalogue state the
bounds (one f32 ulp, one code, half a 2^-13 sRGB step, R10X6_SRGB 1.64 steps).
The host-side clear_texel and the bicubic code still read extended_srgb.rs's
tables, so on an sRGB twin a clear and a shader write can differ by one code.

Verified: 331 touched lib tests; clippy plain and m2v_gpu; rustdoc; conformance
ledger tests; M3 replay of 89 extended-range cases (exit 0, 276 ledger rows,
+254/-57 against development); validation heap_extended on the M3 (6/6); the
new tests fail with FDiv decode. Golden: 346 cells in 20 heap/argument-buffer
subjects move (blessed on development). Translation words of an sRGB twin's read
4433 -> 588, write 5540 -> 632.

One work packet, landed as 2 commits on archive/development-linear-2026-10-29: 8acec5a4a2, then 96d8394995 (the re-pin).
2026-10-29 15:43:54 +02:00
Anees Iqbal 76d89d87a8 See an event signal behind a copied host buffer at its completion turn
An event signal behind a copied host buffer is seen at the batch's completion turn, and the
copied host pages' cost is announced as the catalogue states it.

One work packet, landed as 4 commits on archive/development-linear-2026-10-29, in order:

* See an event signal behind a copied host buffer at its completion turn (8fc9c56dcb)

A batch's event signal is its GPU signal of the event's timeline semaphore,
and the host read the semaphore's counter directly (`EventShared::value`),
while a copied host buffer's GPU writes reach the caller's pages only at the
batch's completion turn (`completion.rs`, merge then `reached`). So a CPU
that saw the value could read the pages before the GPU's writes, and a plain
event's wait chained on the VkQueue let another queue's work start before
them: Metal's writes before a signal are in the pages once its value is
seen (the documented gap in FAST-PATHS, now closed).

A signal kept while the device holds a live copy is marked behind the merge
(`EventTimeline::keep`). No counter read observes it or any signal after it,
and no wait is handed its index (the scheduler's own host wait included); a
plain event's wait for it is held as a shared event's is. The completion
turn, which merges first, observes it and wakes every host wait and held
batch. The signal stays the batch's GPU signal: no submission is added. The
cost per such signal: its value reaches readers one completion turn later
than the counter shows it, and a GPU wait for it is a host hold plus a
vkQueueSubmit at that turn. Counted: WorkCounts::event_signals_behind_merge.
The same mechanism will hold for the GPU-kept copies.

RUNTIME_VERSION 1699 (renumbered at landing).

Verified on the M3 Max (MoltenVK), --cfg m2v_gpu, under memcap and maclock:
57 copied, event, scheduler and fast-path tests pass, among them the new
a_shared_event_s_value_is_seen_once_the_copy_s_bytes_are_in_the_pages
(six rounds, spin reads and host waits, a 64 MiB copy beside to lengthen
the merge) and the timeline unit test
a_signal_behind_a_merge_is_seen_at_its_completion_turn_alone. Negative
control: with the mark off, the device test fails on the byte check
("the write is in the pages once the value is seen"). clippy (plain and
--cfg m2v_gpu) on metal2vulkan and metal2vulkan-runtime, api_signatures
re-blessed (the new field), api_surface pass.

RUNTIME_VERSION 1700.

* Re-pin the runtime sources at the landing tip (2cef515da6)

* Announce the copied host pages' cost as the catalogue states it; list what pack.rs reaches (e9ba27478b) (its crates/metal2vulkan-runtime/src/degradation.rs part)

The final gate on 3e20b58763 failed two tests.

- degradation_catalogue: the signal-behind-merge fix (8fc9c56dcb) closed the
  shared-event gap and rewrote the API.md entry for copied-host-pages, but the
  runtime still announced "(behind a shared event's value among them)". The
  announced cost now drops it, so the catalogue's entry starts with it word
  for word again.
- the_runtime_sources_are_the_committed_ones: pack.rs became a runtime input
  (the mipmap kernel's sRGB transfers), and it also reaches
  metal2vulkan-air's intrinsics, lower/arith/math.rs and lower/arith/narrow.rs
  through its pack and unpack intrinsics, which only the compile emits. They
  are listed as not runtime with that reason. The stale comment about
  srgb.rs's encode, tables and steps (deleted by the mipmap and n7 packets)
  now says only what is true.

Verified: the two tests on the landed tip (see the landing).

* Re-pin the runtime sources at the landing tip (538f3f1161)
2026-10-29 15:43:54 +02:00
Anees Iqbal f4394b8712 Copy a no-copy buffer's pages the kernel cannot pin where the process maps them readable
Cause: a copied host buffer (the caller's gate refused the import, or the admitted import
failed) read its first bytes only through the kernel: `process_vm_readv` of our own pid on
Linux. That read pins each page, and no page of a VM_PFNMAP or VM_IO mapping can be pinned, so
on a dma-buf's mapping (udmabuf's on Linux 7.2) it fails although the pages are mapped
readable. `CopiedBuffers::add` then answered `NotCopied::Unreadable`, and the buffer, heap or
rebind was refused as not importable (`Unsupported { HostMemory, NotRepresentable }`): the copy
never worked for dma-buf mappings, which is where a consumer's gate refuses imports on NVIDIA
at the kernel's default vm.max_map_count.

Fix: where the kernel's read fails, the copy asks the process's mappings whether every page of
the range is mapped with read permission and, if so, reads it with plain loads, the access the
copy's comparisons already make at every commit and completion (`copied::read_caller`). The
mapping check generalizes the import's write check: `PROCMAP_QUERY` tests
`PROCMAP_QUERY_VMA_READABLE` as it tested `..._WRITABLE`, and before Linux 6.11 the
/proc/self/maps lines' `r` as their `w` (`host_memory::Access`, `queried_permitted`,
`permitted`, `mapped_readable`). Pages not mapped, or mapped without read permission, are still
refused. All three users of `add` (buffers, heaps' own buffers, rebinds) take it. Off Linux
nothing changes (no mapping is asked; macOS's mach_vm_read path as before). RUNTIME_VERSION
1696 -> 1697 (renumbered at landing). Docs: API.md's copied-host-pages entry, HOWTO's copied
host buffers, the runtime README, and FAST-PATHS' known gap with the measured cost.

Evidence (verified):
- msi (Linux 7.2.8, RTX 5080): tests::copied + tests::host_memory 21/21; the udmabuf test
  printed "the kernel cannot read this udmabuf mapping: copied with plain loads".
  Under the GPU lock on NVIDIA: tests::copied_device + tests::copied 15/15, among them the new
  copied_buffer_is_made_over_a_dma_buf_mapping_the_gate_refuses (gate refusal -> copy made,
  announced, CPU writes copied in and a fill merged back over the udmabuf pages).
- Negative control on msi: with the fallback disabled the two new copied tests and the new
  device test FAIL (the device test at the buffer's refusal); restored, PASS.
- macOS (M3 Max, MoltenVK, under maclock): copied, copied_device, host_memory 25/25; plus
  degradation, catalogue and fast_paths 45/45.
- clippy -D warnings clean: macOS plain and --cfg m2v_gpu; Linux (msi) plain and
  --cfg m2v_gpu, runtime crate, all targets, all features. rustdoc -D warnings clean (runtime).
- Cost, release, msi: one add of a 64 MiB udmabuf range 15 ms (the failing kernel read 6 us,
  the mapping query 22 us); each comparison of a 64 MiB copy 22-41 ms on the CPU; on NVIDIA a
  live 64 MiB copy makes each empty command buffer's commit and wait 45-68 ms (0.2 ms without).
- Not run: the Mac's Linux container exposes no /dev/udmabuf.

RUNTIME_VERSION 1698 at landing.

One work packet, landed as 2 commits on archive/development-linear-2026-10-29: 1612481fb3, then 95852120a3 (the re-pin).
2026-10-29 15:43:54 +02:00
Anees Iqbal 63859d8cc1 Sum emulated filters' taps in the device's arithmetic
Rule 1: where the device has a native form it is the only form. The
emulated filters reproduced Metal's datapath bit for bit: a 2^-16
Catmull-Rom weight table, two-word integer sums truncated onto grids
and rounded half up, exact quotients, ties-away half rounding, a 12-bit
sRGB grid snap, 64ths of a level and 256ths of a blend, and the
anisotropic filter's piecewise log2 and chord exp2. All of it is gone.

Bicubic (lower/sampler/bicubic.rs, bicubic/routines.rs):
- One routine, `Plane::sum`: Catmull-Rom weights computed in f32 from
  the fraction (vec4 Horner), the sixteen taps summed by the device's
  multiply and add, rows then columns; Metal's bilinear rule (32-bit
  float formats, a level under four texels) is the device's FMix of
  the four inner taps already fetched; UNORM/SNORM clamps.
- 1D: `Line::sum`, the device's FMix of its two taps.
- An 8-bit sRGB twin's taps are the device's transfer, not the
  1/4095 grid. A half result is the device's narrowing
  (`narrow::round`), not ties-away.
- Kept: Metal's footprint, addressing, mirror pin, filter selection,
  `Quad::exact` (in-place YCbCr's filter, owner form H, not touched).
- Deleted: the weight table routine, the exact/half/accumulated plane
  and row routines, the block and float-quad routines, their words and
  specials; metal::bicubic's test-only table and its test.

Extended range (lower/sampler/extended.rs):
- Linear, 3D and the linear mip filter's level blend decode their taps
  through xrconv's functions as they are, then FMix in f32 at the f32
  fractions; the level weight is the f32 fraction, not 64ths; a half
  result is the device's narrowing. Bicubic clamps into the format's
  decoded endpoints. The in-place decode keeps `Quad::exact`.
- Deleted: the step tables' callers (steps_of, step, level_taps,
  half_of) and, in xrconv's extended_range.rs and texel_round.rs, the
  helpers only they used (STEPS_WORDS, has_steps, steps, step_grids,
  ratio_by_255_to_f32, normal_half_bits; minimal edits in another
  lane's files).

Anisotropic (lower/sampler/anisotropic.rs):
- The device's Log2 and Exp2 replace Metal's piecewise log2, chord exp2
  and truncations; the level and spacing are not rounded to 256ths,
  4096ths or a 6-bit mantissa.
- Each tap is one explicit-level sample: under a linear mip filter the
  fractional level, which the device's own linear mip filter blends.
  The two-samples-a-tap form existed because an RTX 3090's blend of a
  fractional level is not Metal's (1.03 codes off without anisotropy);
  under rule 1 that blend is the device's. A nearest mip filter's level
  stays whole (the 3090's anisotropic sampler blends the next level at
  a fractional level whatever its mipmap mode).
- Kept: Metal's length, tap count thresholds, floor(256/n) weights,
  kappa fit and direction.

Notes: PrecisionNote::BicubicFilterArithmetic is reused, broadened to
the extended-range linear, 3D and level blends (select.rs records it);
AnisotropicFilter's doc names the device's logarithm and blend. No new
variant, no ARTIFACT_FORMAT_VERSION bump. FAST-PATHS: the two
"not built yet / none known" bicubic rows are now one device-gap row
(the device's sum is the form); the known-gaps bullet loses the sRGB
grid snap. API.md's catalogue entries rewritten.

SEMANTICS_VERSION 1922 -> 1923.

Tests: the plane routine's interpreter differential against an f32
Catmull-Rom reference in the routine's order (fails on the old table
and integer sum), the line routine's FMix, the routines' word bounds;
engine_bicubic against the polynomial within 2^-18 (+ half ulp);
extended-range engine tests compare within the filter's bound
(`filtered_close`); xr_bicubic's `near` adds Metal's table's
deviation from the polynomial (WEIGHTS_BOUND 2.1e-3); anisotropic and
bias-reach tests count one sample a tap and two Exp2 per emulation.

Lanes and the conformance suite:
- runtime_lane::extended_range_samples compares linear samples within
  `xr_bicubic::filtered_close` (moved to devtools from the engine test,
  which re-exports it); two_plane_samples holds the digest of nearest
  cases only (a linear one's values are compared by the conformance
  suite's xr-two-plane-samples cases).
- runtime_lane::anisotropic_filter's bounds re-measured on the M3 Max
  with samplerAnisotropy withheld: linear 10.375 codes max (mean 0.21),
  nearest mean 0.82 and 6.7% of channels a code or more off, clamp to
  edge 6.531 max. Other devices not measured.
- conformance: the XR two-plane-samples and extended-range/padded
  extended-swizzles cases declare bicubic-filter-arithmetic; 32
  known-gaps rows (Apple M3 Max) for the linear sites the device's FMix
  moves.
- runtime-sources.sha256 re-pinned: metal/bicubic.rs lost its test-only
  table and docs; no run's behaviour depends on it.

Verified (this M3 Max, macOS 27.0.1): metal2vulkan + devtools suites,
3302/3303 passed (golden_hashes_match_the_table fails: 1001 cells moved,
not blessed). Module words of a bicubic sample (ANV Iris Xe profile):
xr_bicubic xrb_edge 12990 -> 2093, a2_bicubic_weights 15731 -> 3858,
bcx_rules 30727 -> 11388; anisotropic emulation (vk12-floor)
2705 -> 1884.

Also in this packet: the padded 10-bit formats' linear samples join the known gaps (d326b293c0), and the conformance coverage document is regenerated for the filter rows. Anisotropic emulation (devices without samplerAnisotropy only) now takes the device's Log2/Exp2 and level blend, and Metal's spacing roundings (r' to 256ths, g*S to 4096ths, S to a 6-bit mantissa) are gone with them: on the M3 with samplerAnisotropy withheld, linear reads up to 10.4 codes from Metal (mean <= 0.21), bounded in runtime_lane/anisotropic_filter.rs.

One work packet, landed as 2 commits on archive/development-linear-2026-10-29: abc366a2fa, then 8f506cb2fd (the re-pin).
2026-10-29 15:43:53 +02:00
Anees Iqbal 20287666c0 Blend extended-range attachments in the device's arithmetic; drop the 32-bit float Metal blend
Rule 1 (owner, 10-29): where the device has a native form, it is the only form.
An extended-range attachment's raw codes are something no blend unit reads, so the
shader still blends it (capability), inside the pixel interlock or over lavapipe's
input attachment. Its arithmetic used to be Metal's compiler's: lerps, common
factors, fusing by factor rank, half rounding at every step, a separate float4
model and computed-output tables. Now it is a blend unit's arithmetic: S*Fs op D*Fd
in float, in the order of the blend equation, with the source, second source and
blend color clamped to the form's range first (`extended_range::blend::native`).
- computed.rs is deleted. blend_color.rs keeps only the two source ranges.
- input_blend.rs and fetch.rs call native().
- The blend color is pushed as raw f32 bits (HalfBlendColor), so
  PushField::BlendColor is gone.
- Every blended extended-range output that stores a channel now records
  ExtendedRangeBlendSource (half) or ExtendedRangeFloatBlendSource (float).
- The refusals ConstantColorDifference, SrgbForm and FloatOutput are gone, as is
  the fast-math DualSource refusal for extended range. Every factor, operation
  and mask is built; only outputs other than four half or float lanes are
  still refused (Output).

The 32-bit float storage-form blend (`Blend::float32`, `fetch::float32_blended`)
computed Metal's fused forms in float. Every committed profile except
roadmap-2022 and vk12-floor sets COLOR_ATTACHMENT_BLEND on R32/RG32/RGBA32_SFLOAT,
so that form copied Metal's bits where the device blends natively. It is removed:
- a fetched 32-bit float attachment takes the generic float blend
  (UnmeasuredFetchBlend);
- one that is not fetched gets the device's blend after the pass splits.
The float4-output paths of the half/unorm8 model (Atom::Sf, Arith::Kept,
round_inner, Blend::float/narrow/takes_float) were dead after this and are pruned.

Removed:
- the Metal blend-table validation lane (extended_range_blend_table.rs)
- devtools xr_blends
- the xr_blend_table*.txt fixtures
- lower/arith/tests/blend32.rs
- the extended_range tests that pinned Metal's forms

Added:
- every_blend_is_the_devices_arithmetic: every form, 19 factors, 5 operations,
  rotating masks and adversarial sources, bit-exact against a float model of
  S*Fs op D*Fd
- every_blend_is_built_but_a_placeholder

Docs:
- FAST-PATHS: the "Metal's rounding per shape" fast row is removed. The
  extended-range blend is now a device-gaps row with the two notes. The
  32-bit float row and the interlock section are fixed.
- artifact.rs note docs and the API.md catalogue are rewritten.
- REFUSALS is regenerated, reach.tsv updated and api_signatures blessed
  (removed ExtendedRangeBlend::{ConstantColorDifference, FloatOutput, SrgbForm},
  PushField::BlendColor).
- Conformance: the two notes join replay::NATIVE_NOTES, and 16 Apple M3 Max
  known-gaps rows hold the xr-blend add/premul sites the device's arithmetic
  moves: one code, two at the sRGB premultiplied sites.
- SEMANTICS_VERSION 1923, ARTIFACT_FORMAT_VERSION 479.

Size: a premultiplied half4 fill into RGB10A8_2P_XR10 on moltenvk-m3 goes from
3275 to 1937 SPIR-V words (the blend itself from 2133 to 795). The float4 fill
goes from 3435 to 1951 words, and BGRA10_XR_sRGB premultiplied from 7992 to 6654.

Verified:
- metal2vulkan lib, touched modules: 511/511.
- Sabotage: rounding the source to half in native() fails
  every_blend_is_the_devices_arithmetic; restored, it passes.
- clippy, plain and with --cfg m2v_gpu; rustdoc -D warnings.
- M3 Max conformance replay of 25 cases: half-output-blends-*,
  blend-interaction-format-float32 and xr-blend-*-one-zero are justified; the 16
  xr-blend add/premul sites are held by the new rows.
  The replay exits 0 with the ledger held exactly. The conformance crate
  passes 1007/1007, CONFORMANCE-COVERAGE is regenerated, and runtime
  degradation/catalogue and api_signatures/api_surface/refusal_surface pass.
- M3 device tests (memcap + maclock, --cfg m2v_gpu): 11/11 of
  runtime_lane::extended_range_blends and framebuffer_fetch::generic_blend.
  The renamed blends_of_half_outputs_into_extended_range_texels asserts
  Metal's bytes for one-zero and prints the 16 add/premul outputs the device's
  arithmetic moves.

One work packet, landed as 2 commits on archive/development-linear-2026-10-29: 808143ef80, then 18431ee908 (the re-pin).
2026-10-29 15:43:53 +02:00
Anees Iqbal 9bd91540f4 Take the device's answers for fast atan2, half fmod and precise pow's NaN; delete exact sRGB leftovers
- fast::atan2 without every fast-math flag divides by the device's own
  reciprocal of x; past 2^126 the denormal it makes is the device's
  (DeviceDenormals through MetalFloatDenormals; NativeDivision as before).
  FastAtan2 { reciprocal_flushed } -> FastAtan2 { by_reciprocal }.
- A half fmod answers its float remainder rounded; the Metal zero-sign
  select is gone and the call records NativeTranscendentals through
  FloatFn::half_zero_of_float.
- Precise pow's NaN is classed BaseToExponentOne, so it records
  NativeNanEncoding like fast pow and atan2 (the measured() exclusion
  was left over from the removed pow(x,1) bit fix). Fast sin/cos keep
  DeviceNanEncoding on purpose: Metal answers +0 there, no NaN to stand for.
- Delete the exact sRGB pack/unpack's dead code: ArithPlan::srgb,
  Declared::srgb, SRGB_PACK/SRGB_UNPACK, srgb::TABLE_WORDS,
  math::unpack's normalized and sRGB branches (UnpackRounding,
  unpack_rounding, mul_exact, unpackable), word::srgb_code.
  WordAttachment::output_word returns Option<u32> (None for Srgb8).
  With the mipmap filter on the transfer (c9dd35e8a4), srgb's declare/
  word/step and SRGB_ENCODE_FIRST lost their last users and go too, with
  their texel_round test; SRGB_DECODE_STEPS stays for the ASTC and PVRTC
  decoders.
- FAST-PATHS: row 58 names half fmod; known gaps lose the atan2 and
  half-fmod lines. API.md: native-transcendentals, native-nan-encoding.
- SEMANTICS_VERSION + 1.

Verified: fmt, clippy (all features, m2v_gpu), rustdoc; metal2vulkan
arith/word/fast_paths 241/241, engine call notes + public fixture
expectations 20/20, api_signatures+api_surface 15/15, runtime 29/29,
validation c3 72/72; the atan2 tests FAIL on the old flushed reciprocal.
No conformance case reaches atan2, fmod or pow. Golden hashes: 21 rows x
19 profiles move (fast_atan2.f32 and fmod.f16 fixtures), re-blessed on
development.

One work packet, landed as 2 commits on archive/development-linear-2026-10-29: abb2b3db6e, then f76cdba457 (the re-pin).
2026-10-29 15:43:52 +02:00
Anees Iqbal 67a1651f35 Filter mipmaps by the device's arithmetic, not Metal's tables
The mipmap compute filter takes the device's arithmetic (pack.rs's sRGB transfer and half
conversions), and the validation guard lists the translator files it now reaches.

One work packet, landed as 5 commits on archive/development-linear-2026-10-29, in order:

* Filter mipmaps by the device's arithmetic, not Metal's tables (c9dd35e8a4)

Rule 1: the mipmap compute filter (extended-range formats, 8-bit sRGB
textures held as their UNORM twins, formats without blits or linear
filtering) reproduced Metal's bits inside a capability path. Its arithmetic
is now the device's: an 8-bit sRGB code decodes as c/255 through the MSL
transfer by the device's division and Pow and encodes by the transfer then
RoundEven(t*255) (pack's srgb_decode/srgb_encode, as the twin's shader reads
do since c70ec588c4); an extended-range sRGB code takes the same transfer on
its magnitude; a half takes UnpackHalf2x16/PackHalf2x16; a float's NaN is the
device's; the products and sums lose NoContraction. The twelve-bit and
8192-step tables, the k/4095 step, srgb::search and the integer half rounding
are gone (RG11B10Float's encode and RGB9E5's conversion stay: no device
instruction gives them).

cpu.rs is the bounded model: MipmapFilterChain::expected_levels is the chain
in IEEE f32, and the new MipmapFilterChain::outside_bound lists a device
level's texels outside 2^-17 of the terms' magnitudes (+2^-140) of the filter
of the level above as the device wrote it: a code at a rounding boundary, an
sRGB transfer within 2^-17 + 2^-20, one RGB9E5 mantissa step, any NaN. The
interpreter models GLSL Pow as the f64 power rounded once. Announced as
before by DeviceFilteredMipmaps; its docs, API.md's entry and FAST-PATHS say
the filter is the device's arithmetic. No version moves: the owned kernel is
built in-process and the driver cache keys on its words.

Verified: 475 touched and contract tests; the bind::mipmap_filter
interpreter tests FAIL with the old table decode restored and pass with the
change; clippy plain and --cfg m2v_gpu; rustdoc. Apple M3 Max: mipmap_chains
4/5 (5 formats within the bound, 8 texels off the IEEE model; the 3D blit
chain is the MoltenVK failure that predates this), runtime mipmap tests 13/13,
conformance blit-generated-mipmaps announced and justified. lavapipe:
mipmap_chains 5/5, 9 formats through the filter including both sRGB twins,
RG11B10Float and RGB9E5Float.

* Re-pin the runtime sources at the landing tip (187fa18b3d)

* List air.pack's lowering among the runtime sources the validation guard hashes (4020aeecc9)

The mipmap filter's owned kernel (bind/mipmap_filter/kernel.rs) takes its sRGB transfer and half
conversions from lower/arith/pack.rs since c9dd35e8a4, so the runtime's inputs reach pack.rs, and
the guard (candidate::engine::artifact::tests::the_runtime_sources_are_the_committed_ones) failed
on development's gate at 4052e2209c: "the runtime inputs reach files that are neither inputs nor
listed: lower/arith/pack.rs <- bind/mipmap_filter/kernel.rs". build.rs now lists pack.rs, and its
comment says srgb.rs's steps feed the ASTC and PVRTC decoders (the mipmap filter no longer reads
them). The hash moves with the new input; no runtime behaviour changes, so RUNTIME_VERSION stays
(the landing re-pins).

* Re-pin the runtime sources at the landing tip (821450aa43)

* Announce the copied host pages' cost as the catalogue states it; list what pack.rs reaches (e9ba27478b) (its crates/metal2vulkan-validation/src/candidate/engine/artifact/tests.rs part)

The final gate on 3e20b58763 failed two tests.

- degradation_catalogue: the signal-behind-merge fix (8fc9c56dcb) closed the
  shared-event gap and rewrote the API.md entry for copied-host-pages, but the
  runtime still announced "(behind a shared event's value among them)". The
  announced cost now drops it, so the catalogue's entry starts with it word
  for word again.
- the_runtime_sources_are_the_committed_ones: pack.rs became a runtime input
  (the mipmap kernel's sRGB transfers), and it also reaches
  metal2vulkan-air's intrinsics, lower/arith/math.rs and lower/arith/narrow.rs
  through its pack and unpack intrinsics, which only the compile emits. They
  are listed as not runtime with that reason. The stale comment about
  srgb.rs's encode, tables and steps (deleted by the mipmap and n7 packets)
  now says only what is true.

Verified: the two tests on the landed tip (see the landing).
2026-10-29 15:43:52 +02:00
Anees Iqbal df2bbfc3ab Merge a shadow over logged host pages back by its changes: words, or whole blocks where Metal rewrites them
Over host pages whose consumer logs every write, a pass replacing every texel takes the gated
merge, stored in whole 256-byte blocks; a loading, storing pass's attachment merges in whole
blocks of its area's rows; a kernel's and a blit's partial writes stay word by word, and
docs/FAST-PATHS.md says why.

One work packet, landed as 6 commits on archive/development-linear-2026-10-29, in order:

* Merge back a pass replacing every texel of a shadow over logged host pages (3b5b3b9b51)

A command that replaces every texel of a shadowed texture (ShadowUse::overwrites,
a cleared pass among them) took no copy in and no keep, and its copy back wrote
every texel it moved into the buffer's bytes: on a discrete GPU, 6 MB per
host_ab drag frame across PCIe for the 23 cleared 256x256 surfaces, whatever
changed. Over host pages whose consumer logs every write to them
(ShadowCopies::logged), such a command now takes the merge a command that
leaves texels in place takes: its gated copy in (only the rows the log reports
changed since the image's last copy, every row where the log cannot say), the
keep, the command, and the merge, which stores only the words the command
changed against the keep (shadow.rs, overwrites_unkept, and the module's
**Overwrites over logged pages**).

Metal's bytes: the gated copy in is decided once the log published the stamp
the command buffer asked at its commit, so the image and the keep hold the host
bytes as of the commit, every CPU write before it included, and a word the
merge leaves already holds the value the command wrote. A byte another writer
writes after the commit is one the command writes too, a race Metal leaves
unordered. Without a log the image may lag the CPU's writes, so there the copy
back stays a plain copy, as before. No switch: no byte differs from Metal's.

RUNTIME_VERSION development's 1692 + 1 = 1693 (renumbered at landing).

Verified on the M3 Max (MoltenVK), tests::dirty_pages_device:
- a_pass_replacing_a_logged_render_target_merges_back_the_words_it_changed:
  frame 1, 0 texels copied back and 1 merge; frame 2, the gated copy in takes
  the told row alone (256 bytes), the told CPU row the pass clears back to the
  image's old black ends black (Metal's), and a CPU row the log left out, which
  the pass clears to the black the keep held, keeps the CPU's 0x50 bytes: only
  changed words are stored.
- a_pass_replacing_an_unlogged_render_target_copies_it_back: 4096 texels copied
  back plainly and no merge, two frames.
Sabotage 1 (overwrites_unkept ignoring the log): the logged test fails (4096
texels copied back, 0 merges). Sabotage 2 (keep and merge without the copy in):
it fails on Metal's bytes (row 0 [16,16,0,16], want [255,0,0,255]). Restored:
dirty_pages_device, shadow, shadow_host_writes, shadow_merge_read,
shadow_carried_read, render::shadows and degradation tests 57/57 under
--cfg m2v_gpu; clippy plain and --cfg m2v_gpu (runtime) clean; rustdoc
-D warnings for the runtime clean.

* Store an overwriting pass's merge over logged pages in whole 256-byte blocks (d34f373d52)

Over host pages whose consumer logs every write to them, a command that
replaces every texel of a shadow (ShadowUse::overwrites, a cleared pass among
them) is merged back word by word since 3b5b3b9b51: only the words it changed
against the keep are stored. Where those changes are scattered, every warp's
store leaves gaps between words, which an RTX 5080 storing into host memory
over PCIe charges hundreds of times for (bind::shadow_merge's module docs:
590 ms against 0.85 ms per 8 MiB), where the plain copy back it replaced stored
every texel without gaps.

The merge kernels (bind::shadow_merge_module, shadow_merge_image_module and
its kept-image form) take a store form, bind::ShadowMergeStores { Words,
Blocks }. In the block form, the 64 words a workgroup takes in one step are one
256-byte block (ShadowMergeModule::BLOCK_BYTES), marked in workgroup memory
where a word of it changed (clear, barrier, atomic or, barrier); a marked block
is stored whole, a word it left as read, and no other block is read or written.

The form is chosen by structure, with no switch: blocks exactly for the merge
of a command that replaces every texel, cut to the texels' rows (so every word
it examines is texels' bytes, none between rows or past the last texel); every
other merge (partial writes, two ways, a linear attachment's) keeps the words.
That is Metal's answer: the command wrote every byte of every such block, as
the plain copy back stored them all, so a word it left is stored with the value
the merge reads, which differs from the command's only by another writer's
write since the commit, a race with the command's own write. A scratch made for
one kind of command is kept again only for the same kind; a command of the
other kind merges it and takes a new one. WorkCounts gains
shadow_merge_dispatches_in_blocks. RUNTIME_VERSION 1693 + 1 = 1694.

Public API: bind::ShadowMergeStores (new), shadow_merge_module /
shadow_merge_image_module / shadow_merge_kept_image_module take it,
ShadowMergeModule::BLOCK_BYTES, WorkCounts::shadow_merge_dispatches_in_blocks
(api_signatures re-blessed, api_surface lists the enum).

Verified on the M3 Max (MoltenVK):
- tests::dirty_pages_device::a_scattered_overwrite_of_logged_pages_merges_back_in_whole_blocks:
  a 1024x1024 target over 4 MiB of logged pages, the CPU's texels (told to the
  log) grey at every other texel; a pass clearing to black (one pixel drawn
  red) merges 8 of 8 dispatches in whole blocks and leaves the pass's bytes, the
  CPU's grey texels black; a pass loading and drawing black everywhere changes
  the same words and merges in words (0 of 8 in blocks), same bytes. GPU time
  median: blocks 1.318 ms (4 MiB stored), words 1.096 ms (2 MiB stored).
- Sabotage (never choose blocks): that test fails (0 of 8 in blocks).
- Device tests dirty_pages_device, owned_pushes, shadow, shadow_host_writes,
  shadow_merge_read, shadow_carried_read, render::shadows: 42/42.
- Interpreter tests of both forms (ported from the measurement branch): equal
  bytes in both forms and orders, two barriers per invocation in blocks, and a
  current buffer holding only the first block, so any access to an unchanged
  block traps; bind::shadow_merge*, owned_divisions, api_surface,
  api_signatures 26/26.
- clippy workspace plain and runtime --cfg m2v_gpu, rustdoc -D warnings.

* Re-pin the runtime sources at the landing tip (44c96cfdf8)

* Merge a loading, storing pass's attachment back in whole blocks of its area's rows (2fcdb470fe)

A render pass that loads a shadowed color attachment and stores it, changing
it only inside its draws' scissors (ShadowUse::area), merged back to the
buffer's bytes word by word: only the words it changed against the keep. Where
those changes are scattered, a GPU storing into host memory over PCIe pays for
every separate run of words in a 64-byte host line (about 180 ns each on an RTX
5080, serialized: 88 to 102 ms for every other word over 4 MiB, against 0.4 ms
in whole blocks).

Metal itself rewrites such texels. Measured on this M3 Max's Metal (macOS
27.0.1, an ObjC harness, not MoltenVK): a 512x256 RGBA8Unorm texture over a
no-copy Shared buffer, 300 passes each loading and storing it and drawing one
pixel (a long fragment loop, about 2.9 ms of GPU time each), while a CPU thread
wrote a fresh value to every other texel over and over and checked that each
read back its last write. For points at (70,70), (200,130), (10,10) and
(100,33), the other 1023 texels of the 32x32 tile holding the point reverted to
an older value in 157 to 229 of the 300 passes each; no texel of any other
tile reverted, inside the render area (renderTargetWidth 384) or past it. A
kernel writing the same texel reverted none (0 of about 1.1e9 checks). So a CPU
write to a texel such a pass leaves inside its render area, made while it runs,
is not kept on Metal either.

ShadowUse gains tile_stores: a color the pass loads and stores inside its
bounded area (render/shadows.rs), joined like area (a draw's write through the
texture another way clears it, a read keeps it). shadow::stores_blocks takes it
with the overwrites rule, and MergeFor::overwrites becomes MergeFor::blocks
(KeptArea::for_overwrite -> in_blocks, ShadowMerge's flag alike): the merge of
such a pass, when its keep is the pass's area, is cut to that rectangle's rows
and stores whole 256-byte blocks (bind::ShadowMergeStores::Blocks), each
holding a changed word as one store, no other block, nothing outside the rows.
Over any merged-back bytes, logged or not: a block's unchanged words are stored
with the value the merge reads, so only a write between that read and the
store is undone, a shorter window than a tile's load to store. A block can
reach past the tiles the draws reach (64 RGBA8 texels of a row, two 32-texel
tiles), never past the rectangle. Docs: shadow.rs **Stored attachments**,
shadow_merge.rs, bind::shadow_merge, WorkCounts::shadow_merge_dispatches_in_blocks,
API.md (shadowed-texture entry), FAST-PATHS known gap (now the partial writes
of kernels and blits). RUNTIME_VERSION 1695 + 1 = 1696.

Verified on the M3 Max (MoltenVK):
- tests::shadow::a_pass_storing_its_loaded_area_merges_in_whole_blocks (new):
  blocks for a bounded loaded-and-stored pass; words unbounded, without tile
  stores, or joined with a draw's write; a read keeps them. Sabotage (never
  tile stores): FAIL; restored: PASS.
- tests::dirty_pages_device::a_scattered_overwrite_of_logged_pages_merges_back_in_whole_blocks:
  the Load pass drawing every texel now merges 8 of 8 in blocks (the old form
  asserted 0), same bytes; GPU time median 1.078 ms (clear leg 1.860 ms).
- tests::dirty_pages_device::a_pass_storing_its_loaded_area_keeps_a_cpu_write_beside_it
  (new): a Load pass drawing a 64x64 square over 4 MiB of logged pages while a
  CPU thread writes three texels beside it (the next block of its rows, far
  right, below) from before the commit to after the completion: 8 of 8 in
  blocks, 12.4 million CPU writes, each texel ending with the CPU's last write,
  every other byte Metal's.
- Device tests dirty_pages_device, shadow*, owned_pushes, render::shadows: 45/45.

RUNTIME_VERSION 1696 -> 1697 (renumbered at landing). Metal's own tile stores measured on the Apple M3 Max with an ObjC harness: 300 Load+Store passes drawing one point while a CPU thread rewrote every other texel; the 1023 other texels of the drawn 32x32 tile reverted in 157-229 of 300 passes, no texel in any other tile did, and a compute kernel writing the same texel reverted none in ~1.1e9 checks. A 256-byte block can reach the neighbouring tile within the scissor rectangle (64 RGBA8 texels), never beyond the rectangle: documented in shadow.rs's "Stored attachments".

* Re-pin the runtime sources at the landing tip (3da7eb9189)

* Say why a kernel's and a blit's partial writes merge back word by word, never in blocks (2e2e238346)

The owner decided (10-29) to keep whole-block merges out of kernels' and
blits' partial writes. Blocks rewrite the unchanged bytes inside each
256-byte block with the value the merge read, undoing a CPU write made
meanwhile. Metal keeps such a write beside a kernel's write: on the M3 Max
(macOS 27.0.1, an ObjC harness over a no-copy Shared buffer), a kernel
writing one texel lost none of a CPU thread's writes to the texels around
it in about 1.1e9 checks. A pass that loads and stores its attachment
rewrites the whole 32x32 tile it draws in (157 to 229 of 300 passes), which
is why only those passes, and commands that write every texel, take blocks.
Blits weren't measured; they keep the kernel's rule.

FAST-PATHS' known gap for the word-by-word merge now says so. Docs only: no
runtime source changes, so the runtime-sources pin doesn't move.
2026-10-29 15:43:51 +02:00
Anees Iqbal e84d5a4b60 Take the device's float denormals in ldexp
ldexp reads and makes float denormals by the device's multiply, records DeviceDenormals only
where the profile's MetalFloatDenormals deviation does not already answer as Metal does, and
the float-tininess notice names it.

One work packet, landed as 4 commits on archive/development-linear-2026-10-29, in order:

* Take the device's float denormals in ldexp, and fix stale exact comments (11eaace858)

math::ldexp_bits read a float denormal operand as zero and flushed a denormal
result on its bits, Metal's flush. A denormal operand is now scaled by 2^64
through the device's product (kept or flushed by the device's mode), and a
result below 2^-126 is the device's product with 2^-126, rounded once or
flushed. Every exponent is still answered (GLSL's Ldexp leaves exponents past
+128 and overflowing products undefined: capability); infinities and NaNs keep
their bits. ldexp leaves FloatFn::metal_denormals, so it records
DeviceDenormals; its rustdoc and docs/API.md say so. Word bound 320.
SEMANTICS_VERSION 1921.

narrow::to_bits is the device's narrowing since 0d7093d826; the snapshot module
docs, two leaf encode comments and ops::lane_bits' doc no longer call it exact.

Verified: the "ldexp f32, every exponent" check expects the denormal-keeping
product and fails on the old form (25 of 192 cases); lower::arith::tests
191/191; device_precision_float_functions, fast_paths, api_signatures,
engine_metal_denormals 25/25; rustdoc clean; clippy clean apart from the dead
code its base still held (deleted since by b7f6dec939).

* Leave ldexp's float denormals to the MetalFloatDenormals deviation (3298b30510)

Since 11eaace858, math::ldexp_bits reads a denormal operand and rounds a
result below 2^-126 by the device's float multiply: a denormal times 2^64, and
a normal times 2^-126. ldexp then recorded DeviceDenormals on every profile.
On a profile that takes DriverDeviation::MetalFloatDenormals the device's
multiply reads a denormal operand as the zero of its sign and flushes a denormal
result, which is Metal's ldexp answer, so the note there named no difference
from Metal. denormal::coverage now lists ldexp as Covered::Deviation, the same
rule as + - *: the module requires MetalFloatDenormals where the profile takes
it and notes DeviceDenormals elsewhere. half and bfloat are unchanged:
leave_denormals touches only f32 lanes. The module is the same on both sides
of the fact. Off MoltenVK, the device's multiply rounds before it flushes, so a
result whose exact value is within half a unit below 2^-126 is 2^-126 where
Metal answers zero. This is the same boundary as a float product, and
float-tininess-after-rounding already announces it on those devices.

The test float_denormals_are_the_devices_and_noted_off_the_device_fact still
treated den_ldexp and den_ldexp_tiny as Metal-on-the-bits kernels. They now
follow + - *: the requirement under the fact, the note without it, and the
device's word from the interpreter, which keeps denormals. The ldexp_bits
rustdoc, PrecisionNote::DeviceDenormals and docs/API.md's degrade-notice
catalogue now list ldexp with the deviation's operations. SEMANTICS_VERSION
1922.

Verified: nextest -E 'test(/^tests::engine_arith::|^tests::engine_metal_denormals::|^lower::arith::/)'
--test-threads 8: 261/261 passed (the failing test included, on moltenvk-m3 and
lavapipe with the fact on and off). cargo clippy -p metal2vulkan
--all-targets --all-features -D warnings: clean.

* Name ldexp in the float-tininess-after-rounding notice (53aefbfc60)

Since 3298b30510, ldexp on float computes a result below 2^-126 as the device's
product of a normal and 2^-126, so it takes the device's float multiply's
tininess. Off MoltenVK the device rounds before it flushes, so an ldexp whose
exact value lies within half a unit below 2^-126 answers 2^-126 where Metal
answers the zero of its sign. The notice's cost text named only the float
product and fused multiply-add. The notice, its rustdoc, the float_tininess
module doc, docs/API.md's catalogue entry and its DeviceDenormals entry, and
the FAST-PATHS.md row now name ldexp too.

The notice's trigger is unchanged and already covers ldexp. The device
announces it once at creation wherever its float functions are not Metal's
own (rounds_before_flushing: not MetalFloatFunctions), whatever its pipelines
hold. ldexp's product is the same OpFMul, so the same devices round it first.
No new trigger is needed, and modules and recorded notes are unchanged
(SEMANTICS_VERSION stays at 1922). The announced cost text is part of the run
(the stderr line and DebugMessage::text), so RUNTIME_VERSION goes to 1694. The
runtime-sources pin moves with degradation.rs and float_tininess.rs.

The "ldexp f32, every exponent" check gains the operand 2 - 2^-23. Times
2^-127 it is 2^-126 - 2^-150, which ties to even at 2^-126 on the interpreter,
a device that rounds first. A sanity assertion pins the expected word.

Verified: a negative control that expected Metal's flush for that one case
fails the check with "1 of 208 cases differ"; without it,
lower::arith::tests::device_precision_float_functions_are_valid 8/8 passed.
Runtime tests::degradation, tests::degradation_catalogue and
tests::device::the_device_s_multiply_rounds_a_tiny_product_before_its_flush_off_moltenvk
17/17 passed. metal2vulkan tests::fast_paths and the api_signatures binary
24/24 passed. Validation candidate::engine::artifact::tests 3/3 passed,
the_runtime_sources_are_the_committed_ones included. Workspace clippy (all
targets, all features, -D warnings) is clean plain and with --cfg m2v_gpu.
RUSTDOCFLAGS='-D warnings' cargo doc --workspace --all-features --no-deps is
clean.

* Re-pin the runtime sources at the landing tip (0d03676902)
2026-10-29 15:43:50 +02:00
Anees Iqbal bc1a6ebf8b Encode a half's bits by the device's narrowing, not an integer sequence
A half value whose bits are not known from a load (a store, a reinterpretation,
a texel's or snapshot's bits) is encoded by the device: with shaderFloat16 one
OpFConvert to 16 bits (NoContraction under the float controls), each lane read
as a word beside a 16-bit zero; without it GLSL.std.450 PackHalf2x16. The exact
integer sequence (rebias, NaN quieting, the 2^24 denormal scaling, the 0x7C00
cap under native rounding) is deleted. narrow::encodes_bits finds the
narrowing; compile.rs records the widening's notes for it: NativeNanEncoding
everywhere, NativeHalfConversion where neither the float controls nor
MetalHalfArithmetic cover it. Bits known from a load, folded constants, an
integer's half and bfloat stay exact. bits_words 136 -> 48 per lane.

Tests pinning the old NaN bits accept the device's where the note is recorded;
40 known-gaps rows the Apple M3 Max no longer diverges at are dropped (29
attribute-format-fetches half-NaN sites, 3 each of half-texel-nans-r16f/
-rg16f/-rgba16f, 2 of math-frexp-ilogb-half: Metal's own NaN bits now).
SEMANTICS_VERSION 1919.

Verified: 347 translator tests (lower::arith::tests, the touched engine
modules, every public fixture on every committed profile), clippy plain and
--cfg m2v_gpu, rustdoc; a sabotaged encode form fails the new
a_half_encode_is_the_devices_narrowing_in_every_form; on the M3 Max:
conformance replay of 28 half cases exit 0 (every divergence a held ledger
row), validation runtime_lane half tests 7/7, runtime nan_signs/vertex
conversion notices/degradation sites 4/4. golden_hashes.tsv cells move,
re-blessed on development. Not run: lavapipe, the full validation and
conformance sets.

One work packet, landed as 1 commit on archive/development-linear-2026-10-29: 0d7093d826.
2026-10-29 15:43:50 +02:00
Anees Iqbal ed114bcf43 Answer Metal's maths special values and fast functions by the device's instructions
The fast transcendental functions and the special values take the device's instructions, with
the precision contract's and c3's near-equivalent checks held at the device's notes.

One work packet, landed as 3 commits on archive/development-linear-2026-10-29, in order:

* Answer Metal's maths special values and fast functions by the device's instructions (d49cbcd398)

The fast sin, cos, tan, sinh, cosh, tanh and atanh are the device's Sin, Cos,
Tan, Sinh, Cosh, Tanh and Atanh on every device: no flush past Metal's last
evaluated quadrant, no kept denormal, no MSL Table 8.2 formula. The half zero and
NaN-sign tables are gone: a half function is its float instruction rounded. pow,
powr, fast::powr, atan2 and fast::atan2 keep only the C99/MSL special values
GLSL.std.450 leaves undefined (a negative base, 0^y with y <= 0, atan2(0,0),
infinities, pow's odd-integer sign), by the device's comparisons: no bit-level
denormal-as-zero reading, no canonical NaN over a NaN operand (the device's sum
instead), no pow(x, 1) = x, no flush of a denormal atan2 result. The fast
functions take libm::Fun entries of their own, so MoltenVK records
DeviceTranscendentals where its instruction is not Metal's fast function;
elsewhere NativeTranscendentals and DeviceDenormals as before; the NaNs no longer
claimed record NativeNanEncoding or DeviceNanEncoding. half fmod's zero stays on
the exact remainder routine (capability; no note path there yet). Dead code goes:
Lib's Metal mode and denormal::flush. FAST-PATHS rows, the libm module doc, and
API.md's fneg/fabs paragraph (now the device's OpFNegate and FAbs) and
native-transcendentals entry say so; known-gaps.tsv gains the M3's
fast-float-tanh row. SEMANTICS_VERSION 1918.

Verified: arith unit tests 192/192, engine tests of the path 42/42 (metal
denormals, arith, metal math, float call notes), fast_paths/profile/
api_signatures 47/47, runtime degradation and catalogue 17/17; clippy plain and
m2v_gpu, rustdoc; restoring pow(x,1) = x and a fast::sin flush fails the new
tests; conformance replay of pass-bytes-half-tanh-regimes on the Apple M3 Max
matches the ledger (exit 0; MoltenVK's Tanh is MSL's precise tanh, 2623 of 4096
words differ from Metal's fast::tanh, DeviceTranscendentals declared).
golden_hashes.tsv moves 1224 cells (65 rows over 59 fixtures), re-blessed on
development. Not run: lavapipe and other venues, the validation crate.

* Hold the precision contract's fast tanh at the device's Tanh notes (685db3e29f)

d49cbcd398 made a fast float tanh the device's Tanh instead of the MSL formula
the crate computed with a division of its own, so on lavapipe it records
NativeTranscendentals, not DeviceArithmetic, and on MoltenVK, whose Tanh is
Metal's precise tanh rather than its fast one, DeviceTranscendentals instead of
nothing. api_surface's the_precision_contract_names_each_float_operations_notes
still held the formula's notes and failed in development's gate at
b7f6dec939; it and its doc now hold the device's.

Verified: the api_surface binary passes (with fast_paths, golden_hashes and the
conformance ledger tests, 41/41) at 11eaace858.

* Hold c3's near-equivalent checks at the device's tanh and NaN notes (43a9c268e4)

d49cbcd398 made a fast float tanh the device's Tanh instead of the MSL formula
the crate computed with a division of its own, and left the NaN of pow and of
fast sin and cos to the device, so three c3 tests held the old notes and failed
on development:

- the_products_own_approximations_are_its_near_equivalents: tanh (fast or
  precise, float or half, lavapipe or MoltenVK) is now no near-equivalent;
  fast atan2 keeps DeviceArithmetic. Fast tanh(44) stays Apple's unstated word
  even where the row records DeviceArithmetic for another operation.
- a_nan_encoding_the_product_answers_is_not_a_near_equivalent: on lavapipe F32
  exactly precise pow and fast sin and cos record DeviceNanEncoding; the test
  asserts that set over msl::Prim::ALL. A differing NaN of fast sin(inf) and of
  precise pow(-1, 0.5) is now the note's (near_equivalent, open); precise
  sin(inf), mul and div keep the old answer.
- an_unstated_word_the_product_approximates_keeps_its_reading_open: fast fmod
  keeps its open reading and refusal (now the named-lowering check); fast
  tanh(44) is the device's answer, unstated, and the sign-off stands with
  DeviceArithmetic recorded.

Doc comments say what is true now. No product code changes.

Verified: cargo nextest run -p metal2vulkan-validation --all-features -E
'test(/^c3::/)' 72/72 passed (3 failed before); clippy -p
metal2vulkan-validation --all-targets --all-features -D warnings clean. The
lavapipe/MoltenVK note sets were read from lowering_notes for every prim.
2026-10-29 15:43:50 +02:00
Anees Iqbal ced4a0ecda Decode and encode 8-bit sRGB storage and twin texels by the device's transfer
Rule 1: a storage image of an 8-bit sRGB format (its UNORM alias,
SrgbEncode/SrgbEncodeBgra) and a slot bound to such a format's UNORM twin decoded
each code through Metal's twelve-bit step table and an exact k/4095 quotient, and
encoded by searching the table. The format is capability (Vulkan has no sRGB
storage; the device cannot sample the twin's format); the arithmetic is the
device's. Reads (alias, twin read/sample/gather/fetch, bicubic taps) take the MSL
transfer through the device's Pow (pack::srgb_decode_texel), a filtered twin
sample decoding the device's filter of the codes; every access records
SrgbTexelDecode. Writes take pack::pack's unorm4x8_srgb (DevicePackConversion).
The module declares no sRGB table for these paths; SrgbReach,
srgb_filtered_texel, the step/ratio helpers and Sampling::srgb_codes are gone.
Words per access: read 520 -> 194, filtered sample 920 -> 194, write 1520 -> 314,
bicubic tap 160 -> 106. Docs (artifact notes, API.md catalogue, FAST-PATHS rows,
doc comments) say so; runtime_lane::srgb_storage now holds the device's bounds,
with an alias-read test. SEMANTICS_VERSION 1917.

Verified: clippy plain and --cfg m2v_gpu, rustdoc; nextest 65 core checks + 98
touched-module + 17 runtime degradation pass; sabotage of the decode FAILS 2,
restored PASS; MoltenVK on the Apple M3 Max: runtime_lane::srgb_storage 4/4
(with the formatless storage features withheld, alias float reads within
1.83e-7 of the transfer, 762 of 1024 lanes differ from Metal's table; writes
within one code; srgb-texel-decode and device-pack-conversion announced);
conformance read-write-tier-round-trip-float and -held announced, justified.
Golden hashes unchanged. Not run: the twin on a device that takes it
(lavapipe, ANV, NVIDIA), release timing, the census.

One work packet, landed as 1 commit on archive/development-linear-2026-10-29: c70ec588c4.
2026-10-29 15:43:49 +02:00
Anees Iqbal 038bad9386 Take the device's conversions in the storage-form fetch and blend, imageblock tiles and snapshots
The storage form, implicit imageblocks and snapshot reads take the device's conversions, and
the MetalFloatStorageNans driver fact, which nothing reads once the blend keeps the device's
NaN, is deleted.

One work packet, landed as 2 commits on archive/development-linear-2026-10-29, in order:

* Take the device's conversions in the storage-form fetch and blend, imageblock tiles and snapshots (a049fcd0ee)

Rule 1 (owner, 10-29): where the device has a native answer, it is the only
form. The interlocked storage form, implicit imageblocks and snapshot reads
are capability and stay; the arithmetic inside them still computed Metal's
own bits. Each now takes the device's form, its difference noted with an
existing note:

- lower/fragment/fetch.rs: an 8-bit sRGB attachment's read and write through
  its uint view decode and encode by arith::pack's unorm4x8_srgb forms (the
  8-bit instruction and the MSL transfer by the device's Pow) instead of
  Metal's twelve-bit table (math::unpack/pack with the table); the module no
  longer declares the table for it. DevicePackConversion.
- fetch.rs: an 8-bit unorm blend's result is stored as computed, the storage
  image's store converting it (unorm8_write's exact product with 255, the
  NaN select and the clamp are gone). DeviceColorConversion, recorded in the
  storage write's plan.
- fetch.rs: a 16-bit float blend no longer makes every NaN 0x7FC00000; the
  NaN is the device's arithmetic's, which the store converts.
  stage_io/color_write.rs records DeviceNanEncoding for every such blend and
  no longer relies on VkProperty::MetalFloatStorageNans (storage_nan
  deleted; the deviation stays as a measured fact, now required by no
  module).
- lower/stage_io/word_color.rs: an 8-bit sRGB word's encode is
  arith::pack::pack (srgb_table and encode's table parameter deleted; its
  two other callers updated). DevicePackConversion.
- lower/access/tile.rs: a normalized implicit imageblock access unpacks and
  packs by arith::pack (instruction or its definition), a half access rounding
  the unpacked float once more by narrow::round, instead of math::unpack/pack
  with Metal's table and the exact c/D-to-half grid (half_channels,
  Norm::grid deleted). DevicePackConversion, but for a float conversion of a
  format GLSL.std.450 names on a device whose float functions are Metal's
  (MoltenVK), as air.pack notes it.
- lower/fragment/snapshot.rs: a normalized form's read decodes c times the
  f32 nearest 1/D (signed: at least -1) instead of exact integer division.
  DevicePackConversion.
- lower/arith/color_write.rs: the unorm rule is gone from round and
  channel_words (normalized deleted); a unorm channel is the device's
  conversion's. FloatNearestEven stays (Metal's textureWriteRoundingMode, a
  capability), as does unorm8_code for the private alpha test.

Dead in this tree and deleted: extended_range::blend::unorm8_write,
texel_round::grid_step, srgb::STEP_WORDS. Word estimates follow
arith::pack::words.

Tests: blend8's two blend checks now hold the blend's result, stored by
Vulkan's conversion, to Metal's code (unorm8_write's test deleted with it);
color_write checks that round takes no unorm rule (fails on the old form)
and its scalar/half test uses the small-float rules; snapshot_codes checks
the device's product c * fl(1/D) (asserted to differ from the quotient at
some code; the old exact test failed on the new form, seen); the
engine_fetch_blend8 tests require DeviceColorConversion (unorm8) and
DevicePackConversion (sRGB), which fail on the old form;
engine_fetch_blend16 requires DeviceNanEncoding on every profile and no NaN
property; engine_tile's normalized tests hold reads, stores and the
read-back within DevicePackConversion's bound (3 f32 ulp, one half step
more, codes within one) on the formats the interpreter models (no Pow: the
sRGB formats, and NaN stores, are the device lane's). Validation lanes: framebuffer_fetch::blend8 asserts the native note
alone on an interlock device and unorm8 channels within one code;
framebuffer_fetch::srgb accepts device-pack-conversion as a conversion;
tile_normalized checks reads and stores within DevicePackConversion's
bound; blend16::nans docs.

Conformance: known-gaps.tsv gains eight Apple M3 Max rows for
fetch-ordered-{bgra8unorm,rgba8unorm}-srgb (x1: a code apart, within the
note's bound; x2/x3/x3-depth: two, compounded across draws), the device's
sRGB conversion in the interlocked storage form.

Docs: API.md catalogue (DevicePackConversion, DeviceColorConversion,
DeviceNanEncoding, the sRGB word paragraph, the fetched sRGB and unorm8
blends), FAST-PATHS.md's air.pack row and the fetched-blend gap, the note
and deviation doc comments.

SEMANTICS_VERSION 1916 (emitted modules change). No public API change.

* Delete the MetalFloatStorageNans driver fact, which no module reads (e3f82758cb)

After the storage form's 16-bit float blend stopped making every NaN
0x7FC00000 (the device's NaN, noted DeviceNanEncoding), nothing reads
DriverDeviation::MetalFloatStorageNans or VkProperty::MetalFloatStorageNans:
no module requires the property and no lowering asks the profile for the
deviation. AGENTS.md's no-dead-code rule, and the owner's approval of deleting
unread facts (the 10-27 unread-fact sweep, 7b4509b9c4's precedent), remove
them.

Removed: both public variants and their docs; the five measured rows
(MoltenVK on Apple9, RADV on the 780M, NVIDIA on the RTX 3090 and the RTX
5080 Laptop GPU, lavapipe) and their measurement paragraph in
device/driver_facts.rs; the derive and profile mappings; the codec's
VkProperty entry; the driver_facts test rows (the deviation-to-property
table, the Apple, NVIDIA, lavapipe and 780M expectations); the
engine_fetch_blend16 split of interlock profiles by the deviation and its
"no such property required" assertions there and in engine_extended_range.
engine_fetch_blend16 still requires DeviceNanEncoding on every interlock
profile.

Corpus observations name the deviation only inside environment.profile, a
free-text Debug string of the profile (format!("{profile:?}"), a
serde_json::Value field nothing parses into an enum), so no reader changes
and no observation file is rewritten: the established handling, as the
MetalHalfQuantize name removed on 10-28 still stands in 152 observation
files. The profiles that took the deviation (moltenvk-m3, the two 780M RADV
profiles, the three lavapipe profiles, nvidia-rtx5080-laptop) change
fingerprint, so their golden cells and evidence re-key.

ARTIFACT_FORMAT_VERSION 478 (the encoded VkProperty list changed; the
orchestrator renumbers). api_signatures re-blessed (two variant rows gone);
REFUSALS.md regenerated, unchanged.

Verified: cargo fmt; clippy --workspace --all-targets --all-features -D
warnings, plain and with --cfg m2v_gpu; rustdoc -D warnings; nextest by
exact module: device::tests::{driver_facts,profile}, cache::tests,
cache::codec::tests, tests::fast_paths, tests::engine_fetch_blend16,
engine_extended_range::half_float_storage_slots_leave_their_writes_to_the_device,
api_signatures, api_surface, refusal_surface (130/130); validation index,
observation, observation_contract, c3, requirement,
candidate::platform::device (118/118).
2026-10-29 15:43:49 +02:00
Anees Iqbal 5f2c69e087 Decode a pulled normalized vertex field by the device's reciprocal product
Pulled normalized fields (vertex, [[stage_in]], post-tessellation) take the device's product,
and a post-tessellation pulled read records its NaN note as the vertex and stage-in reads do.

One work packet, landed as 2 commits on archive/development-linear-2026-10-29, in order:

* Decode a pulled normalized vertex field by the device's reciprocal product (33a8839b7c)

The owner's ruling of 10-29: no exact emulation where the GPU has a native
answer. A normalized field the shader pulls (a vertex attribute fixed-function
input cannot fetch, a kernel's [[stage_in]] attribute, a post-tessellation
function's) was Metal's correctly rounded quotient via exact_division::div_exact.
It is now the device's product float(c)*float(1/m), rounded once, the signed one
max(., -1), as fixed-function fetch already converts it (78ed264c90).

The product is within one f32 ulp of Metal's quotient: 126 of 256 8-bit unsigned
codes one ulp high; 16 signed 8-bit, 24 unsigned 10-bit, 512 unsigned and 1,536
signed 16-bit codes one ulp toward zero; 0, the maximum and -1 exact.
Int1010102Normalized stays exactly Metal's (Metal computes the same product).
Read as half, only 16-bit fields differ, at four codes.

fetch::conversion_notes records PrecisionNote::DeviceVertexConversion on every
profile where the product misses Metal's answer, at the vertex, stage-in and
tessellation pulled reads. Updated: the note's docs, the runtime Degradation
doc, the docs/API.md catalogue entry, the FAST-PATHS row, and known-gaps.tsv
rows for the M3 (constant step, stage-in) and llvmpipe (stage-in) 8-bit
unsigned sites; CONFORMANCE-COVERAGE.md regenerated. SEMANTICS_VERSION 1915.

Verified: fetch unit tests 13/13, including a decode that is FMul with no
UDiv/FDiv and an exhaustive note-versus-Metal check; restoring the old decode
fails 5 of them. Engine constant-step sweep on moltenvk-m3 notes 18 float4 and
8 half4 formats. Clippy (plain and m2v_gpu) and rustdoc clean; golden hashes
unchanged. On the Apple M3 Max: runtime_lane normalized_vertex_fetch 3/3 (its
legs take fixed-function fetch there); conformance replay of
vertex-format-constant-step and attribute-format-fetches (shader-pulled on the
M3: 10 sites read 0x3efeff00 where Metal reads 0x3efefeff, the note accepted)
exits 0 with the new rows; float4/half4/instance-step/class-crossings
unchanged. llvmpipe stage-in rows expected, not run.

* Record a post-tessellation pulled read's NaN note as the vertex and stage-in reads do (397e431a36)

A post-tessellation function's pulled attribute decodes through the same fetch::decode as a
vertex function's and a kernel's [[stage_in]] attribute's, so a narrow float format (a half
format, FloatRG11B10) read as float widens its NaN by the device's bits where Metal answers
0x7fc00000. The vertex and stage-in reads recorded PrecisionNote::DeviceNanEncoding for it;
lower::tessellation's pulled_read recorded only DeviceVertexConversion, so such a function's
artifact under-stated its difference from Metal.

The two note rules are now one function, fetch::decode_notes (DeviceNanEncoding for a narrow
float read as float, DeviceVertexConversion where the normalized product misses Metal's), which
all three pulled reads call; narrow_float_nans and conversion_notes are gone. The NaN note's doc
names the three reads. SEMANTICS_VERSION 1920: a precision note of an
artifact changes under an unchanged key.

Test: engine_tessellation::a_patch_attribute_s_decode_records_the_vertex_fetch_s_notes gives the
fixture's per-patch float4 tint a Half4 (DeviceNanEncoding), UChar4Normalized
(DeviceVertexConversion) and Float4 (neither) format on every committed profile with
tessellationShader. Restoring the pre-fix behaviour (the tessellation read recording only the
normalized note) fails it at Half4; restored, it passes.

Verified: nextest engine_tessellation, lower::stage_io, lower::tessellation,
engine_kernel_stage_in, engine_vertex_fetch, engine_vertex_variants, fast_paths and
api_signatures: 85/85.
2026-10-29 15:43:49 +02:00
Anees Iqbal 0a1851164d Copy a no-copy buffer, heap or rebind whose import the caller's gate refuses or that fails, announced
A new HostMemory::with_import_gate(ImportGate) asks the caller once,
holding no lock of the runtime's, just before a no-copy buffer, a
no-copy heap or a buffer rebind imports its pages, passing an
ImportRequest with the pages the import would map. If the gate answers
false, or an import the device and the gate admitted then fails
(OutOfMemory, another Vulkan error), the object is made over a copy of
the pages instead of failing. The default stays import-first. The copy
is host-visible memory owned by the runtime; `contents` stays the
caller's pointer. Each commit copies in the bytes the CPU changed since
the last sync, and each batch's completion merges back the bytes the GPU
changed (CPU wins where both wrote), byte by byte, before events,
waiters and handlers see it. Every copy is announced
(`copied-host-pages`) and counted. Pages the process cannot read are
never copied (the first copy reads through the kernel:
process_vm_readv / mach_vm_read_overwrite). A copied heap's buffers lie
in the copy and its textures are shadows. A rebind's copy is laid out as
its import would be. A rebind over an in-place image is refused
(NotImplemented(RebindTextures)) and a heap's rebind still imports
without asking. A caller's DirtyPages log stays attached to the copy as
to an import. The in-place check's pointer class skips copied buffers.

Ports dev-perf's fff961b7e5, 630d1b0174, 33d7aa5e98 and 9b4d4190f5 onto
a smaller coherence design: every live copy is compared in full at each
commit and completion, instead of dev-perf's log-driven,
encoder-collected copies (dev-perf's copied.rs, 79301a2515 and its
fixes, sat on a page log development has replaced). Also brings
789fa3d294's unreadable-page rule, 5190983470's lane site, and
1c7d49f788's copied-buffer skip. A driver that refuses the pointer
still fails the call (dev-perf copied there too; not taken). Known gaps
in FAST-PATHS: the compare costs O(size) per commit and completion, a
byte both sides wrote keeps the CPU's value, and a shared event's value
can be seen before the merge (c5db2d1b8a not ported). RUNTIME_VERSION
1690. Runtime-sources pin recomputed.

Public API: ImportGate, ImportRequest { start, length }
(#[non_exhaustive]), HostMemory::with_import_gate,
Degradation::CopiedHostPages, Device::fail_next_host_imports (test
hook), and the WorkCounts fields host_imports_refused_by_host,
copied_host_buffers_{made,refused,degraded}, copied_copy_in_bytes,
copied_merge_back_bytes, copied_rebind_pages_made, copied_heaps_made.

Verified on the M3 Max (MoltenVK, m2v_gpu): 11 new device tests
(tests::copied_device: buffer, rebind and heap, gate refusal and failed
admitted import, unreadable pages, a heap texture round trip) and 167
tests in the touched device filters pass; the counters move as
expected ([1,1,1,0,0] for a refusal, [0,1,0,1,0] for a failed import)
and the announcement is heard; on a 64 KiB copy 4079 bytes copied in and
4080 merged back for a 4 KiB CPU write and a 4 KiB fill, checked
exactly. Sabotage: ignoring the gate and removing the merge fails the 3
buffer tests; ignoring the rebind gate fails both rebind tests (no heap
sabotage). 249 host tests pass. Workspace clippy plain and
--cfg m2v_gpu, and rustdoc, clean; clippy re-run clean on the landing
merge. Not run on Linux.
2026-10-28 23:36:31 +02:00
Anees Iqbal d7d4870598 Wait a bound for a pipeline still being made, then drop its draws and dispatches
A cold MoltenVK compile inside one guest command buffer ran 11.59 s and
tripped the guest's own 10 s FIFO watchdog, which tore the task down;
development had no bound. New runtime choice DevicePolicy::pipeline_waits
(PipelineWaitPolicy::Bounded, the default, or Exact, which
exact_answers() selects), with bounds pipeline_creation_wait and
pipeline_commit_wait (4.5 s each, so one FIFO step waits 9 s at most).

Under Bounded:
- A render or compute state's creation hands its predicted making to the
  pool and waits for it up to the creation bound
  (WorkCounts::creations_left_making).
- A committed command buffer waits until its commit plus the commit
  bound for its draws', dispatches', tile dispatches' and execution
  replays' pipelines, then records each late one as nothing and runs on.
  CommandBuffer::dropped_draw names the first with VK_TIMEOUT. Counted in
  draws_dropped_still_making and dispatches_dropped_still_making, and
  announced as draw-dropped-still-making and dispatch-dropped-still-making.
- An execution's settle hands its makings to the pool.

A draw whose driver making failed now runs nothing and its command
buffer runs on, where it used to fail it: counted in
draws_dropped_unmade, named by dropped_draw(), and announced
draw-dropped-unmade (Degradation::DrawDroppedUnmade: the draw, its
state, a hash of the variant and specialization, and the driver's
error; once per device, or each time where announce_each asks). A
dispatch's failed making still fails its command buffer.

Docs: FAST-PATHS.md row, API.md policy bullet and catalogue entries,
runtime README Errors. RUNTIME_VERSION 1689. api_signatures.tsv
re-blessed. Runtime-sources pin recomputed.

Ports dev-perf 6f499ff764, 8c91a6e254, 33fc25b531, 5963fd6831 and
4ee316c55a, and the notice of aa7e78f23c in its minimal form (no per-key
set, no driver-message relay). The general-form predicted key
(7028c0d92a, ce02b68f23) is left out: on development it changed the
pipeline makings three M3 device tests count
(made_at_creation, pipeline_creation pooled making, its own
general_form_drawn), cause not found.

Verified on an M3 Max (MoltenVK 1.4.2), under maclock: the six bound and
drop device tests under both policies (the unmade one also asserts the
notice is heard once and names the driver's error), fast_paths,
degradation, degradation_catalogue, pipeline_wait_order,
inline_continues, dispatch_pending, api_signatures, api_surface and 169
profile tests: 218/218. Lanes on the M3: 42/44; the two failures are
ycbcr_textures::a_ycbcr_sample_through_an_unmeasured_filter_is_announced
(recorded failing on development before this change) and
pipeline_creation::draws_made_on_the_pool_draw_as_made_ones (1 pooled
making vs 2; fails the same under Exact; not yet run on development
without this change). Clippy plain and --cfg m2v_gpu and rustdoc
-D warnings clean. No sabotage run of the bound.
2026-10-28 23:15:01 +02:00
Anees Iqbal b25f89d0af Zero new buffers by a fill on a discrete GPU, and cut a tiled heap texture's merge work
- A new buffer whose bytes the host cannot write (Private, a Managed
  buffer's device copy, the neutral buffers) is zeroed by one
  vkCmdFillBuffer in the submission's first work on a device without
  unified memory whose fills are not transfers, in place of copies of the
  device's host-visible zeros, which such a GPU reads over the bus. Range
  ends must be multiples of 4. Counted: WorkCounts::new_buffer_zero_fills.
  Same bytes; no FAST-PATHS row.
- A heap's tiled texture's merge in place takes a kept scratch, unzeroed:
  its keep and changed copy write the texture's bytes whole, the bytes its
  kernel reads.
- A one-sample colour tiled texture kept right after its copy in
  (ungated, with no copy of its shadow between) copies the staging buffer
  that copy filled, in place of a move out of the image, tight buffer and
  dispatch. Counted: WorkCounts::shadow_keeps_from_staging. development's
  dirty-page gate stays as it is; a gated copy in keeps the move out.

Ports dev-perf b77843da73, c302c71029 and 01f17bde29
(archive/development-performance-2026-10-27); their measurements (RX
7900 XTX, RTX 5080) are dev-perf's, not re-measured here. RUNTIME_VERSION
1688. api_signatures.tsv: two additive WorkCounts fields. REFUSALS.md
unchanged. Runtime-sources pin recomputed.

Verified on the M3 (MoltenVK, under maclock): first_use, blits fills,
heap_layouts, shadow/merge, dirty-pages and tiled device tests (58 + 34
passed); the tiled merge took no zeroed scratch and every keep came from
the staging buffer (counters asserted); undoing each change fails its
test (3 scratches zeroed vs 0; 6 and 2 bytes differing). The new-buffer
fill path does not run on the M3 (unified memory); a forced local probe
zeroed all 5 MiB through the fill, and failed with the fill word set to
0xdeadbeef. Its unforced run needs a discrete GPU (the round's RTX 5080
run). Clippy plain and --cfg m2v_gpu, rustdoc, touched non-device tests
(338 passed).
2026-10-28 23:09:30 +02:00
Anees Iqbal 2f033d3002 Take the device's Y'CbCr conversion for 4:2:2 twins and for YCbCr planes read in place
4:2:2 twins hold the device's own conversion where it has Metal's reconstruction; planes read
in place are sampled through the device's Y'CbCr sampler where the driver lays them out as the
surface does; RADV's 10-bit conversion recorded as reading codes as words. With development's
golden re-bless after the native landings. SEMANTICS 1911, ARTIFACT 477, RUNTIME 1683.

One work packet, landed as 6 commit(s) (a1088b2c2e..67dc5650e1 on archive/development-linear-2026-10-28-evening), in order:

* Hold a 4:2:2 texture's twin as the device's own conversion where it converts the format

A GBGR422 or BGRG422 texture reads a decoded twin of 8-bit codes on every device: Vulkan views
G8B8G8R8_422_UNORM and B8G8R8G8_422_UNORM only through a sampler Y'CbCr conversion, which no
pipeline's layout bakes. Until now the twin always held Metal's decode, (3c + n + 2) >> 2, computed
by the runtime's own kernel or on the CPU, even where the device converts the format itself.

Now, where the device converts the pairs' format with Metal's reconstruction (its optimal tiling
reports SAMPLED_IMAGE, TRANSFER_DST, MIDPOINT_CHROMA_SAMPLES and a linear chroma filter, and the
width is even), the twin holds the device's conversion:
- each decode pass copies the written rows' pairs out of the carrier into the scratch, then into
  a per-texture image of the 4:2:2 format, and samples it through the device's conversion (the
  identity model at full range) into the band's texels, which go into the twin;
- the kernel is the new bind::chroma_sample_module (ChromaSampleModule), a sample at each luma
  texel's centre at level 0, each channel stored as roundEven(clamp(c, 0, 1) * 255);
- such a carrier takes no host or staging copies, so every write's decode is a GPU pass and no
  texel of the twin is the CPU's decode;
- counted in WorkCounts::chroma_device_twins and chroma_device_decodes, and announced
  decoded-texel-precision (the catalogue's cost text says so).
Elsewhere the twin keeps Metal's decode, as capability. The FAST-PATHS device-gaps table has the
row.

Venues (from the formats' features): MoltenVK 1.4.2 converts both formats (its single-plane 4:2:2
reconstruction is Vulkan's); lavapipe filters their chroma nearest only; RADV (Mesa 26.2.4, 780M)
reports neither format.

Verified:
- clippy -D warnings, plain and --cfg m2v_gpu, for metal2vulkan and metal2vulkan-runtime;
- chroma_decode unit tests (the sample module is valid on every committed profile), fast_paths,
  the degradation catalogue tests, api_surface and api_signatures (table blessed: the new module,
  ChromaDecode::format and the two WorkCounts fields);
- M3 Max (MoltenVK 1.4.2): tests::ycbcr_device::a_four_two_two_twin_holds_the_devices_conversion...
  took the device route for both formats (twins 1, passes >= 2, no CPU decode, announced once);
  chroma within 0.5000 codes of Vulkan's (3c + n) / 4 on 40 x 24 random pairs (the test also
  prints how many chroma codes differ from Metal's; that line is compiled and clippy-clean, not
  yet run);
  runtime_lane::chroma_pairs (5 tests) pass, the read lane checking green exactly and red and
  blue within 1/255 of Metal's on the device route;
- lavapipe (arm64 linux-gate, m2v_cpu_icd): the same runtime test and the five chroma_pairs lane
  tests pass; no 4:2:2 texture took the device route (twins hold Metal's decode, exactly);
- RADV 780M: not run (host away).

docs/REFUSALS.md regenerated: unchanged. runtime-sources.sha256 updated; the RUNTIME_VERSION
bump is in the versions commit.

* Record that RADV's 10-bit Y'CbCr conversion reads codes as words

RADV has the same defect lavapipe has (RuntimeDriverDefect::TenBitCodesReadAsWords): a sampler
Y'CbCr conversion of G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16 reads each code's 16-bit word as a
16-bit UNORM value, its six unused low bits included, where Vulkan converts the 10-bit code as
c / 1023.

Evidence: a bare Vulkan probe on the Radeon 780M (RADV, Mesa 26.2.4) read luma code 1023 (low bits
0) through the identity model of a LINEAR image of the format as 0.999039, which is 65472 / 65535
and not 1.0. The optimal tiling's conversion of the format was not measured; the row is per
driver, as the defect table's rows are.

What changes: the AFFECTED table gains a MESA_RADV row, with no clean GPU. Nothing is refused.
- A 10-bit two-plane texture on RADV now converts through Metal's arithmetic. Before, RADV's
  optimal-tiling device conversion (ycbcr_device.rs) took it, and that path was never measured on
  RADV.
- The planes image of the next commit is not taken for 10-bit codes there.
The driver_defects test expectations (every committed RADV profile, Hawk Point's 780M) and the
docs that name the defect's drivers (ycbcr.rs, ycbcr_device.rs, docs/API.md) say RADV too.

Verified: clippy -D warnings (plain and --cfg m2v_gpu) for metal2vulkan, metal2vulkan-runtime and
metal2vulkan-validation; tests::driver_defects on the host. The RADV device itself was not run: the
host is away.

* Sample YCbCr planes read in place through the device's own Y'CbCr sampler where it has Metal's reconstruction

On an integrated GPU or a CPU device, a function that only samples a YCBCR8_420_2P or
YCBCR10_420_2P texture reads the planes in place through a uniform texel buffer. It converts and
filters them with Metal's fixed-point arithmetic in the shader. Where the device converts the
planes' 4:2:0 format as a linear image with Metal's reconstruction (midpoint chroma through a
linear chroma filter), rule 1 makes the device's own conversion the only form. So such a slot now
samples the planes through the device's sampler Y'CbCr conversion. Elsewhere the texel buffer
read stays, as capability.

Translator (metal2vulkan):
- bind::YCbCrPlanesSampler (new, non-exhaustive) holds the conversion: the codes' bits and the
  surface's range and matrix. It also gives the image's format: G8_B8R8_2PLANE_420_UNORM, or
  G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16.
- YCbCrInPlace::with_planes_image, ::sampler and ::planes_sampler. TextureShape::Texture gains
  ycbcr_planes_sampler.
- RuntimeFact::YCbCrInPlace gains `device`: the device's sampler takes every sample of the slot.
  It does not where a constexpr sampler has a border address mode, or a texel offset is placed by a
  parent's size.
- VariantKey and LoweringInputs gain ycbcr_planes_sampled. The binder fills it from slots with
  `device`, bound to a texture that holds the image, whose runtime sampler words have no border
  mode on s or t.
- Such a slot is declared as a combined image sampler: ResourceKind::YCbCrPlanes and
  BindingSource::YCbCrPlanes, written from WriteSource::YCbCrPlanesImage. Its immutable sampler is
  the new vk::SamplerDesc::ycbcr: linear, clamp to edge, lod 0, and a new `ycbcr` field.
- Each sample (lower/sampler/in_place.rs device_sample) is OpImageSampleExplicitLod at level 0:
  - a linear sample takes Metal's coordinate, with its texel offset moved in texels;
  - a nearest one takes the centre of the luma texel Metal reads, clamped to the edge;
  - pixel coordinates and the filter are known when the module is made (constexpr) or read from
    the runtime word;
  - a half result is rounded to a half, as every sampled texel's is.
- The texel buffer stays the slot's resource otherwise. The planes read use is tracked as before.

Runtime (metal2vulkan-runtime):
- YCbCrFormats queries the two 4:2:0 formats' LINEAR tiling: SAMPLED_IMAGE,
  MIDPOINT_CHROMA_SAMPLES, a linear chroma filter, and the limits and
  combinedImageSamplerDescriptorCount.
- YCbCrSampler::planes gives the conversion. It is None under TwoPlaneChromaMisplaced, and for
  10-bit codes under TenBitCodesReadAsWords. holds_planes checks for an even size within the
  limits.
- texture/ycbcr_planes.rs (new) makes a PREINITIALIZED linear image of the format over the planes'
  bytes, and only in memory the runtime allocated. It is made only where:
  - the luma plane comes first;
  - the driver's PLANE_0 and PLANE_1 subresource layouts are the surface's offsets and pitches;
  - the alignment, the type and the room within the buffer fit.
  Its view and every immutable sampler of it share one VkSamplerYcbcrConversion
  (Device::made_ycbcr_conversion, kept in the owned kernels' map), so the two are identically
  defined (VUID-VkWriteDescriptorSet-descriptorType-02738). Its first move rides the next
  submission (Fresh, never rebindable), and it is announced ycbcr-filter-not-exact.
- Fresh pages, no-copy pages and the caller's VkBuffer keep the texel buffer. An image bound to
  imported memory starts UNDEFINED, and the in-place check covers that first move for single-plane
  images only.
- The texture's facts state the image (with_planes_image). binding.rs writes the view in GENERAL
  under the layout's immutable sampler.
- sampler_set chains the conversion into each SamplerDesc::ycbcr sampler. A non-pushed set 0
  reserves combinedImageSamplerDescriptorCount descriptors per such binding.
- WorkCounts gains ycbcr_planes_images, ycbcr_planes_images_kept_{conversion,memory,layout} and
  ycbcr_planes_images_bound.

Venues (from the formats' linear features):
- Radeon 780M (RADV, Mesa 26.2.4): reports the 8-bit route for rows 256 bytes apart. Its 10-bit
  codes carry TenBitCodesReadAsWords (previous commit).
- MoltenVK 1.4.2: TwoPlaneChromaMisplaced.
- lavapipe: its 4:2:0 conversion is cosited only.

Measured before building, through a bare Vulkan probe on the 780M with 8-bit codes:
- luma centres within 0.0003 codes of Vulkan's model, and points between texels within 0.66
  codes;
- Metal's conversion-then-filter differs by up to 54/255 between texels of random planes;
- GPU time, 3840x2160 composited into 1680x1050: 248 us against the texel buffer's 340 (1 pass),
  741 against 1027 (3 passes).
The runtime's path itself is not measured on a device that takes it: the 780M host is away.

Docs: a FAST-PATHS device-gaps row (the device's route, where the texel buffer stays, and why);
the in-place paragraph; docs/API.md (the pipeline interface paragraph, and the notice's catalogue
entry); module docs (ycbcr.rs, ycbcr_device.rs, ycbcr_image.rs); the api_surface table
(YCbCrPlanesSampler N); api_signatures blessed.

Tests:
- bind::ycbcr_in_place::the_planes_sampler_is_the_conversion_word.
- bind::plan::slots::the_planes_image_variant_takes_a_slot_the_device_s_sampler_reads.
- tests::engine_ycbcr_in_place::a_planes_image_slot_samples_through_the_device_s_conversion: the
  lavapipe and M3 profiles; linear, nearest, pixel, offset and runtime samplers, each half and
  float. Each case links and validates, with one OpImageSampleExplicitLod. Border and repeat-offset
  slots state device false.
- Lane runtime_lane::ycbcr_in_place::a_ycbcr_texture_s_planes_image_samples_through_the_device_s_conversion
  covers surfaces whose rows are 256 bytes apart. Each in-place texture is counted exactly once,
  as an image or by why not. Through the image, nearest samples are Vulkan's conversion within the
  device's bound, announced; without it, Metal's texels through the texel buffer, unannounced.

Verified:
- clippy -D warnings, plain and --cfg m2v_gpu, for metal2vulkan, metal2vulkan-runtime and
  metal2vulkan-validation.
- Host, plain target, the touched selection (ycbcr, fast_paths, api_surface, api_signatures,
  codec, slots, api_tests, the inputs encoding, sampler, ash_interop, driver_defects, degradation,
  vk tests): 408 run, 407 passed. The engine test's half cases failed, because a half result was
  an f16 where a sample holds it widened. They now take narrow::round_texel, and the in-place
  engine tests pass, 4 of 4.
- M3 Max (MoltenVK 1.4.2), runtime and validation, ycbcr|chroma|driver_defects|runtime_sources:
  66 run, 64 passed. The planes image test counted [0, 1, 0, 0] for both surfaces (kept for the
  conversion: TwoPlaneChromaMisplaced), bound the texel buffer and read Metal's texels. The two
  failures:
  - the runtime-sources pin, re-pinned in the versions commit;
  - runtime_lane::ycbcr_textures::a_ycbcr_sample_through_an_unmeasured_filter_is_announced
    (anisotropic through a constexpr sampler), which fails the same way at the base, as
    a1f1677174 recorded.
  The 4:2:2 test's new line: GBGR422 and BGRG422 chroma within 0.5000 codes of Vulkan's, and
  0 of 1920 chroma channels a code off Metal's.
- lavapipe (linux-gate arm64, --cfg m2v_cpu_icd), the same selection without the pin: 66 of 66.
  The planes image test counted [0, 1, 0, 0] for both surfaces (cosited only).
- Radeon 780M, the only venue whose features take the route: not run, the host is away. The
  device route's lane test, its notice and its GPU time against the texel buffer are unverified
  through the runtime.

* Bump the cache versions for the 4:2:2 device twins and the YCbCr planes images

- SEMANTICS_VERSION 1908 -> 1909: the translator emits something new under keys that existed
  before. A two-plane YCbCr in-place slot's RuntimeFact::YCbCrInPlace now states `device`, and
  ycbcr_planes_sampled lowers such a slot as a combined image sampler sampled through the device's
  Y'CbCr conversion.
- ARTIFACT_FORMAT_VERSION 475 -> 476: the encoding changed. RuntimeFact::YCbCrInPlace gains
  `device`, SamplerDesc gains `ycbcr`, ResourceKind and BindingSource gain YCbCrPlanes, and the
  YCbCrPlanesSampler struct is new.
- RUNTIME_VERSION 1681 -> 1682: a run of an unchanged artifact may now do something else.
  - A 4:2:2 texture's twin holds the device's conversion where the device converts the format.
  - RADV's 10-bit two-plane textures convert through Metal's arithmetic (TenBitCodesReadAsWords).
  - The runtime makes planes images where the device converts the 4:2:0 format as a linear image
    with Metal's reconstruction.
  - Pools reserve combinedImageSamplerDescriptorCount for planes samplers.

runtime-sources.sha256 is re-pinned over this branch's runtime inputs:
d520b4179f55291b57dc7ffd5182ea5f37790889c768b9d49914f174f428ce7c. This is the fingerprint the
validation build script computed at the tip's tree.

These are lane numbers. The orchestrator renumbers them at landing.

* Re-pin the runtime sources at the landing tip

The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.

* Re-bless the golden hashes on development after the native landings

Two rows of golden_hashes.tsv move: the RADV profile's cells, whose
16-bit-depth bias and tile-store answers the boundary-case commits made the
device's own (SEMANTICS_VERSION 1910, then 1911 with the YCbCr commits). The
engine inventory and the engine golden printouts blessed with no change.

The YCbCr versions commit (569d988e99) names SEMANTICS 1909, ARTIFACT 476
and RUNTIME 1682, the values it was written with on 8b7a8aa2d8. On
development they collided with the 16-bit half output's 1909/476 and the
boundary cases' 1682, so the landing set them to SEMANTICS 1911,
ARTIFACT_FORMAT_VERSION 477 and RUNTIME_VERSION 1683; the commit's text was
not rewritten.

Verified on macOS at 465e0eb538: bless_engine_inventory,
bless_golden_hashes and bless_engine_goldens pass; the conformance crate's
suite 1007/1007.
2026-10-28 21:19:28 +02:00