shaderir

package
v2.7.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package shaderir offers intermediate representation for shader programs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidSwizzling

func IsValidSwizzling(s string) bool

func ResolveUntypedConstsForBinaryOp added in v2.6.0

func ResolveUntypedConstsForBinaryOp(op Op, lhs, rhs constant.Value, lhst, rhst Type) (newLhs, newRhs constant.Value, ok bool)

Types

type BasicType

type BasicType int
const (
	None BasicType = iota
	Bool
	Int
	Float
	Vec2
	Vec3
	Vec4
	IVec2
	IVec3
	IVec4
	Mat2
	Mat3
	Mat4
	Texture
	Array
	Struct
)

type Block

type Block struct {
	LocalVars           []Type
	LocalVarIndexOffset int
	Stmts               []Stmt
}

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"
	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"
)

func ParseBuiltinFunc

func ParseBuiltinFunc(str string) (BuiltinFunc, bool)

type Expr

type Expr struct {
	Type        ExprType
	Exprs       []Expr
	Const       constant.Value
	BuiltinFunc BuiltinFunc
	Swizzling   string
	Index       int
	Op          Op
}

type ExprType

type ExprType int
const (
	Blank ExprType = iota
	NumberExpr
	UniformVariable
	TextureVariable
	LocalVariable
	StructMember
	BuiltinFuncExpr
	SwizzlingExpr
	FunctionExpr
	Unary
	Binary
	Selection
	Call
	FieldSelector
	Index
)

type FragmentFunc

type FragmentFunc struct {
	Block *Block
}

FragmentFunc takes pseudo params, and the number is len(varyings) + 2. 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 Func

type Func struct {
	Index     int
	InParams  []Type
	OutParams []Type
	Return    Type
	Block     *Block
}

type Op

type Op int
const (
	Add Op = iota
	Sub
	NotOp
	ComponentWiseMul
	MatrixMul
	Div
	ModOp
	LeftShift
	RightShift
	LessThanOp
	LessThanEqualOp
	GreaterThanOp
	GreaterThanEqualOp
	EqualOp
	NotEqualOp
	VectorEqualOp
	VectorNotEqualOp
	And
	Xor
	Or
	AndAnd
	OrOr
)

func OpFromToken

func OpFromToken(t token.Token, lhs, rhs Type) (Op, bool)

type Program

type Program struct {
	UniformNames []string
	Uniforms     []Type
	TextureCount int
	Attributes   []Type
	Varyings     []Type
	Funcs        []Func
	VertexFunc   VertexFunc
	FragmentFunc FragmentFunc
	Unit         Unit
	// contains filtered or unexported fields
}

func (*Program) FilterUniformVariables added in v2.5.0

func (p *Program) FilterUniformVariables(uniforms []uint32)

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) LocalVariableType

func (p *Program) LocalVariableType(topBlock, block *Block, idx int) Type

func (*Program) ReachableFuncsFromBlock added in v2.5.0

func (p *Program) ReachableFuncsFromBlock(block *Block) []*Func

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
}

type StmtType

type StmtType int
const (
	ExprStmt StmtType = iota
	BlockStmt
	Assign
	Init
	If
	For
	Continue
	Break
	Return
	Discard
)

type Type

type Type struct {
	Main   BasicType
	Sub    []Type
	Length int
}

func TypeFromBinaryOp added in v2.6.0

func TypeFromBinaryOp(op Op, lhst, rhst Type, lhsConst, rhsConst constant.Value) (Type, bool)

func (*Type) Equal

func (t *Type) Equal(rhs *Type) bool

func (*Type) IsFloatVector added in v2.6.0

func (t *Type) IsFloatVector() bool

func (*Type) IsIntVector added in v2.6.0

func (t *Type) IsIntVector() bool

func (*Type) IsMatrix added in v2.3.0

func (t *Type) IsMatrix() bool

func (*Type) String

func (t *Type) String() string

func (*Type) Uint32Count added in v2.5.0

func (t *Type) Uint32Count() int

func (*Type) VectorElementCount added in v2.5.0

func (t *Type) VectorElementCount() int

type Unit added in v2.6.0

type Unit int
const (
	Texels Unit = iota
	Pixels
)

type VertexFunc

type VertexFunc struct {
	Block *Block
}

VertexFunc takes pseudo params, and the number if 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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