Documentation
¶
Overview ¶
Package shaderir offers intermediate representation for shader programs, forked from Ebitengine with package shader (see its documentation).
Index ¶
- func IsValidSwizzling(s string) bool
- func PutLanes(buf []byte, offsets []int, types []BasicType, values []float64, boolSize int)
- func ResolveUntypedConstsForBinaryOp(op Op, lhs, rhs constant.Value, lhst, rhst Type) (newLhs, newRhs constant.Value, ok bool)
- type BasicType
- type Block
- type BuiltinFunc
- type Expr
- type ExprType
- type FragmentFunc
- type Func
- type Op
- type Program
- func (p *Program) AssignedAttributes() []bool
- func (p *Program) FilterUniformVariables(uniforms []uint32)
- func (p *Program) FragmentLibrary() (lib *Program, entry *Func, funcs []*Func)
- func (p *Program) LaneTypes() []BasicType
- func (p *Program) LocalVariableType(topBlock, block *Block, idx int) Type
- func (p *Program) ReachableFuncsFromBlock(block *Block) []*Func
- type SourceID
- type Stmt
- type StmtType
- type SwizzlingSet
- type Type
- func (t Type) DwordCount() int
- func (t Type) Equal(rhs *Type) bool
- func (t Type) IsFloatVector() bool
- func (t Type) IsIntVector() bool
- func (t Type) IsInteger() bool
- func (t Type) IsIntegerVector() bool
- func (t Type) IsMatrix() bool
- func (t Type) IsUintVector() bool
- func (t Type) MatrixSize() int
- func (t Type) Scalar() BasicType
- func (t Type) String() string
- func (t Type) VectorElementCount() int
- type TypeEnv
- type VertexFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsValidSwizzling ¶
Types ¶
type BuiltinFunc ¶
type BuiltinFunc string
const ( Len BuiltinFunc = "len" Cap BuiltinFunc = "cap" BoolF BuiltinFunc = "bool" IntF BuiltinFunc = "int" FloatF BuiltinFunc = "float" Vec2F BuiltinFunc = "vec2" Vec3F BuiltinFunc = "vec3" Vec4F BuiltinFunc = "vec4" IVec2F BuiltinFunc = "ivec2" IVec3F BuiltinFunc = "ivec3" IVec4F BuiltinFunc = "ivec4" UintF BuiltinFunc = "uint" UVec2F BuiltinFunc = "uvec2" UVec3F BuiltinFunc = "uvec3" UVec4F BuiltinFunc = "uvec4" Mat2F BuiltinFunc = "mat2" Mat3F BuiltinFunc = "mat3" Mat4F BuiltinFunc = "mat4" Radians BuiltinFunc = "radians" // This function is not used yet (#2253) Degrees BuiltinFunc = "degrees" // This function is not used yet (#2253) Sin BuiltinFunc = "sin" Cos BuiltinFunc = "cos" Tan BuiltinFunc = "tan" Asin BuiltinFunc = "asin" Acos BuiltinFunc = "acos" Atan BuiltinFunc = "atan" Atan2 BuiltinFunc = "atan2" Pow BuiltinFunc = "pow" Exp BuiltinFunc = "exp" Log BuiltinFunc = "log" Exp2 BuiltinFunc = "exp2" Log2 BuiltinFunc = "log2" Sqrt BuiltinFunc = "sqrt" Inversesqrt BuiltinFunc = "inversesqrt" Abs BuiltinFunc = "abs" Sign BuiltinFunc = "sign" Floor BuiltinFunc = "floor" Ceil BuiltinFunc = "ceil" Fract BuiltinFunc = "fract" Mod BuiltinFunc = "mod" Min BuiltinFunc = "min" Max BuiltinFunc = "max" Clamp BuiltinFunc = "clamp" Mix BuiltinFunc = "mix" Step BuiltinFunc = "step" Smoothstep BuiltinFunc = "smoothstep" Length BuiltinFunc = "length" Distance BuiltinFunc = "distance" Dot BuiltinFunc = "dot" Cross BuiltinFunc = "cross" Normalize BuiltinFunc = "normalize" Faceforward BuiltinFunc = "faceforward" Reflect BuiltinFunc = "reflect" Refract BuiltinFunc = "refract" Transpose BuiltinFunc = "transpose" Dfdx BuiltinFunc = "dfdx" Dfdy BuiltinFunc = "dfdy" Fwidth BuiltinFunc = "fwidth" DiscardF BuiltinFunc = "discard" TexelAt BuiltinFunc = "__texelAt" FrontFacing BuiltinFunc = "frontfacing" // Added by NSGo for WGSL (package shader/wgsl), which Kage does not // name: GLSL's names, which the writers map to their languages'. Trunc BuiltinFunc = "trunc" RoundEven BuiltinFunc = "roundEven" Sinh BuiltinFunc = "sinh" Cosh BuiltinFunc = "cosh" Tanh BuiltinFunc = "tanh" FloatBitsToInt BuiltinFunc = "floatBitsToInt" FloatBitsToUint BuiltinFunc = "floatBitsToUint" IntBitsToFloat BuiltinFunc = "intBitsToFloat" UintBitsToFloat BuiltinFunc = "uintBitsToFloat" )
func ParseBuiltinFunc ¶
func ParseBuiltinFunc(str string) (BuiltinFunc, bool)
type Expr ¶
type Expr struct {
Type ExprType
Exprs []Expr
Const constant.Value
BuiltinFunc BuiltinFunc
// Swizzling is spelled in the xyzw set regardless of [Expr.SwizzlingSet].
Swizzling string
SwizzlingSet SwizzlingSet
Index int
Op Op
// Unsigned marks an expression of type uint or uvecN, as the compiler
// infers it: a constant of it is written as one (1u), which GLSL ES
// needs, as it converts no int to uint.
Unsigned bool
// Untyped marks an integer expression that is not a constant but takes
// the type of its context, as in Go: a shift of an untyped constant by
// a count that is not one, and operations of such shifts with untyped
// constants. Its type is int where the context gives none.
Untyped bool
}
func (Expr) SourceSwizzling ¶
SourceSwizzling returns the swizzle of a SwizzlingExpr spelled in Expr.SwizzlingSet.
type FragmentFunc ¶
type FragmentFunc struct {
Block *Block
}
FragmentFunc takes pseudo params, and the number is len(varyings) + 1. If index == 0, the param represents the coordinate of the fragment (gl_FragCoord in GLSL). If 0 < index <= len(varyings), the param represents (index-1)th varying variable.
type Program ¶
type Program struct {
UniformNames []string
Uniforms []Type
TextureCount int
Attributes []Type
Varyings []Type
Funcs []Func
VertexFunc VertexFunc
FragmentFunc FragmentFunc
SourceID SourceID
// FragmentSource is the Kage source the program was compiled from, or nil if it was not built from
// Kage source.
FragmentSource []byte
// contains filtered or unexported fields
}
func (*Program) AssignedAttributes ¶
AssignedAttributes reports, for each attribute, whether the vertex entry point assigns to the whole attribute or a part of it.
func (*Program) FilterUniformVariables ¶
FilterUniformVariables replaces uniform variables with 0 when they are not used. By minimizing uniform variables, more commands can be merged in the graphicscommand package.
func (*Program) FragmentLibrary ¶
FragmentLibrary returns the program as a library for a renderer that draws with a vertex stage of its own, as MyGo's do: a program without entry points, whose fragment entry point is the function entry, taking the fragment's position (vec4) and the varyings, and the functions entry reaches, entry last. Backends emit it as a function of the renderer's fragment shader (Fragment in packages glsl, hlsl and msl).
func (*Program) LaneTypes ¶
LaneTypes returns the scalar type of each lane of p's uniforms, in the order of the backends' UniformLanes: a vector's components, a matrix's columns and an array's elements in turn, Type.DwordCount for each.
func (*Program) LocalVariableType ¶
func (*Program) ReachableFuncsFromBlock ¶
type SourceID ¶
type SourceID [16]byte
func CalcSourceID ¶
func ParseSourceID ¶
ParseSourceID parses a base32 string returned by SourceID.String back into a SourceID.
type Stmt ¶
type Stmt struct {
Type StmtType
Exprs []Expr
Blocks []*Block
ForVarType Type
ForVarIndex int
ForInit constant.Value
ForEnd constant.Value
ForOp Op
ForDelta constant.Value
InitIndex int
}
Stmt is a statement. A For loop's counter starts from ForInit and runs while it compares with ForEnd as ForOp says, ForDelta at a time; where the compiler made it, Exprs holds the start and the end as expressions, which need not be constants (MyGo's), and ForInit and ForEnd are nil for those that are not.
type SwizzlingSet ¶
type SwizzlingSet int
SwizzlingSet is the naming set of vector components a swizzle is written in.
const ( SwizzlingSetXYZW SwizzlingSet = iota SwizzlingSetRGBA SwizzlingSetSTPQ )
type Type ¶
func TypeFromBinaryOp ¶
func TypeOf ¶
TypeOf returns the type of e, an expression the compiler checked. A constant has the type of its kind, bool, float or int, or uint when it is Unsigned; a call of a function with output parameters, which only statements make, has none.
func (Type) DwordCount ¶
func (Type) IsFloatVector ¶
func (Type) IsIntVector ¶
func (Type) IsIntegerVector ¶
IsIntegerVector reports whether t is a vector of int or uint.
func (Type) IsUintVector ¶
IsUintVector reports whether t is uvec2, uvec3 or uvec4.
func (Type) MatrixSize ¶
func (Type) Scalar ¶
Scalar returns the type of t's components: float for a float vector or a matrix, int or uint for an integer vector, and t's own for a scalar.
func (Type) VectorElementCount ¶
type TypeEnv ¶
type TypeEnv interface {
LocalType(index int) Type
UniformType(index int) Type
FuncReturn(index int) Type
}
TypeEnv tells the types of what expressions refer to: local variables, by their index in their function, uniform variables, and the results of functions.
type VertexFunc ¶
type VertexFunc struct {
Block *Block
}
VertexFunc takes pseudo params, and the number is len(attributes) + len(varyings) + 1. If 0 <= index < len(attributes), the params are in-params and represent attribute variables. If index == len(attributes), the param is an out-param and represents the position in vec4 (gl_Position in GLSL) If len(attributes) + 1 <= index < len(attributes) + len(varyings) + 1, the params are out-params and represent varying variables.