Files
metal2vulkan/docs
Anees Iqbal b660f64e17 Copy equal rows between buffers as one dispatch on ANV and the RTX 5080 Laptop, and split long copy regions
A copy of rows between two buffers whose rows lie apart is one vkCmdCopyBuffer with a region per
row, and ANV records each region as a blit operation of its own. In a guest frame's profile on
the Iris Xe one such copy a frame took about 15.7 of the recorder thread's 19 ms. ANV's recording
time for a single region also grows with the region's size at some sizes: one two-plane YCbCr
texture's planes copied into its staging buffer cost about 15 ms of the recorder's time a frame.

Row copies:
- Every copy of rows between buffers goes through one place, row_copies.rs (RowCopies): a blit
  between a buffer and a texture over a buffer or between two textures over buffers (through its
  overlap scratch too), a buffer-texture copy's rows through its staging buffer, and every
  shadow's copy back out of its staging buffer, wherever it records: a render pass's steps
  between instances and before tile dispatches, a rotated texture's store, and a heap's
  two-plane and tiled textures' copies back.
- RowCopies makes the copy one dispatch of the new translator kernel bind::rows_copy_module
  (RowsCopyModule) where the device is measured to run it faster (new
  DriverFact::RowCopiesDispatchFaster), the copy has 2 or more regions of the same size in whole
  4-byte words, 4-byte aligned, evenly spaced with destination rows at least a row apart, and it
  fits the device's storage buffer range and workgroup counts. Invocation (x, y) stores word x
  of source row y at word x of destination row y and writes nothing else, so the bytes are the
  copy's. Every other copy stays regions. The kernel's set 0 is pushed through the device's
  checked push command where VK_KHR_push_descriptor exists, else allocated from a pool the
  command buffer keeps; the callers name the dispatch's accesses so the tracker orders it.
- The fact holds on ANV (Mesa 26.2.4, keyed on the driver, so it covers the measured Iris Xe and
  UHD 770 identities) and on NVIDIA 615.71.09 on the RTX 5080 Laptop GPU. RADV is not listed: its
  GPU time rose 3 to 5% at 1080 rows.

Long copy regions: every vkCmdCopyBuffer the runtime records goes through Vk::cmd_copy_buffer,
which records each region over 16 KiB whose size is no multiple of 4 KiB as two regions of the
same command, its bytes up to the last whole multiple of 4 KiB and the rest. The same bytes are
copied by the same command, so the split is exact on every device and is not keyed to a driver;
five helpers that recorded copies through a bare ash::Device now take the device's functions.

Counters: WorkCounts::row_copies, row_copy_regions, row_copy_regions_most, row_copies_dispatched,
copy_regions_split, and copy_sites, which names the places in the runtime that recorded buffer
and image copies with their calls and regions (the device's checked functions record them
through #[track_caller] methods). The runtime re-exports CopySite. Docs: docs/HOWTO.md's copies
section, row_copies.rs, device/functions.rs, WorkCounts.

Verified, as the commits state:
- runtime_lane::row_copies::row_copies_cost (release, one blit a frame of 1920 BGRA8Unorm rows
  into rows 8192 bytes apart): 1080 rows on the Iris Xe CPU 3.1-3.3 -> 0.28-0.40 ms and GPU
  5.3-7.8 -> 1.13 ms; on the UHD 770 CPU 0.77-0.83 -> 0.04-0.11 ms and GPU 3.3-5.3 -> 0.59-0.91
  ms; on the RTX 5080 Laptop GPU 2.03-2.05 -> 0.42-0.43 ms.
- rotated_textures::rotated_surface_frame_costs (1920x1080 BGRA8Unorm, release, UHD 770): rotation
  1 clear+draw 4.41/4.43 ms against 7.24-8.24 ms, rotation 2 3.59-3.88 against 5.11-5.73 ms.
- span_copy_cost on the UHD 770: one region of 8,294,411 bytes recorded in 0.018-0.020 ms against
  28.4-35.1 ms, its GPU time 0.64-0.66 against 5.97-5.99 ms; the YCbCr frame 2.89-2.98 against
  6.80 ms of GPU. On RADV and NVIDIA the split recorded in the same CPU time and ran within about
  10 us of GPU time where one region was already quick, and faster where it was not (8,294,411
  bytes on the RTX 3090: 1520 against 6051-6061 us).
- Copy lanes with every byte checked under the validation layer (rows between buffers, a shadow's
  staged rows going back as one dispatch, blits of textures over buffers, textures over bytes
  past their VkBuffer) pass as dispatches on the UHD 770 and the RTX 5080 Laptop GPU and as
  regions on lavapipe; the rotated, tile-shadow, two-plane heap and heap-layout lanes pass on the
  UHD 770 with each rotated store's rows going back as a dispatched copy of rows.
  long_copies_of_any_size_copy_metals_bytes (prime sizes and offsets) passes on the UHD 770, the
  RX 7900 XTX, the 780M and the RTX 3090, and the YCbCr, blit, pitched-surface, no-copy,
  first-use, fill and frame-cost lanes pass on the UHD 770.
- tests::exit_guard::only_the_listed_modules_keep_the_device_s_functions (the push goes through
  the checked functions), bind::rows_copy, the driver_facts tests, owned_divisions, api_surface,
  and the runtime unit tests named row_copies, work_counts, functions, copy, shadow, first_move
  and ycbcr; clippy in every configuration and Rustdoc.
2026-10-19 00:16:00 +03:00
..