vkgen

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package vkgen reads the Khronos registry (vk.xml) and generates the Go mirrors of the Vulkan structures, enumerations and handles that go-gfx/vulkan calls. Offsets and sizes are computed by the C rules for a 64-bit target, and the generator emits a test that pins every Go struct against that table, so that a layout has a witness other than the hand that typed it.

Index

Constants

View Source
const MaxRegistryBytes = 64 << 20

MaxRegistryBytes bounds the registry the reader accepts: the real file is about 3.3 MB, and the reader is fuzzed with arbitrary bytes.

Variables

This section is empty.

Functions

func OpenRegistry

func OpenRegistry(path string) (io.ReadCloser, error)

OpenRegistry opens a registry file; a name ending in .gz is decompressed. The repository keeps vk.xml.gz (3.3 MB of XML is 0.3 MB gzipped), and Parse bounds the decompressed size, so a gzip bomb is refused.

func ParseInt

func ParseInt(s string) (int64, error)

ParseInt reads a decimal or 0x-prefixed integer, optionally negative.

Types

type Config

type Config struct {
	Package   string
	Structs   []string // structures to mirror, and every type they reach
	Handles   []string // handles to declare even when no structure holds them
	Enums     []string // enumerations whose every enumerator becomes a constant
	Constants []string // API constants (VK_WHOLE_SIZE)
}

Config says what to generate. Names are the registry's (VkBufferCreateInfo).

func DefaultConfig

func DefaultConfig() Config

DefaultConfig is what go-gfx/vulkan calls: exactly the structures, handles and enumerations of the compute path, and nothing for presentation.

type Constant

type Constant struct {
	Type  string
	Value string
}

Constant is an entry of the API Constants block.

type Enum

type Enum struct {
	Name    string
	Bitmask bool
	Wide    bool // bitwidth 64
	Values  []EnumValue
}

Enum is one `<enums>` block, extended by the `<require>` elements.

type EnumValue

type EnumValue struct {
	Name  string
	Value int64
}

EnumValue is one resolved enumerator.

type Member

type Member struct {
	Name    string
	Type    string
	Pointer bool     // a pointer of any depth: the generator mirrors it as unsafe.Pointer
	Dims    []string // array dimensions, each a number or the name of a constant
	Bits    string   // bit-field width, unsupported by the generator
	Values  string   // the fixed value of an sType member
}

Member is one field of a structure, as the registry spells it.

type Output

type Output struct {
	Types      []byte
	LayoutTest []byte
}

Output is the generated source: the types, and a test that pins their layout.

func Generate

func Generate(reg *Registry, cfg Config) (*Output, error)

Generate emits the Go source for cfg. The output is deterministic.

type Registry

type Registry struct {
	Structs   map[string]*Struct
	Enums     map[string]*Enum
	EnumTypes map[string]bool // names declared with category="enum"
	Constants map[string]Constant
	Base      map[string]string // VkFlags -> uint32_t
	Flags     map[string]string // VkBufferCreateFlags -> VkFlags
	Handles   map[string]bool   // name -> dispatchable
	Aliases   map[string]string // alias -> target, for structs, enums, handles
	Version   string            // VK_HEADER_VERSION, when found
	// contains filtered or unexported fields
}

Registry is what the generator needs of vk.xml.

func Parse

func Parse(r io.Reader) (*Registry, error)

Parse reads a registry. It never panics on arbitrary input.

type Struct

type Struct struct {
	Name    string
	Members []Member
}

Struct is a `<type category="struct">`.

Jump to

Keyboard shortcuts

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