alignsl

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: BSD-3-Clause Imports: 5 Imported by: 0

README

AlignSL

alignsl performs 16-byte alignment and total size modulus checking of struct types to ensure WGSL (and GSL) compatibility.

Checks that struct sizes are an even multiple of 16 bytes (e.g., 4 float32's), fields are 32 or 64 bit types: [U]Int32, Float32, [U]Int64, Float64, and that fields that are other struct types are aligned at even 16 byte multiples.

It is called with a golang.org/x/tools/go/packages Package that provides the types.Sizes and Types.Scope() to get the types.

The CheckPackage method checks all types in a Package, and returns an error if there are any violations -- this error string contains a full user-friendly warning message that can be printed.

Documentation

Overview

package alignsl performs 16-byte alignment checking of struct fields and total size modulus checking of struct types to ensure WGSL (and GSL) compatibility.

Checks that struct sizes are an even multiple of 16 bytes (4 float32's), fields are 32 bit types: [U]Int32, Float32, and that fields that are other struct types are aligned at even 16 byte multiples.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPackage

func CheckPackage(pkg *packages.Package, structTypes map[string]bool) error

CheckPackage is main entry point for checking a package returns error string if any errors found. structTypes is a map of struct type names to check for alignment. any other struct types are purely internal not used for variables, so they don't need to be checked.

func CheckScope

func CheckScope(cx *Context, sc *types.Scope, level int) bool

func CheckStack

func CheckStack(cx *Context) bool

func CheckStruct

func CheckStruct(cx *Context, st *types.Struct, stName string) bool

CheckStruct is the top-level checker -- returns hasErr = true if there are any mis-aligned fields or total size of struct is not an even multiple of 16 bytes -- adds details to Errs. If struct is not on the cx.StructTypes list, it is skipped.

func CheckStructImpl added in v0.1.3

func CheckStructImpl(cx *Context, st *types.Struct, stName string) bool

CheckStructImpl can be used for CheckStack -- doesn't check for top-level StructTypes membership.

func TypeName

func TypeName(tp types.Type) string

Types

type Context

type Context struct {
	Sizes       types.Sizes              // from package
	Structs     map[*types.Struct]string // structs that have been processed already -- value is name
	Stack       map[*types.Struct]string // structs to process in a second pass -- structs encountered during processing of other structs
	StructTypes map[string]bool          // top level list of struct types to examine -- skip anything at a top-level that is not in this list.
	Errs        []string                 // accumulating list of error strings -- empty if all good
}

Context for given package run

func NewContext

func NewContext(sz types.Sizes, structTypes map[string]bool) *Context

func (*Context) AddError

func (cx *Context) AddError(ers string, hasErr bool, stName string) bool

func (*Context) IsNewStruct

func (cx *Context) IsNewStruct(st *types.Struct) bool

Jump to

Keyboard shortcuts

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