spirv

package
v0.17.16 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 2 Imported by: 1

README

SPIR-V Binary Writer

This package provides a low-level SPIR-V binary writer for constructing SPIR-V modules programmatically.

Status

Implemented - Binary writer foundation complete 🔄 Next Step - IR to SPIR-V translation

Features

ModuleBuilder

The main API for building SPIR-V modules:

builder := spirv.NewModuleBuilder(spirv.Version1_3)

// Required setup
builder.AddCapability(spirv.CapabilityShader)
builder.SetMemoryModel(spirv.AddressingModelLogical, spirv.MemoryModelGLSL450)

// Types
floatType := builder.AddTypeFloat(32)
vec4Type := builder.AddTypeVector(floatType, 4)

// Entry points
funcID := builder.AddFunction(...)
builder.AddEntryPoint(spirv.ExecutionModelFragment, funcID, "main", nil)

// Generate binary
binary := builder.Build()
Supported Operations
Type Operations
  • AddTypeVoid() - Void type
  • AddTypeBool() - Boolean type
  • AddTypeFloat(width) - Float types (16, 32, 64-bit)
  • AddTypeInt(width, signed) - Integer types
  • AddTypeVector(componentType, count) - Vector types (vec2, vec3, vec4)
  • AddTypeMatrix(columnType, columnCount) - Matrix types
  • AddTypeArray(elementType, length) - Array types
  • AddTypeStruct(memberTypes...) - Struct types
  • AddTypePointer(storageClass, baseType) - Pointer types
  • AddTypeFunction(returnType, paramTypes...) - Function types
Constant Operations
  • AddConstant(typeID, values...) - Integer/boolean constants
  • AddConstantFloat32(typeID, value) - 32-bit float constant
  • AddConstantFloat64(typeID, value) - 64-bit float constant
  • AddConstantComposite(typeID, constituents...) - Composite constants
Variable Operations
  • AddVariable(pointerType, storageClass) - Global variable
  • AddVariableWithInit(pointerType, storageClass, initID) - Variable with initializer
Function Operations
  • AddFunction(funcType, returnType, control) - Function definition
  • AddFunctionParameter(typeID) - Function parameter
  • AddLabel() - Basic block label
  • AddReturn() - Return from void function
  • AddReturnValue(valueID) - Return with value
  • AddFunctionEnd() - End of function
Entry Point & Execution Mode
  • AddEntryPoint(execModel, funcID, name, interfaces) - Shader entry point
  • AddExecutionMode(entryPoint, mode, params...) - Execution configuration
Debug Operations
  • AddName(id, name) - Debug name for ID
  • AddMemberName(structID, member, name) - Debug name for struct member
  • AddString(text) - Debug string
Decoration Operations
  • AddDecorate(id, decoration, params...) - Decorate type/variable
  • AddMemberDecorate(structID, member, decoration, params...) - Decorate struct member
Constants
Execution Models
  • ExecutionModelVertex - Vertex shader
  • ExecutionModelFragment - Fragment shader
  • ExecutionModelGLCompute - Compute shader
Storage Classes
  • StorageClassUniformConstant - Uniform/constant storage
  • StorageClassInput - Shader input
  • StorageClassOutput - Shader output
  • StorageClassUniform - Uniform buffer
  • StorageClassWorkgroup - Shared/workgroup memory
  • StorageClassPrivate - Private storage
  • StorageClassFunction - Function local storage
  • StorageClassPushConstant - Push constants
  • StorageClassStorageBuffer - Storage buffer
Decorations
  • DecorationLocation - Location decoration
  • DecorationBinding - Binding decoration
  • DecorationDescriptorSet - Descriptor set decoration
  • DecorationBuiltIn - Built-in decoration
  • DecorationBlock - Block decoration
  • DecorationOffset - Struct member offset

SPIR-V Binary Format

Header (5 words)
Word 0: 0x07230203 (Magic number)
Word 1: Version (major.minor << 16 | patch << 8)
Word 2: Generator ID
Word 3: Bound (max ID + 1)
Word 4: Schema (reserved, 0)
Instruction Format
Word 0: (WordCount << 16) | Opcode
Words 1-N: Operands
Module Sections (in order)
  1. Capabilities
  2. Extensions
  3. Extended instruction imports
  4. Memory model
  5. Entry points
  6. Execution modes
  7. Debug strings
  8. Debug names
  9. Annotations (decorations)
  10. Types and constants
  11. Global variables
  12. Functions

Examples

See example_test.go for complete examples:

  • Minimal module
  • Module with types
  • Fragment shader structure

Testing

# Run tests
GOROOT="/c/Program Files/Go" go test ./spirv/...

# Run examples
GOROOT="/c/Program Files/Go" go test -v -run Example ./spirv/...

Implementation Notes

ID Allocation
  • IDs start at 1 (0 is invalid)
  • AllocID() returns sequential IDs
  • bound field tracks max ID + 1
String Encoding
  • UTF-8 null-terminated
  • Padded to 4-byte boundary
  • Stored as little-endian words
Float Encoding
  • AddConstantFloat32() uses IEEE 754 single precision
  • AddConstantFloat64() uses IEEE 754 double precision (2 words)
Binary Generation
  • Little-endian byte order
  • Word-aligned (4 bytes)
  • Sections written in SPIR-V specification order

Next Steps

The next phase of implementation will add:

  1. IR to SPIR-V Translation (spirv/backend.go)

    • Convert naga IR types to SPIR-V types
    • Convert naga IR expressions to SPIR-V instructions
    • Convert naga IR statements to SPIR-V control flow
    • Map naga IR address spaces to SPIR-V storage classes
  2. Type Deduplication

    • Cache created types to avoid duplicates
    • Efficient type lookup
  3. Expression Emission

    • Arithmetic operations
    • Logical operations
    • Load/store operations
    • Function calls
  4. Control Flow

    • If/else blocks
    • Loops
    • Switch statements
    • Structured control flow

References

License

Same as gogpu/naga project.

Documentation

Overview

Package spirv provides SPIR-V code generation from naga IR.

SPIR-V is the standard intermediate language for GPU shaders, used by Vulkan, OpenCL, and other APIs.

Architecture

This package is a thin public API layer. All codegen, builder, and spec logic lives in spirv/internal/codegen (following the DXIL pattern).

IR to SPIR-V Backend

The Backend translates naga IR modules to SPIR-V binary format:

backend := spirv.NewBackend(spirv.DefaultOptions())
binary, err := backend.Compile(irModule)
if err != nil {
	log.Fatal(err)
}

Binary Writer

The package also provides a low-level binary writer for constructing SPIR-V modules programmatically using ModuleBuilder:

builder := spirv.NewModuleBuilder(spirv.Version1_3)
builder.AddCapability(spirv.CapabilityShader)
builder.SetMemoryModel(spirv.AddressingModelLogical, spirv.MemoryModelGLSL450)

// Add types
floatType := builder.AddTypeFloat(32)
vec4Type := builder.AddTypeVector(floatType, 4)

// Build binary
binary := builder.Build()

References

SPIR-V Specification: https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html

Package spirv provides SPIR-V code generation from naga IR.

This package exposes the public API for SPIR-V compilation. All implementation details live in spirv/internal/codegen.

Example (BackendCompile)

Example_backendCompile demonstrates compiling an IR module to SPIR-V.

package main

import (
	"fmt"

	"github.com/gogpu/naga/ir"
	"github.com/gogpu/naga/spirv"
)

