Commit Graph
8 Commits
Author SHA1 Message Date
Anees Iqbal 1b119af370 Pin the two unsupported classes that actually turn up
`tests/must_fallback.rs` exists so a refactor cannot quietly turn a clean FALLBACK into SPIR-V that
"succeeds" with garbage, and it covered the classes that were easy to name: raytracing intrinsics,
emask intrinsics, texture atomics, malformed modules. It did not cover either of the two classes
that account for almost every real rejection.

Measured over the 2880-source local corpus sample: 204 sources do not translate, and 191 are one of
two shapes -- a call through a Metal visible function table (136) and an intersection whose custom
intersection functions come from a function buffer (about 55). Both are function pointers, which
Logical SPIR-V does not have, so neither is a lowering waiting to be written; the only way they can
change is by becoming wrong. Each is now an authored kernel in the negative suite, and each was
checked to produce the same diagnostic the corpus sources produce, through the public
`translate_sanitized_native` path rather than a component entry point:

    unsupported indirect call through function pointer %fp (Metal visible function table)
    unhandled air.* intrinsic: air.intersect.intersection_function_buffer.triangle_data

Both inputs are authored, not extracted: the `HEAD`/`TAIL` template already in that file with one
construct injected, so the rejection is attributable to the construct and to nothing else --
`base_kernel_translates` is the anchor for that. `kernel_with_declarations` is the only new
scaffolding, for the two cases whose callee needs declaring.

The `intersection_function_buffer` tag suffix is a combinatorial family -- the corpus alone has
`instancing`, `triangle_data`, `world_space_data`, `user_data`, `primitive_motion`,
`instance_motion` and `multi_level_instancing` in about twenty combinations. The rejection is on the
`intersection_function_buffer` stem rather than on any one combination, so one of them stands for
all of them and the test says so.

Tests only; no product code changed. Full gate green.
2026-08-31 19:33:18 +03:00
Anees Iqbal 1eec182d2b Record each merge split instead of re-deriving the whole function's dominance after it
`privatize_reused_emitted_merge_targets` gives every owned construct its own merge by splitting
edges into a shared merge target. It called `loopforest::analyze(blocks)` once per claim, so a
function with one construct per block paid a whole-function analysis per construct. Measured on a
generated irreducible chain (`tests/bounded_growth.rs` builds the same shape):

    blocks   before   after
      1502    2.99s   0.40s
      3002   11.53s   1.27s
      6002   27.92s   4.87s

The 6002-block case was over the hard 20-second per-attempt ceiling in AGENTS.md. 87% of its
samples were inside that one call; a 750-claim run over 250 distinct targets re-derived dominance
750 times.

Two things were wrong and both are structural.

The pass only ever asks whether one block dominates another -- it never touches a natural loop --
but it asked for the loop forest, which pays for back-edge discovery, a body closure per header,
and a nesting comparison between every pair of loops before it can answer. `graph::block_dominators`
is now the way to ask the narrow question.

And re-deriving after a split is not needed at all. A split inserts one pass-through `S` between
some predecessors of `T` and `T`; every path through `S` is the old path with `S` elided, so
dominance among the blocks that were already there is exactly unchanged, and every path to `S` is a
path to one of its predecessors plus one edge, so a block dominates `S` exactly when it dominates
all of them. `graph::PassThroughDominance` computes the relation once and records each split.
Recorded splits resolve transitively to original blocks, so a pass-through carrying an earlier
pass-through is answered too.

`a_recorded_pass_through_answers_what_a_fresh_analysis_answers` performs two chained splices by
hand and cross-checks every dominance pair against the definitional path oracle already in that
file, so the equivalence is checked rather than argued.

`tests/bounded_growth.rs` gains the guard for this defect class. A peak-memory bound cannot see it:
each dominance table is linear and short-lived, so the high-water mark stays flat however many
times it is rebuilt. Total bytes handed out does see it. Doubling the function multiplied total
allocation by 3.71 before (187 MB -> 694 MB) and by 1.95 after (27 MB -> 54 MB); the bound is 2.6,
between them, the same way the existing peak bound sits between 2.00 and the dominator-set
representation's 3.85.

Verified byte-identical over 2880 local corpus sources and over the generated chain at 752, 1502,
3002 and 6002 blocks. Full gate green: fmt, clippy `-D warnings`, rustdoc `-D warnings`,
`cargo test --release -p metal2vulkan`, `cargo test -p metal2vulkan-validation`, and the debug
build so the new `debug_assert!` runs.

Still superlinear, and not claimed fixed: the per-claim scan over every block remains, now at a
couple of hash lookups each rather than a rebuilt analysis. A 12002-block chain still takes 18.3s
before returning an honest construction FALLBACK.
2026-08-31 18:44:17 +03:00
Anees Iqbal de7a3b7ba2 Measure that translation memory grows with the function, not its square
The 500 MiB per-translation budget does not get broken by leaks; it gets broken
by an analysis whose representation is quadratic in the block count. One such
representation shipped and stayed for a long time, because nothing about it is
visible on a small graph and every individual translation it produced was
correct.

`tests/bounded_growth.rs` installs a counting global allocator, translates a
generated kernel at 302 and 602 blocks, and asserts that doubling the function
does not much more than double peak translation memory. The ratio is a property
of the code rather than the machine: the allocator counts bytes the translation
asked for, which is the same number on any host, so this is not a microbenchmark.

The generated function is a chain of irreducible pairs. That shape is what
reaches the nesting structurizer's reducibility question -- the one that carried
the quadratic table -- and it also forces the whole function onto the
CFG-construction path instead of the ordinary structured planner, so the
analyses under test actually run.

