Files
metal2vulkan/crates
Anees Iqbal de7ca47842 Make the in-place check's textures the runtime's own: they take no texture ID
The device's check of the first move in place (in_place_check.rs) runs on its own thread,
m2v-in-place-check. It made each texture through the public Buffer::new_texture at the default
placement, so each one took a plain program texture ID and held it through settle_in_place's
submit and wait. That is 3 page classes x 11 shapes x 3 rounds. The check starts when a texture
over host pages first asks for a verdict. Its verdicts are kept in the shader cache's content
store, keyed by driver, check version and RUNTIME_VERSION, so after a runtime bump the first
process runs the check again while the program goes on making textures.

A program texture made while a check texture held an ID got the next one. In the consumer's
texture_identifiers_are_metals on the M3, the check started at its texture over a surface
(ID 9). Under load its first texture landed between t7 and t8 and held 12, so t8 took 13 where
Metal gives 12, and every ID after it moved by one. The refused format-263 texture just before
t8 took no ID: descriptor.check() refuses it before any ID is taken. A check texture also
started the texture pool, so a program's reservation made after it was ignored ("reserve()
must be called before any allocation takes place").

The fix: Buffer::new_runtime_texture (pub(crate)) makes a texture over a buffer that takes no
ID (IdUse::Runtime). make_texture_over takes Whose::Program or Whose::Runtime, and the public
new_texture, new_linear_texture and surface-plane paths pass Program as before. The in-place
check makes its textures through it.

The tests (device tests, m2v_gpu):
- tests::in_place_check::the_in_place_check_takes_no_texture_id (deterministic). Settle the
  check, reserve texture ID 5, make 5 textures: Metal's IDs are [1, 2, 3, 4, 6].
- tests::in_place_check::texture_ids_keep_metals_order_while_the_in_place_check_runs (the
  race). Make and drop a texture until the check settles; every one must take ID 1.
- tests::internal_texture_ids::the_runtime_s_own_textures_take_no_texture_id (guard). Program
  textures made around a pass of separate depth and stencil textures (combined scratch) and a
  memoryless attachment's pass (kept backing) take 1 to 7 in order.

Verified on this M3 Max, through maclock and memcap:
- The test binary built before the fix, idle, failed both in-place tests:
  - [1, 2, 3, 4, 5] instead of [1, 2, 3, 4, 6].
  - 53981 textures made while the check ran, 325 of them at ID 2 ({1: 53656, 2: 325}).
  - internal_texture_ids passed.
- The same binary under 16 `yes` loops, the race test x3, failed all three: ID 2 for 829,
  868 and 2698 textures.
- The fixed tree passed all 4 in_place_check and internal_texture_ids tests under the same
  load x3. The race test saw only ID 1, for 62779, 54485 and 61885 textures. The deterministic
  test ran the check each time (no "made no texture" skip line).
- The fixed tree passed 151 device tests of the touched families idle (in_place_check,
  internal_texture_ids, resource_ids, sparse, heap, heap_tiled, twin_reads, twin_flights,
  bc_own_image, buffer_texture, in_place, freed_memory, wrapped, texture, surface_two_planes,
  rotated, ycbcr_device, texture_descriptor, kept_images, surface_depth).
- The runtime's static suite passed (1218 tests). Clippy -D warnings passed, plain and
  --cfg m2v_gpu, all targets and features. Rustdoc -D warnings passed. The api-signatures check
  passed (no public item changed).

RUNTIME_VERSION and the runtime-sources pin are not bumped here: that is the owner's step.

(cherry picked from commit bc5421fa54621bdb954cb457fd1e2cbc36b8406e)
(cherry picked from commit 9c75fb477421278b8ea20c50d77bf59d4cc7c318)
2026-11-03 11:48:36 -08:00
..