func main() {
	// Create a simple IR module with types and constants
	module := &ir.Module{
		Types: []ir.Type{
			// f32 scalar type
			{Name: "f32", Inner: ir.ScalarType{Kind: ir.ScalarFloat, Width: 4}},
			// vec3<f32> vector type
			{
				Name: "vec3f",
				Inner: ir.VectorType{
					Size:   ir.Vec3,
					Scalar: ir.ScalarType{Kind: ir.ScalarFloat, Width: 4},
				},
			},
		},
		Constants: []ir.Constant{
			// const x: f32 = 1.0;
			{
				Name:  "x",
				Type:  0,                                                      // f32
				Value: ir.ScalarValue{Kind: ir.ScalarFloat, Bits: 0x3f800000}, // 1.0
			},
			// const y: f32 = 2.0;
			{
				Name:  "y",
				Type:  0,                                                      // f32
				Value: ir.ScalarValue{Kind: ir.ScalarFloat, Bits: 0x40000000}, // 2.0
			},
			// const z: f32 = 3.0;
			{
				Name:  "z",
				Type:  0,                                                      // f32
				Value: ir.ScalarValue{Kind: ir.ScalarFloat, Bits: 0x40400000}, // 3.0
			},
			// const position: vec3<f32> = vec3(1.0, 2.0, 3.0);
			{
				Name: "position",
				Type: 1, // vec3f
				Value: ir.CompositeValue{
					Components: []ir.ConstantHandle{0, 1, 2},
				},
			},
		},
		GlobalVariables: []ir.GlobalVariable{},
		Functions:       []ir.Function{},
		EntryPoints:     []ir.EntryPoint{},
	}

	// Configure backend options
	options := spirv.Options{
		Version: spirv.Version1_3,
		Debug:   true, // Include debug names
	}

	// Create backend and compile
	backend := spirv.NewBackend(options)
	binary, err := backend.Compile(module)
	if err != nil {
		panic(err)
	}

	// Verify magic number
	magic := uint32(binary[0]) | uint32(binary[1])<<8 | uint32(binary[2])<<16 | uint32(binary[3])<<24
	fmt.Printf("SPIR-V magic: 0x%08x\n", magic)
	fmt.Printf("Binary size: %d bytes\n", len(binary))
	fmt.Println("Compilation successful!")

}
Output:
SPIR-V magic: 0x07230203
Binary size: 172 bytes
Compilation successful!

Index

Examples

Constants

View Source
const (
	CapabilityMatrix                             = codegen.CapabilityMatrix
	CapabilityShader                             = codegen.CapabilityShader
	CapabilityFloat16                            = codegen.CapabilityFloat16
	CapabilityFloat64                            = codegen.CapabilityFloat64
	CapabilityInt64                              = codegen.CapabilityInt64
	CapabilityInt16                              = codegen.CapabilityInt16
	CapabilityImageGatherExtended                = codegen.CapabilityImageGatherExtended
	CapabilityInt8                               = codegen.CapabilityInt8
	CapabilityLinkage                            = codegen.CapabilityLinkage
	CapabilityInt64Atomics                       = codegen.CapabilityInt64Atomics
	CapabilityClipDistance                       = codegen.CapabilityClipDistance
	CapabilityImageCubeArray                     = codegen.CapabilityImageCubeArray
	CapabilitySampleRateShading                  = codegen.CapabilitySampleRateShading
	CapabilitySampled1D                          = codegen.CapabilitySampled1D
	CapabilityImage1D                            = codegen.CapabilityImage1D
	CapabilitySampledCubeArray                   = codegen.CapabilitySampledCubeArray
	CapabilityStorageImageExtendedFormats        = codegen.CapabilityStorageImageExtendedFormats
	CapabilityImageQuery                         = codegen.CapabilityImageQuery
	CapabilityDerivativeControl                  = codegen.CapabilityDerivativeControl
	CapabilityStorageBuffer16BitAccess           = codegen.CapabilityStorageBuffer16BitAccess
	CapabilityUniformAndStorageBuffer16BitAccess = codegen.CapabilityUniformAndStorageBuffer16BitAccess
	CapabilityStorageInputOutput16               = codegen.CapabilityStorageInputOutput16
	CapabilityMultiView                          = codegen.CapabilityMultiView
	CapabilityFragmentBarycentricKHR             = codegen.CapabilityFragmentBarycentricKHR
	CapabilityShaderNonUniform                   = codegen.CapabilityShaderNonUniform
	CapabilityAtomicFloat32AddEXT                = codegen.CapabilityAtomicFloat32AddEXT
	CapabilityDotProductInput4x8BitPacked        = codegen.CapabilityDotProductInput4x8BitPacked
	CapabilityDotProduct                         = codegen.CapabilityDotProduct
	CapabilityGroupNonUniform                    = codegen.CapabilityGroupNonUniform
	CapabilityGroupNonUniformVote                = codegen.CapabilityGroupNonUniformVote
	CapabilityGroupNonUniformArithmetic          = codegen.CapabilityGroupNonUniformArithmetic
	CapabilityGroupNonUniformBallot              = codegen.CapabilityGroupNonUniformBallot
	CapabilityGroupNonUniformShuffle             = codegen.CapabilityGroupNonUniformShuffle
	CapabilityGroupNonUniformShuffleRel          = codegen.CapabilityGroupNonUniformShuffleRel
	CapabilityGroupNonUniformQuad                = codegen.CapabilityGroupNonUniformQuad
	CapabilityGeometry                           = codegen.CapabilityGeometry
	CapabilitySubgroupBallotKHR                  = codegen.CapabilitySubgroupBallotKHR
	CapabilityInt64ImageEXT                      = codegen.CapabilityInt64ImageEXT
)

Common capabilities.

View Source
const (
	BlockExitReturn  = codegen.BlockExitReturn
	BlockExitBranch  = codegen.BlockExitBranch
	BlockExitBreakIf = codegen.BlockExitBreakIf
)

BlockExitKind values.

View Source
const (
	ExitUsed      = codegen.ExitUsed
	ExitDiscarded = codegen.ExitDiscarded
)

BlockExitDisposition values.

View Source
const (
	MagicNumber = codegen.MagicNumber
	GeneratorID = codegen.GeneratorID
)

SPIR-V magic number and constants.

View Source
const (
	OpNop               = codegen.OpNop
	OpSource            = codegen.OpSource
	OpString            = codegen.OpString
	OpName              = codegen.OpName
	OpMemberName        = codegen.OpMemberName
	OpExtInstImport     = codegen.OpExtInstImport
	OpMemoryModel       = codegen.OpMemoryModel
	OpEntryPoint        = codegen.OpEntryPoint
	OpExecutionMode     = codegen.OpExecutionMode
	OpCapability        = codegen.OpCapability
	OpTypeVoid          = codegen.OpTypeVoid
	OpTypeBool          = codegen.OpTypeBool
	OpTypeInt           = codegen.OpTypeInt
	OpTypeFloat         = codegen.OpTypeFloat
	OpTypeVector        = codegen.OpTypeVector
	OpTypeMatrix        = codegen.OpTypeMatrix
	OpTypeArray         = codegen.OpTypeArray
	OpTypeRuntimeArray  = codegen.OpTypeRuntimeArray
	OpTypeStruct        = codegen.OpTypeStruct
	OpTypePointer       = codegen.OpTypePointer
	OpTypeFunction      = codegen.OpTypeFunction
	OpConstant          = codegen.OpConstant
	OpConstantComposite = codegen.OpConstantComposite
	OpConstantNull      = codegen.OpConstantNull
	OpFunction          = codegen.OpFunction
	OpFunctionParameter = codegen.OpFunctionParameter
	OpFunctionEnd       = codegen.OpFunctionEnd
	OpFunctionCall      = codegen.OpFunctionCall
	OpVariable          = codegen.OpVariable
	OpLoad              = codegen.OpLoad
	OpStore             = codegen.OpStore
	OpAccessChain       = codegen.OpAccessChain
	OpDecorate          = codegen.OpDecorate
	OpMemberDecorate    = codegen.OpMemberDecorate
	OpLabel             = codegen.OpLabel
	OpBranch            = codegen.OpBranch
	OpPhi               = codegen.OpPhi
	OpReturn            = codegen.OpReturn
	OpReturnValue       = codegen.OpReturnValue
	OpUnreachable       = codegen.OpUnreachable
	OpExtension         = codegen.OpExtension
)

