Documentation
¶
Overview ¶
Package types provides the WGSL type system for semantic validation.
This implements the type system as defined in WGSL spec section 6, supporting type inference, type checking, and overload resolution.
Index ¶
- Variables
- func CanConvertTo(src, dst Type) bool
- func IsArray(t Type) bool
- func IsFloat(t Type) bool
- func IsInteger(t Type) bool
- func IsMatrix(t Type) bool
- func IsNumeric(t Type) bool
- func IsPointer(t Type) bool
- func IsReference(t Type) bool
- func IsSampler(t Type) bool
- func IsScalar(t Type) bool
- func IsStruct(t Type) bool
- func IsTexture(t Type) bool
- func IsVector(t Type) bool
- type AccessMode
- type AddressSpace
- type Array
- func (a *Array) Align() int
- func (a *Array) Equals(other Type) bool
- func (a *Array) IsConcrete() bool
- func (a *Array) IsConstructible() bool
- func (a *Array) IsHostShareable() bool
- func (a *Array) IsRuntimeSized() bool
- func (a *Array) IsStorable() bool
- func (a *Array) Size() int
- func (a *Array) String() string
- type Atomic
- type Function
- type Matrix
- type Pointer
- type Reference
- func (r *Reference) Align() int
- func (r *Reference) Equals(other Type) bool
- func (r *Reference) IsConcrete() bool
- func (r *Reference) IsConstructible() bool
- func (r *Reference) IsHostShareable() bool
- func (r *Reference) IsStorable() bool
- func (r *Reference) Size() int
- func (r *Reference) String() string
- type Sampler
- type Scalar
- func (s *Scalar) Align() int
- func (s *Scalar) Equals(other Type) bool
- func (s *Scalar) IsConcrete() bool
- func (s *Scalar) IsConstructible() bool
- func (s *Scalar) IsFloat() bool
- func (s *Scalar) IsHostShareable() bool
- func (s *Scalar) IsInteger() bool
- func (s *Scalar) IsNumeric() bool
- func (s *Scalar) IsStorable() bool
- func (s *Scalar) Size() int
- func (s *Scalar) String() string
- type ScalarKind
- type Struct
- func (s *Struct) Align() int
- func (s *Struct) ComputeLayout()
- func (s *Struct) Equals(other Type) bool
- func (s *Struct) GetField(name string) *StructField
- func (s *Struct) IsConcrete() bool
- func (s *Struct) IsConstructible() bool
- func (s *Struct) IsHostShareable() bool
- func (s *Struct) IsStorable() bool
- func (s *Struct) Size() int
- func (s *Struct) String() string
- type StructField
- type Texture
- type TextureDimension
- type TextureKind
- type Type
- type Vector
- type Void
Constants ¶
This section is empty.
Variables ¶
var ( Bool = &Scalar{Kind: ScalarBool} I32 = &Scalar{Kind: ScalarI32} U32 = &Scalar{Kind: ScalarU32} F32 = &Scalar{Kind: ScalarF32} F16 = &Scalar{Kind: ScalarF16} AbstractInt = &Scalar{Kind: ScalarAbstractInt} AbstractFloat = &Scalar{Kind: ScalarAbstractFloat} VoidType = &Void{} )
Functions ¶
func CanConvertTo ¶
CanConvertTo returns true if src can be implicitly converted to dst.
Types ¶
type AccessMode ¶
type AccessMode uint8
AccessMode represents WGSL access modes.
const ( AccessModeNone AccessMode = iota AccessModeRead AccessModeWrite AccessModeReadWrite )
func (AccessMode) String ¶
func (a AccessMode) String() string
type AddressSpace ¶
type AddressSpace uint8
AddressSpace represents WGSL address spaces.
const ( AddressSpaceNone AddressSpace = iota AddressSpaceFunction AddressSpacePrivate AddressSpaceWorkgroup AddressSpaceUniform AddressSpaceStorage AddressSpaceHandle )
func (AddressSpace) String ¶
func (a AddressSpace) String() string
type Array ¶
Array represents array<T, N> or array<T> (runtime-sized).
func RuntimeArray ¶
RuntimeArray creates a runtime-sized array type.
func (*Array) IsConcrete ¶
func (*Array) IsConstructible ¶
func (*Array) IsHostShareable ¶
func (*Array) IsRuntimeSized ¶
IsRuntimeSized returns true if this is a runtime-sized array.
func (*Array) IsStorable ¶
type Atomic ¶
type Atomic struct {
Element *Scalar // Must be i32 or u32
}
Atomic represents atomic<T>.
func (*Atomic) IsConcrete ¶
func (*Atomic) IsConstructible ¶
func (*Atomic) IsHostShareable ¶
func (*Atomic) IsStorable ¶
type Function ¶
Function represents a function type signature.
func (*Function) IsConcrete ¶
func (*Function) IsConstructible ¶
func (*Function) IsHostShareable ¶
func (*Function) IsStorable ¶
type Matrix ¶
Matrix represents matCxR<T>.
func (*Matrix) IsConcrete ¶
func (*Matrix) IsConstructible ¶
func (*Matrix) IsHostShareable ¶
func (*Matrix) IsStorable ¶
type Pointer ¶
type Pointer struct {
AddressSpace AddressSpace
Element Type
AccessMode AccessMode
}
Pointer represents ptr<space, T, access>.
func Ptr ¶
func Ptr(space AddressSpace, elem Type, access AccessMode) *Pointer
Ptr creates a pointer type.
func (*Pointer) IsConcrete ¶
func (*Pointer) IsConstructible ¶
func (*Pointer) IsHostShareable ¶
func (*Pointer) IsStorable ¶
type Reference ¶
type Reference struct {
AddressSpace AddressSpace
Element Type
AccessMode AccessMode
}
Reference represents a reference type (implicit pointer).
func Ref ¶
func Ref(space AddressSpace, elem Type, access AccessMode) *Reference
Ref creates a reference type.
func (*Reference) IsConcrete ¶
func (*Reference) IsConstructible ¶
func (*Reference) IsHostShareable ¶
func (*Reference) IsStorable ¶
type Sampler ¶
type Sampler struct {
Comparison bool
}
Sampler represents sampler or sampler_comparison.
func (*Sampler) IsConcrete ¶
func (*Sampler) IsConstructible ¶
func (*Sampler) IsHostShareable ¶
func (*Sampler) IsStorable ¶
type Scalar ¶
type Scalar struct {
Kind ScalarKind
}
Scalar represents a scalar type (bool, i32, u32, f32, f16).
func (*Scalar) IsConcrete ¶
func (*Scalar) IsConstructible ¶
func (*Scalar) IsHostShareable ¶
func (*Scalar) IsStorable ¶
type ScalarKind ¶
type ScalarKind uint8
ScalarKind represents the kind of scalar type.
const ( ScalarBool ScalarKind = iota ScalarI32 ScalarU32 ScalarF32 ScalarF16 ScalarAbstractInt ScalarAbstractFloat )
type Struct ¶
type Struct struct {
Name string
Fields []StructField
// contains filtered or unexported fields
}
Struct represents a user-defined struct type.
func (*Struct) ComputeLayout ¶
func (s *Struct) ComputeLayout()
ComputeLayout computes field offsets, struct size, and alignment.
func (*Struct) GetField ¶
func (s *Struct) GetField(name string) *StructField
GetField returns the field with the given name, or nil.
func (*Struct) IsConcrete ¶
func (*Struct) IsConstructible ¶
func (*Struct) IsHostShareable ¶
func (*Struct) IsStorable ¶
type StructField ¶
StructField represents a struct member.
type Texture ¶
type Texture struct {
Kind TextureKind
Dimension TextureDimension
SampledType *Scalar // For sampled textures
TexelFormat string // For storage textures
AccessMode AccessMode
}
Texture represents texture types.
func (*Texture) IsConcrete ¶
func (*Texture) IsConstructible ¶
func (*Texture) IsHostShareable ¶
func (*Texture) IsStorable ¶
type TextureDimension ¶
type TextureDimension uint8
TextureDimension indicates texture dimensionality.
const ( Texture1D TextureDimension = iota Texture2D Texture2DArray Texture3D TextureCube TextureCubeArray )
func (TextureDimension) String ¶
func (d TextureDimension) String() string
type TextureKind ¶
type TextureKind uint8
TextureKind indicates the texture category.
const ( TextureSampled TextureKind = iota TextureMultisampled TextureStorage TextureDepth TextureDepthMultisampled TextureExternal )
type Type ¶
type Type interface {
// String returns the WGSL syntax for this type.
String() string
// Equals returns true if this type equals another type.
Equals(Type) bool
// IsConstructible returns true if values of this type can be constructed.
IsConstructible() bool
// IsConcrete returns true if this is not an abstract type.
IsConcrete() bool
// IsStorable returns true if values can be stored in memory.
IsStorable() bool
IsHostShareable() bool
// Size returns the size in bytes (0 for unsized types).
Size() int
// Align returns the alignment in bytes.
Align() int
// contains filtered or unexported methods
}
Type represents a WGSL type.
func AddSubResultType ¶
AddSubResultType returns the result type of a +/- b, or nil if invalid. Addition and subtraction require matching types or vector/matrix operations.
func CommonType ¶
CommonType returns the common type of two types for binary operations.
func ConcreteType ¶
ConcreteType returns the concrete version of an abstract type. For abstract-float returns f32, for abstract-int returns i32. For vectors/matrices with abstract elements, returns concrete element versions. For already concrete types, returns the type unchanged.
func DivResultType ¶
DivResultType returns the result type of a / b. Division supports:
- scalar / scalar → scalar
- vector / vector → vector (component-wise)
- vector / scalar → vector
- scalar / vector → vector (broadcasts scalar)
func ElementType ¶
ElementType returns the element type of composite types, or nil.
func MultiplyResultType ¶
MultiplyResultType returns the result type of a * b, or nil if invalid. This handles all WGSL multiplication cases:
- scalar * scalar → scalar
- vector * vector → vector (component-wise)
- matrix * matrix → matrix
- scalar * vector → vector
- vector * scalar → vector
- scalar * matrix → matrix
- matrix * scalar → matrix
- matrix * vector → vector (matrix-vector multiplication)
- vector * matrix → vector (vector-matrix multiplication)
type Vector ¶
Vector represents vec2<T>, vec3<T>, vec4<T>.
func (*Vector) IsConcrete ¶
func (*Vector) IsConstructible ¶
func (*Vector) IsHostShareable ¶
func (*Vector) IsStorable ¶
type Void ¶
type Void struct{}
Void represents the absence of a return type.