Files
metal2vulkan/docs
Anees Iqbal 245b51ef7a Read NVIDIA's 10-bit two-plane codes through Metal's arithmetic, and judge the YCbCr lanes by the device's bounds
On the RTX 5080 Laptop GPU (NVIDIA 615.71.09, Linux), development failed 27 of the YCbCr
validation tests (runtime_lane::ycbcr_textures 22, ycbcr_minify 2, ycbcr_in_place 2,
dma_buf_imports' YCbCr test).

Bisect on the 5080, each step built on its own, with the filters
test(/runtime_lane::ycbcr/) | test(/dma_buf_imports::a_ycbcr/):
- cdf59197cc and d4412c9c95: 46 of 46.
- 70068f7cc0 (device colour writes; b7a62be64b, its parent, not split off): both
  ycbcr_minify tests. Their RGBA8 draw is now the device's colour conversion
  (device-color-conversion), so Metal's hash cannot hold.
- 78ed264c90's packet, which deleted the exact YCbCr filter and exact texel conversion
  (78ed264c90 alone does not build; 3c129f4d6f fails 16; 6e0e108d01 re-judges some lanes).
  2ec1f9fdc8 fails 7: the minify samples, 10-bit codes, 10-bit linear samples held to Metal's
  rounded step, and one in-place linear check.
- a1f1677174 (the device's own Y'CbCr conversion on discrete GPUs) takes it to 27.
None of this is from the current round.

Causes and fixes:
- Product: NVIDIA's conversion of G10X6_B10X6R10X6_2PLANE_{420,422,444}_UNORM_3PACK16 reads
  each word's six unused low bits. Vulkan says those bits do not take part: the format holds
  "a 10-bit G component in the top 10 bits of each 16-bit word ... with the bottom 6 bits of
  each word unused", and with image and view formats the same, "these bits will be unused by
  format conversion". Measured on the 5080: within 0.0001/2048 of Vulkan's conversion where
  the low bits are 0, and up to 6.43/2048 off where they are random. Those random-bit reads lie
  within 0.034/2048 of the word read as the code with six bits of fraction. NVIDIA now takes the
  TenBitCodesReadAsWords row (as lavapipe and RADV do), so a 10-bit two-plane texture converts
  through Metal's arithmetic there. Its 8-bit layouts keep the device's conversion. Nothing is
  refused. RUNTIME_VERSION 1708.
- NVIDIA widens a 10-bit UNORM code (the codes image's A2B10G10R10_UNORM_PACK32) by replicating
  its bits to 16: (c << 6 | c >> 4) / 65535. That lies within 0.0144 of a code of c / 1023
  (1.41e-5 absolute, inside Vulkan's "accurate to about 1 part in 10^5" for computation outside
  shaders). It is recorded in PrecisionNote::DeviceTexelConversion's bound, the runtime's
  catalogue, docs/API.md and the ledger row. The lanes' code checks accept that form exactly,
  within one f32 ulp, and still name the code.
- The lanes were never calibrated for textures the device converts itself (8-bit 4:2:0 and
  4:2:2 here). Where WorkCounts::ycbcr_device_conversions moves, a lane now holds each texel to
  Vulkan's conversion within the device's bound (ycbcr_device_reads), a code-reading texture
  to the nearest codes of its reconstruction, and expects ycbcr-filter-not-exact once.
  Elsewhere it still holds Metal's steps exactly.
- With the exact filter deleted, a kept image's linear sample on a natively sampling device is
  the device's filter. The lanes held it to Metal's rounded step within 0.5 codes. Metal's step
  rounds each tap's term, and NVIDIA's sub-texel snapping ("Sub-texel values calculated during
  image sampling will snap to these locations") moves the sum by a 1/256 step of the taps'
  difference. So the filter is now held to the texels' weighted sum within one code, the bound
  the DeviceSampling note records for a linear filter, scaled by the taps' spread where it
  passes 1 (sRGB twins' linear values past [0, 1]). The 5080 lay up to 0.548 codes off. The
  DeviceSampling note records its 0.56 against Metal's sum over 10-bit and packed textures.
- ycbcr_minify on such a device compares the bands, the grid and the draw bit for bit with the
  same kernels and draw over an RGBA16Float texture of the read() texels, whose hash is still
  Metal's. In-place and Metal-sampler devices keep Metal's hashes.
- tests::ycbcr_device: a code-reading format's ties may round either way, within half a code.

Verified on the tree of this commit:
- msi-laptop, RTX 5080 Laptop GPU, NVIDIA 615.71.09, --cfg m2v_gpu, NVIDIA ICD:
  metal2vulkan-validation test(/runtime_lane::ycbcr/) | test(/dma_buf_imports::a_ycbcr/)
  46 of 46 (every one of the 27 included); metal2vulkan-runtime test(/ycbcr|chroma|
  driver_defects/) 16 of 16. The device-converted reads lay within 0.0337/2048 of Vulkan's.
  The minify twin comparisons ran (14 outputs).
- This M3 Max, MoltenVK 1.4.2, macOS 27.0.1, under memcap and maclock, test(/ycbcr/) over
  the runtime and validation crates: 50 of 51. The failure,
  a_ycbcr_sample_through_an_unmeasured_filter_is_announced ("anisotropic through
  Constexpr(...): left None, right Some(1)" for YCbCrFilterNotExact), predates this change
  (same at daf1bf625f).
- A check that fails without the fix: before the row, the 5080 failed
  textures_over_any_surface_read_what_metal_reads,
  four_two_two_and_four_four_four_textures_read_what_metal_reads,
  four_two_two_and_four_four_four_views_read_their_twins_texels and
  a_four_four_four_texture_s_writes_store_metal_s_codes (10-bit reads past the device's
  0.04/2048 bound). The row alone made them pass there.
- clippy --workspace --all-targets --all-features -D warnings, plain and --cfg m2v_gpu; rustdoc
  -D warnings for metal2vulkan and the runtime; host tests of driver_defects, fast_paths, the
  degradation catalogue, api_signatures, api_surface and the refusal surface: 115 passed.
Not run: lavapipe and RADV (no venue here). They are expected to pass: their runtime paths are
unchanged, and the lanes' checks there are as before or wider (a kept image's filter is held to
the weighted sum within one code, where it was held to Metal's step within 0.5).
The runtime-sources pin is left to the landing.

One work packet, landed as 2 commits on archive/development-linear-2026-10-29: 1df2fc38d8, then f4f88dad89 (the re-pin).
2026-10-29 15:43:56 +02:00
..