Common opcodes.

View Source
const (
	OpFNegate           = codegen.OpFNegate
	OpSNegate           = codegen.OpSNegate
	OpFAdd              = codegen.OpFAdd
	OpFSub              = codegen.OpFSub
	OpFMul              = codegen.OpFMul
	OpUDiv              = codegen.OpUDiv
	OpSDiv              = codegen.OpSDiv
	OpFDiv              = codegen.OpFDiv
	OpUMod              = codegen.OpUMod
	OpSRem              = codegen.OpSRem
	OpSMod              = codegen.OpSMod
	OpFRem              = codegen.OpFRem
	OpFMod              = codegen.OpFMod
	OpVectorTimesScalar = codegen.OpVectorTimesScalar
	OpMatrixTimesScalar = codegen.OpMatrixTimesScalar
	OpVectorTimesMatrix = codegen.OpVectorTimesMatrix
	OpMatrixTimesVector = codegen.OpMatrixTimesVector
	OpMatrixTimesMatrix = codegen.OpMatrixTimesMatrix
	OpIAdd              = codegen.OpIAdd
	OpISub              = codegen.OpISub
	OpIMul              = codegen.OpIMul
)

Arithmetic opcodes.

View Source
const (
	OpFOrdEqual            = codegen.OpFOrdEqual
	OpFOrdNotEqual         = codegen.OpFOrdNotEqual
	OpFOrdLessThan         = codegen.OpFOrdLessThan
	OpFOrdGreaterThan      = codegen.OpFOrdGreaterThan
	OpFOrdLessThanEqual    = codegen.OpFOrdLessThanEqual
	OpFOrdGreaterThanEqual = codegen.OpFOrdGreaterThanEqual
	OpIEqual               = codegen.OpIEqual
	OpINotEqual            = codegen.OpINotEqual
	OpSLessThan            = codegen.OpSLessThan
	OpSLessThanEqual       = codegen.OpSLessThanEqual
	OpSGreaterThan         = codegen.OpSGreaterThan
	OpSGreaterThanEqual    = codegen.OpSGreaterThanEqual
	OpULessThan            = codegen.OpULessThan
	OpULessThanEqual       = codegen.OpULessThanEqual
	OpUGreaterThan         = codegen.OpUGreaterThan
	OpUGreaterThanEqual    = codegen.OpUGreaterThanEqual
)

Comparison opcodes.

View Source
const (
	OpLogicalEqual    = codegen.OpLogicalEqual
	OpLogicalNotEqual = codegen.OpLogicalNotEqual
	OpLogicalOr       = codegen.OpLogicalOr
	OpLogicalAnd      = codegen.OpLogicalAnd
	OpLogicalNot      = codegen.OpLogicalNot
	OpSelect          = codegen.OpSelect
	OpNot             = codegen.OpNot
	OpAny             = codegen.OpAny
	OpAll             = codegen.OpAll
	OpIsNan           = codegen.OpIsNan
	OpIsInf           = codegen.OpIsInf
)

Logical opcodes.

View Source
const (
	OpVectorExtractDynamic = codegen.OpVectorExtractDynamic
	OpVectorShuffle        = codegen.OpVectorShuffle
	OpCompositeConstruct   = codegen.OpCompositeConstruct
	OpCompositeExtract     = codegen.OpCompositeExtract
)

Composite opcodes.

View Source
const (
	OpShiftRightLogical    = codegen.OpShiftRightLogical
	OpShiftRightArithmetic = codegen.OpShiftRightArithmetic
	OpShiftLeftLogical     = codegen.OpShiftLeftLogical
	OpBitwiseOr            = codegen.OpBitwiseOr
	OpBitwiseXor           = codegen.OpBitwiseXor
	OpBitwiseAnd           = codegen.OpBitwiseAnd
	OpBitFieldInsert       = codegen.OpBitFieldInsert
	OpBitFieldSExtract     = codegen.OpBitFieldSExtract
	OpBitFieldUExtract     = codegen.OpBitFieldUExtract
	OpBitReverse           = codegen.OpBitReverse
	OpBitCount             = codegen.OpBitCount
)

Bitwise opcodes.

View Source
const (
	OpSelectionMerge    = codegen.OpSelectionMerge
	OpLoopMerge         = codegen.OpLoopMerge
	OpBranchConditional = codegen.OpBranchConditional
	OpSwitch            = codegen.OpSwitch
	OpKill              = codegen.OpKill
)

Control flow opcodes.

View Source
const (
	OpDPdx         = codegen.OpDPdx
	OpDPdy         = codegen.OpDPdy
	OpFwidth       = codegen.OpFwidth
	OpDPdxFine     = codegen.OpDPdxFine
	OpDPdyFine     = codegen.OpDPdyFine
	OpFwidthFine   = codegen.OpFwidthFine
	OpDPdxCoarse   = codegen.OpDPdxCoarse
	OpDPdyCoarse   = codegen.OpDPdyCoarse
	OpFwidthCoarse = codegen.OpFwidthCoarse
)

Derivative opcodes.

View Source
const (
	OpConvertFToU   = codegen.OpConvertFToU
	OpConvertFToS   = codegen.OpConvertFToS
	OpConvertSToF   = codegen.OpConvertSToF
	OpConvertUToF   = codegen.OpConvertUToF
	OpUConvert      = codegen.OpUConvert
	OpSConvert      = codegen.OpSConvert
	OpFConvert      = codegen.OpFConvert
	OpQuantizeToF16 = codegen.OpQuantizeToF16
	OpBitcast       = codegen.OpBitcast
)

Conversion opcodes.

View Source
const (
	OpAtomicLoad        = codegen.OpAtomicLoad
	OpAtomicStore       = codegen.OpAtomicStore
	OpAtomicExchange    = codegen.OpAtomicExchange
	OpAtomicCompareExch = codegen.OpAtomicCompareExch
	OpAtomicIIncrement  = codegen.OpAtomicIIncrement
	OpAtomicIDecrement  = codegen.OpAtomicIDecrement
	OpAtomicIAdd        = codegen.OpAtomicIAdd
	OpAtomicFAddEXT     = codegen.OpAtomicFAddEXT
	OpAtomicISub        = codegen.OpAtomicISub
	OpAtomicSMin        = codegen.OpAtomicSMin
	OpAtomicUMin        = codegen.OpAtomicUMin
	OpAtomicSMax        = codegen.OpAtomicSMax
	OpAtomicUMax        = codegen.OpAtomicUMax
	OpAtomicAnd         = codegen.OpAtomicAnd
	OpAtomicOr          = codegen.OpAtomicOr
	OpAtomicXor         = codegen.OpAtomicXor
)

