Refuse a pipeline of an unspecialized function that declares constants

Since functions whose constants are left undefined compile (a2e34a9d2f),
the runtime made a pipeline state of a function made by
newFunctionWithName: whose function declares function constants. Plain
Metal ends its process there, at every creator's descriptor validation
(probes/undefined_function_constant_values.m, new cases <how>:<shape>,
on the M3 Max under macOS 27.0.1, MTL_DEBUG_LAYER unset, exit 134):
"Compute Pipeline Descriptor Validation / function ko cannot be used to
build a pipeline state. Use newFunctionWithName:constantValues:... to get
the specialized function"; the render and mesh creators name
vertexFunction, fragmentFunction, objectFunction and meshFunction, and
the tile creator says "without setting constant values first". It does
so for an optional constant read only where is_function_constant_defined
says (ko) and for a constant that only gates arguments (kg). Made: a
function made by name that declares none (kn, plain, tile-plain,
mesh-plain), and every shape made with constant values that hold none or
by newFunctionWithDescriptor: without them (each then answers an empty
functionConstantsDictionary; ko stored 7, kn 9).

- metal2vulkan: FunctionDescriptor gains `specialized` (false by default,
  a function made by name; a descriptor with constant values is
  specialized whatever it says) and with_specialized, and
  needs_specialization(budget, entries) answers whether Metal makes no
  state of the stage: not specialized and a non-empty
  functionConstantsDictionary. A module function's constants are read
  through the StageEntries' module decodes (constants_dictionary_with),
  which the stage's compile copies, so the check decodes nothing the
  compile does not. The compile itself is unchanged.
- metal2vulkan-runtime: Function::function_descriptor marks the stage
  specialized where the function was made with constant values or by
  descriptor. pipeline/unspecialized.rs refuses before anything is
  compiled, Invalid with the new Problem::UnspecializedFunction { stage,
  name }: compute and tile states (of_kernel), render states (vertex,
  fragment) and mesh states (object, mesh, fragment). A linked function
  keeps its own rule (LinkProblem::UnresolvedConstant).
- Pipeline records carry the stage's specialized flag, RECORD_FORMAT 3:
  without it every specialized stage's record read back unspecialized
  and went unrecorded.
- The owned fixture engine/unspecialized_stage_functions (the probe's
  shapes at every stage); its golden rows, inventory and printout are
  new rows only (11 functions by 2 forms in each table).
- docs/API.md ("Function constants"), the FunctionConstantValues and
  creators' docs, the runtime README, docs/REFUSALS.md regenerated, the
  signatures blessed (FunctionDescriptor.specialized, with_specialized,
  needs_specialization, Problem::UnspecializedFunction).

Verified:
- metal2vulkan tests::engine_unspecialized 2/2 (every declaring function
  of the fixture needs specialization made by name, no free one does,
  and the eleven answers read one module decode, (1, 10); specialized or
  valued, none does, decoding nothing).
- On MoltenVK (M3 Max) through maclock, --cfg m2v_gpu:
  runtime_lane::unspecialized_functions 3/3 (by name: guarded and gate
  kernels, vertex, fragment, tile, mesh and object refused; free kernel
  stores 9; plain render state made; empty-valued and descriptor-made
  guarded kernels store 7, gate kernels made, render states made; tile
  and mesh states of them not refused as unspecialized) and
  runtime_lane::linked_functions 2/2.
- metal2vulkan-runtime suite 1177/1177; tests::warm_record 4/4.
- metal2vulkan and metal2vulkan-air: 3748 of 3753 before blessing, the 5
  failures the new fixture's table rows; after blessing they and the
  signature and surface tests pass.
- Negative controls: needs_specialization answering false fails
  engine_unspecialized's by-name test; function_descriptor without the
  specialized flag fails all three lane tests (the empty-valued and
  descriptor-made functions refused); the stage flag removed from the
  record's writes and reads fails the four warm_record tests.

(Carried to development from steelbrain/reims-graphics-kext 116efd0dfe.)
This commit is contained in:
Anees Iqbal committed 2026-11-01 21:26:18 -08:00
1 parent c4523d1bdb
commit e54a2c12aa
27 files changed
+2016 -26

No files matched your search

+13 -3
View File
@@ -3696,9 +3696,19 @@ each item named states the rule in full.
alone is its type's zero (an `and`, `or` or `mul` with a constant that decides it is that
constant), and a branch or `select` on one takes its false way; a value it meets with one the
run computes is computed with that zero. As Metal's, `is_function_constant_defined` is false for
it and an argument gated on it, negated or not, is absent. Metal makes the same pipeline, and its
reads of the constant vary from read to read: on an M3 Max under macOS 27.0.1 it read `u + 3` as
0, `u * 7 + 1` as 1, `u == 0 ? 111 : 222` as 222 and `b ? 5 : 6` as 5.
it and an argument gated on it, negated or not, is absent. Metal makes the same pipeline of a
specialized function (made with constant values, none among them too, or by
`newFunctionWithDescriptor:`), and its reads of the constant vary from read to read: on an M3
Max under macOS 27.0.1 it read `u + 3` as 0, `u * 7 + 1` as 1, `u == 0 ? 111 : 222` as 222 and
`b ? 5 : 6` as 5. The compile is the same for a function made by `newFunctionWithName:`, which
Metal makes no pipeline state of where its function declares a constant: its creation ends the
process at every stage ("function ko cannot be used to build a pipeline state. Use
newFunctionWithName:constantValues:... to get the specialized function"), whether the constant
is required, read only where `is_function_constant_defined` says, or only gates an argument.
`FunctionDescriptor::needs_specialization` answers it (`FunctionDescriptor::specialized` and the
function's `function_constants_dictionary`), and the runtime refuses such a state as Metal does
(`Invalid` with `Problem::UnspecializedFunction`). A linked function keeps its own rule (section
3, "Linked functions: names and constants").
- **A linked function's constant without a value reads as zero too**, where the function was made
specialized (section 3, "Linked functions: names and constants"). Metal makes that pipeline,
and its read is undefined: a kernel storing `x * scale + 1` of such a function stored nothing on