Calibrated by running it against the defect: with the dominator-set form put
back behind `Graph::dominators`, the two functions measure 4.59 MB and 17.66 MB,
a 3.85x growth, and the test fails with that number in the message. With the
tree form they measure 2.50 MB and 5.00 MB, exactly 2.00x. The limit is 2.6.
2026-08-31 18:19:11 +03:00
Anees Iqbal a5e01c3f0e Take five more emission decisions off hash-map iteration order
A kernel with an unbound buffer parameter translated to different bytes on
almost every run. Its loads from the absent resource each become a copy of
that type's null, and the nulls were minted by iterating a HashSet of the
load result types -- so three loads of three distinct types came out in one
of six orders. tests/deterministic_output.rs has the reduced kernel, plus a
probe asserting it still reaches that rewrite, so the test cannot quietly
start passing over nothing.

Auditing the rest of the pipeline for the same shape -- a hash collection
whose iteration order decides what gets minted or pushed -- found four more:

  native/psb.rs                 OpTypePointer per memory-view pointee
  native/rewrites.rs            wrapper struct + pointer + decoration per
                                candidate pointer type
  passes/.../texture_array.rs   one access-chain id per bound handle, and
                                the dead-root list
  passes/.../selected_load.rs   OpDecorate ArrayStride per pointer type

Each now walks the module's own instruction stream instead, which makes the
order a property of the input. src/emission_order.rs holds that idiom in one
place so the correct spelling is the short one, and says which collection
each kind of question wants: a HashSet is still right for pure membership,
where nothing is ever iterated.

Verified over 900 local-corpus sources: 820 translated, 0 varied across four
in-process translations each. Before these fixes the same sweep found 24
varying inputs in its first 400.

The cross-stage fixture sweep is new and is what made the reduction findable:
determinism has to hold for whatever stage the caller passes, and translating
each fixture at all three reaches paths the declared stage never does -- a
parameter the declared stage binds to a descriptor is an unbound Private
placeholder under another.
2026-08-31 16:08:04 +03:00
Anees Iqbal e73c87d49b Stop three emission decisions from following hash-map iteration order
The same AIR translated to different SPIR-V on every run. Not different ids that
canonicalization normalizes away -- genuinely different modules: a different
prologue order, different constant declarations, different type declarations. Each
run was individually correct and passed spirv-val, which is why nothing caught it.

It matters because the validation ladder compares a candidate's output by SHA-256,
consumers cache translated SPIR-V by content hash, and a bug report is only
reproducible if the module that produced it can be produced again.

Three sources, all the same shape -- an unordered collection deciding the order
something is emitted or minted in:

- native emitter (functions.rs): the device-address prologue materializes one
  address per direct buffer parameter, and that list was built by iterating
  `raw_offsets`. The position each address lands at fixes which address-table slot
  the module reads there, so the whole prologue permuted. Order by entry parameter
  ordinal, which is stable and is the order a reader expects. The rewrite also
  drops a redundant `contains_key` and, with it, an eager map index that would have
  panicked on any raw offset that is not a direct parameter.
- buffer-address lowering (buffer_addresses.rs): `ctx.const_uint` mints a constant
  the first time it sees a value, so the order the table's location constants were
  requested in -- taken from a `HashSet` -- was their declaration order.
- nesting structurizer (reloop_nest/emit.rs): `demote_phis` walked `blocks.keys()`,
  minting a variable and a `TypePointer Function` per demoted phi in hash-map
  order. Record the function's own block order at indexing time and walk that.

tests/deterministic_output.rs pins the contract. Rust seeds every HashMap's hasher
differently, including two built in the same process, so translating one input
twice in one test is enough to expose an order-following emission decision -- it is
strictly stronger than comparing two CLI runs, and it found the second and third
sources after the first was already fixed. It covers an authored four-buffer
device-address kernel (with a guard that the kernel still lowers to an address
table, so the case cannot decay into covering nothing) and every public fixture
that translates.

Verified: the authored kernel produced 6 distinct hashes in 6 CLI runs before the
first fix and 1 after; 12 in-process runs collapsed from 2 distinct modules to 1
after the second. Over 1267 sampled local-corpus sources, 1159 translated and 2
still varied before the third fix; after it, a 240-source sample was fully stable
and the two known varying cases were checked individually. cargo test -p
metal2vulkan: 1704 lib + 3 determinism + 3 env + 6 fallback, all passing.
Workspace clippy -D warnings and all-features Rustdoc: clean.
2026-08-31 15:39:00 +03:00
Anees Iqbal 8b78eaca3b Expand macOS 26 AIR translation coverage
Overhaul the validation workflow around sharded authored cases, dependency-exact observations, incremental indexed corpus audits, bounded parallel translation, and native Metal/Vulkan comparison.\n\nExpand native AIR lowering, reflection, linked-function specialization, resource and stage-interface support, and structural CFG/pointer repair across the harvested macOS 26 corpus. Add exact intrinsic inventory, distributed 16x16x16 matrix lowering, explicit opaque tensor linkage, and regression coverage for the newly supported feature classes.\n\nThe final corpus verification accounts for all 88,819 indexed AIR modules under the current product fingerprint: 65,355 translate and validate directly, 23,464 require exact authored linkage, and zero fail or remain unresolved.
2026-08-13 21:46:27 +02:00
Anees Iqbal 1b013834bc Improve translation correctness and oracle safety
Add structural lowering fixes for function constants, byte aggregates, texture arrays, sampling, and SIMD operations. Harden corpus oracle planning and quarantine unsafe or non-comparable rows without GPU resubmission. Reject reused SPIR-V merge ownership and fast-fallback oversized systematic CFG failures so broken AIR returns promptly instead of emitting invalid bytes after lengthy retries.
2026-08-10 16:54:26 +02:00
Anees Iqbal 3007485352 🆕 Open Source metal2vulkan 2026-07-22 13:15:24 +03:00