Read a YCbCr texture's planes in place on integrated GPUs

One work packet, landed as 2 commits (42abe9a315..391480a6b2 on archive/development-linear-2026-10-28), in order:

* Read a YCbCr texture's planes in place on integrated GPUs

On an integrated GPU or a CPU device, a function that only samples a two-plane YCbCr texture now
reads the texture's planes directly. Such a texture is `YCBCR8_420_2P` or `YCBCR10_420_2P` over
plane 0 of a surface. "Only samples" means nearest or linear, no comparison, no anisotropy and no
`min_lod_clamp`; reading the texture's size is allowed too. The function fetches the codes from a
uniform texel buffer over the planes' bytes, then converts and filters them as Metal does, with
Metal's integer arithmetic. The draw or dispatch reads those bytes alone, so the texture's image is
not converted for it. Every other device, and every other use (a `read()`, a gather), keeps today's
form: the image is converted from the planes through the refresh, then sampled.

Both forms are exact, so there is no precision note and no switch. The device's kind picks the
cheaper one, by Vulkan's deviceType: INTEGRATED_GPU and CPU read in place; DISCRETE_GPU,
VIRTUAL_GPU and OTHER keep the image. This is the same rule as hasUnifiedMemory. Nothing is timed
at startup.

The measured basis is GPU time of a 3840x2160 texture whose planes lie in host memory, composited
into 1680x1050. Figures are microseconds, best of 3 x 40, over unchanged planes; "image" means
today's refresh compare plus the sample. Mesa 26.2.4 and MoltenVK 1.4.2.

  device             codes   in place 1 pass   image 1 pass   in place 3 passes   image 3 passes
  Radeon 780M        8-bit        340              1178             1027               3013
  Radeon 780M        10-bit       457              1509             1371               3344
  RX 7900 XTX        8-bit       1819              1754             5460               1876
  RX 7900 XTX        10-bit      3614              3479            10843               3613
  M3 Max (MoltenVK)  8-bit        127               259              375                634
  M3 Max (MoltenVK)  10-bit       125               364              378                737

A discrete GPU reads the host's planes across its bus at every pass, while its image lies in its
own memory. Where the planes changed, the image's form also converts every texel: 1055 to 1252 us
more on the 780M, 1790 to 3636 on the 7900 XTX, 350 on the M3 Max.

The texel buffer formats are R8G8_UINT for 8-bit codes and R16G16_UINT for 10-bit ones. Vulkan
requires UNIFORM_TEXEL_BUFFER support for both on every device ("Required Format Support": the
1-3 byte-sized components table and the 16-bit components table). Each element holds two luma
codes or one chroma pair.

The translator:
- bind::YCbCrInPlace (new, public) holds the slot's push words and the view's format and bytes:
  the size, the planes' places and rows in elements, and the conversion word.
- On a profile that reads in place (ProfileFields::ycbcr_in_place), a 2D float texture slot whose
  every access the form reads records RuntimeFact::YCbCrInPlace { slot, samplers }.
- The plan takes VariantKey::ycbcr_in_place for such a slot when the bound texture states
  TextureFacts::ycbcr_in_place and every runtime sampler it is sampled through has one filter for
  min and mag, no anisotropy, no cubic filter, no comparison and the weighted-average reduction.
  The slot then binds WriteSource::YCbCrInPlace and PushField::YCbCrInPlace.
- The variant lowers each sample through lower::sampler::in_place. It builds Metal's texel from
  the luma code and the 9/3/3/1 chroma, and feeds extended's exact filter routine
  (Decode::InPlace). A runtime sampler's address word is mapped in the shader, as 4:2:0 maps
  repeat and mirror to clamp-to-edge.
- Size and level-count queries answer from the push words.
- The YCbCr image variant excludes these slots, so the variant's plan states the same key.

The runtime:
- texture/ycbcr_image.rs states PlanesInPlace for a converted texture where the device reads in
  place. Otherwise the texture keeps its image, counted by reason in
  WorkCounts::ycbcr_images_kept_{device,layout,swizzle,alignment,elements,reach,view}:
  - device: the device's kind;
  - layout: another layout, or staged planes;
  - swizzle: a swizzle;
  - alignment: the planes' first byte misses minTexelBufferOffsetAlignment;
  - elements: more than maxTexelBufferElements;
  - reach: planes past the buffer, which Metal reads as zeros;
  - view: no view usage.
- Binding a slot under the variant makes the texel buffer view, counted in ycbcr_planes_bound.
  It records a read of the planes' bytes in the tracker, so writes to the planes through the
  buffer, plane textures or blits are ordered before it. The texture's image is not used there.
- The image stays allocated; making it lazily is later work.

SEMANTICS_VERSION 1868, RUNTIME_VERSION 1645.

Also fixed: development's runtime_lane/dma_buf_imports.rs did not compile on Linux under the GPU
cfgs (layer_reported_nothing not imported). It now imports it.

