Documentation
¶
Overview ¶
Package wgsl compiles the shaders TSX apps write in WGSL, as NSH's are, into package shaderir's programs, which every backend draws as it draws a Kage program (package shader).
An app writes fn shade(uv: vec2f) -> vec4f, the straight sRGB color of the point uv of the view's box (0 to 1 from its top left corner), with helpers and consts of its own. It reads nsh.size (the box in points), nsh.time (seconds since the shader appeared), nsh.scale (pixels a point), nsh.progress (an effect's progress or a transition's, 0 to 1) and nsh.overflow (the points the shader draws beyond each side of its box), its own values through uniforms when it declares struct Uniforms, and pictures of other views with sample_content, sample_backdrop, sample_from and sample_to.
The program's uniforms are the bridge's (package shader: the surface's size in points, its scale, and the pictures' sizes when it reads any), then __nsh, a vec3 of the time, the progress and the overflow (BuiltinLanes), then the members of struct Uniforms in turn. Its textures are the pictures, content, backdrop, from and to, up to the last it reads. The surface a platform draws covers the box and the overflow on each side.
Index ¶
Constants ¶
const ( MaxSourceBytes = 64 << 10 MaxUniformBytes = 4096 )
Limits on what a shader may be, as NSH's.
const BuiltinLanes = 3
BuiltinLanes is how many lanes __nsh takes after the bridge's: the time, the progress and the overflow.
const Crossfade = `fn shade(uv: vec2f) -> vec4f {
return mix(sample_from(uv), sample_to(uv), nsh.progress);
}
`
Crossfade is the transitions' default program: from sample_from to sample_to as nsh.progress goes from 0 to 1.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
Error is why a shader did not compile, at a line and a column (in bytes) from 1 of the app's source, or 0 where it has no place there.
type PipelineProgram ¶
type PipelineProgram struct {
IR *shaderir.Program
VertexEntries []string
FragmentEntries []string
ComputeEntries []string
WorkgroupSize [3]uint32
Source string
}
PipelineProgram is a compiled 3D GPU WGSL module containing @vertex, @fragment, and/or @compute entry points and explicit @group/@binding resource declarations.
func CompilePipeline ¶
func CompilePipeline(src string) (*PipelineProgram, error)
CompilePipeline compiles a WGSL 3D pipeline module with @vertex and/or @fragment entry points, @location(N) stage inputs/outputs, @builtin(...), user structs, and @group(G) @binding(B) uniform/storage/texture/sampler resources into a shaderir.Program.
type Program ¶
type Program struct {
IR *shaderir.Program
// Uniforms are struct Uniforms' members, in their order.
Uniforms []Uniform
// Animated is whether shade reads nsh.time, so the shader draws every
// frame.
Animated bool
// Inputs are the pictures shade reads, through the functions it
// calls.
Inputs Inputs
}
Program is a compiled shader.