From 2ec1f9fdc8bd77b0fbd2174370284ed6eb8b8977 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 28 Oct 2026 05:04:43 +0200 Subject: [PATCH] Read an sRGB texel through the device's own decode wherever the device samples its format One work packet, landed as 2 commits (9835965499..1a930f5dc1 on archive/development-linear-2026-10-28), in order: * Read an sRGB texel through the device's own decode wherever the device samples its format Rule 1 makes the device's texel conversion the answer wherever it has a native form. A texture bound in an 8-bit sRGB format (and the sRGB forms of BC1 to BC3, BC7, PVRTC, ETC2, EAC and ASTC) was read through a second UNORM "raw" view and decoded through Metal's twelve-bit table on every device; that emulated Metal's bits where the device decodes sRGB itself. What changed: - Every read, nearest and filtered sample, pixel fetch, gather and bicubic tap of a sampled sRGB texture now reads the device's decode through the slot's sRGB view (a decoded twin's R8G8B8A8_SRGB view where the device lacks the compressed format). An input-attachment read of an sRGB color attachment reads the device's decode too (the snap-to-byte and table decode in lower/fragment/color.rs is gone). - The note is the existing PrecisionNote::SrgbTexelDecode: specialized on the bound format's class (BicubicTexels::SRGB, SpecKey::BoundTexelFormat, announced at the draw or dispatch), outright for a heap element, and at link for a float input attachment over an sRGB attachment (StageIo::decoded_fetches). On MoltenVK the module requires VkProperty::MetalSampler instead. - The capability fallback stays: a format the device cannot sample, held as its UNORM twin (R8Unorm_sRGB and RG8Unorm_sRGB on lavapipe, RG8Unorm_sRGB on ANV and NVIDIA among the committed profiles), joins the SrgbTexture variant (srgb_twin_on) and decodes the twin's codes through Metal's table through the slot's own binding: exact for one texel's codes, the device's filter of the codes otherwise (noted). The storage alias, tile, word-attachment and pack/unpack table uses are untouched. - Deleted: the raw view and its plumbing (ResourceKind::RawTexture, BindingSource::RawTexture, CombinedSampler::raw/with_raw/sampler_binding_use, TextureDecls::raw, SlotPlan::raw, BindingKey::raw), texel_format::srgb_raw_view and srgb_raw_on, RuntimeFact::SrgbDeviceDecode, VariantKey/LoweringInputs::srgb_twins (merged into srgb_textures), LoweringInputs::srgb_fetches and the input attachment's snap, the runtime image plan's extra UNORM view of sampled sRGB images, and the ASTC-native bicubic refusal. srgb_raw is renamed srgb_coded. - Versions: SEMANTICS_VERSION 1891, RUNTIME_VERSION 1672 (the image plan lists no raw view; a notice text changed), ARTIFACT_FORMAT_VERSION 469 (CombinedSampler::raw removed, StageIo field renamed). The runtime-sources pin is left for the landing. - Docs: FAST-PATHS rows (sampling, texel conversion with the measured bound, ASTC twin), the stale "runtime sampler's nearest sRGB sample" known gap removed, SrgbTexelDecode moved to the device-gap class in tests::fast_paths; PrecisionNote docs, DriverDeviation::MetalSampler, docs/API.md's catalogue, decode module docs, runtime notice texts. - Lanes: a new runtime_lane::srgb_decode reads every code of RGBA8Unorm_sRGB; the ASTC, ETC, PVRTC, BC, cross-class and fetch lanes hold an sRGB color channel to the device's decode of its own code (srgb_decode_holds: bit for bit through Metal's own texture unit) and assert where the note is announced. The BC lane keeps development's no-twin structure: an sRGB color channel off a measured driver holds as the device's sRGB decode of a code within compressed-texel-decode's bound; the ASTC CPU-write lane's check takes the device's exactness. - known-gaps.tsv: 21 new llvmpipe rows (ETC2, EAC, ASTC sRGB reads, the read-write tier's sRGB round trip), the 12 BC1 to BC3 sRGB rows' answers and words (the device's BC decode, then its sRGB decode: both notes), the 8 sRGB fetch rows' answers updated; CONFORMANCE-COVERAGE.md regenerated. Measured: llvmpipe (LLVM 21.1.8, arm64) decodes every color code within 5.25 table steps (0.00128) of Metal's value; MoltenVK on the M3 Max equals Metal at all 1024 lanes, read and sampled, and in the cross-class gathers (0 of 240 words differ through each class). Words (lavapipe, one-access kernels, a slot bound in RGBA8Unorm_sRGB): read half 2941 -> 1131, read float 2513 -> 836, fetch half 3062 -> 1264, nearest float 2580 -> 915, gather alpha half 2934 -> 1191, gather red float 2571 -> 896; linear and runtime samples unchanged (1210, 1163); a bicubic sample grows, 10524 -> 13254 half and 10318 -> 13048 float (the emulated sum of the device's decoded taps). The twin variant loses its raw binding (read half 2941 -> 2929). Verified, on this tree (rebased onto 7b5cf8328d): cargo fmt; clippy --workspace --all-targets --all-features -D warnings, plain and under --cfg m2v_gpu; rustdoc -D warnings; scripts/api-docs; api_signatures re-blessed (the 9 removals listed above); REFUSALS.md unchanged; 700 of 701 focused metal2vulkan tests (lower::texture/sampler/fragment/select, pipeline, metal, spirv::requirements, the texture/sampler/fragment/srgb engine tests, fast_paths, surfaces) pass, the golden table failing as it does on 7b5cf8328d itself (1608 cells changed under unchanged keys): blessed on both trees, this change moves 0 cells; the conformance suite's 1007 tests pass. On lavapipe (scripts/linux-gate, arm64): 168 touched runtime-lane tests pass; the runtime crate passes 1368 of 1369, the one failure deferred_calls::a_commit_after_an_end_in_flight_returns_and_keeps_its_order (status Scheduled where Committed is expected, no texture involved) failing again in 1 of 5 reruns, a timing flake; `conformance replay --cpu` exits 0 with no unlisted or stale row. MoltenVK lanes were not rerun after the rebase. * 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. --- .../metal2vulkan-conformance/known-gaps.tsv | 67 +- .../src/cases/astc_textures.rs | 8 +- .../src/cases/etc_textures.rs | 20 +- crates/metal2vulkan-runtime/src/astc.rs | 3 +- .../metal2vulkan-runtime/src/degradation.rs | 8 +- crates/metal2vulkan-runtime/src/etc.rs | 4 +- crates/metal2vulkan-runtime/src/image_plan.rs | 14 +- crates/metal2vulkan-runtime/src/texture.rs | 3 +- .../src/texture/decoded_twin.rs | 13 +- .../runtime-sources.sha256 | 2 +- .../src/runtime_lane.rs | 27 + .../src/runtime_lane/astc_textures.rs | 48 +- .../src/runtime_lane/compressed_decode.rs | 41 +- .../src/runtime_lane/cross_class_reads.rs | 44 +- .../src/runtime_lane/etc_textures.rs | 12 +- .../runtime_lane/framebuffer_fetch/srgb.rs | 11 +- .../src/runtime_lane/heap_extended_reads.rs | 4 +- .../src/runtime_lane/pvrtc_textures.rs | 9 +- .../src/runtime_lane/rgbx_textures.rs | 11 +- .../src/runtime_lane/srgb_decode.rs | 117 ++ crates/metal2vulkan/src/bind/astc_decode.rs | 7 +- crates/metal2vulkan/src/bind/etc_decode.rs | 5 +- crates/metal2vulkan/src/bind/graphics.rs | 14 +- crates/metal2vulkan/src/bind/mipmap_filter.rs | 8 +- crates/metal2vulkan/src/bind/plan.rs | 4 +- crates/metal2vulkan/src/bind/plan/compute.rs | 11 +- .../metal2vulkan/src/bind/plan/resources.rs | 106 +- .../src/bind/plan/resources/tests.rs | 8 +- crates/metal2vulkan/src/bind/plan/slots.rs | 63 +- crates/metal2vulkan/src/bind/pvrtc_decode.rs | 8 +- crates/metal2vulkan/src/cache/codec.rs | 7 +- crates/metal2vulkan/src/cache/mod.rs | 34 +- crates/metal2vulkan/src/cache/tests.rs | 113 +- .../metal2vulkan/src/device/driver_facts.rs | 6 +- crates/metal2vulkan/src/device/mechanism.rs | 5 +- .../src/device/tests/mechanism.rs | 7 +- crates/metal2vulkan/src/error/mod.rs | 8 +- .../metal2vulkan/src/lower/fragment/color.rs | 74 +- crates/metal2vulkan/src/lower/fragment/mod.rs | 4 +- .../src/lower/fragment/snapshot.rs | 26 +- .../metal2vulkan/src/lower/sampler/bicubic.rs | 2 +- crates/metal2vulkan/src/lower/sampler/emit.rs | 4 +- crates/metal2vulkan/src/lower/sampler/mod.rs | 38 +- .../metal2vulkan/src/lower/sampler/select.rs | 45 +- crates/metal2vulkan/src/lower/texture/emit.rs | 41 +- crates/metal2vulkan/src/lower/texture/mod.rs | 169 ++- crates/metal2vulkan/src/lower/texture/slot.rs | 11 +- crates/metal2vulkan/src/metal/bicubic.rs | 20 +- crates/metal2vulkan/src/metal/format/mod.rs | 21 +- crates/metal2vulkan/src/metal/format/tests.rs | 8 +- crates/metal2vulkan/src/metal/texel_format.rs | 168 +-- crates/metal2vulkan/src/pipeline/api_tests.rs | 3 - crates/metal2vulkan/src/pipeline/artifact.rs | 69 +- .../metal2vulkan/src/pipeline/color_writes.rs | 51 +- crates/metal2vulkan/src/pipeline/compile.rs | 31 - .../metal2vulkan/src/pipeline/compile/key.rs | 10 - .../src/pipeline/compile/tests.rs | 2 - crates/metal2vulkan/src/pipeline/facts.rs | 28 +- crates/metal2vulkan/src/pipeline/layout.rs | 4 - crates/metal2vulkan/src/pipeline/link.rs | 1 - .../metal2vulkan/src/pipeline/lower_inputs.rs | 34 +- crates/metal2vulkan/src/pipeline/stage_io.rs | 12 +- crates/metal2vulkan/src/pipeline/sym.rs | 66 +- .../src/spirv/requirements/own_pixel.rs | 10 +- .../src/spirv/requirements/snapshot.rs | 8 +- .../src/tests/engine_cross_class.rs | 36 +- .../metal2vulkan/src/tests/engine_fragment.rs | 88 +- .../src/tests/engine_image_shapes.rs | 4 +- .../src/tests/engine_rgbx_storage.rs | 4 +- .../src/tests/engine_snapshot_exact.rs | 26 +- .../src/tests/engine_sparse_unmapped.rs | 2 - ...gine_srgb_raw.rs => engine_srgb_decode.rs} | 1063 ++++++----------- crates/metal2vulkan/src/tests/fast_paths.rs | 2 +- crates/metal2vulkan/src/tests/mod.rs | 2 +- crates/metal2vulkan/tests/api_signatures.tsv | 9 - docs/API.md | 26 +- docs/CONFORMANCE-COVERAGE.md | 39 +- docs/FAST-PATHS.md | 16 +- 78 files changed, 1315 insertions(+), 1842 deletions(-) create mode 100644 crates/metal2vulkan-validation/src/runtime_lane/srgb_decode.rs rename crates/metal2vulkan/src/tests/{engine_srgb_raw.rs => engine_srgb_decode.rs} (56%) diff --git a/crates/metal2vulkan-conformance/known-gaps.tsv b/crates/metal2vulkan-conformance/known-gaps.tsv index 69a78a4d2..bb93d38ac 100644 --- a/crates/metal2vulkan-conformance/known-gaps.tsv +++ b/crates/metal2vulkan-conformance/known-gaps.tsv @@ -569,20 +569,20 @@ fetch-ordered-bgra8unorm llvmpipe divergent case/x3/texels 3904 elements differ fetch-ordered-bgra8unorm-red-alpha llvmpipe divergent case/x1/texels 1056 elements differ (U8), the largest difference 1 A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's stored code and ours are a code apart at the site's largest difference. Under the native-arithmetic contract the device's conversion of the colour into the attachment is the answer: `device-color-conversion` records that near a tie the device may store the other code, and validation derives no tolerance from it. Open: nothing. fetch-ordered-bgra8unorm-red-alpha llvmpipe divergent case/x2/texels 1600 elements differ (U8), the largest difference 1 A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's stored code and ours are a code apart at the site's largest difference. Under the native-arithmetic contract the device's conversion of the colour into the attachment is the answer: `device-color-conversion` records that near a tie the device may store the other code, and validation derives no tolerance from it. Open: nothing. fetch-ordered-bgra8unorm-red-alpha llvmpipe divergent case/x3/texels 1952 elements differ (U8), the largest difference 1 A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's stored code and ours are a code apart at the site's largest difference. Under the native-arithmetic contract the device's conversion of the colour into the attachment is the answer: `device-color-conversion` records that near a tie the device may store the other code, and validation derives no tolerance from it. Open: nothing. -fetch-ordered-bgra8unorm-srgb llvmpipe divergent case/x1 2608 elements differ (U8), the largest difference 1 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device encodes sRGB by its own approximation, where Metal encodes through its twelve-bit table, so the stored code is a code apart at a tie. Under the native-arithmetic contract the device's conversion is the answer: `device-color-conversion` records it, and validation derives no tolerance from it. Open: nothing. -fetch-ordered-bgra8unorm-srgb llvmpipe divergent case/x2 3648 elements differ (U8), the largest difference 2 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device encodes sRGB by its own approximation, where Metal encodes through its twelve-bit table, so the stored code is a code apart at a tie. Under the native-arithmetic contract the device's conversion is the answer: `device-color-conversion` records it, and validation derives no tolerance from it. This site reaches 2 where the stored code is fetched and written again, as each store's encode may move it once more; the note states no bound for such a chain. Open: nothing in the product; the note's recorded bound for a chain of sRGB stores is unstated. -fetch-ordered-bgra8unorm-srgb llvmpipe divergent case/x3 4672 elements differ (U8), the largest difference 2 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device encodes sRGB by its own approximation, where Metal encodes through its twelve-bit table, so the stored code is a code apart at a tie. Under the native-arithmetic contract the device's conversion is the answer: `device-color-conversion` records it, and validation derives no tolerance from it. This site reaches 2 where the stored code is fetched and written again, as each store's encode may move it once more; the note states no bound for such a chain. Open: nothing in the product; the note's recorded bound for a chain of sRGB stores is unstated. -fetch-ordered-bgra8unorm-srgb llvmpipe divergent case/x3-depth 4672 elements differ (U8), the largest difference 2 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device encodes sRGB by its own approximation, where Metal encodes through its twelve-bit table, so the stored code is a code apart at a tie. Under the native-arithmetic contract the device's conversion is the answer: `device-color-conversion` records it, and validation derives no tolerance from it. This site reaches 2 where the stored code is fetched and written again, as each store's encode may move it once more; the note states no bound for such a chain. Open: nothing in the product; the note's recorded bound for a chain of sRGB stores is unstated. +fetch-ordered-bgra8unorm-srgb llvmpipe divergent case/x1 3456 elements differ (U8), the largest difference 1 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function reads the fetched code through the input attachment's sRGB view, the device's own decode, and the device encodes the written colour by its own approximation, where Metal decodes and encodes through its twelve-bit table, so the stored code is a code apart, and two after a second draw reads the first's code. Under the native-arithmetic contract the device's conversions are the answer: `srgb-texel-decode` and `device-color-conversion` record them, and validation derives no tolerance from either. Open: nothing. +fetch-ordered-bgra8unorm-srgb llvmpipe divergent case/x2 5360 elements differ (U8), the largest difference 2 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function reads the fetched code through the input attachment's sRGB view, the device's own decode, and the device encodes the written colour by its own approximation, where Metal decodes and encodes through its twelve-bit table, so the stored code is a code apart, and two after a second draw reads the first's code. Under the native-arithmetic contract the device's conversions are the answer: `srgb-texel-decode` and `device-color-conversion` record them, and validation derives no tolerance from either. Open: nothing. +fetch-ordered-bgra8unorm-srgb llvmpipe divergent case/x3 6496 elements differ (U8), the largest difference 2 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function reads the fetched code through the input attachment's sRGB view, the device's own decode, and the device encodes the written colour by its own approximation, where Metal decodes and encodes through its twelve-bit table, so the stored code is a code apart, and two after a second draw reads the first's code. Under the native-arithmetic contract the device's conversions are the answer: `srgb-texel-decode` and `device-color-conversion` record them, and validation derives no tolerance from either. Open: nothing. +fetch-ordered-bgra8unorm-srgb llvmpipe divergent case/x3-depth 6496 elements differ (U8), the largest difference 2 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function reads the fetched code through the input attachment's sRGB view, the device's own decode, and the device encodes the written colour by its own approximation, where Metal decodes and encodes through its twelve-bit table, so the stored code is a code apart, and two after a second draw reads the first's code. Under the native-arithmetic contract the device's conversions are the answer: `srgb-texel-decode` and `device-color-conversion` record them, and validation derives no tolerance from either. Open: nothing. fetch-ordered-rgba8unorm llvmpipe divergent case/x1/texels 2112 elements differ (U8), the largest difference 1 A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's stored code and ours are a code apart at the site's largest difference. Under the native-arithmetic contract the device's conversion of the colour into the attachment is the answer: `device-color-conversion` records that near a tie the device may store the other code, and validation derives no tolerance from it. Open: nothing. fetch-ordered-rgba8unorm llvmpipe divergent case/x2/texels 3200 elements differ (U8), the largest difference 1 A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's stored code and ours are a code apart at the site's largest difference. Under the native-arithmetic contract the device's conversion of the colour into the attachment is the answer: `device-color-conversion` records that near a tie the device may store the other code, and validation derives no tolerance from it. Open: nothing. fetch-ordered-rgba8unorm llvmpipe divergent case/x3/texels 3904 elements differ (U8), the largest difference 1 A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's stored code and ours are a code apart at the site's largest difference. Under the native-arithmetic contract the device's conversion of the colour into the attachment is the answer: `device-color-conversion` records that near a tie the device may store the other code, and validation derives no tolerance from it. Open: nothing. fetch-ordered-rgba8unorm-red-alpha llvmpipe divergent case/x1/texels 1056 elements differ (U8), the largest difference 1 A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's stored code and ours are a code apart at the site's largest difference. Under the native-arithmetic contract the device's conversion of the colour into the attachment is the answer: `device-color-conversion` records that near a tie the device may store the other code, and validation derives no tolerance from it. Open: nothing. fetch-ordered-rgba8unorm-red-alpha llvmpipe divergent case/x2/texels 1600 elements differ (U8), the largest difference 1 A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's stored code and ours are a code apart at the site's largest difference. Under the native-arithmetic contract the device's conversion of the colour into the attachment is the answer: `device-color-conversion` records that near a tie the device may store the other code, and validation derives no tolerance from it. Open: nothing. fetch-ordered-rgba8unorm-red-alpha llvmpipe divergent case/x3/texels 1952 elements differ (U8), the largest difference 1 A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's stored code and ours are a code apart at the site's largest difference. Under the native-arithmetic contract the device's conversion of the colour into the attachment is the answer: `device-color-conversion` records that near a tie the device may store the other code, and validation derives no tolerance from it. Open: nothing. -fetch-ordered-rgba8unorm-srgb llvmpipe divergent case/x1 2608 elements differ (U8), the largest difference 1 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device encodes sRGB by its own approximation, where Metal encodes through its twelve-bit table, so the stored code is a code apart at a tie. Under the native-arithmetic contract the device's conversion is the answer: `device-color-conversion` records it, and validation derives no tolerance from it. Open: nothing. -fetch-ordered-rgba8unorm-srgb llvmpipe divergent case/x2 3648 elements differ (U8), the largest difference 2 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device encodes sRGB by its own approximation, where Metal encodes through its twelve-bit table, so the stored code is a code apart at a tie. Under the native-arithmetic contract the device's conversion is the answer: `device-color-conversion` records it, and validation derives no tolerance from it. This site reaches 2 where the stored code is fetched and written again, as each store's encode may move it once more; the note states no bound for such a chain. Open: nothing in the product; the note's recorded bound for a chain of sRGB stores is unstated. -fetch-ordered-rgba8unorm-srgb llvmpipe divergent case/x3 4672 elements differ (U8), the largest difference 2 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device encodes sRGB by its own approximation, where Metal encodes through its twelve-bit table, so the stored code is a code apart at a tie. Under the native-arithmetic contract the device's conversion is the answer: `device-color-conversion` records it, and validation derives no tolerance from it. This site reaches 2 where the stored code is fetched and written again, as each store's encode may move it once more; the note states no bound for such a chain. Open: nothing in the product; the note's recorded bound for a chain of sRGB stores is unstated. -fetch-ordered-rgba8unorm-srgb llvmpipe divergent case/x3-depth 4672 elements differ (U8), the largest difference 2 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device encodes sRGB by its own approximation, where Metal encodes through its twelve-bit table, so the stored code is a code apart at a tie. Under the native-arithmetic contract the device's conversion is the answer: `device-color-conversion` records it, and validation derives no tolerance from it. This site reaches 2 where the stored code is fetched and written again, as each store's encode may move it once more; the note states no bound for such a chain. Open: nothing in the product; the note's recorded bound for a chain of sRGB stores is unstated. +fetch-ordered-rgba8unorm-srgb llvmpipe divergent case/x1 3456 elements differ (U8), the largest difference 1 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function reads the fetched code through the input attachment's sRGB view, the device's own decode, and the device encodes the written colour by its own approximation, where Metal decodes and encodes through its twelve-bit table, so the stored code is a code apart, and two after a second draw reads the first's code. Under the native-arithmetic contract the device's conversions are the answer: `srgb-texel-decode` and `device-color-conversion` record them, and validation derives no tolerance from either. Open: nothing. +fetch-ordered-rgba8unorm-srgb llvmpipe divergent case/x2 5360 elements differ (U8), the largest difference 2 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function reads the fetched code through the input attachment's sRGB view, the device's own decode, and the device encodes the written colour by its own approximation, where Metal decodes and encodes through its twelve-bit table, so the stored code is a code apart, and two after a second draw reads the first's code. Under the native-arithmetic contract the device's conversions are the answer: `srgb-texel-decode` and `device-color-conversion` record them, and validation derives no tolerance from either. Open: nothing. +fetch-ordered-rgba8unorm-srgb llvmpipe divergent case/x3 6496 elements differ (U8), the largest difference 2 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function reads the fetched code through the input attachment's sRGB view, the device's own decode, and the device encodes the written colour by its own approximation, where Metal decodes and encodes through its twelve-bit table, so the stored code is a code apart, and two after a second draw reads the first's code. Under the native-arithmetic contract the device's conversions are the answer: `srgb-texel-decode` and `device-color-conversion` record them, and validation derives no tolerance from either. Open: nothing. +fetch-ordered-rgba8unorm-srgb llvmpipe divergent case/x3-depth 6496 elements differ (U8), the largest difference 2 A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function reads the fetched code through the input attachment's sRGB view, the device's own decode, and the device encodes the written colour by its own approximation, where Metal decodes and encodes through its twelve-bit table, so the stored code is a code apart, and two after a second draw reads the first's code. Under the native-arithmetic contract the device's conversions are the answer: `srgb-texel-decode` and `device-color-conversion` record them, and validation derives no tolerance from either. Open: nothing. half-read-nans-r16f llvmpipe divergent case/words/nearest-sample 131 elements differ (U32), the largest difference 2151669760 A `float` read or nearest sample of a 16-bit float texel's NaN: Metal answers its canonical `0x7FC00000`, and ours is this device's widening of the texel, which keeps its payload (the first differing element is Metal 0x7FC00000 against our 0x7FC02000 or 0x7FEAA000) and, at the site's largest difference of 0x803FE000, its sign. Under the native-arithmetic contract this is the device's texel conversion: `device-texel-conversion`'s recorded bound gives a half-float texel's NaN the device's encoding where Metal answers `0x7FC00000`, and validation derives no tolerance from it. Open: nothing. half-read-nans-r16f llvmpipe divergent case/words/read 131 elements differ (U32), the largest difference 2151669760 A `float` read or nearest sample of a 16-bit float texel's NaN: Metal answers its canonical `0x7FC00000`, and ours is this device's widening of the texel, which keeps its payload (the first differing element is Metal 0x7FC00000 against our 0x7FC02000 or 0x7FEAA000) and, at the site's largest difference of 0x803FE000, its sign. Under the native-arithmetic contract this is the device's texel conversion: `device-texel-conversion`'s recorded bound gives a half-float texel's NaN the device's encoding where Metal answers `0x7FC00000`, and validation derives no tolerance from it. Open: nothing. half-read-nans-rg16f llvmpipe divergent case/words/nearest-sample 258 elements differ (U32), the largest difference 2151669760 A `float` read or nearest sample of a 16-bit float texel's NaN: Metal answers its canonical `0x7FC00000`, and ours is this device's widening of the texel, which keeps its payload (the first differing element is Metal 0x7FC00000 against our 0x7FC02000 or 0x7FEAA000) and, at the site's largest difference of 0x803FE000, its sign. Under the native-arithmetic contract this is the device's texel conversion: `device-texel-conversion`'s recorded bound gives a half-float texel's NaN the device's encoding where Metal answers `0x7FC00000`, and validation derives no tolerance from it. Open: nothing. @@ -932,31 +932,32 @@ vertex-format-constant-step llvmpipe divergent case/MTLVertexFormatHalf4/rows 8 blit-generated-mipmaps llvmpipe divergent case/levels 2 elements differ (U8), the largest difference 1 `generateMipmapsForTexture:` of an 8x8 `RGBA8Unorm` texture of four levels is the device's own filter: its blit chain (`vkCmdBlitImage` with `VK_FILTER_LINEAR`), announced as `device-filtered-mipmaps` (in `replay::NATIVE_NOTES`), where Metal's levels are Apple's datapath (this case's committed recording, an Apple M3 Max under macOS 27.0.1). Two bytes of the chain are one code from Metal's, the rest Metal's. The note's documentation states no bound against Metal's answer, so what is open is that bound: one code at 8 bits here. # # A BC1 to BC5 texel on llvmpipe, whose driver is not measured to decode the formats as Metal -# does: the device's own decode of the texture's BC image, announced `compressed-texel-decode`. +# does: the device's own decode of the texture's BC image, announced `compressed-texel-decode` +# (an sRGB form's codes then through the device's sRGB decode, announced `srgb-texel-decode`). bc1-rgba llvmpipe divergent case/round/0/texels 204 elements differ (F32), the largest difference 0.00784313678741455 A BC1 texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights and rounds each channel to an 8-bit code; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 2 codes (0.007843 between the codes' `float` values). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe (3/255, a channel 3 codes off) covers the site; validation derives no tolerance from it. Open: nothing. bc1-rgba llvmpipe divergent case/round/1/texels 123 elements differ (F32), the largest difference 0.00784313678741455 A BC1 texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights and rounds each channel to an 8-bit code; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 2 codes (0.007843 between the codes' `float` values). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe (3/255, a channel 3 codes off) covers the site; validation derives no tolerance from it. Open: nothing. bc1-rgba llvmpipe divergent case/round/2/texels 142 elements differ (F32), the largest difference 0.00784313678741455 A BC1 texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights and rounds each channel to an 8-bit code; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 2 codes (0.007843 between the codes' `float` values). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe (3/255, a channel 3 codes off) covers the site; validation derives no tolerance from it. Open: nothing. bc1-rgba llvmpipe divergent case/round/3/texels 144 elements differ (F32), the largest difference 0.00784313678741455 A BC1 texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights and rounds each channel to an 8-bit code; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 2 codes (0.007843 between the codes' `float` values). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe (3/255, a channel 3 codes off) covers the site; validation derives no tolerance from it. Open: nothing. -bc1-rgba-srgb llvmpipe divergent case/round/0/texels 155 elements differ (F32), the largest difference 0.010744810104370117 A BC1 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), whose codes the format's slots decode through the same table, so a code a step off moves the value by that step of the table (the site's largest difference 0.0107). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe, 3/255 of the code before the table, covers the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every code of these blocks within it); validation derives no tolerance from it. Open: nothing. -bc1-rgba-srgb llvmpipe divergent case/round/1/texels 129 elements differ (F32), the largest difference 0.010256409645080566 A BC1 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), whose codes the format's slots decode through the same table, so a code a step off moves the value by that step of the table (the site's largest difference 0.0103). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe, 3/255 of the code before the table, covers the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every code of these blocks within it); validation derives no tolerance from it. Open: nothing. -bc1-rgba-srgb llvmpipe divergent case/round/2/texels 134 elements differ (F32), the largest difference 0.011721611022949219 A BC1 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), whose codes the format's slots decode through the same table, so a code a step off moves the value by that step of the table (the site's largest difference 0.0117). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe, 3/255 of the code before the table, covers the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every code of these blocks within it); validation derives no tolerance from it. Open: nothing. -bc1-rgba-srgb llvmpipe divergent case/round/3/texels 156 elements differ (F32), the largest difference 0.00952380895614624 A BC1 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), whose codes the format's slots decode through the same table, so a code a step off moves the value by that step of the table (the site's largest difference 0.0095). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe, 3/255 of the code before the table, covers the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every code of these blocks within it); validation derives no tolerance from it. Open: nothing. +bc1-rgba-srgb llvmpipe divergent case/round/0/texels 662 elements differ (F32), the largest difference 0.010926872491836548 A BC1 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table (`k / 4095` for the code's step `k`); ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture) read through its sRGB view, each code decoded by the device's own sRGB transfer function (the site's largest difference 0.0109). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records the block decode for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, its recorded bound for lavapipe 3/255 of the code before the sRGB decode, and `srgb-texel-decode` records the sRGB decode under the bound format (llvmpipe's within 5.25 table steps, 0.00128, of Metal's at every code, `runtime_lane::srgb_decode`); together they cover the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every channel of these blocks within them), and validation derives no tolerance from them. Open: nothing. +bc1-rgba-srgb llvmpipe divergent case/round/1/texels 660 elements differ (F32), the largest difference 0.010237425565719604 A BC1 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table (`k / 4095` for the code's step `k`); ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture) read through its sRGB view, each code decoded by the device's own sRGB transfer function (the site's largest difference 0.0102). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records the block decode for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, its recorded bound for lavapipe 3/255 of the code before the sRGB decode, and `srgb-texel-decode` records the sRGB decode under the bound format (llvmpipe's within 5.25 table steps, 0.00128, of Metal's at every code, `runtime_lane::srgb_decode`); together they cover the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every channel of these blocks within them), and validation derives no tolerance from them. Open: nothing. +bc1-rgba-srgb llvmpipe divergent case/round/2/texels 672 elements differ (F32), the largest difference 0.012284725904464722 A BC1 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table (`k / 4095` for the code's step `k`); ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture) read through its sRGB view, each code decoded by the device's own sRGB transfer function (the site's largest difference 0.0123). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records the block decode for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, its recorded bound for lavapipe 3/255 of the code before the sRGB decode, and `srgb-texel-decode` records the sRGB decode under the bound format (llvmpipe's within 5.25 table steps, 0.00128, of Metal's at every code, `runtime_lane::srgb_decode`); together they cover the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every channel of these blocks within them), and validation derives no tolerance from them. Open: nothing. +bc1-rgba-srgb llvmpipe divergent case/round/3/texels 666 elements differ (F32), the largest difference 0.009236752986907959 A BC1 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table (`k / 4095` for the code's step `k`); ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture) read through its sRGB view, each code decoded by the device's own sRGB transfer function (the site's largest difference 0.0092). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records the block decode for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, its recorded bound for lavapipe 3/255 of the code before the sRGB decode, and `srgb-texel-decode` records the sRGB decode under the bound format (llvmpipe's within 5.25 table steps, 0.00128, of Metal's at every code, `runtime_lane::srgb_decode`); together they cover the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every channel of these blocks within them), and validation derives no tolerance from them. Open: nothing. bc2-rgba llvmpipe divergent case/round/0/texels 242 elements differ (F32), the largest difference 0.00784313678741455 A BC2 texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights and rounds each channel to an 8-bit code; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 2 codes (0.007843 between the codes' `float` values). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe (3/255, a channel 3 codes off) covers the site; validation derives no tolerance from it. Open: nothing. bc2-rgba llvmpipe divergent case/round/1/texels 208 elements differ (F32), the largest difference 0.00784313678741455 A BC2 texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights and rounds each channel to an 8-bit code; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 2 codes (0.007843 between the codes' `float` values). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe (3/255, a channel 3 codes off) covers the site; validation derives no tolerance from it. Open: nothing. bc2-rgba llvmpipe divergent case/round/2/texels 234 elements differ (F32), the largest difference 0.00784313678741455 A BC2 texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights and rounds each channel to an 8-bit code; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 2 codes (0.007843 between the codes' `float` values). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe (3/255, a channel 3 codes off) covers the site; validation derives no tolerance from it. Open: nothing. bc2-rgba llvmpipe divergent case/round/3/texels 230 elements differ (F32), the largest difference 0.00784313678741455 A BC2 texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights and rounds each channel to an 8-bit code; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 2 codes (0.007843 between the codes' `float` values). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe (3/255, a channel 3 codes off) covers the site; validation derives no tolerance from it. Open: nothing. -bc2-rgba-srgb llvmpipe divergent case/round/0/texels 254 elements differ (F32), the largest difference 0.013675212860107422 A BC2 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), whose codes the format's slots decode through the same table, so a code a step off moves the value by that step of the table (the site's largest difference 0.0137). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe, 3/255 of the code before the table, covers the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every code of these blocks within it); validation derives no tolerance from it. Open: nothing. -bc2-rgba-srgb llvmpipe divergent case/round/1/texels 217 elements differ (F32), the largest difference 0.014163613319396973 A BC2 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), whose codes the format's slots decode through the same table, so a code a step off moves the value by that step of the table (the site's largest difference 0.0142). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe, 3/255 of the code before the table, covers the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every code of these blocks within it); validation derives no tolerance from it. Open: nothing. -bc2-rgba-srgb llvmpipe divergent case/round/2/texels 253 elements differ (F32), the largest difference 0.01538461446762085 A BC2 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), whose codes the format's slots decode through the same table, so a code a step off moves the value by that step of the table (the site's largest difference 0.0154). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe, 3/255 of the code before the table, covers the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every code of these blocks within it); validation derives no tolerance from it. Open: nothing. -bc2-rgba-srgb llvmpipe divergent case/round/3/texels 254 elements differ (F32), the largest difference 0.008791208267211914 A BC2 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), whose codes the format's slots decode through the same table, so a code a step off moves the value by that step of the table (the site's largest difference 0.0088). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe, 3/255 of the code before the table, covers the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every code of these blocks within it); validation derives no tolerance from it. Open: nothing. +bc2-rgba-srgb llvmpipe divergent case/round/0/texels 732 elements differ (F32), the largest difference 0.01481640338897705 A BC2 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table (`k / 4095` for the code's step `k`); ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture) read through its sRGB view, each code decoded by the device's own sRGB transfer function (the site's largest difference 0.0148). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records the block decode for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, its recorded bound for lavapipe 3/255 of the code before the sRGB decode, and `srgb-texel-decode` records the sRGB decode under the bound format (llvmpipe's within 5.25 table steps, 0.00128, of Metal's at every code, `runtime_lane::srgb_decode`); together they cover the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every channel of these blocks within them), and validation derives no tolerance from them. Open: nothing. +bc2-rgba-srgb llvmpipe divergent case/round/1/texels 751 elements differ (F32), the largest difference 0.015398383140563965 A BC2 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table (`k / 4095` for the code's step `k`); ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture) read through its sRGB view, each code decoded by the device's own sRGB transfer function (the site's largest difference 0.0154). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records the block decode for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, its recorded bound for lavapipe 3/255 of the code before the sRGB decode, and `srgb-texel-decode` records the sRGB decode under the bound format (llvmpipe's within 5.25 table steps, 0.00128, of Metal's at every code, `runtime_lane::srgb_decode`); together they cover the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every channel of these blocks within them), and validation derives no tolerance from them. Open: nothing. +bc2-rgba-srgb llvmpipe divergent case/round/2/texels 761 elements differ (F32), the largest difference 0.01559227705001831 A BC2 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table (`k / 4095` for the code's step `k`); ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture) read through its sRGB view, each code decoded by the device's own sRGB transfer function (the site's largest difference 0.0156). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records the block decode for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, its recorded bound for lavapipe 3/255 of the code before the sRGB decode, and `srgb-texel-decode` records the sRGB decode under the bound format (llvmpipe's within 5.25 table steps, 0.00128, of Metal's at every code, `runtime_lane::srgb_decode`); together they cover the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every channel of these blocks within them), and validation derives no tolerance from them. Open: nothing. +bc2-rgba-srgb llvmpipe divergent case/round/3/texels 735 elements differ (F32), the largest difference 0.009130775928497314 A BC2 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table (`k / 4095` for the code's step `k`); ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture) read through its sRGB view, each code decoded by the device's own sRGB transfer function (the site's largest difference 0.0091). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records the block decode for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, its recorded bound for lavapipe 3/255 of the code before the sRGB decode, and `srgb-texel-decode` records the sRGB decode under the bound format (llvmpipe's within 5.25 table steps, 0.00128, of Metal's at every code, `runtime_lane::srgb_decode`); together they cover the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every channel of these blocks within them), and validation derives no tolerance from them. Open: nothing. bc3-rgba llvmpipe divergent case/round/0/texels 331 elements differ (F32), the largest difference 0.00784313678741455 A BC3 texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights and rounds each channel to an 8-bit code; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 2 codes (0.007843 between the codes' `float` values). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe (3/255, a channel 3 codes off) covers the site; validation derives no tolerance from it. Open: nothing. bc3-rgba llvmpipe divergent case/round/1/texels 326 elements differ (F32), the largest difference 0.00784313678741455 A BC3 texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights and rounds each channel to an 8-bit code; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 2 codes (0.007843 between the codes' `float` values). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe (3/255, a channel 3 codes off) covers the site; validation derives no tolerance from it. Open: nothing. bc3-rgba llvmpipe divergent case/round/2/texels 341 elements differ (F32), the largest difference 0.011764705181121826 A BC3 texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights and rounds each channel to an 8-bit code; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 3 codes (0.011765 between the codes' `float` values). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe (3/255, a channel 3 codes off) covers the site; validation derives no tolerance from it. Open: nothing. bc3-rgba llvmpipe divergent case/round/3/texels 338 elements differ (F32), the largest difference 0.011764734983444214 A BC3 texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights and rounds each channel to an 8-bit code; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 3 codes (0.011765 between the codes' `float` values). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe (3/255, a channel 3 codes off) covers the site; validation derives no tolerance from it. Open: nothing. -bc3-rgba-srgb llvmpipe divergent case/round/0/texels 279 elements differ (F32), the largest difference 0.013186812400817871 A BC3 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), whose codes the format's slots decode through the same table, so a code a step off moves the value by that step of the table (the site's largest difference 0.0132). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe, 3/255 of the code before the table, covers the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every code of these blocks within it); validation derives no tolerance from it. Open: nothing. -bc3-rgba-srgb llvmpipe divergent case/round/1/texels 290 elements differ (F32), the largest difference 0.012454211711883545 A BC3 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), whose codes the format's slots decode through the same table, so a code a step off moves the value by that step of the table (the site's largest difference 0.0125). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe, 3/255 of the code before the table, covers the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every code of these blocks within it); validation derives no tolerance from it. Open: nothing. -bc3-rgba-srgb llvmpipe divergent case/round/2/texels 320 elements differ (F32), the largest difference 0.01221001148223877 A BC3 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), whose codes the format's slots decode through the same table, so a code a step off moves the value by that step of the table (the site's largest difference 0.0122). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe, 3/255 of the code before the table, covers the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every code of these blocks within it); validation derives no tolerance from it. Open: nothing. -bc3-rgba-srgb llvmpipe divergent case/round/3/texels 270 elements differ (F32), the largest difference 0.011721611022949219 A BC3 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), whose codes the format's slots decode through the same table, so a code a step off moves the value by that step of the table (the site's largest difference 0.0117). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, and its recorded bound for lavapipe, 3/255 of the code before the table, covers the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every code of these blocks within it); validation derives no tolerance from it. Open: nothing. +bc3-rgba-srgb llvmpipe divergent case/round/0/texels 834 elements differ (F32), the largest difference 0.014142632484436035 A BC3 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table (`k / 4095` for the code's step `k`); ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture) read through its sRGB view, each code decoded by the device's own sRGB transfer function (the site's largest difference 0.0141). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records the block decode for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, its recorded bound for lavapipe 3/255 of the code before the sRGB decode, and `srgb-texel-decode` records the sRGB decode under the bound format (llvmpipe's within 5.25 table steps, 0.00128, of Metal's at every code, `runtime_lane::srgb_decode`); together they cover the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every channel of these blocks within them), and validation derives no tolerance from them. Open: nothing. +bc3-rgba-srgb llvmpipe divergent case/round/1/texels 826 elements differ (F32), the largest difference 0.013140678405761719 A BC3 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table (`k / 4095` for the code's step `k`); ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture) read through its sRGB view, each code decoded by the device's own sRGB transfer function (the site's largest difference 0.0131). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records the block decode for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, its recorded bound for lavapipe 3/255 of the code before the sRGB decode, and `srgb-texel-decode` records the sRGB decode under the bound format (llvmpipe's within 5.25 table steps, 0.00128, of Metal's at every code, `runtime_lane::srgb_decode`); together they cover the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every channel of these blocks within them), and validation derives no tolerance from them. Open: nothing. +bc3-rgba-srgb llvmpipe divergent case/round/2/texels 849 elements differ (F32), the largest difference 0.012858033180236816 A BC3 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table (`k / 4095` for the code's step `k`); ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture) read through its sRGB view, each code decoded by the device's own sRGB transfer function (the site's largest difference 0.0129). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records the block decode for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, its recorded bound for lavapipe 3/255 of the code before the sRGB decode, and `srgb-texel-decode` records the sRGB decode under the bound format (llvmpipe's within 5.25 table steps, 0.00128, of Metal's at every code, `runtime_lane::srgb_decode`); together they cover the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every channel of these blocks within them), and validation derives no tolerance from them. Open: nothing. +bc3-rgba-srgb llvmpipe divergent case/round/3/texels 831 elements differ (F32), the largest difference 0.01244327425956726 A BC3 sRGB texel read on lavapipe: Metal interpolates the block's endpoints with 6-bit weights, rounds each channel to an 8-bit code and decodes the code through its twelve-bit table (`k / 4095` for the code's step `k`); ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture) read through its sRGB view, each code decoded by the device's own sRGB transfer function (the site's largest difference 0.0124). Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records the block decode for a BC1 to BC3 texture on a driver without `ColorBlockDecodeIsMetals`, its recorded bound for lavapipe 3/255 of the code before the sRGB decode, and `srgb-texel-decode` records the sRGB decode under the bound format (llvmpipe's within 5.25 table steps, 0.00128, of Metal's at every code, `runtime_lane::srgb_decode`); together they cover the site (the lane `bc1_to_bc5_texels_read_the_device_s_decode` holds every channel of these blocks within them), and validation derives no tolerance from them. Open: nothing. bc4-r-unorm llvmpipe divergent case/round/0/texels 140 elements differ (F32), the largest difference 0.008946061134338379 A BC4 unsigned texel read on lavapipe: Metal interpolates the channel's endpoints with 6-bit weights and answers its sum over 16320, unrounded; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 2.281/255. Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC4 or BC5 texture on a driver without `ChannelBlockDecodeIsMetals`, and its recorded bound for lavapipe (2.4/255) covers the site; validation derives no tolerance from it. Open: nothing. bc4-r-unorm llvmpipe divergent case/round/1/texels 160 elements differ (F32), the largest difference 0.005882352590560913 A BC4 unsigned texel read on lavapipe: Metal interpolates the channel's endpoints with 6-bit weights and answers its sum over 16320, unrounded; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 1.500/255. Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC4 or BC5 texture on a driver without `ChannelBlockDecodeIsMetals`, and its recorded bound for lavapipe (2.4/255) covers the site; validation derives no tolerance from it. Open: nothing. bc4-r-unorm llvmpipe divergent case/round/2/texels 182 elements differ (F32), the largest difference 0.006249964237213135 A BC4 unsigned texel read on lavapipe: Metal interpolates the channel's endpoints with 6-bit weights and answers its sum over 16320, unrounded; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 1.594/255. Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC4 or BC5 texture on a driver without `ChannelBlockDecodeIsMetals`, and its recorded bound for lavapipe (2.4/255) covers the site; validation derives no tolerance from it. Open: nothing. @@ -973,3 +974,27 @@ bc5-rg-snorm llvmpipe divergent case/round/0/texels 335 elements differ (F32), t bc5-rg-snorm llvmpipe divergent case/round/1/texels 291 elements differ (F32), the largest difference 0.021161407232284546 A BC5 signed texel read on lavapipe: Metal interpolates the channel's endpoints with 6-bit weights and answers its sum over 8128, unrounded; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 0.0212. Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC4 or BC5 texture on a driver without `ChannelBlockDecodeIsMetals`, and its recorded bound for lavapipe (signed 0.022) covers the site; validation derives no tolerance from it. Open: nothing. bc5-rg-snorm llvmpipe divergent case/round/2/texels 326 elements differ (F32), the largest difference 0.020915359258651733 A BC5 signed texel read on lavapipe: Metal interpolates the channel's endpoints with 6-bit weights and answers its sum over 8128, unrounded; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 0.0209. Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC4 or BC5 texture on a driver without `ChannelBlockDecodeIsMetals`, and its recorded bound for lavapipe (signed 0.022) covers the site; validation derives no tolerance from it. Open: nothing. bc5-rg-snorm llvmpipe divergent case/round/3/texels 313 elements differ (F32), the largest difference 0.017716534435749054 A BC5 signed texel read on lavapipe: Metal interpolates the channel's endpoints with 6-bit weights and answers its sum over 8128, unrounded; ours is the device's own decode of the texture's BC image (the runtime keeps no decoded twin of a BC texture), at the site's largest difference of 0.0177. Under the native-arithmetic contract the device's decode is the answer: `compressed-texel-decode` records it for a BC4 or BC5 texture on a driver without `ChannelBlockDecodeIsMetals`, and its recorded bound for lavapipe (signed 0.022) covers the site; validation derives no tolerance from it. Open: nothing. +# The device's own sRGB decode on llvmpipe: an 8-bit sRGB texel, or a compressed sRGB form's +# decoded code, read through an sRGB view is the device's decode wherever the device samples the +# format (`srgb-texel-decode`); each row says what differs, and that the note records it. +etc2-rgb8-srgb llvmpipe divergent case/seeded-blocks/texels 632 elements differ (F32), the largest difference 0.0012813806533813477 A read of an ETC2 or EAC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +etc2-rgb8-srgb llvmpipe divergent case/zero-blocks/texels 768 elements differ (F32), the largest difference 0.000134070694912225 A read of an ETC2 or EAC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +etc2-rgb8a1-srgb llvmpipe divergent case/seeded-blocks/texels 584 elements differ (F32), the largest difference 0.0012541413307189941 A read of an ETC2 or EAC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +eac-rgba8-srgb llvmpipe divergent case/seeded-blocks/texels 715 elements differ (F32), the largest difference 0.0012813806533813477 A read of an ETC2 or EAC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +eac-rgba8-srgb llvmpipe divergent case/zero-blocks/texels 768 elements differ (F32), the largest difference 0.000134070694912225 A read of an ETC2 or EAC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +astc-4x4-srgb llvmpipe divergent case/seeded-blocks/texels 288 elements differ (F32), the largest difference 0.0012541413307189941 A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +astc-5x4-srgb llvmpipe divergent case/seeded-blocks/texels 52 elements differ (F32), the largest difference 0.0011273026466369629 A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +astc-5x5-srgb llvmpipe divergent case/seeded-blocks/texels 63 elements differ (F32), the largest difference 0.0012813806533813477 A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +astc-6x5-srgb llvmpipe divergent case/seeded-blocks/texels 252 elements differ (F32), the largest difference 0.0010811686515808105 A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +astc-6x6-srgb llvmpipe divergent case/seeded-blocks/texels 290 elements differ (F32), the largest difference 0.0012347698211669922 A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +astc-8x5-srgb llvmpipe divergent case/seeded-blocks/texels 192 elements differ (F32), the largest difference 0.0009763091802597046 A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +astc-8x6-srgb llvmpipe divergent case/seeded-blocks/texels 144 elements differ (F32), the largest difference 0.000903397798538208 A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +astc-8x8-srgb llvmpipe divergent case/seeded-blocks/texels 256 elements differ (F32), the largest difference 0.001168668270111084 A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +astc-10x5-srgb llvmpipe divergent case/seeded-blocks/texels 138 elements differ (F32), the largest difference 0.0009495317935943604 A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +astc-10x6-srgb llvmpipe divergent case/seeded-blocks/texels 108 elements differ (F32), the largest difference 0.000759124755859375 A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +astc-10x8-srgb llvmpipe divergent case/seeded-blocks/texels 144 elements differ (F32), the largest difference 0.0009251236915588379 A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +astc-10x10-srgb llvmpipe divergent case/seeded-blocks/texels 338 elements differ (F32), the largest difference 0.0009988099336624146 A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +astc-12x10-srgb llvmpipe divergent case/seeded-blocks/texels 96 elements differ (F32), the largest difference 0.001266777515411377 A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +astc-12x12-srgb llvmpipe divergent case/seeded-blocks/texels 496 elements differ (F32), the largest difference 0.001266777515411377 A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +read-write-tier-round-trip-float llvmpipe divergent case/MTLPixelFormatBGRA8Unorm_sRGB/beyond/texels 804 elements differ (U32), the largest difference 200990 A read of the round-tripped 8-bit sRGB texels through the texture's sRGB view: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. +read-write-tier-round-trip-float llvmpipe divergent case/MTLPixelFormatRGBA8Unorm_sRGB/beyond/texels 805 elements differ (U32), the largest difference 200990 A read of the round-tripped 8-bit sRGB texels through the texture's sRGB view: the device decodes each 8-bit code by its own sRGB transfer function, where Metal decodes it through its twelve-bit table (`k / 4095` for the code's step `k`), and the alpha is the device's conversion of its code. Under the native-arithmetic contract the device's decode is the answer: `srgb-texel-decode` records it under the bound format, and validation derives no tolerance from it; llvmpipe's decode lies within 5.25 table steps (0.00128) of Metal's at every code (`runtime_lane::srgb_decode`), as here. Open: nothing. diff --git a/crates/metal2vulkan-conformance/src/cases/astc_textures.rs b/crates/metal2vulkan-conformance/src/cases/astc_textures.rs index 89aebe4eb..d3d217118 100644 --- a/crates/metal2vulkan-conformance/src/cases/astc_textures.rs +++ b/crates/metal2vulkan-conformance/src/cases/astc_textures.rs @@ -85,8 +85,10 @@ //! code nearest Metal's 12-bit value, which the runtime announces as `decoded-texel-precision` //! where such a texture is made, and whose catalogue entry (docs/API.md) bounds it at **1/510**. //! That is the notice's own number, not a round one. The fourteen sRGB forms hold Metal's own 8-bit -//! codes, which their slots decode through Metal's table, so they are exact and name **no tolerance -//! at all**. An `_HDR` format names none, having no twin. +//! codes, which their slots read through the twin's sRGB view, the device's own decode +//! (`srgb-texel-decode`, a native note that loosens no value), so they name **no tolerance at +//! all**: through Metal's own texture unit they are exact, and a value another device's decode +//! moves is a `known-gaps.tsv` row of its venue. An `_HDR` format names none, having no twin. //! //! Nothing here can fault a GPU: one compute pass a read, one read-only texture, one buffer, one //! thread a texel inside the texture, no loop and no sampling. @@ -440,7 +442,7 @@ impl AstcTextures { /// How far a compact texel of this format may be off Metal's value, where that is not zero: /// a linear format's half 8-bit step. `None` for an sRGB form, whose twin holds Metal's own - /// codes and whose slots decode them through Metal's table, so it names no tolerance, and + /// codes and whose slots read the device's decode of them, which loosens no value, and /// `None` for an HDR form, which has no twin to be compact about. fn compact_bound(&self) -> Option { self.decode() diff --git a/crates/metal2vulkan-conformance/src/cases/etc_textures.rs b/crates/metal2vulkan-conformance/src/cases/etc_textures.rs index 699de7165..7e2992aee 100644 --- a/crates/metal2vulkan-conformance/src/cases/etc_textures.rs +++ b/crates/metal2vulkan-conformance/src/cases/etc_textures.rs @@ -48,9 +48,10 @@ //! code, not Metal's `c / 255` correctly rounded, which the runtime announces as //! `device-texel-conversion`, whose note bounds it at **one `f32` ulp** for 8- and 16-bit codes. It reaches the three **linear** 8-bit formats //! (`ETC2_RGB8`, `ETC2_RGB8A1`, `EAC_RGBA8`): their twin holds Metal's codes exactly and the -//! device converts them. It does not reach their sRGB forms, whose colour the function decodes -//! from the raw code through Metal's twelve-bit table itself and whose alpha it converts by the -//! format's class, so no device arithmetic stands between the twin's codes and the answer. +//! device converts them. Their sRGB forms read the device's sRGB decode of the twin's codes +//! (`srgb-texel-decode`), a native note that loosens no value: Metal's answer through Metal's own +//! texture unit, and elsewhere a value the device's decode moves is a `known-gaps.tsv` row of the +//! venue. //! //! //! Nothing here can fault a GPU: one compute pass a read, one read-only texture, one buffer, one @@ -284,11 +285,10 @@ impl EtcTextures { /// Decided from the format's own shape, never from the device or the case's name: the twin /// holds 8-bit codes ([`EtcDecode::eleven_bit`] is false — an 11-bit format's compact twin /// holds 16-bit codes, whose own, wider bound `compact_bound` already covers) and the format - /// is not an sRGB form ([`srgb_raw_twin`]), whose colour the function decodes from the raw - /// code through Metal's table and whose alpha it converts by the format's class, so no device - /// conversion is involved either way. It is the same test the translator's read path makes - /// (`lower::texture`: an sRGB slot's raw codes are converted exactly, so its access records - /// no `PrecisionNote::DeviceTexelConversion`). + /// is not an sRGB form ([`srgb_raw_twin`]), whose texel is the device's sRGB decode of the + /// twin's codes (`srgb-texel-decode`), a native note that loosens no value: through Metal's + /// own texture unit Metal's, elsewhere a `known-gaps.tsv` row of the venue where the device's + /// decode moves it, so it names no texel allowance. fn device_converts_codes(&self) -> bool { !self.decode().eleven_bit() && srgb_raw_twin(self.format().format).is_none() } @@ -573,8 +573,8 @@ mod tests { /// /// - the three **linear** 8-bit formats, whose codes the device converts: one `f32` ulp, both /// rounds; - /// - their **sRGB** forms, whose colour the function decodes from the raw code through Metal's - /// twelve-bit table itself: **nothing at all**; + /// - their **sRGB** forms, the device's sRGB decode of the codes, whose note loosens no value: + /// **nothing at all**; /// - the four EAC **11-bit** formats, read from a compact 16-bit twin: half a 16-bit step by /// the format's signedness. #[test] diff --git a/crates/metal2vulkan-runtime/src/astc.rs b/crates/metal2vulkan-runtime/src/astc.rs index b1044e03a..c5744db09 100644 --- a/crates/metal2vulkan-runtime/src/astc.rs +++ b/crates/metal2vulkan-runtime/src/astc.rs @@ -20,7 +20,8 @@ //! blit out of it hand back the blocks written. Its sampled views present its decoded twin //! (`texture/decoded_twin.rs`), Metal's decode of the blocks as 8-bit codes (an LDR form's the //! code nearest Metal's 12-bit value, announced `decoded-texel-precision`; an sRGB form's its own -//! codes, which its slots read raw and decode through Metal's table, exactly), decoded after each write as a BC +//! codes, which its slots read through the twin's `R8G8B8A8_SRGB` view, the device's decode, +//! announced `srgb-texel-decode`), decoded after each write as a BC //! texture's twin is: on the GPU (`bind::astc_decode_module`), or a host write's on the CPU. //! A view in the texture's other colour space (its `_sRGB` or LDR form) presents a second twin //! of that form's decode, made at the first such view. Refused: a heap's or a sparse heap's diff --git a/crates/metal2vulkan-runtime/src/degradation.rs b/crates/metal2vulkan-runtime/src/degradation.rs index 8732c5948..4c1e28031 100644 --- a/crates/metal2vulkan-runtime/src/degradation.rs +++ b/crates/metal2vulkan-runtime/src/degradation.rs @@ -1647,8 +1647,8 @@ degradations! { /// driver not named is unmeasured, and validation derives no tolerance from them. CompressedTexelDecode = "compressed-texel-decode", Precision, "a read, sample or gather of its texels answers the device's decode of its blocks \ - (an sRGB form's code through Metal's table), where Metal interpolates with 6-bit \ - weights: a BC1 to BC3 channel up to 3/255 off Metal's on NVIDIA (615.71.09, the RTX \ + (an sRGB form's code through the device's sRGB decode), where Metal interpolates \ + with 6-bit weights: a BC1 to BC3 channel up to 3/255 off Metal's on NVIDIA (615.71.09, the RTX \ 3090 and RTX 5080 Laptop GPU; BC3's alpha 6/255) and lavapipe, 1/255 on ANV; a BC4 \ or BC5 channel up to 7.3/255 (signed 0.064) on NVIDIA, 1.3/255 (signed 0.013) on \ ANV, 2.4/255 (signed 0.022) on lavapipe, and on RADV (Mesa 26.2.4, the Radeon \ @@ -1696,8 +1696,8 @@ degradations! { /// twin's R8G8B8A8 texels hold as the nearest 8-bit code (at most 1/510 off Metal's value). /// It reads an EAC 11-bit channel as `c / 2047` (signed `c / 1023`), which the twin holds /// as the nearest 16-bit normalized code (at most half a 16-bit step off). (An ASTC sRGB - /// texture's twin holds Metal's own 8-bit codes, which its slots decode through Metal's - /// table: exact.) + /// texture's twin holds Metal's own 8-bit codes, which its slots read through the twin's + /// sRGB view, the device's decode: `srgb-texel-decode`.) DecodedTexelPrecision = "decoded-texel-precision", Precision, "a read, sample or gather of its texels answers the nearest 8-bit code to Metal's \ 12-bit value, at most 1/510 off it; an EAC 11-bit texture's, the nearest 16-bit \ diff --git a/crates/metal2vulkan-runtime/src/etc.rs b/crates/metal2vulkan-runtime/src/etc.rs index 57e40df91..114448941 100644 --- a/crates/metal2vulkan-runtime/src/etc.rs +++ b/crates/metal2vulkan-runtime/src/etc.rs @@ -18,8 +18,8 @@ //! alike (the same codes), present its decoded twin (`texture/decoded_twin.rs`): Metal's decode //! of the blocks, decoded after each write as an ASTC texture's twin is, on the GPU //! (`bind::etc_decode_module`), or a host write's on the CPU. An 8-bit format's twin holds its -//! codes, exact (an sRGB form's slots read them raw and decode them through Metal's table, -//! `metal::texel_format::srgb_raw`); an 11-bit format's holds 16-bit normalized codes +//! codes, exact (an sRGB form's views decode them as `R8G8B8A8_SRGB`, the device's sRGB decode, +//! `metal::texel_format::srgb_coded`); an 11-bit format's holds 16-bit normalized codes //! (`bind::EtcTexels::Compact`, announced `decoded-texel-precision`), or Metal's values exactly //! where the device does not take those codes' format (`EtcTexels::Float`). Announced //! `carried-decoded-twin`. diff --git a/crates/metal2vulkan-runtime/src/image_plan.rs b/crates/metal2vulkan-runtime/src/image_plan.rs index 025c18ee1..f3b4901f8 100644 --- a/crates/metal2vulkan-runtime/src/image_plan.rs +++ b/crates/metal2vulkan-runtime/src/image_plan.rs @@ -618,7 +618,7 @@ fn plan_held( let wants = |bit: TextureUsage| usage.contains(bit); // An 8-bit sRGB format the device cannot sample is sampled through its UNORM twin's view, - // whose raw codes the shader decodes as Metal does ([`holds_srgb_twin`]). + // whose codes the shader decodes through Metal's table ([`holds_srgb_twin`]). let sampled = vk_format(pf, &[FormatUsage::SampledImage].into(), profile) .ok() .or_else(|| { @@ -823,18 +823,6 @@ fn plan_held( ))); } - // The raw view through which a function decodes an 8-bit sRGB format's codes as Metal does: its - // UNORM twin's format, which the sRGB pair's views below list for the formats Metal pairs; - // `RGBX8Unorm_sRGB` has no pair (Metal's view between it and `RGBX8Unorm` is not measured), so - // its sampled image lists the raw view alone. - if usage_flags.contains(ImageUsageFlags::SAMPLED) { - if let Some(raw) = srgb_raw_twin(pf) - .and_then(direct_format) - .filter(|&raw| compatible(format, raw, true)) - { - views.insert(raw); - } - } // The sRGB twin's views, which Metal makes without `PixelFormatView`; not the view of the // twin's word (`WordAttachment`), which would make every such render target mutable for a view // few textures take: an attachment view of the twin the device renders only through its word diff --git a/crates/metal2vulkan-runtime/src/texture.rs b/crates/metal2vulkan-runtime/src/texture.rs index 2535efea1..c83cb6515 100644 --- a/crates/metal2vulkan-runtime/src/texture.rs +++ b/crates/metal2vulkan-runtime/src/texture.rs @@ -3617,8 +3617,7 @@ impl Heap { /// BC format, whose decode Vulkan leaves to the implementation: BC1 to BC3 (the sRGB forms too) /// `ColorBlockDecodeIsMetals`, BC4 and BC5 `ChannelBlockDecodeIsMetals` (NVIDIA's, ANV's and /// lavapipe's decode both otherwise, RADV's the second), BC6H `Bc6hBlockDecodeIsMetals` and BC7 -/// (its sRGB form through its unorm view and Metal's table, `metal::texel_format::srgb_raw`) -/// `Bc7BlockDecodeIsMetals` (lavapipe's lies a `float` ulp off). A texture of the format without +/// (its sRGB form too, whose codes the device's sRGB view decodes) `Bc7BlockDecodeIsMetals` (lavapipe's lies a `float` ulp off). A texture of the format without /// the fact announces `compressed-texel-decode` ([`Device::degrade_block_decode`]). Every other /// format is `None`. pub(super) fn block_decode_fact(pf: PixelFormat) -> Option { diff --git a/crates/metal2vulkan-runtime/src/texture/decoded_twin.rs b/crates/metal2vulkan-runtime/src/texture/decoded_twin.rs index a366bca16..42dbee736 100644 --- a/crates/metal2vulkan-runtime/src/texture/decoded_twin.rs +++ b/crates/metal2vulkan-runtime/src/texture/decoded_twin.rs @@ -40,7 +40,7 @@ //! //! **ASTC** (`astc.rs`): its twin holds Metal's decode as 8-bit codes (`TwinDecode::Astc`; an LDR //! form's the code nearest Metal's 12-bit value, an sRGB form's its own codes, which its slots read -//! raw and decode through Metal's table), kept in step as above (`bind::astc_decode_module` on the +//! through the twin's sRGB view, the device's decode), kept in step as above (`bind::astc_decode_module` on the //! GPU, `AstcDecode::decode_into` on the CPU): a pass's bands are of the texture's texels, each //! band's blocks copied out of the carrier's texels over them. A new one's zero blocks read //! magenta (an error block). @@ -64,7 +64,8 @@ //! `WorkCounts::second_twins`, `second_twin_checks`, `second_twin_decodes`). //! //! **PVRTC** (`pvrtc.rs`): its twin holds the blocks' codes (`TwinDecode::Pvrtc`, -//! `R8G8B8A8_UNORM`; an sRGB form's slots read them raw and decode them through Metal's table), +//! `R8G8B8A8_UNORM`; an sRGB form's slots read them through its `R8G8B8A8_SRGB` view, the +//! device's decode), //! which serve the views of the format's linear and sRGB forms alike. Each texel's colors come //! from the four blocks around it, wrapping at the level's edges, so a write's decode is of whole //! levels (`twin_region`): on the GPU (`bind::pvrtc_decode_module`), each band of a level's rows @@ -320,8 +321,8 @@ impl Decoded { fn view_format(&self, format: Format) -> Option { use Format as F; // An ASTC texture's binding views name its candidate's 8-bit format (its `_sRGB` form's - // `R8G8B8A8_SRGB`, or its raw view `R8G8B8A8_UNORM`, whose codes its twin holds): the - // twin's own view of it, or an LDR twin's exact values. + // `R8G8B8A8_SRGB`, whose codes its twin holds, or `R8G8B8A8_UNORM`): the twin's own view + // of it, or an LDR twin's exact values. // A PVRTC texture's name the same formats, and the twin holds their codes; so does an // ETC2 or EAC 8-bit format's, and an 11-bit one's name its compact texels' format. A // 4:2:2 texture's name the codes' `R8G8B8A8_UNORM` alone (it has no sRGB form). @@ -418,8 +419,8 @@ pub(crate) fn twin_plan( impl Device { /// The texels of the decoded twin of an ASTC texture of `decode` on this device: 8-bit codes, /// an LDR form's each the code nearest Metal's 12-bit value (`decoded-texel-precision`), an - /// sRGB form's its own, which its slots read raw and decode through Metal's table, exactly - /// (`metal::texel_format::srgb_raw_on`). Refused where the device does not take the codes' + /// sRGB form's its own, which its `R8G8B8A8_SRGB` view decodes, the device's sRGB decode + /// (`metal::texel_format::srgb_coded`). Refused where the device does not take the codes' /// format so (no conformant device). fn astc_texels(&self, decode: AstcDecode) -> Result { let facts = self diff --git a/crates/metal2vulkan-validation/runtime-sources.sha256 b/crates/metal2vulkan-validation/runtime-sources.sha256 index af3a86a92..8b6c770d4 100644 --- a/crates/metal2vulkan-validation/runtime-sources.sha256 +++ b/crates/metal2vulkan-validation/runtime-sources.sha256 @@ -1 +1 @@ -bbf9691cdd6c7686bff4111b21573c6f63040fcf262477798925ccc67fb94b18 +7ddb9d93ec3e6a1f9312bd47267182b9cd12d899035e4581d800308486c3e121 diff --git a/crates/metal2vulkan-validation/src/runtime_lane.rs b/crates/metal2vulkan-validation/src/runtime_lane.rs index 59c1717e7..fbec4aacb 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane.rs @@ -758,6 +758,8 @@ mod snorm_tile_store; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod sparse_textures; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] +mod srgb_decode; +#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod srgb_storage; #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] mod stage_in_regions; @@ -1677,6 +1679,31 @@ fn converted_holds(got: f32, want: f32, exact: bool) -> bool { && got.to_bits().abs_diff(want.to_bits()) <= 1) } +/// Whether `got`, a `float` channel a module read from a texel's 8-bit sRGB color code, holds as +/// Metal's `want` (the code's step of Metal's twelve-bit table over 4095, [`srgb_step`]): bit for +/// bit where `exact` (the device samples through Metal's own texture unit, +/// `pixel_samplers::metal_sampler`), else as the device's decode of the same code +/// (`PrecisionNote::SrgbTexelDecode`, whose precision Vulkan does not set): nearer `want` than +/// Metal's value of either neighbouring code. +#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] +fn srgb_decode_holds(got: f32, want: f32, exact: bool) -> bool { + if got.to_bits() == want.to_bits() { + return true; + } + if exact || !got.is_finite() { + return false; + } + let value = |c: u32| (f64::from(srgb_step(c)) / 4095.0) as f32; + let Some(code) = (0..=255).find(|&c| value(c).to_bits() == want.to_bits()) else { + return false; + }; + let off = |v: f32| (f64::from(got) - f64::from(v)).abs(); + [code.checked_sub(1), (code < 255).then_some(code + 1)] + .into_iter() + .flatten() + .all(|n| off(want) < off(value(n))) +} + /// Whether `got` holds as Metal's `half` result `want` (a value on the `half` grid, widened) under /// `PrecisionNote::NativeHalfConversion`'s recorded bound: within one unit in the last place of /// the `half`, the device rounding otherwise or not at all, so that a value Metal takes to an diff --git a/crates/metal2vulkan-validation/src/runtime_lane/astc_textures.rs b/crates/metal2vulkan-validation/src/runtime_lane/astc_textures.rs index f9eb465e4..9a2b4ba0a 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/astc_textures.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/astc_textures.rs @@ -6,7 +6,8 @@ //! carrier and its reads go through a decoded twin, announced `carried-decoded-twin` once and //! `decoded-texel-precision` once ([`ASTC_TWINS`]). Every format's texels read as Metal's after //! every kind of write ([`astc_texels_read_as_metal_s`]): an LDR form's within 1/510, an sRGB -//! form's exactly (its twin's 8-bit codes read raw and decoded through Metal's table); a new +//! form's as the device decodes its twin's 8-bit codes, Metal's own 8-bit codes (through Metal's +//! own texture unit Metal's value exactly, elsewhere `srgb-texel-decode`: [`reads_as`]); a new //! texture's zero blocks as magenta; then blocks a CPU copy //! wrote, a blit from a buffer, a fill of one block, and a copy from another ASTC texture, each //! read by a command buffer after the write's, each decoded into the twin by a GPU decode pass (a @@ -333,7 +334,8 @@ fn astc_texels_read_as_metal_s() { for c in 0..4 { let off = (got[c] - want[c]).abs(); most = most.max(off); - let fits = reads_as(decode, got[c], want[c]); + let exact = super::pixel_samplers::metal_sampler(device); + let fits = reads_as(decode, c, got[c], want[c], exact); if !fits && wrong.len() < 24 { wrong.push(format!( "{pf:?} {what} texel {t} channel {c}: {} against Metal's {}", @@ -405,39 +407,42 @@ fn astc_texels_read_as_metal_s() { }); } -/// Whether `got` reads as Metal's `want` for a channel of a texel of `decode` (the module docs): -/// an sRGB form's bit for bit (its twin's codes, decoded through Metal's table); an LDR form's -/// within 1/510. -fn reads_as(decode: AstcDecode, got: f32, want: f32) -> bool { - match decode.srgb { - true => got.to_bits() == want.to_bits(), - false => (got - want).abs() <= UNORM8_BOUND, +/// Whether `got` reads as Metal's `want` for channel `c` of a texel of `decode` on a device that +/// samples through Metal's own texture unit where `exact` (the module docs): an sRGB form's color +/// as the device's decode of the twin's code (`srgb_decode_holds`) and its alpha as the device's +/// conversion of it (`converted_holds`); an LDR form's within 1/510. +fn reads_as(decode: AstcDecode, c: usize, got: f32, want: f32, exact: bool) -> bool { + match (decode.srgb, c) { + (true, 3) => super::converted_holds(got, want, exact), + (true, _) => super::srgb_decode_holds(got, want, exact), + (false, _) => (got - want).abs() <= UNORM8_BOUND, } } -/// Note in `wrong` that `what`'s texels `got` are off Metal's decode of every one of `blocks`. +/// Note in `wrong` that `what`'s texels `got` are off Metal's decode of every one of `blocks`, on +/// a device that samples through Metal's own texture unit where `exact`. fn check( wrong: &mut Vec, what: String, - decode: AstcDecode, + (decode, exact): (AstcDecode, bool), got: &[[f32; 4]], blocks: &[&[u8]], ) { - let off = off_metal(decode, got, blocks); + let off = off_metal((decode, exact), got, blocks); if off > 0 { wrong.push(format!("{what}: {off} texels off Metal's")); } } /// The texels of `got` (`SIDE` x `SIDE`) that read as Metal's texel at their place of none of -/// `blocks` ([`reads_as`]), each a level of `decode`'s blocks. -fn off_metal(decode: AstcDecode, got: &[[f32; 4]], blocks: &[&[u8]]) -> usize { +/// `blocks` ([`reads_as`], `exact` as there), each a level of `decode`'s blocks. +fn off_metal((decode, exact): (AstcDecode, bool), got: &[[f32; 4]], blocks: &[&[u8]]) -> usize { let wants: Vec<_> = blocks.iter().map(|b| metal_texels(decode, b)).collect(); (got.iter().enumerate()) .filter(|(t, texel)| { !wants .iter() - .any(|want| (0..4).all(|c| reads_as(decode, texel[c], want[*t][c]))) + .any(|want| (0..4).all(|c| reads_as(decode, c, texel[c], want[*t][c], exact))) }) .count() } @@ -461,6 +466,7 @@ fn astc_cpu_writes_decode_on_the_cpu() { on_device(|device, messages| { let name = device.name().to_owned(); let state = reader(device); + let exact = super::pixel_samplers::metal_sampler(device); let queue = device.new_command_queue().unwrap(); let busy = Busy::new(device, &queue); let mut wrong = Vec::new(); @@ -478,6 +484,7 @@ fn astc_cpu_writes_decode_on_the_cpu() { let decode = AstcDecode::of(pf).unwrap(); let (row, count) = (row_bytes(decode), block_count(decode)); let seed = 0xa57c_b000 + 0x100 * f as u64; + let checked = (decode, exact); // Made and written while nothing is in flight. let made = device.work_counts(); let target = texture(device, pf, TextureUsage::SHADER_READ); @@ -496,7 +503,7 @@ fn astc_cpu_writes_decode_on_the_cpu() { check( &mut wrong, format!("{pf:?} written"), - decode, + checked, &got, &[&blocks], ); @@ -580,12 +587,12 @@ fn astc_cpu_writes_decode_on_the_cpu() { let got = texels(&out); let what = format!("{pf:?} {behind:?}"); match behind { - Behind::Event => check(&mut wrong, what, decode, &got, &[&new]), - Behind::Busy => check(&mut wrong, what, decode, &got, &[&old, &new]), + Behind::Event => check(&mut wrong, what, checked, &got, &[&new]), + Behind::Busy => check(&mut wrong, what, checked, &got, &[&old, &new]), } let later = texels(&later_out); let what = format!("{pf:?} {behind:?} later"); - check(&mut wrong, what, decode, &later, &[&new]); + check(&mut wrong, what, checked, &later, &[&new]); } } eprintln!( @@ -655,7 +662,8 @@ fn astc_views_in_the_other_colour_space_read_as_metal_s() { let want = metal_texels(decode, blocks); for (t, (got, want)) in got.iter().zip(&want).enumerate() { for c in 0..4 { - let fits = reads_as(decode, got[c], want[c]); + let exact = super::pixel_samplers::metal_sampler(device); + let fits = reads_as(decode, c, got[c], want[c], exact); if !fits && wrong.len() < 24 { wrong.push(format!( "{pf:?} as {:?} {what} texel {t} channel {c}: {} against Metal's {}", diff --git a/crates/metal2vulkan-validation/src/runtime_lane/compressed_decode.rs b/crates/metal2vulkan-validation/src/runtime_lane/compressed_decode.rs index 5f442f2ef..ab7b0cb0c 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/compressed_decode.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/compressed_decode.rs @@ -22,10 +22,11 @@ //! ([`Kind::fact`]: BC1 to BC3 `DriverFact::ColorBlockDecodeIsMetals`, BC4 and BC5 //! `DriverFact::ChannelBlockDecodeIsMetals`) every texel reads as Metal's (where the device does //! not sample through Metal's own texture unit, within its conversion of the codes, announced -//! `device-texel-conversion`: one `f32` unit in the last place); elsewhere the texture announces -//! `compressed-texel-decode` once ([`BLOCK_DECODES`]), and every texel reads within the largest -//! difference that note states for its format ([`noted_bound`]). A BC6H or BC7 texture announces -//! it where the driver lacks the format's fact +//! `device-texel-conversion`: one `f32` unit in the last place, and an sRGB color channel the +//! device's decode of its code, announced `srgb-texel-decode`, [`channel_holds`]); elsewhere the +//! texture announces `compressed-texel-decode` once ([`BLOCK_DECODES`]), and every texel reads +//! within the largest difference that note states for its format ([`noted_bound`]). A BC6H or +//! BC7 texture announces it where the driver lacks the format's fact //! ([`bc6h_and_bc7_announce_where_their_decode_is_unmeasured`]). After every kind of write (a //! blit into a level, a CPU copy of a region inside an array's slice, a copy into a cube's face, an //! sRGB view, and a heap's textures, fresh and over the bytes a released one left) a texture @@ -347,7 +348,7 @@ fn read_whole(device: &Device, state: &ComputePipelineState, texture: &Texture) /// driver without the kind's fact: the largest difference `compressed-texel-decode` states for /// the family (NVIDIA's, ANV's, lavapipe's and RADV's), copied here so a run past it fails rather /// than being re-fitted. An sRGB form's color channel is bound in codes (`srgb`): its value is -/// the step of a code at most that many codes from Metal's. +/// the device's sRGB decode of a code at most that many codes from Metal's. fn noted_bound(kind: Kind, c: usize) -> f32 { match kind { Kind::Bc3 if c == 3 => 6.0 / 255.0, @@ -357,18 +358,33 @@ fn noted_bound(kind: Kind, c: usize) -> f32 { } } +/// Whether channel `got` holds as Metal's `want`, bit for bit where `exact`: an sRGB color channel +/// (`srgb`) as the device's decode of its code (`srgb_decode_holds`, +/// `PrecisionNote::SrgbTexelDecode`), another within the device's conversion of the codes +/// (`converted_holds`, `PrecisionNote::DeviceTexelConversion`). +fn channel_holds((got, want): (f32, f32), exact: bool, srgb: bool) -> bool { + match srgb { + true => super::srgb_decode_holds(got, want, exact), + false => converted_holds(got, want, exact), + } +} + /// Whether channel `c` of a texel of `kind` the device read as `got` lies within the note's bound /// ([`noted_bound`]) of Metal's `want`, whose code was `code` where it is an sRGB color channel -/// (`srgb`): the step through Metal's table of a code at most the bound's codes from it (the -/// device's decode of the unorm view's code, decoded through the table), else the value within -/// the bound, one `f32` ulp beside. +/// (`srgb`): the device's sRGB decode of a code at most the bound's codes from it +/// ([`channel_holds`]), else the value within the bound, one `f32` ulp beside. fn within_note(kind: Kind, c: usize, srgb: Option, got: f32, want: f32) -> bool { let bound = noted_bound(kind, c); match srgb { Some(code) => { let codes = (bound * 255.0).round() as u32; - (code.saturating_sub(codes)..=(code + codes).min(255)) - .any(|near| converted_holds(got, ratio(super::srgb_step(near) as i32, 4095), false)) + (code.saturating_sub(codes)..=(code + codes).min(255)).any(|near| { + channel_holds( + (got, ratio(super::srgb_step(near) as i32, 4095)), + false, + true, + ) + }) } None => (got - want).abs() <= bound + f32::EPSILON, } @@ -420,12 +436,13 @@ fn bc1_to_bc5_texels_read_the_device_s_decode() { let (x, y) = (t % 16, t / 16); let want = metal_texel(kind, srgb, &blocks, x, y); for c in 0..4 { - if converted_holds(got[c], want[c], exact) { + let srgb = srgb && c < 3; + if channel_holds((got[c], want[c]), exact, srgb) { continue; } differ += 1; most = most.max((got[c] - want[c]).abs()); - let code = (srgb && c < 3).then(|| metal_code(kind, &blocks, x, y, c)); + let code = srgb.then(|| metal_code(kind, &blocks, x, y, c)); let holds = !measured && within_note(kind, c, code, got[c], want[c]); if !holds && wrong.len() < 24 { wrong.push(format!( diff --git a/crates/metal2vulkan-validation/src/runtime_lane/cross_class_reads.rs b/crates/metal2vulkan-validation/src/runtime_lane/cross_class_reads.rs index d6d20d143..e6c573fa5 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/cross_class_reads.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/cross_class_reads.rs @@ -40,17 +40,17 @@ //! in each foreign declared type, with its width and height, against the native slot's read (every //! lane, and the queries, the slot's; a read that went to the neutral would give zero texels and a //! 1 x 1 size). A sample through an argument buffer has no answer for such a member yet: it reads -//! the neutral, announced the same way. One difference is announced, and printed on a -//! `CROSS-CLASS-ANNOUNCED` line and counted apart: an 8-bit sRGB texture an argument buffer holds -//! decodes on the device, where a slot decodes its raw codes through Metal's table, where the stage -//! records `PrecisionNote::SrgbTexelDecode` and the device announced it (as `heap_extended_reads` -//! allows the same texture's own-class read). +//! the neutral, announced the same way. One difference may be announced, and is printed on a +//! `CROSS-CLASS-ANNOUNCED` line and counted apart: an 8-bit sRGB texture's read is the device's +//! decode, where the stage records `PrecisionNote::SrgbTexelDecode` and the device announced it +//! (as `heap_extended_reads` allows the same texture's own-class read). //! //! The words of an 8-bit sRGB texture's gather are also checked against Metal's own answer, not //! only against the native slot's: Metal gathers an `RGBA8Unorm_sRGB` texture through a `float`, //! `int`, or `uint` slot as the table's decode of each footprint texel's code, the same bits //! through each (the probe's texture and positions, 240 of 240 words through each class on an M4 -//! and an M3). +//! and an M3). The device decodes the texels: through Metal's own texture unit Metal's words, +//! elsewhere the device's own, the same through each class, announced. use super::degrade_notices::on_device; use super::driver_deviations::half_nan; @@ -786,12 +786,15 @@ fn metal_srgb_gather(bytes: &[u8], lane: [u32; 4]) -> [u32; 4] { ] } -/// A gather of an `RGBA8Unorm_sRGB` texture's red component through a slot of each class is -/// Metal's: each word the footprint texel's code decoded through Metal's table, the same bits -/// through a `float`, an `int`, and a `uint` slot (our probe's texture and positions: 240 of 240 -/// words through each on an M4 and an M3). No access announces the device's decode. +/// A gather of an `RGBA8Unorm_sRGB` texture's red component through a slot of each class is the +/// device's decode of the footprint texels, the same bits through a `float`, an `int`, and a `uint` +/// slot. Through Metal's own texture unit (`VkProperty::MetalSampler`) each word is Metal's, the +/// footprint texel's code decoded through Metal's table (our probe's texture and positions: 240 of +/// 240 words through each on an M4 and an M3), and nothing announces the device's decode; +/// elsewhere the gathers announce `srgb-texel-decode`, and the words that differ from Metal's are +/// counted. #[test] -fn an_srgb_gather_through_each_class_is_metals_table_decode() { +fn an_srgb_gather_through_each_class_is_the_devices_decode() { on_device(|device, messages| { let format = PixelFormat::RGBA8UnormSRGB; let (w, h) = (u64::from(W), u64::from(H)); @@ -805,9 +808,11 @@ fn an_srgb_gather_through_each_class_is_metals_table_decode() { let op = Op::Gather(Through::Constexpr(sampler_words(false)), 0); let _ = messages.take_notices(); let mut differ = 0; + let mut through: Vec> = Vec::new(); for ty in [Ty::Float, Ty::Int, Ty::Uint] { let pipeline = pipeline_of(device, &kernel(op, ty)); let got = dispatch(device, &pipeline, (&texture, None), &lanes); + through.push(got.clone()); let wrong: Vec = (0..lanes.len()).filter(|&i| got[i] != want[i]).collect(); println!( "CROSS-CLASS-SRGB-GATHER {}: {ty:?}: {} words, {} differ from Metal's table{}", @@ -834,11 +839,24 @@ fn an_srgb_gather_through_each_class_is_metals_table_decode() { .map(|n| n.degradation) .collect(); let srgb = Degradation::from_precision_note(PrecisionNote::SrgbTexelDecode); + let metals = device + .compile_device() + .profile() + .enabled() + .properties + .contains(&metal2vulkan::device::VkProperty::MetalSampler); assert!( - !kinds.contains(&srgb), + through.iter().all(|got| *got == through[0]), + "sRGB gathers differ between the classes" + ); + assert_eq!( + kinds.contains(&srgb), + !metals, "the device's decode announced: {kinds:?}" ); - assert_eq!(differ, 0, "sRGB gathers differ from Metal's table decode"); + if metals { + assert_eq!(differ, 0, "sRGB gathers differ from Metal's table decode"); + } }); } diff --git a/crates/metal2vulkan-validation/src/runtime_lane/etc_textures.rs b/crates/metal2vulkan-validation/src/runtime_lane/etc_textures.rs index fd14a6d89..6de33417c 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/etc_textures.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/etc_textures.rs @@ -6,9 +6,9 @@ //! holds its blocks in a carrier and its reads go through a decoded twin, announced //! `carried-decoded-twin` once and, for an 11-bit format, `decoded-texel-precision` once. Every //! format's texels read as Metal's after every kind of write ([`etc_texels_read_as_metal_s`]): an -//! 8-bit format's exactly (an sRGB form's colour through Metal's table, read from the twin's -//! codes; where the device does not sample through Metal's own texture unit, within its -//! conversion of the codes, announced `device-texel-conversion`: `converted_holds`), an 11-bit +//! 8-bit format's exactly (where the device does not sample through Metal's own texture unit, +//! within its conversion of the codes, announced `device-texel-conversion`: `converted_holds`; an +//! sRGB form's colour there the device's decode of the code, `srgb_decode_holds`), an 11-bit //! format's within half a 16-bit step; a new texture's zero blocks, then blocks a CPU copy wrote, //! a blit from a buffer, a fill of one block and a copy from another texture, each read by a //! command buffer after the write's, each decoded into the twin (a blit's by a GPU decode pass, a @@ -20,7 +20,7 @@ use super::astc_textures::{blit, download, read_whole, reader, texture, upload}; use super::degrade_notices::{counts, on_device}; -use super::{converted_holds, pixel_samplers::metal_sampler}; +use super::{converted_holds, pixel_samplers::metal_sampler, srgb_decode_holds}; use metal2vulkan::bind::{EtcDecode, EtcTexels, PvrtcDecode}; use metal2vulkan::device::FormatUsage; use metal2vulkan::metal::format::{srgb_raw_twin, vk_format, FormatEmulation}; @@ -171,7 +171,11 @@ fn etc_texels_read_as_metal_s() { let exact = !decode.eleven_bit(); for (t, (got, want)) in got.iter().zip(&want).enumerate() { for c in 0..4 { + let srgb = c < 3 && srgb_raw_twin(read_as).is_some(); let fits = match exact { + true if srgb => { + srgb_decode_holds(got[c], want[c], metal_sampler(device)) + } true => converted_holds(got[c], want[c], metal_sampler(device)), false => (got[c] - want[c]).abs() <= compact_bound(pf), }; diff --git a/crates/metal2vulkan-validation/src/runtime_lane/framebuffer_fetch/srgb.rs b/crates/metal2vulkan-validation/src/runtime_lane/framebuffer_fetch/srgb.rs index 7fa3ab21c..939f70360 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/framebuffer_fetch/srgb.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/framebuffer_fetch/srgb.rs @@ -33,7 +33,7 @@ //! that view (`runtime::attachment_stand_in`), or at 4x, on a device without multisampled storage //! images, into sample planes made so (`runtime::sample_planes`). Through input attachments //! (lavapipe) the function reads the device's own decode of the code, which on llvmpipe is not -//! Metal's, and takes it back to its code by Metal's encode and decodes that by Metal's table. +//! Metal's, and the pipeline records `srgb-texel-decode` there alone (asserted). //! Every byte is Metal's in either form, but where the pipeline records `device-color-conversion` //! (the device's encode of the written color, every device but MoltenVK's): there a channel within //! one code of Metal's holds, counted and printed (`device_rounded`), and a case of more than one @@ -484,8 +484,13 @@ fn an_srgb_target_is_fetched_as_metal_fetches_it() { .pipeline(&lane, (&fetch, "fetch_ordered"), false, all) .unwrap(); let descriptor = target.descriptor(&lane, (&fetch, "fetch_ordered"), false, all); - let converts = made_render_kinds(&lane.device, &descriptor) - .contains(&Degradation::DeviceColorConversion); + let made = made_render_kinds(&lane.device, &descriptor); + let converts = made.contains(&Degradation::DeviceColorConversion); + assert_eq!( + made.contains(&Degradation::SrgbTexelDecode), + inputs, + "{pf:?} at {samples}x on {device}: the device's decode of the input attachment" + ); // What the cases without the attachment stored, by their draws: where the device // converts, a later draw is Metal's map over the device's own bytes (the module docs). let mut stored: BTreeMap> = BTreeMap::new(); diff --git a/crates/metal2vulkan-validation/src/runtime_lane/heap_extended_reads.rs b/crates/metal2vulkan-validation/src/runtime_lane/heap_extended_reads.rs index ebade609a..29914b623 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/heap_extended_reads.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/heap_extended_reads.rs @@ -22,7 +22,9 @@ //! `HEAP-READ-ANNOUNCED` line and counted apart: an 8-bit sRGB texture's //! (`metal::format::srgb_raw_twin`) read through a heap pipeline whose stage records //! `PrecisionNote::SrgbTexelDecode`, which the device announced, decodes on the device where a slot -//! decodes its raw codes through Metal's table; every other difference fails. The extended-range +//! of a format the device holds as its UNORM twin decodes the codes through Metal's table (a slot +//! of a format the device samples decodes on the device too, the same words); every other +//! difference fails. The extended-range //! `_sRGB` twins, whose decode needs the module's tables, are not read so yet: their heap dispatch //! is printed on a `HEAP-READ-UNCOVERED` line, refused or not, and not counted. A texture the //! runtime does not make (the padded formats', whose plain creation is refused) is printed on a diff --git a/crates/metal2vulkan-validation/src/runtime_lane/pvrtc_textures.rs b/crates/metal2vulkan-validation/src/runtime_lane/pvrtc_textures.rs index ea8eded49..f0164f640 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/pvrtc_textures.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/pvrtc_textures.rs @@ -34,7 +34,8 @@ //! announced `carried-decoded-twin` once: every format's texels read exactly as Metal's //! (`metal2vulkan::bind::PvrtcDecode`, matched against an Apple M3 Max by its own tests; where //! the device does not sample through Metal's own texture unit, within its conversion of the -//! codes, announced `device-texel-conversion`: `converted_holds`), and so +//! codes, announced `device-texel-conversion`: `converted_holds`, an sRGB form's colour the +//! device's decode of its code, announced `srgb-texel-decode`: `srgb_decode_holds`), and so //! do its view's as the format's other colour space, after a CPU copy, a row-linear blit and a //! copy from another texture, each decoded into the twin (a blit's by a GPU decode pass, a CPU //! copy's by one or on the CPU, counted in `WorkCounts`; [`pvrtc_texels_read_as_metal_s`]). @@ -1164,7 +1165,11 @@ fn pvrtc_texels_read_as_metal_s() { for (t, got) in got.iter().enumerate() { for (c, &got) in got.iter().enumerate() { let want = as_read.metal_value(c, codes[4 * t + c]); - if !converted_holds(got, want, exact) && wrong.len() < 24 { + let holds = match as_read.srgb && c < 3 { + true => super::srgb_decode_holds(got, want, exact), + false => converted_holds(got, want, exact), + }; + if !holds && wrong.len() < 24 { wrong.push(format!( "{pf:?} {what} read as {through:?}, texel {t} channel {c}: \ {got} against Metal's {want}" diff --git a/crates/metal2vulkan-validation/src/runtime_lane/rgbx_textures.rs b/crates/metal2vulkan-validation/src/runtime_lane/rgbx_textures.rs index 1ce3a4284..05edff53b 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/rgbx_textures.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/rgbx_textures.rs @@ -78,7 +78,8 @@ impl Rng { } } -fn state(device: &Device, kernel: &str) -> ComputePipelineState { +/// `fpv_rgbx_textures`' kernel `kernel`, compiled for `device`. +pub(super) fn state(device: &Device, kernel: &str) -> ComputePipelineState { let bitcode = llvm_assemble(&engine_dir().join("fpv_rgbx_textures.ll")).unwrap(); let library = device.new_library_with_air(&bitcode).unwrap(); let function = library.new_function_with_name(kernel).unwrap(); @@ -115,7 +116,13 @@ fn bytes_of(texture: &Texture, bytes: usize) -> Vec { /// Run `kernel` over every texel of `texture` with `data` at buffer 0 (and a nearest sampler /// where `sampled`), and return buffer 0's bytes. -fn run(device: &Device, kernel: &str, texture: &Texture, data: &[u8], sampled: bool) -> Vec { +pub(super) fn run( + device: &Device, + kernel: &str, + texture: &Texture, + data: &[u8], + sampled: bool, +) -> Vec { let state = state(device, kernel); let data = buffer_with(device, data).unwrap(); let width = buffer_with(device, &(SIDE as u32).to_le_bytes()).unwrap(); diff --git a/crates/metal2vulkan-validation/src/runtime_lane/srgb_decode.rs b/crates/metal2vulkan-validation/src/runtime_lane/srgb_decode.rs new file mode 100644 index 000000000..8b482f785 --- /dev/null +++ b/crates/metal2vulkan-validation/src/runtime_lane/srgb_decode.rs @@ -0,0 +1,117 @@ +//! An 8-bit sRGB texture's texels read and sampled on the device the cfg selects, under the +//! validation layer, against Metal's decode (each color code `c` through Metal's twelve-bit table, +//! `k / 4095` for its step `k`; alpha `c / 255`): the device's own decode wherever the device +//! samples the format (`PrecisionNote::SrgbTexelDecode`). +//! +//! A 16 by 16 `RGBA8Unorm_sRGB` texture holds every code in each channel (texel `n`'s codes `n`, +//! `255 - n`, `7n + 3` and `13n + 5`, mod 256), read by a kernel's read and by its sample through a +//! nearest runtime sampler (`fpv_rgbx_textures`' `fpv_rgbx_fetch` and `fpv_rgbx_sample`). On a +//! device that samples through Metal's own texture unit (`VkProperty::MetalSampler`: MoltenVK on +//! Apple's GPU) every lane is Metal's bit for bit and nothing is announced. Elsewhere the +//! dispatches announce `srgb-texel-decode`, every color lane is the decode of its own code (nearer +//! Metal's value of that code than of either neighbour's), alpha is `c / 255` within one `f32` ulp, +//! and the lanes that differ from Metal's are counted with the largest difference, in table steps +//! (`1/4095`), on an `SRGB-DEVICE-DECODE` line. + +use super::degrade_notices::{counts, on_device}; +use super::pixel_samplers::metal_sampler; +use super::rgbx_textures::run; +use metal2vulkan::metal::{PixelFormat, TextureUsage}; +use metal2vulkan_runtime::{ + Degradation, Device, Region, ResourceOptions, Texture, TextureDescriptor, +}; + +/// The texture's side. +const SIDE: u64 = 16; + +/// The texels. +const TEXELS: usize = (SIDE * SIDE) as usize; + +/// Texel `n`'s four codes: every code in each channel. +fn codes(n: usize) -> [u8; 4] { + let n = n as u32; + [n, 255 - n, (7 * n + 3) % 256, (13 * n + 5) % 256].map(|c| c as u8) +} + +/// Metal's value of channel `channel`'s code `c`: a color code's step over 4095, alpha's code over +/// 255, each correctly rounded to `f32`. +fn metal(channel: usize, c: u8) -> f32 { + match channel { + 3 => (f64::from(c) / 255.0) as f32, + _ => (f64::from(super::srgb_step(u32::from(c))) / 4095.0) as f32, + } +} + +/// A shared texture of every code, read only. +fn texture(device: &Device) -> Texture { + let bytes: Vec = (0..TEXELS).flat_map(codes).collect(); + let mut d = TextureDescriptor::texture_2d(PixelFormat::RGBA8UnormSRGB, SIDE, SIDE, false); + d.usage = TextureUsage::SHADER_READ; + d.resource_options = ResourceOptions::shared(); + let texture = device.new_texture(&d).unwrap(); + texture + .replace_region(Region::new_2d(0, 0, SIDE, SIDE), 0, 0, &bytes, SIDE * 4, 0) + .unwrap(); + texture +} + +/// A read and a nearest sample of every code are the device's decode: Metal's bit for bit through +/// Metal's own texture unit, elsewhere announced, each color lane its own code's decode (the +/// module docs). +#[test] +fn an_srgb_texture_reads_the_devices_decode() { + on_device(|device, messages| { + let name = device.name().to_owned(); + let metals = metal_sampler(device); + let texture = texture(device); + let _ = messages.take_notices(); + for (kernel, sampled) in [("fpv_rgbx_fetch", false), ("fpv_rgbx_sample", true)] { + let out = run(device, kernel, &texture, &vec![0u8; TEXELS * 16], sampled); + let got: Vec = out + .as_chunks::<4>() + .0 + .iter() + .map(|w| f32::from_le_bytes(*w)) + .collect(); + let (mut differ, mut steps, mut misread) = (0, 0f64, Vec::new()); + for n in 0..TEXELS { + for (channel, c) in codes(n).into_iter().enumerate() { + let (read, want) = (got[4 * n + channel], metal(channel, c)); + if read.to_bits() == want.to_bits() { + continue; + } + differ += 1; + if channel == 3 { + if read.to_bits().abs_diff(want.to_bits()) > 1 { + misread.push((n, channel, c, read, want)); + } + continue; + } + steps = steps.max((f64::from(read) - f64::from(want)).abs() * 4095.0); + if !super::srgb_decode_holds(read, want, metals) { + misread.push((n, channel, c, read, want)); + } + } + } + println!( + "SRGB-DEVICE-DECODE {name} {kernel}: {differ} of {} lanes differ from Metal's, \ + color at most {steps:.4} table steps (1/4095) off", + 4 * TEXELS + ); + assert!( + misread.is_empty(), + "{kernel} on {name}: lanes (texel, channel, code, read, Metal's) not their code's \ + decode: {:?}", + &misread[..misread.len().min(8)] + ); + if metals { + assert_eq!(differ, 0, "{kernel} on {name}: Metal's own texture unit"); + } + } + let announced = counts(&messages.take_notices()) + .get(&Degradation::SrgbTexelDecode) + .copied() + .unwrap_or(0); + assert_eq!(announced > 0, !metals, "srgb-texel-decode on {name}"); + }); +} diff --git a/crates/metal2vulkan/src/bind/astc_decode.rs b/crates/metal2vulkan/src/bind/astc_decode.rs index 2915a81ab..fd3d2b240 100644 --- a/crates/metal2vulkan/src/bind/astc_decode.rs +++ b/crates/metal2vulkan/src/bind/astc_decode.rs @@ -27,9 +27,10 @@ //! **The twin's texels** ([`AstcTexels`]): [`AstcTexels::Float`] holds each texel's value exactly //! (`R32G32B32A32_SFLOAT`); [`AstcTexels::Unorm8`] holds 8-bit codes (`R8G8B8A8_UNORM`): a linear //! channel the code nearest its value, at most `1/510` off it, and an sRGB format's channels the -//! code `C >> 8` itself, which a function reads raw through the image's `R8G8B8A8_UNORM` view and -//! decodes through Metal's table (`metal::texel_format::srgb_raw_on`), exactly. The runtime holds -//! an sRGB format's twin in those codes whatever its policy. +//! code `C >> 8` itself, which Metal decodes through its table (`metal::texel_format::srgb_coded`) +//! and the device decodes through the image's `R8G8B8A8_SRGB` view +//! (`PrecisionNote::SrgbTexelDecode`). The runtime holds an sRGB format's twin in those codes +//! whatever its policy. //! //! **The GPU's decode** ([`astc_decode_module`]) is this decode in integer operations, each //! texel's from its block alone, writing the texels [`decode`](AstcDecode::decode) writes; its diff --git a/crates/metal2vulkan/src/bind/etc_decode.rs b/crates/metal2vulkan/src/bind/etc_decode.rs index 698ec85b2..9fafa5d7f 100644 --- a/crates/metal2vulkan/src/bind/etc_decode.rs +++ b/crates/metal2vulkan/src/bind/etc_decode.rs @@ -27,12 +27,13 @@ //! **Metal's answers** (an Apple M3 Max under macOS 27.0.1, our own probe: 4096 random blocks of //! each format, every texel read as `float`, equal to this decode's in every channel): an 8-bit //! channel reads `c / 255`, an sRGB format's color channel the step of Metal's twelve-bit table -//! (`lower::arith::srgb`, as BC1 to BC3's sRGB forms read, `metal::texel_format::srgb_raw`), +//! (`lower::arith::srgb`, as BC1 to BC3's sRGB forms read, `metal::texel_format::srgb_coded`), //! alpha `c / 255`; an unsigned 11-bit channel reads `c / 2047` and a signed one `c / 1023`, //! correctly rounded to `f32` (not the 16-bit code the specification widens them to). //! //! **The twin's texels** ([`EtcTexels`]): `R8G8B8A8_UNORM` codes of the ETC2 formats and -//! `EAC_RGBA8` either way (an sRGB form's codes too, for a raw view decoded by Metal's table). An 11-bit format's: [`EtcTexels::Compact`] holds the 16-bit +//! `EAC_RGBA8` either way (an sRGB form's codes too, which the device decodes through the twin's +//! `R8G8B8A8_SRGB` view). An 11-bit format's: [`EtcTexels::Compact`] holds the 16-bit //! normalized code nearest each value (`R16_UNORM`, `R16_SNORM` and their two-channel forms), at //! most half a 16-bit step off it; [`EtcTexels::Float`] holds the values exactly (`R32_SFLOAT`, //! `R32G32_SFLOAT`). diff --git a/crates/metal2vulkan/src/bind/graphics.rs b/crates/metal2vulkan/src/bind/graphics.rs index 044d0fc7b..6b56a6511 100644 --- a/crates/metal2vulkan/src/bind/graphics.rs +++ b/crates/metal2vulkan/src/bind/graphics.rs @@ -321,8 +321,8 @@ use crate::bind::plan::resources::{separate_samplers, ResourcePlanner}; use crate::bind::plan::slots::{ address_map_variant, anisotropic_variant, bindings, bound_value, buffer_use, check_slots, check_sparse_textures, cross_variant, cubic_variant, large_view_candidates, mark_disjoint, - plan_buffer, psb_variant, range_variant, record_specialized, snapshot_forms, srgb_twin_variant, - srgb_variant, storage_view_variant, used_uses, ycbcr_in_place_variant, + plan_buffer, psb_variant, range_variant, record_specialized, snapshot_forms, srgb_variant, + storage_view_variant, used_uses, ycbcr_in_place_variant, }; use crate::bind::plan::{ AccessClass, BindingPlan, BoundKind, ByteRange, DescriptorWrite, FactorSite, FactorTemplate, @@ -1962,8 +1962,7 @@ fn plan(p: &RenderPipeline, device: &Device, shape: &BindShape) -> Result { - let use_ = sampler.sampler_binding_use(); - let immutable = separate.get(&(texture.stage, use_)).ok_or_else(|| { + let immutable = separate.get(&(texture.stage, sampler)).ok_or_else(|| { internal(format!( "separate texture {texture:?} without its sampler {sampler:?}" )) @@ -2140,10 +2139,6 @@ fn plan(p: &RenderPipeline, device: &Device, shape: &BindShape) -> Result resources.tile_map(slot), - // An 8-bit sRGB texture's raw view. - BindingSource::RawTexture(slot) => { - resources.raw_texture(set.set, b.binding, b.ty, slot)? - } // The `half` shadow of an extended-range attachment the draw's instance holds. BindingSource::ExtendedShadow(color_index) => { WriteSource::ExtendedShadow { color_index } @@ -2481,7 +2476,6 @@ fn plan(p: &RenderPipeline, device: &Device, shape: &BindShape) -> Result Result Option { - let view = crate::metal::texel_format::srgb_raw_view(image).unwrap_or(image); + let view = match image { + Format::R8_SRGB => Format::R8_UNORM, + Format::R8G8_SRGB => Format::R8G8_UNORM, + Format::R8G8B8A8_SRGB => Format::R8G8B8A8_UNORM, + Format::B8G8R8A8_SRGB => Format::B8G8R8A8_UNORM, + other => other, + }; fetch::components(view).map(|_| view) } diff --git a/crates/metal2vulkan/src/bind/plan.rs b/crates/metal2vulkan/src/bind/plan.rs index 74304cd4d..8c6ff810a 100644 --- a/crates/metal2vulkan/src/bind/plan.rs +++ b/crates/metal2vulkan/src/bind/plan.rs @@ -859,8 +859,8 @@ pub enum SamplerSource { #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct ImageViewDesc { pub view_type: vk::ImageViewType, - /// The view format: the texture's own, the storage alias the variant chose, or the UNORM format - /// of an 8-bit sRGB texture's channels, its raw view. + /// The view format: the texture's own (an 8-bit sRGB texture's UNORM twin where the device + /// holds one), or the storage alias the variant chose. pub format: vk::Format, pub aspect: vk::ImageAspectFlags, /// The layout the texture is in while the draw or dispatch runs. Every write of one slot's diff --git a/crates/metal2vulkan/src/bind/plan/compute.rs b/crates/metal2vulkan/src/bind/plan/compute.rs index 38de59853..6497f1cb5 100644 --- a/crates/metal2vulkan/src/bind/plan/compute.rs +++ b/crates/metal2vulkan/src/bind/plan/compute.rs @@ -62,8 +62,7 @@ use super::resources::{separate_samplers, ResourcePlanner}; use super::slots::{ address_map_variant, anisotropic_variant, bindings, bound_value, buffer_use, check_slots, check_sparse_textures, cross_variant, cubic_variant, mark_disjoint, plan_buffer, psb_variant, - record_specialized, srgb_twin_variant, srgb_variant, storage_view_variant, used_uses, - ycbcr_in_place_variant, + record_specialized, srgb_variant, storage_view_variant, used_uses, ycbcr_in_place_variant, }; use super::{ BindingPlan, BoundKind, ComputeTemplate, DescriptorWrite, FieldLocation, LocalRules, @@ -629,8 +628,7 @@ fn plan(p: &ComputePipeline, device: &Device, shape: &BindShape) -> Result { - let use_ = sampler.sampler_binding_use(); - let immutable = separate.get(&(texture.stage, use_)).ok_or_else(|| { + let immutable = separate.get(&(texture.stage, sampler)).ok_or_else(|| { internal(format!( "separate texture {texture:?} without its sampler {sampler:?}" )) @@ -643,10 +641,6 @@ fn plan(p: &ComputePipeline, device: &Device, shape: &BindShape) -> Result resources.tile_map(slot), - // An 8-bit sRGB texture's raw view. - BindingSource::RawTexture(slot) => { - resources.raw_texture(set.set, b.binding, b.ty, slot)? - } // A tile function's attachment. BindingSource::TileAttachment(color_index) => WriteSource::TileAttachment { color_index, @@ -823,7 +817,6 @@ fn plan(p: &ComputePipeline, device: &Device, shape: &BindShape) -> Result Option { - srgb_raw_view(view.format).map(|format| ImageViewDesc { format, ..view }) -} - /// The view type of a declared image class (the binder's cube-as-2D-array view included). pub(crate) fn view_type(class: &ImageHandleClass) -> Result { use vk::ImageViewType as V; @@ -778,25 +769,6 @@ impl ResourcePlanner<'_> { .collect()) } - /// The write of slot `slot`'s raw view, binding `(set, binding)` of type `ty` - /// (`BindingSource::RawTexture`): the bound 8-bit sRGB texture through a UNORM view of its own - /// channels ([`raw_view`]), or the slot's neutral where its own binding takes one. A bound - /// format without a raw view takes the neutral too: the plan's variant then leaves the slot out - /// (`slots::srgb_variant`), so the pipeline it binds is not the one compiled. - pub fn raw_texture( - &mut self, - set: u32, - binding: u32, - ty: vk::DescriptorType, - slot: SlotRef, - ) -> Result { - if ty != vk::DescriptorType::SAMPLED_IMAGE { - return Err(internal(format!("a {ty:?} raw view of {slot:?}"))); - } - let (write, _) = self.plain_texture(set, binding, ty, slot, true)?; - Ok(write) - } - /// The level count of the texture the shape binds at `slot`. fn bound_levels(&self, slot: SlotRef) -> u32 { match self.texture_shape(slot) { @@ -828,7 +800,7 @@ impl ResourcePlanner<'_> { return Ok(self.in_place_write(slot)); } let levels_read = self.has_fact(RuntimeFact::StorageTextureLevels { slot }); - let write = self.plain_texture(set, binding, ty, slot, false)?; + let write = self.plain_texture(set, binding, ty, slot)?; self.write_rounding(slot, &write.0)?; if levels_read { let levels = match write.0 { @@ -880,15 +852,14 @@ impl ResourcePlanner<'_> { } } - /// `raw`: the binding reads the raw view ([`ResourcePlanner::texel_view`]; the neutral for a format - /// without one). + /// The write of slot `slot`'s texture binding `(set, binding)` of type `ty`, through the view + /// [`ResourcePlanner::texel_view`] gives a sampled one, and the neutral of its declared type. fn plain_texture( &mut self, set: u32, binding: u32, ty: vk::DescriptorType, slot: SlotRef, - raw: bool, ) -> Result<(WriteSource, NeutralResource), BindError> { let shape = self.texture_shape(slot).copied(); let numeric = self.has_fact(RuntimeFact::StorageTextureNumericType { slot }); @@ -1185,10 +1156,10 @@ impl ResourcePlanner<'_> { && extended.is_none() && (t.access.read || t.access.sample) && swizzled_packed(self.profile, pixel_format, swizzle); - let reads_srgb_raw = !storage + let decodes_srgb = !storage && (t.access.read || t.access.sample) && self.swizzles_decoded_srgb(slot, pixel_format, swizzle); - let shader_swizzle = (accessed || reads_extended || reads_packed || reads_srgb_raw) + let shader_swizzle = (accessed || reads_extended || reads_packed || decodes_srgb) && !swizzle.is_default(); if shader_swizzle { self.variant.swizzled_storage.insert(slot); @@ -1220,7 +1191,7 @@ impl ResourcePlanner<'_> { shader_swizzle, } } else { - match self.texel_view(pixel_format, &class, raw)? { + match self.texel_view(pixel_format, &class)? { Some((view, _)) => ImageViewDesc { shader_swizzle, ..view @@ -1243,22 +1214,17 @@ impl ResourcePlanner<'_> { } /// The view a binding of a texture slot reads a texture of `pf` through (declared `class`): - /// its sampled view, or for a binding of the raw view (`raw`) that - /// view, `None` for a format without one. Where the device cannot sample an 8-bit sRGB format, - /// whose sampled texture it holds as the format's UNORM twin (`metal::format::srgb_raw_twin`), - /// the twin's sampled view serves both bindings: the raw codes are the twin's texels, and the - /// slot's own binding is read for queries alone, or, where the function decodes texels through - /// the device's view (`RuntimeFact::SrgbDeviceDecode`), under the slot's - /// `VariantKey::srgb_twins`, whose function decodes what the device samples there. With the - /// view, the format whose sampled view it is (the twin's, where the twin serves). + /// its sampled view, an sRGB format's decoding its codes. Where the device cannot sample an + /// 8-bit sRGB format, whose sampled texture it holds as the format's UNORM twin + /// (`metal::format::srgb_raw_twin`), the twin's sampled view, which reads the codes, under the + /// slot's `VariantKey::srgb_textures`, whose function decodes them. With the view, the format + /// whose sampled view it is (the twin's, where the twin serves). fn texel_view( &self, pf: PixelFormat, class: &ImageHandleClass, - raw: bool, ) -> Result, BindError> { let missing = match self.sampled_view(pf, class) { - Ok(own) if raw => return Ok(raw_view(own).map(|view| (view, pf))), Ok(own) => return Ok(Some((own, pf))), Err(missing) => missing, }; @@ -1271,16 +1237,17 @@ impl ResourcePlanner<'_> { } } - /// Whether slot `slot`'s function decodes the raw codes of a texture of `pf` bound there with - /// `swizzle` by Metal's table (`RuntimeFact::SrgbTexture`, an 8-bit sRGB format) where the - /// swizzle moves a code between a color lane and alpha: a view's component mapping would move - /// it before the decode (a color code onto alpha, read as alpha's `c / 255`; alpha's code onto - /// a color lane, decoded through the table), where plain Metal swizzles the decoded texel. The - /// function then decodes the unswizzled texel and swizzles it, every access of the slot alike, - /// under `VariantKey::swizzled_storage`, and the slot's views take no swizzle. A swizzle among - /// the color lanes, or to a constant (0 and 1 decode to themselves), reads the same either way - /// and keeps the view's. A format whose codes the device does not hold (an ASTC sRGB format - /// it decodes itself, `srgb_raw_on`) is decoded by the device's view, swizzle and all. + /// Whether slot `slot`'s function decodes the codes of a texture of `pf` bound there with + /// `swizzle` through Metal's table (`RuntimeFact::SrgbTexture`, an 8-bit sRGB format the + /// device holds as its UNORM twin, `srgb_twin_on`) where the swizzle moves a code between a + /// color lane and alpha: a view's component mapping would move it before the decode (a color + /// code onto alpha, read as alpha's `c / 255`; alpha's code onto a color lane, decoded through + /// the table), where plain Metal swizzles the decoded texel. The function then decodes the + /// unswizzled texel and swizzles it, every access of the slot alike, under + /// `VariantKey::swizzled_storage`, and the slot's views take no swizzle. A swizzle among the + /// color lanes, or to a constant (0 and 1 decode to themselves), reads the same either way and + /// keeps the view's. A format the device samples is decoded by the device's sRGB view, which + /// decodes before its component mapping swizzles, swizzle and all. fn swizzles_decoded_srgb( &self, slot: SlotRef, @@ -1291,15 +1258,9 @@ impl ResourcePlanner<'_> { let color = |s: S| matches!(s, S::Red | S::Green | S::Blue); let crosses = color(swizzle.alpha) || [swizzle.red, swizzle.green, swizzle.blue].contains(&S::Alpha); - crosses && self.has_fact(RuntimeFact::SrgbTexture { slot }) && srgb_raw_on(pf, self.profile) - } - - /// Whether the device decodes the texels of `pf` itself, though Metal decodes them from raw - /// codes (`srgb_raw`, not `srgb_raw_on`): an ASTC sRGB format the device samples, whose - /// image's every view decodes its blocks. Its texels take no family there - /// ([`TexelFormat::OTHER`]) and no bicubic treatment, as a format outside the families. - fn decodes_srgb_itself(&self, pf: PixelFormat) -> bool { - srgb_raw(pf) && !srgb_raw_on(pf, self.profile) + crosses + && self.has_fact(RuntimeFact::SrgbTexture { slot }) + && srgb_twin_on(pf, self.profile) } /// The runtime sampler `slot` for a use, with the shape's value checks @@ -1492,9 +1453,7 @@ impl ResourcePlanner<'_> { /// The write of a combined image-sampler binding: the texture's own view type (a cube is a cube /// view) with the symbol's comparison, and the runtime sampler for the symbol's use or the - /// layout's immutable sampler (`immutable`). A raw binding (`CombinedSampler::raw`) views the - /// bound 8-bit sRGB texture as UNORM ([`raw_view`]), and binds the neutral where the bound - /// format has none (the plan's variant then leaves the slot out). A bound texture read with an + /// layout's immutable sampler (`immutable`). A bound texture read with an /// opaque-black border (the runtime sampler's shape, or the immutable sampler's clamp-to-border /// modes and color) must read it exactly through its view /// (`metal::sampler::check_border_view`). The immutable sampler's filters must be ones the @@ -1669,7 +1628,7 @@ impl ResourcePlanner<'_> { pixel_format, swizzle, .. - }) => match self.texel_view(pixel_format, &class, sampler.raw)? { + }) => match self.texel_view(pixel_format, &class)? { Some((view, viewed)) => { self.texture_use(texture, &t, false); // A swizzled packed normalized texture's sampled view takes no swizzle where @@ -1823,8 +1782,7 @@ impl ResourcePlanner<'_> { /// incompatibly, or bound in an extended-range format, whose texels the slot's variant this /// plan asks for samples itself, `VariantKey::extended_range`) takes `BicubicTexels::NEUTRAL`; /// another compatible format of no measured family is refused - /// `NotImplemented(SamplerBicubicFilter)`, and so is an ASTC sRGB format the device decodes - /// itself (`metal::texel_format::srgb_raw_on`). + /// `NotImplemented(SamplerBicubicFilter)`. pub fn bicubic_texels(&self, slot: SlotRef) -> Result { let t = *self.texture_slot(slot)?; let class = declared( @@ -1838,7 +1796,6 @@ impl ResourcePlanner<'_> { _ if self.variant.extended_range.contains_key(&slot) => BicubicTexels::NEUTRAL, Some(s @ TextureShape::Texture { pixel_format, .. }) if compatible(s, &t, &class) => { bicubic_texels(*pixel_format) - .filter(|_| !self.decodes_srgb_itself(*pixel_format)) .ok_or(BindError::Unsupported(Unsupported::not_implemented( Feature::SamplerBicubicFilter, )))? @@ -1874,12 +1831,9 @@ impl ResourcePlanner<'_> { /// function swizzles the converted texel (`VariantKey::swizzled_storage`: a storage slot's; an /// extended-range sampled one's; a packed normalized sampled one's on a device without Metal's /// own sampler, whose border texels are then the unswizzled texture's). A slot bound to nothing - /// takes [`TexelFormat::OTHER`]: a neutral reads zero, which every class converts alike. So - /// does one bound to a format the device decodes itself where Metal decodes raw codes (an ASTC - /// sRGB format the device samples, `metal::texel_format::srgb_raw_on`). + /// takes [`TexelFormat::OTHER`]: a neutral reads zero, which every class converts alike. pub fn texel_format(&self, slot: SlotRef) -> u64 { let class = match self.texture_shape(slot) { - Some(shape) if self.decodes_srgb_itself(shape.pixel_format()) => TexelFormat::OTHER.0, Some(shape) => { let class = match texel_format(shape.pixel_format()) { class if !class.has_channels() => class.0, diff --git a/crates/metal2vulkan/src/bind/plan/resources/tests.rs b/crates/metal2vulkan/src/bind/plan/resources/tests.rs index 3b061cbfc..773a7ebf5 100644 --- a/crates/metal2vulkan/src/bind/plan/resources/tests.rs +++ b/crates/metal2vulkan/src/bind/plan/resources/tests.rs @@ -278,7 +278,7 @@ fn a_numeric_slot_binds_either_integer_type() { alpha_red_texels: Default::default(), }; let (write, _) = planner - .plain_texture(0, 1, vk::DescriptorType::STORAGE_IMAGE, texture, false) + .plain_texture(0, 1, vk::DescriptorType::STORAGE_IMAGE, texture) .expect("plan"); let bound = matches!(write, WriteSource::Texture { .. }); (bound, planner.variant.storage_images.get(&texture).copied()) @@ -1460,12 +1460,12 @@ fn an_a8_texture_buffer_without_a8_unorm_views_its_bytes_in_red() { true => vk::Format::R8_UNORM, false => vk::Format::A8_UNORM, }; - let planned = planner.plain_texture(0, 0, uniform_ty, uniform, false); + let planned = planner.plain_texture(0, 0, uniform_ty, uniform); let Ok((WriteSource::TexelBuffer { format, .. }, _)) = planned else { panic!("{profile}: {planned:?}"); }; assert_eq!(format, own, "{profile}: the uniform view"); - let planned = planner.plain_texture(0, 1, storage_ty, storage, false); + let planned = planner.plain_texture(0, 1, storage_ty, storage); let Ok((WriteSource::TexelBuffer { format, .. }, _)) = planned else { panic!("{profile}: {planned:?}"); }; @@ -1500,7 +1500,7 @@ fn an_a8_texture_buffer_without_a8_unorm_views_its_bytes_in_red() { // A read that does not apply the swizzle. let plain = shape(TextureSwizzleChannels::DEFAULT); let mut planner = make(&p, &plain, &slots, &[]); - let planned = planner.plain_texture(0, 0, uniform_ty, uniform, false); + let planned = planner.plain_texture(0, 0, uniform_ty, uniform); match held { true => assert_eq!( planned.map(|(w, _)| w), diff --git a/crates/metal2vulkan/src/bind/plan/slots.rs b/crates/metal2vulkan/src/bind/plan/slots.rs index faf9710d2..5d644ef42 100644 --- a/crates/metal2vulkan/src/bind/plan/slots.rs +++ b/crates/metal2vulkan/src/bind/plan/slots.rs @@ -291,14 +291,15 @@ fn offset_base_axes(shape: &BindShape, slot: SlotRef) -> u64 { bound_texture(shape, slot).map_or(0, TextureShape::offset_base_axes) } -/// The texture slots whose function decodes an 8-bit sRGB texel from its raw code -/// (`RuntimeFact::SrgbTexture`) at which `shape` binds a texture of such a format whose codes -/// `profile`'s device holds (`metal::texel_format::srgb_raw_on`: not an ASTC sRGB format it -/// decodes itself): the plan's `VariantKey::srgb_textures`. So is each slot of `cross` that the -/// variant reads in the float class (an integer slot), whose accesses there take `float` results, -/// which the raw code serves as a float slot's: the variant's compile states `SrgbTexture` there. -/// The variant's compile states the same facts, so its plan for the same shape states the same -/// key. +/// The texture slots whose function decodes an 8-bit sRGB texel (`RuntimeFact::SrgbTexture`) at +/// which `shape` binds a texture of such a format that `profile`'s device holds as its UNORM twin +/// (`metal::texel_format::srgb_twin_on`: a format it cannot sample), whose views read the codes: +/// the plan's `VariantKey::srgb_textures`. So is each slot of `cross` that the variant reads in +/// the float class (an integer slot), whose accesses there take `float` results, which the codes +/// serve as a float slot's: the variant's compile states `SrgbTexture` there. A slot bound in an +/// sRGB format the device samples reads the device's decode and joins nothing. Derived from the +/// device's format features alone, as the runtime's image plan holds the twin; the variant's +/// compile states the same facts, so its plan for the same shape states the same key. pub(crate) fn srgb_variant( profile: &DeviceProfile, dependencies: &[RuntimeDependency], @@ -318,51 +319,23 @@ pub(crate) fn srgb_variant( .chain(read_float) .filter(|slot| { matches!(bound_texture(shape, *slot), Some(TextureShape::Texture { pixel_format, .. }) - if metal::texel_format::srgb_raw_on(*pixel_format, profile)) + if metal::texel_format::srgb_twin_on(*pixel_format, profile)) }) .collect() } -/// The slots of `srgb` (`VariantKey::srgb_textures`) at which `shape` binds a texture whose 8-bit -/// sRGB format `profile`'s device cannot sample, which the runtime holds as the format's UNORM twin -/// (`metal::format::srgb_raw_twin`), a format it can: the plan's `VariantKey::srgb_twins`. Its -/// views read the codes, so the function decodes what the device samples there. Derived from the -/// device's format features alone, as the runtime's image plan holds the twin. -pub(crate) fn srgb_twin_variant( - profile: &DeviceProfile, - srgb: &std::collections::BTreeSet, - shape: &BindShape, -) -> std::collections::BTreeSet { - use crate::device::requirements::FormatUsage; - let samples = |pf: metal::PixelFormat| { - metal::format::vk_format(pf, &[FormatUsage::SampledImage].into(), profile).is_ok() - }; - srgb.iter() - .filter(|slot| { - matches!(bound_texture(shape, **slot), Some(TextureShape::Texture { pixel_format, .. }) - if !samples(*pixel_format) - && metal::format::srgb_raw_twin(*pixel_format).is_some_and(samples)) - }) - .copied() - .collect() -} - /// The form each of the snapshot slots `slots` keeps its texels in (`VariantKey::snapshot_textures`, -/// `SnapshotForm::of`): by the view the snapshot's copy fetches through, the bound texture's -/// sampled view or, at a slot whose raw codes the variant reads (`srgb`, `slots::srgb_variant`), -/// its raw view (`metal::texel_format::srgb_raw_view`), and the slot's declared sampled type. -/// [`SnapshotForm::Bits`] at a slot the variant reads in another class (`cross`), or one whose -/// sampled view the device has no format for. The variant's compile reads the same +/// `SnapshotForm::of`): by the bound texture's sampled view, which the snapshot's copy fetches +/// through, and the slot's declared sampled type. [`SnapshotForm::Bits`] at a slot the variant +/// reads in another class (`cross`), or one whose sampled view the device has no format for (an +/// 8-bit sRGB format held as its UNORM twin among them). The variant's compile reads the same /// key, so its plan for the same shape states the same forms. pub(crate) fn snapshot_forms( profile: &DeviceProfile, slots: &std::collections::BTreeSet, interface: &BTreeMap, shape: &BindShape, - (srgb, cross): ( - &std::collections::BTreeSet, - &BTreeMap, - ), + cross: &BTreeMap, ) -> BTreeMap { let form = |slot: SlotRef| { let Some(SlotInterface::Texture(t)) = interface.get(&slot) else { @@ -379,11 +352,7 @@ pub(crate) fn snapshot_forms( let Ok(m) = metal::format::vk_format(*pixel_format, &usages, profile) else { return SnapshotForm::Bits; }; - let view = match srgb.contains(&slot) { - true => metal::texel_format::srgb_raw_view(m.format).unwrap_or(m.format), - false => m.format, - }; - SnapshotForm::of(view, t.sampled_type) + SnapshotForm::of(m.format, t.sampled_type) }; slots.iter().map(|&slot| (slot, form(slot))).collect() } diff --git a/crates/metal2vulkan/src/bind/pvrtc_decode.rs b/crates/metal2vulkan/src/bind/pvrtc_decode.rs index 0b38b78fe..59271dc0e 100644 --- a/crates/metal2vulkan/src/bind/pvrtc_decode.rs +++ b/crates/metal2vulkan/src/bind/pvrtc_decode.rs @@ -29,10 +29,10 @@ //! table (`k / 4095` for `lower::arith::srgb`'s step `k`). //! //! **The twin's texels** are the codes, in `R8G8B8A8_UNORM` ([`PvrtcDecode::texel_format`]), -//! exact: a linear format's read is the code's `c / 255`, and an sRGB format's slot reads them raw -//! through that view and decodes its color through Metal's table -//! (`metal::texel_format::srgb_raw`), as for `RGBA8Unorm_sRGB`. A format's linear and sRGB forms -//! decode to the same codes, so one twin serves the views of both. +//! exact: a linear format's read is the code's `c / 255`, and an sRGB format's slot reads them +//! through the twin's `R8G8B8A8_SRGB` view, the device's decode (`PrecisionNote::SrgbTexelDecode`), +//! as for `RGBA8Unorm_sRGB`. A format's linear and sRGB forms decode to the same codes, so one twin +//! serves the views of both. //! //! **The module** ([`pvrtc_decode_module`], one per device and block shape: 2 or 4 bits a pixel, //! RGB or RGBA). `BlockDecodeModule`'s entry point, local size and bindings: the shape diff --git a/crates/metal2vulkan/src/cache/codec.rs b/crates/metal2vulkan/src/cache/codec.rs index a01d967c7..7f682e1f8 100644 --- a/crates/metal2vulkan/src/cache/codec.rs +++ b/crates/metal2vulkan/src/cache/codec.rs @@ -811,7 +811,7 @@ codec_struct! { codec_struct! { SlotRef { stage, class, index } ImageHandleClass { dim, arrayed, multisampled, sampled_type, depth_compare, access, format } - CombinedSampler { sampler, compare, integer, cube_gradient, raw } + CombinedSampler { sampler, compare, integer, cube_gradient } ResourceSlot { stage, kind, index } } @@ -847,7 +847,6 @@ codec_enum! { Buffer, Texture, Sampler, Heap(f0), Synthetic(f0), InputAttachment(f0), CombinedTextureSampler(f0), HeapSampler(f0), AccelerationStructure(f0), TileAttachment(f0), TileMap, SeparateTexture(f0), SeparateSampler(f0), - RawTexture, ExtendedShadow(f0), SnapshotTexels(f0), } @@ -1129,7 +1128,7 @@ codec_struct! { inputs, outputs, builtins, pulled, stage_in, multisampled, varyings_at_pixel, position_depth, coverage_loop, color_writes, rounded_colors, primitive_inputs, early_fragment_tests, extended_range_colors, unattached_colors, sample_mask, - rotated_colors, rotated_factors, rotated_blends, srgb_fetches, half_output_lanes, + rotated_colors, rotated_factors, rotated_blends, decoded_fetches, half_output_lanes, texture_write_rounding, uniform_outputs, uniform_inputs, instanced_attributes, half_blend_colors, half_fast_colors, float_blend_colors, zero_indices, color_group, word_colors, alpha_in_red_colors, alpha_test, depth_compares, @@ -1239,7 +1238,6 @@ codec_enum! { FoldedGroups, ReplayBindings, AbsentArgumentRead { stage }, - SrgbDeviceDecode { slot }, ZeroedColor { color, format }, DroppedColor { color }, DepthClampRange, @@ -1455,7 +1453,6 @@ codec_enum! { Synthetic { stage, binding }, Heap(f0), InputAttachment(f0), HeapSampler { stage, sampler }, AccelerationStructure { slot, level }, TileAttachment(f0), TileMap(f0), SeparateTexture { texture, sampler }, SeparateSampler { stage, sampler }, - RawTexture(f0), ExtendedShadow(f0), SnapshotTexels(f0), } diff --git a/crates/metal2vulkan/src/cache/mod.rs b/crates/metal2vulkan/src/cache/mod.rs index 64696a049..eedadefeb 100644 --- a/crates/metal2vulkan/src/cache/mod.rs +++ b/crates/metal2vulkan/src/cache/mod.rs @@ -60,7 +60,7 @@ mod tests; /// unchanged version, and its bless records the version. Independent of the crate's version and of /// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no /// history. -pub const SEMANTICS_VERSION: u32 = 1890; +pub const SEMANTICS_VERSION: u32 = 1891; /// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the /// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another @@ -70,7 +70,7 @@ pub const SEMANTICS_VERSION: u32 = 1890; /// re-typed in an encoded type, its `codec` body or its `envelope`. A variant removed while its tag /// stays unused needs no bump: an entry holding it fails to decode, which is a miss. The commit that /// bumps it says what changed; this comment keeps no history. -pub const ARTIFACT_FORMAT_VERSION: u32 = 468; +pub const ARTIFACT_FORMAT_VERSION: u32 = 469; /// The version of what this crate's runtime does with a compiled pipeline: instantiating a binding /// plan (`BindingPlan::instantiate_*`: descriptor ranges, push bytes, root, argument, and handle @@ -93,7 +93,7 @@ pub const ARTIFACT_FORMAT_VERSION: u32 = 468; /// changes no behaviour, and then updates that hash alone with the commit saying why, or changes /// behaviour and also bumps this version. The commit that bumps it says what changed; this comment /// keeps no history. -pub const RUNTIME_VERSION: u32 = 1671; +pub const RUNTIME_VERSION: u32 = 1672; /// The digest of the sources this build of the crate was compiled from: SHA-256, as lowercase hex, /// of the manifest, the build script, and exactly the files the crate roots' module tree compiles @@ -181,21 +181,16 @@ pub struct VariantKey { /// per-stage limit). The plan of a pipeline compiled under it states it. #[cfg_attr(feature = "serde", serde(default))] pub storage_view_slots: BTreeSet, - /// Texture slots bound in an 8-bit sRGB format whose raw codes the function reads: every slot - /// of a `RuntimeFact::SrgbTexture` the shape binds in a `metal::texel_format::srgb_raw` format. - /// The function's reads, nearest samples, and gathers there read the slot's raw view - /// (`ResourceKind::RawTexture`, `CombinedSampler::raw`) and decode Metal's twelve-bit table; - /// the plan of a pipeline compiled under it states it. + /// Texture slots bound to an 8-bit sRGB texture the device cannot sample, which the runtime + /// holds as the format's UNORM twin (`metal::format::srgb_raw_twin`), whose views read the + /// codes (`c / 255`): every slot of a `RuntimeFact::SrgbTexture` the shape binds in such a + /// format (`metal::texel_format::srgb_twin_on`). The function decodes what it reads there + /// through Metal's twelve-bit table, as the device would through an sRGB view it lacks + /// (`LoweringInputs::srgb_textures`); a slot bound in an sRGB format the device samples reads + /// the device's decode and is no slot of this. The plan of a pipeline compiled under it + /// states it. #[cfg_attr(feature = "serde", serde(default))] pub srgb_textures: BTreeSet, - /// Slots of [`srgb_textures`](Self::srgb_textures) bound to a texture whose 8-bit sRGB format - /// the device cannot sample, which it holds as the format's UNORM twin - /// (`metal::format::srgb_raw_twin`), whose views read the codes (`c / 255`): the accesses the - /// raw codes do not serve exactly (a runtime sampler's sample, a filter the emulation does not - /// reach) sample the twin and decode the device's filtered codes - /// (`LoweringInputs::srgb_twins`). The plan of a pipeline compiled under it states it. - #[cfg_attr(feature = "serde", serde(default))] - pub srgb_twins: BTreeSet, /// Fragment texture slots the draw reads through a snapshot an earlier draw of the same /// primitives took (`LoweringInputs::snapshot_textures`), each with the form the snapshot /// keeps its texels in (`SnapshotForm::of` the slot's bound view): the slots @@ -528,7 +523,6 @@ impl VariantKey { && !self.dropped_vertex_layer && self.storage_view_slots.is_empty() && self.srgb_textures.is_empty() - && self.srgb_twins.is_empty() && self.snapshot_textures.is_empty() && self.ycbcr_in_place.is_empty() && self.address_maps.is_empty() @@ -631,12 +625,6 @@ impl VariantKey { .filter(|s| s.stage == stage) .copied() .collect(); - out.srgb_twins = self - .srgb_twins - .iter() - .filter(|s| s.stage == stage) - .copied() - .collect(); out.snapshot_textures = self .snapshot_textures .iter() diff --git a/crates/metal2vulkan/src/cache/tests.rs b/crates/metal2vulkan/src/cache/tests.rs index 500814cb3..9740252a6 100644 --- a/crates/metal2vulkan/src/cache/tests.rs +++ b/crates/metal2vulkan/src/cache/tests.rs @@ -811,13 +811,11 @@ fn the_version_377_member_round_trips() { /// decode together in one render pipeline: `PrecisionNote::CubeGradientFootprint` and /// `CombinedSampler::cube_gradient`, `RuntimeFact::InterlockedFramebufferFetch` and /// `GraphicsState::storage_attachments`, `SpecKey::TexelFormat`, `RuntimeFact::TexelFormat` and -/// `SrgbTexture`, `VkProperty::MetalSampler`, `ResourceKind::RawTexture`, -/// `BindingSource::RawTexture`, `CombinedSampler::raw` (on the same sampler as `cube_gradient`), -/// and `PrecisionNote::HalfTexelConversion`, `HalfSampleFilter`, `SrgbTexelDecode`, and -/// `FloatSampleFilter`, `HandleClass::Sampler { compare, integer, cube_gradient }` and -/// `SyntheticBinding::SamplerTable`, `RuntimeFact::UlongAtomicView`, and -/// `RuntimeFact::SrgbDeviceDecode`, each beside the others rather than only on its own side's -/// fixtures. +/// `SrgbTexture`, `VkProperty::MetalSampler`, and `PrecisionNote::HalfTexelConversion`, +/// `HalfSampleFilter`, `SrgbTexelDecode`, and `FloatSampleFilter`, +/// `HandleClass::Sampler { compare, integer, cube_gradient }` and +/// `SyntheticBinding::SamplerTable`, and `RuntimeFact::UlongAtomicView`, each beside the others +/// rather than only on its own side's fixtures. #[test] fn the_merged_members_round_trip_in_one_render_pipeline() { use crate::device::requirements::VkProperty; @@ -834,15 +832,9 @@ fn the_merged_members_round_trip_in_one_render_pipeline() { class: SlotClass::Texture, index: 3, }; - let sampler = CombinedSampler::new(SamplerRef::Slot(1), false, false) - .with_cube_gradient(true) - .with_raw(true); - for kind in [ - ResourceKind::RawTexture, - ResourceKind::CombinedTextureSampler(sampler), - ] { - assert_eq!(decode::(&encode(&kind)), Ok(kind)); - } + let sampler = CombinedSampler::new(SamplerRef::Slot(1), false, false).with_cube_gradient(true); + let kind = ResourceKind::CombinedTextureSampler(sampler); + assert_eq!(decode::(&encode(&kind)), Ok(kind)); let notes = [ PrecisionNote::CubeGradientFootprint, PrecisionNote::HalfTexelConversion, @@ -892,7 +884,7 @@ fn the_merged_members_round_trip_in_one_render_pipeline() { ty: vk::DescriptorType::SAMPLED_IMAGE, count: 1, stages: vk::ShaderStageFlags::FRAGMENT, - source: BindingSource::RawTexture(texture), + source: BindingSource::Texture(texture), immutable_sampler: None, flags: vk::DescriptorBindingFlags::empty(), variables: 1, @@ -970,10 +962,6 @@ fn the_merged_members_round_trip_in_one_render_pipeline() { fact: RuntimeFact::SrgbTexture { slot: texture }, mechanism: Mechanism::Variant, }); - p.dependencies.push(RuntimeDependency { - fact: RuntimeFact::SrgbDeviceDecode { slot: texture }, - mechanism: Mechanism::PlanTimeCheck, - }); let ulong_view = RuntimeFact::UlongAtomicView { slot: texture }; p.dependencies.push(RuntimeDependency { fact: ulong_view, @@ -1001,11 +989,11 @@ fn the_merged_members_round_trip_in_one_render_pipeline() { assert!(matches!( bindings.map(|b| &b[0].source), Some(BindingSource::CombinedTextureSampler { sampler, .. }) - if sampler.cube_gradient && sampler.raw + if sampler.cube_gradient )); assert_eq!( bindings.map(|b| &b[1].source), - Some(&BindingSource::RawTexture(texture)) + Some(&BindingSource::Texture(texture)) ); assert!(matches!( bindings.map(|b| &b[2].source), @@ -1025,7 +1013,6 @@ fn the_merged_members_round_trip_in_one_render_pipeline() { for fact in [ RuntimeFact::TexelFormat { slot: texture }, RuntimeFact::SrgbTexture { slot: texture }, - RuntimeFact::SrgbDeviceDecode { slot: texture }, ] { assert!( sealed.dependencies.iter().any(|d| d.fact == fact), @@ -1087,35 +1074,22 @@ fn the_emulated_simdgroups_variant_round_trips() { assert_eq!(plan.variant, key); } -/// The raw sRGB view's encodings round trip (a combined binding's `raw`, the `RawTexture` binding -/// and resource, the `SrgbTexture` fact, and the `SrgbTexelDecode` note), and a kernel compiled -/// under the `SrgbTexture` variant round trips as a function and as a pipeline, whose decoded plan -/// for a shape binding an 8-bit sRGB texture at the slot states the variant, so a cached variant -/// settles as the compiled one does. +/// The `SrgbTexture` fact round trips, and a kernel compiled under the `SrgbTexture` variant (a +/// slot bound to an 8-bit sRGB format the device holds as its UNORM twin) round trips as a +/// function and as a pipeline, whose decoded plan for a shape binding such a texture at the slot +/// states the variant, so a cached variant settles as the compiled one does; a shape binding an +/// sRGB format the device samples states none. #[test] fn the_srgb_texture_variant_round_trips() { use crate::bind::{BindState, BoundTexture, StageTable, TextureFacts}; use crate::cache::VariantKey; use crate::pipeline::artifact::PrecisionNote; use crate::pipeline::facts::RuntimeFact; - use crate::pipeline::layout::BindingSource; - use crate::pipeline::sym::{CombinedSampler, ResourceKind, SamplerRef}; let slot = SlotRef { stage: Stage::Kernel, class: SlotClass::Texture, index: 2, }; - let raw = - CombinedSampler::new(SamplerRef::Constexpr([0x0008_0000, 0]), false, false).with_raw(true); - assert_eq!(decode::(&encode(&raw)), Ok(raw)); - for kind in [ - ResourceKind::RawTexture, - ResourceKind::CombinedTextureSampler(raw), - ] { - assert_eq!(decode::(&encode(&kind)), Ok(kind)); - } - let source = BindingSource::RawTexture(slot); - assert_eq!(decode::(&encode(&source)), Ok(source)); let fact = RuntimeFact::SrgbTexture { slot }; assert_eq!(decode::(&encode(&fact)), Ok(fact)); let note = PrecisionNote::SrgbTexelDecode; @@ -1151,31 +1125,32 @@ fn the_srgb_texture_variant_round_trips() { &Budget::standard(), ) .expect("pipeline"); - assert!(pipeline - .layout - .sets - .iter() - .flat_map(|s| &s.bindings) - .any(|b| b.source == source)); let decoded = ComputePipeline::from_bytes(&pipeline.to_bytes(), &dev).expect("decoded"); assert_eq!(decoded, pipeline); let mut table = StageTable::default(); - let mut facts = TextureFacts::new( - metal::TextureType::Type3D, - metal::PixelFormat::RGBA8UnormSRGB, - ); - facts.usage = metal::TextureUsage::SHADER_READ; - table.textures.insert( - 2, - BoundTexture::Texture { - facts, - resource_id: None, - }, - ); - let mut state = BindState::default(); - state.stages.insert(Stage::Kernel, table); - let plan = decoded.plan(&dev, &state.shape()).expect("plan"); - assert_eq!(plan.variant.srgb_textures, key.srgb_textures); + // lavapipe samples no `RG8Unorm_sRGB`, which the runtime holds as `RG8Unorm`, and samples + // `RGBA8Unorm_sRGB` itself. + for (pf, twin) in [ + (metal::PixelFormat::RG8UnormSRGB, true), + (metal::PixelFormat::RGBA8UnormSRGB, false), + ] { + let mut facts = TextureFacts::new(metal::TextureType::Type3D, pf); + facts.usage = metal::TextureUsage::SHADER_READ; + table.textures.insert( + 2, + BoundTexture::Texture { + facts, + resource_id: None, + }, + ); + let mut state = BindState::default(); + state.stages.insert(Stage::Kernel, table.clone()); + let plan = decoded.plan(&dev, &state.shape()).expect("plan"); + match twin { + true => assert_eq!(plan.variant.srgb_textures, key.srgb_textures, "{pf:?}"), + false => assert!(plan.variant.srgb_textures.is_empty(), "{pf:?}"), + } + } } /// The `CubicSampler` fact round trips, and a kernel compiled under the cubic-sampler variant round @@ -1513,8 +1488,7 @@ fn the_separate_bindings_round_trip() { } /// A combined binding's symbol and a separate texture's, whose index packs its use above its -/// texture slot, round-trip through the codec for every use, a raw view's included, at the slots' -/// bounds. +/// texture slot, round-trip through the codec for every use, at the slots' bounds. #[test] fn combined_and_separate_texture_symbols_round_trip() { use crate::pipeline::sym::{CombinedSampler, ResourceKind, ResourceSlot, SamplerRef}; @@ -1522,10 +1496,9 @@ fn combined_and_separate_texture_symbols_round_trip() { SamplerRef::Slot(3), SamplerRef::Constexpr([u64::MAX >> 1, 7]), ] { - for rank in 0..16u32 { - let c = CombinedSampler::new(sampler, rank & 8 != 0, rank & 4 != 0) - .with_cube_gradient(rank & 2 != 0) - .with_raw(rank & 1 != 0); + for rank in 0..8u32 { + let c = CombinedSampler::new(sampler, rank & 4 != 0, rank & 2 != 0) + .with_cube_gradient(rank & 1 != 0); for texture in [0, 127, (1 << 28) - 1] { let combined = ResourceSlot { stage: Stage::Fragment, diff --git a/crates/metal2vulkan/src/device/driver_facts.rs b/crates/metal2vulkan/src/device/driver_facts.rs index 50e9e7629..fa4a946b6 100644 --- a/crates/metal2vulkan/src/device/driver_facts.rs +++ b/crates/metal2vulkan/src/device/driver_facts.rs @@ -1008,8 +1008,8 @@ pub enum DriverFact { TimestampsWaitForEveryQueue, /// The driver decodes each texel of a BC1 to BC3 texture (`BC1_RGBA`, `BC2_RGBA`, /// `BC3_RGBA`) to Metal's value, and each texel of their sRGB forms to Metal's code before - /// its sRGB step (which the translation takes through Metal's table, - /// `metal::texel_format::srgb_raw`): Vulkan leaves the decode's arithmetic to the + /// its sRGB step (which the device's sRGB view then decodes, `PrecisionNote::SrgbTexelDecode`): + /// Vulkan leaves the decode's arithmetic to the /// implementation. Metal's (an Apple M4, every texel of random blocks of the fourteen BC /// formats read): each endpoint widened by replicating its bits, the index's /// weight of 64 (BC7's: 21 and 43 for the thirds, 9 to 55 for BC3's alpha's sevenths, 13 to @@ -1086,7 +1086,7 @@ pub enum DriverFact { /// the runtime makes it: the runtime has no decoded twin of BC6H. Bc6hBlockDecodeIsMetals, /// The driver decodes each texel of a BC7 texture (`BC7_RGBAUnorm`, and `BC7_RGBAUnorm_sRGB` - /// through its unorm view and Metal's table, `metal::texel_format::srgb_raw`) to Metal's + /// to Metal's code before its sRGB step, which the device's sRGB view then decodes) to Metal's /// value. lavapipe (Mesa 26.0.8) answers some a `float` ulp off. On a driver without it a /// texture of such a format announces `compressed-texel-decode` where the runtime makes it: /// the runtime has no decoded twin of BC7. diff --git a/crates/metal2vulkan/src/device/mechanism.rs b/crates/metal2vulkan/src/device/mechanism.rs index 06a3abaa1..8a4cf9461 100644 --- a/crates/metal2vulkan/src/device/mechanism.rs +++ b/crates/metal2vulkan/src/device/mechanism.rs @@ -35,7 +35,7 @@ pub fn mechanism(fact: &RuntimeFact, profile: &DeviceProfile) -> Mechanism { // Keyed by a per-slot StorageImageChoice, a separate per-function compile. RuntimeFact::StorageTextureFormat { .. } | RuntimeFact::StorageTextureNumericType { .. } => Mechanism::Variant, - // Keyed by the slots bound in an sRGB format whose raw code the function reads. + // Keyed by the slots bound to an sRGB format's UNORM twin, whose codes the function decodes. RuntimeFact::SrgbTexture { .. } => Mechanism::Variant, RuntimeFact::SamplerCoordinates { .. } => Mechanism::Specialization, RuntimeFact::SamplerReduction { .. } => Mechanism::PlanTimeCheck, @@ -186,9 +186,6 @@ pub fn mechanism(fact: &RuntimeFact, profile: &DeviceProfile) -> Mechanism { // The function marks the `ExecutionStatus` buffer its `ExecutionStatus` fact binds; the // consumer reads the bit after the command buffer. RuntimeFact::AbsentArgumentRead { .. } => Mechanism::None, - // The planner refuses an sRGB texture the device cannot sample at a slot the function - // decodes through the device. - RuntimeFact::SrgbDeviceDecode { .. } => Mechanism::PlanTimeCheck, // A separate compile of the pipeline, which a pass with colors the pipeline lacks asks // for. RuntimeFact::ZeroedColor { .. } | RuntimeFact::DroppedColor { .. } => Mechanism::Variant, diff --git a/crates/metal2vulkan/src/device/tests/mechanism.rs b/crates/metal2vulkan/src/device/tests/mechanism.rs index 52ec478ce..025321b28 100644 --- a/crates/metal2vulkan/src/device/tests/mechanism.rs +++ b/crates/metal2vulkan/src/device/tests/mechanism.rs @@ -161,7 +161,6 @@ fn every_fact() -> Vec { RuntimeFact::AbsentArgumentRead { stage: Stage::Fragment, }, - RuntimeFact::SrgbDeviceDecode { slot }, RuntimeFact::ZeroedColor { color: 1, format: crate::metal::PixelFormat::RGBA8Unorm, @@ -324,7 +323,6 @@ fn variant(f: &RuntimeFact) -> usize { RuntimeFact::ViewportCompensation { .. } => 55, RuntimeFact::FoldedGroups => 56, RuntimeFact::AbsentArgumentRead { .. } => 57, - RuntimeFact::SrgbDeviceDecode { .. } => 58, RuntimeFact::ZeroedColor { .. } => 59, RuntimeFact::DroppedColor { .. } => 60, RuntimeFact::DepthClampRange => 61, @@ -352,7 +350,7 @@ fn variant(f: &RuntimeFact) -> usize { RuntimeFact::WordInputMerge { .. } => 87, RuntimeFact::ReplayBindings => 88, RuntimeFact::MergedDraws => 89, - RuntimeFact::QuadPrimitiveIds => 90, + RuntimeFact::QuadPrimitiveIds => 58, RuntimeFact::RotatedWeights => 82, RuntimeFact::PrivateList => 86, RuntimeFact::MeshLastFirst => 71, @@ -364,7 +362,7 @@ fn variant(f: &RuntimeFact) -> usize { fn mechanism_is_total_over_every_fact_and_profile() { let facts = every_fact(); let covered: std::collections::BTreeSet = facts.iter().map(variant).collect(); - assert_eq!(covered, (0..91).collect(), "every_fact misses a variant"); + assert_eq!(covered, (0..90).collect(), "every_fact misses a variant"); for (stem, _) in super::committed_profiles() { let dev = device(&stem); let p = dev.profile(); @@ -406,7 +404,6 @@ fn mechanism_is_total_over_every_fact_and_profile() { .. } | RuntimeFact::SparseTextureWrites { atomic: true, .. } - | RuntimeFact::SrgbDeviceDecode { .. } | RuntimeFact::CubicArgumentSampler { .. } | RuntimeFact::HeapRawSamples { .. } | RuntimeFact::StorageTextureWriteRounding { .. } diff --git a/crates/metal2vulkan/src/error/mod.rs b/crates/metal2vulkan/src/error/mod.rs index 46bd39fec..71f8554f5 100644 --- a/crates/metal2vulkan/src/error/mod.rs +++ b/crates/metal2vulkan/src/error/mod.rs @@ -567,9 +567,11 @@ pub enum DriverDeviation { /// way; unmeasured, a NaN Metal answers records `PrecisionNote::NativeNanEncoding`. MetalCanonicalNans, /// The device samples, filters and converts texels through Metal's own sampler - /// (`VkProperty::MetalSampler`). Unmeasured, every sample, gather and comparison is the - /// device's own sampler's all the same (`VkProperty::DeviceSampling`), recorded as - /// `PrecisionNote::DeviceSampling`. + /// (`VkProperty::MetalSampler`), an 8-bit sRGB texel's decode included. Unmeasured, every + /// sample, gather and comparison is the device's own sampler's all the same + /// (`VkProperty::DeviceSampling`), recorded as `PrecisionNote::DeviceSampling`, and every + /// read, sample, gather and input-attachment read of an sRGB texel the device's own decode, + /// recorded as `PrecisionNote::SrgbTexelDecode`. MetalSampler, /// How the driver hands a vertex or fragment function's cube sample's explicit gradients to /// the GPU under macOS 27 (the graphics route, `CubeGradientRoute::AppleProjected`): through diff --git a/crates/metal2vulkan/src/lower/fragment/color.rs b/crates/metal2vulkan/src/lower/fragment/color.rs index b04bc8a6c..b9b90657d 100644 --- a/crates/metal2vulkan/src/lower/fragment/color.rs +++ b/crates/metal2vulkan/src/lower/fragment/color.rs @@ -41,16 +41,15 @@ //! function writes, the write blends over the same input attachment (`input_blend`), which a //! `[[color(n)]]` read of the attachment shares ([`input_texel`]). //! -//! **An 8-bit four-channel sRGB attachment** (`RGBA8Unorm_sRGB`, `BGRA8Unorm_sRGB`) reads through -//! its input attachment the device's decode, which is not Metal's: Metal decodes a color byte to -//! its twelve-bit step over 4095, and lavapipe's decode lands elsewhere at many bytes. Where the -//! pipeline names the color (`LoweringInputs::srgb_fetches`), the read snaps the device's value -//! back to its byte by Metal's encode (`math::pack` of `unorm4x8_srgb`), on which every byte's -//! exact decode lands at least 4.9e-5 inside its code's interval, and decodes the byte by Metal's -//! table (`math::unpack`), as the storage form reads its bytes; alpha's byte over 255 comes back as -//! it was. Exact wherever the device's decode lies within that margin of the exact one, which the -//! fetch lane checks on every byte. The interface records the color (`StageIo::srgb_fetches`), -//! which link holds the pipeline's to. +//! **An 8-bit sRGB attachment** (`RGBA8Unorm_sRGB`, `BGRA8Unorm_sRGB` and the rest) reads through +//! its input attachment the device's decode of its bytes, Vulkan's sRGB EOTF within the device's +//! precision, where Metal decodes a color byte to its twelve-bit step over 4095. On a device that +//! decodes through Metal's own texture unit (`VkProperty::MetalSampler`) that is Metal's decode, +//! and the module requires the property; elsewhere the interface records each `float` color it +//! reads so (`StageIo::decoded_fetches`), and a render pipeline whose attachment there has such a +//! format records `PrecisionNote::SrgbTexelDecode` (`color_writes::pipeline_writes`). The +//! interlocked storage form reads the attachment's bytes, no sRGB view of them, and decodes them +//! by Metal's table itself (`fetch`). //! //! **An `A8Unorm` attachment whose image holds Metal's alpha in red** (`R8_UNORM` on a device //! without `A8_UNORM`, `LoweringInputs::alpha_in_red_colors`) reads `(r, 0, 0, 1)` through its @@ -68,12 +67,12 @@ use std::collections::BTreeMap; use crate::air::abi::{AbiInt, OutputRole, ParamBinding, ParamRole}; -use crate::air::intrinsics::{PackDir, PackFormat}; + use crate::air::ir::{ArgIdx, TypeId as AirTypeId, Value}; use crate::device::requirements::VkFeature; use crate::error::{Attachment, Capability, DescriptorError, Error, Feature, Unsupported}; use crate::lower::arith::legal::{form_on, refuse_int64_interface}; -use crate::lower::arith::{extended_range, math, narrow, ops, srgb, Form, Held}; +use crate::lower::arith::{extended_range, narrow, ops, Form, Held}; use crate::lower::emit::EmitCx; use crate::lower::select::SelectCx; use crate::metal::format::ExtendedRange; @@ -101,10 +100,6 @@ pub struct ColorInput { /// image holds Metal's raw texels: an input attachment of the raw format's `uint`s, which /// the read decodes to Metal's tile value. `None` for a format held directly. pub extended: Option, - /// The attachment is `RGBA8Unorm_sRGB` or `BGRA8Unorm_sRGB` (`LoweringInputs::srgb_fetches`): - /// an input attachment's read snaps the device's decode back to its byte and decodes that by - /// Metal's table. - pub srgb: bool, /// The attachment's image holds Metal's alpha in red (`LoweringInputs::alpha_in_red_colors`, /// `A8Unorm` in `R8_UNORM`): a read, `(r, 0, 0, 1)` from the image, is Metal's `(0, 0, 0, r)`. pub alpha_red: bool, @@ -173,7 +168,6 @@ pub(super) fn select_param(cx: &mut SelectCx<'_>, b: &ParamBinding) -> Result, b: &ParamBinding) -> Result cx.families.sampler.metal_sampler = true, + false => { + cx.families.stage_io.interface.decoded_fetches.insert(color); + } } - cx.families.arith.srgb.get_or_insert(PackDir::Unpack); - cx.families.stage_io.interface.srgb_fetches.insert(color); } // An attachment whose image holds Metal's alpha in red reads the red as Metal's alpha: a float // (an integer read is Metal's pipeline error). The interface records the attachment, which @@ -317,10 +316,6 @@ pub(super) fn words(cx: &SelectCx<'_>, colors: &[ColorInput]) -> u64 { .copied() .collect(); let decodes = self::uses(cx, &extended); - // An sRGB attachment's read encodes the device's value and decodes the byte. - let srgb: Vec = colors.iter().filter(|c| c.srgb).copied().collect(); - let snaps = self::uses(cx, &srgb); - let snap = u64::from(3 * srgb::SEARCH_WORDS + 3 * srgb::STEP_WORDS) + 400; // An alpha-in-red attachment's read moves its red to alpha: a shuffle and its zero. let red: Vec = colors.iter().filter(|c| c.alpha_red).copied().collect(); let moves = self::uses(cx, &red); @@ -331,7 +326,6 @@ pub(super) fn words(cx: &SelectCx<'_>, colors: &[ColorInput]) -> u64 { .saturating_mul(attachments.len() as u64) .saturating_add(READ_WORDS.saturating_mul(uses)) .saturating_add(u64::from(extended_range::DECODE_WORDS + 120).saturating_mul(decodes)) - .saturating_add(snap.saturating_mul(snaps)) .saturating_add(ALPHA_IN_RED_WORDS.saturating_mul(moves)) } @@ -436,20 +430,6 @@ pub(super) fn value( let table = crate::lower::texture::extended_table(cx, form)?; extended_range::tile_value(fb, form, texel, table)? } - // The device's decode, snapped back to its byte by Metal's encode (every byte's exact - // decode lies at least 4.9e-5 inside its code's encode interval), then Metal's decode. - None if c.srgb => { - let Some(table) = cx.decl.families.arith.srgb else { - return Err(cx.fail("an sRGB input attachment read without Metal's table")); - }; - let f4 = Form { - held: Held::Float(crate::lower::arith::FloatFmt::F32), - lanes: 4, - }; - let test = crate::lower::arith::nan::NanTest::for_modes(&cx.plan.families.arith.modes); - let byte = math::pack(fb, PackFormat::Unorm4x8Srgb, f4, texel, Some(table), test)?; - math::unpack(fb, PackFormat::Unorm4x8Srgb, f4, byte, Some(table))? - } // The image's red, Metal's alpha: `(0, 0, 0, r)`. None if c.alpha_red => alpha_in_red(fb, texel)?, None => texel, diff --git a/crates/metal2vulkan/src/lower/fragment/mod.rs b/crates/metal2vulkan/src/lower/fragment/mod.rs index 3d94d12e5..f9a7edbb7 100644 --- a/crates/metal2vulkan/src/lower/fragment/mod.rs +++ b/crates/metal2vulkan/src/lower/fragment/mod.rs @@ -113,9 +113,7 @@ pub(crate) use input_blend::texel as input_blend_texel; pub use input_blend::{select_second_output as select_input_second_output, InputBlend}; #[cfg(test)] pub(crate) use snapshot::{decode as snapshot_decode, encode as snapshot_encode}; -pub(crate) use snapshot::{ - fetches_raw as snapshot_fetches_raw, prepare as snapshot_prepare, read as snapshot_read, -}; +pub(crate) use snapshot::{prepare as snapshot_prepare, read as snapshot_read}; pub(crate) use stencil::{face_word, SHADOW_FORMAT}; pub use stencil::{select_output as select_stencil_output, ShadowStencil}; pub(crate) use word_input::merge as word_input_merge; diff --git a/crates/metal2vulkan/src/lower/fragment/snapshot.rs b/crates/metal2vulkan/src/lower/fragment/snapshot.rs index 23ac65ba8..88ffb744b 100644 --- a/crates/metal2vulkan/src/lower/fragment/snapshot.rs +++ b/crates/metal2vulkan/src/lower/fragment/snapshot.rs @@ -102,9 +102,7 @@ //! whose codes the form holds too, and a swizzled view's lanes are channels or those constants. //! //! **The view the copy fetches through** is the one the read it stands for would have fetched, and -//! the one the binder names the form by: the slot's raw view where the slot's reads take the raw -//! codes (an 8-bit sRGB texel's, `metal::texel_format::srgb_raw_view`), else the slot's own image -//! ([`fetches_raw`]). +//! the one the binder names the form by: the slot's own image. use std::collections::BTreeMap; @@ -243,24 +241,10 @@ pub(super) fn declare( Ok(d) } -/// Whether the copy of slot `index`, and so each read of it the snapshot stands for, fetches -/// through the slot's raw view rather than through its image: where the slot's reads take the raw -/// codes (an 8-bit sRGB texel's, `SlotPlan::raw`), the view the binder names the snapshot's form -/// by (`bind::plan::slots`'s `snapshot_forms`, `metal::texel_format::srgb_raw_view`). -pub(crate) fn fetches_raw(cx: &EmitCx<'_>, index: u32) -> bool { - cx.decl.families.texture.raw.contains_key(&index) -} - -/// The image variable the copy of slot `index` fetches from, with its image type: the slot's raw -/// view where its reads take one ([`fetches_raw`]), else its image. +/// The image variable the copy of slot `index` fetches from, with its image type: the slot's +/// image. fn source(cx: &EmitCx<'_>, index: u32) -> Option<(GlobalId, TypeId)> { - let texture = &cx.decl.families.texture; - let &(img, ty) = texture.images.get(&index)?; - match fetches_raw(cx, index) { - // An 8-bit sRGB slot's raw view is a second binding of the slot's own image type. - true => texture.raw.get(&index).map(|&g| (g, ty)), - false => Some((img, ty)), - } + cx.decl.families.texture.images.get(&index).copied() } /// Whether `form`'s codes hold every lane an image of sampled type `sampled` returns: a float @@ -599,7 +583,7 @@ pub(crate) struct SnapshotRead { } /// The snapshot read standing for a fetch of texture slot `index` from image `img` (loaded from -/// the image or raw view the copy fetches from), or `None` where the function reads the slot +/// the image the copy fetches from), or `None` where the function reads the slot /// directly. The read must be the fetch of a single-sampled 2D level the copy makes: anything /// else is an invariant failure, since the slot's interface fact admits no other. pub(crate) fn prepare( diff --git a/crates/metal2vulkan/src/lower/sampler/bicubic.rs b/crates/metal2vulkan/src/lower/sampler/bicubic.rs index b2a4db75f..0a127701f 100644 --- a/crates/metal2vulkan/src/lower/sampler/bicubic.rs +++ b/crates/metal2vulkan/src/lower/sampler/bicubic.rs @@ -169,7 +169,7 @@ impl Bicubic { /// ([`PINNED_WORDS`]), and Metal's offset rule on each axis a constant offset moves /// (`position::OFFSET_RULE_WORDS`). The estimate bounds every public bicubic fixture /// (`the_estimate_bounds_the_bicubic_fixtures`), every raw form - /// (`the_raw_estimate_bounds_its_emission`), and the mirrored forms (`mirrored_axes`). + /// (`the_srgb_estimate_bounds_its_emission`), and the mirrored forms (`mirrored_axes`). pub(super) fn words(&self) -> u32 { let (base, taps) = if self.linear_only() { (448, 2) diff --git a/crates/metal2vulkan/src/lower/sampler/emit.rs b/crates/metal2vulkan/src/lower/sampler/emit.rs index bd2b49d6e..674af5a93 100644 --- a/crates/metal2vulkan/src/lower/sampler/emit.rs +++ b/crates/metal2vulkan/src/lower/sampler/emit.rs @@ -2158,14 +2158,14 @@ pub(super) fn held_value( }; // An 8-bit sRGB texel's raw code, decoded as Metal decodes it: a gather's lanes are one // channel's, all alpha or all color. - if s.raw() || s.srgb_codes { + if s.raw || s.srgb_codes { let color = match s.op { SampleOp::Gather { component, .. } => [component != 3; 4], _ => crate::lower::texture::SRGB_TEXEL, }; // The device's sample of a twin's codes, filtered: decoded through the table, exactly // where it read one texel. - if !s.raw() { + if !s.raw { return crate::lower::texture::srgb_filtered_texel(cx, fb, form, texel, color); } return crate::lower::texture::srgb_raw_texel(cx, fb, form, texel, color); diff --git a/crates/metal2vulkan/src/lower/sampler/mod.rs b/crates/metal2vulkan/src/lower/sampler/mod.rs index 925fb5f13..a817c09da 100644 --- a/crates/metal2vulkan/src/lower/sampler/mod.rs +++ b/crates/metal2vulkan/src/lower/sampler/mod.rs @@ -229,18 +229,13 @@ impl FamilyStrategy for SamplerStrategy { /// final: the texture slot index, the sampler, whether it samples with comparison, and whether it /// samples a cube with explicit gradients in the `Length` form through a sampler that may be /// anisotropic, on a device whose cube-gradient route is not measured ([`Lod::CubeGrad`], whose -/// sampler is made isotropic for it: `metal::sampler::SamplerUse::cube_gradient`), and whether it -/// samples the slot's raw view. +/// sampler is made isotropic for it: `metal::sampler::SamplerUse::cube_gradient`). #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct BindingKey { pub texture: u32, pub sampler: SamplerRef, pub compare: bool, pub cube_gradient: bool, - /// The binding pairs the sampler with a UNORM view of the slot's 8-bit sRGB image, whose - /// texels' raw codes the sample decodes as Metal does (`CombinedSampler::raw`, - /// `RuntimeFact::SrgbTexture`). - pub raw: bool, } /// One separate heap sampler use: heap group `group` sampled through `sampler`, with comparison or @@ -642,10 +637,15 @@ pub struct Sampling { /// device's samples at explicit levels, answers ([`anisotropic`]): through a constexpr /// sampler always, through a runtime sampler slot where its word states anisotropy. pub anisotropic: Option, - /// The slot's own binding views the codes of an 8-bit sRGB texture held as its UNORM twin - /// (`LoweringInputs::srgb_twins`), where the access would keep the device's decode: the - /// device's sample there, filtered codes, decodes through Metal's table - /// (`texture::srgb_filtered_texel`), exactly where it read one texel. + /// The slot's binding views the codes of an 8-bit sRGB texture held as its UNORM twin + /// (`LoweringInputs::srgb_textures`), and the sample reads one texel's: its codes decode + /// exactly through Metal's table (`texture::srgb_raw_texel`), or a bicubic sample's taps do + /// (`texture::srgb_raw_tap`). + pub raw: bool, + /// The slot's binding views the codes of an 8-bit sRGB texture held as its UNORM twin + /// (`LoweringInputs::srgb_textures`), and the sample filters them: the device's sample there, + /// filtered codes, decodes through Metal's table (`texture::srgb_filtered_texel`), exactly + /// where it read one texel. pub srgb_codes: bool, /// A fragment function's depth comparison whose reference the pipeline's private /// `fragmentDepthCompareClampMask` clamps (`LoweringInputs::depth_compare_clamp_mask`): the @@ -721,11 +721,6 @@ pub enum Unmapped { } impl Sampling { - /// The sample reads its slot's raw view ([`BindingKey::raw`]). - pub fn raw(&self) -> bool { - matches!(self.source, Source::Combined(key) if key.raw) - } - /// The shape the arms of a switch-at-use share where it emulates once (SEMANTICS 1012, /// `sampler::shared_value`): this sampling with its texture slot and sampler taken out, where /// it is an emulation on a combined binding whose residency the function does not observe: a @@ -997,7 +992,7 @@ impl Sampling { // raw decode; the bicubic routines round their `half` result themselves. let half = match (&self.op, self.texel) { (SampleOp::Bicubic(_), _) | (_, None) => 0, - _ if self.raw() => crate::lower::texture::SRGB_RAW_WORDS, + _ if self.raw => crate::lower::texture::SRGB_RAW_WORDS, _ if self.srgb_codes => crate::lower::texture::SRGB_FILTERED_WORDS, // A heap color texture's call reads the class its handle carries first. (_, Some(f)) if f.conv == crate::lower::texture::TexelConv::F16 => { @@ -1347,8 +1342,7 @@ pub fn finish(cx: &mut SelectCx<'_>) -> Result<(), Error> { .ok_or_else(|| invariant("a sampled texture slot without a shape"))?; let texel = crate::lower::texture::image_class(cx.inputs, s); let sampler = CombinedSampler::new(key.sampler, key.compare, texel != TexelClass::Float) - .with_cube_gradient(key.cube_gradient) - .with_raw(key.raw); + .with_cube_gradient(key.cube_gradient); if let SamplerRef::Constexpr(words) = key.sampler { constexpr_desc(words, sampler.sampler_use(), cx.profile)?; } @@ -1420,11 +1414,7 @@ pub fn finish(cx: &mut SelectCx<'_>) -> Result<(), Error> { let combined = count(decls.len()).saturating_add(count(heap_samplers.len())); let limit = cx.profile.fields().limits.max_per_stage_descriptor_samplers; let separate = combined > limit; - // A raw view's binding samples through its use's separate sampler. - let uses: BTreeSet = decls - .values() - .map(|d| d.sampler.sampler_binding_use()) - .collect(); + let uses: BTreeSet = decls.values().map(|d| d.sampler).collect(); counts.samplers = if separate { count(uses.len()).saturating_add(count(heap_samplers.len())) } else { @@ -1516,7 +1506,7 @@ pub fn declare( let image = c.image.declare(mb)?; let binding = if plan.families.sampler.separate { let g = mb.resource(c.symbol, StorageClass::UniformConstant, image)?; - let use_ = c.sampler.sampler_binding_use(); + let use_ = c.sampler; let sampler = match separate.get(&use_) { Some(s) => *s, None => { diff --git a/crates/metal2vulkan/src/lower/sampler/select.rs b/crates/metal2vulkan/src/lower/sampler/select.rs index c48a47625..c28d587bb 100644 --- a/crates/metal2vulkan/src/lower/sampler/select.rs +++ b/crates/metal2vulkan/src/lower/sampler/select.rs @@ -2093,37 +2093,30 @@ fn select_one( if matches!(op, SampleOp::Sample { .. } | SampleOp::Gather { .. }) { cx.families.sampler.device_sampling = true; } - // Whether the device's sampler is Metal's own (`VkProperty::MetalSampler` alone), whose sRGB - // decode is Metal's table. - let metal_unit = cx - .profile - .fields() - .enabled - .properties - .contains(&crate::device::requirements::VkProperty::MetalSampler); - // An 8-bit sRGB texel Metal decodes from its raw code: a nearest sample's, a pixel fetch's, a - // `half` gather's, a `float` gather's on a device whose sampler is not Metal's own (Metal's own - // sampler gathers the table's decode; a gather reads one texel per lane, so the table's decode - // is exact and cheap), and a bicubic sample's. Under the slot's twin variant (a bound format the - // device cannot sample) the device's view reads the codes, so an access the raw codes do not - // serve decodes what the device samples there (`srgb_codes`). An LOD query reads no texel. + // An 8-bit sRGB texture the device reads through its own sRGB view, but under the slot's twin + // variant (a bound format the device cannot sample, held as its UNORM twin), whose view reads + // the codes: a nearest sample's, a pixel fetch's, a gather's and a bicubic sample's texels are + // one texel's codes, decoded exactly through Metal's table (`raw`), and any other sample's are + // the device's filter of the codes, decoded through it (`srgb_codes`). An LOD query reads no + // texel. let (raw, srgb_codes) = match form { Some(f) if matches!(f.conv, TexelConv::F16 | TexelConv::F32) => { use crate::lower::texture::SrgbReach; let reach = match &op { - SampleOp::PixelFetch { .. } | SampleOp::Bicubic(_) => SrgbReach::Raw, - SampleOp::Sample { dref: None, .. } => match stat { - Some((r, _)) if nearest_texel(r)? => SrgbReach::Raw, - _ => SrgbReach::Device, - }, - SampleOp::Gather { .. } if f.conv == TexelConv::F16 || !metal_unit => { - SrgbReach::Raw + SampleOp::PixelFetch { .. } | SampleOp::Bicubic(_) | SampleOp::Gather { .. } => { + SrgbReach::Codes } - _ => SrgbReach::Device, + SampleOp::Sample { dref: None, .. } => match stat { + Some((r, _)) if nearest_texel(r)? => SrgbReach::Codes, + _ => SrgbReach::Filtered, + }, + _ => SrgbReach::Filtered, }; - let read = crate::lower::texture::srgb_texels(cx, image, shape, reach)?; - let codes = reach != SrgbReach::Raw && crate::lower::texture::srgb_twin(cx, image)?; - (read && reach == SrgbReach::Raw, codes) + let twin = crate::lower::texture::srgb_texels(cx, image, shape, reach, m)?; + ( + twin && reach == SrgbReach::Codes, + twin && reach == SrgbReach::Filtered, + ) } _ => (false, false), }; @@ -2265,7 +2258,6 @@ fn select_one( sampler, compare, cube_gradient, - raw, }; cx.families.sampler.combined.insert(key); Source::Combined(key) @@ -2408,6 +2400,7 @@ fn select_one( swizzle, offset_base, anisotropic, + raw, srgb_codes, clamp_reference, }; diff --git a/crates/metal2vulkan/src/lower/texture/emit.rs b/crates/metal2vulkan/src/lower/texture/emit.rs index 61f82e4be..c4c1bd58a 100644 --- a/crates/metal2vulkan/src/lower/texture/emit.rs +++ b/crates/metal2vulkan/src/lower/texture/emit.rs @@ -895,7 +895,7 @@ fn from_image( StorageImageClass::Identity => x, StorageImageClass::SwizzleBgra => swizzle_bgra(fb, x)?, // An 8-bit sRGB format's codes, through its UNORM alias: decoded as Metal decodes them, - // through its twelve-bit table, as a raw view's are (alpha 1 for an RGBX format's). + // through its twelve-bit table, as a UNORM twin's are (alpha 1 for an RGBX format's). StorageImageClass::SrgbEncode => { let x = match decl.x_channel { true => x_channel_read(fb, decl, x)?, @@ -939,7 +939,7 @@ fn from_image( } } -/// The held texel (`form`, a `half` or `float` result) of raw view texel `x` (a `vec4` of `f32`: +/// The held texel (`form`, a `half` or `float` result) of texel `x` of codes (a `vec4` of `f32`: /// each lane an 8-bit code `c` as a UNORM view reads it, `c / 255` correctly rounded) of an 8-bit /// sRGB texture, as Metal reads it (`metal::texel_format`): `c` recovered by rounding `x · 255` to /// nearest (within `2^-16` of `c`), a color lane's step `k` of Metal's twelve-bit table and its @@ -1040,7 +1040,7 @@ pub(crate) fn srgb_filtered_texel( } } -/// The steps of raw view texel `x` ([`srgb_raw_texel`]): per lane the code `c` recovered by +/// The steps of texel `x` of codes ([`srgb_raw_texel`]): per lane the code `c` recovered by /// rounding `x · 255` to nearest, a color lane's table step `k` with its grid 4095, an alpha /// lane's `c` with 255, as a `uvec4` of numerators and one of denominators. fn srgb_raw_steps( @@ -1106,7 +1106,7 @@ fn srgb_ratio( } } -/// Raw view texel `x` (a `vec4` of `f32`, codes `c / 255` as in [`srgb_raw_texel`]) of an 8-bit +/// Texel `x` of codes (a `vec4` of `f32`, `c / 255` as in [`srgb_raw_texel`]) of an 8-bit /// sRGB texture as a filter's tap on the grids of `BicubicTexels::SRGB`: each color lane the /// step `k` of its code over 4095 (`ConvertUToF(k) / 4095`, within an ulp of `k / 4095`, so the /// exact routines' `RoundEven(x · 4095)` recovers `k`), alpha's `c / 255` as it is (`16 c` on @@ -1144,7 +1144,7 @@ pub(crate) fn srgb_raw_tap( } /// The words [`srgb_raw_tap`] emits, at most: per color lane the recovery, the step, and the -/// quotient, and the texel's assembly (`the_raw_estimate_bounds_its_emission`). +/// quotient, and the texel's assembly (`the_srgb_estimate_bounds_its_emission`). pub(crate) const SRGB_TAP_WORDS: u32 = 160; /// The color lanes of an sRGB texel ([`srgb_raw_texel`]): red, green, and blue. @@ -1156,7 +1156,7 @@ pub(crate) const SRGB_RAW_WORDS: u32 = 520; /// The words [`srgb_filtered_texel`] emits, at most: [`srgb_raw_texel`]'s, the codes' scale, test /// and interpolation (two table steps per color lane), a `half` result's rounding, and the -/// selection (`the_raw_estimate_bounds_its_emission`). +/// selection (`the_srgb_estimate_bounds_its_emission`). pub(crate) const SRGB_FILTERED_WORDS: u32 = SRGB_RAW_WORDS + 400; /// The conversion of a slot's `half` texels by the bound format's class: the module's routine and @@ -2535,21 +2535,6 @@ fn read(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, r: &Read) -> BResult< within, flagged, } = image_in(cx, fb, &r.image, view, r.heap_class)?; - // An 8-bit sRGB texel's raw code, from the slot's raw view of the same image type. - let raw = match (r.raw, r.image) { - (true, ImageRef::Slot(index)) => match cx.decl.families.texture.raw.get(&index) { - Some(g) => Some(*g), - None => return Err(cx.fail(format!("texture slot {index} has no raw view"))), - }, - _ => None, - }; - let img = match raw { - Some(g) => { - let ptr = fb.module().global_value(g)?; - fb.load(ptr, MemAccess::default())? - } - None => img, - }; let plain = match (volume, r.edge) { (true, _) => Some(u32s(fb, coord_len(&decl), 0)?), (false, None) => Some(coordinate(cx, fb, &decl, &r.at)?), @@ -2656,8 +2641,7 @@ fn read(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, r: &Read) -> BResult< }; // A slot the draw reads through a snapshot (`LoweringInputs::snapshot_textures`): its // interface fact admits only the plain fetch of a level the snapshot's copy makes, through the - // image the copy fetches from (`snapshot_fetches_raw`: the slot's raw view where its reads - // take an 8-bit sRGB texel's raw codes, else its image). + // slot's image, which the copy fetches from. let snapshot = match r.image { ImageRef::Slot(index) => { let plain = sampled @@ -2665,8 +2649,7 @@ fn read(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, r: &Read) -> BResult< && sample.is_none() && r.edge.is_none() && !r.level_views - && within.is_none() - && r.raw == crate::lower::fragment::snapshot_fetches_raw(cx, index); + && within.is_none(); crate::lower::fragment::snapshot_prepare(cx, fb, index, img, plain)? } ImageRef::Heap { .. } => None, @@ -2781,9 +2764,11 @@ fn read(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, r: &Read) -> BResult< } _ => texel, }; - let texel = match raw { - Some(_) => srgb_raw_texel(cx, fb, r.texel, texel, SRGB_TEXEL)?, - None => { + // An 8-bit sRGB texture held as its UNORM twin: the codes the slot's image reads, decoded + // through Metal's table. + let texel = match r.raw { + true => srgb_raw_texel(cx, fb, r.texel, texel, SRGB_TEXEL)?, + false => { let half = half_class(cx, &r.image, r.texel); from_image(cx, fb, &decl, r.texel, texel, half)? } diff --git a/crates/metal2vulkan/src/lower/texture/mod.rs b/crates/metal2vulkan/src/lower/texture/mod.rs index 92f8f4685..39c23591b 100644 --- a/crates/metal2vulkan/src/lower/texture/mod.rs +++ b/crates/metal2vulkan/src/lower/texture/mod.rs @@ -285,8 +285,9 @@ pub struct Read { pub alpha: bool, /// A Metal 4.1 read through a clamp-to-edge sampler ([`Edge`]). pub edge: Option, - /// The read takes an 8-bit sRGB texel's raw code from its slot's raw view, decoded as Metal - /// decodes it (`emit::srgb_raw_texel`, `RuntimeFact::SrgbTexture`). + /// The read takes an 8-bit sRGB texel's codes from its slot's image, which holds the format's + /// UNORM twin (`LoweringInputs::srgb_textures`), and decodes them as Metal decodes them + /// (`emit::srgb_raw_texel`, `RuntimeFact::SrgbTexture`). pub raw: bool, /// The read, of a storage slot whose class is `SrgbEncode`, takes the codes of an 8-bit sRGB /// format from its UNORM alias and decodes them as Metal does, through the module's table @@ -969,9 +970,6 @@ pub struct Declared { /// The tile map of each slot with a tile-map arm: a word view of its `ResourceKind::TileMap` /// binding. pub tile_maps: BTreeMap, - /// The raw view of each slot a read of which takes an 8-bit sRGB texel's raw code - /// (`ResourceKind::RawTexture`): its variable. - pub raw: BTreeMap, /// The `TexelFormat` specialization constant of each slot whose texels a read, gather, or /// sample converts to a `half` result by the bound format's class. pub half_format: BTreeMap, @@ -1138,20 +1136,6 @@ pub fn declare( mb.volatile(g)?; } d.images.insert(*index, (g, image)); - // The raw view, a sampled slot's, never level views: an 8-bit sRGB texture's codes - // through an image of the same type. - if s.raw { - let r = mb.resource( - crate::pipeline::sym::ResourceSlot { - stage: s.slot.stage, - kind: crate::pipeline::sym::ResourceKind::RawTexture, - index: s.slot.index, - }, - crate::spirv::ir::StorageClass::UniformConstant, - image, - )?; - d.raw.insert(*index, r); - } } if s.presence { let b = mb.ty(SType::Bool)?; @@ -1555,7 +1539,7 @@ pub(crate) fn half_texels( vec![[NoteTest::equal(NoteOn::Unmeasured(index), 1, 1)].into()] } half::HalfFamilies::Every => { - let unmeasured = [unconverted_class(cx, index)?]; + let unmeasured = [unconverted_class(cx, index)]; let unpacked: NoteClause = [NoteTest::equal( NoteOn::Texel(index), crate::metal::texel_format::TexelFormat::PACKED_MASK, @@ -1681,35 +1665,33 @@ pub(crate) fn unmeasured_class(index: u32) -> NoteClause { } /// The clause of texture slot `index` where its `half` conversion may not be Metal's -/// ([`half_texels`]): [`unmeasured_class`], and where the slot may be bound in an 8-bit sRGB -/// format (its variant, `LoweringInputs::srgb_textures`) on a device that samples through -/// Metal's own texture unit (`VkProperty::MetalSampler`: MoltenVK on Apple's GPU), also no `SRGB` -/// bit, the module requiring the property there. That device's `f32` texel of such a format is -/// Metal's `float` value: a step on `1/4095` (a color channel's table step, or a linear sum -/// rounded onto its grid), `1/4080` (alpha's linear sum), or `1/255` (alpha's code), rounded to -/// nearest even (`metal::texel_format`). The conversion's `OTHER` arm rounds that to `half` to -/// nearest even, which is the step's own rounding to `half`, Metal's `half` value: on those grids -/// no step lies near enough a tie between halves for the `f32` rounding to move it across -/// (`metals_srgb_float_steps_round_to_their_half_steps`). -fn unconverted_class(cx: &mut SelectCx<'_>, index: u32) -> Result { +/// ([`half_texels`]): [`unmeasured_class`], and on a device that samples through Metal's own +/// texture unit (`VkProperty::MetalSampler`: MoltenVK on Apple's GPU) also no `SRGB` bit, the +/// module requiring the property there. That device's `f32` texel of an 8-bit sRGB format, its +/// own decode, is Metal's `float` value: a step on `1/4095` (a color channel's table step, or a +/// linear sum rounded onto its grid), `1/4080` (alpha's linear sum), or `1/255` (alpha's code), +/// rounded to nearest even (`metal::texel_format`). The conversion's `OTHER` arm rounds that to +/// `half` to nearest even, which is the step's own rounding to `half`, Metal's `half` value: on +/// those grids no step lies near enough a tie between halves for the `f32` rounding to move it +/// across (`metals_srgb_float_steps_round_to_their_half_steps`). +fn unconverted_class(cx: &mut SelectCx<'_>, index: u32) -> NoteClause { use crate::metal::bicubic::BicubicTexels as B; - let srgb = cx.inputs.srgb_textures.contains(&slot_of(cx, index)?.slot); let metal = cx .profile .fields() .enabled .properties .contains(&crate::device::requirements::VkProperty::MetalSampler); - if !(srgb && metal) { - return Ok(unmeasured_class(index)); + if !metal { + return unmeasured_class(index); } cx.families.sampler.metal_sampler = true; - Ok([NoteTest::equal( + [NoteTest::equal( NoteOn::Texel(index), B::LINEAR | B::HALF | B::EXACT | B::SRGB, 0, )] - .into()) + .into() } /// The address-mode map constexpr sampler `words` samples texture slot `index` under: the map @@ -1729,43 +1711,50 @@ pub(crate) fn constexpr_address_map( Ok(cx.inputs.address_maps.get(&slot).copied()) } -/// How an access of a texture an 8-bit sRGB format may be bound to reads its texels under the -/// slot's variant ([`srgb_texels`]). +/// How an access of a texture held as an 8-bit sRGB format's UNORM twin decodes the codes its +/// view reads ([`srgb_texels`]). #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub(crate) enum SrgbReach { - /// Through the device's decode alone: no form the raw codes serve. - Device, - /// From the raw codes alone, decoded or summed exactly as Metal does. - Raw, + /// The device's filter of the codes, decoded through Metal's table: Metal's value where the + /// filter reads one texel (`emit::srgb_filtered_texel`). + Filtered, + /// One texel's codes, decoded or summed exactly as Metal does. + Codes, } -/// A read, sample, or gather of `image` (shape `shape`) with a `half` or `float` result, which -/// an 8-bit sRGB format bound to it would decode (`metal::texel_format`). `reach` says where the -/// module can answer as Metal does from the raw codes: a read, a nearest sample, a pixel-coordinate -/// fetch, and a gather with a `half` result decode the code through Metal's twelve-bit table, and a -/// bicubic sample sums the table steps exactly (the exact routines' `BicubicTexels::SRGB` grids); -/// the caller decides. On a sampled color texture slot (not a texture -/// buffer, a depth texture, or a storage slot) the module records `RuntimeFact::SrgbTexture`, and -/// where the slot is one of `LoweringInputs::srgb_textures` (its variant: bound in such a format) -/// an access the raw codes serve reads them, returning `true` and declaring Metal's table -/// (`arith::srgb`, shared with `air.unpack`'s `unorm4x8_srgb`, whose census name it is charged to), -/// and any other access keeps the device's decode, recording `PrecisionNote::SrgbTexelDecode` and -/// `RuntimeFact::SrgbDeviceDecode` (a device that cannot sample the bound format has no view to -/// decode it through, so the planner refuses the texture there). A heap element's format is not known, so a heap element's access records the note. On a -/// device that decodes through Metal's own texture unit (`VkProperty::MetalSampler`: MoltenVK on -/// Apple's GPU) the device's decode is Metal's, so the module requires the property there instead -/// of the note. +/// A read, sample, or gather of `image` (shape `shape`) with a `half` or `float` result, which an +/// 8-bit sRGB format bound to it would decode (`metal::texel_format`). On a sampled color texture +/// slot (not a texture buffer, a depth texture, or a storage slot) the module records +/// `RuntimeFact::SrgbTexture`. +/// +/// Where the slot is one of `LoweringInputs::srgb_textures` (its variant: bound to a format the +/// device cannot sample, held as its UNORM twin, whose view reads the codes) the access decodes +/// the codes through Metal's twelve-bit table, returning `true` and declaring the table +/// (`arith::srgb`, shared with `air.unpack`'s `unorm4x8_srgb`, whose census name it is charged +/// to): `reach` says how, the caller deciding. A read, a nearest sample, a pixel-coordinate +/// fetch, a gather and a bicubic tap read one texel's codes and decode them exactly +/// ([`SrgbReach::Codes`]); any other sample decodes the device's filter of the codes +/// ([`SrgbReach::Filtered`]), recording `PrecisionNote::SrgbTexelDecode`. +/// +/// Elsewhere the access reads the device's own decode through the slot's view, an sRGB format's +/// sRGB view: the module records `PrecisionNote::SrgbTexelDecode` where the bound format's class +/// is an sRGB one (`BicubicTexels::SRGB`, a test of the bound format that the runtime announces at +/// a draw or dispatch binding such a texture), and outright for a heap element, whose format is +/// never known. On a device that decodes through Metal's own texture unit +/// (`VkProperty::MetalSampler`: MoltenVK on Apple's GPU) the device's decode is Metal's, so the +/// module requires the property there instead of the note. pub(crate) fn srgb_texels( cx: &mut SelectCx<'_>, image: ImageRef, shape: ImageShape, reach: SrgbReach, + m: &mut Meter, ) -> Result { if shape.dim == ImageDim::Buffer || shape.depth { return Ok(false); } let ImageRef::Slot(index) = image else { - device_decode(cx); + device_decode(cx, None, m)?; return Ok(false); }; let s = slot_of(cx, index)?; @@ -1776,55 +1765,42 @@ pub(crate) fn srgb_texels( cx.facts .insert(crate::pipeline::facts::RuntimeFact::SrgbTexture { slot }); if !cx.inputs.srgb_textures.contains(&slot) { + device_decode(cx, Some(index), m)?; return Ok(false); } - // A form the raw codes do not serve decodes through the device's view, which a device that - // cannot sample the bound format does not have: under the slot's twin variant it decodes the - // device's filtered codes instead, through Metal's table. - let device = reach == SrgbReach::Device; - if device { - cx.facts - .insert(crate::pipeline::facts::RuntimeFact::SrgbDeviceDecode { slot }); - if !cx.inputs.srgb_twins.contains(&slot) { - device_decode(cx); - return Ok(false); - } + if reach == SrgbReach::Filtered { cx.precision.insert(PrecisionNote::SrgbTexelDecode); } cx.families .arith .srgb .get_or_insert(crate::air::intrinsics::PackDir::Unpack); - Ok(!device) + Ok(true) } -/// Whether an access of `image` that keeps the device's decode of an 8-bit sRGB texture -/// ([`srgb_texels`] with [`SrgbReach::Device`]) samples the bound format's UNORM -/// twin instead (`LoweringInputs::srgb_twins`: a format the device cannot sample), whose view reads -/// the codes, so the access decodes the device's filtered codes through Metal's table -/// (`texture::srgb_filtered_texel`), Metal's value exactly where the filter reads one texel. -pub(crate) fn srgb_twin(cx: &SelectCx<'_>, image: ImageRef) -> Result { - match image { - ImageRef::Slot(index) => Ok(cx.inputs.srgb_twins.contains(&slot_of(cx, index)?.slot)), - ImageRef::Heap { .. } => Ok(false), - } -} - -/// An access that keeps the device's decode of a texture that may be bound in an 8-bit sRGB -/// format ([`srgb_texels`]): `PrecisionNote::SrgbTexelDecode`, or on a device that decodes -/// through Metal's own texture unit the requirement of `VkProperty::MetalSampler`. -fn device_decode(cx: &mut SelectCx<'_>) { +/// An access that reads the device's decode of a texture that may be bound in an 8-bit sRGB +/// format ([`srgb_texels`]): `PrecisionNote::SrgbTexelDecode` where texture slot `index` is bound +/// in such a format, or outright for a heap element (`None`); on a device that decodes through +/// Metal's own texture unit, the requirement of `VkProperty::MetalSampler` instead. +fn device_decode(cx: &mut SelectCx<'_>, index: Option, m: &mut Meter) -> Result<(), Error> { + use crate::metal::bicubic::BicubicTexels as B; let metal = cx .profile .fields() .enabled .properties .contains(&crate::device::requirements::VkProperty::MetalSampler); - if metal { - cx.families.sampler.metal_sampler = true; - } else { - cx.precision.insert(PrecisionNote::SrgbTexelDecode); + match (metal, index) { + (true, _) => cx.families.sampler.metal_sampler = true, + (false, Some(index)) => { + let srgb = NoteTest::equal(NoteOn::Bound(index), B::SRGB, B::SRGB); + cx.note_when(PrecisionNote::SrgbTexelDecode, vec![[srgb].into()], m)?; + } + (false, None) => { + cx.precision.insert(PrecisionNote::SrgbTexelDecode); + } } + Ok(()) } /// The value id of an operand (constants included: emission materializes them). @@ -3014,17 +2990,12 @@ fn select_read_as( } _ => false, }; - // An 8-bit sRGB texel's raw code, under the slot's variant, decoded exactly; another `half` + // An 8-bit sRGB texel's codes, under the slot's twin variant, decoded exactly; another `half` // texel converts by the bound format's class, and its NaN is the device's decode. let raw = matches!(texel.conv, TexelConv::F16 | TexelConv::F32) - && srgb_texels(cx, image, shape, SrgbReach::Raw)?; - if let (true, ImageRef::Slot(index)) = (raw, image) { - if let Some(s) = cx.families.texture.slots.get_mut(&index) { - s.raw = true; - } - } + && srgb_texels(cx, image, shape, SrgbReach::Codes, m)?; // A storage slot's 8-bit sRGB codes, through its UNORM alias, decoded through Metal's table - // (the slot's planning declares it), as a raw view's are. + // (the slot's planning declares it), as a UNORM twin's are. let srgb_codes = storage && matches!(texel.conv, TexelConv::F16 | TexelConv::F32) && matches!( diff --git a/crates/metal2vulkan/src/lower/texture/slot.rs b/crates/metal2vulkan/src/lower/texture/slot.rs index 192751c13..50871070c 100644 --- a/crates/metal2vulkan/src/lower/texture/slot.rs +++ b/crates/metal2vulkan/src/lower/texture/slot.rs @@ -225,10 +225,6 @@ pub struct SlotPlan { /// (`TexelFormat::unmeasured_on_metal_sampler`): the slot declares its `UnmeasuredTexels` /// specialization, which the note's clause tests. pub unmeasured: bool, - /// A read of the slot, or an emulated linear sample of its cube's faces, takes an 8-bit sRGB - /// texel's raw code from the slot's raw view (`ResourceKind::RawTexture`), the slot being one - /// of `LoweringInputs::srgb_textures` (`RuntimeFact::SrgbTexture`). - pub raw: bool, /// A read of the slot, a texture buffer, applies the bound texture buffer's swizzle, which /// the slot's `TextureSwizzle` specialization gives (`RuntimeFact::TextureSwizzle`); or the /// slot, a storage slot of `LoweringInputs::swizzled_storage`, applies the bound texture's to @@ -271,7 +267,6 @@ impl SlotPlan { texel_format: false, half_filtered: false, unmeasured: false, - raw: false, swizzle: false, constant_lanes: false, offset_base: false, @@ -1139,11 +1134,7 @@ fn declare_slot( let n = views.unwrap_or(1); counts.storage_images = counts.storage_images.saturating_add(n); } else { - // The raw view's binding beside the texture's own: an 8-bit sRGB texture's codes, or a - // 16-bit float texture's own bits. - counts.sampled_images = counts - .sampled_images - .saturating_add(if s.raw { 2 } else { 1 }); + counts.sampled_images = counts.sampled_images.saturating_add(1); } Ok(ImageDecl { dim, diff --git a/crates/metal2vulkan/src/metal/bicubic.rs b/crates/metal2vulkan/src/metal/bicubic.rs index 4488577a0..e8a2c9fa5 100644 --- a/crates/metal2vulkan/src/metal/bicubic.rs +++ b/crates/metal2vulkan/src/metal/bicubic.rs @@ -101,12 +101,13 @@ impl BicubicTexels { pub const EXACT: u32 = 1 << 8; /// With [`EXACT`](Self::EXACT): the codes are 16-bit. pub const WIDE16: u32 = 1 << 9; - /// The channels are 8-bit sRGB codes (`metal::texel_format::srgb_raw`). With - /// [`EXACT`](Self::EXACT), set only where a function reads the raw codes (the slot's - /// `SrgbTexture` variant), each tap's color value is a step of Metal's twelve-bit table on the - /// grid `1/4095`, and its alpha a code on `1/(16 · 255)`, so the exact sum rounds half up onto - /// those grids. [`texels`] never sets it; `metal::texel_format::texel_format` does, without - /// `EXACT`. + /// The channels are 8-bit sRGB codes (`metal::texel_format::srgb_coded`). With + /// [`EXACT`](Self::EXACT), set only where a function decodes the codes itself (the slot's + /// `SrgbTexture` variant: a format the device holds as its UNORM twin), each tap's color value + /// is a step of Metal's twelve-bit table on the grid `1/4095`, and its alpha a code on + /// `1/(16 · 255)`, so the exact sum rounds half up onto those grids. [`texels`] never sets it; + /// `metal::texel_format::texel_format` does, without `EXACT`, where the device decodes the + /// taps and the sum is the emulated one. pub const SRGB: u32 = 1 << 10; /// The channels are Apple's extended-range codes (`metal::format::ExtendedRange`), set with /// [`EXACT`](Self::EXACT) where a function samples such a texture, and with @@ -250,11 +251,8 @@ pub fn texels(pf: PixelFormat) -> Option { // on an Apple M3 Max under macOS 27.0.1: reads, nearest, linear and bicubic samples and // gathers bit for bit, `bind::ChromaDecode`): `RGBX8Unorm`'s treatment. P::GBGR422 | P::BGRG422 => (exact8u, RGB), - // A BC sRGB form reads its codes through its unorm view, as an 8-bit sRGB format does; - // so does a PVRTC, ETC2 or EAC sRGB form (its linear form's codes, `bind::PvrtcDecode`, - // `bind::EtcDecode`), an RGB one's alpha 1, and an ASTC sRGB form its decoded twin's - // (`bind::AstcDecode`; a device with the format decodes it itself, and the binder takes - // this treatment there for none, `metal::texel_format::srgb_raw_on`). + // A BC, PVRTC, ETC2, EAC or ASTC sRGB form's texels are 8-bit sRGB codes once decoded, + // which Metal filters as an 8-bit sRGB format's; an RGB one's alpha 1. P::BC1RGBASRGB | P::BC2RGBASRGB | P::BC3RGBASRGB diff --git a/crates/metal2vulkan/src/metal/format/mod.rs b/crates/metal2vulkan/src/metal/format/mod.rs index fc3620f3f..a3e7ac2c1 100644 --- a/crates/metal2vulkan/src/metal/format/mod.rs +++ b/crates/metal2vulkan/src/metal/format/mod.rs @@ -201,8 +201,8 @@ pub enum FormatEmulation { /// [`EtcDecode`](crate::bind::EtcDecode), [`ChromaDecode`](crate::bind::ChromaDecode)), which /// the consumer decodes after each write. The candidate's format is the twin's view of compact /// texels, `R8G8B8A8_UNORM` (an `_sRGB` form's `R8G8B8A8_SRGB`), whose texels are 8-bit codes - /// of Metal's values (a PVRTC, ETC2, EAC or 4:2:2 format's own codes, an sRGB one's read raw, - /// `texel_format::srgb_raw`), or an EAC 11-bit + /// of Metal's values (a PVRTC, ETC2, EAC or 4:2:2 format's own codes, an sRGB one's decoded by + /// the device through that view, `texel_format::srgb_coded`), or an EAC 11-bit /// format's 16-bit normalized codes nearest Metal's values (`R16_UNORM`, `R16_SNORM` and their /// two-channel forms); for an ASTC or an EAC 11-bit format the consumer may hold Metal's values /// exactly as `float`s instead ([`AstcTexels`](crate::bind::AstcTexels), @@ -1134,9 +1134,8 @@ macro_rules! formats_named_not_held { // component mapping cannot move the function, which format conversion applies // before the swizzle, so an image of it would read Metal's alpha decoded and // Metal's blue linear: two channels of four wrong, not a near-equivalent. Holding - // it exactly needs the raw-code sRGB decode in the shader - // (`metal::texel_format::srgb_raw`) as the only read of it, not as a refinement - // over the device's decode. + // it needs an sRGB decode of the codes in the shader as the only read of it, which + // no view gives. | PixelFormat::ARGB8UnormSRGB | PixelFormat::RGB16Unorm | PixelFormat::RGB16Snorm @@ -1954,12 +1953,12 @@ fn candidates(pf: PixelFormat) -> Result<(vk::ImageAspectFlags, &'static [Candid } } -/// The UNORM format of an 8-bit sRGB format whose texels Metal decodes from their raw codes -/// (`R8Unorm_sRGB`, `RG8Unorm_sRGB`, `RGBA8Unorm_sRGB`, `BGRA8Unorm_sRGB`; a BC, PVRTC, ETC2 or -/// EAC sRGB format's unorm form, the same blocks): the same channels and bits, its texels the sRGB format's codes -/// read as `c / 255`. A device that cannot sample the sRGB format holds a sampled texture of it in -/// this format, and a pipeline reads the raw codes through its view and decodes them as Metal does. -/// `None` for any other format. +/// The UNORM format of an 8-bit sRGB format (`R8Unorm_sRGB`, `RG8Unorm_sRGB`, `RGBA8Unorm_sRGB`, +/// `BGRA8Unorm_sRGB`, `RGBX8Unorm_sRGB`; a BC, PVRTC, ETC2 or EAC sRGB format's unorm form, the +/// same blocks): the same channels and bits, its texels the sRGB format's codes read as `c / 255`. +/// A device that cannot sample the sRGB format holds a sampled texture of it in this format +/// (`texel_format::srgb_twin_on`), and a pipeline reads the codes through its view and decodes +/// them through Metal's table, having no sRGB view to decode them. `None` for any other format. pub fn srgb_raw_twin(pf: PixelFormat) -> Option { use PixelFormat as P; Some(match pf { diff --git a/crates/metal2vulkan/src/metal/format/tests.rs b/crates/metal2vulkan/src/metal/format/tests.rs index 0b285d73d..c91a5ea75 100644 --- a/crates/metal2vulkan/src/metal/format/tests.rs +++ b/crates/metal2vulkan/src/metal/format/tests.rs @@ -961,7 +961,7 @@ fn compressed_extension_formats_follow_exposure() { ]]; // A PVRTC format's decoded twin, whose codes' format this floor does not list. if crate::bind::PvrtcDecode::of(pf).is_some() { - let codes = match crate::metal::texel_format::srgb_raw(pf) { + let codes = match crate::metal::texel_format::srgb_coded(pf) { true => vk::Format::R8G8B8A8_SRGB, false => vk::Format::R8G8B8A8_UNORM, }; @@ -3178,10 +3178,10 @@ fn the_srgb_straggler_has_no_vulkan_image_and_keeps_its_footprint() { let argb = direct_format(PixelFormat::ARGB8Unorm).expect("ARGB8Unorm is held"); assert_eq!(argb, vk::Format::R8G8B8A8_UNORM); assert_eq!( - crate::metal::texel_format::srgb_raw_view(vk::Format::R8G8B8A8_SRGB), - Some(argb), + vk::Format::R8G8B8A8_SRGB.block().map(|b| b.class), + argb.block().map(|b| b.class) ); - assert!(!crate::metal::texel_format::srgb_raw(pf)); + assert!(!crate::metal::texel_format::srgb_coded(pf)); } /// `BGRA4Unorm`'s colour-attachment conversion, measured on an Apple M3 Max under macOS 27.0.1 diff --git a/crates/metal2vulkan/src/metal/texel_format.rs b/crates/metal2vulkan/src/metal/texel_format.rs index 3f6480c5d..36dfc441d 100644 --- a/crates/metal2vulkan/src/metal/texel_format.rs +++ b/crates/metal2vulkan/src/metal/texel_format.rs @@ -102,32 +102,31 @@ //! `R8Unorm`, `R16Float`, and `R32Float`, in 1D and 2D: the P2a probe). //! //! **sRGB.** Metal decodes an 8-bit sRGB color channel through its twelve-bit table (the code `c` -//! to the step `k`, the value `k / 4095`, `lower::arith::srgb`), which the device's decode does -//! not reproduce, and reads alpha as `c / 255`: a read or a nearest sample with a `half` result -//! rounds that value to nearest even, a gather's likewise, and a read or a nearest sample with a -//! `float` result rounds it to `f32` to nearest even (`RGBA8Unorm_sRGB`, every code: `f8f81b81`, -//! the probe cases). A linear sample sums the taps' steps exactly with the linear filter's weights, -//! rounds the sum half up onto `1/4095` (alpha's codes onto `1/(16 · 255)`), and that value to -//! nearest even, to `half` or `f32` (the probe cases and P2a), as the bicubic filter sums them. -//! Only the raw code gives these values, so a texture bound in such a format is read through a -//! UNORM view of the same image ([`srgb_raw_view`]): the `RuntimeFact::SrgbTexture` variant of a -//! function. Its [`texel_format`] is [`UNORM`](BicubicTexels::UNORM) and -//! [`SRGB`](BicubicTexels::SRGB) with its channels, never [`EXACT`](BicubicTexels::EXACT): a -//! conversion of the device's value keeps its rounding. A gather's `float` value is not -//! measured, so it keeps the device's decode (`PrecisionNote::SrgbTexelDecode`). `RGBA8Unorm_sRGB` -//! was read, and so were `BGRA8Unorm_sRGB`, `R8Unorm_sRGB`, and `RG8Unorm_sRGB` (the probe): they -//! take its rule ([`srgb_raw`]). So do the sRGB forms of BC1 to BC3 and BC7 (an Apple M4: every -//! color channel of their random blocks' reads is the step of the unorm form's -//! 8-bit code, alpha `c / 255`), read through their unorm views: exact where the device decodes the -//! unorm form's codes as Metal does (BC7's on every venue measured, as Direct3D specifies its -//! decode bit for bit; BC1 to BC3's where the driver has `DriverFact::ColorBlockDecodeIsMetals`, -//! and elsewhere announced as `compressed-texel-decode`). So do the ASTC sRGB formats, whose -//! colour Metal reads as the table's step of the top byte of each channel's decode (`bind::AstcDecode`, -//! an Apple M3 Max): read through the unorm view of their decoded twin's codes on a device without -//! the format, exact; a device with it decodes them itself, as its unorm view would decode the -//! blocks the LDR way, so they take the rule only where the device holds the codes -//! ([`srgb_raw_on`]). The other compressed and the wide sRGB formats are not measured and keep the -//! device's decode. +//! to the step `k`, the value `k / 4095` correctly rounded to the result, `lower::arith::srgb`) +//! and reads alpha as `c / 255`; its linear and bicubic filters sum the decoded steps +//! (`RGBA8Unorm_sRGB`, every code: `f8f81b81`, the probe cases). The device decodes such a texel +//! itself, through a view of the image in the sRGB format (Vulkan's texel decode applies the sRGB +//! EOTF to the codes before filtering, within the device's precision), and that is the only form +//! wherever the device samples the format: a texture slot's reads, samples, gathers and bicubic +//! taps take it, recording `PrecisionNote::SrgbTexelDecode` where the bound format's class has +//! [`SRGB`](BicubicTexels::SRGB) on a device that does not decode through Metal's own texture +//! unit (`VkProperty::MetalSampler`, whose decode is Metal's). The class is +//! [`UNORM`](BicubicTexels::UNORM) and [`SRGB`](BicubicTexels::SRGB) with its channels, never +//! [`EXACT`](BicubicTexels::EXACT): a `half` result rounds the device's `float` value, and a +//! bicubic sample sums the device's decoded taps. The formats ([`srgb_coded`]) are +//! `RGBA8Unorm_sRGB`, `BGRA8Unorm_sRGB`, `R8Unorm_sRGB` and `RG8Unorm_sRGB` (the probe), their +//! `RGBX8Unorm_sRGB` kin, and the sRGB forms of BC1 to BC3, BC7, PVRTC, ETC2, EAC and ASTC, whose +//! decoded 8-bit codes Metal decodes alike (an Apple M4, an Apple M3 Max): a device without such +//! a compressed format samples its decoded twin through an `R8G8B8A8_SRGB` view of the twin's +//! codes (`bind::AstcDecode`, `bind::PvrtcDecode`, `bind::EtcDecode`), its own decode again. +//! +//! A device that cannot sample an 8-bit sRGB format holds a sampled texture of it as the format's +//! UNORM twin (`metal::format::srgb_raw_twin`, [`srgb_twin_on`]: `R8Unorm_sRGB` and +//! `RG8Unorm_sRGB` on lavapipe, `RG8Unorm_sRGB` on ANV and NVIDIA among the committed profiles), +//! whose views read the codes as `c / 255`. Having no sRGB decode there, the slot's +//! `RuntimeFact::SrgbTexture` variant decodes the codes through Metal's table: a read, a nearest +//! sample, a pixel-coordinate fetch, a gather and a bicubic tap exactly, any other sample the +//! device's filter of the codes (`PrecisionNote::SrgbTexelDecode`). //! //! **Depth formats**. A depth texture has no `half` result, and no linear filter is emulated on //! one, so its class is read by a read, plain gather or sample of one texel with a `float` result @@ -155,7 +154,6 @@ use crate::metal::bicubic::{texels, BicubicTexels}; use crate::metal::{PixelFormat, TextureSwizzleChannels}; -use crate::vk; /// The treatment of a bound format's texels with a `half` result: the value of the /// `SpecKey::TexelFormat` specialization constant, the bits of [`BicubicTexels`] for a measured @@ -603,8 +601,8 @@ pub fn texel_format(pf: PixelFormat) -> TexelFormat { } match texels(pf) { Some(t) if measured => TexelFormat(t.0), - // Measured through the raw view only: the device's view gives no code (module docs). - Some(t) if srgb_raw(pf) => TexelFormat(t.0 | BicubicTexels::SRGB), + // An sRGB format's family, its channels sRGB codes (module docs). + Some(t) if srgb_coded(pf) => TexelFormat(t.0 | BicubicTexels::SRGB), // A cube gather's corner, measured alone, and a packed format's codes, with its family // where Metal's linear filter of it is measured: a packed normalized format's `EXACT` // sum on its field's grids, a small float's half-float one (module docs). @@ -853,14 +851,10 @@ pub fn heap_class_index(pf: PixelFormat, swizzle: TextureSwizzleChannels) -> u32 .map_or(from, |i| from + u32::try_from(i).unwrap_or(0)) } -/// Whether Metal decodes `pf`'s texels from their raw 8-bit codes through its twelve-bit table -/// (module docs): the 8-bit sRGB formats whose raw code a UNORM view of the same image reads, -/// the sRGB forms of BC1 to BC3 and BC7, whose codes their unorm views decode, the PVRTC, -/// ETC2 and EAC sRGB formats, whose codes their linear forms decode (`bind::PvrtcDecode`, -/// `bind::EtcDecode`; a decoded twin's codes on a device without them), and the ASTC sRGB -/// formats, whose codes their decoded twin holds (`bind::AstcDecode`), which a device takes only -/// where it holds the twin ([`srgb_raw_on`]). -pub fn srgb_raw(pf: PixelFormat) -> bool { +/// Whether `pf`'s color channels are 8-bit sRGB codes, which Metal decodes through its twelve-bit +/// table (module docs): the 8-bit sRGB formats, and the sRGB forms of BC1 to BC3, BC7, PVRTC, ETC2, +/// EAC and ASTC, whose blocks decode to such codes. +pub fn srgb_coded(pf: PixelFormat) -> bool { use PixelFormat as P; matches!( pf, @@ -897,44 +891,15 @@ pub fn srgb_raw(pf: PixelFormat) -> bool { ) } -/// Whether `profile`'s device reads a texture of `pf` from its raw codes as Metal decodes them -/// ([`srgb_raw`]): where the format it samples `pf` in has a raw view ([`srgb_raw_view`]), or where -/// it samples no format of `pf`'s, which the binder holds as its UNORM twin -/// (`metal::format::srgb_raw_twin`) or refuses. An ASTC sRGB format a device samples itself has -/// none: its unorm form widens the blocks' endpoints the LDR way (`bind::AstcDecode`), so no view -/// of its image reads Metal's codes, and the device's own sRGB decode answers. -pub fn srgb_raw_on(pf: PixelFormat, profile: &crate::device::profile::DeviceProfile) -> bool { +/// Whether `profile`'s device holds a sampled texture of `pf` as its 8-bit sRGB format's UNORM twin +/// (`metal::format::srgb_raw_twin`): it samples no format of `pf`'s and samples the twin's, whose +/// views read the codes, so a function decodes them itself (module docs). The runtime's image plan +/// holds the twin by the same format features. +pub fn srgb_twin_on(pf: PixelFormat, profile: &crate::device::profile::DeviceProfile) -> bool { use crate::device::requirements::FormatUsage; let usages = [FormatUsage::SampledImage].into(); - srgb_raw(pf) - && match crate::metal::format::vk_format(pf, &usages, profile) { - Ok(m) => srgb_raw_view(m.format).is_some(), - Err(_) => true, - } -} - -/// The raw view's format of an image of Vulkan format `format`, the sampled view of an -/// [`srgb_raw`] format: the UNORM format of the same channels and bits (a BC, PVRTC, ETC2 or EAC -/// format's of the same blocks), which views the image's texels as their codes (`c / 255`). `None` for any -/// other format. -pub fn srgb_raw_view(format: vk::Format) -> Option { - use vk::Format as F; - Some(match format { - F::R8_SRGB => F::R8_UNORM, - F::R8G8_SRGB => F::R8G8_UNORM, - F::R8G8B8A8_SRGB => F::R8G8B8A8_UNORM, - F::B8G8R8A8_SRGB => F::B8G8R8A8_UNORM, - F::BC1_RGBA_SRGB_BLOCK => F::BC1_RGBA_UNORM_BLOCK, - F::BC2_SRGB_BLOCK => F::BC2_UNORM_BLOCK, - F::BC3_SRGB_BLOCK => F::BC3_UNORM_BLOCK, - F::BC7_SRGB_BLOCK => F::BC7_UNORM_BLOCK, - F::PVRTC1_2BPP_SRGB_BLOCK_IMG => F::PVRTC1_2BPP_UNORM_BLOCK_IMG, - F::PVRTC1_4BPP_SRGB_BLOCK_IMG => F::PVRTC1_4BPP_UNORM_BLOCK_IMG, - F::ETC2_R8G8B8_SRGB_BLOCK => F::ETC2_R8G8B8_UNORM_BLOCK, - F::ETC2_R8G8B8A1_SRGB_BLOCK => F::ETC2_R8G8B8A1_UNORM_BLOCK, - F::ETC2_R8G8B8A8_SRGB_BLOCK => F::ETC2_R8G8B8A8_UNORM_BLOCK, - _ => return None, - }) + let samples = |pf| crate::metal::format::vk_format(pf, &usages, profile).is_ok(); + !samples(pf) && crate::metal::format::srgb_raw_twin(pf).is_some_and(samples) } #[cfg(test)] @@ -942,43 +907,34 @@ mod tests { use super::*; use BicubicTexels as T; - /// The raw view is the UNORM twin of each candidate image format of an [`srgb_raw`] format (a - /// PVRTC, ETC2, EAC or ASTC sRGB format's decoded twin's among them), but an ASTC sRGB - /// format's own block, whose unorm form decodes the blocks the LDR way; nothing else has one. + /// An sRGB-coded format's twin (`metal::format::srgb_raw_twin`) is a format whose direct image + /// format is the UNORM format of the sRGB format's own class: the same channels and bits, read + /// as their codes; nothing else has one, nor an ASTC sRGB format, whose unorm form decodes the + /// blocks otherwise. #[test] - fn an_srgb_format_has_a_raw_view_of_its_own_channels() { - for &pf in PixelFormat::ALL { - let astc = crate::bind::AstcDecode::of(pf).is_some(); - for format in crate::metal::format::candidate_formats(pf) { - let own_block = astc && crate::metal::format::direct_format(pf) == Some(format); - assert_eq!( - srgb_raw_view(format).is_some(), - srgb_raw(pf) && !own_block, - "{pf:?}: {format:?}" - ); - } - } - assert_eq!( - srgb_raw_view(vk::Format::B8G8R8A8_SRGB), - Some(vk::Format::B8G8R8A8_UNORM) - ); - } - - /// An [`srgb_raw`] format's twin (`metal::format::srgb_raw_twin`) is a format whose direct - /// image format is the raw view of the sRGB format's: the same channels and bits, read as - /// their codes; nothing else has one, nor an ASTC sRGB format. - #[test] - fn an_srgb_format_s_twin_holds_its_raw_view() { + fn an_srgb_format_s_twin_holds_its_codes() { for &pf in PixelFormat::ALL { match crate::metal::format::srgb_raw_twin(pf) { Some(twin) => { - assert!(srgb_raw(pf), "{pf:?}"); - let own = crate::metal::format::direct_format(pf).and_then(srgb_raw_view); - assert_eq!(own, crate::metal::format::direct_format(twin), "{pf:?}"); + assert!(srgb_coded(pf), "{pf:?}"); + let own = crate::metal::format::direct_format(pf).and_then(|f| f.block()); + let codes = crate::metal::format::direct_format(twin).and_then(|f| f.block()); + // A PVRTC RGB format and its twin are held only through decoded twins. + let (own, codes) = match (own, codes) { + (Some(own), Some(codes)) => (own, codes), + (None, None) => continue, + _ => panic!("{pf:?}: one of the pair without a direct format"), + }; + assert_eq!(own.color, Some(crate::vk::NumericFormat::Srgb), "{pf:?}"); + assert_eq!(codes.color, Some(crate::vk::NumericFormat::Unorm), "{pf:?}"); + assert_eq!( + (own.class, own.size, own.component_bits), + (codes.class, codes.size, codes.component_bits), + "{pf:?}" + ); } - // An ASTC sRGB format has none: its unorm form decodes the blocks otherwise. None => assert!( - !srgb_raw(pf) || crate::bind::AstcDecode::of(pf).is_some(), + !srgb_coded(pf) || crate::bind::AstcDecode::of(pf).is_some(), "{pf:?}" ), } @@ -1001,7 +957,7 @@ mod tests { /// An RGBX format converts as its RGBA twin with red, green and blue (every /// read, sample, gather and bicubic sample equals the twin's but for alpha 1): its family, - /// an `_sRGB` one's raw codes through the twin's raw view. + /// an `_sRGB` one's sRGB codes. #[test] fn rgbx_formats_convert_as_their_twins_with_three_channels() { use PixelFormat as P; @@ -1020,7 +976,7 @@ mod tests { [true, true, true, false], "{pf:?}" ); - assert_eq!(srgb_raw(pf), srgb_raw(twin), "{pf:?}"); + assert_eq!(srgb_coded(pf), srgb_coded(twin), "{pf:?}"); } // The integer formats, as their twins, convert by no family. for pf in [P::RGBX8Uint, P::RGBX16Sint, P::RGBX32Uint] { diff --git a/crates/metal2vulkan/src/pipeline/api_tests.rs b/crates/metal2vulkan/src/pipeline/api_tests.rs index 32c3c8bc3..b961e4f7d 100644 --- a/crates/metal2vulkan/src/pipeline/api_tests.rs +++ b/crates/metal2vulkan/src/pipeline/api_tests.rs @@ -196,7 +196,6 @@ mod serde_round_trips { dropped_vertex_layer: true, storage_view_slots: BTreeSet::from([buffer(3)]), srgb_textures: BTreeSet::from([slot(Stage::Kernel, SlotClass::Texture, 4)]), - srgb_twins: BTreeSet::from([slot(Stage::Kernel, SlotClass::Texture, 4)]), ycbcr_in_place: BTreeSet::from([slot(Stage::Kernel, SlotClass::Texture, 7)]), flat_grid: true, replay_bindings: true, @@ -324,7 +323,6 @@ mod serde_round_trips { amplified: true, }), srgb_textures: BTreeSet::from([slot(Stage::Fragment, SlotClass::Texture, 7)]), - srgb_twins: BTreeSet::from([slot(Stage::Fragment, SlotClass::Texture, 7)]), snapshot_textures: BTreeMap::from([( slot(Stage::Fragment, SlotClass::Texture, 3), crate::pipeline::SnapshotForm::Half, @@ -398,7 +396,6 @@ mod serde_round_trips { crate::metal::format::WordAttachment::layout(metal::PixelFormat::ABGR4Unorm) .expect("a word layout"), )]), - srgb_fetches: BTreeSet::from([0, 2]), zeroed_colors: BTreeMap::from([(2, metal::PixelFormat::RGBA32Sint)]), dropped_colors: BTreeSet::from([3]), kept_imageblock_bytes: Some(12), diff --git a/crates/metal2vulkan/src/pipeline/artifact.rs b/crates/metal2vulkan/src/pipeline/artifact.rs index 804cf3bad..2fc60d692 100644 --- a/crates/metal2vulkan/src/pipeline/artifact.rs +++ b/crates/metal2vulkan/src/pipeline/artifact.rs @@ -753,14 +753,14 @@ pub enum PrecisionNote { /// color lane, `1/8192` an `_sRGB` color lane, `1/4080` alpha); 4,050 of the 3,317,760 lanes /// measured (every one at most 0.013968 of a step from a tie), every other lane exact. No /// model of Metal's datapath tried fits. - /// - An sRGB sum of an argument-buffer (heap) element, whose format is never known: Metal - /// decodes each tap's code through its twelve-bit table and sums the steps exactly; the - /// emulation sums the device's decoded values in `f32`, which Vulkan does not bound - /// ([`PrecisionNote::SrgbTexelDecode`]). A texture slot bound in an 8-bit sRGB format reads - /// the raw codes under its `SrgbTexture` variant and sums the steps exactly as Metal does, - /// on the grids `1/4095` (color) and `1/(16 · 255)` (alpha), so only the first bullet's - /// 2D residue applies to it. The packed normalized formats and `Depth16Unorm` sum in `f32` - /// (their exact rule is not measured). + /// - An sRGB sum: Metal decodes each tap's code through its twelve-bit table and sums the + /// steps exactly; the emulation sums the device's decoded taps in `f32`, the device's decode + /// being the only form where it samples the format ([`PrecisionNote::SrgbTexelDecode`]). A + /// texture slot bound in an 8-bit sRGB format the device holds as its UNORM twin decodes the + /// codes under its `SrgbTexture` variant and sums the steps exactly as Metal does, on the + /// grids `1/4095` (color) and `1/(16 · 255)` (alpha), so only the first bullet's 2D residue + /// applies to it. The packed normalized formats and `Depth16Unorm` sum in `f32` (their exact + /// rule is not measured). /// /// The footprint, the fraction, the addressing of each tap, the filter each format selects, /// the weights, each format's clamp and rounding, and the non-finite results are Metal's, but @@ -903,8 +903,8 @@ pub enum PrecisionNote { /// texel to `half` by the bound format: measured for the 32-bit float, half-float, and 8- and /// 16-bit normalized formats, which a texture slot converts exactly by its `TexelFormat` /// specialization (`metal::texel_format`); a read, nearest sample, or gather of a slot bound in - /// an 8-bit sRGB format decodes the raw code exactly instead, and a bicubic sample sums the - /// raw codes' steps exactly, under the slot's `SrgbTexture` variant, + /// an 8-bit sRGB format the device holds as its UNORM twin decodes the code exactly instead, + /// and a bicubic sample sums the codes' steps exactly, under the slot's `SrgbTexture` variant, /// and records nothing. A texture buffer converts by its bound format the same way (Metal reads /// a texture buffer's texels as a texture's: the P2a probe). A texture bound in another format /// (sRGB otherwise, packed, depth, and the rest) and a heap element keep the exact rounding of @@ -949,27 +949,36 @@ pub enum PrecisionNote { HalfSampleFilter, /// The module reads, samples, or gathers a texture with a `half` or `float` result through /// the device's sRGB decode, or decodes the device's filter of its codes, where the texture may - /// be bound in an 8-bit sRGB format. Metal - /// decodes such a texel's color channels through its twelve-bit table (`k / 4095` for the - /// code's step `k`) and its alpha as `c / 255`, which the device's decode (Vulkan's transfer - /// function, within its precision rules) does not reproduce. A texture slot the shape binds in - /// such a format (`metal::texel_format::srgb_raw`) joins the plan's variant - /// (`RuntimeFact::SrgbTexture`), under which its reads, nearest samples (a constexpr sampler - /// with nearest filters, no mip filter or a nearest one, no anisotropy, and weighted-average - /// reduction), pixel-coordinate fetches, and gathers (a `float` one's where the device does not - /// sample through Metal's own sampler) decode the raw code exactly as Metal does, and its - /// bicubic samples sum the raw codes' steps exactly as Metal does. Recorded where an access - /// keeps the device's decode on a device that does not sample through Metal's own sampler: - /// under that variant, a filtered sample of the slot (a linear filter, a linear mip filter, - /// anisotropy, or a runtime sampler, whose filter is not known when the function compiles); - /// and any such access of an argument-buffer (heap) element, whose format is never known. On a device that does (`VkProperty::MetalSampler`: MoltenVK on - /// Apple's GPU) the device's decode is Metal's, and the module requires the property instead. + /// be bound in an 8-bit sRGB format (`metal::texel_format::srgb_coded`: the 8-bit sRGB formats + /// and the sRGB forms of BC1 to BC3, BC7, PVRTC, ETC2, EAC and ASTC). Metal decodes such a + /// texel's color channels through its twelve-bit table (`k / 4095` for the code's step `k`) + /// and its alpha as `c / 255`, and its filters sum the decoded steps. Wherever the device + /// samples the format, its decode is the only form: the slot's view is an sRGB view of the + /// image (an `R8G8B8A8_SRGB` view of a decoded twin's codes where the device lacks a + /// compressed format), and a read, sample, gather, bicubic tap or input-attachment read takes + /// the device's value, Vulkan's sRGB EOTF applied before filtering (the specification sets no + /// precision for it). Recorded under the bound format's class (`BicubicTexels::SRGB`, a test + /// of `SpecKey::BoundTexelFormat` the runtime reads at a draw or dispatch binding such a + /// texture), outright for an argument-buffer (heap) element, whose format is never known, + /// and at the pipeline for a `float` input attachment whose color attachment is an sRGB format + /// (`StageIo::decoded_fetches`). On a device that samples through Metal's own texture unit + /// (`VkProperty::MetalSampler`: MoltenVK on Apple's GPU) the device's decode is Metal's, and + /// the module requires the property instead. Measured over every code of `RGBA8Unorm_sRGB` + /// (`runtime_lane::srgb_decode`): MoltenVK on an Apple M3 Max decodes each as Metal does, bit + /// for bit; lavapipe (LLVM 21.1.8, arm64) each color code within 5.25 table steps (0.00128, a + /// third of a code's `1/255`) of Metal's value, alpha within one `f32` ulp; other devices are + /// not measured. + /// /// Where the device cannot sample the bound format, whose texture it holds as the format's - /// UNORM twin (`LoweringInputs::srgb_twins`), such an access samples the twin's codes and - /// decodes the device's filtered value through the table: Metal's value where the filter reads - /// one texel (a nearest sampler's), Metal's sum where it blends two adjacent codes, otherwise - /// the decode of the codes' blend, where Metal blends the decoded texels; recorded on every - /// device under that variant. Validation derives no tolerance from it: the class is unbounded. + /// UNORM twin (`metal::texel_format::srgb_twin_on`: `R8Unorm_sRGB` and `RG8Unorm_sRGB` on + /// lavapipe, `RG8Unorm_sRGB` on ANV and NVIDIA among the committed profiles), the slot's + /// `SrgbTexture` variant decodes the twin's codes through the table: a read, a nearest sample, + /// a pixel-coordinate fetch, a gather and a bicubic tap exactly, recording nothing; a filtered + /// sample (a linear filter, a linear mip filter, anisotropy, or a runtime sampler) decodes the + /// device's filter of the codes, Metal's value where the filter reads one texel, Metal's sum + /// where it blends two adjacent codes, otherwise the decode of the codes' blend where Metal + /// blends the decoded texels, recorded on every device. Validation derives no tolerance from + /// it: the class is unbounded. SrgbTexelDecode, /// The module samples a texture with a `float` result through a filter that Metal's own /// sampler (`VkProperty::MetalSampler`, MoltenVK) answers otherwise than Metal filters the diff --git a/crates/metal2vulkan/src/pipeline/color_writes.rs b/crates/metal2vulkan/src/pipeline/color_writes.rs index 8101844c0..8da473d28 100644 --- a/crates/metal2vulkan/src/pipeline/color_writes.rs +++ b/crates/metal2vulkan/src/pipeline/color_writes.rs @@ -179,7 +179,10 @@ fn metal_color_writes(p: &DeviceProfile) -> bool { /// `StageIo::half_fast_colors` stores some channel ([`stores_output`]), and /// `PrecisionNote::CoverageReadsRoundedAlpha` where the pipeline covers by alpha /// (`alpha_to_coverage`, `GraphicsState::alpha_to_coverage`) and the function rounds that alpha to -/// nearest even ([`rounds_coverage_alpha`]). Each sorted, each entry once. +/// nearest even ([`rounds_coverage_alpha`]), and `PrecisionNote::SrgbTexelDecode` where an +/// attachment of `StageIo::decoded_fetches` has an sRGB format: the device's sRGB decode of the +/// input attachment, where Metal decodes the bytes through its twelve-bit table. Each sorted, each +/// entry once. pub(crate) fn pipeline_writes( a: &FunctionArtifact, colors: &[Option], @@ -216,6 +219,16 @@ pub(crate) fn pipeline_writes( if a.interface.io.half_fast_colors.iter().any(stored) { insert(&mut notes, PrecisionNote::HalfOutputFastMathBlend); } + let srgb = |c: &u32| { + attachment(c).is_some_and(|s| { + s.format + .block() + .is_some_and(|b| b.color == Some(crate::vk::NumericFormat::Srgb)) + }) + }; + if a.interface.io.decoded_fetches.iter().any(srgb) { + insert(&mut notes, PrecisionNote::SrgbTexelDecode); + } (notes, rounded) } @@ -330,7 +343,6 @@ pub(crate) fn check( if writes_hold(fragment, colors, (alpha_to_coverage, rounding), p) && wanted_extended_range(fragment, colors, rounding) == io.extended_range_colors && wanted_word_colors(fragment, colors, alpha_to_coverage, p) == io.word_colors - && wanted_srgb_fetches(fragment, colors) == io.srgb_fetches && wanted_rotated(fragment, colors, p) == io.rotated_colors && wanted_alpha_in_red(fragment, colors, p) == io.alpha_in_red_colors && wanted_rotated_factors(fragment, colors, p) == io.rotated_factors @@ -345,41 +357,6 @@ pub(crate) fn check( } } -/// Whether a fetched color attachment of `pf` is read through Metal's decode of its bytes -/// (`LoweringInputs::srgb_fetches`): `RGBA8Unorm_sRGB` and `BGRA8Unorm_sRGB`, whose fetch our -/// probes measured. The one- and two-channel sRGB formats' are not. -pub fn srgb_fetched(pf: metal::PixelFormat) -> bool { - matches!( - pf, - metal::PixelFormat::RGBA8UnormSRGB | metal::PixelFormat::BGRA8UnormSRGB - ) -} - -/// The input attachments `fragment` reads whose pixel format in `colors` takes Metal's decode -/// ([`srgb_fetched`]): the set the function must have compiled under -/// (`StageIo::srgb_fetches`). -pub(crate) fn wanted_srgb_fetches( - fragment: &FunctionArtifact, - colors: &[Option], -) -> BTreeSet { - fragment - .interface - .descriptors - .iter() - .filter_map(|d| match d.slot.kind { - crate::pipeline::sym::ResourceKind::InputAttachment(color) => Some(color), - _ => None, - }) - .filter(|&c| { - colors - .get(c as usize) - .copied() - .flatten() - .is_some_and(|a| srgb_fetched(a.pixel_format)) - }) - .collect() -} - /// The extended-range color attachments of a render pipeline whose color attachments are /// `colors` and whose `textureWriteRoundingMode` is `rounding`, by color index /// (`LoweringInputs::extended_range_colors`): every attachment of one of Apple's extended-range diff --git a/crates/metal2vulkan/src/pipeline/compile.rs b/crates/metal2vulkan/src/pipeline/compile.rs index 19ad4ced1..18754e039 100644 --- a/crates/metal2vulkan/src/pipeline/compile.rs +++ b/crates/metal2vulkan/src/pipeline/compile.rs @@ -1953,36 +1953,6 @@ pub(crate) fn kernel_inputs_read( }) } -/// The color attachments the specialized fragment entry `spec` reads (`[[color(n)]]`) whose -/// pixel format in `colors` is `RGBA8Unorm_sRGB` or `BGRA8Unorm_sRGB` -/// (`LoweringInputs::srgb_fetches`). Empty for any other stage. -pub(crate) fn srgb_fetches( - spec: &air::Entry, - colors: &[Option], -) -> BTreeSet { - if !matches!(spec.ep.stage, AbiStage::Fragment { .. }) { - return BTreeSet::new(); - } - spec.ep - .params - .iter() - .filter_map(|b| match b.role { - ParamRole::ColorInput { - index: AbiInt::Const(color), - .. - } => Some(color), - _ => None, - }) - .filter(|&c| { - colors - .get(c as usize) - .copied() - .flatten() - .is_some_and(|a| crate::pipeline::color_writes::srgb_fetched(a.pixel_format)) - }) - .collect() -} - /// The color attachments the specialized fragment entry `spec` writes (an output of either /// dual-source index) whose pixel format in `colors` is a signed integer. Empty for any other /// stage. @@ -2324,7 +2294,6 @@ fn lower_inputs( out.unattached_colors = unattached_colors_written(spec, d.color_attachments, d.alpha_to_coverage); out.framebuffer_fetch = fetch_inputs(spec, d, variant, p); - out.srgb_fetches = srgb_fetches(spec, d.color_attachments); let read = raw_indices_read(spec); out.viewport_index_varying = written.viewport && read.viewport; out.render_target_array_index_varying = written.layer && read.layer; diff --git a/crates/metal2vulkan/src/pipeline/compile/key.rs b/crates/metal2vulkan/src/pipeline/compile/key.rs index 08f06ce11..c735b942a 100644 --- a/crates/metal2vulkan/src/pipeline/compile/key.rs +++ b/crates/metal2vulkan/src/pipeline/compile/key.rs @@ -204,11 +204,6 @@ pub fn function_key( .bytes(format!("{:?}", inputs.srgb_textures).as_bytes()); } // Appended only when set, as `storage_view_slots`. - if !inputs.srgb_twins.is_empty() { - h.bytes(b"srgb-twins") - .bytes(format!("{:?}", inputs.srgb_twins).as_bytes()); - } - // Appended only when set, as `storage_view_slots`. if !inputs.snapshot_textures.is_empty() { h.bytes(b"snapshot-textures") .bytes(format!("{:?}", inputs.snapshot_textures).as_bytes()); @@ -234,11 +229,6 @@ pub fn function_key( .bytes(format!("{:?}", inputs.word_colors).as_bytes()); } // Appended only when set, as `storage_view_slots`. - if !inputs.srgb_fetches.is_empty() { - h.bytes(b"srgb-fetches") - .bytes(format!("{:?}", inputs.srgb_fetches).as_bytes()); - } - // Appended only when set, as `storage_view_slots`. if !inputs.rotated_colors.is_empty() { h.bytes(b"rotated-colors") .bytes(format!("{:?}", inputs.rotated_colors).as_bytes()); diff --git a/crates/metal2vulkan/src/pipeline/compile/tests.rs b/crates/metal2vulkan/src/pipeline/compile/tests.rs index ba51df6d3..6ed5134db 100644 --- a/crates/metal2vulkan/src/pipeline/compile/tests.rs +++ b/crates/metal2vulkan/src/pipeline/compile/tests.rs @@ -701,7 +701,6 @@ fn the_inputs_encoding_is_the_earlier_derived_debug() { .replace(", merged_draws: false", "") .replace(", framebuffer_fetch: None", "") .replace(", srgb_textures: {}", "") - .replace(", srgb_twins: {}", "") .replace(", snapshot_textures: {}", "") .replace(", ycbcr_in_place: {}", "") .replace(", viewport_index_varying: false", "") @@ -721,7 +720,6 @@ fn the_inputs_encoding_is_the_earlier_derived_debug() { .replace(", extended_range: {}", "") .replace(", extended_range_colors: {}", "") .replace(", word_colors: {}", "") - .replace(", srgb_fetches: {}", "") .replace(", zeroed_colors: {}", "") .replace(", dropped_colors: {}", "") .replace(", kept_imageblock_bytes: None", "") diff --git a/crates/metal2vulkan/src/pipeline/facts.rs b/crates/metal2vulkan/src/pipeline/facts.rs index 2b354742d..1a0aec92b 100644 --- a/crates/metal2vulkan/src/pipeline/facts.rs +++ b/crates/metal2vulkan/src/pipeline/facts.rs @@ -293,17 +293,14 @@ pub enum RuntimeFact { /// 8-bit sRGB slot's raw read, a fetched gather and a NaN texel's rule (the NaN switch) read /// it too. TexelFormat { slot: SlotRef }, - /// The function reads, samples, or gathers the texture bound to the slot in a form whose - /// result Metal takes from the raw code of an 8-bit sRGB texel, decoded through its - /// twelve-bit table (a read, a nearest sample, or a pixel-coordinate fetch with a `half` or - /// `float` result, and a gather with a `half` result; `metal::texel_format`), which the - /// device's decode does not reproduce. Bound in such a format - /// (`metal::texel_format::srgb_raw`), the slot joins the plan's variant - /// (`VariantKey::srgb_textures`, `LoweringInputs::srgb_textures`), under which the function - /// reads those texels through a UNORM view of the same image: the slot's - /// `ResourceKind::RawTexture` binding and its combined bindings with - /// `CombinedSampler::raw`. Bound in any other format, or unbound, the slot leaves the variant, - /// and the function reads the texture's own view. + /// The function reads, samples, or gathers the texture bound to the slot with a `half` or + /// `float` result, which an 8-bit sRGB format bound there would decode. Bound in such a + /// format that the device cannot sample, which the runtime holds as the format's UNORM twin + /// (`metal::format::srgb_raw_twin`, `metal::texel_format::srgb_twin_on`), the slot joins the + /// plan's variant (`VariantKey::srgb_textures`, `LoweringInputs::srgb_textures`), under which + /// the function decodes the codes its own binding reads through Metal's twelve-bit table. + /// Bound in any other format, or unbound, the slot leaves the variant, and the function reads + /// the device's decode through the texture's own view. SrgbTexture { slot: SlotRef }, /// A `ulong` atomic (`atomic_{min,max}`) updates the `ulong` texture bound to the slot, so the /// slot is declared as an `R64ui` storage image: the binder views the bound `RG32Uint` texture @@ -430,15 +427,6 @@ pub enum RuntimeFact { /// after the command buffer reports its execution as failed, since none of its results is then /// Metal's. A run that never reaches such a read is Metal's exactly. Nothing binds it. AbsentArgumentRead { stage: Stage }, - /// Under its `SrgbTexture` variant (`LoweringInputs::srgb_textures`), the function still - /// decodes texels of the 8-bit sRGB texture bound to the slot through the device's sampled - /// view, in a form the raw codes do not serve (a `float` gather on Metal's own sampler, a - /// linear mip filter, a runtime sampler's sample; `PrecisionNote::SrgbTexelDecode`). Where the - /// device cannot sample the bound sRGB format, whose texture it holds as the format's UNORM - /// twin, the slot's own binding takes the twin's view, and the plan's variant names the slot - /// in `VariantKey::srgb_twins`, under which the function decodes what the device samples - /// there; without the fact that binding serves queries alone. - SrgbDeviceDecode { slot: SlotRef }, /// The fragment function was compiled under `VariantKey::zeroed_colors` /// (`LoweringInputs::zeroed_colors`): it writes zero to color attachment `color`, of pixel /// format `format`, which its Metal pipeline lacks and the pass has, as plain Metal stores diff --git a/crates/metal2vulkan/src/pipeline/layout.rs b/crates/metal2vulkan/src/pipeline/layout.rs index 781ee4095..b4aa606a4 100644 --- a/crates/metal2vulkan/src/pipeline/layout.rs +++ b/crates/metal2vulkan/src/pipeline/layout.rs @@ -125,10 +125,6 @@ pub enum BindingSource { stage: Stage, sampler: CombinedSampler, }, - /// The raw view of the texture bound at a Metal `[[texture(n)]]` slot: a sampled image of the - /// same image in the UNORM format of its channels, which reads an 8-bit sRGB texture's raw - /// codes (`RuntimeFact::SrgbTexture`). - RawTexture(SlotRef), /// The `half` shadow of the extended-range color attachment of this color index that the /// draw's render pass instance holds (`ResourceKind::ExtendedShadow`), bound as a storage /// image. diff --git a/crates/metal2vulkan/src/pipeline/link.rs b/crates/metal2vulkan/src/pipeline/link.rs index eb0d1d5b0..5b868de89 100644 --- a/crates/metal2vulkan/src/pipeline/link.rs +++ b/crates/metal2vulkan/src/pipeline/link.rs @@ -679,7 +679,6 @@ fn binding_source(slot: ResourceSlot) -> BindingSource { stage: slot.stage, sampler: CombinedSampler::from_heap_index(sampler, slot.index), }, - ResourceKind::RawTexture => BindingSource::RawTexture(metal(SlotClass::Texture)), ResourceKind::ExtendedShadow(color) => BindingSource::ExtendedShadow(color), ResourceKind::SnapshotTexels(texture) => BindingSource::SnapshotTexels(texture), } diff --git a/crates/metal2vulkan/src/pipeline/lower_inputs.rs b/crates/metal2vulkan/src/pipeline/lower_inputs.rs index 1b99421e7..7dc80c78a 100644 --- a/crates/metal2vulkan/src/pipeline/lower_inputs.rs +++ b/crates/metal2vulkan/src/pipeline/lower_inputs.rs @@ -143,21 +143,17 @@ pub struct LoweringInputs { /// function. #[cfg_attr(feature = "serde", serde(default))] pub framebuffer_fetch: Option, - /// Texture slots bound in an 8-bit sRGB format whose raw codes the function reads - /// (`VariantKey::srgb_textures`, `RuntimeFact::SrgbTexture`): each such slot's reads, nearest - /// samples, and gathers whose result Metal decodes from the raw code read a UNORM view of the - /// same image (`ResourceKind::RawTexture`, `CombinedSampler::raw`) and decode it through - /// Metal's twelve-bit table. A slot of no such access is ignored. - #[cfg_attr(feature = "serde", serde(default))] - pub srgb_textures: BTreeSet, - /// Slots of `srgb_textures` bound to a texture held as its 8-bit sRGB format's UNORM twin, a - /// format the device cannot sample (`VariantKey::srgb_twins`): each access the raw codes do - /// not serve exactly, which elsewhere keeps the device's decode, samples the twin through the - /// slot's own binding and decodes the device's filtered codes - /// (`PrecisionNote::SrgbTexelDecode`): exactly where the filter reads one texel. A slot of no + /// Texture slots bound to an 8-bit sRGB texture the device cannot sample, which the runtime + /// holds as the format's UNORM twin, whose views read the codes (`VariantKey::srgb_textures`, + /// `RuntimeFact::SrgbTexture`): each `half` or `float` access of such a slot decodes what its + /// own binding reads through Metal's twelve-bit table. A read, a nearest sample, a + /// pixel-coordinate fetch and a gather (a `float` one's where the device does not sample + /// through Metal's own sampler) read one texel's codes and decode them exactly, and a bicubic + /// sample sums their steps exactly; any other access decodes the device's filter of the codes + /// (`PrecisionNote::SrgbTexelDecode`), exactly where the filter reads one texel. A slot of no /// such access is ignored. #[cfg_attr(feature = "serde", serde(default))] - pub srgb_twins: BTreeSet, + pub srgb_textures: BTreeSet, /// Fragment texture slots of `StageInterface::snapshot_textures` the draw reads through a /// snapshot (`VariantKey::snapshot_textures`), each with its snapshot's form, drawn twice /// (`PushField::SnapshotPhase`). The entry opens with the ordered pixel interlock's critical @@ -441,18 +437,6 @@ pub struct LoweringInputs { /// compiled under another map as `NeedsInput(ColorWrites)`. Empty for any other function. #[cfg_attr(feature = "serde", serde(default))] pub word_colors: BTreeMap, - /// The color attachments the fragment function reads (`[[color(n)]]`) that its render - /// pipeline gives an 8-bit four-channel sRGB format (`RGBA8Unorm_sRGB`, `BGRA8Unorm_sRGB`), - /// by color index. Read through an input attachment, such an attachment's value is the - /// device's decode, which is not Metal's: the function snaps it back to its byte (Metal's - /// encode, which every byte's exact decode lands on) and decodes that byte by Metal's table - /// (`math::pack` and `math::unpack` of `unorm4x8_srgb`). The storage form decodes its bytes - /// itself and takes nothing from this. `Device::compile_render_pipeline` sets it for a - /// `Function` fragment stage from the pipeline's color attachments, and link refuses a - /// fragment compiled under another set than the pipeline's as `NeedsInput(ColorWrites)`. - /// Empty for any other function. - #[cfg_attr(feature = "serde", serde(default))] - pub srgb_fetches: BTreeSet, /// Color attachments of the pass the fragment function's render pipeline has no pixel /// format for, the pass's pixel format of each by color index /// (`VariantKey::zeroed_colors`): plain Metal stores zero bytes into each at every sample a diff --git a/crates/metal2vulkan/src/pipeline/stage_io.rs b/crates/metal2vulkan/src/pipeline/stage_io.rs index e01c06b38..70fe502c0 100644 --- a/crates/metal2vulkan/src/pipeline/stage_io.rs +++ b/crates/metal2vulkan/src/pipeline/stage_io.rs @@ -219,12 +219,14 @@ pub struct StageIo { /// (`NeedsInput(ColorWrites)`). #[cfg_attr(feature = "serde", serde(default))] pub word_colors: BTreeMap, - /// The input attachments the fragment function reads through Metal's decode of their bytes - /// (`LoweringInputs::srgb_fetches`): each read snaps the device's sRGB decode back to its - /// byte and decodes that by Metal's table. Link refuses a stage compiled for another set - /// than the pipeline's (`NeedsInput(ColorWrites)`). + /// The input attachments the fragment function reads as `float` texels through the device's + /// decode, on a device that does not decode through Metal's own texture unit (without + /// `VkProperty::MetalSampler`): a render pipeline whose attachment there has an 8-bit sRGB + /// format records `PrecisionNote::SrgbTexelDecode` for the stage + /// (`color_writes::pipeline_writes`), the device's sRGB decode standing for Metal's + /// twelve-bit table. #[cfg_attr(feature = "serde", serde(default))] - pub srgb_fetches: std::collections::BTreeSet, + pub decoded_fetches: std::collections::BTreeSet, /// The attachments held with their channels rotated (`LoweringInputs::rotated_colors`) that /// the fragment function writes through an output variable of either dual-source index, by /// color index: each such output stores Metal's channels rotated diff --git a/crates/metal2vulkan/src/pipeline/sym.rs b/crates/metal2vulkan/src/pipeline/sym.rs index 1bd797c7e..a4279e25c 100644 --- a/crates/metal2vulkan/src/pipeline/sym.rs +++ b/crates/metal2vulkan/src/pipeline/sym.rs @@ -427,10 +427,6 @@ pub enum ResourceKind { /// constexpr sampler is the binding's immutable sampler. `ResourceSlot::index` is the use /// ([`ResourceSlot::separate_sampler`]), as a heap sampler's is. SeparateSampler(SamplerRef), - /// The raw view of the texture bound at the stage's texture slot `ResourceSlot::index`: a - /// sampled image viewing the same image in the UNORM format of its channels, from which a - /// function reads the raw codes of an 8-bit sRGB texture (`RuntimeFact::SrgbTexture`). - RawTexture, /// The `half` shadow of extended-range color attachment `n` (`ResourceSlot::index` too) for /// the draw's render pass instance (`VariantKey::extended_shadows`): an `RGBA16_SFLOAT` 2D /// storage image of the attachment's extent holding Metal's tile value of each texel, which @@ -485,7 +481,7 @@ impl SamplerRef { /// How a combined image sampler samples: its sampler, and the use facts that change or check the /// `VkSampler` (`metal::sampler::SamplerUse`): depth comparison, which is static in AIR, whether /// the texture is an integer one (integer border colors), whether it samples a cube with explicit -/// gradients (no anisotropy), and whether it samples the texture's raw view. +/// gradients (no anisotropy). #[non_exhaustive] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] @@ -501,23 +497,17 @@ pub struct CombinedSampler { /// for it (`metal::sampler::SamplerUse::cube_gradient`). Elsewhere a sampler's footprint /// follows its anisotropy. pub cube_gradient: bool, - /// The binding samples the texture's raw view, the UNORM format of its channels, from which - /// the function reads an 8-bit sRGB texture's raw codes (`RuntimeFact::SrgbTexture`): - /// another binding than the one of the texture's own view through the same sampler. - #[cfg_attr(feature = "serde", serde(default))] - pub raw: bool, } impl CombinedSampler { /// Sampler `sampler` used with `compare` on a texture that is `integer` or not, without - /// explicit cube gradients, through the texture's own view. + /// explicit cube gradients. pub fn new(sampler: SamplerRef, compare: bool, integer: bool) -> CombinedSampler { CombinedSampler { sampler, compare, integer, cube_gradient: false, - raw: false, } } @@ -529,11 +519,6 @@ impl CombinedSampler { } } - /// The same use through the texture's raw view when `raw` ([`CombinedSampler::raw`]). - pub fn with_raw(self, raw: bool) -> CombinedSampler { - CombinedSampler { raw, ..self } - } - /// The use as a heap sampler symbol's index, or a separate sampler's: bit 0 comparison, bit 1 /// an integer texel, bit 2 explicit cube gradients. pub fn heap_index(&self) -> u32 { @@ -550,27 +535,18 @@ impl CombinedSampler { } /// The use's rank in a separate texture symbol's index: comparison, then an integer texel, then - /// explicit cube gradients, then the raw view, from the most significant bit down, so the ranks - /// order as the uses' fields do in `CombinedSampler`'s derived order. + /// explicit cube gradients, from the most significant bit down, so the ranks order as the + /// uses' fields do in `CombinedSampler`'s derived order. fn use_rank(&self) -> u32 { - (u32::from(self.compare) << 3) - | (u32::from(self.integer) << 2) - | (u32::from(self.cube_gradient) << 1) - | u32::from(self.raw) + (u32::from(self.compare) << 2) + | (u32::from(self.integer) << 1) + | u32::from(self.cube_gradient) } /// Sampler `sampler` with the use of rank `rank` ([`CombinedSampler::use_rank`]). fn from_use_rank(sampler: SamplerRef, rank: u32) -> CombinedSampler { - CombinedSampler::new(sampler, rank & 8 != 0, rank & 4 != 0) - .with_cube_gradient(rank & 2 != 0) - .with_raw(rank & 1 != 0) - } - - /// The use a separate sampler binding serves: this one through the texture's own view. A raw - /// view is another sampled image of the same texture, sampled through the same sampler, so a - /// raw separate texture shares its use's separate sampler. - pub fn sampler_binding_use(self) -> CombinedSampler { - self.with_raw(false) + CombinedSampler::new(sampler, rank & 4 != 0, rank & 2 != 0) + .with_cube_gradient(rank & 1 != 0) } /// The use the binder (and link, for a constexpr sampler) builds the `VkSampler` for. @@ -1200,12 +1176,10 @@ mod tests { ); } - /// A separate texture's symbol round-trips its texture slot, sampler, and use, the raw view - /// included, and the symbols order as the `CombinedTextureSampler` symbols they stand for (by - /// sampler, use, and slot), so link numbers the bindings of both forms alike. A raw view's - /// texture and its own view's are two symbols, sampled through one separate sampler. A slot - /// past the index's 28 bits has no symbol; canonicalization refuses every slot past Metal's 128 - /// entries first. + /// A separate texture's symbol round-trips its texture slot, sampler, and use, and the symbols + /// order as the `CombinedTextureSampler` symbols they stand for (by sampler, use, and slot), so + /// link numbers the bindings of both forms alike. A slot past the index's 28 bits has no + /// symbol; canonicalization refuses every slot past Metal's 128 entries first. #[test] fn separate_texture_symbols_round_trip_in_the_combined_order() { let mut pairs = Vec::new(); @@ -1217,19 +1191,13 @@ mod tests { ] { for compare in [false, true] { for integer in [false, true] { - for (cube_gradient, raw) in - [(false, false), (false, true), (true, false), (true, true)] - { + for cube_gradient in [false, true] { let c = CombinedSampler::new(sampler, compare, integer) - .with_cube_gradient(cube_gradient) - .with_raw(raw); - // A raw view samples through its use's separate sampler. - let own = c.sampler_binding_use(); - assert!(!own.raw && own.with_raw(raw) == c); + .with_cube_gradient(cube_gradient); assert_eq!( - ResourceSlot::separate_sampler(Stage::Fragment, own) + ResourceSlot::separate_sampler(Stage::Fragment, c) .separate_sampler_use(), - Some(own) + Some(c) ); for texture in [0, 1, 127, (1 << 28) - 1] { let s = ResourceSlot::separate_texture(Stage::Fragment, texture, c) diff --git a/crates/metal2vulkan/src/spirv/requirements/own_pixel.rs b/crates/metal2vulkan/src/spirv/requirements/own_pixel.rs index e1884843d..1f269d4b1 100644 --- a/crates/metal2vulkan/src/spirv/requirements/own_pixel.rs +++ b/crates/metal2vulkan/src/spirv/requirements/own_pixel.rs @@ -34,8 +34,8 @@ //! pixel where the pass has no fragment shading rate or density map. //! //! The test is structural and exact, never a name: a slot qualifies only where every use of each -//! of its bindings (the texture's own, a combined image sampler's or a separate image's of it, its -//! raw view) is one of the operations above, a size, level or sample-count query, which reads no +//! of its bindings (the texture's own, a combined image sampler's or a separate image's of it) +//! is one of the operations above, a size, level or sample-count query, which reads no //! texel, or a load, `OpSampledImage`, `OpImage` or copy that carries the image on to those. A //! coordinate is traced through copies, bitcasts and conversions between integers of at least 16 //! bits, extracts, shuffles and constructs, and the steps above. Anything else on the way (other @@ -118,9 +118,9 @@ pub fn own_pixel_textures(m: &TypedModule, meter: &mut Meter) -> Result } GlobalKind::Resource(slot) => { let texture = match slot.kind { - ResourceKind::Texture - | ResourceKind::RawTexture - | ResourceKind::CombinedTextureSampler(_) => Some(slot.index), + ResourceKind::Texture | ResourceKind::CombinedTextureSampler(_) => { + Some(slot.index) + } ResourceKind::SeparateTexture(_) => slot.separate_texture_of().map(|(t, _)| t), _ => None, }; diff --git a/crates/metal2vulkan/src/spirv/requirements/snapshot.rs b/crates/metal2vulkan/src/spirv/requirements/snapshot.rs index 997a8cb51..252c3f7df 100644 --- a/crates/metal2vulkan/src/spirv/requirements/snapshot.rs +++ b/crates/metal2vulkan/src/spirv/requirements/snapshot.rs @@ -116,9 +116,7 @@ fn reach(m: &TypedModule, own: &[u32], n: usize) -> Result, Error> { for g in m.globals() { if let GlobalKind::Resource(slot) = &g.kind { let texture = match slot.kind { - ResourceKind::Texture - | ResourceKind::RawTexture - | ResourceKind::CombinedTextureSampler(_) => Some(slot.index), + ResourceKind::Texture | ResourceKind::CombinedTextureSampler(_) => Some(slot.index), ResourceKind::SeparateTexture(_) => slot.separate_texture_of().map(|(t, _)| t), _ => None, }; @@ -338,9 +336,7 @@ fn copies_alone(m: &TypedModule, slots: &[u32], n: usize) -> Result for g in m.globals() { if let GlobalKind::Resource(slot) = &g.kind { let texture = match slot.kind { - ResourceKind::Texture - | ResourceKind::RawTexture - | ResourceKind::CombinedTextureSampler(_) => Some(slot.index), + ResourceKind::Texture | ResourceKind::CombinedTextureSampler(_) => Some(slot.index), ResourceKind::SeparateTexture(_) => slot.separate_texture_of().map(|(t, _)| t), _ => None, }; diff --git a/crates/metal2vulkan/src/tests/engine_cross_class.rs b/crates/metal2vulkan/src/tests/engine_cross_class.rs index aa5deb56a..b735f4a9c 100644 --- a/crates/metal2vulkan/src/tests/engine_cross_class.rs +++ b/crates/metal2vulkan/src/tests/engine_cross_class.rs @@ -126,7 +126,7 @@ enum Access { } /// The words of a nearest constexpr sampler of normalized coordinates, every axis clamped to -/// its edge, no mip filter (`engine_srgb_raw`'s `sampler_words(0, 0, false)`). +/// its edge, no mip filter (`engine_srgb_decode`'s `sampler_words(0, 0, false)`). fn nearest_words() -> u64 { const BASE: u64 = 0x007b_ff00_0008_0000; let edge = 1; @@ -539,6 +539,12 @@ fn a_texture_of_another_class_joins_the_variant() { PixelFormat::RGBA8UnormSRGB, S::Float, ), + ( + Access::Gather, + Ty::Uint, + PixelFormat::RG8UnormSRGB, + S::Float, + ), ]; let mut planned = 0; for (access, ty, pf, class) in cases { @@ -571,10 +577,11 @@ fn a_texture_of_another_class_joins_the_variant() { BTreeMap::from([(TEXTURE, class)]), "{what}" ); - let srgb = pf == PixelFormat::RGBA8UnormSRGB; + // Only a format the device holds as its UNORM twin joins the sRGB variant. + let twin = crate::metal::texel_format::srgb_twin_on(pf, dev.profile()); assert_eq!( plan.variant.srgb_textures.contains(&TEXTURE), - srgb, + twin, "{what}" ); let key = plan.variant.lowering_inputs(Stage::Kernel); @@ -589,25 +596,16 @@ fn a_texture_of_another_class_joins_the_variant() { again.diagnostics ); let view = view_format(&again).unwrap_or_else(|| panic!("{what}: no view")); + // Every access views the texture's own format, an sRGB one's decoding its codes; a + // format held as its UNORM twin, the twin's. let usages = [crate::device::FormatUsage::SampledImage].into(); - let own = crate::metal::format::vk_format(pf, &usages, dev.profile()) + let held = match twin { + true => crate::metal::format::srgb_raw_twin(pf).expect("a twin"), + false => pf, + }; + let want = crate::metal::format::vk_format(held, &usages, dev.profile()) .expect("the format") .format; - // Under the sRGB variant a gather reads the raw view and decodes each code through - // Metal's table where the device's sampler is not Metal's own, whose gather already - // decodes so; every other access here views the texture's own format. - let metal = dev - .profile() - .fields() - .enabled - .properties - .contains(&crate::device::requirements::VkProperty::MetalSampler); - let want = match (srgb, access) { - (true, Access::Gather) if !metal => { - crate::metal::texel_format::srgb_raw_view(own).expect("a raw view") - } - _ => own, - }; assert_eq!(view, want, "{what}"); planned += 1; // A texture of the declared class leaves the variant. diff --git a/crates/metal2vulkan/src/tests/engine_fragment.rs b/crates/metal2vulkan/src/tests/engine_fragment.rs index 4750a672a..42d06178d 100644 --- a/crates/metal2vulkan/src/tests/engine_fragment.rs +++ b/crates/metal2vulkan/src/tests/engine_fragment.rs @@ -605,15 +605,30 @@ fn framebuffer_fetch_reads_in_an_ordered_form_where_the_device_has_one() { assert!(forms.iter().all(|&n| n > 0), "{forms:?}"); } +/// Whether module `words` holds a constant composite of 256 or more constituents: Metal's sRGB +/// table (`lower::arith::srgb::declare`), which no other initializer of these fixtures reaches. +pub(super) fn holds_srgb_table(words: &[u32]) -> bool { + const CONSTANT_COMPOSITE: u32 = 44; + let mut at = 5; + while let Some(&first) = words.get(at) { + let count = (first >> 16) as usize; + if first & 0xffff == CONSTANT_COMPOSITE && count >= 3 + 256 { + return true; + } + at += count.max(1); + } + false +} + /// On a device that reads a fetched color through an input attachment (both lavapipes), an -/// `RGBA8Unorm_sRGB` or `BGRA8Unorm_sRGB` color the pipeline names (`LoweringInputs::srgb_fetches`) -/// is read through Metal's decode: the module holds Metal's sRGB table (256 words of initializer) -/// and the interface records the color; compiled without the input, the read is the device's, and -/// the interface records nothing. The render pipeline compile names the color from its attachments, -/// and a fragment compiled without the input is `NeedsInput(ColorWrites)` in that pipeline. Every -/// module passes L3. +/// `RGBA8Unorm_sRGB` or `BGRA8Unorm_sRGB` color reads the device's own decode through its input +/// attachment: the render pipeline's fragment module is the one an `RGBA8Unorm` attachment's +/// pipeline takes, word for word, holding no Metal sRGB table; the interface records the `float` +/// colors the device decodes (`StageIo::decoded_fetches`), and the pipeline notes +/// `PrecisionNote::SrgbTexelDecode` for the sRGB attachment alone. A fragment compiled alone links +/// into the sRGB pipeline exactly as into the `RGBA8Unorm` one. Every module passes L3. #[test] -fn an_srgb_input_attachment_is_read_through_metals_decode() { +fn an_srgb_input_attachment_reads_the_devices_decode() { let (Some(bc), Some(io)) = (fixture("fragment_fetch"), fixture("stage_io")) else { return; }; @@ -622,31 +637,20 @@ fn an_srgb_input_attachment_is_read_through_metals_decode() { if !p.fields().fragment.rasterization_order_color_access { continue; } - let mut inputs = LoweringInputs::new(); - inputs.srgb_fetches = std::collections::BTreeSet::from([0]); - let snapped = - compile_with(&bc, "fetch_blend", &p, &inputs).unwrap_or_else(|e| panic!("{stem}: {e}")); - link_and_validate(&snapped, &p).unwrap_or_else(|e| panic!("{stem}: L3: {e}")); let plain = compile_with(&bc, "fetch_blend", &p, &LoweringInputs::new()) .unwrap_or_else(|e| panic!("{stem}: {e}")); - assert_eq!(attachments(&snapped), [0, 1, 2], "{stem}"); + link_and_validate(&plain, &p).unwrap_or_else(|e| panic!("{stem}: L3: {e}")); + assert_eq!(attachments(&plain), [0, 1, 2], "{stem}"); assert_eq!( - snapped.interface.io.srgb_fetches, - std::collections::BTreeSet::from([0]), + plain.interface.io.decoded_fetches, + std::collections::BTreeSet::from([0, 2]), "{stem}" ); - assert!(plain.interface.io.srgb_fetches.is_empty(), "{stem}"); - // Metal's table: 256 words of initializer, and the encode and decode around the read. - assert!( - snapped.module.words.len() > plain.module.words.len() + 256, - "{stem}: {} words against {}", - snapped.module.words.len(), - plain.module.words.len() - ); + assert!(!holds_srgb_table(&plain.module.words), "{stem}"); checked += 1; } assert!(checked > 0, "no profile reads through input attachments"); - // The whole pipeline on `lavapipe`, and a fragment compiled without the input in it. + // The whole pipeline on `lavapipe`, and a fragment compiled alone in it. let path = Path::new(env!("CARGO_MANIFEST_DIR")) .join("../metal2vulkan-validation/profiles/lavapipe.json"); let text = std::fs::read_to_string(path).expect("profile"); @@ -660,20 +664,38 @@ fn an_srgb_input_attachment_is_read_through_metals_decode() { .expect("function"), ) }; - for pf in [PixelFormat::BGRA8UnormSRGB, PixelFormat::RGBA8UnormSRGB] { + let pipeline = |first: PixelFormat, fragment: StageSource| { let mut d = RenderPipelineDescriptor::new(StageSource::Function(function( &io, "stage_io_vertex_position", ))); - d.fragment = Some(StageSource::Function(function(&bc, "fetch_blend"))); - for (i, f) in [pf, PixelFormat::RGBA32Uint, PixelFormat::RG16Float] + d.fragment = Some(fragment); + for (i, f) in [first, PixelFormat::RGBA32Uint, PixelFormat::RG16Float] .into_iter() .enumerate() { d.color_attachments[i] = Some(ColorAttachmentDescriptor::new(f)); } dev.compile_render_pipeline(&d, &Budget::standard()) - .unwrap_or_else(|e| panic!("{pf:?}: {e}")); + }; + let fragment = || StageSource::Function(function(&bc, "fetch_blend")); + let linear = pipeline(PixelFormat::RGBA8Unorm, fragment()).expect("RGBA8Unorm"); + let linear_stage = &linear.stages[1]; + assert!(!linear_stage + .precision_notes + .contains(&PrecisionNote::SrgbTexelDecode)); + for pf in [PixelFormat::BGRA8UnormSRGB, PixelFormat::RGBA8UnormSRGB] { + let srgb = pipeline(pf, fragment()).unwrap_or_else(|e| panic!("{pf:?}: {e}")); + let stage = &srgb.stages[1]; + assert!(!holds_srgb_table(&stage.spirv), "{pf:?}"); + assert_eq!(stage.spirv, linear_stage.spirv, "{pf:?}"); + assert!( + stage + .precision_notes + .contains(&PrecisionNote::SrgbTexelDecode), + "{pf:?}: {:?}", + stage.precision_notes + ); let alone = dev .compile_function( &function(&bc, "fetch_blend"), @@ -681,12 +703,10 @@ fn an_srgb_input_attachment_is_read_through_metals_decode() { &Budget::standard(), ) .expect("the fragment alone"); - d.fragment = Some(StageSource::Compiled(alone)); - assert!( - matches!( - dev.compile_render_pipeline(&d, &Budget::standard()), - Err(Error::NeedsInput(RuntimeInput::ColorWrites)) - ), + // The sRGB attachment asks the fragment for nothing the `RGBA8Unorm` one does not. + assert_eq!( + pipeline(pf, StageSource::Compiled(alone.clone())).map(|_| ()), + pipeline(PixelFormat::RGBA8Unorm, StageSource::Compiled(alone)).map(|_| ()), "{pf:?}" ); } diff --git a/crates/metal2vulkan/src/tests/engine_image_shapes.rs b/crates/metal2vulkan/src/tests/engine_image_shapes.rs index 3b6b18fec..6fbd29586 100644 --- a/crates/metal2vulkan/src/tests/engine_image_shapes.rs +++ b/crates/metal2vulkan/src/tests/engine_image_shapes.rs @@ -14,7 +14,7 @@ //! The mapping, written out again here: 1D, 2D and 3D types are their dimension, an array type //! is arrayed, a multisample type is multisampled, a cube is a cube, a cube array an arrayed //! cube, and a texture buffer a buffer image. `ImageViewShape` makes a cube or a cube array an -//! arrayed 2D image in the slot's own binding and its raw view, which texel reads go through; a +//! arrayed 2D image in the slot's own binding, which texel reads go through; a //! combined image sampler's or a separate texture's binding samples, and keeps the cube. Each //! binding that holds a texture slot's image is checked. //! @@ -147,7 +147,7 @@ fn expected(texture_type: TextureType, cube_as_array: bool) -> Shape { /// texture slot's image. fn texture_slot(resource: &ResourceSlot) -> Option<(u32, bool)> { match resource.kind { - ResourceKind::Texture | ResourceKind::RawTexture => Some((resource.index, false)), + ResourceKind::Texture => Some((resource.index, false)), ResourceKind::CombinedTextureSampler(_) => Some((resource.index, true)), ResourceKind::SeparateTexture(_) => resource.separate_texture_of().map(|(t, _)| (t, true)), _ => None, diff --git a/crates/metal2vulkan/src/tests/engine_rgbx_storage.rs b/crates/metal2vulkan/src/tests/engine_rgbx_storage.rs index f97a40a12..a5567c09f 100644 --- a/crates/metal2vulkan/src/tests/engine_rgbx_storage.rs +++ b/crates/metal2vulkan/src/tests/engine_rgbx_storage.rs @@ -418,7 +418,7 @@ const SRGB: (vk::Format, StorageImageClass) = /// The `f32` bits a UNORM alias's image holds for code `c`: `c / 255` correctly rounded. fn unorm_bits(c: u32) -> u32 { - super::engine_srgb_raw::f32_bits(u64::from(c), 255) + super::engine_srgb_decode::f32_bits(u64::from(c), 255) } /// Metal's code of channel value `v` written to an 8-bit sRGB format, a color channel's @@ -487,7 +487,7 @@ fn srgb_values(color: bool, half: bool) -> Vec { /// answered `[3e1c98af, 3c0373b5, 3e8645bb, 3f800000]`. #[test] fn an_srgb_storage_read_is_metals_table() { - use super::engine_srgb_raw::{f32_bits, half_bits as ratio_half}; + use super::engine_srgb_decode::{f32_bits, half_bits as ratio_half}; use crate::lower::arith::srgb::SRGB_DECODE_STEPS; let mut ran = 0; for texel in [Texel::Float, Texel::Half] { diff --git a/crates/metal2vulkan/src/tests/engine_snapshot_exact.rs b/crates/metal2vulkan/src/tests/engine_snapshot_exact.rs index 17ad4634f..3146032d8 100644 --- a/crates/metal2vulkan/src/tests/engine_snapshot_exact.rs +++ b/crates/metal2vulkan/src/tests/engine_snapshot_exact.rs @@ -1,14 +1,13 @@ -//! A texture read through a snapshot at a slot whose reads may take a raw view beside its image. +//! A texture read through a snapshot at a slot whose reads may take any bound format. //! //! The copy that fills a snapshot (`lower::fragment`'s `snapshot`) fetches through one view, and -//! the read the snapshot stands for must be the fetch through that same view: the slot's raw view -//! where the slot's reads take the raw codes (an 8-bit sRGB texel's, whose view the binder names -//! the snapshot's form by), else the slot's own image. +//! the read the snapshot stands for must be the fetch through that same view: the slot's own image, +//! whose bound view the binder names the snapshot's form by. //! //! - Every form the binder can name for a `texture2d` slot — the bound //! view's codes, or the fetched lanes' bits — translates and passes L3, under the fast default -//! and under `exact_answers`. An 8-bit sRGB texture, whose codes the reads do take, keeps its -//! raw view on both. +//! and under `exact_answers`. An 8-bit sRGB texture, whose view decodes its codes, keeps the +//! fetched lanes' bits. //! - The copy pairs the form with its fetch's lanes where the invariant lives: a form whose codes //! those lanes do not hold is named, not left to the builder to refuse (a float code form over //! integer lanes walks into `FClamp`, and an integer form over float lanes bitcasts the value). @@ -174,8 +173,8 @@ fn state(pixel_format: Option) -> BindState { /// A `texture2d` slot the draw reads through a snapshot translates under /// every form the binder names for it, on the fast default and under `exact_answers`. An 8-bit -/// sRGB texture, whose raw codes the read does take, keeps its raw view on both, and no other -/// texture takes one. Each variant passes L3 and binds the snapshot as a storage image. +/// sRGB texture, whose view decodes its codes, keeps the fetched bits on both. Each variant passes +/// L3 and binds the snapshot as a storage image. #[test] fn a_snapshot_slot_translates_under_every_form() { let Some(bc) = fixture("tob_renders") else { @@ -193,7 +192,7 @@ fn a_snapshot_slot_translates_under_every_form() { (PixelFormat::RGBA16Float, SnapshotForm::Half), (PixelFormat::R16Float, SnapshotForm::Half), (PixelFormat::RGBA32Float, SnapshotForm::Bits), - (PixelFormat::RGBA8UnormSRGB, SnapshotForm::Unorm8), + (PixelFormat::RGBA8UnormSRGB, SnapshotForm::Bits), ]; for stem in PROFILES { for (label, policy) in [ @@ -226,15 +225,6 @@ fn a_snapshot_slot_translates_under_every_form() { .any(|b| b.source == BindingSource::SnapshotTexels(0)), "{stem}/{label}/{pf:?}: no snapshot binding" ); - // The raw view beside the slot's image: an sRGB slot's, on both policies. - let raw = variant - .layout - .sets - .iter() - .flat_map(|s| &s.bindings) - .any(|b| b.source == BindingSource::RawTexture(SLOT)); - let srgb = pf == PixelFormat::RGBA8UnormSRGB; - assert_eq!(raw, srgb, "{stem}/{label}/{pf:?}: raw view"); for m in &variant.stages { check_words_valid(&m.spirv, &variant.requirements, dev.profile()) .unwrap_or_else(|e| panic!("{stem}/{label}/{pf:?}: L3: {e}")); diff --git a/crates/metal2vulkan/src/tests/engine_sparse_unmapped.rs b/crates/metal2vulkan/src/tests/engine_sparse_unmapped.rs index 40d15efe9..453f7c399 100644 --- a/crates/metal2vulkan/src/tests/engine_sparse_unmapped.rs +++ b/crates/metal2vulkan/src/tests/engine_sparse_unmapped.rs @@ -383,7 +383,6 @@ fn a_pixel_fetch_reads_metals_value_of_an_unmapped_texel() { compare: false, integer: false, cube_gradient: false, - raw: false, }), index: 0, }; @@ -616,7 +615,6 @@ fn an_access_that_does_not_read_its_residency_reads_metals_constant_lanes() { compare: false, integer: false, cube_gradient: false, - raw: false, }), index: 0, } diff --git a/crates/metal2vulkan/src/tests/engine_srgb_raw.rs b/crates/metal2vulkan/src/tests/engine_srgb_decode.rs similarity index 56% rename from crates/metal2vulkan/src/tests/engine_srgb_raw.rs rename to crates/metal2vulkan/src/tests/engine_srgb_decode.rs index 9091af893..80be79fe5 100644 --- a/crates/metal2vulkan/src/tests/engine_srgb_raw.rs +++ b/crates/metal2vulkan/src/tests/engine_srgb_decode.rs @@ -1,21 +1,18 @@ -//! An 8-bit sRGB texel read as Metal reads it: under a slot's `SrgbTexture` variant, a read, a -//! nearest sample, a pixel-coordinate fetch, and a gather (a `half` result's, and a `float` one's -//! on a device that does not sample through Metal's own sampler) take the texel's raw code from a -//! UNORM view of the image and decode it through Metal's twelve-bit table, rounded exactly to the -//! result. +//! An 8-bit sRGB texel read as Metal reads it, by the device's decode wherever the device samples +//! the format, and through Metal's twelve-bit table where it holds the format as its UNORM twin. //! -//! - On the CPU interpreter, a read and a pixel-coordinate fetch of every code, with a `half` and -//! a `float` result, are the reference bit for bit: a color channel's step +//! - Without a slot's `SrgbTexture` variant every access reads the device's decode through the +//! slot's sRGB view, declaring no table: `PrecisionNote::SrgbTexelDecode` under the bound +//! format's class off Metal's own texture unit, `VkProperty::MetalSampler` on it. +//! - Under the variant (a format the device cannot sample, held as its UNORM twin), on the CPU +//! interpreter, a read and a pixel-coordinate fetch of every code, with a `half` and a `float` +//! result, are the reference bit for bit: a color channel's step //! `k = round(decode(c / 255) · 4095)` (the MSL transfer, which A1's every-byte reading matches) -//! and its value `k / 4095`, alpha's `c / 255`, each correctly rounded to the result's type. -//! - The selection pins which accesses read the raw view under the variant, which keep the -//! device's decode there and record `PrecisionNote::SrgbTexelDecode` (a filtered sample, a -//! runtime sampler's included), and that without the variant every access records the fact and -//! nothing else. -//! - The binder joins a slot bound in an 8-bit sRGB format to the plan's variant, the variant's -//! plan states the same key, and its raw bindings view the image in the UNORM format of the -//! same channels, on every committed profile. -//! - The plan's word estimate bounds the emission of every raw form on every committed profile. +//! and its value `k / 4095`, alpha's `c / 255`, each correctly rounded to the result's type. A +//! filtered sample decodes the device's filter of the codes (`SrgbTexelDecode`). +//! - The binder joins a slot to the plan's variant exactly where the device holds the bound +//! format's twin, and its views then view the twin; elsewhere they view the sRGB format. +//! - The plan's word estimate bounds the emission of every form on every committed profile. //! //! `llvm-as` assembles the kernels; without it the tests skip visibly. @@ -29,12 +26,12 @@ use crate::budget::{Budget, SPIRV_WORDS}; use crate::device::{Device, DeviceDescription, DevicePolicy, FormatUsage}; use crate::library::{FunctionConstantValues, Library}; use crate::lower::select::{LowerInputs, Plan}; -use crate::metal::texel_format::srgb_raw_view; +use crate::metal::format::bound_texel_format; +use crate::metal::texel_format::srgb_twin_on; use crate::metal::{self, PixelFormat, TextureType}; use crate::pipeline::compile::{compile_bitcode, plan_bitcode, EntryRef}; use crate::pipeline::facts::RuntimeFact; use crate::pipeline::interface::PushLoc; -use crate::pipeline::layout::BindingSource; use crate::pipeline::sym::{ Axis, PushField, ResourceKind, ResourceSlot, SlotClass, SlotRef, SpecKey, Stage, }; @@ -42,7 +39,8 @@ use crate::pipeline::testing::{ link_and_validate, llvm_assemble, meter, profile, typed_module_with, AssembleError, }; use crate::pipeline::{ - ComputePipeline, ComputePipelineDescriptor, FunctionDescriptor, PrecisionNote, StageSource, + ComputePipeline, ComputePipelineDescriptor, FunctionDescriptor, PrecisionNote, SpecializedNote, + StageSource, }; use crate::spirv::interp::{run_with_images, Buffer, Config, Image, Order, Resources}; use crate::spirv::ir::{GlobalKind, TypedModule}; @@ -222,7 +220,8 @@ fn kernel(access: Access, half: bool) -> String { ) } -/// Lowering inputs with slot 0 in the `SrgbTexture` variant, or none. +/// Lowering inputs with slot 0 in the `SrgbTexture` variant (bound to a format the device holds +/// as its UNORM twin), or none. fn inputs(variant: bool) -> LowerInputs { let mut i = LowerInputs::new(); if variant { @@ -231,14 +230,6 @@ fn inputs(variant: bool) -> LowerInputs { i } -/// Lowering inputs with slot 0 in the `SrgbTexture` variant and bound to a format held as its -/// UNORM twin (`LoweringInputs::srgb_twins`). -fn twin_inputs() -> LowerInputs { - let mut i = inputs(true); - i.srgb_twins.insert(TEXTURE); - i -} - fn lavapipe() -> crate::device::profile::DeviceProfile { profile("lavapipe", DevicePolicy::default()).expect("profile") } @@ -312,9 +303,9 @@ fn quotient(channel: usize, code: u32) -> (u64, u64) { } } -/// The raw view's image at `slot`: texel `(x, y)` holds codes `codes(x + 16 y)`, each read as +/// The twin's image at `slot`: texel `(x, y)` holds codes `codes(x + 16 y)`, each read as /// `c / 255` correctly rounded to `f32`, as a UNORM view reads it. -fn raw_image(slot: ResourceSlot) -> Image { +fn codes_image(slot: ResourceSlot) -> Image { let mut img = Image::new(slot, [SIDE, SIDE, 1], 1, 1, 1); for n in 0..SIDE * SIDE { let at = img.index(0, 0, 0, [n % SIDE, n / SIDE, 0]).expect("texel"); @@ -331,8 +322,14 @@ fn resource(m: &TypedModule, kind: impl Fn(&ResourceKind) -> bool) -> Option bool { - matches!(k, ResourceKind::CombinedTextureSampler(c) if c.raw) +/// A sampled texture's binding: a texture, separate or combined with its sampler. +fn texture(k: &ResourceKind) -> bool { + matches!( + k, + ResourceKind::Texture + | ResourceKind::SeparateTexture(_) + | ResourceKind::CombinedTextureSampler(_) + ) } /// Resources of a dispatch of one-thread threadgroups over the 16 x 16 grid, `out` sized for @@ -387,10 +384,11 @@ fn run(m: &TypedModule, res: &Resources, images: &[Image]) -> Vec { outs.swap_remove(0).swap_remove(0) } -/// A read and a pixel-coordinate fetch of every code, `half` and `float`, are Metal's decode bit -/// for bit under the variant, reading only the raw view (the texture's own view holds NaNs). +/// Under the variant (a slot bound in a format the device holds as its UNORM twin, whose view +/// reads each code as `c / 255`), a read and a pixel-coordinate fetch of every code, `half` and +/// `float`, are Metal's decode bit for bit, through the slot's own binding, noting nothing. #[test] -fn raw_reads_and_fetches_decode_every_code_as_metal_does() { +fn twin_reads_and_fetches_decode_every_code_as_metal_does() { let fetch = sampler_words(0, 0, true); for (name, access) in [("read", Access::Read), ("fetch", Access::Sample(fetch))] { for half in [true, false] { @@ -402,28 +400,17 @@ fn raw_reads_and_fetches_decode_every_code_as_metal_does() { let (plan, m) = typed_module_with(&bc, "k", &p, &inputs(true)) .unwrap_or_else(|e| panic!("{what} on {stem}: {e}")); assert!( - !plan.precision.contains(&PrecisionNote::SrgbTexelDecode), + !plan.precision.contains(&PrecisionNote::SrgbTexelDecode) + && !plan + .specialized + .iter() + .any(|s| s.note == PrecisionNote::SrgbTexelDecode), "{what} on {stem}" ); - let raw = match access { - Access::Read => resource(&m, |k| *k == ResourceKind::RawTexture), - _ => resource(&m, raw_combined), - } - .unwrap_or_else(|| panic!("{what} on {stem}: no raw binding")); - let mut own = Image::new( - ResourceSlot { - stage: Stage::Kernel, - kind: ResourceKind::Texture, - index: 0, - }, - [SIDE, SIDE, 1], - 1, - 1, - 1, - ); - own.texels.fill([0x7fc0_0001; 4]); + let own = resource(&m, texture) + .unwrap_or_else(|| panic!("{what} on {stem}: no texture binding")); let bytes = if half { 8 } else { 16 }; - let out = run(&m, &resources(&plan, bytes), &[raw_image(raw), own]); + let out = run(&m, &resources(&plan, bytes), &[codes_image(own)]); for n in 0..SIDE * SIDE { for (c, code) in codes(n).into_iter().enumerate() { let (k, d) = quotient(c, code); @@ -452,13 +439,13 @@ fn raw_reads_and_fetches_decode_every_code_as_metal_does() { } } -/// A read of an 8-bit sRGB texture whose swizzle moves a code between a color lane and alpha -/// (`abgr`) decodes each code by its own channel and then swizzles, as plain Metal does, under -/// the slot's `swizzled_storage` variant (the view takes no swizzle): each lane is its source -/// channel's quotient, a color channel's step over 4095 on alpha's lane and alpha's code over 255 -/// on red's, bit for bit, on the interpreter. +/// Under the variant, a read of a texture whose swizzle moves a code between a color lane and +/// alpha (`abgr`) decodes each code by its own channel and then swizzles, as plain Metal does, +/// under the slot's `swizzled_storage` variant (the view takes no swizzle): each lane is its +/// source channel's quotient, a color channel's step over 4095 on alpha's lane and alpha's code +/// over 255 on red's, bit for bit, on the interpreter. #[test] -fn a_swizzled_srgb_read_decodes_before_its_swizzle() { +fn a_swizzled_twin_read_decodes_before_its_swizzle() { use crate::metal::{TextureSwizzle as S, TextureSwizzleChannels}; let Some(bc) = assemble("read float", &kernel(Access::Read, false)) else { return; @@ -475,24 +462,11 @@ fn a_swizzled_srgb_read_decodes_before_its_swizzle() { under.swizzled_storage.insert(TEXTURE); let (plan, m) = typed_module_with(&bc, "k", &p, &under).unwrap_or_else(|e| panic!("{stem}: {e}")); - let raw = resource(&m, |k| *k == ResourceKind::RawTexture) - .unwrap_or_else(|| panic!("{stem}: no raw binding")); - let mut own = Image::new( - ResourceSlot { - stage: Stage::Kernel, - kind: ResourceKind::Texture, - index: 0, - }, - [SIDE, SIDE, 1], - 1, - 1, - 1, - ); - own.texels.fill([0x7fc0_0001; 4]); + let own = resource(&m, texture).unwrap_or_else(|| panic!("{stem}: no texture binding")); let mut res = resources(&plan, 16); res.spec .insert(SpecKey::TextureSwizzle(TEXTURE), u64::from(swizzle.word())); - let out = run(&m, &res, &[raw_image(raw), own]); + let out = run(&m, &res, &[codes_image(own)]); for n in 0..SIDE * SIDE { let codes = codes(n); for (lane, &from) in source.iter().enumerate() { @@ -510,12 +484,14 @@ fn a_swizzled_srgb_read_decodes_before_its_swizzle() { } } -/// The plan of a slot bound in an 8-bit sRGB format with a swizzle names the slot in -/// `VariantKey::swizzled_storage`, and its views take no swizzle, exactly where the swizzle moves -/// a code between a color lane and alpha; a swizzle among the color lanes or to constants keeps -/// the views' component mapping, which reads the same. +/// The plan of a slot bound with a swizzle in an 8-bit sRGB format the device holds as its UNORM +/// twin names the slot in `VariantKey::swizzled_storage`, and its views take no swizzle, exactly +/// where the swizzle moves a code between a color lane and alpha (the function decodes, then +/// swizzles); a swizzle among the color lanes or to constants keeps the views' component mapping, +/// which reads the same. A format the device samples is decoded by its sRGB view before the +/// view's component mapping swizzles, so its views take every swizzle. #[test] -fn an_srgb_swizzle_across_alpha_swizzles_in_the_function() { +fn an_srgb_swizzle_across_alpha_swizzles_in_the_function_on_a_twin() { use crate::metal::{TextureSwizzle as S, TextureSwizzleChannels}; let Some(bc) = assemble("read float", &kernel(Access::Read, false)) else { return; @@ -534,159 +510,140 @@ fn an_srgb_swizzle_across_alpha_swizzles_in_the_function() { (channels(S::Red, S::Red, S::Red, S::One), false), (channels(S::Zero, S::Green, S::One, S::Alpha), false), ]; - let mut planned = 0; + let (mut planned, mut swizzled) = (0, 0); for (stem, dev) in devices() { - let variant = pipeline(&dev, &bc, &inputs(true)); - for (swizzle, crosses) in cases { - let what = format!("{stem} {swizzle:?}"); - let mut state = state(Some(PixelFormat::RGBA8UnormSRGB)); - if let Some(BoundTexture::Texture { facts, .. }) = state - .stages - .get_mut(&Stage::Kernel) - .and_then(|t| t.textures.get_mut(&0)) - { - facts.swizzle = swizzle; + let plain = pipeline(&dev, &bc, &inputs(false)); + for pf in [PixelFormat::RGBA8UnormSRGB, PixelFormat::RG8UnormSRGB] { + let twin = srgb_twin_on(pf, dev.profile()); + for (swizzle, crosses) in cases { + let what = format!("{stem} {pf:?} {swizzle:?}"); + let mut state = state(Some(pf)); + if let Some(BoundTexture::Texture { facts, .. }) = state + .stages + .get_mut(&Stage::Kernel) + .and_then(|t| t.textures.get_mut(&0)) + { + facts.swizzle = swizzle; + } + let Ok(plan) = plain.plan(&dev, &state.shape()) else { + continue; + }; + let in_function = crosses && twin; + assert_eq!( + plan.variant.swizzled_storage.contains(&TEXTURE), + in_function, + "{what}" + ); + let views = slot_views(&plan, TEXTURE); + assert!(!views.is_empty(), "{what}"); + for v in views { + assert_eq!(v.shader_swizzle, in_function, "{what}"); + } + planned += 1; + swizzled += usize::from(in_function); } - let Ok(plan) = variant.plan(&dev, &state.shape()) else { - continue; - }; - assert_eq!( - plan.variant.swizzled_storage.contains(&TEXTURE), - crosses, - "{what}" - ); - let (raw, own) = views(&variant, &plan); - for v in raw.iter().chain(own.iter()).filter_map(view_of) { - assert_eq!(v.shader_swizzle, crosses, "{what}"); - } - planned += 1; } } assert!(planned > 0, "no committed profile planned the texture"); + assert!(swizzled > 0, "no committed profile holds a twin"); } -/// Where an access reads the raw view under the variant. -#[derive(Clone, Copy, Debug, PartialEq, Eq)] -enum Raw { - /// On every device. - Always, - /// Where the device does not sample through Metal's own sampler: a `float` gather, which - /// Metal's own sampler gathers as the table decodes. - Unmetal, - /// Nowhere: the device's decode. - Never, -} - -/// Which accesses read the raw view under the variant, and which keep the device's decode there: -/// recording `PrecisionNote::SrgbTexelDecode` on lavapipe, and on MoltenVK, whose decode is -/// Metal's own, requiring `VkProperty::MetalSampler` instead, and stating -/// `RuntimeFact::SrgbDeviceDecode` on both. A filtered sample (a linear filter, a linear mip filter -/// or a runtime sampler) is the device's, and keeps its decode. Without the variant every access -/// records `RuntimeFact::SrgbTexture` and none of them. On MoltenVK every sample and gather the -/// device makes requires the property, and so does a `half` access that converts its texel by the -/// bound format's class (`RuntimeFact::TexelFormat`) outside the raw view; a filtered sample -/// records `PrecisionNote::HalfSampleFilter` or `PrecisionNote::FloatSampleFilter` under the bound -/// format (`lower::sampler::linear::metal_filtered_ycbcr`). On lavapipe the texel is the device's -/// conversion: no class, no filter note. Every form validates on both devices. +/// Every access of an 8-bit sRGB texture slot records `RuntimeFact::SrgbTexture`. Without the +/// variant every one of them (a read, a fetch, a nearest, linear, mipmapped or bicubic sample, a +/// gather, a runtime sampler's sample) reads the device's own decode and declares no Metal table: +/// on lavapipe it notes `PrecisionNote::SrgbTexelDecode` under the bound format's class (an +/// `RGBA8Unorm_sRGB` or ASTC sRGB texture's, not an `RGBA8Unorm` one's), and on MoltenVK, whose +/// decode is Metal's own, it requires `VkProperty::MetalSampler` instead. Under the variant every +/// access declares the table, and only a filtered sample (a linear filter, a linear mip filter, a +/// runtime sampler), the device's filter of the codes, notes `SrgbTexelDecode`, outright. On +/// MoltenVK a filtered sample records `PrecisionNote::HalfSampleFilter` or +/// `PrecisionNote::FloatSampleFilter` (`lower::sampler::linear::metal_filtered_ycbcr`), a `half` +/// access that converts the device's texel by the bound format's class states +/// `RuntimeFact::TexelFormat`, and every sample and gather the device makes requires the +/// property. Every form validates on both devices. #[test] -fn the_raw_view_serves_what_metal_measured() { +fn the_device_decodes_every_access_but_a_twins() { use crate::device::requirements::VkProperty; let nearest = sampler_words(0, 0, false); let linear = sampler_words(1, 0, false); let bicubic = sampler_words(2, 0, false); + let fetch = sampler_words(0, 0, true); + // Each access, and whether it reads one texel's codes under the variant (not a filter's). let cases = [ - ("read half", Access::Read, true, Raw::Always), - ("read float", Access::Read, false, Raw::Always), - ( - "fetch half", - Access::Sample(sampler_words(0, 0, true)), - true, - Raw::Always, - ), - ( - "fetch float", - Access::Sample(sampler_words(0, 0, true)), - false, - Raw::Always, - ), - ("nearest half", Access::Sample(nearest), true, Raw::Always), - ("nearest float", Access::Sample(nearest), false, Raw::Always), + ("read half", Access::Read, true, true), + ("read float", Access::Read, false, true), + ("fetch half", Access::Sample(fetch), true, true), + ("fetch float", Access::Sample(fetch), false, true), + ("nearest half", Access::Sample(nearest), true, true), + ("nearest float", Access::Sample(nearest), false, true), ( "nearest level", Access::Sample(sampler_words(0, 1, false)), false, - Raw::Always, + true, ), - ("gather red half", Access::Gather(0), true, Raw::Always), - ("gather alpha half", Access::Gather(3), true, Raw::Always), - ("bicubic half", Access::Sample(bicubic), true, Raw::Always), - ("bicubic float", Access::Sample(bicubic), false, Raw::Always), - ("gather float", Access::Gather(0), false, Raw::Unmetal), - ("linear half", Access::Sample(linear), true, Raw::Never), - ("linear float", Access::Sample(linear), false, Raw::Never), + ("gather red half", Access::Gather(0), true, true), + ("gather alpha half", Access::Gather(3), true, true), + ("gather float", Access::Gather(0), false, true), + ("bicubic half", Access::Sample(bicubic), true, true), + ("bicubic float", Access::Sample(bicubic), false, true), + ("linear half", Access::Sample(linear), true, false), + ("linear float", Access::Sample(linear), false, false), ( "mip linear", Access::Sample(sampler_words(0, 2, false)), false, - Raw::Never, + false, ), - ("runtime half", Access::Runtime, true, Raw::Never), - ("runtime float", Access::Runtime, false, Raw::Never), + ("runtime half", Access::Runtime, true, false), + ("runtime float", Access::Runtime, false, false), ]; let consts = FunctionConstantValues::defaults(); - for (name, access, half, raw) in cases { + for (name, access, half, codes) in cases { let Some(bc) = assemble(name, &kernel(access, half)) else { return; }; for (stem, p) in [("lavapipe", lavapipe()), ("moltenvk-m3", m3())] { let metal = stem == "moltenvk-m3"; - let raw = match raw { - Raw::Always => true, - Raw::Unmetal => !metal, - Raw::Never => false, - }; for variant in [false, true] { let what = format!("{name} on {stem}, variant {variant}"); - let (plan, m) = typed_module_with(&bc, "k", &p, &inputs(variant)) + let (plan, _) = typed_module_with(&bc, "k", &p, &inputs(variant)) .unwrap_or_else(|e| panic!("{what}: {e}")); assert!( plan.facts .contains(&RuntimeFact::SrgbTexture { slot: TEXTURE }), "{what}" ); - let reads_raw = resource(&m, |k| *k == ResourceKind::RawTexture).is_some() - || resource(&m, raw_combined).is_some(); - assert_eq!(reads_raw, variant && raw, "{what}"); assert_eq!( plan.precision.contains(&PrecisionNote::SrgbTexelDecode), - variant && !raw && !metal, + !variant && !metal || variant && !codes, "{what}" ); - assert!( - !plan - .specialized - .iter() - .any(|s| s.note == PrecisionNote::SrgbTexelDecode), - "{what}" - ); - // A form that keeps the device's decode under the variant states it, so the - // planner refuses a texture whose format the device cannot sample. - assert_eq!( - plan.facts - .contains(&RuntimeFact::SrgbDeviceDecode { slot: TEXTURE }), - variant && !raw, - "{what}" - ); - // On MoltenVK a `half` access outside the raw view converts its texel by the + let noted = |pf| bound_note(&plan.specialized, pf); + for pf in [PixelFormat::RGBA8UnormSRGB, PixelFormat::ASTC4x4SRGB] { + assert_eq!(noted(pf), !variant && !metal, "{what} {pf:?}"); + } + assert!(!noted(PixelFormat::RGBA8Unorm), "{what}"); + // On MoltenVK a `half` access outside the codes converts its texel by the // format's class, whose rounding to `half` is Metal's there only through Metal's // own texture unit; a bicubic sample's taps are fetched. - let converts = metal && half && !(variant && raw) && name != "bicubic half"; + let converts = metal && half && !(variant && codes) && name != "bicubic half"; assert_eq!( plan.facts .contains(&RuntimeFact::TexelFormat { slot: TEXTURE }), converts, "{what}" ); + assert_eq!( + plan.precision.contains(&PrecisionNote::FloatSampleFilter), + !codes && !half && metal, + "{what}" + ); + assert_eq!( + plan.precision.contains(&PrecisionNote::HalfSampleFilter), + !codes && half && metal, + "{what}" + ); let a = compile_bitcode( &bc, EntryRef::Name("k"), @@ -697,26 +654,13 @@ fn the_raw_view_serves_what_metal_measured() { SPIRV_WORDS, ) .unwrap_or_else(|e| panic!("{what}: {e}")); - let filtered = matches!( - name, - "linear half" - | "linear float" - | "mip linear" - | "runtime half" - | "runtime float" - ); assert_eq!( - plan.precision.contains(&PrecisionNote::FloatSampleFilter), - filtered && !half && metal, - "{what}" - ); - assert_eq!( - plan.precision.contains(&PrecisionNote::HalfSampleFilter), - filtered && half && metal, + super::engine_fragment::holds_srgb_table(&a.module.words), + variant, "{what}" ); // Every sample and gather the device makes (not a read, a pixel fetch or a - // bicubic sample's fetched taps). + // bicubic sample's fetched taps), and every decode of the device's. let sampled = !matches!( name, "read half" @@ -730,7 +674,7 @@ fn the_raw_view_serves_what_metal_measured() { a.requirements .properties .contains(&VkProperty::MetalSampler), - metal && (sampled || converts), + metal && (!variant || sampled || converts), "{what}" ); link_and_validate(&a, &p).unwrap_or_else(|e| panic!("{what}: {e}")); @@ -739,6 +683,22 @@ fn the_raw_view_serves_what_metal_measured() { } } +/// Whether `specialized` notes `PrecisionNote::SrgbTexelDecode` where texture slot 0 binds a +/// texture of `pf`: a clause testing the bound format's class alone, as the runtime reads it. +fn bound_note(specialized: &[SpecializedNote], pf: PixelFormat) -> bool { + specialized + .iter() + .filter(|s| s.note == PrecisionNote::SrgbTexelDecode) + .flat_map(|s| &s.when) + .any(|c| { + c.tests_bound_formats() + && c.holds_of_bound(&|slot| { + assert_eq!(slot, TEXTURE); + Some(bound_texel_format(pf)) + }) + }) +} + /// A kernel sampling a `dims`-dimensional texture (`texture1d`, `texture2d`, or `texture3d`) slot 0 /// of `half` texels (`float`) through the constexpr sampler of `words` at buffer 1's lane `tid` /// (a `float2`, its `x` for 1D; a `float4`'s `xyz` for 3D), storing the `half4` (`float4`) to @@ -830,11 +790,11 @@ declare {{ {vec4}, i8 }} @air.sample_texture_{name}.{suffix}({args}) ) } -/// The plan's word estimate bounds the emitted module of every raw form under the variant (and of -/// the device's samples beside them), with the slot bound to a twin (whose device sample decodes -/// the filtered codes) and without, on every committed profile, and every form validates there. +/// The plan's word estimate bounds the emitted module of every access, with the slot in the +/// variant (decoding the twin's codes) and without (the device's decode), on every committed +/// profile, and every form validates there. #[test] -fn the_raw_estimate_bounds_its_emission() { +fn the_srgb_estimate_bounds_its_emission() { let consts = FunctionConstantValues::defaults(); let forms = [ ("read half", Access::Read, true), @@ -894,8 +854,8 @@ fn the_raw_estimate_bounds_its_emission() { .into_iter() .flat_map(|sp| { [ - (sp.clone(), ("", inputs(true))), - (sp, (" twin", twin_inputs())), + (sp.clone(), ("", inputs(false))), + (sp, (" twin", inputs(true))), ] }) { @@ -986,200 +946,177 @@ fn state(pf: Option) -> BindState { s } -/// The texture writes of `plan` for `p`: its raw bindings' (`BindingSource::RawTexture`, or a -/// combined binding with `CombinedSampler::raw`) and every other's. -fn views( - p: &ComputePipeline, - plan: &crate::bind::BindingPlan, -) -> (Vec, Vec) { - let raw_bindings: BTreeSet = p - .layout - .sets - .iter() - .flat_map(|s| s.bindings.iter()) - .filter(|b| match b.source { - BindingSource::RawTexture(_) => true, - BindingSource::CombinedTextureSampler { sampler, .. } => sampler.raw, - _ => false, - }) - .map(|b| b.binding) - .collect(); +/// The image views `plan` writes for texture slot `slot`, through a texture or a combined write. +fn slot_views(plan: &crate::bind::BindingPlan, slot: SlotRef) -> Vec { plan.descriptors .iter() - .filter(|d| { - matches!( - d.source, - WriteSource::Texture { .. } - | WriteSource::CombinedImageSampler { .. } - | WriteSource::Neutral(_) - ) && d.set == 0 + .filter_map(|d| match &d.source { + WriteSource::Texture { slot: s, view } if *s == slot => Some(*view), + WriteSource::CombinedImageSampler { + image: ImageSource::Texture { slot: s, view }, + .. + } if *s == slot => Some(*view), + _ => None, }) - .map(|d| (raw_bindings.contains(&d.binding), d.source.clone())) - .fold( - (Vec::new(), Vec::new()), - |(mut raw, mut own), (is_raw, s)| { - if is_raw { - raw.push(s); - } else { - own.push(s); - } - (raw, own) - }, - ) + .collect() } -/// The image view of a texture write. -fn view_of(w: &WriteSource) -> Option { - match w { - WriteSource::Texture { view, .. } => Some(*view), - WriteSource::CombinedImageSampler { - image: ImageSource::Texture { view, .. }, - .. - } => Some(*view), - _ => None, - } +/// Whether `profile`'s device decodes through Metal's own texture unit. +fn metal_sampler(dev: &Device) -> bool { + dev.profile() + .fields() + .enabled + .properties + .contains(&crate::device::requirements::VkProperty::MetalSampler) } -/// A slot bound in an 8-bit sRGB format joins the plan's variant; the variant's pipeline plans -/// the same key for the same shape, and its raw binding views the image in the UNORM format of -/// the same channels with the own view's type, components, and layout; a slot bound in another -/// format, or unbound, leaves the variant, and the variant's raw binding then takes a neutral. -/// On every committed profile where the format is sampled, for a read and a nearest sample; -/// where only its UNORM twin is, every binding of the slot views the image in the twin's format. +/// Whether `p`'s stage notes `PrecisionNote::SrgbTexelDecode` where slot 0 binds a texture of +/// `pf`, as the runtime reads it at a dispatch (`StageModule::bound_format_clauses`). +fn notes_bound(p: &ComputePipeline, pf: PixelFormat) -> bool { + !p.stage + .bound_format_clauses(PrecisionNote::SrgbTexelDecode, &|_| { + Some(bound_texel_format(pf)) + }) + .is_empty() +} + +/// A slot bound in an 8-bit sRGB format joins the plan's variant exactly where the device holds +/// the format as its UNORM twin (`metal::texel_format::srgb_twin_on`), from the device's format +/// features alone. Where the device samples the format the slot joins nothing, every binding of +/// the slot views the image in that sRGB format (the device decodes it), and off Metal's own +/// texture unit the pipeline notes `PrecisionNote::SrgbTexelDecode` under the bound format, which +/// an `RGBA8Unorm` texture does not take. Where the device holds the twin, the variant's pipeline +/// plans the same key, every binding of the slot views the twin, and only a runtime sampler's +/// sample (the device's filter of the codes) notes `SrgbTexelDecode`, outright; each variant +/// validates. A device that samples neither form refuses the format. Every committed profile, for +/// a read, a nearest sample and a runtime sampler's sample. #[test] -fn a_slot_bound_in_srgb_joins_the_variant_and_binds_its_raw_view() { +fn a_slot_bound_in_srgb_joins_the_variant_only_where_the_device_holds_its_twin() { + use crate::device::requirements::FormatUsage as U; let forms = [ - ("read", Access::Read), - ("nearest", Access::Sample(sampler_words(0, 0, false))), + ("read", Access::Read, false), + ("nearest", Access::Sample(sampler_words(0, 0, false)), false), + ("runtime", Access::Runtime, true), ]; - let (mut planned, mut twinned) = (0, 0); - for (name, access) in forms { - let Some(bc) = assemble(name, &kernel(access, true)) else { + let (mut decoded, mut twinned) = (0, 0); + for (name, access, filtered) in forms { + let Some(bc) = assemble(name, &kernel(access, false)) else { return; }; for (stem, dev) in devices() { - let what = format!("{name} on {stem}"); + let metal = metal_sampler(&dev); let plain = pipeline(&dev, &bc, &inputs(false)); + assert!(!notes_bound(&plain, PixelFormat::RGBA8Unorm), "{stem}"); for pf in [ PixelFormat::RGBA8UnormSRGB, PixelFormat::BGRA8UnormSRGB, PixelFormat::R8UnormSRGB, PixelFormat::RG8UnormSRGB, ] { + let what = format!("{name} on {stem} {pf:?}"); let shape = state(Some(pf)).shape(); - // A profile that cannot sample the format samples its UNORM twin's view, through - // which the variant reads the raw codes. - let sampled = crate::metal::format::vk_format( - pf, - &[FormatUsage::SampledImage].into(), - dev.profile(), - ) - .is_ok(); - let twin = crate::metal::format::srgb_raw_twin(pf) - .and_then(crate::metal::format::direct_format); + let sampled = + crate::metal::format::vk_format(pf, &[U::SampledImage].into(), dev.profile()); + let twin = srgb_twin_on(pf, dev.profile()); + assert!(!(twin && sampled.is_ok()), "{what}"); let plan = match plain.plan(&dev, &shape) { Ok(plan) => plan, - // A profile that samples neither refuses the format. Err(crate::error::BindError::Unsupported(u)) - if u.feature == crate::error::Feature::Format && !sampled => + if u.feature == crate::error::Feature::Format + && sampled.is_err() + && !twin => { continue } - Err(e) => panic!("{what} {pf:?}: {e}"), + Err(e) => panic!("{what}: {e}"), }; + let views = slot_views(&plan, TEXTURE); + assert!(!views.is_empty(), "{what}"); + if let Ok(s) = sampled { + assert!(plan.variant.srgb_textures.is_empty(), "{what}"); + for v in &views { + assert_eq!(v.format, s.format, "{what}"); + assert_eq!( + v.format.block().and_then(|b| b.color), + Some(crate::vk::NumericFormat::Srgb), + "{what}" + ); + } + assert_eq!(notes_bound(&plain, pf), !metal, "{what}"); + decoded += 1; + continue; + } + assert!(twin, "{what}"); assert_eq!( plan.variant.srgb_textures, BTreeSet::from([TEXTURE]), - "{what} {pf:?}" + "{what}" ); + let held = crate::metal::format::srgb_raw_twin(pf) + .and_then(crate::metal::format::direct_format) + .expect(&what); + for v in &views { + assert_eq!(v.format, held, "{what}"); + } let key = plan.variant.lowering_inputs(Stage::Kernel); - assert_eq!( - key.srgb_textures, - BTreeSet::from([TEXTURE]), - "{what} {pf:?}" - ); + assert_eq!(key.srgb_textures, BTreeSet::from([TEXTURE]), "{what}"); let variant = pipeline(&dev, &bc, &key); - let again = variant.plan(&dev, &shape).expect("variant plan"); - assert_eq!(again.variant, plan.variant, "{what} {pf:?}"); - let (raw, variant_own) = views(&variant, &again); - assert_eq!(raw.len(), 1, "{what} {pf:?}: {raw:?}"); - let raw = view_of(&raw[0]).unwrap_or_else(|| panic!("{what} {pf:?}: {raw:?}")); - // The texture's own view: the plain pipeline's. - let (_, own) = views(&plain, &plan); - let own: Vec<_> = own.iter().filter_map(view_of).collect(); - assert!(!own.is_empty(), "{what} {pf:?}"); - if !sampled { - // The twin's view serves every binding: the raw one, and the own ones, which - // a function decoding nothing through the device reads for queries alone. - assert_eq!(Some(raw.format), twin, "{what} {pf:?}"); - for o in own - .iter() - .copied() - .chain(variant_own.iter().filter_map(view_of)) - { - assert_eq!(o, raw, "{what} {pf:?}"); - } - twinned += 1; - planned += 1; - continue; + assert_eq!( + variant + .stage + .precision_notes + .contains(&PrecisionNote::SrgbTexelDecode), + filtered, + "{what}" + ); + assert!(!notes_bound(&variant, pf), "{what}"); + let a = compile_bitcode( + &bc, + EntryRef::Name("k"), + &FunctionConstantValues::defaults(), + dev.profile(), + &key, + &mut meter(), + SPIRV_WORDS, + ) + .unwrap_or_else(|e| panic!("{what}: {e}")); + link_and_validate(&a, dev.profile()).unwrap_or_else(|e| panic!("{what}: {e}")); + let again = variant + .plan(&dev, &shape) + .unwrap_or_else(|e| panic!("{what}: {e}")); + assert_eq!(again.variant, plan.variant, "{what}"); + for v in slot_views(&again, TEXTURE) { + assert_eq!(v.format, held, "{what}"); } - for o in own { - assert_eq!(srgb_raw_view(o.format), Some(raw.format), "{what} {pf:?}"); - assert_eq!( - (o.view_type, o.components, o.layout, o.aspect, o.level), - ( - raw.view_type, - raw.components, - raw.layout, - raw.aspect, - raw.level - ), - "{what} {pf:?}" - ); - } - planned += 1; - // Another format, or nothing: no variant, and the variant's raw binding is - // neutral. + twinned += 1; + // Another format, or nothing, leaves the variant. for other in [Some(PixelFormat::RGBA8Unorm), None] { let shape = state(other).shape(); let plan = variant.plan(&dev, &shape).expect("plan"); assert!(plan.variant.srgb_textures.is_empty(), "{what} {other:?}"); - let (raw, _) = views(&variant, &plan); - assert!( - raw.iter().all(|w| view_of(w).is_none()), - "{what} {other:?}: {raw:?}" - ); - assert!( - plain - .plan(&dev, &shape) - .expect("plan") - .variant - .srgb_textures - .is_empty(), - "{what} {other:?}" - ); } } } } - assert!(planned > 0); + assert!(decoded > 0, "no committed profile samples an sRGB format"); assert!( twinned > 0, "no committed profile samples an sRGB format only through its twin" ); } -/// A slot bound in an ASTC sRGB format joins the variant exactly where the device holds the -/// format's decoded twin (no ASTC block, `metal::texel_format::srgb_raw_on`): its raw binding -/// views the twin's codes as `R8G8B8A8_UNORM`, its own binding as `R8G8B8A8_SRGB`. A device with -/// the block (ANV, MoltenVK) decodes the texture itself: no variant, and its own view the block's. +/// An ASTC sRGB slot samples the device's decode wherever the device samples a format of it: its +/// own block where the device has ASTC (ANV, MoltenVK), its decoded twin's `R8G8B8A8_SRGB` view +/// elsewhere (`bind::AstcDecode`). It joins no variant, and off Metal's own texture unit the +/// pipeline notes `PrecisionNote::SrgbTexelDecode` under the bound format. #[test] -fn an_astc_srgb_slot_reads_raw_codes_only_where_its_twin_holds_them() { +fn an_astc_srgb_slot_samples_the_devices_decode() { let Some(bc) = assemble("astc read", &kernel(Access::Read, true)) else { return; }; - let (mut twinned, mut native) = (0, 0); + let (mut decoded, mut native) = (0, 0); for (stem, dev) in devices() { + let metal = metal_sampler(&dev); let plain = pipeline(&dev, &bc, &inputs(false)); for pf in [PixelFormat::ASTC4x4SRGB, PixelFormat::ASTC12x10SRGB] { let what = format!("{stem} {pf:?}"); @@ -1189,58 +1126,38 @@ fn an_astc_srgb_slot_reads_raw_codes_only_where_its_twin_holds_them() { dev.profile(), ) .unwrap_or_else(|e| panic!("{what}: {e}")); - let shape = state(Some(pf)).shape(); - let plan = plain.plan(&dev, &shape).expect(&what); - let decoded = sampled.emulation == crate::metal::format::FormatEmulation::Decoded; - assert_eq!( - crate::metal::texel_format::srgb_raw_on(pf, dev.profile()), - decoded, - "{what}" - ); - if !decoded { - assert!(plan.variant.srgb_textures.is_empty(), "{what}"); - let (_, own) = views(&plain, &plan); - for o in own.iter().filter_map(view_of) { - assert_eq!(o.format, sampled.format, "{what}"); - } + assert!(!srgb_twin_on(pf, dev.profile()), "{what}"); + let plan = plain.plan(&dev, &state(Some(pf)).shape()).expect(&what); + assert!(plan.variant.srgb_textures.is_empty(), "{what}"); + let views = slot_views(&plan, TEXTURE); + assert!(!views.is_empty(), "{what}"); + for v in &views { + assert_eq!(v.format, sampled.format, "{what}"); + } + if sampled.emulation == crate::metal::format::FormatEmulation::Decoded { + assert_eq!(sampled.format, crate::vk::Format::R8G8B8A8_SRGB, "{what}"); + decoded += 1; + } else { native += 1; - continue; } - assert_eq!( - plan.variant.srgb_textures, - BTreeSet::from([TEXTURE]), - "{what}" - ); - let key = plan.variant.lowering_inputs(Stage::Kernel); - let variant = pipeline(&dev, &bc, &key); - let again = variant.plan(&dev, &shape).expect("variant plan"); - assert_eq!(again.variant, plan.variant, "{what}"); - let (raw, own) = views(&variant, &again); - let raw: Vec<_> = raw.iter().filter_map(view_of).collect(); - assert_eq!(raw.len(), 1, "{what}: {raw:?}"); - assert_eq!(raw[0].format, crate::vk::Format::R8G8B8A8_UNORM, "{what}"); - for o in own.iter().filter_map(view_of) { - assert_eq!(o.format, crate::vk::Format::R8G8B8A8_SRGB, "{what}"); - } - twinned += 1; + assert_eq!(notes_bound(&plain, pf), !metal, "{what}"); } } - assert!(twinned > 0, "no committed profile holds an ASTC sRGB twin"); + assert!(decoded > 0, "no committed profile holds an ASTC sRGB twin"); assert!( native > 0, "no committed profile samples an ASTC sRGB block" ); } -/// A `half` sample the device decodes and filters under the variant (a linear one with a linear -/// mip filter, which the raw view does not serve) converts the device's `f32` texel by the bound -/// format's class, the conversion's `OTHER` arm for an 8-bit sRGB format. On MoltenVK, whose -/// decode and filter are Metal's own texture unit's, that `f32` is Metal's `float` value, whose -/// rounding to `half` is Metal's (`metals_srgb_float_steps_round_to_their_half_steps`): the -/// pipeline takes no `PrecisionNote::HalfTexelConversion` under the format and requires -/// `VkProperty::MetalSampler`, and the note holds under a format of no measured family, which the -/// variant leaves for another bound format. On lavapipe, whose decode and conversion are the -/// device's, the note holds under every format. +/// A `half` sample the device decodes and filters (a linear one with a linear mip filter) +/// converts the device's `f32` texel by the bound format's class, the conversion's `OTHER` arm +/// for an 8-bit sRGB format. On MoltenVK, whose decode and filter are Metal's own texture unit's, +/// that `f32` is Metal's `float` value, whose rounding to `half` is Metal's +/// (`metals_srgb_float_steps_round_to_their_half_steps`): the pipeline takes no +/// `PrecisionNote::HalfTexelConversion` under the format and requires `VkProperty::MetalSampler`, +/// and the note holds under a format of no measured family. On lavapipe, whose decode and +/// conversion are the device's, the note holds under every format. #[test] fn metals_own_srgb_decode_converts_to_half_as_metal_does() { use crate::device::requirements::VkProperty; @@ -1258,7 +1175,7 @@ fn metals_own_srgb_decode_converts_to_half_as_metal_does() { _ => continue, }; seen += 1; - let p = pipeline(&dev, &bc, &inputs(true)); + let p = pipeline(&dev, &bc, &inputs(false)); assert_eq!( p.requirements .properties @@ -1268,7 +1185,7 @@ fn metals_own_srgb_decode_converts_to_half_as_metal_does() { ); for pf in [PixelFormat::RGBA8UnormSRGB, PixelFormat::BGRA8UnormSRGB] { let plan = p.plan(&dev, &state(Some(pf)).shape()).expect("plan"); - assert_eq!(plan.variant.srgb_textures, BTreeSet::from([TEXTURE])); + assert!(plan.variant.srgb_textures.is_empty(), "{stem} {pf:?}"); let notes = p.stage.precision_notes_under(&plan.specialization); assert_eq!( notes.contains(&PrecisionNote::HalfTexelConversion), @@ -1294,11 +1211,11 @@ fn metals_own_srgb_decode_converts_to_half_as_metal_does() { ); continue; } - // The variant's module keeps the note for a format of no measured family: its slot's + // The module keeps the note for a format of no measured family: its slot's // `UnmeasuredTexels` specialization, 1 for such a format. let other = crate::metal::texel_format::TexelFormat::OTHER.0; - let value = |key: &crate::pipeline::sym::SpecKey| match key { - crate::pipeline::sym::SpecKey::UnmeasuredTexels(_) => 1, + let value = |key: &SpecKey| match key { + SpecKey::UnmeasuredTexels(_) => 1, _ => other, }; let held = p.stage.specialized_notes.iter().any(|s| { @@ -1314,111 +1231,6 @@ fn metals_own_srgb_decode_converts_to_half_as_metal_does() { assert_eq!(seen, 2); } -/// Under the variant, a form the raw codes do not serve (a runtime sampler's sample) states -/// `RuntimeFact::SrgbDeviceDecode`. On a profile that samples the bound format only through its -/// UNORM twin, the plan names the slot in `VariantKey::srgb_twins` beside `srgb_textures`, from -/// the device's format features alone; the pipeline compiled under that key notes -/// `PrecisionNote::SrgbTexelDecode` (the device's filter of the codes, decoded through the table), -/// validates, plans the same key with every binding of the slot viewing the image in the twin's -/// format, and refuses nothing. A profile that samples the format leaves the twins empty. -#[test] -fn a_device_decode_samples_the_twin_of_a_format_the_device_cannot_sample() { - let Some(bc) = assemble("runtime float", &kernel(Access::Runtime, false)) else { - return; - }; - let (mut twinned, mut sampled_count) = (0, 0); - for (stem, dev) in devices() { - let plain = pipeline(&dev, &bc, &inputs(false)); - for pf in [ - PixelFormat::RGBA8UnormSRGB, - PixelFormat::BGRA8UnormSRGB, - PixelFormat::R8UnormSRGB, - PixelFormat::RG8UnormSRGB, - ] { - let what = format!("{stem} {pf:?}"); - let sampled = |pf| { - crate::metal::format::vk_format( - pf, - &[FormatUsage::SampledImage].into(), - dev.profile(), - ) - .is_ok() - }; - let twin = crate::metal::format::srgb_raw_twin(pf).expect(&what); - if !sampled(pf) && !sampled(twin) { - continue; - } - let shape = state(Some(pf)).shape(); - let plan = plain - .plan(&dev, &shape) - .unwrap_or_else(|e| panic!("{what}: {e}")); - assert_eq!( - plan.variant.srgb_textures, - BTreeSet::from([TEXTURE]), - "{what}" - ); - if sampled(pf) { - assert!(plan.variant.srgb_twins.is_empty(), "{what}"); - sampled_count += 1; - continue; - } - assert_eq!(plan.variant.srgb_twins, BTreeSet::from([TEXTURE]), "{what}"); - let variant = pipeline(&dev, &bc, &plan.variant.lowering_inputs(Stage::Kernel)); - assert!( - variant - .dependencies - .iter() - .any(|d| d.fact == RuntimeFact::SrgbDeviceDecode { slot: TEXTURE }), - "{what}" - ); - let twins = plan.variant.lowering_inputs(Stage::Kernel); - let (lowered, _) = typed_module_with(&bc, "k", dev.profile(), &twins) - .unwrap_or_else(|e| panic!("{what}: {e}")); - assert!( - lowered.precision.contains(&PrecisionNote::SrgbTexelDecode), - "{what}: {:?}", - lowered.precision - ); - let a = compile_bitcode( - &bc, - EntryRef::Name("k"), - &FunctionConstantValues::defaults(), - dev.profile(), - &twins, - &mut meter(), - SPIRV_WORDS, - ) - .unwrap_or_else(|e| panic!("{what}: {e}")); - link_and_validate(&a, dev.profile()).unwrap_or_else(|e| panic!("{what}: {e}")); - let again = variant - .plan(&dev, &shape) - .unwrap_or_else(|e| panic!("{what}: {e}")); - assert_eq!(again.variant, plan.variant, "{what}"); - let (raw, own) = views(&variant, &again); - let formats: BTreeSet<_> = raw - .iter() - .chain(own.iter()) - .filter_map(view_of) - .map(|v| v.format) - .collect(); - assert_eq!( - formats, - BTreeSet::from([crate::metal::format::direct_format(twin).expect(&what)]), - "{what}" - ); - twinned += 1; - } - } - assert!( - twinned > 0, - "no committed profile samples a format only through its twin" - ); - assert!( - sampled_count > 0, - "no committed profile samples the formats" - ); -} - /// A render pipeline: a vertex function placing vertex `vid`, and a fragment function returning /// texel `(0, 0)` of its `texture2d` slot 0. const RENDER: &str = r#"define <{ <4 x float> }> @v(i32 noundef %vid) { @@ -1454,12 +1266,13 @@ declare { <4 x float>, i8 } @air.read_texture_2d.v4f32(ptr addrspace(1), ptr add !24 = !{i32 0, !"air.vertex_id", !"air.arg_type_name", !"uint", !"air.arg_name", !"vid"} "#; -/// A render pipeline's fragment slot bound in an 8-bit sRGB format joins the plan's variant; -/// `compile_render_variant` compiles it, its plan states the same key, and its fragment stage's -/// raw binding views the image in the UNORM format of the same channels. Another format leaves -/// the variant. +/// A render pipeline's fragment slot bound in an 8-bit sRGB format the device holds as its UNORM +/// twin (`RG8Unorm_sRGB` on lavapipe) joins the plan's variant; `compile_render_variant` compiles +/// it, its plan states the same key, and the fragment's binding views the twin. A format the +/// device samples (`RGBA8Unorm_sRGB` everywhere, `RG8Unorm_sRGB` on MoltenVK and RADV) joins +/// nothing, and the binding views the image in that sRGB format. #[test] -fn a_fragment_slot_bound_in_srgb_joins_the_render_variant() { +fn a_fragment_slot_bound_in_a_twin_joins_the_render_variant() { use crate::pipeline::descriptor::ColorAttachmentDescriptor; use crate::pipeline::RenderPipelineDescriptor; let Some(bc) = assemble("render", RENDER) else { @@ -1484,7 +1297,7 @@ fn a_fragment_slot_bound_in_srgb_joins_the_render_variant() { s.stages.insert(Stage::Fragment, f); s }; - let mut ran = 0; + let (mut ran, mut twinned) = (0, 0); for (stem, dev) in devices() { if !["lavapipe", "moltenvk-m3", "amd-rdna3-radv"].contains(&stem.as_str()) { continue; @@ -1500,216 +1313,40 @@ fn a_fragment_slot_bound_in_srgb_joins_the_render_variant() { let p = dev .compile_render_pipeline(&d, &Budget::standard()) .unwrap_or_else(|e| panic!("{stem}: {e}")); - let shape = state(PixelFormat::RGBA8UnormSRGB).shape(); - let plan = p.plan(&dev, &shape).expect("plan"); - assert_eq!( - plan.variant.srgb_textures, - BTreeSet::from([fragment]), - "{stem}" - ); - let own = plan - .descriptors - .iter() - .find_map(|w| match &w.source { - WriteSource::Texture { slot, view } if *slot == fragment => Some(*view), - _ => None, - }) - .unwrap_or_else(|| panic!("{stem}: no texture write")); - let variant = dev - .compile_render_variant(&d, &plan.variant, &Budget::standard()) - .unwrap_or_else(|e| panic!("{stem} variant: {e}")); - let again = variant.plan(&dev, &shape).expect("variant plan"); - assert_eq!(again.variant, plan.variant, "{stem}: a fixed point"); - let raw_binding = variant - .layout - .sets - .iter() - .flat_map(|s| &s.bindings) - .find(|b| b.source == BindingSource::RawTexture(fragment)) - .unwrap_or_else(|| panic!("{stem}: no raw binding")); - let raw = again - .descriptors - .iter() - .find(|w| (w.set, w.binding) == (0, raw_binding.binding)) - .and_then(|w| view_of(&w.source)) - .unwrap_or_else(|| panic!("{stem}: no raw view")); - assert_eq!(srgb_raw_view(own.format), Some(raw.format), "{stem}"); - assert_eq!( - (own.view_type, own.components, own.layout), - (raw.view_type, raw.components, raw.layout), - "{stem}" - ); - let other = state(PixelFormat::RGBA8Unorm).shape(); - assert!( - p.plan(&dev, &other) - .expect("plan") - .variant - .srgb_textures - .is_empty(), - "{stem}" - ); - } - assert_eq!(ran, 3); -} - -/// A kernel sampling texture slot 0 (`t`) and slot 1 (`u`) at its thread's texel through one -/// nearest constexpr sampler, with a `half` result, storing the sum to `out[gid.x + 16 gid.y]`. -fn two_texture_kernel() -> String { - let w = sampler_words(0, 0, false); - format!( - r#"@__air_sampler_state = internal addrspace(2) constant [2 x i64] [i64 {w}, i64 0], align 8 - -define void @k(ptr addrspace(1) %t, ptr addrspace(1) %out, ptr addrspace(1) %u, <2 x i32> %gid) {{ - %x = extractelement <2 x i32> %gid, i64 0 - %y = extractelement <2 x i32> %gid, i64 1 - %row = shl i32 %y, 4 - %n = add i32 %x, %row - %i = zext i32 %n to i64 - %fx = uitofp i32 %x to float - %fy = uitofp i32 %y to float - %cx = fadd float %fx, 0.5 - %cy = fadd float %fy, 0.5 - %c0 = insertelement <2 x float> zeroinitializer, float %cx, i64 0 - %c1 = insertelement <2 x float> %c0, float %cy, i64 1 - %uv = fmul <2 x float> %c1, - %r = call {{ <4 x half>, i8 }} @air.sample_texture_2d.v4f16(ptr addrspace(1) %t, ptr addrspace(2) @__air_sampler_state, <2 x float> %uv, i1 true, <2 x i32> zeroinitializer, i1 false, float 0.0, float 0.0, i32 0) - %v = extractvalue {{ <4 x half>, i8 }} %r, 0 - %r1 = call {{ <4 x half>, i8 }} @air.sample_texture_2d.v4f16(ptr addrspace(1) %u, ptr addrspace(2) @__air_sampler_state, <2 x float> %uv, i1 true, <2 x i32> zeroinitializer, i1 false, float 0.0, float 0.0, i32 0) - %v1 = extractvalue {{ <4 x half>, i8 }} %r1, 0 - %s = fadd <4 x half> %v, %v1 - %q = getelementptr inbounds <4 x half>, ptr addrspace(1) %out, i64 %i - store <4 x half> %s, ptr addrspace(1) %q, align 8 - ret void -}} - -declare {{ <4 x half>, i8 }} @air.sample_texture_2d.v4f16(ptr addrspace(1), ptr addrspace(2), <2 x float>, i1, <2 x i32>, i1, float, float, i32) - -!air.kernel = !{{!0}} -!air.sampler_states = !{{!5}} -!0 = !{{ptr @k, !1, !2}} -!1 = !{{}} -!2 = !{{!3, !4, !6, !7}} -!3 = !{{i32 0, !"air.texture", !"air.location_index", i32 0, i32 1, !"air.sample", !"air.arg_type_name", !"texture2d", !"air.arg_name", !"t"}} -!4 = !{{i32 1, !"air.buffer", !"air.location_index", i32 0, i32 1, !"air.read_write", !"air.address_space", i32 1, !"air.arg_type_size", i32 8, !"air.arg_type_align_size", i32 8, !"air.arg_type_name", !"half4", !"air.arg_name", !"out"}} -!5 = !{{!"air.sampler_state", ptr addrspace(2) @__air_sampler_state}} -!6 = !{{i32 2, !"air.texture", !"air.location_index", i32 1, i32 1, !"air.sample", !"air.arg_type_name", !"texture2d", !"air.arg_name", !"u"}} -!7 = !{{i32 3, !"air.thread_position_in_grid", !"air.arg_type_name", !"uint2", !"air.arg_name", !"gid"}} -"# - ) -} - -/// A stage past its sampler limit takes its combined bindings apart, a raw view's included: under -/// slot 0's variant, with one sampler per stage, slot 0's raw view and slot 1's own view are two -/// separate textures, their symbols distinct by the raw view's bit, sampled through the one -/// separate sampler of their shared use. The binder writes slot 0's separate texture with the UNORM -/// view of its 8-bit sRGB image and slot 1's with its own view. -#[test] -fn a_raw_view_past_the_sampler_limit_is_its_own_separate_texture() { - use crate::pipeline::sym::CombinedSampler; - let Some(bc) = assemble("two textures", &two_texture_kernel()) else { - return; - }; - let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) - .join("../metal2vulkan-validation/profiles/moltenvk-m3.json"); - let text = std::fs::read_to_string(path).expect("profile"); - let mut desc = DeviceDescription::from_khronos_json(&text, None).expect("description"); - desc.limits.max_per_stage_descriptor_samplers = 1; - let dev = Device::new(desc, DevicePolicy::default()).expect("device"); - let (_, m) = typed_module_with(&bc, "k", dev.profile(), &inputs(true)).expect("module"); - let (mut textures, mut samplers) = (Vec::new(), Vec::new()); - for g in m.globals() { - let GlobalKind::Resource(s) = g.kind else { - continue; - }; - assert!( - !matches!(s.kind, ResourceKind::CombinedTextureSampler(_)), - "{s:?}" - ); - textures.extend(s.separate_texture_of()); - samplers.extend(s.separate_sampler_use()); - } - textures.sort(); - let own: Vec = samplers.clone(); - assert_eq!(own.len(), 1, "{samplers:?}"); - let own = own[0]; - assert!(!own.raw); - assert_eq!(textures, vec![(0, own.with_raw(true)), (1, own)]); - - let p = pipeline(&dev, &bc, &inputs(true)); - let mut t = StageTable::default(); - for (slot, pf) in [ - (0, PixelFormat::RGBA8UnormSRGB), - (1, PixelFormat::RGBA8Unorm), - ] { - let mut facts = TextureFacts::new(TextureType::Type2D, pf); - facts.usage = metal::TextureUsage::SHADER_READ; - t.textures.insert( - slot, - BoundTexture::Texture { - facts, - resource_id: None, - }, - ); - } - t.buffers.insert( - 0, - BoundBuffer::Buffer { - length: 4096, - offset: 0, - gpu_address: 0x1_0000, - device_address: None, - attribute_stride: None, - }, - ); - let mut s = BindState::default(); - s.stages.insert(Stage::Kernel, t); - let plan = p.plan(&dev, &s.shape()).expect("plan"); - assert_eq!(plan.variant.srgb_textures, BTreeSet::from([TEXTURE])); - let mut seen = BTreeMap::new(); - for set in &p.layout.sets { - for b in &set.bindings { - if let BindingSource::SeparateTexture { texture, sampler } = b.source { - let w = plan - .descriptors - .iter() - .find(|d| d.set == set.set && d.binding == b.binding) - .unwrap_or_else(|| panic!("no write for {texture:?}")); - let WriteSource::Texture { view, .. } = &w.source else { - panic!("{texture:?}: {:?}", w.source); - }; - seen.insert((texture.index, sampler.raw), view.format); + for pf in [PixelFormat::RGBA8UnormSRGB, PixelFormat::RG8UnormSRGB] { + let what = format!("{stem} {pf:?}"); + let shape = state(pf).shape(); + let plan = p.plan(&dev, &shape).expect("plan"); + let views = slot_views(&plan, fragment); + assert_eq!(views.len(), 1, "{what}: {views:?}"); + if !srgb_twin_on(pf, dev.profile()) { + assert!(plan.variant.srgb_textures.is_empty(), "{what}"); + let sampled = crate::metal::format::vk_format( + pf, + &[FormatUsage::SampledImage].into(), + dev.profile(), + ) + .unwrap_or_else(|e| panic!("{what}: {e}")); + assert_eq!(views[0].format, sampled.format, "{what}"); + continue; } + assert_eq!( + plan.variant.srgb_textures, + BTreeSet::from([fragment]), + "{what}" + ); + let held = crate::metal::format::srgb_raw_twin(pf) + .and_then(crate::metal::format::direct_format); + assert_eq!(Some(views[0].format), held, "{what}"); + let variant = dev + .compile_render_variant(&d, &plan.variant, &Budget::standard()) + .unwrap_or_else(|e| panic!("{what} variant: {e}")); + let again = variant.plan(&dev, &shape).expect("variant plan"); + assert_eq!(again.variant, plan.variant, "{what}: a fixed point"); + assert_eq!(slot_views(&again, fragment), views, "{what}"); + twinned += 1; } } - let own_format = |pf: PixelFormat| { - let plain = pipeline(&dev, &bc, &inputs(false)); - let mut t = StageTable::default(); - let mut facts = TextureFacts::new(TextureType::Type2D, pf); - facts.usage = metal::TextureUsage::SHADER_READ; - t.textures.insert( - 0, - BoundTexture::Texture { - facts, - resource_id: None, - }, - ); - let mut s = BindState::default(); - s.stages.insert(Stage::Kernel, t); - let plan = plain.plan(&dev, &s.shape()).expect("plan"); - plan.descriptors - .iter() - .find_map(|d| match &d.source { - WriteSource::Texture { view, slot } if slot.index == 0 => Some(view.format), - _ => None, - }) - .expect("the own view") - }; - let srgb = own_format(PixelFormat::RGBA8UnormSRGB); - assert_eq!( - seen, - BTreeMap::from([ - ((0, true), srgb_raw_view(srgb).expect("a raw view")), - ((1, false), own_format(PixelFormat::RGBA8Unorm)), - ]) - ); + assert_eq!(ran, 3); + assert!(twinned > 0, "lavapipe holds no twin"); } diff --git a/crates/metal2vulkan/src/tests/fast_paths.rs b/crates/metal2vulkan/src/tests/fast_paths.rs index 3bd84431b..8d91b434c 100644 --- a/crates/metal2vulkan/src/tests/fast_paths.rs +++ b/crates/metal2vulkan/src/tests/fast_paths.rs @@ -116,6 +116,7 @@ fn notes() -> Vec<(&'static str, Ledger)> { DeviceSampling, DeviceTexelConversion, HalfTexelConversion, + SrgbTexelDecode, DeviceVertexConversion, RestrictedDepthRange, DeviceSignedZeroInfNan, @@ -149,7 +150,6 @@ fn notes() -> Vec<(&'static str, Ledger)> { DeviceNanEncoding, CubeGradientFootprint, HalfSampleFilter, - SrgbTexelDecode, FloatSampleFilter, QuadsCountedBeforeDiscard, ViewBaseTexelOffset, diff --git a/crates/metal2vulkan/src/tests/mod.rs b/crates/metal2vulkan/src/tests/mod.rs index a28c0b37f..9c7085df2 100644 --- a/crates/metal2vulkan/src/tests/mod.rs +++ b/crates/metal2vulkan/src/tests/mod.rs @@ -136,7 +136,7 @@ mod engine_sparse_unmapped; mod engine_spec_bits; mod engine_specialized; mod engine_spirv_cross_forms; -mod engine_srgb_raw; +mod engine_srgb_decode; mod engine_stage_io; mod engine_stage_io_tail; mod engine_stage_root_attributes; diff --git a/crates/metal2vulkan/tests/api_signatures.tsv b/crates/metal2vulkan/tests/api_signatures.tsv index fd25dbca7..f407dd57f 100644 --- a/crates/metal2vulkan/tests/api_signatures.tsv +++ b/crates/metal2vulkan/tests/api_signatures.tsv @@ -3627,7 +3627,6 @@ field metal2vulkan::cache::VariantKey.shader_stencil pub shader_stencil: bool field metal2vulkan::cache::VariantKey.shader_tests pub shader_tests: bool field metal2vulkan::cache::VariantKey.snapshot_textures pub snapshot_textures: BTreeMap field metal2vulkan::cache::VariantKey.srgb_textures pub srgb_textures: BTreeSet -field metal2vulkan::cache::VariantKey.srgb_twins pub srgb_twins: BTreeSet field metal2vulkan::cache::VariantKey.storage_images pub storage_images: BTreeMap field metal2vulkan::cache::VariantKey.storage_view_slots pub storage_view_slots: BTreeSet field metal2vulkan::cache::VariantKey.swizzled_storage pub swizzled_storage: BTreeSet @@ -4020,7 +4019,6 @@ field metal2vulkan::pipeline::ColorGroup.width pub width: u32 field metal2vulkan::pipeline::CombinedSampler.compare pub compare: bool field metal2vulkan::pipeline::CombinedSampler.cube_gradient pub cube_gradient: bool field metal2vulkan::pipeline::CombinedSampler.integer pub integer: bool -field metal2vulkan::pipeline::CombinedSampler.raw pub raw: bool field metal2vulkan::pipeline::CombinedSampler.sampler pub sampler: SamplerRef field metal2vulkan::pipeline::CommandWrites.operations pub operations: u32 field metal2vulkan::pipeline::CommandWrites.primitive_types pub primitive_types: u8 @@ -4196,9 +4194,7 @@ field metal2vulkan::pipeline::LoweringInputs.shader_stencil pub shader_stencil: field metal2vulkan::pipeline::LoweringInputs.shader_tests pub shader_tests: bool field metal2vulkan::pipeline::LoweringInputs.signed_color_attachments pub signed_color_attachments: BTreeSet field metal2vulkan::pipeline::LoweringInputs.snapshot_textures pub snapshot_textures: BTreeMap -field metal2vulkan::pipeline::LoweringInputs.srgb_fetches pub srgb_fetches: BTreeSet field metal2vulkan::pipeline::LoweringInputs.srgb_textures pub srgb_textures: BTreeSet -field metal2vulkan::pipeline::LoweringInputs.srgb_twins pub srgb_twins: BTreeSet field metal2vulkan::pipeline::LoweringInputs.stage_input pub stage_input: Option field metal2vulkan::pipeline::LoweringInputs.storage_images pub storage_images: BTreeMap field metal2vulkan::pipeline::LoweringInputs.storage_view_slots pub storage_view_slots: BTreeSet @@ -8903,10 +8899,8 @@ method metal2vulkan::pipeline::ColorGroup::width_on pub fn width_on(profile: &cr method metal2vulkan::pipeline::CombinedSampler::from_heap_index pub fn from_heap_index(sampler: SamplerRef, index: u32) -> CombinedSampler method metal2vulkan::pipeline::CombinedSampler::heap_index pub fn heap_index(&self) -> u32 method metal2vulkan::pipeline::CombinedSampler::new pub fn new(sampler: SamplerRef, compare: bool, integer: bool) -> CombinedSampler -method metal2vulkan::pipeline::CombinedSampler::sampler_binding_use pub fn sampler_binding_use(self) -> CombinedSampler method metal2vulkan::pipeline::CombinedSampler::sampler_use pub fn sampler_use(&self) -> crate::metal::sampler::SamplerUse method metal2vulkan::pipeline::CombinedSampler::with_cube_gradient pub fn with_cube_gradient(self, cube_gradient: bool) -> CombinedSampler -method metal2vulkan::pipeline::CombinedSampler::with_raw pub fn with_raw(self, raw: bool) -> CombinedSampler method metal2vulkan::pipeline::CommandWrites::is_empty pub const fn is_empty(self) -> bool method metal2vulkan::pipeline::CommandWrites::may pub const fn may(self, bits: u32) -> bool method metal2vulkan::pipeline::CommandWrites::may_draw_primitive_type pub const fn may_draw_primitive_type(self, raw: u32) -> bool @@ -13366,7 +13360,6 @@ variant metal2vulkan::pipeline::BindingSource::ExtendedShadow ExtendedShadow(u32 variant metal2vulkan::pipeline::BindingSource::Heap Heap(HandleClass) variant metal2vulkan::pipeline::BindingSource::HeapSampler HeapSampler { stage: Stage, sampler: CombinedSampler } variant metal2vulkan::pipeline::BindingSource::InputAttachment InputAttachment(u32) -variant metal2vulkan::pipeline::BindingSource::RawTexture RawTexture(SlotRef) variant metal2vulkan::pipeline::BindingSource::Sampler Sampler(SlotRef) variant metal2vulkan::pipeline::BindingSource::SeparateSampler SeparateSampler { stage: Stage, sampler: CombinedSampler } variant metal2vulkan::pipeline::BindingSource::SeparateTexture SeparateTexture { texture: SlotRef, sampler: CombinedSampler } @@ -13572,7 +13565,6 @@ variant metal2vulkan::pipeline::ResourceKind::ExtendedShadow ExtendedShadow(u32) variant metal2vulkan::pipeline::ResourceKind::Heap Heap(HandleClass) variant metal2vulkan::pipeline::ResourceKind::HeapSampler HeapSampler(SamplerRef) variant metal2vulkan::pipeline::ResourceKind::InputAttachment InputAttachment(u32) -variant metal2vulkan::pipeline::ResourceKind::RawTexture RawTexture variant metal2vulkan::pipeline::ResourceKind::Sampler Sampler variant metal2vulkan::pipeline::ResourceKind::SeparateSampler SeparateSampler(SamplerRef) variant metal2vulkan::pipeline::ResourceKind::SeparateTexture SeparateTexture(SamplerRef) @@ -13642,7 +13634,6 @@ variant metal2vulkan::pipeline::RuntimeFact::ShadowStencil ShadowStencil { forma variant metal2vulkan::pipeline::RuntimeFact::SimdgroupEmulation SimdgroupEmulation { bytes_per_simdgroup: u32, arena: Option } variant metal2vulkan::pipeline::RuntimeFact::SparseTexture SparseTexture { slot: SlotRef, sparse_arm: bool, tile_map: bool } variant metal2vulkan::pipeline::RuntimeFact::SparseTextureWrites SparseTextureWrites { slot: SlotRef, atomic: bool } -variant metal2vulkan::pipeline::RuntimeFact::SrgbDeviceDecode SrgbDeviceDecode { slot: SlotRef } variant metal2vulkan::pipeline::RuntimeFact::SrgbTexture SrgbTexture { slot: SlotRef } variant metal2vulkan::pipeline::RuntimeFact::StageInRegion StageInRegion variant metal2vulkan::pipeline::RuntimeFact::StageInStride StageInStride { layout: u32 } diff --git a/docs/API.md b/docs/API.md index 3f8238749..edd860795 100644 --- a/docs/API.md +++ b/docs/API.md @@ -838,7 +838,8 @@ Textures follow Metal's texel rules: sparse textures report residency where the `Depth32Float` texels are the device's depth image's (a value it clamps or a denormal it flushes is announced, `restricted-depth-upload`, `depth-denormals`), `ulong` textures and their atomics use 64-bit images where the device has them, and `half` and sRGB reads give Metal's values or record -their bound. The +their bound (an sRGB texel is the device's own decode wherever the device samples its format, +`srgb-texel-decode`). The rustdoc of `BindState`, `TextureFacts` and `BindingPlan` states each rule. ## 6. At bind time @@ -2283,12 +2284,12 @@ bound. on random blocks of every format; a driver not named is unmeasured, and validation derives no tolerance from them. Cost: a read, sample or gather of its texels answers the device's decode of its blocks (an sRGB - form's code through Metal's table), where Metal interpolates with 6-bit weights: a BC1 to BC3 - channel up to 3/255 off Metal's on NVIDIA (615.71.09, the RTX 3090 and RTX 5080 Laptop GPU; BC3's - alpha 6/255) and lavapipe, 1/255 on ANV; a BC4 or BC5 channel up to 7.3/255 (signed 0.064) on - NVIDIA, 1.3/255 (signed 0.013) on ANV, 2.4/255 (signed 0.022) on lavapipe, and on RADV (Mesa - 26.2.4, the Radeon 780M) a signed texel with an endpoint of -128 up to 1.7/255; a BC7 channel a - `float` ulp on lavapipe; its blocks' bytes, copies and sizes are Metal's. + form's code through the device's sRGB decode), where Metal interpolates with 6-bit weights: a BC1 + to BC3 channel up to 3/255 off Metal's on NVIDIA (615.71.09, the RTX 3090 and RTX 5080 Laptop + GPU; BC3's alpha 6/255) and lavapipe, 1/255 on ANV; a BC4 or BC5 channel up to 7.3/255 (signed + 0.064) on NVIDIA, 1.3/255 (signed 0.013) on ANV, 2.4/255 (signed 0.022) on lavapipe, and on RADV + (Mesa 26.2.4, the Radeon 780M) a signed texel with an endpoint of -128 up to 1.7/255; a BC7 + channel a `float` ulp on lavapipe; its blocks' bytes, copies and sizes are Metal's. - `metal2vulkan-degrade-cpu-block-decode` (performance). `CpuBlockDecode`: A CPU copy into a texture with a decoded twin (`replace_region`) whose CPU copies go on the host or the staging queue: its region is decoded on the CPU, on the device's decode thread, and copied into the twin; the first @@ -2330,8 +2331,8 @@ bound. texels answers the nearest 8-bit code to Metal's 12-bit value, at most 1/510 off it; an EAC 11-bit texture's, the nearest 16-bit normalized code to Metal's 11-bit value, at most half a 16-bit step off it (Metal reads an EAC 11-bit channel as `c / 2047`, signed `c / 1023`). An ASTC sRGB - texture's twin holds Metal's own 8-bit codes, which its slots decode through Metal's table: - exact. + texture's twin holds Metal's own 8-bit codes, which its slots read through the twin's sRGB view, + the device's decode (`srgb-texel-decode`). - `metal2vulkan-degrade-shared-present-queue` (performance). `SharedPresentQueue`: A command queue made for presenting (`Device::new_command_queue_for_presenting`) on a device that reserved no `VkQueue` for presenting: its queue family has no queue past the ones the round robin takes @@ -2729,7 +2730,12 @@ bound. - `metal2vulkan-degrade-srgb-texel-decode` (precision). `PrecisionNote::SrgbTexelDecode`: The module reads, samples, or gathers a texture with a `half` or `float` result through the device's sRGB decode, or decodes the device's filter of its codes, where the texture may be bound in an 8-bit - sRGB format. + sRGB format. The device's decode is the only form wherever it samples the format (an 8-bit sRGB + format, or the sRGB form of a BC, PVRTC, ETC2, EAC or ASTC format, through the texture's or its + decoded twin's sRGB view), so it is announced at a draw or dispatch that binds such a texture, + at an argument buffer's texture access, and at a render pipeline that reads an sRGB color + attachment as an input attachment; never on MoltenVK, whose decode is Metal's own. Where the + device holds the format as its UNORM twin, only a filtered sample announces it. - `metal2vulkan-degrade-float-sample-filter` (precision). `PrecisionNote::FloatSampleFilter`: The module samples a texture with a `float` result through a filter that Metal's own sampler (MoltenVK) answers otherwise than Metal filters the format bound there: a two-plane YCbCr diff --git a/docs/CONFORMANCE-COVERAGE.md b/docs/CONFORMANCE-COVERAGE.md index dcae09c41..b2af9050d 100644 --- a/docs/CONFORMANCE-COVERAGE.md +++ b/docs/CONFORMANCE-COVERAGE.md @@ -44,7 +44,7 @@ Its limits, measured rather than asserted: | committed recordings | 1122 | | distinct SDK items the Metal leg reaches, of any status | 800 | | of those, reached only where this cannot name the family | 2 | -| ledger rows (a case whose gap is recorded) | 882 | +| ledger rows (a case whose gap is recorded) | 903 | | declared crossings of the option space (pairs put to Metal at once) | 26 | | declared crossings that are no pair of it (a boolean or numeric field, or one type in two slots) | 30 | @@ -2683,20 +2683,20 @@ A case whose difference from Metal is recorded rather than compared away. The le | `fetch-ordered-bgra8unorm-red-alpha` | A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's store… | | `fetch-ordered-bgra8unorm-red-alpha` | A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's store… | | `fetch-ordered-bgra8unorm-red-alpha` | A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's store… | -| `fetch-ordered-bgra8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device enc… | -| `fetch-ordered-bgra8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device enc… | -| `fetch-ordered-bgra8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device enc… | -| `fetch-ordered-bgra8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device enc… | +| `fetch-ordered-bgra8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function r… | +| `fetch-ordered-bgra8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function r… | +| `fetch-ordered-bgra8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function r… | +| `fetch-ordered-bgra8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function r… | | `fetch-ordered-rgba8unorm` | A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's store… | | `fetch-ordered-rgba8unorm` | A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's store… | | `fetch-ordered-rgba8unorm` | A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's store… | | `fetch-ordered-rgba8unorm-red-alpha` | A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's store… | | `fetch-ordered-rgba8unorm-red-alpha` | A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's store… | | `fetch-ordered-rgba8unorm-red-alpha` | A fragment function's colour write into an 8-bit unorm attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): Metal's store… | -| `fetch-ordered-rgba8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device enc… | -| `fetch-ordered-rgba8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device enc… | -| `fetch-ordered-rgba8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device enc… | -| `fetch-ordered-rgba8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the device enc… | +| `fetch-ordered-rgba8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function r… | +| `fetch-ordered-rgba8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function r… | +| `fetch-ordered-rgba8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function r… | +| `fetch-ordered-rgba8unorm-srgb` | A fragment function's colour write into an 8-bit sRGB attachment it also fetches (the `x1` to `x3` sites fetch and store it once to three times): the function r… | | `half-read-nans-r16f` | A `float` read or nearest sample of a 16-bit float texel's NaN: Metal answers its canonical `0x7FC00000`, and ours is this device's widening of the texel, which… | | `half-read-nans-r16f` | A `float` read or nearest sample of a 16-bit float texel's NaN: Metal answers its canonical `0x7FC00000`, and ours is this device's widening of the texel, which… | | `half-read-nans-rg16f` | A `float` read or nearest sample of a 16-bit float texel's NaN: Metal answers its canonical `0x7FC00000`, and ours is this device's widening of the texel, which… | @@ -3084,4 +3084,25 @@ A case whose difference from Metal is recorded rather than compared away. The le | `bc5-rg-snorm` | A BC5 signed texel read on lavapipe: Metal interpolates the channel's endpoints with 6-bit weights and answers its sum over 8128, unrounded; ours is the device'… | | `bc5-rg-snorm` | A BC5 signed texel read on lavapipe: Metal interpolates the channel's endpoints with 6-bit weights and answers its sum over 8128, unrounded; ours is the device'… | | `bc5-rg-snorm` | A BC5 signed texel read on lavapipe: Metal interpolates the channel's endpoints with 6-bit weights and answers its sum over 8128, unrounded; ours is the device'… | +| `etc2-rgb8-srgb` | A read of an ETC2 or EAC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code b… | +| `etc2-rgb8-srgb` | A read of an ETC2 or EAC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code b… | +| `etc2-rgb8a1-srgb` | A read of an ETC2 or EAC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code b… | +| `eac-rgba8-srgb` | A read of an ETC2 or EAC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code b… | +| `eac-rgba8-srgb` | A read of an ETC2 or EAC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code b… | +| `astc-4x4-srgb` | A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its o… | +| `astc-5x4-srgb` | A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its o… | +| `astc-5x5-srgb` | A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its o… | +| `astc-6x5-srgb` | A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its o… | +| `astc-6x6-srgb` | A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its o… | +| `astc-8x5-srgb` | A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its o… | +| `astc-8x6-srgb` | A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its o… | +| `astc-8x8-srgb` | A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its o… | +| `astc-10x5-srgb` | A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its o… | +| `astc-10x6-srgb` | A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its o… | +| `astc-10x8-srgb` | A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its o… | +| `astc-10x10-srgb` | A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its o… | +| `astc-12x10-srgb` | A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its o… | +| `astc-12x12-srgb` | A read of an ASTC sRGB form's texels through its decoded twin's `R8G8B8A8_SRGB` view, which holds Metal's own codes: the device decodes each 8-bit code by its o… | +| `read-write-tier-round-trip-float` | A read of the round-tripped 8-bit sRGB texels through the texture's sRGB view: the device decodes each 8-bit code by its own sRGB transfer function, where Metal… | +| `read-write-tier-round-trip-float` | A read of the round-tripped 8-bit sRGB texels through the texture's sRGB view: the device decodes each 8-bit code by its own sRGB transfer function, where Metal… | diff --git a/docs/FAST-PATHS.md b/docs/FAST-PATHS.md index 45438f55a..0366db515 100644 --- a/docs/FAST-PATHS.md +++ b/docs/FAST-PATHS.md @@ -57,11 +57,11 @@ known. The rest of the differences are docs/API.md section 9's precision notes. | `dot`, `mix` and `fast::sqrt` are the device's `OpDot`, `FMix` and `Sqrt`, not Metal's fused chain, its two fused multiply-adds and `x · rsqrt(x)`, on every device but MoltenVK, which takes Metal's order; a `dot` of other than two to four lanes sums the `OpDot` of each chunk of up to four lanes. | The device's order is the contract. | `float` `dot` of n lanes within (3n − 1)·2^-24·Σ\|aᵢbᵢ\|, `mix` within 2^-21 of its two terms, `fast::sqrt` 4.5 ulp. `NativeDot` (`native-dot`), `NativeMix` (`native-mix`), `NativeTranscendentals` (`native-transcendentals`); a `dot` of other than two to four lanes within Vulkan's precision of its chunks' `OpDot` and sum, `DeviceArithmetic` (`device-arithmetic`) | | Off MoltenVK a `float` multiply, and a fused multiply-add by `OpFmaKHR`, round before Metal's flush: Metal flushes a result whose exact value lies below `2^-126` before rounding it, so a result whose exact value lies within half a unit below `2^-126` answers `2^-126` of its sign where Metal answers the zero of its sign. | Every device measured off MoltenVK (RADV, ANV, NVIDIA, lavapipe) rounds first; its multiply is the contract. | Announced once per device as it is made: `float-tininess-after-rounding` | | `f32` denormals in a `float` operation on a device not measured to read them as Metal does (`DriverDeviation::MetalFloatDenormals`: lavapipe, and every unmeasured device), in `floor` and `ceil` on every device, in the maths functions and the device's order of the rows above, and in a conversion to or from `double`. Metal reads them as zero and flushes a denormal result. | The device's reading is the contract: Vulkan lets each device keep or flush them, and Metal runs no `double`, so its reading of a conversion is not measured. | `DeviceDenormals` (`device-denormals`) | -| Samples, gathers and depth comparisons are the device's own sampler's on every device whose sampler is not Metal's (every device but MoltenVK): its filter, footprint, level, anisotropy, sRGB decode and comparison. A two-plane YCbCr texture's linear sample is the device's filter of its texels, which hold Metal's reads exactly; where the device's memory is the host's, a sample that reads the planes in place is Metal's filter exactly. An 8-bit sRGB format the device cannot sample (`R8G8_SRGB` on NVIDIA) is held as its UNORM twin: a sample the raw codes do not serve is the device's filter of the codes, decoded through Metal's table. | The device's sampler is the contract. | Linear filter within one code (1/255) on the measured devices, sRGB within 1.83, a two-plane YCbCr texture's within 1.183; levels, anisotropy, cubes, 3D, gathers and comparisons unmeasured. A twin's filtered sample: exact for one texel and for a blend of two adjacent codes, up to 0.286 off for a blend of codes 0 and 255 (`SrgbTexelDecode`). `DeviceSampling` (`device-sampling`) | -| A texel's `float` value is the device's conversion of its codes, and a `half` result the device's `float` texel rounded to nearest even, on every device whose texture unit is not Metal's (every device but MoltenVK). | The device's conversion is the contract. | One `f32` ulp for 8- and 16-bit codes, 0.18 of a code for 5- and 6-bit packed channels; `half` within one ulp; NaN bits the device's. `DeviceTexelConversion` (`device-texel-conversion`), `HalfTexelConversion` (`half-texel-conversion`, also recorded for heap textures and unmeasured formats) | -| A texture of a BC format (`BC1_RGBA` to `BC7_RGBAUnorm_sRGB`) is the device's decode of its own BC image on every device: where its driver is not measured to decode the format as Metal does (BC1 to BC3 off MoltenVK and RADV on the 780M; BC4 and BC5 off MoltenVK; BC7 on lavapipe), its reads, samples and gathers answer the device's interpolation of the blocks, where Metal's weights are 6-bit (an sRGB form's code through Metal's table). No BC texture keeps a decoded twin. | The device has the format: its decode is the contract. | A BC1 to BC3 channel within 3/255 of Metal's on NVIDIA (BC3's alpha 6/255) and lavapipe, 1/255 on ANV; a BC4 or BC5 channel within 7.3/255 (signed 0.064) on NVIDIA, 1.3/255 (signed 0.013) on ANV, 2.4/255 (signed 0.022) on lavapipe, a signed one with an endpoint of -128 within 1.7/255 on RADV; a BC7 channel a `float` ulp on lavapipe; other drivers unmeasured. `CompressedTexelDecode` (`compressed-texel-decode`) | +| Samples, gathers and depth comparisons are the device's own sampler's on every device whose sampler is not Metal's (every device but MoltenVK): its filter, footprint, level, anisotropy, sRGB decode and comparison. A two-plane YCbCr texture's linear sample is the device's filter of its texels, which hold Metal's reads exactly; where the device's memory is the host's, a sample that reads the planes in place is Metal's filter exactly. An 8-bit sRGB format the device cannot sample (`R8_SRGB` on lavapipe, `R8G8_SRGB` on lavapipe, ANV and NVIDIA) is held as its UNORM twin, the device lacking its decode: a read, a nearest sample, a fetch, a gather and a bicubic tap decode the twin's codes through Metal's table, exactly, and a filtered sample is the device's filter of the codes, decoded through the table. | The device's sampler is the contract. | Linear filter within one code (1/255) on the measured devices, sRGB within 1.83, a two-plane YCbCr texture's within 1.183; levels, anisotropy, cubes, 3D, gathers and comparisons unmeasured. A twin's filtered sample: exact for one texel and for a blend of two adjacent codes, up to 0.286 off for a blend of codes 0 and 255 (`SrgbTexelDecode`). `DeviceSampling` (`device-sampling`) | +| A texel's `float` value is the device's conversion of its codes, and a `half` result the device's `float` texel rounded to nearest even, on every device whose texture unit is not Metal's (every device but MoltenVK). An sRGB texel (the 8-bit sRGB formats, and the sRGB forms of BC1 to BC3, BC7, PVRTC, ETC2, EAC and ASTC, a decoded twin's through its `R8G8B8A8_SRGB` view) is the device's sRGB decode through the texture's sRGB view, in every read, sample, gather, bicubic tap and input-attachment read, where Metal decodes each code through its twelve-bit table. | The device's conversion is the contract. | One `f32` ulp for 8- and 16-bit codes, 0.18 of a code for 5- and 6-bit packed channels; `half` within one ulp; NaN bits the device's. An sRGB decode: lavapipe's within 5.25 steps of Metal's table (0.00128) at every code, MoltenVK's Metal's at every code (`runtime_lane::srgb_decode`); Vulkan sets no precision for it, and other devices are not measured. `DeviceTexelConversion` (`device-texel-conversion`), `HalfTexelConversion` (`half-texel-conversion`, also recorded for heap textures and unmeasured formats), `SrgbTexelDecode` (`srgb-texel-decode`, under the bound format) | +| A texture of a BC format (`BC1_RGBA` to `BC7_RGBAUnorm_sRGB`) is the device's decode of its own BC image on every device: where its driver is not measured to decode the format as Metal does (BC1 to BC3 off MoltenVK and RADV on the 780M; BC4 and BC5 off MoltenVK; BC7 on lavapipe), its reads, samples and gathers answer the device's interpolation of the blocks, where Metal's weights are 6-bit (an sRGB form's code then through the device's sRGB decode, the texel-conversion row). No BC texture keeps a decoded twin. | The device has the format: its decode is the contract. | A BC1 to BC3 channel within 3/255 of Metal's on NVIDIA (BC3's alpha 6/255) and lavapipe, 1/255 on ANV; a BC4 or BC5 channel within 7.3/255 (signed 0.064) on NVIDIA, 1.3/255 (signed 0.013) on ANV, 2.4/255 (signed 0.022) on lavapipe, a signed one with an endpoint of -128 within 1.7/255 on RADV; a BC7 channel a `float` ulp on lavapipe; other drivers unmeasured. `CompressedTexelDecode` (`compressed-texel-decode`) | | A vertex attribute that fixed-function vertex input fetches is the device's conversion of its format: a normalized one (`UCharNormalized` through `Short4Normalized` of either sign, `UChar4Normalized_BGRA`, `Int1010102Normalized`, `UInt1010102Normalized`) through its own Vulkan `UNORM` or `SNORM` vertex format, where Metal divides each code by its maximum correctly rounded (an `Int1010102Normalized` 10-bit field it multiplies by `float(1 / 511)` in `float`) and rounds the quotient once to a `half` attribute; a narrow float's (a `half` format, `FloatRG11B10`) read as `float` by the device's widening, NaNs included. The format is `VertexAttribute` state that no instruction names, so every format the device fetches shares one module, and the render pipeline's link notes the conversion on its vertex stage (`pipeline::link::vertex`). **Exempt:** a normalized attribute on a profile that takes `DriverDeviation::MetalNormalizedVertexFetch`, MoltenVK on Apple's GPUs of the Apple M3 Max's macOS 27 identity, which hands the format to Metal's own fetch and was measured to answer Metal's `float` at every code of all 19 normalized formats, per vertex and per instance (`runtime_lane::normalized_vertex_fetch`): its pipeline records no note and requires `VkProperty::MetalNormalizedVertexFetch`, but for a 16-bit format read as `half`, whose `float` the module rounds to `half` again. | The device's conversion is the contract. | One `f32` ulp at some codes on a driver that multiplies by the reciprocal: llvmpipe, read at every code (Mesa 26.0.8 on LLVM 21.1.8, arm64), is within one ulp per vertex at every normalized format (127/255 as `0x3EFEFF00` where Metal reads `0x3EFEFEFF`; `Int1010102Normalized` Metal's), and per instance reads the most negative code of an 8- or 16-bit signed format unclamped (-128/127, -32768/32767) where Metal reads -1; RADV's unsigned formats are Metal's at the sites measured. A 16-bit format read as `half`: one `half` ulp at codes 65455 and 65519 unsigned, 32759 and -32759 signed, on a device whose `float` is Metal's (the quotient rounded to `half` twice). The signed formats are **unaudited** on RADV, ANV and NVIDIA. A narrow float's NaN is the device's widening's, where Metal answers `0x7fc00000`. `DeviceVertexConversion` (`device-vertex-conversion`), `DeviceNanEncoding` (`device-nan-encoding`) | -| A texture of an ASTC LDR format on a device without that ASTC format reads a decoded twin of 8-bit codes, each channel the code nearest Metal's 12-bit value (`C >> 4` over 4095); an sRGB form's twin holds Metal's own 8-bit codes, which its slots decode through Metal's table, exactly. A texture of an EAC 11-bit format (`R11`, `RG11`, unsigned and signed) on a device without ETC2 reads one of 16-bit normalized codes, each nearest Metal's value (`c / 2047`, signed `c / 1023`). | The device lacks the format; the twin's codes are the compact form the device samples. | Within 1/510 of Metal's value; an EAC 11-bit channel within half a 16-bit step (1/131070, signed 1/65534). `decoded-texel-precision`, announced where such a texture is made | +| A texture of an ASTC LDR format on a device without that ASTC format reads a decoded twin of 8-bit codes, each channel the code nearest Metal's 12-bit value (`C >> 4` over 4095); an sRGB form's twin holds Metal's own 8-bit codes, which its slots read through the twin's `R8G8B8A8_SRGB` view, the device's sRGB decode (the texel-conversion row). A texture of an EAC 11-bit format (`R11`, `RG11`, unsigned and signed) on a device without ETC2 reads one of 16-bit normalized codes, each nearest Metal's value (`c / 2047`, signed `c / 1023`). | The device lacks the format; the twin's codes are the compact form the device samples. | Within 1/510 of Metal's value; an EAC 11-bit channel within half a 16-bit step (1/131070, signed 1/65534). `decoded-texel-precision`, announced where such a texture is made | | `generate_mipmaps` of a filtered format is the device's filter of each level at the scaled texel centres: its blit chain (`vkCmdBlitImage` with `VK_FILTER_LINEAR`) where its blits filter the image's format, else the runtime's bilinear (trilinear in 3D) compute filter in `float` (an extended-range format, an 8-bit sRGB texture held as its UNORM twin, a format without blits or linear filtering). An integer format's texels are picked as plain Metal picks them, exactly. | The device's filter is the contract; Apple's datapath is not modelled, and its answers differ between Apple's GPUs. | `DeviceFilteredMipmaps` (`device-filtered-mipmaps`) | | Depth values outside [0, 1] stored clamped (RADV, ANV) on a device without `VK_EXT_depth_range_unrestricted`. | Vulkan leaves them undefined without the extension: enable it. | `RestrictedDepthRange` (`restricted-depth-range`) | | A multisampled 32-bit float depth written by a blit copy from a buffer or a colour texture, or a separate depth texture's copies to and from its pass's scratch image, on a device whose depth/colour copies are missing or wrong (lavapipe, MoltenVK, NVIDIA's GA10x, a device without `VK_KHR_maintenance8`): the values its driver's fragment depth changes (MoltenVK's, NVIDIA's), or on a driver not measured may change (outside [0, 1], denormals, -0), land changed. | Vulkan writes a multisampled depth image's samples by no other means there but a clear; a driver measured to store every fragment depth unchanged (lavapipe's measured releases) is exact. | `DrawnDepthCopy` (`drawn-depth-copy`) | @@ -507,10 +507,6 @@ driver's. Each is open work. compute encoder its unit of command predication reaches past, which is one whose unit laid a step before it opened or one of its own that the unit's later encoders read, and one whose unit laid a loop or left work out; work on the GPU alone) fail `EncodedUseRebound` (announced). -- **A runtime sampler's nearest sample of an 8-bit sRGB texture.** On a device that samples the - format, the sample keeps the device's sRGB decode (announced as `SrgbTexelDecode`), where the - table's exact decode of the one texel it reads would cost little: the function does not know the - bound sampler's filter, and a variant keyed on a nearest sampler's word is not built. - **A fetched or resolved packed 16-bit attachment on a device that does not render the format** (`A1BGR5Unorm`, `ABGR4Unorm` on the RTX 5080). Its word view (`WordAttachment`) takes writes (blended and partly masked ones through the pixel interlock, the row above); a color input or @@ -557,8 +553,8 @@ driver's. Each is open work. this crate holds, and no Vulkan format applies the sRGB transfer function to the three channels Metal's does -- every Vulkan `_SRGB` format encodes the word's low three and leaves the fourth linear, and Metal's alpha is the low byte here, which a view's component mapping cannot move - because format conversion runs before the swizzle. Holding it needs the raw-code sRGB decode in - the shader (`metal::texel_format::srgb_raw`) as the only read of it. + because format conversion runs before the swizzle. Holding it needs a shader-side decode of its + codes through Metal's table (`lower::arith::srgb`), as a UNORM twin's are, as the only read of it. - **`BGRA4Unorm` as a render target on a device that does not render its word.** Its texel is `A4R4G4B4_UNORM_PACK16`'s word bit for bit (core 1.3, or `VK_EXT_4444_formats`), and a device exposing neither is refused the version or the extension at the format's first use. The two