Documentation
¶
Overview ¶
Package shaderir holds the naga IR of a WGSL shader module and specializes it for one pipeline stage.
A HAL backend lowers WGSL to IR once, when the shader module is created. If the module has no pipeline-overridable constants (WGSL `override`), the backend may compile it once and reuse the result for every pipeline. If it has overrides, or a pipeline gives constants, the backend calls Specialize for every pipeline stage and compiles the result: the override values, the expressions that depend on them and workgroup sizes given by overrides are known only then. This is Rust wgpu-hal's call to naga::back::pipeline_constants::process_overrides before every backend (vulkan/device.rs:804, dx12/device.rs:349, gles/device.rs:385, metal/device.rs:174).
Index ¶
- Variables
- func BackendError(err error) error
- func Lower(source string) (*ir.Module, error)
- func LowerValidated(source string) (*ir.Module, error)
- func PerStage(module *ir.Module, constants map[string]float64) bool
- func SPIRV(module *ir.Module) ([]uint32, error)
- func Specialize(module *ir.Module, stage ir.ShaderStage, entryPoint string, ...) (*ir.Module, error)
- func StageName(stage ir.ShaderStage) string
Constants ¶
This section is empty.
Variables ¶
var ErrUnresolvedOverride = errors.New("BUG: HAL compiled a shader with unresolved overrides (naga.ProcessOverrides not run)")
ErrUnresolvedOverride wraps a naga backend error caused by overrides that were not resolved before the backend ran. It is a bug in the HAL backend, never in the shader or the pipeline.
Functions ¶
func BackendError ¶
BackendError returns err from a naga shader backend. If err says that overrides were not resolved (ir.ErrUnresolvedOverride), the result also wraps ErrUnresolvedOverride, which marks it as an internal error.
func Lower ¶
Lower parses WGSL and lowers it to IR without validation, as the DX12, GLES and Metal backends have always done.
func LowerValidated ¶
LowerValidated parses, lowers and validates WGSL with the capabilities of naga.Compile's default options. The Vulkan and software backends used naga.Compile before, so they keep its validation.
func PerStage ¶
PerStage reports whether module must be specialized for each pipeline stage: it has overrides, or the pipeline gives constants (which must then name overrides of the module). Otherwise module can be compiled once.
A module from the WGSL frontend without overrides has no override expressions, override workgroup sizes or override-sized arrays (the guarantee of naga.ProcessOverrides).
func Specialize ¶
func Specialize(module *ir.Module, stage ir.ShaderStage, entryPoint string, constants map[string]float64) (*ir.Module, error)
Specialize returns module for one pipeline stage: only the entry point named entryPoint of the given stage is kept (it is EntryPoints[0] of the result), and every override takes its value from constants or its default.
module is not modified, and Specialize may run concurrently on the same module. The result may share memory with module; treat it as read-only.
A constant error keeps naga's error: errors.Is with naga.ErrOverrideNotFound and the other sentinels, and errors.As with *naga.PipelineConstantError, work on the result.
func StageName ¶
func StageName(stage ir.ShaderStage) string
StageName returns the WGSL attribute name of a shader stage.
Types ¶
This section is empty.