shaders

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package shaders implements the `glutter-gen shaders` subcommand: it compiles the WGSL shaders of the explicit renderer to SPIR-V with naga, and writes the Go file that holds them (D20).

Flutter: no counterpart.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Generate

func Generate(srcDir, outDir string, naga Compiler) error

Generate reads srcDir/shaders/*.wgsl and writes outDir/shaders/*.spv and outDir/shaders_gen.go. The files are the same for the same shaders and the same naga, so a test can generate into a temporary directory and compare.

func Run

func Run(args []string) error

Run executes `glutter-gen shaders [-dir dir] [-naga command]` with the arguments that follow the subcommand name. In dir (internal/gpu/explicit) it reads shaders/*.wgsl, writes shaders/*.spv and shaders_gen.go, and removes the .spv of a shader that is gone.

Flutter: no counterpart

Types

type Binding

type Binding struct {
	Name           string
	Group, Binding int
	Kind           Kind
}

Binding is one `@group(g) @binding(b) var` declaration of a module.

type Compiler

type Compiler interface {
	// Version is naga's version, such as "30.0.1".
	Version() (string, error)
	// Compile validates the WGSL file and writes its SPIR-V to the second file.
	Compile(wgsl, spirv string) error
}

Compiler is naga, or a stand-in for it in tests.

type Entry

type Entry struct {
	Name     string
	Stage    string // "Vertex" or "Fragment"
	Bindings []Binding
}

Entry is an entry point of a module and the bindings it reads.

type Kind

type Kind string

Kind is what a binding is, as the generated code spells it.

const (
	KindUniform Kind = "BindingUniformBuffer"
	KindTexture Kind = "BindingSampledTexture"
	KindSampler Kind = "BindingSampler"
)

The kinds of binding the design limits allow (SPEC §9.3).

type Module

type Module struct {
	Bindings []Binding
	Entries  []Entry
}

Module is what the generator reads from a WGSL file.

func Parse

func Parse(src string) (Module, error)

Parse reads the bindings and the entry points of a WGSL module: the declarations `@group(g) @binding(b) var<uniform> x: T;`, `var t: texture_2d<f32>;` and `var s: sampler;`, and the functions marked @vertex or @fragment. An entry point reads a binding when its name is in the body of the entry point or of a function it calls. A binding of another kind (a storage buffer, a texture of another type), a compute entry point, or two declarations of one group and binding, is an error.

type Naga

type Naga struct {
	// Path is the command; "naga" when empty.
	Path string
}

Naga runs the naga command.

func (Naga) Compile

func (n Naga) Compile(wgsl, spirv string) error

Compile runs `naga in.wgsl out.spv`, which validates the shader and writes the SPIR-V. It fails with ShadersNagaFailed, carrying naga's message, when the shader is not valid.

func (Naga) Version

func (n Naga) Version() (string, error)

Version runs `naga --version`. It fails with ShadersNagaMissing when naga is not installed.

Jump to

Keyboard shortcuts

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