Files
metal2vulkan/crates
Anees Iqbal cdb708d35f RUNTIME 2373: Heap textures: a tiled heap texture's making builds no kernel; its first use does
What: HeapTiledCopies (a heap texture held as a shadow in Metal's tiles,
AliasRoute::Tiled, and the surface depth textures that use it) no longer
builds the device's TiledTexels kernel or writes its two descriptor sets as
the texture is made. They live in a OnceLock and are made at the texture's
first use, in ShadowCopies::prepare(), which the encoder's plan_shadows calls
before it records any shadow copy. That is the path a converted YCbCr
texture's conversion already takes. dispatch() debug-asserts that the kernel
was made. So the compile moves to the first encode that needs any tiled
shadow, once per device, as owned_kernel.rs's rule says ("made once per
device, when a command first needs it"). That cost is now on the encoding
thread, not on resource creation.

Why: runtime_lane::first_use::new_resources_wait_for_no_gpu_work failed three
times on the Radeon 780M (RADV PHOENIX), always at "new_texture in a heap",
which returned 0.7-0.8 s later, about 65-70 ms after the busy work ended, with
no internal submission. A probe on um790's PHOENIX (9 runs, 3 of them beside
the lane's partition 4/4) showed that this making takes 10-43 ms every time,
while every other making takes about 1 ms. Backtrace samples taken 4 ms into
the call (3 runs) sit in vkCreateComputePipelines under HeapTiledCopies::new,
via Device::owned_kernel(TiledTexels). It is the only timed call that builds a
pipeline. Expected, not verified (the long wait did not reproduce in the probe
runs, nor beside a VRAM hog): the 0.7-0.8 s is that compile waiting in the
driver or kernel for the GPU's in-flight work, on an APU with a 2 GiB carve-out
shared by the lane's parallel processes. Metal's makings compile nothing.

Test: the first-use test records WorkCounts::owned_kernels_made around each
timed call and fails where a making built a kernel. Without this change that
check fails wherever the heap texture takes the tiled route (the 780M:
verified). The test also prints the tiled-heap-texture count and the kernels
the later uses built, as evidence the path ran. The heap texture's copy in and
copy out still read Metal's bytes.

Left alone (main records it): owned_kernel holds the device's owned_kernels
lock across every compile, so a lookup of a kernel already built waits behind
another kernel's compile.

Verified (m3-max-33194, msi, at 01fe19ba22): clippy of the runtime and validation crates (all
targets, all features, -D warnings) 0; lavapipe 132/132 of first_use|heap*|shadow*, including
first_use::new_resources_wait_for_no_gpu_work and every heap_tiled unit test. The PHOENIX runs
(the cause's device) and clippy in the device configurations follow on development.
2026-11-15 11:35:22 -08:00
..