Documentation
¶
Overview ¶
Package shaders implements the `glutter-gen shaders` subcommand: it compiles the WGSL shaders of the explicit renderer to SPIR-V and to HLSL (shader model 5.1) with naga, and writes the Go file that holds them (D20, D25).
Flutter: no counterpart.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
Generate reads srcDir/shaders/*.wgsl and writes outDir/shaders/*.spv and outDir/shaders_gen.go, which holds the HLSL of each shader (naga's, rewritten by rewriteHLSL and checked against the WGSL by checkHLSL). 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 ¶
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 (which holds the HLSL), and removes the .spv of a shader that is gone.
Flutter: no counterpart
Types ¶
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
// CompileHLSL writes the HLSL for shader model 5.1 of the WGSL file to the second file,
// as naga writes it (hlsl.go rewrites it afterwards).
CompileHLSL(wgsl, hlsl string) error
}
Compiler is naga, or a stand-in for it in tests.
type Module ¶
Module is what the generator reads from a WGSL file.
func Parse ¶
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 ¶
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) CompileHLSL ¶
CompileHLSL runs `naga in.wgsl out.hlsl --shader-model 51`. It fails with ShadersNagaFailed, carrying naga's message, when naga cannot write the HLSL.