rt: a kernel past the stage bound is made from its helper's compile alone, never compiled in the process

A driver's compiler takes memory that grows faster than the stage, in the process that creates the
pipeline. The translator refused every stage past COMPILED_STAGE_WEIGHT (99,109, the heaviest
measured to compile within host-sized memory, ANV on the Iris Xe of RPL-P), where Metal makes it.
Now the translator states the weight and the runtime compiles such a kernel only in a helper
process the consumer starts, caps and times.

Translator: the stage bound refuses nothing. stage_bound::emit still plans a kernel again keeping
its widest-mode pin where only that emulation passed the bound, and returns the module with its
entry weight, now ModuleStats::entry_weight (codec and serde carry it). COMPILED_STAGE_WEIGHT is
public in pipeline. Feature::StageSize and Needs::StageBound are gone. SEMANTICS_VERSION 2257,
ARTIFACT_FORMAT_VERSION 588.

Runtime (new stage.rs):
- Floor: pipelineCreationCacheControl, required and enabled (Vulkan 1.3 requires it), for
  VK_PIPELINE_CREATE_FAIL_ON_PIPELINE_COMPILE_REQUIRED_BIT.
- A kernel's VkPipeline of a module past the bound is made from a VkPipelineCache of its own entry
  in the cache directory's stages/ alone, with the fail-on-compile-required flag, the cache
  destroyed when the create returns; the device's shared cache and blob never hold it
  (Metrics::pipelines_from_stage_fills).
- With no entry the make is refused with Error::StageUnfilled(StageRequest), at the state's
  creation, at prepare_dispatch (which now returns Result and reports only this refusal) and at
  the dispatch. A StageRequest is Clone, Send, Sync, Eq and Hash by its stage key, the entry's
  name, so a consumer joins the makes and dispatches of one pipeline into one fill.
- Device::fill_stage writes the request to the helper's pipe, reads its reply and keeps the
  cache data as the entry (Metrics::stage_fills); serve_stage is the helper's main: it opens the
  device of the request's deviceUUID and driverUUID with the parent's options, checks the
  enables, compiles through an empty cache and writes its data. A wire frame is the magic
  m2vstage, the wire version, the length and a checksum.
- Device::record_stage_breach keeps what the consumer ended its helper for (memory, time) as the
  entry; fill_stage keeps a failed compile; a create answered compile-required keeps that. Each
  refuses the pipeline (Gap::StageSize, StageGap::Breach) with no helper asked again, until the
  driver's header changes the key.
- stages/ holds at most 256 MiB and 32 entries, breaches among them, least recently used out
  first (a hit touches the file). An entry that does not check, of another key or another
  driver's header is a miss and is removed. Nothing of an entry stays in memory past the call
  that reads or writes it.
- A device with no cache directory, or whose driver writes no pipeline cache header (lavapipe),
  and a render stage past the bound are refused typed (Gap::StageSize with its StageGap).

The validation runtime executor reports a refused prepare_dispatch; the replay prepass ignores it
as the dispatch reports it again.

Docs: the runtime README's "Kernels past the stage bound" and its known gaps, the stages/
directory, prepare_dispatch's one error, the floor row; docs/API.md's entry_weight;
docs/REFUSALS.md regenerated; the api signature and surface tables.

Tests: tests/stage.rs: the directory past capacity on both bounds, oldest use out first, a hit
outliving older entries, a breach under the same bounds; cut, foreign-key, other-header and
unknown-breach entries a miss and removed; the wire's version and cut frames; the request's
joinable bounds; and on a device (m2v_gpu, m2v_cpu_icd), with the bound lowered for the test, the
refusal with no directory, lavapipe's NoPipelineCache, and elsewhere refused unfilled, filled by
serve_stage over two pipes, made from the entry alone with the shared cache's data unchanged,
then refused by a recorded breach.
This commit is contained in:
Anees Iqbal committed 2026-11-21 05:55:29 -08:00
1 parent e6e70666ed
commit c3f9f55e63
38 files changed
+1591 -199

No files matched your search

+8 -3
View File
@@ -508,6 +508,14 @@ assert!(stats.reachable_blocks <= stats.blocks);
a program far larger than its own blocks; the two read alike in `blocks` alone. Lowering emits
such functions itself: the handle-table search (unrolled branch-free steps) and the root-table
search (a loop), each emitted once and called at every access.
- `entry_weight` is what a driver compiles once it has inlined every call: the entry's
instructions with each call counted as its callee's body, after repeated regions are rolled
into loops. A stage past `pipeline::COMPILED_STAGE_WEIGHT` (99,109, the heaviest measured to
compile within host-sized memory on the slowest compiler measured) is one whose creation may
take the host's memory: the translator makes it all the same, and `metal2vulkan-runtime`
compiles such a kernel only in a helper process the consumer caps (its README, "Kernels past
the stage bound"). A kernel past the bound only because it emulates its SIMD groups is planned
again keeping the device's widest subgroup mode pinned, where that plan is lighter.
- Compare one module against the next of the same shader, not one shader against another. Measured
cost per block differed several-fold between a synthetic module and a real workload, so a
per-block figure taken from one shader predicts nothing for the next; `instructions` is the
@@ -1614,9 +1622,6 @@ match floor.compile_function(&min_lod, &LoweringInputs::new(), &Budget::standard
- `AnyOf`: alternative sets of device capabilities; a device that enables every capability of one
set compiles it.
- `NotImplemented`: a gap of this version. `NotRepresentable`: no Vulkan mechanism exists.
- `StageBound`: a stage that the device's plan writes heavier than the translator hands any
driver (the heaviest measured to compile within host-sized memory); `symbol` names its entry
weight and the bound. A device whose plan writes it lighter compiles it.
- `MetalGpuFamily`: a Metal GPU family the device does not claim, where Metal itself refuses the
input without it.