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: <WgpuServer<Self> as ComputeServer>::Kernel,
        definition: KernelDefinition,
        mode: ExecutionMode,
    ) -> Result<CompiledKernel<Self>, CompilationError>;
    fn lang_tag(&self) -> &'static str;
    fn normalize_repr(
        &self,
        repr: Option<Self::Representation>,
    ) -> (CompilerInfo, Option<AutoRepresentation>);
}
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 CubeTask 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: <WgpuServer<Self> as ComputeServer>::Kernel, definition: KernelDefinition, mode: ExecutionMode, ) -> 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 lang_tag(&self) -> &'static str

Short identifier of the shader language produced by this compiler (e.g. "wgsl").

Used for logging and debug-info tagging.

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.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§