Files
metal2vulkan/crates/metal2vulkan-runtime/src/texture
Anees Iqbal 0ce880cd85 RUNTIME 2527: a submission makes, or waits for, every decode kernel noted before its walk
What: Device::make_pending_decodes claimed its work with one flag swap
(decodes_unmade.swap(false)) before making the kernels. A second
submitting thread that came while the first was still compiling found the
flag clear and returned at once, so its batch found the passes unmade:
take_second_decodes left an ASTC view's second-twin decode queued, and a
staged CPU copy (TexelCopy with its decode) waited for a later submission
with every staged copy after it. The batch read the twin undecoded (zeros).
The flag is now two counters, decodes noted (note_unmade_decode) and
decodes walked. A walk returns at once only where walked >= noted. Else it
lists the passes still unmade, makes each one or waits for the making
another thread began (FirstUse::make's own lock; the walk holds no other
lock meanwhile), and only then raises walked to the count it read. A
failed making leaves walked as it was, so the next walk tries again (the
re-note on error goes). How long a commit can wait: at most for the
makings other threads began of the kernels it needs, one per decode,
made once per device. Where nothing was noted, the cost is two atomic loads
(was one swap).

Why: the device's view check (RUNTIME 2495+) makes internal submissions on
its own thread from the device's making, each a walk, so it nearly always
took the flag first: runtime_lane::astc_textures::astc_views_in_the_other_
colour_space_read_as_metal_s read 0 against Metal's 1 through the view
after a CPU copy on the XTX and the 5080 (bundle round at 5fc0508f0b), and
on lavapipe alone deterministically (job m3-max-39582). Probe m3-max-39595
(never lands) printed "walk on m2v-view-check: took the flag, making 1
kernels", then the test thread's "flag already clear, 1 queued second
decodes unmade" and "take: 1 queued, 1 unmade". With the check settled
first, every walk took the flag itself and nothing was wrong. The same flag
guards a CPU copy that goes through a submission (lavapipe's PVRTC
carriers: probe m3-max-39612 shows each CPU copy's staged pass made by the
test thread's walk), which is how
runtime_lane::pvrtc_textures::pvrtc_texels_read_as_metal_s read zeros under
the lavapipe lane's load (m3-max-39505). The race is between any two
submitting threads: two program threads, the scheduler's or an internal
submission's.

Test: tests/twin_reads.rs
a_view_s_decode_another_thread_s_walk_found_first_is_recorded_by_the_next_batch,
a device test. A test-only pause (Device::pause_next_decode_walk, compiled
for the device tests alone) stops the first walk that finds the view's
decode right after it found it. Meanwhile this thread commits a read through
the view, and the test asserts that its batch recorded the decode
(second_twin_decodes +1). Verification is in the lane's report.

Verified (astcrace lane, tip 11391ccdc4 on 422fe4fe49), lavapipe on msi: m3-max-39620: the
negative control (the walk raises its count before making, as the swap did) FAILS the new
runtime test tests::twin_reads::a_view_s_decode_another_thread_s_walk_found_first_is_recorded_
by_the_next_batch (0 against 1); at the tip it passes alone, and the twin_reads module with the
validation astc_textures and pvrtc_textures modules pass 21/21, astc_views_in_the_other_colour_
space_read_as_metal_s included (it failed deterministically at development, m3-max-39582).
m3-max-39622: clippy -D warnings plain, m2v_gpu and m2v_cpu_icd 0, rustdoc 0. The XTX run
follows on development. No new Degradation kind, WorkCounts field or public item.
2026-11-17 00:21:08 -08:00
..