Docs: the runtime's ycbcr.rs and ycbcr_image.rs module docs, docs/FAST-PATHS.md ("Costs of
matching Metal", and the YCbCr filter row), docs/API.md, the runtime README. The api_surface table
and api_signatures.tsv are blessed. REFUSALS, METAL-COVERAGE and CONFORMANCE-COVERAGE did not move.

Verified:
- New interpreter tests (tests::engine_linear_half::in_place) run every texel of a 7x5 texture
  against Metal's model, on lavapipe and moltenvk-m3:
  - 8-bit and 10-bit codes, with junk in the 10-bit words' low bits, under all six conversions;
  - constexpr linear, nearest and offset (2, -1) samples;
  - runtime linear, nearest and repeat-as-edge samples;
  - half and float results.
  They also check that the planner states the fact on lavapipe and moltenvk-m3 and not on
  nvidia-rtx5080-laptop, and that a dynamic offset, min_lod_clamp or a 3D texture gets none. A
  negative control, a deliberately broken in-place form, failed them.
- bind::plan::slots: the_in_place_variant_takes_a_slot_its_texture_and_samplers_read.
- The device lanes, filter test(/ycbcr/) over the validation and runtime crates, 49 tests:
  - M3 Max, MoltenVK 1.4.2, INTEGRATED: 48 passed. The one failure, a constexpr linear mip
    filter that is now read in place, is fixed in this commit's test.
  - Radeon 780M, RADV, Mesa 26.2.4, INTEGRATED: 49 passed. The samples bind the planes:
    ycbcr_planes_bound 3, refreshes 0, whole conversions 0 per three-dispatch round. The 4K
    10-bit minify and padded lanes match Metal's hashes in place (planes bound 7, no refresh).
  - RX 7900 XTX, RADV, DISCRETE: 49 passed. ycbcr_images_kept_device is counted, the planes are
    bound 0 times and the refresh runs.
  - lavapipe (linux-gate, LLVM 21.1.8, CPU): 47 passed. The 2 failures are test expectations,
    fixed in this commit: the constexpr mip case above, and the baked-sampler test, where the
    in-place variant bakes no sampler. The minify lanes read in place and match Metal's hashes.
- Chunked dma-buf buffer, runtime_lane::dma_buf_imports::
  a_ycbcr_texture_over_a_buffer_of_chunks_reads_its_planes_in_place. The buffer is
  list_limit + 76 single pages, assembled from 2 udmabuf chunks into 1 sparse buffer.
  - 780M: read in place across the chunks, every texel Metal's (planes bound 1, no refresh).
  - 7900 XTX: kept the image, every texel Metal's.
- Conformance replay on the M3 Max: ycbcr-minify-band-x and -y, ycbcr-texel-reads-420v and
  ycbcr-two-plane-format-descriptors all compare exact against Metal's recordings. The bands now
  count ycbcr_planes_bound 1 and no refresh, where the recordings hold ycbcr_refreshes 1, so their
  cost records want a re-bless on development.
- clippy -D warnings over the workspace (all features), and over the validation, runtime and
  translator crates under --cfg m2v_gpu. cargo fmt.
- The core suite is still running at commit time; its result goes in the report.

* 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.
This commit is contained in:
Anees Iqbal committed 2026-10-28 17:24:19 +02:00
1 parent 54a8b32154
commit cdf59197cc
56 files changed
+3013 -78

No files matched your search

+10
View File
@@ -785,6 +785,16 @@ for dependency in &pipeline.dependencies {
pipeline of its own: leave out a slot bound at offsets that move, so that its draws keep one
shape and one pipeline (the runtime leaves out each slot of a state once it finds one bound at
an offset the alignment does not divide).
- A two-plane YCbCr texture whose planes a function may read in place states them in its facts
(`TextureFacts::ycbcr_in_place`, a `YCbCrInPlace` of its planes; the runtime states one on a
device whose memory is the host's, `DeviceProfile::reads_ycbcr_planes_in_place`: an integrated
GPU or a CPU device). A slot whose function only samples it (nearest or linear, no comparison,
anisotropy or `min_lod_clamp`) or reads its size (`RuntimeFact::YCbCrInPlace`) takes the
pipeline's in-place variant (`VariantKey::ycbcr_in_place`): the slot binds a uniform texel buffer
over the planes' bytes (`WriteSource::YCbCrInPlace`, in `YCbCrInPlace::format`), its push field
(`PushField::YCbCrInPlace`) holds `YCbCrInPlace::words`, and the function converts and filters
the codes as Metal does, exactly. Any other slot, and any texture without the fact, binds the
texture's image of converted texels.
- `interface.reaches_command_buffers` and `interface.texture_writing_stages` say, provably, which
pipelines may touch an indirect command buffer and which stages may write a texture.
`interface.command_writes` (`CommandWrites`) says what its functions may write into the