Atomic operation opcodes.

View Source
const (
	OpSDotKHR = codegen.OpSDotKHR
	OpUDotKHR = codegen.OpUDotKHR

	PackedVectorFormat4x8Bit = codegen.PackedVectorFormat4x8Bit
)

Integer dot product opcodes.

View Source
const (
	ScopeDevice    = codegen.ScopeDevice
	ScopeWorkgroup = codegen.ScopeWorkgroup
	ScopeSubgroup  = codegen.ScopeSubgroup
)

Memory scope for atomic operations.

View Source
const (
	MemorySemanticsNone                = codegen.MemorySemanticsNone
	MemorySemanticsAcquire             = codegen.MemorySemanticsAcquire
	MemorySemanticsRelease             = codegen.MemorySemanticsRelease
	MemorySemanticsAcquireRelease      = codegen.MemorySemanticsAcquireRelease
	MemorySemanticsUniformMemory       = codegen.MemorySemanticsUniformMemory
	MemorySemanticsSubgroupMemory      = codegen.MemorySemanticsSubgroupMemory
	MemorySemanticsWorkgroupMemory     = codegen.MemorySemanticsWorkgroupMemory
	MemorySemanticsAtomicCounterMemory = codegen.MemorySemanticsAtomicCounterMemory
	MemorySemanticsImageMemory         = codegen.MemorySemanticsImageMemory
)

Memory semantics for atomic operations.

View Source
const (
	OpControlBarrier = codegen.OpControlBarrier
	OpMemoryBarrier  = codegen.OpMemoryBarrier
)

Barrier opcodes.

View Source
const (
	OpGroupNonUniformElect            = codegen.OpGroupNonUniformElect
	OpGroupNonUniformAll              = codegen.OpGroupNonUniformAll
	OpGroupNonUniformAny              = codegen.OpGroupNonUniformAny
	OpGroupNonUniformAllEqual         = codegen.OpGroupNonUniformAllEqual
	OpGroupNonUniformBroadcast        = codegen.OpGroupNonUniformBroadcast
	OpGroupNonUniformBroadcastFirst   = codegen.OpGroupNonUniformBroadcastFirst
	OpGroupNonUniformBallot           = codegen.OpGroupNonUniformBallot
	OpGroupNonUniformInverseBallot    = codegen.OpGroupNonUniformInverseBallot
	OpGroupNonUniformBallotBitExtract = codegen.OpGroupNonUniformBallotBitExtract
	OpGroupNonUniformBallotBitCount   = codegen.OpGroupNonUniformBallotBitCount
	OpGroupNonUniformBallotFindLSB    = codegen.OpGroupNonUniformBallotFindLSB
	OpGroupNonUniformBallotFindMSB    = codegen.OpGroupNonUniformBallotFindMSB
	OpGroupNonUniformShuffle          = codegen.OpGroupNonUniformShuffle
	OpGroupNonUniformShuffleXor       = codegen.OpGroupNonUniformShuffleXor
	OpGroupNonUniformShuffleUp        = codegen.OpGroupNonUniformShuffleUp
	OpGroupNonUniformShuffleDown      = codegen.OpGroupNonUniformShuffleDown
	OpGroupNonUniformIAdd             = codegen.OpGroupNonUniformIAdd
	OpGroupNonUniformFAdd             = codegen.OpGroupNonUniformFAdd
	OpGroupNonUniformIMul             = codegen.OpGroupNonUniformIMul
	OpGroupNonUniformFMul             = codegen.OpGroupNonUniformFMul
	OpGroupNonUniformSMin             = codegen.OpGroupNonUniformSMin
	OpGroupNonUniformUMin             = codegen.OpGroupNonUniformUMin
	OpGroupNonUniformFMin             = codegen.OpGroupNonUniformFMin
	OpGroupNonUniformSMax             = codegen.OpGroupNonUniformSMax
	OpGroupNonUniformUMax             = codegen.OpGroupNonUniformUMax
	OpGroupNonUniformFMax             = codegen.OpGroupNonUniformFMax
	OpGroupNonUniformBitwiseAnd       = codegen.OpGroupNonUniformBitwiseAnd
	OpGroupNonUniformBitwiseOr        = codegen.OpGroupNonUniformBitwiseOr
	OpGroupNonUniformBitwiseXor       = codegen.OpGroupNonUniformBitwiseXor
	OpGroupNonUniformLogicalAnd       = codegen.OpGroupNonUniformLogicalAnd
	OpGroupNonUniformLogicalOr        = codegen.OpGroupNonUniformLogicalOr
	OpGroupNonUniformLogicalXor       = codegen.OpGroupNonUniformLogicalXor
	OpGroupNonUniformQuadBroadcast    = codegen.OpGroupNonUniformQuadBroadcast
	OpGroupNonUniformQuadSwap         = codegen.OpGroupNonUniformQuadSwap
)

Subgroup opcodes.

View Source
const (
	GroupOperationReduce        = codegen.GroupOperationReduce
	GroupOperationInclusiveScan = codegen.GroupOperationInclusiveScan
	GroupOperationExclusiveScan = codegen.GroupOperationExclusiveScan
)

GroupOperation for subgroup collective operations.

