Translator and runtime: BGR10_XR and BGRA10_XR render targets take Metal's writes, clears, masks and covered blends

The red commit's test, and the conformance cases that render into either format, which the runtime
refused (Gap::TextureFormat on a RenderTarget texture).

Attachments. A BGR10_XR or BGRA10_XR color attachment is its texture's UNORM image
(FormatEmulation::ExtendedRangeUnorm, now admitted as a color attachment and, blended, as a blended
one): A2R10G10B10_UNORM_PACK32, and R16G16B16A16_UNORM with red and blue exchanged. The formats'
second, raw candidate and ExtendedRange::of_attachment are gone; the runtime makes a RenderTarget
texture of either, and a device whose format query lacks the usages is refused the pipeline,
naming them (the runtime's floor does not require R16G16B16A16_UNORM as a color attachment).

Writes (lower::stage_io::extended_unorm_color). A fragment function writes Metal's code of its
output (rounded to half, nearest even, then encoded as a kernel write encodes it) as the field's
value over its maximum, a little above the code (metal::format::extended_unorm_field: 10-bit
(c + 0.0005) / 1023, 16-bit (64 c + 0.25) / 65535), which a device's conversion stores as that code
whether it rounds to nearest, toward zero, by floor(x 1024) or, as lavapipe does for a 10-bit
target, through 16 bits (round(x 65535) >> 6; an offset of 0.25 stored code + 1 for the 251 codes
from 772). BGR10_XR's two alpha bits are written as ones, as Metal writes them. Clears store
Metal's clear codes (metal::format::extended_unorm_clear, the runtime's clear values). Masks are
Metal's on the image's channels (BGRA10_XR's red and blue exchanged; BGR10_XR's alpha bits written
with any color channel). A resolve is the device's AVERAGE of the codes, which average as the
values do; PrecisionNote::DeviceRoundedResolve now names a BGRA10_XR field's low bits. A fetch of
either attachment is refused NotImplemented(Format) at compile, and at link where the function
does not write it.

Blends (pipeline::extended_blend). Metal's blend into these formats, measured on an Apple M3 Max
(macOS 27.0.1) over the xr-blend recordings: the source clamped to the values of codes 0 and 1022
(a NaN to code 0) and alpha to [0, 1], a destination color code to 1022, half arithmetic, the
result rounded to a code. That model is every recorded channel's but 9 of 172,032 (premultiplied
source-over, one code each, listed in the ledger rows). The function clamps its output as Metal's
blend does; a blend that stores its source (one and zero, added) stores the clamped codes exactly.
Any other blends the codes in Vulkan with a source factor of one, the function writing the term
X that makes Vulkan's blend of the codes Metal's blend of the values; destination factors that read
the source read it from a second output (dualSrcBlend, in the floor), BGR10_XR's alpha too, so its
alpha bits stay ones. A factor pair the module does not cover (a BGRA10_XR destination alpha among
them) is refused NotImplemented(Format).

Notes, static per pipeline: PrecisionNote::ExtendedRangeBlend on every blend that does not store its
source (the device rounds each draw's result to the field, a BGRA10_XR field keeping the fraction of
a code in its six low bits); PrecisionNote::ExtendedRangeBlendWindow where the corrected term or a
second-output factor can leave [0, 1], which Vulkan clamps (pipeline::extended_blend::window_holds,
from the factors and operations at the corners of the source's range; a unit test classifies every
factor pair and operation at both formats). Both are in docs/API.md's catalogue with counts, and the
runtime's README records the window as a known gap with its trigger.

