Commit Graph
14 Commits
Author SHA1 Message Date
Anees Iqbal 4f6dc912f3 Identity domains: a plain ulong texture slot is the RG32 element its resource ID names
A `ulong` texture slot that no `ulong` atomic updates is an `RG32` unsigned image whose two words
the shader joins and splits (`TexelClass::Uint64`), declared `Rg32ui` where it is a storage image
(`ulong_format`, under the floor's `shaderStorageImageExtendedFormats`). Under the identity domains
identity_class refused every `ulong` declaration, so such a kernel was
`Unsupported{IdentityDomains}` ("a type the identity arrays hold no element of"). It now admits it:
its class is the unsigned integer class of its shape, as its declared image is, and a storage
declaration of `Rg32ui` is the class `StorageFormatClass::Format(R32G32_UINT)`, whose variable is
the storage-image array's (set 1, binding 1, which every storage class aliases), as Metal binds
only an `RG32Uint` texture there. A slot a `ulong` atomic updates (an `R64ui` image) and an
argument buffer's `ulong` texture stay refused. The default domains are unchanged.

Docs: RESOURCE-ID.md's arrays name the `RG32Uint` storage class of a `ulong` texture; API.md's
identity forms name a `ulong` slot's reads and writes.

Test: engine_identity's ulong_texture_slots_are_rg32_elements_their_resource_ids_name: the owned
fixture unk_ulong_access (a sample-access and a read-access `texture2d<ulong>`, a write-access
`texture3d<ulong>`) under the identity domains on lavapipe, moltenvk-m3 and moltenvk-m3 without
robustImageAccess2: each passes L3, its classes are the sampled array's unsigned 2D class and the
storage array's 3D `R32G32_UINT` class, and on the CPU interpreter each of 20 threads reads its
elements' two words joined as `(v, 0, 0, 1)`, `(0, 0, 0, 1)` outside the textures, and writes the
sum's two words inside the texture alone.

SEMANTICS_VERSION 2246 -> 2247: a refusal becomes a module.

Evidence:
- The 9 public conformance cases on the plain ulong slot (unk_ulong_rw x7, unk_ulong_access
  x2): before, at f3418eacb9 on lavapipe (m3-max-61725), the 2 access rows not_supported;
  after, at 2796fb6e14 (an earlier form of this commit), 9/9 match, the 2 access rows on
  runtime-compute (m3-max-61703).
- States-only play of all 36 streams at 3bb97361a8 (an earlier form of this commit plus probe
  commits that never land): every render and compute pipeline state made, 0 refused. msi
  m3-max-61733 (1 stream), um870 61734 (1), um790 61760 (5), ms01 61775 (7), gem10 61795 (22).
2026-11-20 22:10:44 -08:00
Anees Iqbal 841c6872ac Identity domains: a read through a sampler takes its border texels from the resource ID's word
MSL 4.1's read(sampler, coord[, offset][, lod]) of a texture slot, through a constexpr sampler
with a clamp_to_zero or clamp_to_border axis or through a runtime [[sampler(n)]], reads Metal's
border texel at an index outside the level. The default domains take the border texels from the
slot's BorderTexels specialization (RuntimeFact::BorderTexels); under the identity domains that was
state of the bound texture they did not source, so such a kernel was
Unsupported{IdentityDomains}. The border texels are bits 0-11 of the texture word
(TextureWord::BORDER_TEXELS, docs/RESOURCE-ID.md), already in the slot's pushed resource ID
(PushField::SlotGuestBase). Under the identity domains select_through now sets neither the slot's
border_texels nor the fact, and border_bits reads the word through emit::identity_id and masks
it, as the format's missing alpha is read. SlotPlan::identity_lowered and identity_unsourced drop
the border texels, which the identity domains now source. An argument buffer's texture read so
(its handle-table entry's border texels) is still refused. The default domains are unchanged.

Conformance (known-gaps-rt.tsv, runtime on lavapipe against the committed Metal answers): six
read-through rows translate and match, so their rows go: read-through-int exact;
read-through-half, -layers, -line, -read-write and -volume differ only by notices the suite
declares. read-through-volume reads through a runtime sampler of an opaque-black border, whose
sampler state the runtime notes on every device: the case now declares that notice
(replay::swizzled_border_notice) wherever it reads through such a sampler, as border_swizzles
does. The four plane rows (a8, r32f, rgba8, rgba8-swizzled) now make every pipeline up to
rt_heap_zero, an argument buffer's texture read through a border sampler, where they are still
refused; their rows move there.

Docs: RESOURCE-ID.md says a slot's read through a sampler takes its border texel from bits 0-11
of the word; API.md's identity forms name the read through a sampler (the paragraph's lines
reflowed); CONFORMANCE-COVERAGE.md re-derived for the six rows gone (REFUSALS.md re-derives
unchanged).

Test: engine_identity's a_read_through_a_sampler_takes_its_border_texels_from_the_word:
engine/kernel_read_through's rt_arg (a runtime sampler, offset (1, -1)) under the identity domains
on lavapipe, moltenvk-m3 and moltenvk-m3 without robustImageAccess2: L3, no specialization
constant but the dispatch's, no BorderTexels fact, and on the CPU interpreter, through a sampler
that clamps every axis to the border, each of R32Float, RGBA8Unorm, A8Unorm and RGBA8Unorm
swizzled (a, b, 0, r), under each border color, reads metal::sampler::border_texel's texel past
the right, left and top edges and the texel inside.

SEMANTICS_VERSION 2234, one above the previous commit's (main renumbers at landing): a refusal
becomes a module. The old runtime's render descriptor key changes with it, pinned at landing.

Verified (potluck; the jobs ran this diff on the previous commit's diff on development
846f7c1428, and this commit is the same diff on the previous commit, whose base 62c563f564 touches
none of its lines but SEMANTICS_VERSION and the API.md paragraph's neighbours):
- m3-max-61431 (msi, at the WIP tree b94d87fbf1, this diff but the coverage document): cargo fmt
  --check, clippy with all features, with --cfg m2v_gpu and with --cfg m2v_cpu_icd, and Rustdoc
  -D warnings pass; nextest of metal2vulkan and metal2vulkan-conformance 4364 run, 4362 passed,
  among them both engine_identity tests of this and the previous commit and
  golden_hashes_match_the_table; the two failures the old render descriptor key above and
  the_conformance_coverage_document_is_what_the_sources_derive, for the coverage document this
  commit re-derives (coverage.py --check passes at this tree); the metal2vulkan-conformance suite
  under --cfg m2v_cpu_icd on lavapipe 1014 of 1015 passed, the one failure that coverage document.
- m3-max-61342 (msi, at the WIP tree 80c41fdb12, the code before the ledger rows): conformance
  replay --cpu of the read-through cases and swizzled-storage-atomics: read-through-int exact;
  -half, -layers, -line and -read-write announced (declared notices); -volume divergent by the
  undeclared opaque-black border notice, which the case now declares; the four plane rows
  refused at rt_heap_zero.
- m3-max-61353 (um870, llvmpipe LLVM 23.1.4, at b94d87fbf1): the same replay with the ledger rows
  and the declared notice: announced 5, exact 1, refused 7, "exactly the open gaps
  known-gaps-rt.tsv expects", exit 0.
- States-only play (the probe player, M2V_PROBE_STATES_ONLY=1, on lavapipe) built at b94d87fbf1
  plus the five probe commits (m3-max-61345, um790), run over the 36 recorded streams on five
  nodes (m3-max-61358 ms01, 61377 um790, 61379 gem10, 61404 um870, 61423 msi): 61 runs of 36
  distinct streams, every one exit 0; 502920 render and 108189 compute states made, 0 refused.
2026-11-20 20:27:12 -08:00
Anees Iqbal 2dd8ffce0d Identity domains: a texture atomic's slot is the R32 storage element its resource ID names
A texture atomic (atomic_fetch_*, atomic_exchange, atomic_compare_exchange_weak, atomic_load or
atomic_store on a texture1d, 1d_array, 2d, 2d_array or 3d of uint or int, access::read_write)
declares its slot R32ui or R32i, as Vulkan's image atomics require and as Metal requires an R32Uint
or R32Sint texture there. Under the identity domains identity_class refused every storage
declaration with a format, so such a kernel was Unsupported{IdentityDomains}. It now admits an
R32ui or R32i storage declaration as the class StorageFormatClass::Format(R32_UINT | R32_SINT),
whose variable is the storage-image array's (set 1, binding 1, which every storage class aliases;
no link or declaration change). The atomic's emission takes the element of that array at the
index the slot's pushed resource ID holds (emit::identity_id), as a read or write does; it took the
array variable itself before, which no path reached. The default domains are unchanged.

Still refused under the identity domains: ulong atomics, texture-buffer atomics and an argument
buffer's atomic texture.

The CPU interpreter models OpImageTexelPointer (unmodelled before): a pointer to a texel inside
its image (Root::Texel), through which an atomic reads and writes the texel's first component, as
an atomic of an R32ui / R32i image does. Robustness's atomic outside the image and one on an
unmapped texel stay unmodelled.

Conformance: swizzled-storage-atomics now makes its pipeline and meets the runtime's
Gap::SwizzledReadWrite at its first dispatch (case/RRRR/dispatch), where a read_write slot bound to
a swizzled texture is refused; its known-gaps-rt.tsv row moves there and says why: Metal's atomic
answers the texel unswizzled, but nothing yet says a slot's reads are atomics alone.

Docs: RESOURCE-ID.md's arrays name the R32Uint / R32Sint storage class of a texture atomic;
API.md's identity forms name a texture slot's atomics (the paragraph's lines reflowed);
CONFORMANCE-COVERAGE.md re-derived for the atomics row's reason (REFUSALS.md re-derives
unchanged).

Test: engine_identity's a_texture_atomic_is_the_r32_storage_element_its_resource_id_names: a
generated texture2d<uint, access::read_write> atomic_fetch_add under the identity domains on
lavapipe, moltenvk-m3 and moltenvk-m3 without robust image access; each passes L3, its one image
class is R32_UINT storage at set 1 binding 1, the guard's size query is there exactly where the
device lacks robust image access, and on the CPU interpreter each thread adds 5 to its texel of
element 2 (the one the pushed resource ID names), answers the texel it held, and no other element
changes.

SEMANTICS_VERSION 2233, one above development's (main renumbers at landing): a refusal becomes a
module. The old runtime's render descriptor key changes with it
(the_old_render_descriptor_key_keeps_its_value), pinned at landing.

Verified (potluck; the jobs ran this diff on development 846f7c1428, and this commit is the same
diff on 62c563f564, whose eight commits since touch none of its lines but SEMANTICS_VERSION and
the API.md paragraph's neighbours):
- m3-max-61334 (msi, at the WIP tree e55576964b, this commit's code and test before its ledger row
  and docs): cargo fmt --check, clippy with all features, with --cfg m2v_gpu and with --cfg
  m2v_cpu_icd, and Rustdoc -D warnings pass; nextest of metal2vulkan and metal2vulkan-conformance
  4363 run, 4362 passed, the one failure the old render descriptor key above; the
  metal2vulkan-conformance suite under --cfg m2v_cpu_icd on lavapipe 1015 passed.
- m3-max-61335 (um790, at e55576964b): conformance replay --cpu swizzled-storage-atomics on
  lavapipe makes the pipeline and is refused at case/RRRR/dispatch (Gap::SwizzledReadWrite).
- m3-max-61438 (msi, llvmpipe LLVM 23.1.1, at the WIP tree ad62594111, this diff but the coverage
  document): conformance replay --cpu of swizzled-storage-atomics and the 13 read-through cases
  against the committed Metal answers: 14 refused, "exactly the open gaps known-gaps-rt.tsv
  expects", exit 0.
- scripts/conformance-coverage/coverage.py and scripts/refusal-surface/refusal_surface.py run at
  this tree (the coverage document's one changed row is in this commit).
- The next commit's states-only play over the 36 recorded streams runs this commit's code too.
2026-11-20 20:25:23 -08:00
Anees Iqbal d3d40dd31e Identity domains: an argument buffer's texture sampled through the argument buffer's own sampler
Under the identity domains, an argument buffer's sampler was refused. Its cubic test pushed the
execution status address ("an encoder value the function reads as ExecutionStatusAddress"), and
behind that was the form's own refusal ("an argument buffer's sampler"). The sampler's resource ID
is now its handle, read from the member's 8 bytes with no sampler table (access::handle,
emit_identity_sampler):
- Its index selects the element of the set-1 sampler array of its use. That is the array an
  argument buffer's sampler already declares, at the same binding the slot samplers' identity
  arrays use.
- The word's fields (pixel coordinates, the nearest-pixel test) come from the ID's high word
  (sampler::emit::heap_sampler_field).
- The handle is a uvec2 wherever it is held (lowered_pointer, and word_repr for a member word).
  A select's null operand is the nil ID.

Bad-ID guard: compare-and-select, index < 4,000 ? index : 0, so an index past the arrays samples
through element 0, the default sampler. I chose it over 4,096-element arrays with a 12-bit mask
because it is two instructions with no layout or floor change. The mask would need every array at
4,096 elements and every unowned element holding the default sampler, which the floor does not
state. pipeline::link::IDENTITY_SAMPLERS becomes pub(crate) for it.

No cubic test under the identity domains (sampler::select::cubic_reach returns early). The runtime
makes no sampler state of a cubic filter (Gap::CubicSampler), so no live ID's word carries bit 30.
The runtime README says so beside the gap, and docs/RESOURCE-ID.md says how the shader reads the
ID.

The conformance ledger's 32 rows refused only by the cubic mark now run through the runtime. On
lavapipe:
- 3 match: pixel-samplers-rgba16f-nearest-{border,edge,zero}.
- 5 are refused at case/encoder, Unavailable argument_encoder or argument_encoder_with_arguments:
  the rt side has no argument encoder.
- 24 differ. In each, every source our side runs answers alike wherever Metal's do.
Their 32 rows become 192 rows scoped to llvmpipe, each naming its note and bound:
- pixel-downscales: pixel-sampler-scaling, 2/255.
- pixel-samplers linear: device-sampling.
- rgba8 nearest and subnormal: device-texel-conversion.
- the two nearest mirror norm sites: device-sampling, the device's mirror clamp to edge at
  normalized coordinates, which a device test shows a slot's sampler and an argument buffer's
  read alike.
docs/CONFORMANCE-COVERAGE.md is regenerated for the ledger (7,490 rows to 7,650).

pixel-samplers now declares the slot form's pixel-sampler-scaling on nearest states as well
(replay::pixel_sampler_scaling_notice): under the identity domains the slot's word is read at
dispatch, so the note is the operation's on any state.

SEMANTICS_VERSION 2231 (a placeholder for the landing to renumber).

Tests:
- engine_identity's
  an_argument_buffers_sampler_samples_through_the_identity_arrays_by_its_resource_id covers
  tail_argument_samplers' four kernels and tail_argument_cube_gradient on every profile: L3, set
  0 empty, set 1 the identity layout, the bindings used, no sampler slot ID, constexpr index or
  status address pushed, and no RuntimeFact::CubicArgumentSampler.
- metal2vulkan-runtime tests::argument_sampling (lavapipe, m2v_cpu_icd):
  - argument_sampler_edges through a linear state reads the edge averages; through an ID of that
    word with index 4,000 it reads element 0's nearest texels (the guard).
  - every_device_samples_alike_through_an_argument_buffers_sampler_and_a_slots: one texture at
    the pixel-samplers case's 800 normalized coordinates through one nearest state under clamp to
    edge, to zero, to an opaque white border and mirror clamp to edge, bound at a slot and held in
    an argument buffer; bit-equal.
- validation's an_argument_buffer_sampler_samples_its_member_texture compares the runtime's run
  with Metal's texels, where it held the refusal.

Verified (potluck jobs; this commit's tree equals WIP 16c70bf88a on acc706ca47):
- Gate m3-max-61241 (um870, at WIP 7df837b74d, the same tree but for the coverage document):
  focused tests (the (ii) translator, runtime device and validation tests, golden, argument
  sampler and cubic) pass on lavapipe; fmt, clippy (plain, --cfg m2v_gpu, --cfg m2v_cpu_icd) and
  Rustdoc clean; the suites of metal2vulkan, metal2vulkan-runtime and metal2vulkan-conformance on
  lavapipe: 4,866 of 4,868 pass. The two red: the_old_render_descriptor_key_keeps_its_value (red
  between pins) and the coverage document test, for this ledger's rows; the document is
  regenerated here (python3 -I scripts/conformance-coverage/coverage.py) and its test passes
  at 16c70bf88a (m3-max-61285, um870).
- Mirror control, lavapipe (m3-max-61184, at WIP 01ba67160c on dc21cd66c7): both
  argument_sampling device tests pass; slot and argument-buffer samplers bit-equal under all four
  address modes.
- Conformance replay --cpu on lavapipe with the new ledger: m3-max-61194 (um790, WIP 8793aab9ce
  on dc21cd66c7) and m3-max-61223 (gem10, at 7df837b74d) rc=0: announced 3, divergent 24 (each
  held by its llvmpipe row), refused 5.
- Family C proofs at WIP 5277d7228 on dc21cd66c7 (translator source equal to this commit's but for
  SEMANTICS): SCOPE=public m3-max-61166, 14 cases, match 10 -> 14 (06b41c83, 0e720f8b, 2648a020,
  34f89406 flip from not_supported to match), slowest after 06b41c83 1.05 s, 207 MiB; SCOPE=private
  m3-max-61180, 6/6 match before and after, slowest after 1.92 s, 220 MiB.
- States-only play on lavapipe, 36 streams, player built at WIP 0ff352d28b on dc21cd66c7
  (translator source equal): render made 291,334, refused 0; compute made 51,029, refused 0;
  0 newly refused states (m3-max-61181 ms01, 61188 um870, 61196 um790, 61206 gem10, 61210 msi).
2026-11-20 19:31:25 -08:00
Anees Iqbal b676eda182 rt: a colour render target takes an index, and a draw reads it as an attachment as it reads a shader-read one
Metal fetches any render target, and its header gives every texture a handle with no tie to
usage (MTLTexture.h: gpuResourceID, "Handle of the GPU resource suitable for storing in an
Argument Buffer"). rt took an index only for shader-read or shader-write usage, so a colour
target made for rendering alone had no second element and every fetch from it was
Gap::Draw(FetchedAttachment): guest 26's 4,792 refusals, all of that shape.

- The index rule: shaders reach a texture made for shader reads or writes, or a colour render
  target (render-target usage of a pixel format with no depth or stencil), which takes an index
  exactly where it does (Refusal::TextureIndex), at every maker: new_texture and the heap, buffer
  and Managed makers, views, drawables and surface planes. A depth or stencil target made for
  neither is unchanged.
- A colour render target not read takes what a shader-read one takes for attachment reads: the
  sampled usage, and the feedback usage where the image format query offers both beside its
  usage; the shadow on a device without the loop; neither where the query refuses them, and its
  draws that read it stay Gap::Draw. Its home stays the attachment layout, so a pass that does
  not read it records no move of it, and a fetching pass moves it home, feedback, home with the
  existing move code.
- Only its second element is written: its sampled-texture element stays the null one, so a slot
  that binds it reads nil as before. place_texture takes the view its second element names in
  place of a flag.
- A linear image in place over a buffer takes no sampled usage for a target shaders do not read.
- The in-tree consumers take the rule: the replay player's texture class, the harness's and the
  conformance suite's rt side. rt's own tests make their unindexed colour targets with
  new_texture_for_views, and give indices where a test needs new_texture's path.
- docs/RESOURCE-ID.md, the runtime README and Refusal::TextureIndex's doc say the rule; docs/REFUSALS.md is regenerated.

Also rides along, from the planner, in the README's known gaps of memory blocks: a block freed
before a submission used it waits on the block-maker thread for its bind, and a ring take that
needs a new ring block can wait behind it.

Verified: see the check job named in the landing.
2026-11-19 21:40:56 -08:00
Anees Iqbal a47fc3e69d translator: an argument buffer's texture index is masked to the set-1 image arrays
What: under the identity domains (Device::from_queries' profile alone; Device::new never takes
them, so its modules are unchanged), the handle of a texture whose resource ID an argument buffer
holds is the ID's low word masked to its low 16 bits (IDENTITY_TEXTURES - 1, the two image
arrays' 65,536 elements, a power of two the compiler checks): one OpBitwiseAnd a handle. A bad ID
reads the element at index & 0xFFFF, never one outside the arrays. Nothing else changes: a slot's
index is the runtime's own push (SlotGuestBase), a constexpr sampler's too (ConstexprSampler), and
an argument buffer's sampler is not lowered under these domains, so the sampler arrays stay at
4,000 with no mask. docs/API.md, where that sampler's refusal is listed, and RESOURCE-ID.md say
the change that first lowers one masks its index the same way. The new runtime's README records,
among the known gaps of memory blocks, that a shader uses a buffer's gpuAddress unchecked, so a
stale one can still fault the device. SEMANTICS_VERSION 2178: from_queries' translations of such a
texture change (2177 is the unlanded float-array branch's).

The feedback elements (index + 65,536 in the sampled array, where the device reads attachments):
only a draw's push of a texture slot's index reaches them. The render encoder builds no
useResource: or useHeap:, so no draw makes an argument buffer's texture resident, and Metal reads
an argument buffer's texture only once it is resident; the mask keeps every argument-buffer index
below 65,536 besides. So an argument-buffer texture that is also the pass's attachment is never
offset to its feedback element: the shader reads element index, as before, a read Metal leaves
undefined while the texture is not made resident (only the compute encoder has use_resource and
use_heap).

Why: the ID is the program's word, and an index past the arrays fetches a descriptor outside
them.

Verified:
- Check 46942 (msi) at this change on 98efd4de50: clippy, all features, 0; clippy under
  m2v_gpu 0; the identity, golden, old render key, resource ID and public fixture tests 86 of 87,
  the one failure the old render key, pinned here at 64b84e0f... from that run (SEMANTICS 2178).
- Final check 47056 (msi) at this tree (as 5794117bcb): clippy, all features, 0; clippy under
  m2v_gpu 0; the same tests 87 of 87, the old render key at its pin among them.
- Words per identity texture kernel (base d392d453d6, 46865 -> this change, 46942): without an
  argument buffer 829 -> 829; with one 1172 -> 1191; without robustImageAccess2 942 -> 942 and
  1368 -> 1387.
- Negative control 46864: with the mask taken out, the identity test of IDs 65,536 past the
  arrays fails (rc 100); with it, passes.
- The rt device test, ID 0x1_0005 reading element 5 (index 5 and 5 + 0x1_0000 both answer
  7 x 3 and the texel): RX 550 46854, XTX 46855, RTX 3090 46856, Iris Xe 46857, all pass.
- Harness module hashes, every compute row, the mask (8d9317bef0) against its base (d392d453d6),
  the same harness: XTX 46951 19 of 19 equal; RTX 3090 46952 19 of 19 equal.
2026-11-18 09:37:25 -08:00
Anees Iqbal fe23decd1b rt: a constexpr sampler's index under the owner rule, and an object released with work pending
A constexpr sampler's numbering is a placement like any other. Where a sampler state took the
index from it, a later pipeline state that numbers the constexpr sampler there took nothing back:
it sampled through the program's sampler. Now it places the constexpr sampler there again with
every element it holds (Arrays::hold_samplers: under the grants' lock, the owner's additions where
it still owns the index, else a placement), and the constexpr sampler keeps its elements' samplers
to write them. The consumer chooses constexpr indices and keeps them from the program's sampler
states while a state numbering one lives; rt does not check it (rt README, compute pipeline
docs).

An object the program released while a command buffer that used it is pending is displaced like
a live one: a placement at its index takes it at once, and its teardown once the command buffer
retires touches nothing it no longer owns (one owner compare for both). Nothing empties an
element at the program's release: a committed command buffer still reads the object through its
index, which Metal allows. The owner's teardown nulls it. RESOURCE-ID.md states the duty (no work
in flight reads a displaced or released object through its ID) and what an element no object owns
holds: every element is written at device creation, a null descriptor (nullDescriptor, on the
floor) or the array's default sampler, and written back to that when its owner goes.

The replay player gave constexpr samplers the lowest free sampler index, the range the stream's
named sampler IDs come from, so a program's sampler state could take a constexpr sampler's index.
It now gives them the highest free one, outside that sequence (Indices::highest; REPLAY-STREAM.md).

Tests:
- sampling::every_device_gives_a_constexpr_sampler_s_index_to_the_object_placed_there_last: a
  nearest sampler state over sample_up's linear constexpr sampler reads nearest; a later state
  numbering it takes the index back (linear, for both states); the sampler state's going touches
  nothing; the slot gauge counts the index once.
- sampling::every_device_gives_a_released_object_s_index_to_the_next_at_once: a command buffer
  samples A through SA, signals and waits on the host; A and SA are released and B and SB made at
  their indices while it is pending (asserted); another queue reads B through SB; after the first
  command buffer retires, and A and SA with it, the index still reads B through SB. The writes are
  valid under UPDATE_UNUSED_WHILE_PENDING with PARTIALLY_BOUND (vkspec: "as long as they are not
  dynamically used by any shader invocations"): A's dispatch completed before its signal.
- replay a_constexpr_sampler_takes_no_index_of_the_sequence.
2026-11-18 07:43:13 -08:00
Anees Iqbal fd916e7f99 rt: an index has one owner, the texture or sampler placed there last
The consumer's program places a texture at an index a live texture of its own still holds, and
releases the older one later (179 placements in one recorded stream, 92 in another). Metal takes
it: the later texture takes the ID. rt refused it (IndexInUse).

Now Grants keeps one owner word per held index (a HashMap per class, the word given at placement
and never again on the device; no list of holders, no refcount, no second bitset). A placement at
a granted index always succeeds and makes the placed object the owner; a release vacates the index
and empties its elements only where the releaser still owns it, so a displaced object's going
touches nothing. Placement and element writes happen under the grants lock in one step
(Arrays::place_texture, place_samplers, add_samplers, vacate_texture, vacate_samplers), so the
elements always belong to the owner. Where a placement displaces another object, a texture with
no storage view writes its storage element null and a sampler writes the arrays it does not use
back to their defaults, so nothing stale answers. The descriptor-slot gauge counts held indices:
a displacing placement adds none.

The same occupancy serves textures, sampler states and constexpr samplers. Constexpr samplers are
kept by (index, state words), each with its owner word; a later pipeline state of the same words
adds its arrays where the constexpr sampler still owns the index. Refusal::IndexInUse is deleted:
nothing Metal refuses remains. A texture now takes its index after its image and views are made,
so an index not granted is refused after the image is made and freed at once.

The duty: no work in flight reads a displaced object through its ID, as Metal's. rt does not
check it. RESOURCE-ID.md and the rt README state the rule and the duty.

The harness takes the next index round each class's range (its workloads make far fewer objects
than a range holds). The replay player keeps the object placed last per index: a named index an
object holds is taken, and the earlier object's release leaves it; with no index free for a
constexpr sampler it answers IndicesNotGranted past the range.

Tests: grants' an_index_has_one_owner_the_object_placed_there_last (both classes);
sampling::every_device_gives_an_index_to_the_texture_placed_there_last (a storage-capable D at 3,
a sampled-only A over it, whose placement empties D's storage element: a write through 3 is
dropped and D keeps its texels; B storage-capable over A, A dropped; sampling through 3 reads B,
writing through 3 writes B; B dropped, sampling through D's ID reads zero; the slot gauge counts
3 once); the sampler states' test places a state over a live one; replay's indices test.
REFUSALS.md regenerated, api_signatures loses IndexInUse.
2026-11-18 07:43:13 -08:00
Anees Iqbal cc9ab54b86 rt: one texture index class, 1 to 65,535, and a storage array as long as the sampled
The consumer hands each guest process texture IDs from one pool (1 to 16,320) and places every
texture at its own ID whatever its usage. rt split textures into two index classes by usage
(StorageTexture 1..4095 with shader-write usage, Texture 4096..65535 without), so every named
sampled-only texture below 4,096 and every storage-capable one above it was refused
(IndicesNotGranted), where Metal takes them: 4,818 makings in one recorded stream and 5,707 in
another.

Now there is one texture class, IndexClass::Texture, 1 to 65,535, with one grant bitset and one
occupancy; IndexClass::StorageTexture is deleted. Set 1's storage-image array (binding 1) is as
long as the sampled-image array, 65,536 (floor::TEXTURES replaces SAMPLED_IMAGES and
STORAGE_IMAGES). A texture with a storage view writes both elements at its index; any other writes
its sampled element alone and its storage element stays null; a texture that goes writes both
null. Samplers keep their class.

Why every floor device holds it: Vulkan's Required Limits (vkspec 56.1, Table 75 and Table 76)
give maxPerStageDescriptorUpdateAfterBindStorageImages, maxDescriptorSetUpdateAfterBindStorageImages,
the two SampledImages limits, maxPerStageUpdateAfterBindResources and
maxUpdateAfterBindDescriptorsInAllPools a minimum of 500,000 on a device that supports
descriptorIndexing. The floor's own sums become 2 * 65,536 + maxColorAttachments (131,080 at 8)
and 2 * 65,536 + 3 * 4,000 = 143,072, both below 500,000. Every lab capture (2080, 3090, XTX,
780M x2, HawkPoint, RX 550, Iris Xe, UHD 630, lavapipe) reports descriptorIndexing and 1,015,808
or more for each of the six limits. The floor's limit check stays the one gate: no query-chosen
size, no second form.

Translator: link.rs's identity set 1 sizes binding 1 by IDENTITY_TEXTURES (65,536), the same
constant as binding 0, so rt's of_the_device check still matches it. Nothing else in the pipeline
interface, binding plan or resource-ID decode assumes a storage index below 4,096: the identity
handle is the low word (masked only of bit 31 where the alpha flag rides it), indexing each
array's runtime-array variable. The identity domains are reached only from Device::from_queries'
profile (rt sets PointerDomain::Identity; the old runtime never does), so Device::new's modules,
refusals and notes do not change. SEMANTICS_VERSION 2173: the identity set 1 layout is a
binding-plan fact that changed under unchanged keys.

Consumers in the tree: the harness and the replay player grant and place every texture in the
one class; the player reserves a texture ID in it.

Docs: RESOURCE-ID.md's class table (nil, texture, sampler), the rt README (set 1, grants,
textures, the fault paragraph, the floor's limits table), IndicesNotGranted's doc (an object at an
index not granted, as well as a release) and IndexRange's basis; REFUSALS.md regenerated;
api_signatures loses the variant.

Tests: sampling::every_device_makes_a_texture_of_any_usage_at_any_index grants the whole texture
range, makes a shader-read texture at 2 and a shader-write one at 5,000, and checks one
sample_down dispatch against the CPU mean. arrays' fill-past-capacity fills every texture index
(a storage texture at 1, views of it at 2..65,535, 128 made again).
2026-11-18 07:43:12 -08:00
Anees Iqbal 100b92d608 identity: constexpr samplers by a pushed index into set 1's sampler arrays
Under the identity domains a texture slot sampled through a constexpr sampler takes the sampler
from the set-1 sampler array of its use (binding 2 plain, 3 compare, 4 integer texture) at an
index the consumer pushes: PushField::ConstexprSampler(CombinedSampler), one u32. The consumer
makes the device sampler that the new public CombinedSampler::constexpr_sampler(profile)
describes, places it at an index of that array, and pushes the index. The index is a push word,
not a specialization constant: an index allocated at run time would key the driver's and the
pipeline cache's entries. Link's immutable sampler for the default domains now goes through the
same method, with the same result.

Under the identity domains every device sampler is normalized: a constexpr pixel sampler's
coordinate is scaled in the shader, as a runtime sampler's is, never handed to the device's
unnormalized sampler. A linear sample or gather through it records
PrecisionNote::PixelSamplerScaling, which is static. No address-mode-map variant applies there
(no binder picks a variant), so the sampler keeps its own modes and the slot records no
ConstexprSampled fact.

Still refused as Unsupported{IdentityDomains}: an argument buffer's sampler, arrays of samplers,
bicubic and anisotropy emulation. The refusal test now uses engine/a2_bicubic_weights.

Translation output changes only under the identity domains (Device::from_queries). Device::new
output is unchanged: golden_hashes_match_the_table passes at this tip (job m3-max-42192), with no
"changed under an unchanged key" and no "profile changed:" line.

Public surface: PushField::ConstexprSampler and CombinedSampler::constexpr_sampler are added
(api_signatures blessed); nothing is removed or changed.

SEMANTICS_VERSION 2162: identity-domain modules of constexpr-sampling kernels change.
ARTIFACT_FORMAT_VERSION 531: PushField gains a variant.

Verified:
- m3-max-42097 (msi), this change on cd5a76a757: clippy -p metal2vulkan --all-targets
  --all-features and rustdoc -D warnings green; nextest all() of metal2vulkan, 3,689 of 3,693
  passed. The four failures were development's own (the new pad_simd_shape and
  vector_word_phases fixtures had no table rows), re-blessed at 74669c0552.
- m3-max-42098 (msi): clippy --cfg m2v_gpu and --cfg m2v_cpu_icd green.
- m3-max-42192 (msi), this tip on the samplers landing on 58891b9ce5: golden_hashes_match_the_table,
  public_fixtures_engine inventory and llvm_as part 8, and air_input's engine golden printouts
  pass.
- engine_identity a_constexpr_sampler_is_the_set_1_element_its_pushed_index_names: sample_up and
  the same kernel through a linear pixel sampler link and pass L3 on every profile and on
  moltenvk-m3 without robustImageAccess2. Their push fields are the two texture IDs and
  ConstexprSampler(c) of the normalized use, with no spec constant but LocalSize, no immutable
  sampler and no ConstexprSampled fact; set 1 bindings 0, 1 and 2 are used; constexpr_sampler
  gives a normalized device sampler. PixelSamplerScaling is recorded for the pixel kernel under
  identity, and under the default domains, which hand that kernel the unnormalized sampler, it is
  not.
2026-11-17 12:46:53 -08:00
Anees Iqbal 445b720f78 identity: texture slots sampled through runtime sampler slots from set 1's sampler arrays
Under the identity domains a kernel samples a texture slot through a runtime sampler slot. The
texture is its class's set-1 element at the index of its pushed gpuResourceID, as a read's is.
The sampler is the element of a set-1 sampler array at the index of the sampler slot's pushed
gpuResourceID (SlotGuestBase of the sampler slot), joined to the texture by OpSampledImage. The
array is picked by the use: binding 2 for a plain sample, 3 for a depth comparison, 4 for a
texture of an integer format; 4,000 SAMPLER descriptors each, PARTIALLY_BOUND |
UPDATE_AFTER_BIND | UPDATE_UNUSED_WHILE_PENDING, every stage, the same set 1 for every pipeline.
The sampler's word (pixel coordinates, a nearest pixel sampler) is read from the ID's high word,
so no specialization constant and no SamplerReduction, SamplerCoordinates, CubicSampler or
ConstantLanes fact remains; every precision note is static. An integer write to a storage slot
without a format saturates to the channel widths the consumer pushes
(PushField::TextureIntegerChannels, a u32), with no fact.

Still refused as Unsupported{IdentityDomains}: constexpr samplers (next change: a pushed index),
an argument buffer's sampler, arrays of samplers, bicubic and anisotropy emulation, a slot's
minimum level.

Translation output changes only under the identity domains (Device::from_queries). Device::new
output is unchanged: golden_hashes_match_the_table passes at this tip (job m3-max-42189), with no
"changed under an unchanged key" and no "profile changed:" line.

For the runtime's side (the planner's three facts):
a. The runtime must dedupe device samplers by create info across the three arrays' uses.
   Exhausting maxSamplerAllocationCount (4,000 on the 2080, 3090 and UHD 630; 32,768 on
   lavapipe; 65,536 on the others) must be a typed refusal, with a fill-past-capacity test.
b. The update-after-bind limits for 65,536 sampled images, 4,096 storage images and 12,000
   samplers hold on all nine profiles (the smallest is lavapipe's 1,015,808); the floor must
   check them by query.
c. The count of cubic sampler descriptors is asked of the replay lane; if any exist it goes back
   to the planner before step 5 closes.

SEMANTICS_VERSION 2161: identity-domain modules of sampling kernels and integer writes change.

Verified:
- m3-max-42094 (msi), this change on cd5a76a757: clippy -p metal2vulkan --all-targets
  --all-features and rustdoc -D warnings green; nextest all() of metal2vulkan and metal2vulkan-rt,
  3,719 of 3,723 passed. The four failures were development's own (the new pad_simd_shape and
  vector_word_phases fixtures had no table rows), re-blessed at 74669c0552.
- m3-max-42096 (msi): clippy --cfg m2v_gpu and --cfg m2v_cpu_icd green.
- m3-max-42189 (msi), this tip on 58891b9ce5: golden_hashes_match_the_table,
  public_fixtures_engine inventory and llvm_as part 8, and air_input's engine golden printouts
  pass.
- engine_identity: sample_down links and passes L3 on every profile and on moltenvk-m3 without
  robustImageAccess2, with set 1 bindings 0, 1 and 2 used, no spec constant but LocalSize, and no
  sampler fact; an integer write of (300, 70000, 5, 2^31) stores (255, 255, 5, 255) under the
  RGBA8Uint word and the raw lanes under word 0, on the CPU interpreter.
2026-11-17 12:46:10 -08:00
Anees Iqbal 75b422338a identity: argument-buffer textures are the set-1 elements their resource IDs name
Under the identity domains an argument buffer's texture handle is the gpuResourceID its member
holds: the handle is the ID's index, the element of the class's set-1 array (0 is nil, the null
descriptor), with no handle table, no search and no descriptor. Where the shader checks a read
itself (no robustImageAccess2) the handle carries the word's missing-alpha bit (word bit 12) at
HANDLE_ALPHA_ONE, so the handle form is Lookup::Element or Lookup::Flagged{alpha} only.

The handle tables' variant forms are off under these domains (`texture::tabled`): reads of a
member of another numeric class, raw-texel decodes, storage conversions (red-blue, sRGB alias),
A8 alpha-in-red, unreadable-storage nulls, YCbCr write marks, and the HeapCrossClassNeutral,
HeapStorageReads and HeapResidency facts. A slot and a member of one class index one array, so
the class's volatility now merges the slots' uses with the groups'. The admission takes heap
groups whose declaration is their identity class with no plain, raw or cross classes; anything
else stays Unsupported{IdentityDomains}.

Translation output changes only under the identity domains: the default domains plan and emit
as before (no golden re-bless needed). SEMANTICS_VERSION 2153.

The test kernel `tex` gains an argument-buffer form (`texture_kernel(true)`), checked on
lavapipe, moltenvk-m3 and moltenvk-m3 without robustImageAccess2: same answers at the same
elements, set 0 empty, and the handle form Element or Flagged{alpha} as the profile checks reads.

Verified (this commit's tree, as 657e2245c2 on 2872c419e0):
- msi 41756: clippy -p metal2vulkan --all-targets --all-features -D warnings, rustdoc
  -D warnings, nextest -p metal2vulkan -p metal2vulkan-rt in full: 3,701 of 3,702 pass; the one
  failure is golden_hashes_match_the_table, stale under development's own profile change.
- msi 41800: that golden test with every difference listed: 7,260 cells under a changed profile
  fingerprint (development's at 2872c419e0; this commit changes no profile field), no cell whose
  value moved, no cell changed under an unchanged key. Fixtures that need metal-as (macOS) are
  not compared there.
- msi 41757: clippy under --cfg m2v_gpu and --cfg m2v_cpu_icd.
- msi 41712, 41713 and 41752: the same at 160a3c5bae on 9cb90de8cc (SEMANTICS 2152 there), the
  golden test matching 1,815 rows x 19 profiles.
2026-11-17 10:56:25 -08:00
Anees Iqbal fa52012831 identity: texture slots are the set-1 elements their pushed resource IDs name
Under the identity domains a kernel's texture slots now lower. A slot's
gpuResourceID is pushed as its PushField::SlotGuestBase (the index in the
low word, the word in the high one). Its texture is the element at that
index of one of set 1's two fixed arrays: binding 0, SAMPLED_IMAGE x
65,536, and binding 1, STORAGE_IMAGE x 4,096. Each is partially bound,
updated after binding and while unused elements are pending, and seen by
every stage, with the same layout for every pipeline
(BindingSource::IdentityArray). Each image class the kernel declares
(shape, numeric type and depth comparison, sampled, or storage without a
format) is a variable of its descriptor type's binding. The slot binds no
descriptor and declares no specialization constant:
- is_null_texture answers whether the index is 0. Nil needs nothing
  else in the shader, since element 0 of each array is a null descriptor
  (the device test of ba4454b05b).
- A read the shader checks itself takes Metal's out-of-bounds alpha of 1
  from bit 12 of the word (TextureWord::OUT_OF_BOUNDS_ALPHA_ONE).
- The ResourcePresence and OutOfBoundsAlpha facts are not stated there.

No binder chooses a variant under identity, so a slot reads whatever
texture its ID names through the plain form:
- the variant facts (cross-class reads, planes read in place, texel rows,
  texture-buffer parts) are not stated;
- a float or half read takes the device's sRGB decode with
  PrecisionNote::SrgbTexelDecode (VkProperty::MetalSampler on MoltenVK),
  as a heap element's does, with no SrgbTexture twin;
- no texture is sparse (the consumer refuses one): no write-dropping
  SparseTexture constant and no ConstantLanes;
- a storage slot is formatless with no StorageTextureFormat fact. Where
  the device cannot access it without a format, the slot is refused as
  Unsupported{IdentityDomains} instead of asking for an input no consumer
  gives there.

Admission stays typed. Under identity, a function is refused as
Unsupported{IdentityDomains}, not implemented, if it:
- samples (any sampler plan; Metal's own sampler as a requirement is
  allowed);
- reaches textures through argument buffers (any heap group);
- declares a slot with no identity class: texture buffers, level views,
  cube-as-array, planes, extended range, RGBX, ulong, or a storage
  image with a format;
- uses a slot whose state comes from anything but its ID: border texels,
  sparse residency arms, a half conversion by the bound format, swizzles,
  offset bases;
- carries a fact naming such state (identity_unsourced).
That keeps the arm64-only forms (two-plane, extended range, sRGB twins)
out of the identity domains, as the x86 scope wants. The old binder
refuses an identity array as an internal error, since the consumer
writes those arrays.

SEMANTICS_VERSION 2150 (identity output changes), ARTIFACT_FORMAT_VERSION
529 (BindingSource gains IdentityArray). docs/RESOURCE-ID.md says what the
arrays are and what the shader reads of an ID. docs/API.md says what the
identity domains lower. The refusal surface and the API signatures are
regenerated. The blessed table also gains
metal2vulkan-rt::PrecisionNote::CappedLodBias, a variant development's
table lacked.

Verified, on development cfa389aa9b (check commit 564d131163, same tree):
- msi, job m3-max-41519: clippy -p metal2vulkan --all-targets
  --all-features -D warnings, rustdoc -D warnings, and nextest of
  metal2vulkan's whole suite: 3672 tests run, 3672 passed, 20 skipped.
- msi, job m3-max-41520: clippy of metal2vulkan under --cfg m2v_gpu and
  --cfg m2v_cpu_icd, both clean.
- The new test, texture_slots_are_the_set_1_elements_their_pushed_resource_ids_name,
  runs on lavapipe, moltenvk-m3, and moltenvk-m3 without
  robustImageAccess2. Its words come from tests/resource_words.tsv rows
  70 and 10, checked against TextureWord::of. It checks the fixed set-1
  layout and that the pushed fields are exactly the buffer, the three
  texture IDs and the region. On the interpreter, with the source at
  sampled element 3 and the destination at storage element 2, it checks
  the reads, the writes, the width and is_null_texture both ways (index
  0 and index 1). On moltenvk-m3 without robustImageAccess2, where the
  shader checks the read, the source image traps any access outside it
  and the out-of-bounds alpha comes from bit 12 of the word: 1.0 for
  R8Unorm, 0.0 for RGBA8Unorm. On the other two profiles the device's
  robust texel answers.
- The same change on the earlier base 9a3b6587b2 (jobs m3-max-41478 and
  41479): 3670 of 3670, clippy clean in all three configurations.
2026-11-17 09:51:53 -08:00
Anees Iqbal 737ccbf81a metal: the resource ID word, its spec and test vectors
Under the identity binding domains a guest computes a texture's or sampler's gpuResourceID itself,
with no round trip: the index the consumer grants in the low 32 bits and a word in the high 32 bits
that is a pure function of the Metal descriptor. The guest's port needs the word specified and a
file of vectors both sides check.

- metal::resource_word::TextureWord::of(pixel_format, swizzle): bits 0-11 Metal's border texels
  after the swizzle (the existing border_texels rule), bit 12 the out-of-bounds alpha of a format
  without alpha, bits 16-31 the MTLPixelFormat raw value, so a texture's word is never 0. None for
  the placeholders and the formats the translator holds no texture of or only copies.
- The sampler word is the existing SamplerWord, unchanged.
- docs/RESOURCE-ID.md: the ID's layout, the index classes (0 nil; storage-capable textures 1 to
  4,095, valid in both arrays; other textures 4,096 to 65,535; samplers 1 to 3,999), both words'
  bits and the level rule, and the vectors file. README's documentation table lists it.
- crates/metal2vulkan/tests/resource_words.tsv: 392 vectors (every pixel format with a word under
  the default swizzle, each channel of seven formats from each other source, every sampler field
  through its values, the level clamps around the points the nearest level turns at, and one
  descriptor with every field changed). tests/resource_words.rs recomputes every line through the
  public API and holds the file equal to what the generator writes; an ignored test blesses it.
- api_surface lists the new module; api_signatures regenerated.

Verified:
- msi job 40810 at the same tree: clippy -p metal2vulkan --all-targets --all-features -D warnings,
  rustdoc -D warnings, nextest 18 of 18 (resource_words, the TextureWord unit test, api_surface,
  api_signatures).
- msi job 40811 at the same tree: clippy under --cfg m2v_gpu and --cfg m2v_cpu_icd.
- msi job 40809: the bless test wrote the vectors; the combined sampler line (0x58f6ab53) and the
  A8Unorm and R8Unorm texture lines checked by hand against the bit tables.
2026-11-17 07:01:32 -08:00