Render packed 16-bit, 8-bit sRGB and RGB9E5 attachments the device cannot render through integer views of their words

The RTX 5080 samples A1BGR5Unorm, ABGR4Unorm (and every other 16-bit packed order), R8Unorm_sRGB,
RG8Unorm_sRGB and RGB9E5Float but renders none of them, and lavapipe renders neither 8-bit sRGB
format. A render target, clear or draw of such a texture was refused as the device lacking the
format, which ends the guest of any app that renders to one. They now render through an R8_UINT,
R16_UINT or R32_UINT view of the same bits, the fragment function writing Metal's word.

What changes:
- metal::format::WordAttachment (public, with WordField): a format's fields in its word (packed
  16-bit layouts named from the least significant bit, Srgb8, Rgb9e5). WordAttachment::of holds
  where the device samples the format (or its UNORM twin), does not render it, and renders the
  word's integer format: derived from format features alone, on every driver.
- Translator: LoweringInputs::word_colors names such attachments. The fragment output to one is
  declared as a uint and each return stores Metal's word: a packed channel h(x) to nearest even,
  NaN 0, clamped to [0, 1], times the maximum code, rounded to even; an sRGB channel through
  Metal's twelve-bit table; RGB9E5 by the truncating kernel-write rule (shared with the storage
  write, lower::texture::rgb9e5_word). The cache codec carries the new fields.
- Partial write masks and blends:
  - in the pixel interlock (where the device orders fetch through it alone), a packed 16-bit or
    8-bit sRGB word's partial mask merges the kept fields from the word read first;
  - a packed 16-bit word's blend other than One/Zero decodes each code as Metal's blend reads
    it, h(c / m), blends in half as the 8-bit unorm blend does and encodes Metal's word. Metal's
    tile holds a pass's earlier result finer than the codes, so this is a near-equivalent within
    one code, recorded as PrecisionNote::DeviceColorConversion and announced; the exact form (the
    extended-range half shadow taken by word attachments) is a FAST-PATHS "not built yet" row;
  - where fetch reads rasterization-order input attachments (lavapipe), an 8-bit sRGB word's
    partial mask merges over its input attachment (new RuntimeFact::WordInputMerge), per sample in
    a multisampled pipeline.
- Runtime: the texture's image keeps its own format, sampled and blitted natively, made mutable
  with extended usage and the word view listed; the pass's attachment is the view; a pass clear
  writes the word of Metal's clear.
- New degradation kind shared-exponent-kept (Precision): Metal's tile store normalizes a loaded
  RGB9E5 word whose largest mantissa is below 256 in each tile a draw reaches, which a Vulkan pass
  keeps; announced at each such draw, with a FAST-PATHS row.
- DeviceColorConversion's rustdoc states that Metal blends a packed 16-bit attachment against its
  tile's finer values within a pass.
- Still refused, recorded as FAST-PATHS known gaps: colour inputs and resolves of word
  attachments, blended or fetched sRGB words, an output of fewer than four lanes for a blended
  packed word, RGB9E5 half outputs, blends, masks, inputs and resolves.
- New owned fixture engine/wm_samples and runtime_lane::word_samples for the multisampled merge.

Why: these formats are Metal render targets the guest uses, and the device holds and samples them;
only rendering them directly is missing.

Metal's rules, measured with plain Metal on the M3 Max under macOS 27.0.1: 65,536 float4 and half4
outputs and 4,096 clear colours per packed format, 0 texels off the rule; a One/Zero blend stores
the same bytes; the blend sweep (2,891 states, 8,192 random pixels, four packed formats, half and
float, fast and safe maths) gave Metal's code in every channel without fast maths and within one
code under it; within a pass Metal's tile holds a packed attachment finer than its codes (blends
in one pass follow the unrounded value, across two passes the stored codes); RGB9E5 draws and
clears 65,536 of each, 0 off.

Verified:
- Translator and runtime unit filters on gem10: 162 of 162 and 258 of 258 (word attachments),
  394 (partial masks in the interlock), 370 and 422 (blends, including 864 words the M3 stored
  checked on the interpreter), 538 (sRGB and RGB9E5 words), 38 and 108 (input-attachment merge).
- On lavapipe: runtime_lane::color_writes 5 passed, RG8UnormSRGB under the red mask 0 of 107,814
  channels off where it was refused before; word_samples, 64 texels of 4 samples merged, the edge
  texels keeping both greens; public_fixtures_engine with the new rows.
