alignsl

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 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 HLSL (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 HLSL (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) error

CheckPackage is main entry point for checking a package returns error string if any errors found.

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 primary 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

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
	Errs    []string                 // accumulating list of error strings -- empty if all good
}

Context for given package run

func NewContext

func NewContext(sz types.Sizes) *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