Ledger: 18 llvmpipe rows of the B cases that differ (the xr-blend addition and premultiplied
source-over, xr-gamut, the blended xr-gradient and xr-masked over draws, and xr-gradient's
unblended resolve), each citing its note, with counts from a model of our blend whose count of
differing elements is lavapipe's replay's to within 11; and the same cases' rows on the RTX 3090
(NVIDIA 620.70.06, m3-max-85796; there xr-gradient-bgra10xr-unblended-x1 too, 39 fields a code
off by the device's arithmetic of the gradient), the RX 7900 XTX (m3-max-85797) and the Iris Xe
(m3-max-85798), each pointing at the case's llvmpipe row, with that device's counts.

Cache key: LoweringInputs::extended_unorm_colors is hashed into the function key where it is set
(pipeline::compile::key), so a fragment function compiled for a BGR10_XR or BGRA10_XR attachment
never takes another's translation; the key test asserts that the attachment and the format each
change the key.

SEMANTICS_VERSION 2378 and ARTIFACT_FORMAT_VERSION 612. RUNTIME_VERSION 2577 (XR render targets
are made); runtime-sources.sha256 re-pinned. api_signatures blessed and
api_surface extended (ExtendedUnormBlend, ExtendedUnormColor, extended_unorm_clear);
docs/REFUSALS.md regenerated (the fetch's refusal site).
This commit is contained in:
Anees Iqbal committed 2026-12-03 16:18:20 -08:00
1 parent e9290d8138
commit 3e3deb25b9
44 files changed
+1986 -215

No files matched your search

+56 -7
View File
@@ -1028,11 +1028,31 @@ Where Metal's rules differ from Vulkan's, the pipeline gives Metal's answer:
cannot take: none attached, or one of another numeric class than the read's
(`InvalidDescriptor` at the color attachment), or one of a rotated, Y'CbCr or extended-range
format (`Unsupported{Format}`). A read of one of Apple's extended-range formats (`BGR10_XR`,
`BGRA10_XR`, `RGB10A8_2P_XR10` and their `_sRGB` twins), and a blend into one, are refused on
every device (`Unsupported{Format}` at the color attachment): Metal's tile holds
such an attachment as `half` through the render pass and rounds it to the codes only at the
store, so a read or a blend after an earlier draw's write sees that draw's `half`, which the
stored codes do not keep. An unblended write, under any write mask, is built. A write the
`BGRA10_XR`, `RGB10A8_2P_XR10` and their `_sRGB` twins), and a blend into one but `BGR10_XR` and
`BGRA10_XR`, are refused on every device (`Unsupported{Format}` at the color attachment):
Metal's tile holds such an attachment as `half` through the render pass and rounds it to the
codes only at the store, so a read or a blend after an earlier draw's write sees that draw's
`half`, which the stored codes do not keep. An unblended write, under any write mask, is built.
A `BGR10_XR` or `BGRA10_XR` attachment is the UNORM image of its bits: the function writes each
channel as the code Metal stores (its `float` output rounded to `half`, nearest even, then a
kernel write's code) as its field's value a little up over the field's maximum (a quarter of a
16-bit field's unit, 1/2000 of a 10-bit code), which a device's conversion to nearest, toward
zero, or through 16 bits stores as the code (`BGRA10_XR`'s six low bits zero, `BGR10_XR`'s two
top bits ones), Metal's mask applies to the image's channels, a clear stores the code of the
clear color through `half` (Metal clears a plain private target of 16 by 16 in a pass with no
draw from the `float`, another code at a tie and at a NaN), and a resolve averages the codes.
Where the pipeline blends there, the function first clamps the output as Metal's blend clamps its
source (measured: each color channel to the values of codes 0 and 1022, a NaN to code 0's, alpha
to `[0, 1]`); a blend of one and zero, added, then stores the clamped output's codes, as Metal's
does. Another blend is Vulkan's blend of the codes with a source factor of one, the function
writing `X = (Fs v + (1 - Fd) 384/510) 510/m` under an addition (`(1 + Fd)` under a
subtraction, `v` alone under a minimum or a maximum), Metal's source factor folded and its
destination factor Vulkan's, from a second output (the source's alpha or colour, which needs
dual-source blending at attachment 0) or a constant (`BGR10_XR`'s destination alpha, 1), with
`PrecisionNote::ExtendedRangeBlend`, and with `PrecisionNote::ExtendedRangeBlendWindow` where
`X` can leave `[0, 1]` for a source in Metal's range. A blend whose factors read the destination's colour,
`BGRA10_XR`'s destination alpha, the blend colour or a second output of the function's own, or a
reverse subtraction, is refused (`Unsupported{Format}` at the color attachment). A write the
function would compute over its own read of the attachment, where no Vulkan blend or write mask
gives Metal's, is not built (`Unsupported{FramebufferFetch}`, not implemented, on every device):
a padded extended-range attachment's blend, a write of some of the codes one word of an
@@ -1615,8 +1635,11 @@ category, and says what makes an operation carry the note and what may differ. E
- `metal2vulkan-degrade-device-rounded-resolve` (precision). `DeviceRoundedResolve`: A multisample
color resolve averages through Vulkan's `AVERAGE` mode, which leaves the rounding of the average
(and the sRGB encoding) to the device: any
color attachment but an extended-range one and one resolving into its format's sRGB twin (each
resolved after the pass). Also, on every device, a resolve into an 8-bit UNORM attachment's
color attachment but an extended-range one held raw and one resolving into its format's sRGB
twin (each resolved after the pass); a `BGR10_XR` or `BGRA10_XR` attachment, held as the UNORM
codes of its bits, averages its codes as the values average, a `BGRA10_XR` field keeping the
average's fraction of a code in its six low bits, which Metal writes as zero (lavapipe: 146 of
the 4,096 fields of `xr-gradient-bgra10xr-unblended-x4`, within 48 of a code's 64 steps). Also, on every device, a resolve into an 8-bit UNORM attachment's
sRGB twin where the device has
the sRGB format: the crate-owned resolve decodes the samples and encodes their average by the
device's own sRGB conversions, where Metal's resolve takes its own 12-bit tables (with correctly
@@ -2267,6 +2290,32 @@ category, and says what makes an operation carry the note and what may differ. E
apart in its color and alpha arithmetic, as Apple's does, and the rotation moves Metal's blue into
the image's alpha and Metal's alpha into its red, so a channel may store one code apart from
Metal's.
- `metal2vulkan-degrade-extended-range-blend` (precision). `PrecisionNote::ExtendedRangeBlend`: A
fragment function writes a `BGR10_XR` or `BGRA10_XR` color attachment the pipeline blends by more
than storing its source as it is (`LoweringInputs::extended_unorm_colors`). The device blends the
image's UNORM codes, with a source term the function corrects so the blend is Metal's blend of
the values, in its own precision, and rounds the result to the field at every draw, where Metal
blends `half` values and its tile keeps them through the pass. Where the source term lies in the
code range, a channel stores Metal's code or one beside it a draw: of 40,000 random single draws
a blend, on `BGR10_XR`, straight alpha-over stored a code one from Metal's on 2,169 channels,
destination-in on 1,296 and destination-out on 1,595; a `BGRA10_XR` field's six low bits, which
Metal writes as zero and reads past, hold the blend's fraction of a code on about 98% of its
channels. A destination code Metal's blend reads clamped (a color code 1023, an alpha code
outside 384 to 894) is read as it is.
- `metal2vulkan-degrade-extended-range-blend-window` (precision).
`PrecisionNote::ExtendedRangeBlendWindow`: A `BGR10_XR` or `BGRA10_XR` color attachment's blend
whose corrected source term can leave `[0, 1]` for a source in Metal's range, or whose
destination factor Vulkan reads from a second output where Metal's value of it can leave
`[0, 1]`, decided from the blend's factors and operations at the corners of the source's range.
Vulkan clamps both to `[0, 1]`, so a source outside the window stores a code up to 386 from
Metal's. An addition of one and one with a negative source, and premultiplied source-over with a
source below `-0.7529` times its alpha, are outside it: on the conformance suite's random
sources, 12,450 of 32,768 `BGRA10_XR` channels and 8,421 of 24,576 `BGR10_XR` ones under the
addition, and 4,724 of 32,768 and 4,233 of 24,576 under premultiplied source-over, lie more than
32 codes from Metal's, up to 386 (a model of the blend whose count of differing elements is
lavapipe's replay's to within 11 of 32,768; the conformance ledger's rows). Straight alpha-over, a
source factor of zero, a minimum and a maximum hold by construction, and premultiplied
source-over of a premultiplied extended-range source stays inside the window.
- `metal2vulkan-degrade-linked-sampler-numbering` (precision).
`PrecisionNote::LinkedSamplerNumbering`: The sampler resource IDs a pipeline state takes for the
constexpr samplers of the visible functions its stage links may be other than Metal's: two or more