- clippy -D warnings (plain, m2v_gpu, m2v_cpu_icd) and rustdoc.
This commit is contained in:
Anees Iqbal committed 2026-10-19 00:15:59 +03:00
1 parent 697c55d514
commit 2b97fc1cf0
60 files changed
+4105 -83

No files matched your search

+35
View File
@@ -356,6 +356,36 @@ Where Metal's rules differ from Vulkan's, the pipeline gives Metal's answer:
outputs at one attachment are `InvalidDescriptor(DuplicateColorOutput)`.
- On a device without `independentBlend`, attachments the function does not write copy the blend
state of those it does; where those differ the pipeline is refused, naming the feature.
- A packed 16-bit attachment (`A1BGR5Unorm`, `ABGR4Unorm`) of a format the device samples but does
not render (the RTX 5080) renders through an `R16_UINT` view of its texture
(`metal::format::WordAttachment`, `LoweringInputs::word_colors`): the fragment function writes
the word Metal stores and `graphics` gives the attachment that format; a pass clears it to the
word of Metal's clear. Exact, for a write unblended (or blended one and zero); under a mask of
some of its channels the function merges the word into the texel in the interlocked storage
form (a `GraphicsState::storage_attachments` entry of `R16_UINT`) where the device orders fetch
through the pixel interlock. Blended otherwise, there too the function computes Metal's blend of
a `half4` or `float4` output over the word it reads, within one code of Metal's
(`PrecisionNote::DeviceColorConversion`: the attachment holds codes where Metal's tile holds a
clear's or an earlier blend's result in the pass as a `half`, and under fast math Metal sums a
few states otherwise; `docs/FAST-PATHS.md`). A blend of the second source, and a blend or
partial mask on a device without the interlock, is refused as the device lacking the format; a
color input or resolve of one, and a blend of an output of fewer lanes, is `NotImplemented`.
- An 8-bit sRGB attachment of one or two channels (`R8Unorm_sRGB`, `RG8Unorm_sRGB`) the device
does not render (the RTX 5080: it renders neither `R8_SRGB` nor `R8G8_SRGB`, and holds the
latter in its UNORM twin) renders through an `R8_UINT` or `R16_UINT` view of its texture the
same way: the fragment function writes Metal's bytes (its twelve-bit encode), a pass clears it
to the bytes of Metal's clear, and a partial mask merges the word in the interlock, or over the
attachment's input attachment on a device that orders fetch through rasterization-order input
attachments (lavapipe; `RuntimeFact::WordInputMerge`). Exact. A blend of one
other than one and zero is refused as the device lacking the format; a color input or resolve
of one is `NotImplemented(Format)`.
- An `RGB9E5Float` attachment the device does not render (the RTX 5080) renders through an
`R32_UINT` view of its texture: the fragment function writes Metal's word of a `float` output
(each channel clamped to `[0, 65408]`, a NaN 0, the exponent of the largest, every mantissa
truncated), and a pass clears it to the word of Metal's clear. Exact. A `half` output to one
is `NotImplemented(Format)` (Metal rounds the `float` the `half` was converted from, half up);
a blend, or a mask of some of its channels, is refused as the device lacking the format; a
color input or resolve of one is `NotImplemented(Format)`.
- A fragment function that reads a color attachment (framebuffer fetch) reads it in an ordered
form wherever the device has one: rasterization-order attachment access, or the interlocked
storage form, which binds the attachment as a storage image viewed in
@@ -1589,6 +1619,11 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound.
pass would change. Not on a driver whose pass stores the codes as Metal's
(`DriverFact::TileStoreIsMetals`: MoltenVK on Apple's GPUs, whose pass is a Metal pass), nor under
`TileStorePolicy::Exact` for an attachment the load pass rewrites as Metal's store leaves it.
- `metal2vulkan-degrade-shared-exponent-kept` (precision). `SharedExponentKept`: A draw in a render
pass that loads a single-sampled `RGB9E5Float` color attachment and does not discard it at the
store. Cost: the texels the pass's draws do not write keep their words; Metal's pass normalizes a
word whose largest mantissa is below 256 (its exponent above 0) in each tile a draw reaches: a
texel whose bytes no Metal write left (uploaded or copied words) keeps a word Metal's pass would
change, of the same value. Not on a driver whose pass stores the words as Metal's
(`DriverFact::TileStoreIsMetals`), nor under `TileStorePolicy::Exact` for an attachment the load
pass rewrites as Metal's store leaves it.