Skip to main content

Crate vulkane_kernel_text

Crate vulkane_kernel_text 

Source
Expand description

The shared text walker for Vulkane’s kernel emitters (ROADMAP rows 8a, 8b and 8g for GLSL and WGSL).

lower_kernel takes an Unpopped kernel-layer KernelFn and a Dialect and writes shader source. The walk (scope checks, statements, control flow, the structure of a For) is written once; a dialect supplies only the spellings that differ between GLSL and WGSL: declarations, the entry point, literals, operators, barriers.

§What it lowers (v1)

Integer kernels (I32/U32): buffer parameters, static Shared arrays, locals, Let, Load, Assign, Store, MaskedLoad and MaskedStore (ROADMAP 9e: a guarded plain access, so the memory is not touched where the mask is false), Barrier and Fence, If, For, While, Break, Continue, Return, and the expressions Local, ConstInt, Exec (thread, block, BlockDim, GridDim), Add, Sub, Mul, the comparisons, BitAnd/BitOr/BitXor, Shl/Shr (the count masked to the width, as the SPIR-V emitter does) and Select. Anything else is a typed UnsupportedKernel naming it.

§Semantics shared with the SPIR-V emitter

A comparison gives 1 or 0 in the compute dtype. A For evaluates its bounds once; a zero step leaves the loop at once (a shader cannot trap). A barrier under thread-divergent control is refused by check_kernel (BarrierDivergent) before any text is written.

§Refused by name

The thirteen NVIDIA-only statements of board 434 C and its extension (CopyAsync, Collective, MbarInit, WgmmaWait, …) and LaunchGrid (board 539) are refused by name, at any nesting depth, before the walk starts.

Structs§

Decl
A buffer or shared array the prologue declares.
Layout
Everything the prologue needs.
SubgroupCollective
One subgroup collective (board 506 “A”, narrowed) for a dialect to spell: the ruled reductions, shuffles, votes and broadcasts of crate::collective_is_ruled. The walker has already lowered the value and the operand to text, and the checker (check_kernel) has already refused a collective after a lane-divergent Return (CollectiveAfterReturn) or under lane-divergent control (BarrierDivergent).

Enums§

Coverage
What the emitters of this repository do with a statement.

Constants§

BIT_OPS
The bitwise operators both dialects spell with the same operator text.
COMPARISONS
The comparisons both dialects spell with the same operator text; each gives 1 or 0 in the dtype.
DECLINED_539
The reason text the board 539 refusal (LaunchGrid) carries.
DECLINED_434C
The reason text the four board 434 C refusals carry, so a caller and a test can recognise it.
DECLINED_434C_EXT
The reason text the seven board 434 C extended refusals carry.
DECLINED_MAX_DEPTH
The refusal text of a kernel that declares KernelFn::max_depth.

Traits§

Dialect
The spellings of one target language.

Functions§

collective_is_ruled
Whether a Collective of kind over scope is in the set CireSnave ruled liftable on non-NVIDIA targets (board 506 “A”, narrowed, 2026-11-26): subgroup-scope reductions (sum, product, max, min, and, or, xor), shuffles, votes and broadcasts. Everything else stays declined by name with the 434 C marker: scans (inclusive or exclusive, any op), user combines (ReduceWith, ScanWith), CollectiveTuple, and every Block-scope collective.
coverage
The coverage of stmt, dialect-agnostic: an emitter that lowers the ruled subgroup collectives (WGSL, MSL) lowers more than this says for a Collective, so ask coverage_in with its subgroup_collectives(). This match has no wildcard arm on purpose: it names every Stmt variant, so a new statement in unpopped fails to compile here until someone decides which of the four it is.
coverage_in
The coverage of stmt for an emitter that lowers the ruled subgroup collectives (lift_subgroup, the answer of Dialect::subgroup_collectives(): WGSL and MSL since #186) or not (every other emitter). It is coverage except for a Stmt::Collective that collective_is_ruled admits, which a lifting emitter LOWERS: coverage alone says “refused for exposure” (ROADMAP row 8w). It calls collective_is_ruled exactly, so what counts as lowered cannot widen here without widening there; the unruled kinds and scopes, and CollectiveTuple, stay Coverage::Patent for every emitter.
declined_by_name
The by-name refusal of the first declined statement in kernel (at any depth), or None.
declined_by_name_with
As declined_by_name, for a target that lowers the ruled subgroup collectives (lift_subgroup: see collective_is_ruled); the other collectives, and every other declined statement, are still refused by name.
lower_kernel
Lower kernel to source in dialect, or say why it cannot.
not_lowered_note
The sentence an emitter adds to its “not lowered” refusal of stmt: the row it waits for, the by-name ruling or the NVIDIA-specific reason, or None for a statement the emitters lower (a refusal of one is about its operands).
operator
The operator text op has in table, if any.
scalarize
kernel with every packed local, Pack and Extract replaced by scalars, or None when it has no packed local (the common case: nothing to do).