Announce a loaded snorm or RGB9E5 attachment's kept codes, and store them as Metal's tile store does under TileStorePolicy::Exact

Metal's pass, once it draws, writes each 32x32 tile a draw reaches back through its texels'
values: a signed normalized channel's minimum code (-128, -32768) reads as -1.0 and is stored as
the code above it, and an RGB9E5Float word whose largest mantissa is below 256 under an exponent
above 0 is stored normalized. A Vulkan pass's load and store keep those bytes.

What changes:
- New degradation kind snorm-minimum-kept (Precision), announced at every draw and indirect
  execution in a pass that loads a single-sampled R8, RG8, RGBA8, R16, RG16 or RGBA16 Snorm colour
  attachment and keeps it, naming each such attachment. It joins shared-exponent-kept for RGB9E5.
- New DevicePolicy::tile_store, TileStorePolicy { Device (default), Exact }; exact_answers()
  selects Exact. It is the runtime's choice alone and keys no profile. Under Exact the load pass
  that already rewrites extended-range, padded and bfloat attachments also takes a single-sampled
  snorm or RGB9E5Float attachment in the tiles the pass's draws reach, with two new
  bind::unused_bits_module rules (SnormMinimum, SharedExponent; the module is keyed by
  PixelFormat), and nothing is announced. An attachment the load pass cannot take keeps the
  device's load and store, announced.
- New answer fact DriverFact::TileStoreIsMetals for MoltenVK 1.4.1 on Apple's GPUs: its render
  pass is a Metal render pass, so its tile store is Metal's for both kinds. There neither value
  adds a load pass or a notice.
- Docs: one FAST-PATHS row for the switch, its cost the load pass's measured GPU time; a known gap
  for lavapipe, which states no blend for any snorm format, so a blending snorm pipeline is
  refused there; API.md's policy bullet and catalogue entries; the unreached-tiles-rewritten text.

Why: a code no Metal write leaves, but uploaded or copied bytes may hold, reads back differently
after a drawing pass. The exact form costs a copy of the render area through a dispatch before
every such pass, so the device's store stays the default, announced, and Metal's store is a
switch away.

Verified:
- Metal's behaviour probed on an M3 Max under macOS 27.0.1 (70x40 targets of five snorm formats):
  a pass that draws nothing moves no code; a tiny triangle moves every minimum code of its first
  32x32 tile and none elsewhere; a blended full-target draw moves all of them; a blit there and
  back moves none. The guest's sweep showed the same on R8Snorm and RG8Snorm.
- Unit tests: unused_bits (both rules against CPU models over every code, the M3's example
  RGB9E5 word, the masked-tile rewrite), fast_paths (the row, no profile key), driver_facts,
  api_surface, owned_divisions: 38 passed on gem10.
- runtime_lane::snorm_tile_store under Device and Exact for both kinds, asserting load-pass
  counts, bytes and notices: on lavapipe with padded_loads, extended_range_blends and the notice
  site check, 15 passed (Exact took the load pass, Device announced); on the M3 Max under
  MoltenVK 1.4.1, 4 passed through the fact (no load pass, no notice) and 11 more beside them.
- The load pass's cost (FAST-PATHS): on the Radeon 780M, a 1080p pass per frame of BGRA10_XR
  1958.8 us against RGBA16Float's 135.3 us; the snorm and RGB9E5 cases take the same pass, not
  timed alone.
- 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 2423b8de61
commit 697c55d514
19 files changed
+951 -139

No files matched your search

