Skip to main content

WgpuCompiler

Trait WgpuCompiler 

Source
pub trait WgpuCompiler: Compiler<Representation: Send> {
    // Required methods
    fn init(backend: Backend, options: &WgpuCompilationOptions) -> Self;
    fn validate_ir(
        &self,
        repr: &Option<Self::Representation>,
        props: &DeviceProperties,
    ) -> Result<(), LaunchError>;
    fn compile_kernel(
        &mut self,
        kernel: &dyn CubeKernel,
        definition: KernelDefinition,
        options: &WgpuCompilationOptions,
    ) -> Result<CompiledKernel<Self>, CompilationError>;
    fn normalize_repr(
        &self,
        repr: Option<Self::Representation>,
    ) -> (CompilerInfo, Option<AutoRepresentation>);

    // Provided methods
    fn validate_runtime(
        _backend: Backend,
        _options: &WgpuCompilationOptions,
        _requested_backend: WgpuBackend,
    ) -> Result<(), WgpuCompilerInitError> { ... }
    fn limit_properties(&self, _properties: &mut DeviceProperties) { ... }
    fn target_properties(&self) -> TargetProperties { ... }
}
Expand description

Extension trait implemented by every compiler usable with the wgpu runtime.

The base Compiler trait already exposes a compile method that turns a KernelDefinition into a backend representation. WgpuCompiler sits one level higher: it owns the wgpu-specific lifecycle around a CubeKernel kernel — initializing the compiler for a given wgpu::Backend, compiling a kernel using the server’s WgpuCompilationOptions, validating the resulting IR against the device, and projecting the typed representation into the runtime-erased AutoRepresentation.

Its representation is Send so a compiled kernel can travel to the thread that builds its pipeline.

Required Methods§

Source

fn init(backend: Backend, options: &WgpuCompilationOptions) -> Self

Build the compiler instance appropriate for the given wgpu backend.

options is consulted to decide between alternative implementations (for example, to opt into the SPIR-V compiler on Vulkan when the device advertises the required features).

Source

fn validate_ir( &self, repr: &Option<Self::Representation>, props: &DeviceProperties, ) -> Result<(), LaunchError>

Validate that the compiled representation fits within the device’s resource limits.

Today this checks shared memory usage; additional checks may be added without breaking the contract.

Source

fn compile_kernel( &mut self, kernel: &dyn CubeKernel, definition: KernelDefinition, options: &WgpuCompilationOptions, ) -> Result<CompiledKernel<Self>, CompilationError>

Compile a runtime kernel into a CompiledKernel ready for pipeline creation.

Distinct from Compiler::compile, which only translates a KernelDefinition. This entry point operates on a full server-level kernel and pulls compilation options from server, so its signature cannot collide with the base trait method.

Source

fn normalize_repr( &self, repr: Option<Self::Representation>, ) -> (CompilerInfo, Option<AutoRepresentation>)

Normalize the backend-specific representation into the AutoRepresentation shared by every wgpu compiler, and report the CompilerInfo derived from it.

The CompilerInfo tells the server which parameter-passing strategy to use for the resulting pipeline.

Provided Methods§

Source

fn validate_runtime( _backend: Backend, _options: &WgpuCompilationOptions, _requested_backend: WgpuBackend, ) -> Result<(), WgpuCompilerInitError>

Check that this compiler can serve the selected graphics backend and device.

Explicit compilers should return an error instead of silently selecting another shader language. requested_backend preserves the unresolved selection; WgpuBackend::Auto allows automatic API selection. With msl enabled, AutoCompiler requires native MSL for an explicit Metal request; otherwise it permits WGSL fallback. Explicit compilers apply their own requirements.

Source

fn limit_properties(&self, _properties: &mut DeviceProperties)

Narrow the device’s properties to what this compiler’s kernels can reach. Most compilers reach the device’s own limits and leave them as they are.

Source

fn target_properties(&self) -> TargetProperties

What a kernel reads of this compiler’s target as it expands: how a manual MMA’s registers map onto its matrices. Only MSL lowers a manual MMA; the others keep the defaults, which nothing reads.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§