View Source
const (
	DecorationBlock         = codegen.DecorationBlock
	DecorationColMajor      = codegen.DecorationColMajor
	DecorationRowMajor      = codegen.DecorationRowMajor
	DecorationArrayStride   = codegen.DecorationArrayStride
	DecorationMatrixStride  = codegen.DecorationMatrixStride
	DecorationBuiltIn       = codegen.DecorationBuiltIn
	DecorationFlat          = codegen.DecorationFlat
	DecorationNoPerspective = codegen.DecorationNoPerspective
	DecorationCentroid      = codegen.DecorationCentroid
	DecorationSample        = codegen.DecorationSample
	DecorationNonWritable   = codegen.DecorationNonWritable
	DecorationNonReadable   = codegen.DecorationNonReadable
	DecorationLocation      = codegen.DecorationLocation
	DecorationIndex         = codegen.DecorationIndex
	DecorationBinding       = codegen.DecorationBinding
	DecorationDescriptorSet = codegen.DecorationDescriptorSet
	DecorationOffset        = codegen.DecorationOffset
	DecorationNonUniform    = codegen.DecorationNonUniform
)
View Source
const (
	BuiltInPosition             = codegen.BuiltInPosition
	BuiltInPointSize            = codegen.BuiltInPointSize
	BuiltInClipDistance         = codegen.BuiltInClipDistance
	BuiltInCullDistance         = codegen.BuiltInCullDistance
	BuiltInVertexID             = codegen.BuiltInVertexID
	BuiltInInstanceID           = codegen.BuiltInInstanceID
	BuiltInPrimitiveID          = codegen.BuiltInPrimitiveID
	BuiltInInvocationID         = codegen.BuiltInInvocationID
	BuiltInLayer                = codegen.BuiltInLayer
	BuiltInViewportIndex        = codegen.BuiltInViewportIndex
	BuiltInTessLevelOuter       = codegen.BuiltInTessLevelOuter
	BuiltInTessLevelInner       = codegen.BuiltInTessLevelInner
	BuiltInTessCoord            = codegen.BuiltInTessCoord
	BuiltInPatchVertices        = codegen.BuiltInPatchVertices
	BuiltInFragCoord            = codegen.BuiltInFragCoord
	BuiltInPointCoord           = codegen.BuiltInPointCoord
	BuiltInFrontFacing          = codegen.BuiltInFrontFacing
	BuiltInSampleID             = codegen.BuiltInSampleID
	BuiltInSamplePosition       = codegen.BuiltInSamplePosition
	BuiltInSampleMask           = codegen.BuiltInSampleMask
	BuiltInFragDepth            = codegen.BuiltInFragDepth
	BuiltInHelperInvocation     = codegen.BuiltInHelperInvocation
	BuiltInNumWorkgroups        = codegen.BuiltInNumWorkgroups
	BuiltInWorkgroupSize        = codegen.BuiltInWorkgroupSize
	BuiltInWorkgroupID          = codegen.BuiltInWorkgroupID
	BuiltInLocalInvocationID    = codegen.BuiltInLocalInvocationID
	BuiltInGlobalInvocationID   = codegen.BuiltInGlobalInvocationID
	BuiltInLocalInvocationIndex = codegen.BuiltInLocalInvocationIndex
	BuiltInVertexIndex          = codegen.BuiltInVertexIndex
	BuiltInInstanceIndex        = codegen.BuiltInInstanceIndex
	BuiltInSubgroupSize         = codegen.BuiltInSubgroupSize
	BuiltInSubgroupLocalInvID   = codegen.BuiltInSubgroupLocalInvID
	BuiltInNumSubgroups         = codegen.BuiltInNumSubgroups
	BuiltInSubgroupID           = codegen.BuiltInSubgroupID
	BuiltInViewIndex            = codegen.BuiltInViewIndex
	BuiltInBaryCoordKHR         = codegen.BuiltInBaryCoordKHR
)
View Source
const (
	ExecutionModelVertex                 = codegen.ExecutionModelVertex
	ExecutionModelTessellationControl    = codegen.ExecutionModelTessellationControl
	ExecutionModelTessellationEvaluation = codegen.ExecutionModelTessellationEvaluation
	ExecutionModelGeometry               = codegen.ExecutionModelGeometry
	ExecutionModelFragment               = codegen.ExecutionModelFragment
	ExecutionModelGLCompute              = codegen.ExecutionModelGLCompute
	ExecutionModelKernel                 = codegen.ExecutionModelKernel
)
View Source
const (
	ExecutionModeInvocations              = codegen.ExecutionModeInvocations
	ExecutionModeSpacingEqual             = codegen.ExecutionModeSpacingEqual
	ExecutionModeSpacingFractionalEven    = codegen.ExecutionModeSpacingFractionalEven
	ExecutionModeSpacingFractionalOdd     = codegen.ExecutionModeSpacingFractionalOdd
	ExecutionModeVertexOrderCw            = codegen.ExecutionModeVertexOrderCw
	ExecutionModeVertexOrderCcw           = codegen.ExecutionModeVertexOrderCcw
	ExecutionModePixelCenterInteger       = codegen.ExecutionModePixelCenterInteger
	ExecutionModeOriginUpperLeft          = codegen.ExecutionModeOriginUpperLeft
	ExecutionModeOriginLowerLeft          = codegen.ExecutionModeOriginLowerLeft
	ExecutionModeEarlyFragmentTests       = codegen.ExecutionModeEarlyFragmentTests
	ExecutionModePointMode                = codegen.ExecutionModePointMode
	ExecutionModeXfb                      = codegen.ExecutionModeXfb
	ExecutionModeDepthReplacing           = codegen.ExecutionModeDepthReplacing
	ExecutionModeDepthGreater             = codegen.ExecutionModeDepthGreater
	ExecutionModeDepthLess                = codegen.ExecutionModeDepthLess
	ExecutionModeDepthUnchanged           = codegen.ExecutionModeDepthUnchanged
	ExecutionModeLocalSize                = codegen.ExecutionModeLocalSize
	ExecutionModeLocalSizeHint            = codegen.ExecutionModeLocalSizeHint
	ExecutionModeInputPoints              = codegen.ExecutionModeInputPoints
	ExecutionModeInputLines               = codegen.ExecutionModeInputLines
	ExecutionModeInputLinesAdjacency      = codegen.ExecutionModeInputLinesAdjacency
	ExecutionModeTriangles                = codegen.ExecutionModeTriangles
	ExecutionModeInputTrianglesAdjacency  = codegen.ExecutionModeInputTrianglesAdjacency
	ExecutionModeQuads                    = codegen.ExecutionModeQuads
	ExecutionModeIsolines                 = codegen.ExecutionModeIsolines
	ExecutionModeOutputVertices           = codegen.ExecutionModeOutputVertices
	ExecutionModeOutputPoints             = codegen.ExecutionModeOutputPoints
	ExecutionModeOutputLineStrip          = codegen.ExecutionModeOutputLineStrip
	ExecutionModeOutputTriangleStrip      = codegen.ExecutionModeOutputTriangleStrip
	ExecutionModeVecTypeHint              = codegen.ExecutionModeVecTypeHint
	ExecutionModeContractionOff           = codegen.ExecutionModeContractionOff
	ExecutionModeInitializer              = codegen.ExecutionModeInitializer
	ExecutionModeFinalizer                = codegen.ExecutionModeFinalizer
	ExecutionModeSubgroupSize             = codegen.ExecutionModeSubgroupSize
	ExecutionModeSubgroupsPerWorkgroup    = codegen.ExecutionModeSubgroupsPerWorkgroup
	ExecutionModeSubgroupsPerWorkgroupID  = codegen.ExecutionModeSubgroupsPerWorkgroupID
	ExecutionModeLocalSizeID              = codegen.ExecutionModeLocalSizeID
	ExecutionModeLocalSizeHintID          = codegen.ExecutionModeLocalSizeHintID
	ExecutionModePostDepthCoverage        = codegen.ExecutionModePostDepthCoverage
	ExecutionModeDenormPreserve           = codegen.ExecutionModeDenormPreserve
	ExecutionModeDenormFlushToZero        = codegen.ExecutionModeDenormFlushToZero
	ExecutionModeSignedZeroInfNanPreserve = codegen.ExecutionModeSignedZeroInfNanPreserve
	ExecutionModeRoundingModeRTE          = codegen.ExecutionModeRoundingModeRTE
	ExecutionModeRoundingModeRTZ          = codegen.ExecutionModeRoundingModeRTZ
)
View Source
const (
	StorageClassUniformConstant         = codegen.StorageClassUniformConstant
	StorageClassInput                   = codegen.StorageClassInput
	StorageClassUniform                 = codegen.StorageClassUniform
	StorageClassOutput                  = codegen.StorageClassOutput
	StorageClassWorkgroup               = codegen.StorageClassWorkgroup
	StorageClassCrossWorkgroup          = codegen.StorageClassCrossWorkgroup
	StorageClassPrivate                 = codegen.StorageClassPrivate
	StorageClassFunction                = codegen.StorageClassFunction
	StorageClassGeneric                 = codegen.StorageClassGeneric
	StorageClassPushConstant            = codegen.StorageClassPushConstant
	StorageClassAtomicCounter           = codegen.StorageClassAtomicCounter
	StorageClassImage                   = codegen.StorageClassImage
	StorageClassStorageBuffer           = codegen.StorageClassStorageBuffer
	StorageClassTaskPayloadWorkgroupEXT = codegen.StorageClassTaskPayloadWorkgroupEXT
)
View Source
const (
	AddressingModelLogical    = codegen.AddressingModelLogical
	AddressingModelPhysical32 = codegen.AddressingModelPhysical32
	AddressingModelPhysical64 = codegen.AddressingModelPhysical64
)
View Source
const (
	MemoryModelSimple  = codegen.MemoryModelSimple
	MemoryModelGLSL450 = codegen.MemoryModelGLSL450
	MemoryModelOpenCL  = codegen.MemoryModelOpenCL
	MemoryModelVulkan  = codegen.MemoryModelVulkan
)
View Source
const (
	FunctionControlNone       = codegen.FunctionControlNone
	FunctionControlInline     = codegen.FunctionControlInline
	FunctionControlDontInline = codegen.FunctionControlDontInline
	FunctionControlPure       = codegen.FunctionControlPure
	FunctionControlConst      = codegen.FunctionControlConst
)
View Source
const (
	SelectionControlNone        = codegen.SelectionControlNone
	SelectionControlFlatten     = codegen.SelectionControlFlatten
	SelectionControlDontFlatten = codegen.SelectionControlDontFlatten
)
View Source
const (
	LoopControlNone               = codegen.LoopControlNone
	LoopControlUnroll             = codegen.LoopControlUnroll
	LoopControlDontUnroll         = codegen.LoopControlDontUnroll
	LoopControlDependencyInfinite = codegen.LoopControlDependencyInfinite
	LoopControlDependencyLength   = codegen.LoopControlDependencyLength
	LoopControlMinIterations      = codegen.LoopControlMinIterations
	LoopControlMaxIterations      = codegen.LoopControlMaxIterations
	LoopControlIterationMultiple  = codegen.LoopControlIterationMultiple
	LoopControlPeelCount          = codegen.LoopControlPeelCount
	LoopControlPartialCount       = codegen.LoopControlPartialCount
)
View Source
const (
	ImageFormatUnknown      = codegen.ImageFormatUnknown
	ImageFormatRgba32f      = codegen.ImageFormatRgba32f
	ImageFormatRgba16f      = codegen.ImageFormatRgba16f
	ImageFormatR32f         = codegen.ImageFormatR32f
	ImageFormatRgba8        = codegen.ImageFormatRgba8
	ImageFormatRgba8Snorm   = codegen.ImageFormatRgba8Snorm
	ImageFormatRg32f        = codegen.ImageFormatRg32f
	ImageFormatRg16f        = codegen.ImageFormatRg16f
	ImageFormatR11fG11fB10f = codegen.ImageFormatR11fG11fB10f
	ImageFormatR16f         = codegen.ImageFormatR16f
	ImageFormatRgba16       = codegen.ImageFormatRgba16
	ImageFormatRgb10A2      = codegen.ImageFormatRgb10A2
	ImageFormatRg16         = codegen.ImageFormatRg16
	ImageFormatRg8          = codegen.ImageFormatRg8
	ImageFormatR16          = codegen.ImageFormatR16
	ImageFormatR8           = codegen.ImageFormatR8
	ImageFormatRgba16Snorm  = codegen.ImageFormatRgba16Snorm
	ImageFormatRg16Snorm    = codegen.ImageFormatRg16Snorm
	ImageFormatRg8Snorm     = codegen.ImageFormatRg8Snorm
	ImageFormatR16Snorm     = codegen.ImageFormatR16Snorm
	ImageFormatR8Snorm      = codegen.ImageFormatR8Snorm
	ImageFormatRgba32i      = codegen.ImageFormatRgba32i
	ImageFormatRgba16i      = codegen.ImageFormatRgba16i
	ImageFormatRgba8i       = codegen.ImageFormatRgba8i
	ImageFormatR32i         = codegen.ImageFormatR32i
	ImageFormatRg32i        = codegen.ImageFormatRg32i
	ImageFormatRg16i        = codegen.ImageFormatRg16i
	ImageFormatRg8i         = codegen.ImageFormatRg8i
	ImageFormatR16i         = codegen.ImageFormatR16i
	ImageFormatR8i          = codegen.ImageFormatR8i
	ImageFormatRgba32ui     = codegen.ImageFormatRgba32ui
	ImageFormatRgba16ui     = codegen.ImageFormatRgba16ui
	ImageFormatRgba8ui      = codegen.ImageFormatRgba8ui
	ImageFormatR32ui        = codegen.ImageFormatR32ui
	ImageFormatRgb10a2ui    = codegen.ImageFormatRgb10a2ui
	ImageFormatRg32ui       = codegen.ImageFormatRg32ui
	ImageFormatRg16ui       = codegen.ImageFormatRg16ui
	ImageFormatRg8ui        = codegen.ImageFormatRg8ui
	ImageFormatR16ui        = codegen.ImageFormatR16ui
	ImageFormatR8ui         = codegen.ImageFormatR8ui
	ImageFormatR64ui        = codegen.ImageFormatR64ui
	ImageFormatR64i         = codegen.ImageFormatR64i
)
View Source
const (
	GLSLstd450Round                 = codegen.GLSLstd450Round
	GLSLstd450RoundEven             = codegen.GLSLstd450RoundEven
	GLSLstd450Trunc                 = codegen.GLSLstd450Trunc
	GLSLstd450FAbs                  = codegen.GLSLstd450FAbs
	GLSLstd450SAbs                  = codegen.GLSLstd450SAbs
	GLSLstd450FSign                 = codegen.GLSLstd450FSign
	GLSLstd450SSign                 = codegen.GLSLstd450SSign
	GLSLstd450Floor                 = codegen.GLSLstd450Floor
	GLSLstd450Ceil                  = codegen.GLSLstd450Ceil
	GLSLstd450Fract                 = codegen.GLSLstd450Fract
	GLSLstd450Radians               = codegen.GLSLstd450Radians
	GLSLstd450Degrees               = codegen.GLSLstd450Degrees
	GLSLstd450Sin                   = codegen.GLSLstd450Sin
	GLSLstd450Cos                   = codegen.GLSLstd450Cos
	GLSLstd450Tan                   = codegen.GLSLstd450Tan
	GLSLstd450Asin                  = codegen.GLSLstd450Asin
	GLSLstd450Acos                  = codegen.GLSLstd450Acos
	GLSLstd450Atan                  = codegen.GLSLstd450Atan
	GLSLstd450Sinh                  = codegen.GLSLstd450Sinh
	GLSLstd450Cosh                  = codegen.GLSLstd450Cosh
	GLSLstd450Tanh                  = codegen.GLSLstd450Tanh
	GLSLstd450Asinh                 = codegen.GLSLstd450Asinh
	GLSLstd450Acosh                 = codegen.GLSLstd450Acosh
	GLSLstd450Atanh                 = codegen.GLSLstd450Atanh
	GLSLstd450Atan2                 = codegen.GLSLstd450Atan2
	GLSLstd450Pow                   = codegen.GLSLstd450Pow
	GLSLstd450Exp                   = codegen.GLSLstd450Exp
	GLSLstd450Log                   = codegen.GLSLstd450Log
	GLSLstd450Exp2                  = codegen.GLSLstd450Exp2
	GLSLstd450Log2                  = codegen.GLSLstd450Log2
	GLSLstd450Sqrt                  = codegen.GLSLstd450Sqrt
	GLSLstd450InverseSqrt           = codegen.GLSLstd450InverseSqrt
	GLSLstd450Determinant           = codegen.GLSLstd450Determinant
	GLSLstd450MatrixInverse         = codegen.GLSLstd450MatrixInverse
	GLSLstd450Modf                  = codegen.GLSLstd450Modf
	GLSLstd450ModfStruct            = codegen.GLSLstd450ModfStruct
	GLSLstd450FMin                  = codegen.GLSLstd450FMin
	GLSLstd450UMin                  = codegen.GLSLstd450UMin
	GLSLstd450SMin                  = codegen.GLSLstd450SMin
	GLSLstd450FMax                  = codegen.GLSLstd450FMax
	GLSLstd450UMax                  = codegen.GLSLstd450UMax
	GLSLstd450SMax                  = codegen.GLSLstd450SMax
	GLSLstd450FClamp                = codegen.GLSLstd450FClamp
	GLSLstd450UClamp                = codegen.GLSLstd450UClamp
	GLSLstd450SClamp                = codegen.GLSLstd450SClamp
	GLSLstd450FMix                  = codegen.GLSLstd450FMix
	GLSLstd450IMix                  = codegen.GLSLstd450IMix
	GLSLstd450Step                  = codegen.GLSLstd450Step
	GLSLstd450SmoothStep            = codegen.GLSLstd450SmoothStep
	GLSLstd450Fma                   = codegen.GLSLstd450Fma
	GLSLstd450Frexp                 = codegen.GLSLstd450Frexp
	GLSLstd450FrexpStruct           = codegen.GLSLstd450FrexpStruct
	GLSLstd450Ldexp                 = codegen.GLSLstd450Ldexp
	GLSLstd450PackSnorm4x8          = codegen.GLSLstd450PackSnorm4x8
	GLSLstd450PackUnorm4x8          = codegen.GLSLstd450PackUnorm4x8
	GLSLstd450PackSnorm2x16         = codegen.GLSLstd450PackSnorm2x16
	GLSLstd450PackUnorm2x16         = codegen.GLSLstd450PackUnorm2x16
	GLSLstd450PackHalf2x16          = codegen.GLSLstd450PackHalf2x16
	GLSLstd450PackDouble2x32        = codegen.GLSLstd450PackDouble2x32
	GLSLstd450UnpackSnorm2x16       = codegen.GLSLstd450UnpackSnorm2x16
	GLSLstd450UnpackUnorm2x16       = codegen.GLSLstd450UnpackUnorm2x16
	GLSLstd450UnpackHalf2x16        = codegen.GLSLstd450UnpackHalf2x16
	GLSLstd450UnpackSnorm4x8        = codegen.GLSLstd450UnpackSnorm4x8
	GLSLstd450UnpackUnorm4x8        = codegen.GLSLstd450UnpackUnorm4x8
	GLSLstd450UnpackDouble2x32      = codegen.GLSLstd450UnpackDouble2x32
	GLSLstd450Length                = codegen.GLSLstd450Length
	GLSLstd450Distance              = codegen.GLSLstd450Distance
	GLSLstd450Cross                 = codegen.GLSLstd450Cross
	GLSLstd450Normalize             = codegen.GLSLstd450Normalize
	GLSLstd450FaceForward           = codegen.GLSLstd450FaceForward
	GLSLstd450Reflect               = codegen.GLSLstd450Reflect
	GLSLstd450Refract               = codegen.GLSLstd450Refract
	GLSLstd450FindILsb              = codegen.GLSLstd450FindILsb
	GLSLstd450FindSMsb              = codegen.GLSLstd450FindSMsb
	GLSLstd450FindUMsb              = codegen.GLSLstd450FindUMsb
	GLSLstd450InterpolateAtCentroid = codegen.GLSLstd450InterpolateAtCentroid
	GLSLstd450InterpolateAtSample   = codegen.GLSLstd450InterpolateAtSample
	GLSLstd450InterpolateAtOffset   = codegen.GLSLstd450InterpolateAtOffset
	GLSLstd450NMin                  = codegen.GLSLstd450NMin
	GLSLstd450NMax                  = codegen.GLSLstd450NMax
	GLSLstd450NClamp                = codegen.GLSLstd450NClamp
)
View Source
const (
	OpExtInst = codegen.OpExtInst
)

