Where a device cannot store, sample or render an 8-bit sRGB or shared-exponent format directly,
the texture now goes through a view of a format the device does handle, and the shader applies
Metal's own encode or decode. Before, these textures were refused or read wrong values with no
notice.
What changes:
- Storage. An R8Unorm_sRGB or RG8Unorm_sRGB storage texture on a device without sRGB storage (the
RTX 5080) writes through its R8_UNORM or R8G8_UNORM view with Metal's sRGB encode, and a
read_write read decodes through Metal's table, as RGBA8Unorm_sRGB already did. The sRGB format
stays the image's own wherever the device holds it, so the texture keeps its render-target
usage; the UNORM twin is the image's format only where the device holds no sRGB image at all.
A BGRA8Unorm_sRGB storage texture whose twin needs storage access without a format (ARL,
Pascal, ANV on the Iris Xe for read_write) falls back to an Rgba8 view that encodes, then swaps
red and blue (StorageImageClass::SrgbEncodeBgra).
- Shared exponent. An RGB9E5Float storage slot takes a new class, SharedExponentBits, on every
device: an R32_UINT view whose word the shader computes in integer arithmetic with Metal's
truncating encode, since Vulkan's conversion rounds each mantissa up where Metal truncates.
- Sampling. A device that samples an sRGB format's UNORM twin but not the format (the RTX 5080
with RG8Unorm_sRGB) samples the twin, and the function decodes with Metal's table (a new
srgb_twins variant set), announced SrgbTexelDecode. A swizzle that moves alpha into a colour
channel, or a colour into alpha, decodes before swizzling. A float gather decodes by Metal's
table on every device without Metal's own sampler unit. Under SamplingPolicy::Exact a runtime
sampler's one-texel sample reads the slot's raw view and decodes its code through Metal's table.
Device::pixel_format_capabilities answers Filter for such a texture by the twin's filter.
- Resolves. The exact shader resolve of an 8-bit sRGB attachment reads its samples and writes its
result through views in the UNORM twin, so codes move as an 8-bit unorm channel's do, with no
midpoint or linear-value table. The stored codes are unchanged.
- Docs: the FAST-PATHS native sRGB row covers the twin's filtered sample (exact for one texel and
adjacent codes, up to 0.286 off between codes 0 and 255); known gaps scope a runtime sampler's
nearest sample under native sampling.
Why: the consumer's guest on the RTX 5080 refused kernel writes to these formats and pipelines
sampling them, and an in-guest comparison under exact sampling showed BC sRGB cells off.
Metal's rules, probed on the M3 Max under macOS 27.0.1: an sRGB write clamps to [0, 1], scales by
4095 to nearest even and stores the largest code whose table step is at most that index, alpha
x255 to nearest even; a read is step / 4095. An RGB9E5 write clamps each channel to [0, 65408],
takes the exponent of the largest and truncates each mantissa; 0 of 65,536 float and 65,536 half
texels off, and every read exact.
Verified:
- New lane runtime_lane::shared_exponent_storage, and srgb_storage widened to R8 and RG8 and to a
device without storage access without a format (lavapipe), against Metal's bytes.
- On the Iris Xe (ANV): runtime_lane::resolve_rounding 5 passed, 0 channels off Metal's rule for
every closed format at 2 and 4 samples, sRGB included; the runtime's own BGRA8UnormSRGB 4x
resolve at 1080p went from about 2.2x an RGBA8Unorm resolve's GPU time to about the same
(2138 -> 1635 us for the write side alone, edge-dense 4193 -> 2638 us).
- Translator unit filters on gem10: 42 of 42 (shared exponent, image plans, storage choices), 58
of 58 (sRGB raw, fast paths, the sRGB filter), 251 (sRGB, linear and sampler, the raw one-texel
sample tests among them, which fail without the change), bind::color_resolve 25 passed; runtime
image_plan 31 of 31.
- clippy -D warnings (plain, m2v_gpu, m2v_cpu_icd) and rustdoc.