Files
metal2vulkan/docs
Anees Iqbal 7e48216b37 Make the canonical encoding's image scratch without zeros
What: under ExtendedRangeBlitPolicy::Canonical, a blit into a compressed BGRA10_XR or
BGRA10_XR_sRGB image rewrites its texels through a scratch buffer: a copy out, one dispatch a
region, a copy back. The scratch was made with Device::own_buffer, which zeroes a Private buffer
in a submission's first work (a copy of the device's zeros on a device with unified memory, a fill
on a discrete one), in a command buffer of its own. The copy out writes every byte the dispatches
and the copy back read (the regions, tightly packed) and nothing reads the alignment gaps, so the
scratch is now made with Device::unzeroed_buffer (Private, tracked as before), as shadow_merge's
fully written scratch already is. Nothing the program or Metal observes changes; the work counts
do.

Why: the whole-set conformance cost check on the M3 Max read compressed-blits-bgra10xr and its
sRGB twin over their records since 4b194d24af (which added the Canonical form and which the suite's
exact policy selects). Each case alone, cost --runs 8 --show, debug build, MoltenVK 1.4.2:
- 452c17aa2c (before) -> 4b194d24af: command_barriers 5 -> 24, command buffers begun and
  submitted 11 -> 14 (batch work 2 -> 5), cmd_copy_buffer 2 -> 7, cmd_copy_buffer_to_image
  7 -> 12, cmd_copy_image_to_buffer 6 -> 11, cmd_pipeline_barrier 18 -> 44, 9 dispatches.
- 4b194d24af -> this change: command buffers begun and submitted 14 -> 11 (batch work 5 -> 2),
  cmd_copy_buffer 7 -> 2, cmd_pipeline_barrier 44 -> 37; nothing else moved. The copies out and
  back, the dispatches and the encoder's barriers around them are the rewrite itself.

Test: runtime_lane::compressed_blits::extended_range_blits_write_metal_s_encoding_under_the_canonical_policy
now asserts that a blit into each Private texture, compressed or not, records no buffer-to-buffer
copy and makes no zero fill (WorkCounts::commands_recorded.cmd_copy_buffer +
new_buffer_zero_fills), under both policies.

FAST-PATHS: the Canonical row's cost column no longer lists the zeroing command buffer, and says
its figures were taken while it ran.

Verified on the M3 Max (MoltenVK 1.4.2), --cfg m2v_gpu: the test passes; with the scratch made by
own_buffer again it fails under Canonical ("BGRA10XR optimized true, 64 high, blitted in on Apple
M3 Max under Canonical", left 1, right 0) after passing the Kept leg. Conformance suite (no cfg):
1010 passed. Runtime behaviour changes (counts only): RUNTIME_VERSION is left to the stacker.

(cherry picked from commit 409aafaca513c03f6bad3378de1f0d8af6fdc5f0)
(cherry picked from commit 2b5f0731c54fa66350e88c82fceaed9909dc442a)
2026-11-03 07:56:21 -08:00
..