Extended instruction set opcodes.

Variables

View Source
var (
	Version1_0 = Version{1, 0}
	Version1_1 = Version{1, 1}
	Version1_2 = Version{1, 2}
	Version1_3 = Version{1, 3}
	Version1_4 = Version{1, 4}
	Version1_5 = Version{1, 5}
	Version1_6 = Version{1, 6}
)

Common SPIR-V versions.

Functions

This section is empty.

Types

type AddressingModel

type AddressingModel = codegen.AddressingModel

AddressingModel represents a SPIR-V addressing model.

type Backend

type Backend = codegen.Backend

Backend translates IR to SPIR-V.

func NewBackend

func NewBackend(options Options) *Backend

NewBackend creates a new SPIR-V backend.

type Block added in v0.15.0

type Block = codegen.Block

Block represents a SPIR-V basic block under construction.

func NewBlock added in v0.15.0

func NewBlock(labelID uint32) Block

NewBlock creates a new block with the given label ID and an empty body.

type BlockExit added in v0.15.0

type BlockExit = codegen.BlockExit

BlockExit specifies how a block should end.

type BlockExitDisposition added in v0.15.0

type BlockExitDisposition = codegen.BlockExitDisposition

BlockExitDisposition indicates whether writeBlock consumed the provided exit.

