Skip to main content

Module spirv

Module spirv 

Source
Expand description

SPIR-V emission target.

Unlike the other native targets (HLSL/MSL/PTX/CUDA-C), which print source in the foreign language, the SPIR-V target produces a binary SPIR-V module by reusing the deterministic WGSL the emit_wgsl path already generates, parsing it back into a naga::Module, validating it with the same capabilities as crate::wgsl_forge::validate::validate_wgsl (RAY_QUERY | COOPERATIVE_MATRIX | SHADER_FLOAT16), then lowering it through naga’s spv-out backend.

§Word encoding in GeneratedShader::source

GeneratedShader::source is a String, but SPIR-V is a sequence of 32-bit words. We serialize the Vec<u32> as ;-joined decimal words (e.g. "119734787;65536;..."). Decimal (rather than hex) keeps it unambiguous and trivially round-trippable with split(';') + u32::from_str; the first word is always the SPIR-V magic number 0x07230203 = 119734787 decimal.

Constants§

SPIRV_WORD_SEPARATOR
Separator between decimal SPIR-V words in GeneratedShader::source.

Functions§

decode_spirv_words
Decode a ;-joined decimal SPIR-V word string back into Vec<u32>.
emit_spirv
Emit a validated SPIR-V module for kernel/schedule.
emit_spirv_patched
Emit SPIR-V and patch the workgroup size to schedule.workgroup_size.
patch_spirv_workgroup_size
Patch the workgroup size in a SPIR-V binary to (x, 1, 1).