One work packet, landed as 9 commits (62c7d7a9f5..378d636d2f on archive/development-linear-2026-10-28), in order:
* Keep the device's copy for blits through a texture Metal compresses
Metal's GPU blit into or out of a texture it keeps losslessly compressed
writes three families' texels in its compressor's canonical encoding:
BGRA10_XR (and its sRGB twin) with each field's low six bits cleared and
the alpha code clamped, RG11B10Float with a NaN made the quiet NaN, and
RGB9E5Float with the shared exponent lowered. The runtime reproduced that
with a crate-owned compute rewrite of the copied rows (bind::CompressedBlit
and its module) after every such blit.
That is Metal's compressor's encoding, not the format's: Metal's own
uncompressed texture of the format keeps the bytes through the same blit,
and every rewritten texel reads the same value either way. The device's
copy, which keeps the bytes, is now the only form. A blit through such a
texture announces the note of the encoding it keeps, once per device:
extended-range-bits-kept (BGRA10_XR), device-nan-encoding (RG11B10Float)
and shared-exponent-kept (RGB9E5Float), each existing kinds; no new kind.
Where the device's own copy already writes Metal's encoding (MoltenVK,
RuntimeDriverDefect::CompressedImageCopiesRewriteTexels) nothing is
announced; the defect's PixelFormatView usage, which keeps CPU copies
byte-exact there, stays.
Removed public items: bind::CompressedBlit, bind::CompressedBlitModule,
bind::compressed_blit_module, WorkCounts::compressed_rows_rewritten.
RUNTIME_VERSION 1740. The conformance recordings' runtime cost records
that count compressed_rows_rewritten (compressed-blits-*, fresh-pattern-*,
xr-clear-routes-*, xr-draw-*) move at the next re-bless.
The compressed-blits lane now asserts the bytes are kept and each format's
note is announced; the conformance case declares the note where it is not
one of the suite's native notes.
Verified: cargo clippy --workspace --all-targets --all-features -D warnings;
RUSTFLAGS='--cfg m2v_gpu' cargo check of runtime and validation; nextest
of blit_plan, degradation, degradation_catalogue, conformance
compressed_blits, unused_bits, fast_paths, owned_divisions, api_surface,
api_signatures and refusal_surface (77 passed). Device lanes and replay
run after the whole series.
* Resolve a fetching pass's sample planes by the device's average
A color attachment whose sample planes held its samples as the pass ended
(framebuffer fetch in the pixel interlock on a device without multisampled
storage images: ANV, MoltenVK) was resolved from the planes by the
crate-owned resolve, which computes Metal's closed rules for every unorm,
snorm, sRGB, 32-bit float, half, packed 16-bit, RG11B10Float and
RGB9E5Float format. Every other color attachment resolves by the device's
AVERAGE. The average is the device's native answer, so it is now the only
form here too: the planes merge back and one more instance of no draws
resolves the attachment, announced device-rounded-resolve where the
driver's average is not measured to be Metal's (on MoltenVK it is,
DriverFact::ColorResolveAverageIsMetals, so nothing is announced there).
The crate-owned resolve keeps the two resolves no device's average writes:
into the attachment's format's sRGB twin (the 8-bit unorm and sRGB rules)
and of an extended-range attachment. Its rules for every other format, and
their tests, are deleted. ColorResolveFormat::of names the twin's eight
formats; sample planes are read only for an extended-range form, and a
module of a twin format from planes is refused.
Removed public items: ResolveRule::{HalfUnorm, Snorm, Float32, Float16,
SmallFloat, SharedExponent}, ResolveRule::bits, ResolveRule::resolves,
ColorResolveFormat::resolves; ResolveRule::Unorm loses its bits field.
Cost: such a pass now merges its planes back and resolves in one more
render pass instance, where it drew one resolve pass from the planes; a
memoryless attachment the pass only fetches and resolves needs a backing.
The ColorResolveAverageIsMetals docs, the shader-resolve and
device-rounded-resolve entries (degradation.rs, docs/API.md) now say what
resolves where. The fetch lanes expect no shader-resolve for a fetched
attachment.
Verified: cargo check --workspace --all-targets --all-features; the GPU
cfg check of runtime and validation; nextest of color_resolve,
sample_planes, degradation, driver_facts, fast_paths, api_surface,
api_signatures, refusal_surface (84 passed). Device lanes run after the
series.
* Clear a float attachment to the clear color as the device converts it
A render pass's Clear of a normalized, sRGB, packed 16-bit, half, float or
small-float color attachment computed Metal's texel on the CPU (its
rounding, its trip through half for the packed 16-bit formats, its
truncated small-float and shared-exponent mantissas) and handed the device
a value that converts back to it; a Depth16Unorm clear took a quarter step
above Metal's truncated code. The conversion is the device's native
answer, so the clear value is now the color (or depth) as a float, which
the device converts.
Where the device's conversion can stand a code from Metal's it is
announced, once per device: device-color-conversion where a normalized
channel's scaled value lies within 1/1024 of a midpoint between two codes
(a packed 16-bit channel's within Metal's half step too), an sRGB channel
lies inside (0, 1), or a half, small float or shared exponent does not
hold the value exactly; unorm-depth-rounding where a Depth16Unorm depth's
scaled value lies at or above a midpoint, which Metal truncates and a
device rounding to nearest takes up. Vulkan asks for rounding to nearest
and leaves ties, sRGB encodes and float rounding to the device. A NaN in a
normalized or RGB9E5Float channel still clears as 0 (Vulkan states no such
conversion); integer, extended-range, word and YCbCr attachments keep
Metal's conversion, which no device makes for them.
Metal's measured conversion moves into the tests as the model they compare
with. The renders lane accepts a device texel a code from Metal's where
the note is announced and prints it; the cleared sRGB resolve lane
compares the resolve with the device's own 1x clear.
UnormDepthRounding's docs and cost, PrecisionNote::DeviceColorConversion's
docs and both docs/API.md entries say so.
Verified: cargo clippy --workspace --all-targets --all-features -D
warnings; the GPU cfg check of validation; nextest of clear_value,
heap_tiled, fresh, nan_clear and degradation (55 passed). Device lanes and
replay run after the series.
* Expect the device's clear conversion in the lanes that clear at a tie
Since 5925c303f8 a clear converts the clear color (and a 16-bit depth)
the device's way, announcing device-color-conversion where a channel
lies at a rounding question (0.5 on an 8-bit unorm channel is 127.5
codes, a tie; any sRGB channel's encode) and unorm-depth-rounding where
a Depth16Unorm clear's fraction reaches the midpoint (Metal truncates).
Lanes that hold exact notice sets or Metal's truncated depth codes now
expect them:
- dont_care_stores: every pass clears through color_pass or earlier()
at 0.5; clear_tie() adds the note to each expected set (MoltenVK's
pipelines record no color-conversion note, so it showed there first).
- resolves: the depth stand-in clears Depth16Unorm to 0.5 (32767.5
codes): Metal's 0x7fff or the device's 0x8000, and the note announced
exactly for that format.
- buffer_depth_samples: the 16-bit clear to 0.25 (16383.75 codes)
announces unorm-depth-rounding.
- buffer_texture_blits: the planar depth clears (0.375, 0.625, 0.875)
hold Metal's truncated code or the one above it, the note's bound.
Verified: the four lanes' failing tests on lavapipe (linux-gate
halfnative) failed before these edits; on MoltenVK (Apple M3 Max,
maclock) dont_care_stores, resolves' depth stand-in,
buffer_depth_samples and the planar depth lane pass with them.
* Merge a fetched attachment's sample planes back before its twin resolve
A pass whose last draws fetch a multisampled attachment through sample
planes (the pixel interlock without multisampled storage images: ANV,
MoltenVK) left the planes unmerged after it under MultisampleResolve
wherever the crate-owned resolve drew the attachment's resolve, on the
reading that that resolve reads the planes. A resolve into the
attachment's sRGB twin is crate-owned but reads the attachment itself
(color_resolve.rs filters its planes out), so it resolved samples the
pass never wrote: on MoltenVK a 4x RGBA8Unorm attachment cleared to 0,
fetched once and resolved into RGBA8Unorm_sRGB read all zeros, where
the same pass stored too resolves (255, 225, 0, 0).
The planes steps now skip the merge only for a resolve that reads the
planes, an extended-range attachment's (the flag is renamed
planes_resolve to say so); a twin resolve merges first, as a stored
attachment does.
Test: runtime_lane::framebuffer_fetch::planes::
a_twin_resolve_of_a_fetched_attachment_reads_its_samples holds the
MultisampleResolve answer to the StoreAndMultisampleResolve one.
Verified on MoltenVK (Apple M3 Max, maclock): the test failed without
the fix (zeros) and passes with it, beside the planes, memoryless,
kept_resolves and twin-resolve lanes (18 passed); the runtime's
sample_planes unit tests pass.
* Expect the clear note in color_reformat's passes, through one helper
color_reformat's passes clear to (0.5, 0.25, 0.75, 1.0), whose red is a
tie in an 8-bit unorm channel, so the device's conversion of the clear
announces device-color-conversion at the device's first such pass.
Lavapipe's pipelines record the note already; MoltenVK's record none
(VkProperty::MetalColorWrites), so its exact notice sets failed there.
degrade_notices::tie_cleared() names that note for every lane whose
passes clear at a tie; dont_care_stores' local helper moves there.
Verified on MoltenVK (Apple M3 Max, maclock): color_reformat and
dont_care_stores pass (they failed in the full runtime_lane run before
this change).
* Hold the kept compressed-blit encodings to the ledger, and declare their notes
Since 01f733c6f0 a blit through a texture Metal keeps losslessly
compressed is the device's copy, which keeps the bytes Metal's
compression rewrites into the canonical encoding. The lavapipe replay
then read 46 rows the ledger did not expect:
- 28 value sites of compressed-blits-{bgra10xr,bgra10xr-srgb,rg11b10f,
rgb9e5f}: the device's bytes against Metal's canonical encoding. Each
is now a known-gaps.tsv row (venue llvmpipe) naming the note that
records it: extended-range-bits-kept, device-nan-encoding,
shared-exponent-kept, whose bound (the same value, another encoding)
covers it. Nothing is open: rule 1 rules out writing Metal's encoding.
- 18 notice sites of fresh-pattern-{552,553,93}, xr-draw-bgra10xr*
and xr-clear-routes-bgra10xr*: their read-backs blit out of such a
texture and announce the note, every value exact. They now declare
it through compressed_blits::kept_encoding_notice, the one table of
which format announces which note (device-nan-encoding is native and
declared for every case already). fresh_contents' row-notice test
counts the three pattern rows' second allowance.
docs/CONFORMANCE-COVERAGE.md regenerated (the ledger's row count).
Verified: conformance replay --cpu on lavapipe (linux-gate halfnative,
arm64): exit 0, 751 rows, exactly the ledger's (723 before the series
plus these 28), 0 unlisted and 0 stale; cargo nextest -p
metal2vulkan-conformance (1005 passed); clippy -D warnings.
* Format owned_divisions' bind import after the rebase
The rebase onto development dropped both CompressedBlit (this series)
and BlockDecode (development's BC twin removal) from the import, which
rustfmt now joins onto one line. No behaviour changes.
Verified: cargo fmt --all --check.
* 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.
189 lines
9.4 KiB
Rust
189 lines
9.4 KiB
Rust
//! Blits through a texture Metal keeps losslessly compressed.
|
|
//!
|
|
//! **Metal's answers** (an Apple M4 under macOS 27.0.1, plain; random bytes through every blit
|
|
//! direction, every level, slice and texture type, heap textures and views; the package share-cblit
|
|
//! on an Apple M3 Max under 26.7 and the M3 Max under 27.0.1 alike). Metal keeps a texture
|
|
//! losslessly compressed where `texture/heap_tiled.rs`'s rule holds (`metal_compresses`:
|
|
//! `allowGPUOptimizedContents`, the shorter side of level 0 16 texels or more, a colour format of
|
|
//! neither `ShaderWrite` nor `PixelFormatView` usage). A GPU blit that reads or writes such a
|
|
//! texture (a buffer into it, it into a buffer, a texture into another either way) moves its texels
|
|
//! through the compression, which writes three families' texels in their canonical encoding, the
|
|
//! same value: `BGRA10_XR` (and its `_sRGB` twin) each 16-bit field's low six bits cleared and the
|
|
//! alpha code clamped to `[384, 894]`, `RG11B10Float` a NaN field made the quiet NaN, `RGB9E5Float`
|
|
//! the shared exponent lowered to the least that holds the texel's value. The 70 other formats the
|
|
//! census tried keep their bytes, and so do a texture over a buffer or of an IOSurface and CPU
|
|
//! copies (`replace_region`, `get_bytes`) of any texture.
|
|
//!
|
|
//! **The runtime's answer** is the device's copy, which keeps the bytes it read: the canonical
|
|
//! encoding is Metal's compressor's, not the format's (Metal's own uncompressed texture of the
|
|
//! format keeps the bytes through the same blit), and a texel whose bytes no Metal write left
|
|
//! (uploaded or copied bytes) reads the same value either way: alpha reads clamped and the low six
|
|
//! bits unread for `BGRA10_XR`, a NaN for `RG11B10Float`, the value for `RGB9E5Float`. A blit through
|
|
//! such a texture announces the note of its format ([`kept_encoding`]: `extended-range-bits-kept`,
|
|
//! `device-nan-encoding`, `shared-exponent-kept`), once per device, except where the device's own
|
|
//! copy is Metal's blit of a compressed image ([`copy_rewrites`]).
|
|
//!
|
|
//! **MoltenVK** (`RuntimeDriverDefect::CompressedImageCopiesRewriteTexels`): its copies of an
|
|
//! image are Metal's blits, so a copy of a compressed `RG11B10Float` or `RGB9E5Float` image writes
|
|
//! the canonical encoding. A CPU copy, which the runtime makes a Vulkan copy, would make it too, so
|
|
//! the image of a `Shared` or `Managed` texture that Metal compresses is made uncompressed there
|
|
//! (`PixelFormatView` usage, [`Device::copy_exact_usage`]), and so is a device's own texture's
|
|
//! without `allowGPUOptimizedContents`, whose blits Metal makes on an uncompressed texture: its
|
|
//! image of the texture's own usage would be compressed (a heap's texture still takes the
|
|
//! compressed image's bytes of the heap).
|
|
|
|
use super::error::Error;
|
|
use super::texture::heap_tiled::metal_compresses;
|
|
use super::texture::Texture;
|
|
use super::texture_descriptor::{TextureDescriptor, TextureLayout};
|
|
use super::values::StorageMode;
|
|
use super::{Degradation, Device};
|
|
use metal2vulkan::error::RuntimeDriverDefect;
|
|
use metal2vulkan::metal::format::is_depth_stencil;
|
|
use metal2vulkan::metal::{PixelFormat, TextureType, TextureUsage};
|
|
use metal2vulkan::vk::{Format, ImageCreateFlags, ImageUsageFlags};
|
|
|
|
/// The note a blit through a compressed texture of `pf` announces, whose texels Metal's
|
|
/// compression writes in their canonical encoding (the module docs); `None` for a format whose
|
|
/// blits keep their bytes on Metal too.
|
|
fn kept_encoding(pf: PixelFormat) -> Option<Degradation> {
|
|
match pf {
|
|
PixelFormat::BGRA10XR | PixelFormat::BGRA10XRSRGB => {
|
|
Some(Degradation::ExtendedRangeBitsKept)
|
|
}
|
|
PixelFormat::RG11B10Float => Some(Degradation::DeviceNanEncoding),
|
|
PixelFormat::RGB9E5Float => Some(Degradation::SharedExponentKept),
|
|
_ => None,
|
|
}
|
|
}
|
|
|
|
/// Whether Metal keeps a texture of `pixel_format` losslessly compressed and its blits rewrite
|
|
/// its texels ([`kept_encoding`]): a texture (a view's first) of `texture_type`, its level 0
|
|
/// `width` by `height`, of `samples` samples and the `(usage, allowGPUOptimizedContents)` of
|
|
/// `optimized`.
|
|
fn rewritten(
|
|
pixel_format: PixelFormat,
|
|
texture_type: TextureType,
|
|
[width, height]: [u64; 2],
|
|
samples: u64,
|
|
(usage, allow_gpu_optimized_contents): (TextureUsage, bool),
|
|
) -> bool {
|
|
let one_row = matches!(texture_type, TextureType::Type1D | TextureType::Type1DArray);
|
|
let level0 = [width, if one_row { 1 } else { height }];
|
|
let colour = !is_depth_stencil(pixel_format);
|
|
samples == 1
|
|
&& kept_encoding(pixel_format).is_some()
|
|
&& metal_compresses(colour, usage, allow_gpu_optimized_contents, level0)
|
|
}
|
|
|
|
/// Whether a driver of `RuntimeDriverDefect::CompressedImageCopiesRewriteTexels` rewrites texels
|
|
/// in its copies of a compressed image of `format`: the Vulkan formats MoltenVK makes Metal's
|
|
/// `RG11B10Float` and `RGB9E5Float` textures of. `BGRA10_XR`'s images are of a format whose
|
|
/// copies keep their bytes.
|
|
fn copies_rewrite(format: Format) -> bool {
|
|
matches!(
|
|
format,
|
|
Format::B10G11R11_UFLOAT_PACK32 | Format::E5B9G9R9_UFLOAT_PACK32
|
|
)
|
|
}
|
|
|
|
/// Whether `texture`'s own copies write Metal's canonical encoding: on a driver whose copies of a
|
|
/// compressed image rewrite texels, an image of such a format that Metal keeps compressed (neither
|
|
/// `STORAGE` usage nor `MUTABLE_FORMAT`).
|
|
fn copy_rewrites(texture: &Texture) -> Result<bool, Error> {
|
|
let defects = &texture.device().properties().driver_defects;
|
|
if !defects.contains(&RuntimeDriverDefect::CompressedImageCopiesRewriteTexels) {
|
|
return Ok(false);
|
|
}
|
|
let plan = texture.image_plan()?;
|
|
Ok(copies_rewrite(plan.format)
|
|
&& !plan.usage.contains(ImageUsageFlags::STORAGE)
|
|
&& !plan.flags.contains(ImageCreateFlags::MUTABLE_FORMAT))
|
|
}
|
|
|
|
/// Announce, for a blit (`call`) that reads or writes `texture`, the note of its format's
|
|
/// canonical encoding where Metal keeps the texture losslessly compressed and the device's copy
|
|
/// keeps the bytes (the module docs).
|
|
pub(super) fn degrade_compressed_blit(call: &'static str, texture: &Texture) -> Result<(), Error> {
|
|
if texture.over_buffer() {
|
|
return Ok(());
|
|
}
|
|
let mut root = texture;
|
|
while let Some(parent) = root.parent_texture() {
|
|
root = parent;
|
|
}
|
|
let pf = texture.pixel_format();
|
|
let compressed = rewritten(
|
|
pf,
|
|
root.texture_type(),
|
|
[root.width(), root.height()],
|
|
texture.sample_count(),
|
|
(root.usage(), root.allow_gpu_optimized_contents()),
|
|
);
|
|
let Some(kind) = kept_encoding(pf).filter(|_| compressed) else {
|
|
return Ok(());
|
|
};
|
|
if copy_rewrites(texture)? {
|
|
return Ok(());
|
|
}
|
|
let what = match kind {
|
|
Degradation::ExtendedRangeBitsKept => {
|
|
"clears each field's low six bits and clamps the alpha code to [384, 894]"
|
|
}
|
|
Degradation::DeviceNanEncoding => "makes a NaN field the quiet NaN",
|
|
_ => "lowers the shared exponent to the least that holds the texel's value",
|
|
};
|
|
texture.device().degrade(kind, || {
|
|
(
|
|
format!("{call} through a {pf:?} texture Metal keeps losslessly compressed"),
|
|
format!(
|
|
"the device's copy keeps the texels' bytes, where Metal's blit through its \
|
|
compression {what}: the same value in another encoding"
|
|
),
|
|
)
|
|
});
|
|
Ok(())
|
|
}
|
|
|
|
impl Device {
|
|
/// `usage`, the usage of the image of `format` of a texture of `descriptor` (checked as
|
|
/// `layout`), with `PixelFormatView` where this device's copies of the image would rewrite
|
|
/// texels Metal keeps (`RuntimeDriverDefect::CompressedImageCopiesRewriteTexels`): an image
|
|
/// of a format whose copies rewrite, which the device's Metal keeps compressed (an image of
|
|
/// `usage` with GPU-optimized contents, [`rewritten`]), of a texture whose bytes Metal keeps
|
|
/// through such a copy: a `Shared` or `Managed` texture, which CPU copies read and write, or
|
|
/// one without `allowGPUOptimizedContents`, which Metal keeps uncompressed, so that its GPU
|
|
/// blits keep the bytes too. Metal keeps an image of that usage uncompressed (MoltenVK makes a
|
|
/// `PixelFormatView` Metal texture of a `MUTABLE_FORMAT` image with no list of formats), so its
|
|
/// copies keep the bytes. `None` elsewhere: a `Private` texture with GPU-optimized contents,
|
|
/// whose bytes no CPU copy reads or writes, keeps the compression.
|
|
pub(super) fn copy_exact_usage(
|
|
&self,
|
|
descriptor: &TextureDescriptor,
|
|
layout: &TextureLayout,
|
|
format: Format,
|
|
usage: TextureUsage,
|
|
) -> Option<TextureUsage> {
|
|
let properties = self.properties();
|
|
let defect = RuntimeDriverDefect::CompressedImageCopiesRewriteTexels;
|
|
let reachable = matches!(
|
|
descriptor.resource_options.storage_mode(),
|
|
Ok(StorageMode::Shared | StorageMode::Managed)
|
|
);
|
|
let [width, height, _] = layout.extent;
|
|
let compressed = rewritten(
|
|
layout.pixel_format,
|
|
layout.texture_type,
|
|
[u64::from(width), u64::from(height)],
|
|
u64::from(layout.samples),
|
|
(usage, true),
|
|
);
|
|
let kept = reachable || !descriptor.allow_gpu_optimized_contents;
|
|
let rewrites = properties.driver_defects.contains(&defect)
|
|
&& kept
|
|
&& copies_rewrite(format)
|
|
&& compressed;
|
|
rewrites.then_some(usage | TextureUsage::PIXEL_FORMAT_VIEW)
|
|
}
|
|
}
|