type BlockExitKind added in v0.15.0

type BlockExitKind = codegen.BlockExitKind

BlockExitKind specifies how a block should be terminated.

type BoundsCheckPolicies added in v0.15.0

type BoundsCheckPolicies struct {
	// ImageLoad controls bounds checking for image load operations.
	ImageLoad BoundsCheckPolicy
	// ImageStore controls bounds checking for image store operations.
	ImageStore BoundsCheckPolicy
	// Index controls bounds checking for buffer index operations.
	Index BoundsCheckPolicy
}

BoundsCheckPolicies holds per-resource-type bounds check policies.

type BoundsCheckPolicy added in v0.15.0

type BoundsCheckPolicy uint8

BoundsCheckPolicy controls how out-of-bounds resource accesses are handled.

const (
	// BoundsCheckUnchecked performs no bounds checking (default).
	BoundsCheckUnchecked BoundsCheckPolicy = iota
	// BoundsCheckRestrict clamps coordinates/level/sample to valid range.
	BoundsCheckRestrict
	// BoundsCheckReadZeroSkipWrite returns zero for out-of-bounds reads, skips writes.
	BoundsCheckReadZeroSkipWrite
)

BoundsCheckPolicy values.

type BuiltIn added in v0.8.4

type BuiltIn = codegen.BuiltIn

BuiltIn represents a SPIR-V built-in decoration value.

type Capability

type Capability = codegen.Capability

Capability represents a SPIR-V capability. This is an alias because Capability values are used directly with implementation types (ModuleBuilder, Backend) that remain aliases.

type Decoration

type Decoration = codegen.Decoration

Decoration represents a SPIR-V decoration.

type ExecutionMode

type ExecutionMode = codegen.ExecutionMode

