Skip to main content

WgpuCompiler

Trait WgpuCompiler 

Source
pub trait WgpuCompiler: Compiler {
    // 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,
        server: &mut WgpuServer<Self>,
        kernel: Box<dyn CubeKernel>,
        definition: KernelDefinition,
    ) -> Result<CompiledKernel<Self>, CompilationError>;
    fn normalize_repr(
        &self,
        repr: Option<Self::Representation>,
    ) -> (CompilerInfo, Option<AutoRepresentation>);

    // Provided method
    fn validate_runtime(
        _backend: Backend,
        _options: &WgpuCompilationOptions,
        _requested_backend: WgpuBackend,
    ) -> Result<(), WgpuCompilerInitError> { ... }
}
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.

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, server: &mut WgpuServer<Self>, kernel: Box<dyn CubeKernel>, definition: KernelDefinition, ) -> 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.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§