Charge a sparse heap for a mapping update of a slice past the texture's

Plain Metal takes a sparse mapping update whose slice is past the
texture's own (its API validation refuses it) and charges its heap's
usedSize exactly what the same region on an in-bounds slice costs: one
page a tile of the region clipped to the level's tiles, idempotent per
tile, given back on an unmap of that tile, never below where it stood
(probes/sparse_indirect_usedsize.m and sparse_mapping_past_the_bounds.m
on the M3 Max, macOS 27.0.1, both selectors). Ours counted nothing, so
sparse-mapping-a-slice-past-the-textures read 65,536 where Metal read
81,920 at used-size/2, /3 and /4.

UnitGrid::clipped_region now names such a region's units at the slice
(past_slices tells them apart); sparse/bind.rs's apply takes and gives
back their heap room into SparseState::charged and binds nothing for
them, and undo reverts them with the rest. The move keeps the slice
bound (clipped_size), as measured.

The texels plain Metal's page reaches (read/4: a 16 by 16 block of slice
0's tile (0, 0) reads its unwritten pattern) are not mirrored, on the
owner's call via the orchestrator: an accepted difference in docs/API.md
section 10 (Vulkan binds nothing past an image's layers,
VUID-VkSparseImageMemoryBindInfo-subresource-01723, and the address is
not derivable), which the remaining ledger row now names.

Removes the three used-size rows of known-gaps.tsv. tests::sparse holds
the counts against Metal's readings row by row (every row now equal).

(cherry picked from commit 636522137c717715521cdda950fbb7213e00089f)
This commit is contained in:
Anees Iqbal committed 2026-11-07 06:26:30 -08:00
1 parent 1edd55cb98
commit 08ca74da22
7 files changed
+170 -90

No files matched your search

+9
View File
@@ -4234,6 +4234,15 @@ each item named states the rule in full.
- **A `Shared` heap's textures are linear images** where the device's optimal images take no
host-visible memory.
- **A sparse texture on a device without shader residency holds all its texels' memory.**
- **A sparse mapping update of a slice past the texture's own maps nothing.** Metal's API
validation refuses such an update; plain Metal takes it, charges its heap's `usedSize` one page
a tile of the region (clipped to the level's tiles), and binds that page at an address its own
page layout derives: on an Apple M3 Max under macOS 27.0.1 a 16 by 16 texel block of slice 0's
mapped tile (0, 0) then read Metal's unwritten pattern. The runtime charges the heap the same
pages, given back on an unmap of each tile (`ResourceStateCommandEncoder::
update_texture_mapping`), and leaves every texel as it was: Vulkan binds nothing past an image's
layers (`VUID-VkSparseImageMemoryBindInfo-subresource-01723`), and which texels Metal's page
reaches is not derivable from what was measured.
- **A heap's buffer and texture over the same bytes alias them, in the device's layout**, not
Apple's tiled or compressed one.