ExecutionMode represents a SPIR-V execution mode.

type ExecutionModel

type ExecutionModel = codegen.ExecutionModel

ExecutionModel represents a SPIR-V execution model.

type ExpressionEmitter

type ExpressionEmitter = codegen.ExpressionEmitter

ExpressionEmitter handles expression and statement emission.

type FunctionBuilder added in v0.15.0

type FunctionBuilder = codegen.FunctionBuilder

FunctionBuilder collects terminated blocks for a single SPIR-V function.

type FunctionControl

type FunctionControl = codegen.FunctionControl

FunctionControl represents a SPIR-V function control.

type ImageFormat added in v0.10.0

type ImageFormat = codegen.ImageFormat

ImageFormat represents a SPIR-V image format.

func StorageFormatToImageFormat added in v0.10.0

func StorageFormatToImageFormat(format ir.StorageFormat) ImageFormat

StorageFormatToImageFormat converts an IR storage format to a SPIR-V image format.

type Instruction

type Instruction = codegen.Instruction

Instruction represents a SPIR-V instruction.

type InstructionBuilder

type InstructionBuilder = codegen.InstructionBuilder

InstructionBuilder builds SPIR-V instructions.

func NewInstructionBuilder

func NewInstructionBuilder() *InstructionBuilder

NewInstructionBuilder creates a new instruction builder.

type LoopContext added in v0.15.0

type LoopContext = codegen.LoopContext

LoopContext provides break/continue targets for loop bodies.

type LoopControl

type LoopControl = codegen.LoopControl

LoopControl flags for OpLoopMerge.

type MemoryModel

type MemoryModel = codegen.MemoryModel

MemoryModel represents a SPIR-V memory model.

type ModuleBuilder

type ModuleBuilder = codegen.ModuleBuilder

ModuleBuilder builds complete SPIR-V modules.

Example (FragmentShader)

ExampleModuleBuilder_fragmentShader demonstrates a simple fragment shader structure.

package main

import (
	"fmt"

	"github.com/gogpu/naga/spirv"
)

func main() {
	builder := spirv.NewModuleBuilder(spirv.Version1_3)

	// Capabilities and memory model
	builder.AddCapability(spirv.CapabilityShader)
	builder.SetMemoryModel(spirv.AddressingModelLogical, spirv.MemoryModelGLSL450)

	// Types
	voidType := builder.AddTypeVoid()
	vec4Type := builder.AddTypeVector(builder.AddTypeFloat(32), 4)
	vec4PtrOutput := builder.AddTypePointer(spirv.StorageClassOutput, vec4Type)
	funcType := builder.AddTypeFunction(voidType)

	// Output variable
	outputVar := builder.AddVariable(vec4PtrOutput, spirv.StorageClassOutput)
	builder.AddName(outputVar, "fragColor")
	builder.AddDecorate(outputVar, spirv.DecorationLocation, 0)

	// Main function
	mainFunc := builder.AddFunction(funcType, voidType, spirv.FunctionControlNone)
	builder.AddName(mainFunc, "main")
	builder.AddLabel()
	builder.AddReturn()
	builder.AddFunctionEnd()

	// Entry point
	builder.AddEntryPoint(spirv.ExecutionModelFragment, mainFunc, "main", []uint32{outputVar})
	builder.AddExecutionMode(mainFunc, spirv.ExecutionModeOriginUpperLeft)

	binary := builder.Build()

	fmt.Printf("Fragment shader: %d bytes\n", len(binary))
}
Output:
Fragment shader: 244 bytes
Example (Minimal)

ExampleModuleBuilder_minimal demonstrates creating a minimal SPIR-V module.

package main

import (
	"fmt"

	"github.com/gogpu/naga/spirv"
)

func main() {
	// Create a module builder targeting SPIR-V 1.3
	builder := spirv.NewModuleBuilder(spirv.Version1_3)

	// Add required capability
	builder.AddCapability(spirv.CapabilityShader)

	// Set memory model (required for all modules)
	builder.SetMemoryModel(spirv.AddressingModelLogical, spirv.MemoryModelGLSL450)

	// Build the binary
	binary := builder.Build()

	fmt.Printf("Generated SPIR-V module: %d bytes\n", len(binary))
}
Output:
Generated SPIR-V module: 40 bytes
Example (WithTypes)

ExampleModuleBuilder_withTypes demonstrates creating types.

package main

import (
	"fmt"

	"github.com/gogpu/naga/spirv"
)

func main() {
	builder := spirv.NewModuleBuilder(spirv.Version1_3)
	builder.AddCapability(spirv.CapabilityShader)
	builder.SetMemoryModel(spirv.AddressingModelLogical, spirv.MemoryModelGLSL450)

	// Create basic types
	voidType := builder.AddTypeVoid()
	floatType := builder.AddTypeFloat(32)
	vec4Type := builder.AddTypeVector(floatType, 4)

	// Add debug names
	builder.AddName(floatType, "float")
	builder.AddName(vec4Type, "vec4")

	binary := builder.Build()

	fmt.Printf("void=%d float=%d vec4=%d size=%d\n", voidType, floatType, vec4Type, len(binary))
}
Output:
void=1 float=2 vec4=3 size=108

func NewModuleBuilder

func NewModuleBuilder(version Version) *ModuleBuilder

NewModuleBuilder creates a new SPIR-V module builder.

type OpCode

type OpCode = codegen.OpCode

OpCode represents a SPIR-V opcode.

type Options

type Options struct {
	// Version is the SPIR-V version to target.
	Version Version

	// Capabilities are additional capabilities to declare.
	Capabilities []Capability

	// Debug includes debug information.
	Debug bool

	// Validation enables output validation.
	Validation bool

	// UseStorageInputOutput16 enables StorageInputOutput16 capability for f16.
	UseStorageInputOutput16 bool

	// ForcePointSize adds a BuiltIn PointSize output variable with value 1.0.
	ForcePointSize bool

	// AdjustCoordinateSpace flips the Y coordinate of Position outputs.
	AdjustCoordinateSpace bool

	// ForceLoopBounding inserts a decrementing counter to prevent infinite loops.
	ForceLoopBounding bool

	// BoundsCheckPolicies controls how out-of-bounds image accesses are handled.
	BoundsCheckPolicies BoundsCheckPolicies

	// CapabilitiesAvailable limits which capabilities may be used.
	CapabilitiesAvailable map[Capability]struct{}

	// RayQueryInitTracking enables initialization tracking for ray queries.
	RayQueryInitTracking bool
}

Options configures SPIR-V generation.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns sensible default options.

type SelectionControl

type SelectionControl = codegen.SelectionControl

SelectionControl flags for OpSelectionMerge.

type StorageClass

type StorageClass = codegen.StorageClass

StorageClass represents a SPIR-V storage class.

type TerminatedBlock added in v0.15.0

type TerminatedBlock = codegen.TerminatedBlock

TerminatedBlock is a finalized basic block.

type Version

type Version struct {
	Major uint8
	Minor uint8
}

Version represents a SPIR-V version.

type Writer

type Writer = codegen.Writer

Writer generates SPIR-V from IR.

func NewWriter

func NewWriter(options Options) *Writer

NewWriter creates a new SPIR-V writer.

Directories

Path Synopsis
internal
codegen
Package codegen implements SPIR-V code generation from naga IR.
Package codegen implements SPIR-V code generation from naga IR.

Jump to

Keyboard shortcuts

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