Help us shape the future of Go! Take the 2026 Go Developer Survey

shaderir

package
v0.34.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 6 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func BackendError(err error) error

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

func Lower(source string) (*ir.Module, error)

Lower parses WGSL and lowers it to IR without validation, as the DX12, GLES and Metal backends have always done.

func LowerValidated

func LowerValidated(source string) (*ir.Module, error)

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

func PerStage(module *ir.Module, constants map[string]float64) bool

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 SPIRV

func SPIRV(module *ir.Module) ([]uint32, error)

SPIRV compiles module to SPIR-V words with naga.Compile's default options.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL