vyre-emit-spirv
SPIR-V binary emitter for vyre's KernelDescriptor.
Routes through vyre-emit-naga to produce a naga::Module first,
then uses naga::back::spv::Writer to output a SPIR-V binary. This
shares the lossless lowering work with the wgpu/naga path: both
backends consume the same naga::Module, and avoids forking a
second KernelOp → SPIR-V translation table.
Quick start
use ;
use DataType;
use ;
let desc = KernelDescriptor ;
let words = emit_optimized.unwrap;
assert_eq!;
API
emit(&desc) -> Result<Vec<u32>, EmitError>: lower as given. Output is SPIR-V words (the canonical representation per the spec).emit_optimized(&desc) -> Result<Vec<u32>, EmitError>: recommended. Runsvyre_lower::rewrites::run_allfirst; debug builds also runverifyviadebug_assert!.emit_optimized_with_stats(&desc) -> Result<(Vec<u32>, OptimizationStats), EmitError>: same asemit_optimizedplus optimization metrics.emit_bytes(&desc) -> Result<Vec<u8>, EmitError>: convenience for runtime loaders that want little-endian bytes.emit_optimized_bytes(&desc)/emit_optimized_bytes_with_stats(&desc): bytes-axis variants that also run the optimization pipeline first.emit_from_naga_module(&module) -> Result<Vec<u32>, EmitError>: lower-level entry point if you want to apply naga-level rewrites betweenvyre_emit_naga::emitand SPIR-V conversion.
Constants
SPIRV_MAGIC: u32 = 0x07230203: the SPIR-V magic word per the spec. Useful for sanity checks on emit output.
Substrate-specific patterns
patterns/ contains SPIR-V-specific analyses:
subgroup_capabilities: walks the descriptor for subgroup ops (Ballot, Shuffle, Add, LocalId, Size) and produces aSubgroupCapabilities { basic, ballot, shuffle, arithmetic }flag set so the host knows whichVkSubgroupFeatureFlagBitsto require on the pipeline.workgroup_size_validation: checksdispatch.workgroup_sizeagainstVULKAN_BASELINE(or a customDeviceLimitsprofile). Catches per-dim overflow, product overflow, zero-dim violations.
Run patterns::audit(&desc) for a unified SpirvAuditReport with
both patterns. Run patterns::audit_optimized(&desc) to audit the
post-run_all form (subgroup capability detection may report fewer
required caps after dead-code elimination).
Validation
naga::valid::Validator runs before naga::back::spv::Writer, so
any module that gets to Writer is structurally valid per Naga's
spec compliance. The emitted SPIR-V binary therefore satisfies
SPIR-V's structural requirements as far as Naga's coverage goes;
optional external spirv-val validation can be wired into your CI.
Errors
EmitError::NagaEmit(naga_err): the upstreamvyre_emit_nagacall failed. Most oftenUnsupportedOp(...)for KernelOpKinds Naga can't represent.EmitError::NagaValidation(s): Naga's validator rejected the module. Indicates a bug in this crate or in vyre-emit-naga.EmitError::WriterConstruction(s)/WriterWrite(s): Naga's SPIR-V writer failed.
See also
vyre-lower: IR + rewrite stack + verify.vyre-emit-naga: the upstream emit path this crate routes through.vyre-emit-ptx: independent PTX emitter for CUDA.
License
MIT OR Apache-2.0.