rt: a heap makes texture buffers in place in its bytes

Metal's heap makes a texture buffer (MTLTextureTypeTextureBuffer): heapTextureSizeAndAlign
answers its texels' bytes at an alignment of 16, and newTextureWithDescriptor:offset: lays the
texels linearly in place at the offset (m3-max-80369, m3-max-80398). rt refused both with
Refusal::TextureBufferNotOverBuffer.

Now:
- Device::heap_texture_size_and_align of a texture buffer answers width x texel bytes, unrounded,
  at 16, or at the device's texel-buffer offset alignment for the format where that is larger
  (minimum_texture_buffer_alignment). No Vulkan call.
- Device::new_heap_texture and new_heap_texture_for_views of a texture buffer place a buffer of
  those bytes at the offset as new_heap_buffer places one, and make the texture buffer over it as
  Buffer::new_texture makes one, through the same texel_texture: one buffer view, one form on
  every device, no query. It takes the heap buffer's heap id and placement, so its uses are the
  heap's in the hazard sets and its writes mark the heap's aliasing textures stale.
- Its backing is TextureBacking::Texture, as Metal answers its buffer with nil.
- A placement past the heap or off the alignment is Refusal::HeapTexturePlace. A heap in an
  exported block makes one too: a buffer view needs no image.
- texel_texture's descriptor checks move to texel_shape and texel_width, shared with the size
  answer.

TextureBufferNotOverBuffer stays for new_texture, new_texture_for_views, new_managed_texture and
new_drawable_texture. The test also checks HeapTexturePlace at offset 8 and past the heap's end.

Docs: the runtime's README (textures, heaps, exported blocks), docs/API.md's heap-size accepted
difference, the refusals' docs; docs/REFUSALS.md regenerated.

Conformance ledger (docs/CONFORMANCE-COVERAGE.md regenerated):
- 22 rows of a one-level RGBA8Unorm, R8Unorm or RGBA16Float texture buffer's heap size in the
  texture-pairs cases are dropped: the replay now matches them;
- 6 rows of a texture buffer of 2 or 7 levels now record Refusal::TextureLevelCount, as
  Buffer::new_texture refuses it, where Metal's heap answers one level's footprint;
- 11 rows of RGBA16Float_XR, YCBCR8_420_2P, Unspecialized and BGRA4Unorm texture buffers' heap
  sizes now record Gap::TextureFormat;
- the device's newTextureWithDescriptor: rows keep TextureBufferNotOverBuffer, their reason
  naming the heap as the other way to make one.

Verified (the change at 6d5f748347 on 787fbbb061, then this commit rebased onto development
8a2f155883, the same change):
- red: the test fails at heap_texture_size_and_align on llvmpipe (job m3-max-80460) and on the
  RX 7900 XTX and the 780M (m3-max-80461);
- green: it passes on llvmpipe, whose 6 dispatches reach the buffers at their addresses
  (m3-max-80460), and on the RX 7900 XTX and the 780M, bound (m3-max-80461). Each device's
  texel-buffer alignment for R32Uint is 4, so all three answer 16 at 16;
- the conformance replay matches known-gaps-rt.tsv: llvmpipe, every case (m3-max-80487, and on
  this tree m3-max-80503); the RX 7900 XTX, the 8 cases the ledger edit touches (m3-max-80488);
  the conformance suite, 1047 passed (m3-max-80493);
- on this tree (m3-max-80502): signatures, refusals, both coverage checks, fmt, clippy plain,
  --cfg m2v_gpu and --cfg m2v_cpu_icd, rustdoc and private rustdoc, all 0; the runtime suite on
  llvmpipe 942 passed, 1 failed, 4 skipped. The failure,
  private_sinks::every_device_keeps_a_store_past_a_private_array_off_its_words, fails the same
  at development 8a2f155883 without this change (m3-max-80535) and passed at 787fbbb061 with it
  (m3-max-80462, 940 passed).
This commit is contained in:
Anees Iqbal committed 2026-12-02 16:25:21 -08:00
1 parent 4786da9503
commit a3fb852de3
9 files changed
+411 -303

No files matched your search

+12 -9
View File
@@ -2680,15 +2680,18 @@ named states the rule in full.
`Device::heap_texture_size_and_align`, its README's textures): the device's own image
requirements, not Metal's, the size rounded up to and the alignment raised to the device's
`bufferImageGranularity`, so a buffer placed by the same answers never shares a granularity page
with the texture. The answers differ by device, so the consumer places by this device's. The
conformance suite does not compare the two numbers with Metal's; it holds each answer to three
steps: (1) the alignment is a power of two; (2) a Private descriptor's texture is made at offset
`align` in a heap of `align + size` bytes; (3) there, level 0's first slice written from a buffer
reads back unchanged. A Shared descriptor is held to the same steps in a heap of a Shared block
where the device's image takes the Shared memory type, and to step 1 where its placement there
is `Gap::HeapTexture`. A Managed or Memoryless descriptor is held to step 1 alone, as no heap of
either mode is made. A descriptor whose bytes the runtime does not move (depth and stencil both,
multisample, `Depth32Float`) is held to steps 1 and 2.
with the texture. The answers differ by device, so the consumer places by this device's. A texture
buffer's are Metal's: its texels' bytes, the width times a texel's, at an alignment of 16, raised
to the device's texel-buffer offset alignment for the format where that is larger
(`Device::minimum_texture_buffer_alignment`). The conformance suite does not compare the two
numbers with Metal's; it holds each answer to three steps: (1) the alignment is a power of two;
(2) a Private descriptor's texture is made at offset `align` in a heap of `align + size` bytes;
(3) there, level 0's first slice written from a buffer reads back unchanged. A Shared descriptor
is held to the same steps in a heap of a Shared block where the device's image takes the Shared
memory type, and to step 1 where its placement there is `Gap::HeapTexture`. A Managed or
Memoryless descriptor is held to step 1 alone, as no heap of either mode is made. A descriptor
whose bytes the runtime does not move (depth and stencil both, multisample, `Depth32Float`) is
held to steps 1 and 2.
- **Apple's private texture usage bits are kept** in `TextureUsage` (`NO_CONCURRENT_ACCESS`,
`VIDEO`, `BLOCK_WRITES_ONLY`).
- **A pipeline state's `allocatedSize` is the bytes of its translated SPIR-V**