+26 -13
View File
@@ -95,15 +95,14 @@ compile does. `DevicePolicy::default()` is `DevicePolicy::UNTRUSTED`:
[FAST-PATHS.md](FAST-PATHS.md) lists every choice, its bound and the measured cost of its exact
form. On MoltenVK on an Apple GPU, whose sampler and `float` functions are Metal's own, most of
these choices change nothing.
- **An image over a padded texture that only reads** (`PaddedReadsPolicy::Alias`, the runtime's
choice; no pipeline differs). A texture over a buffer whose rows lie with bytes between them,
and whose usage holds no `RenderTarget`, `ShaderWrite`, `ShaderAtomic` or block writes, is an
image over the buffer's bytes at its row pitch where the device lays one there. Its subresources
hold the bytes between the rows, which its first move may rewrite: the host keeps them across it
with the texels (below), so a CPU write to them while it keeps them is undone, once per image
(FAST-PATHS.md's known gaps).
`padded_reads = PaddedReadsPolicy::Shadow`, which
`exact_answers()` selects, makes it the runtime's shadow, copied in before each use.
- **The device's load and store of a signed normalized or `RGB9E5Float` attachment**
(`TileStorePolicy::Device`, the runtime's choice; no pipeline differs). A render pass that loads
one and draws keeps the texels its draws do not write as they were, where Metal's tile store
writes a channel's minimum code back as the code above it and an unnormalized shared-exponent
word normalized, announced as `snorm-minimum-kept` and `shared-exponent-kept`.
`tile_store = TileStorePolicy::Exact`, which `exact_answers()` selects, rewrites them before
the pass as Metal's store leaves them, through the extended-range attachments' load pass. On
MoltenVK the pass is a Metal pass and stores them as Metal's under either value.
Loops run as written: no execution bound is translated in.
@@ -1581,6 +1580,18 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound.
BGRA10_XR's low six bits of each field to zeros, the two-plane color word's top two bits to zeros)
and clamps BGRA10_XR's alpha code to [384, 894]: a texel whose bytes no Metal write left (uploaded
bytes, or an alpha code past 894) keeps bytes Metal's pass would change.
- `metal2vulkan-degrade-snorm-minimum-kept` (precision). `SnormMinimumKept`: A draw in a render pass
that loads a single-sampled color attachment of a signed normalized format (`R8Snorm`, `RG8Snorm`,
`RGBA8Snorm`, `R16Snorm`, `RG16Snorm`, `RGBA16Snorm`) and does not discard it at the store. Cost:
the texels the pass's draws do not write keep their bytes; Metal's pass rewrites a channel's
minimum code (-128, or -32768 for 16 bits) as the code above it (-127, -32767) in each tile a draw
reaches: a texel whose bytes no Metal write left (uploaded or copied bytes) keeps a code Metal's
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.
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.
- `metal2vulkan-degrade-two-plane-buffer-blit` (precision). `TwoPlaneBufferBlit`: A blit between a
buffer and a level of `RGB10A8_2P_XR10` or its sRGB twin whose width is not a multiple of 4: it
moves the texels at the rows the texture holds them in, where Metal's blit addresses the level's
@@ -1654,15 +1665,17 @@ fast forms record, and each `PrecisionNote`'s rustdoc states its bound.
older release stops.
- `metal2vulkan-degrade-unreached-tiles-rewritten` (precision). `UnreachedTilesRewritten`: A render
pass that loads a color attachment of an extended-range or padded 10-bit format (`BGR10_XR`,
`BGRA10_XR`, `RGB10A8_2P_XR10`, `R10Unorm_X6`, `RG10Unorm_X12` and their sRGB twins), stores it
and draws, whose load pass rewrites every 32 x 32 tile of its render area: Metal's pass rewrites
`BGRA10_XR`, `RGB10A8_2P_XR10`, `R10Unorm_X6`, `RG10Unorm_X12` and their sRGB twins), or under
`TileStorePolicy::Exact` of a signed normalized format or `RGB9E5Float`, stores it and draws,
whose load pass rewrites every 32 x 32 tile of its render area: Metal's pass rewrites
only the tiles a draw's primitives reach, and every tile only where a color attachment of the pass
is cleared and stored (announced where none is, or where the pass renders more than one layer).
Cost: in tiles no draw reaches the pass rewrites what Metal keeps: the unused bits made canonical
(BGR10_XR's bits 30 and 31 ones, BGRA10_XR's low six bits of each field and the two-plane color
word's top two bits zeros) and BGRA10_XR alpha codes clamped to [384, 894], so an out-of-range raw
alpha reads back changed, and a padded word's low six bits zeroed (an sRGB twin's code moved
through Metal's table); the tiles a draw reaches are Metal's.
alpha reads back changed, a padded word's low six bits zeroed (an sRGB twin's code moved through
Metal's table) and, under the exact tile store, a signed normalized minimum code raised and an
RGB9E5Float word normalized; the tiles a draw reaches are Metal's.
- `metal2vulkan-degrade-zero-layer-map-after-release` (precision). `ZeroLayerMapAfterRelease`: A
draw in a render pass over a rasterization-rate map of no layers that was made after the device
released a map of one or more layers. Cost: the draws write nothing, where Metal draws rows of the