Documentation
¶
Overview ¶
Package codegen implements SPIR-V code generation from naga IR.
Index ¶
- Constants
- Variables
- type AddressingModel
- type Backend
- type Block
- type BlockExit
- type BlockExitDisposition
- type BlockExitKind
- type BoundsCheckPolicies
- type BoundsCheckPolicy
- type BuiltIn
- type Capability
- type Decoration
- type ExecutionMode
- type ExecutionModel
- type ExpressionEmitter
- type FunctionBuilder
- type FunctionControl
- type ImageFormat
- type Instruction
- type InstructionBuilder
- type LoopContext
- type LoopControl
- type MemoryModel
- type ModuleBuilder
- func (b *ModuleBuilder) AddAccessChain(resultType uint32, base uint32, indices ...uint32) uint32
- func (b *ModuleBuilder) AddBinaryOp(opcode OpCode, resultType uint32, left uint32, right uint32) uint32
- func (b *ModuleBuilder) AddBranchConditional(condition uint32, trueLabel uint32, falseLabel uint32)
- func (b *ModuleBuilder) AddCapability(capability Capability)
- func (b *ModuleBuilder) AddCompositeConstruct(resultType uint32, constituents ...uint32) uint32
- func (b *ModuleBuilder) AddCompositeExtract(resultType uint32, composite uint32, indexes ...uint32) uint32
- func (b *ModuleBuilder) AddConstant(typeID uint32, values ...uint32) uint32
- func (b *ModuleBuilder) AddConstantComposite(typeID uint32, constituents ...uint32) uint32
- func (b *ModuleBuilder) AddConstantFloat32(typeID uint32, value float32) uint32
- func (b *ModuleBuilder) AddConstantFloat64(typeID uint32, value float64) uint32
- func (b *ModuleBuilder) AddConstantNull(typeID uint32) uint32
- func (b *ModuleBuilder) AddCopyLogical(resultType uint32, operand uint32) uint32
- func (b *ModuleBuilder) AddDecorate(id uint32, decoration Decoration, params ...uint32)
- func (b *ModuleBuilder) AddEntryPoint(execModel ExecutionModel, funcID uint32, name string, interfaces []uint32)
- func (b *ModuleBuilder) AddExecutionMode(entryPoint uint32, mode ExecutionMode, params ...uint32)
- func (b *ModuleBuilder) AddExtInst(resultType uint32, extSet uint32, instruction uint32, operands ...uint32) uint32
- func (b *ModuleBuilder) AddExtInstImport(name string) uint32
- func (b *ModuleBuilder) AddExtension(name string)
- func (b *ModuleBuilder) AddFunction(funcType uint32, returnType uint32, control FunctionControl) uint32
- func (b *ModuleBuilder) AddFunctionEnd()
- func (b *ModuleBuilder) AddFunctionParameter(typeID uint32) uint32
- func (b *ModuleBuilder) AddKill()
- func (b *ModuleBuilder) AddLabel() uint32
- func (b *ModuleBuilder) AddLabelWithID(id uint32)
- func (b *ModuleBuilder) AddLoad(resultType uint32, pointer uint32) uint32
- func (b *ModuleBuilder) AddLoopMerge(mergeLabel uint32, continueLabel uint32, control LoopControl)
- func (b *ModuleBuilder) AddMemberDecorate(structID, member uint32, decoration Decoration, params ...uint32)
- func (b *ModuleBuilder) AddMemberName(structID, member uint32, name string)
- func (b *ModuleBuilder) AddName(id uint32, name string)
- func (b *ModuleBuilder) AddReturn()
- func (b *ModuleBuilder) AddReturnValue(valueID uint32)
- func (b *ModuleBuilder) AddSelect(resultType uint32, condition uint32, accept uint32, reject uint32) uint32
- func (b *ModuleBuilder) AddSelectionMerge(mergeLabel uint32, control SelectionControl)
- func (b *ModuleBuilder) AddStore(pointer uint32, value uint32)
- func (b *ModuleBuilder) AddString(text string) uint32
- func (b *ModuleBuilder) AddTypeArray(elementType uint32, length uint32) uint32
- func (b *ModuleBuilder) AddTypeBool() uint32
- func (b *ModuleBuilder) AddTypeFloat(width uint32) uint32
- func (b *ModuleBuilder) AddTypeFunction(returnType uint32, paramTypes ...uint32) uint32
- func (b *ModuleBuilder) AddTypeInt(width uint32, signed bool) uint32
- func (b *ModuleBuilder) AddTypeMatrix(columnType uint32, columnCount uint32) uint32
- func (b *ModuleBuilder) AddTypePointer(storageClass StorageClass, baseType uint32) uint32
- func (b *ModuleBuilder) AddTypeRuntimeArray(elementType uint32) uint32
- func (b *ModuleBuilder) AddTypeSampler() uint32
- func (b *ModuleBuilder) AddTypeStruct(memberTypes ...uint32) uint32
- func (b *ModuleBuilder) AddTypeVector(componentType uint32, count uint32) uint32
- func (b *ModuleBuilder) AddTypeVoid() uint32
- func (b *ModuleBuilder) AddUnaryOp(opcode OpCode, resultType uint32, operand uint32) uint32
- func (b *ModuleBuilder) AddUnreachable()
- func (b *ModuleBuilder) AddVariable(pointerType uint32, storageClass StorageClass) uint32
- func (b *ModuleBuilder) AddVariableWithInit(pointerType uint32, storageClass StorageClass, initID uint32) uint32
- func (b *ModuleBuilder) AddVectorExtractDynamic(resultType uint32, vector uint32, index uint32) uint32
- func (b *ModuleBuilder) AddVectorShuffle(resultType uint32, vec1 uint32, vec2 uint32, components []uint32) uint32
- func (b *ModuleBuilder) AllocID() uint32
- func (b *ModuleBuilder) Build() []byte
- func (b *ModuleBuilder) RequireVersion(minVersion Version)
- func (b *ModuleBuilder) Reset(version Version)
- func (b *ModuleBuilder) SetMemoryModel(addressing AddressingModel, memory MemoryModel)
- type OpCode
- type Options
- type SelectionControl
- type StorageClass
- type TerminatedBlock
- type Version
- type Writer
Constants ¶
const ( OpRayQueryInitializeKHR OpCode = 4473 OpRayQueryTerminateKHR OpCode = 4474 OpRayQueryGenerateIntersectionKHR OpCode = 4475 OpRayQueryConfirmIntersectionKHR OpCode = 4476 OpRayQueryProceedKHR OpCode = 4477 OpRayQueryGetIntersectionTypeKHR OpCode = 4479 OpRayQueryGetRayTMinKHR OpCode = 6016 OpRayQueryGetRayFlagsKHR OpCode = 6017 OpRayQueryGetIntersectionTKHR OpCode = 6018 OpRayQueryGetIntersectionInstanceCustomIndexKHR OpCode = 6019 OpRayQueryGetIntersectionInstanceIdKHR OpCode = 6020 OpRayQueryGetIntersectionInstanceShaderBindingTableRecordOffsetKHR OpCode = 6021 OpRayQueryGetIntersectionGeometryIndexKHR OpCode = 6022 OpRayQueryGetIntersectionPrimitiveIndexKHR OpCode = 6023 OpRayQueryGetIntersectionBarycentricsKHR OpCode = 6024 OpRayQueryGetIntersectionFrontFaceKHR OpCode = 6025 OpRayQueryGetIntersectionObjectToWorldKHR OpCode = 6031 OpRayQueryGetIntersectionWorldToObjectKHR OpCode = 6032 CapabilityRayQueryKHR Capability = 4472 RayFlagsNone uint32 = 0 )
SPIR-V ray query opcodes.
const ( MagicNumber = 0x07230203 GeneratorID = 0x00000000 // Unregistered generator )
SPIR-V magic number and constants
const ( OpSDotKHR OpCode = 4450 // Signed integer dot product OpUDotKHR OpCode = 4451 // Unsigned integer dot product // PackedVectorFormat4x8Bit is the packed vector format for 4x8 bit integers. PackedVectorFormat4x8Bit uint32 = 0 )
Integer dot product opcodes (SPV_KHR_integer_dot_product)
const ( ScopeDevice uint32 = 1 // Visible to all invocations in the device ScopeWorkgroup uint32 = 2 // Visible to all invocations in the workgroup ScopeSubgroup uint32 = 3 // Visible to all invocations in the subgroup )
Memory scope for atomic operations
const ( MemorySemanticsNone uint32 = 0x0 MemorySemanticsAcquire uint32 = 0x2 MemorySemanticsRelease uint32 = 0x4 MemorySemanticsAcquireRelease uint32 = 0x8 MemorySemanticsUniformMemory uint32 = 0x40 MemorySemanticsSubgroupMemory uint32 = 0x80 MemorySemanticsWorkgroupMemory uint32 = 0x100 MemorySemanticsAtomicCounterMemory uint32 = 0x400 MemorySemanticsImageMemory uint32 = 0x800 )
Memory semantics for atomic operations
const ( GroupOperationReduce uint32 = 0 GroupOperationInclusiveScan uint32 = 1 GroupOperationExclusiveScan uint32 = 2 )
GroupOperation for subgroup collective operations.
const ( GLSLstd450Round uint32 = 1 GLSLstd450RoundEven uint32 = 2 GLSLstd450Trunc uint32 = 3 GLSLstd450FAbs uint32 = 4 GLSLstd450SAbs uint32 = 5 GLSLstd450FSign uint32 = 6 GLSLstd450SSign uint32 = 7 GLSLstd450Floor uint32 = 8 GLSLstd450Ceil uint32 = 9 GLSLstd450Fract uint32 = 10 GLSLstd450Radians uint32 = 11 GLSLstd450Degrees uint32 = 12 GLSLstd450Sin uint32 = 13 GLSLstd450Cos uint32 = 14 GLSLstd450Tan uint32 = 15 GLSLstd450Asin uint32 = 16 GLSLstd450Acos uint32 = 17 GLSLstd450Atan uint32 = 18 GLSLstd450Sinh uint32 = 19 GLSLstd450Cosh uint32 = 20 GLSLstd450Tanh uint32 = 21 GLSLstd450Asinh uint32 = 22 GLSLstd450Acosh uint32 = 23 GLSLstd450Atanh uint32 = 24 GLSLstd450Atan2 uint32 = 25 GLSLstd450Pow uint32 = 26 GLSLstd450Exp uint32 = 27 GLSLstd450Log uint32 = 28 GLSLstd450Exp2 uint32 = 29 GLSLstd450Log2 uint32 = 30 GLSLstd450Sqrt uint32 = 31 GLSLstd450InverseSqrt uint32 = 32 GLSLstd450Determinant uint32 = 33 GLSLstd450MatrixInverse uint32 = 34 GLSLstd450Modf uint32 = 35 GLSLstd450ModfStruct uint32 = 36 GLSLstd450FMin uint32 = 37 GLSLstd450UMin uint32 = 38 GLSLstd450SMin uint32 = 39 GLSLstd450FMax uint32 = 40 GLSLstd450UMax uint32 = 41 GLSLstd450SMax uint32 = 42 GLSLstd450FClamp uint32 = 43 GLSLstd450UClamp uint32 = 44 GLSLstd450SClamp uint32 = 45 GLSLstd450FMix uint32 = 46 GLSLstd450IMix uint32 = 47 GLSLstd450Step uint32 = 48 GLSLstd450SmoothStep uint32 = 49 GLSLstd450Fma uint32 = 50 GLSLstd450Frexp uint32 = 51 GLSLstd450FrexpStruct uint32 = 52 GLSLstd450Ldexp uint32 = 53 GLSLstd450PackSnorm4x8 uint32 = 54 GLSLstd450PackUnorm4x8 uint32 = 55 GLSLstd450PackSnorm2x16 uint32 = 56 GLSLstd450PackUnorm2x16 uint32 = 57 GLSLstd450PackHalf2x16 uint32 = 58 GLSLstd450PackDouble2x32 uint32 = 59 GLSLstd450UnpackSnorm2x16 uint32 = 60 GLSLstd450UnpackUnorm2x16 uint32 = 61 GLSLstd450UnpackHalf2x16 uint32 = 62 GLSLstd450UnpackSnorm4x8 uint32 = 63 GLSLstd450UnpackUnorm4x8 uint32 = 64 GLSLstd450UnpackDouble2x32 uint32 = 65 GLSLstd450Length uint32 = 66 GLSLstd450Distance uint32 = 67 GLSLstd450Cross uint32 = 68 GLSLstd450Normalize uint32 = 69 GLSLstd450FaceForward uint32 = 70 GLSLstd450Reflect uint32 = 71 GLSLstd450Refract uint32 = 72 GLSLstd450FindILsb uint32 = 73 GLSLstd450FindSMsb uint32 = 74 GLSLstd450FindUMsb uint32 = 75 GLSLstd450InterpolateAtCentroid uint32 = 76 GLSLstd450InterpolateAtSample uint32 = 77 GLSLstd450InterpolateAtOffset uint32 = 78 GLSLstd450NMin uint32 = 79 GLSLstd450NMax uint32 = 80 GLSLstd450NClamp uint32 = 81 )
GLSL.std.450 extended instruction set constants
Variables ¶
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 uint32
AddressingModel represents a SPIR-V addressing model.
const ( AddressingModelLogical AddressingModel = 0 AddressingModelPhysical32 AddressingModel = 1 AddressingModelPhysical64 AddressingModel = 2 )
Common addressing models
type Backend ¶
type Backend struct {
// contains filtered or unexported fields
}
Backend translates IR to SPIR-V.
func NewBackend ¶
NewBackend creates a new SPIR-V backend.
func (*Backend) Compile ¶
Compile translates an IR module to SPIR-V binary. The Backend is automatically reset before each compilation, so a single Backend instance can be reused across multiple Compile calls.
func (*Backend) Reset ¶
func (b *Backend) Reset()
Reset clears all state in the Backend without deallocating. This allows reuse of the same Backend instance across compilations, avoiding repeated allocation of maps and slices. After Reset, the Backend is in the same logical state as a freshly created one.
Reset is called automatically at the start of Compile, so callers do not need to call it explicitly.
type Block ¶
type Block struct {
LabelID uint32
Body []Instruction
}
Block represents a SPIR-V basic block under construction. Instructions are appended via Push; the block is not yet terminated.
func (*Block) Push ¶
func (b *Block) Push(inst Instruction)
Push appends an instruction to the block body.
type BlockExit ¶
type BlockExit struct {
Kind BlockExitKind
Target uint32 // branch target label ID (for BlockExitBranch)
Condition uint32 // SPIR-V ID of the boolean condition (for BlockExitBreakIf)
PreambleID uint32 // branch-back target (for BlockExitBreakIf)
}
BlockExit specifies how a block should end.
type BlockExitDisposition ¶
type BlockExitDisposition int
BlockExitDisposition indicates whether writeBlock consumed the provided exit.
const ( // ExitUsed means the exit was applied normally. ExitUsed BlockExitDisposition = iota // ExitDiscarded means the block ended early (break/continue/return/kill) // and the provided exit was not emitted. ExitDiscarded )
type BlockExitKind ¶
type BlockExitKind int
BlockExitKind specifies how a block should be terminated.
const ( // BlockExitReturn terminates with OpReturn or OpReturnValue. BlockExitReturn BlockExitKind = iota // BlockExitBranch terminates with OpBranch to a target label. BlockExitBranch // BlockExitBreakIf terminates with OpBranchConditional (break-if pattern). BlockExitBreakIf )
type BoundsCheckPolicies ¶
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 ¶
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 )
type BuiltIn ¶
type BuiltIn uint32
BuiltIn represents a SPIR-V built-in decoration value.
const ( BuiltInPosition BuiltIn = 0 BuiltInPointSize BuiltIn = 1 BuiltInClipDistance BuiltIn = 3 BuiltInCullDistance BuiltIn = 4 BuiltInVertexID BuiltIn = 5 BuiltInInstanceID BuiltIn = 6 BuiltInPrimitiveID BuiltIn = 7 BuiltInInvocationID BuiltIn = 8 BuiltInLayer BuiltIn = 9 BuiltInViewportIndex BuiltIn = 10 BuiltInTessLevelOuter BuiltIn = 11 BuiltInTessLevelInner BuiltIn = 12 BuiltInTessCoord BuiltIn = 13 BuiltInPatchVertices BuiltIn = 14 BuiltInFragCoord BuiltIn = 15 BuiltInPointCoord BuiltIn = 16 BuiltInFrontFacing BuiltIn = 17 BuiltInSampleID BuiltIn = 18 BuiltInSamplePosition BuiltIn = 19 BuiltInSampleMask BuiltIn = 20 BuiltInFragDepth BuiltIn = 22 BuiltInHelperInvocation BuiltIn = 23 BuiltInNumWorkgroups BuiltIn = 24 BuiltInWorkgroupSize BuiltIn = 25 BuiltInWorkgroupID BuiltIn = 26 BuiltInLocalInvocationID BuiltIn = 27 BuiltInGlobalInvocationID BuiltIn = 28 BuiltInLocalInvocationIndex BuiltIn = 29 BuiltInVertexIndex BuiltIn = 42 BuiltInInstanceIndex BuiltIn = 43 BuiltInSubgroupSize BuiltIn = 36 BuiltInSubgroupLocalInvID BuiltIn = 41 BuiltInNumSubgroups BuiltIn = 38 BuiltInSubgroupID BuiltIn = 40 BuiltInViewIndex BuiltIn = 4440 BuiltInBaryCoordKHR BuiltIn = 5286 )
SPIR-V built-in values (used with DecorationBuiltIn).
type Capability ¶
type Capability uint32
Capability represents a SPIR-V capability.
const ( CapabilityMatrix Capability = 0 // Implied by Shader CapabilityShader Capability = 1 CapabilityFloat16 Capability = 9 // Required for OpTypeFloat 16 CapabilityFloat64 Capability = 10 // Required for OpTypeFloat 64 CapabilityInt64 Capability = 11 // Required for OpTypeInt 64 CapabilityInt16 Capability = 22 // Required for OpTypeInt 16 CapabilityImageGatherExtended Capability = 25 // Offset on image gather/sample CapabilityInt8 Capability = 39 // Required for OpTypeInt 8 CapabilityLinkage Capability = 5 // Import/export linkage CapabilityInt64Atomics Capability = 12 // 64-bit atomic operations CapabilityClipDistance Capability = 32 // ClipDistance builtin CapabilityImageCubeArray Capability = 34 // Cube array storage images CapabilitySampleRateShading Capability = 35 // Sample-rate shading CapabilitySampled1D Capability = 43 // Sampled 1D images CapabilityImage1D Capability = 44 // 1D storage images CapabilitySampledCubeArray Capability = 45 // Sampled cube array images CapabilityStorageImageExtendedFormats Capability = 49 // Extended storage image formats CapabilityImageQuery Capability = 50 // Required for OpImageQuerySize/Lod/Levels/Samples CapabilityDerivativeControl Capability = 51 // Fine/coarse derivatives CapabilityStorageBuffer16BitAccess Capability = 4433 // 16-bit storage buffer access CapabilityUniformAndStorageBuffer16BitAccess Capability = 4434 // 16-bit uniform+storage buffer access CapabilityStorageInputOutput16 Capability = 4436 // 16-bit input/output CapabilityMultiView Capability = 4439 // MultiView extension CapabilityFragmentBarycentricKHR Capability = 5284 // Fragment barycentric CapabilityShaderNonUniform Capability = 5301 // NonUniform decorations CapabilityAtomicFloat32AddEXT Capability = 6033 // Float32 atomic add extension CapabilityDotProductInput4x8BitPacked Capability = 6018 // Required for packed 4x8 dot product CapabilityDotProduct Capability = 6019 // Required for integer dot product CapabilityGroupNonUniform Capability = 61 // Basic subgroup operations CapabilityGroupNonUniformVote Capability = 62 // subgroupAll, subgroupAny CapabilityGroupNonUniformArithmetic Capability = 63 // subgroupAdd, etc. CapabilityGroupNonUniformBallot Capability = 64 // subgroupBallot CapabilityGroupNonUniformShuffle Capability = 65 // subgroupShuffle CapabilityGroupNonUniformShuffleRel Capability = 66 // subgroupShuffleUp/Down CapabilityGroupNonUniformQuad Capability = 68 // quad operations CapabilityGeometry Capability = 2 // Geometry shader CapabilitySubgroupBallotKHR Capability = 4423 // KHR subgroup ballot CapabilityInt64ImageEXT Capability = 5016 // 64-bit image types (SPV_EXT_shader_image_int64) )
Common capabilities
type Decoration ¶
type Decoration uint32
Decoration represents a SPIR-V decoration.
const ( DecorationBlock Decoration = 2 DecorationColMajor Decoration = 5 DecorationRowMajor Decoration = 4 DecorationArrayStride Decoration = 6 DecorationMatrixStride Decoration = 7 DecorationBuiltIn Decoration = 11 DecorationFlat Decoration = 14 DecorationNoPerspective Decoration = 13 DecorationCentroid Decoration = 16 DecorationSample Decoration = 17 DecorationNonWritable Decoration = 24 DecorationNonReadable Decoration = 25 DecorationLocation Decoration = 30 DecorationIndex Decoration = 32 // For dual-source blending DecorationBinding Decoration = 33 DecorationDescriptorSet Decoration = 34 DecorationOffset Decoration = 35 DecorationNonUniform Decoration = 5300 // NonUniformEXT )
Common decorations
type ExecutionMode ¶
type ExecutionMode uint32
ExecutionMode represents a SPIR-V execution mode.
const ( ExecutionModeInvocations ExecutionMode = 0 ExecutionModeSpacingEqual ExecutionMode = 1 ExecutionModeSpacingFractionalEven ExecutionMode = 2 ExecutionModeSpacingFractionalOdd ExecutionMode = 3 ExecutionModeVertexOrderCw ExecutionMode = 4 ExecutionModeVertexOrderCcw ExecutionMode = 5 ExecutionModePixelCenterInteger ExecutionMode = 6 ExecutionModeOriginUpperLeft ExecutionMode = 7 ExecutionModeOriginLowerLeft ExecutionMode = 8 ExecutionModeEarlyFragmentTests ExecutionMode = 9 ExecutionModePointMode ExecutionMode = 10 ExecutionModeXfb ExecutionMode = 11 ExecutionModeDepthReplacing ExecutionMode = 12 ExecutionModeDepthGreater ExecutionMode = 14 ExecutionModeDepthLess ExecutionMode = 15 ExecutionModeDepthUnchanged ExecutionMode = 16 ExecutionModeLocalSize ExecutionMode = 17 ExecutionModeLocalSizeHint ExecutionMode = 18 ExecutionModeInputPoints ExecutionMode = 19 ExecutionModeInputLines ExecutionMode = 20 ExecutionModeInputLinesAdjacency ExecutionMode = 21 ExecutionModeTriangles ExecutionMode = 22 ExecutionModeInputTrianglesAdjacency ExecutionMode = 23 ExecutionModeQuads ExecutionMode = 24 ExecutionModeIsolines ExecutionMode = 25 ExecutionModeOutputVertices ExecutionMode = 26 ExecutionModeOutputPoints ExecutionMode = 27 ExecutionModeOutputLineStrip ExecutionMode = 28 ExecutionModeOutputTriangleStrip ExecutionMode = 29 ExecutionModeVecTypeHint ExecutionMode = 30 ExecutionModeContractionOff ExecutionMode = 31 ExecutionModeInitializer ExecutionMode = 33 ExecutionModeFinalizer ExecutionMode = 34 ExecutionModeSubgroupSize ExecutionMode = 35 ExecutionModeSubgroupsPerWorkgroup ExecutionMode = 36 ExecutionModeSubgroupsPerWorkgroupID ExecutionMode = 37 ExecutionModeLocalSizeID ExecutionMode = 38 ExecutionModeLocalSizeHintID ExecutionMode = 39 ExecutionModePostDepthCoverage ExecutionMode = 4446 ExecutionModeDenormPreserve ExecutionMode = 4459 ExecutionModeDenormFlushToZero ExecutionMode = 4460 ExecutionModeSignedZeroInfNanPreserve ExecutionMode = 4461 ExecutionModeRoundingModeRTE ExecutionMode = 4462 ExecutionModeRoundingModeRTZ ExecutionMode = 4463 )
Common execution modes
type ExecutionModel ¶
type ExecutionModel uint32
ExecutionModel represents a SPIR-V execution model.
const ( ExecutionModelVertex ExecutionModel = 0 ExecutionModelTessellationControl ExecutionModel = 1 ExecutionModelTessellationEvaluation ExecutionModel = 2 ExecutionModelGeometry ExecutionModel = 3 ExecutionModelFragment ExecutionModel = 4 ExecutionModelGLCompute ExecutionModel = 5 ExecutionModelKernel ExecutionModel = 6 )
Common execution models
type ExpressionEmitter ¶
type ExpressionEmitter struct {
// contains filtered or unexported fields
}
ExpressionEmitter handles expression emission within a function context.
type FunctionBuilder ¶
type FunctionBuilder struct {
Blocks []TerminatedBlock
Variables []Instruction // OpVariable instructions emitted in the first block only
Signature Instruction // OpFunction instruction
Parameters []Instruction // OpFunctionParameter instructions
}
FunctionBuilder collects terminated blocks for a single SPIR-V function. It mirrors the Rust naga Function struct: blocks own their instructions, and ToInstructions serializes them into a flat list.
func (*FunctionBuilder) Consume ¶
func (f *FunctionBuilder) Consume(block Block, terminator Instruction)
Consume finalizes a block by appending the given terminator instruction, then adds the resulting TerminatedBlock to the function.
func (*FunctionBuilder) ToInstructions ¶
func (f *FunctionBuilder) ToInstructions() []Instruction
ToInstructions serializes all blocks into a flat instruction list suitable for SPIR-V binary encoding. OpLabel is emitted from block.LabelID (NOT stored in Body). Local variables are emitted only in the first block. This matches Rust naga's Function::to_words() layout:
OpFunction OpFunctionParameter... OpLabel (block 0) OpVariable... (locals) body instructions... OpLabel (block 1) body instructions... ... OpFunctionEnd
type FunctionControl ¶
type FunctionControl uint32
FunctionControl represents a SPIR-V function control.
const ( FunctionControlNone FunctionControl = 0x0 FunctionControlInline FunctionControl = 0x1 FunctionControlDontInline FunctionControl = 0x2 FunctionControlPure FunctionControl = 0x4 FunctionControlConst FunctionControl = 0x8 )
Common function control flags
type ImageFormat ¶
type ImageFormat uint32
ImageFormat represents a SPIR-V image format.
const ( ImageFormatUnknown ImageFormat = 0 ImageFormatRgba32f ImageFormat = 1 ImageFormatRgba16f ImageFormat = 2 ImageFormatR32f ImageFormat = 3 ImageFormatRgba8 ImageFormat = 4 ImageFormatRgba8Snorm ImageFormat = 5 ImageFormatRg32f ImageFormat = 6 ImageFormatRg16f ImageFormat = 7 ImageFormatR11fG11fB10f ImageFormat = 8 ImageFormatR16f ImageFormat = 9 ImageFormatRgba16 ImageFormat = 10 ImageFormatRgb10A2 ImageFormat = 11 ImageFormatRg16 ImageFormat = 12 ImageFormatRg8 ImageFormat = 13 ImageFormatR16 ImageFormat = 14 ImageFormatR8 ImageFormat = 15 ImageFormatRgba16Snorm ImageFormat = 16 ImageFormatRg16Snorm ImageFormat = 17 ImageFormatRg8Snorm ImageFormat = 18 ImageFormatR16Snorm ImageFormat = 19 ImageFormatR8Snorm ImageFormat = 20 ImageFormatRgba32i ImageFormat = 21 ImageFormatRgba16i ImageFormat = 22 ImageFormatRgba8i ImageFormat = 23 ImageFormatR32i ImageFormat = 24 ImageFormatRg32i ImageFormat = 25 ImageFormatRg16i ImageFormat = 26 ImageFormatRg8i ImageFormat = 27 ImageFormatR16i ImageFormat = 28 ImageFormatR8i ImageFormat = 29 ImageFormatRgba32ui ImageFormat = 30 ImageFormatRgba16ui ImageFormat = 31 ImageFormatRgba8ui ImageFormat = 32 ImageFormatR32ui ImageFormat = 33 ImageFormatRgb10a2ui ImageFormat = 34 ImageFormatRg32ui ImageFormat = 35 ImageFormatRg16ui ImageFormat = 36 ImageFormatRg8ui ImageFormat = 37 ImageFormatR16ui ImageFormat = 38 ImageFormatR8ui ImageFormat = 39 ImageFormatR64ui ImageFormat = 40 ImageFormatR64i ImageFormat = 41 )
SPIR-V image format values (for OpTypeImage)
func StorageFormatToImageFormat ¶
func StorageFormatToImageFormat(format ir.StorageFormat) ImageFormat
StorageFormatToImageFormat converts an IR storage format to a SPIR-V image format.
type Instruction ¶
Instruction represents a SPIR-V instruction.
func (Instruction) Encode ¶
func (i Instruction) Encode() []uint32
Encode encodes the instruction to binary.
func (Instruction) WordCount ¶
func (i Instruction) WordCount() int
WordCount returns the total word count including the opcode word.
type InstructionBuilder ¶
type InstructionBuilder struct {
// contains filtered or unexported fields
}
InstructionBuilder builds SPIR-V instructions.
func NewInstructionBuilder ¶
func NewInstructionBuilder() *InstructionBuilder
NewInstructionBuilder creates a new instruction builder.
func (*InstructionBuilder) AddString ¶
func (b *InstructionBuilder) AddString(s string)
AddString adds a null-terminated UTF-8 string.
func (*InstructionBuilder) AddWord ¶
func (b *InstructionBuilder) AddWord(word uint32)
AddWord adds a word to the instruction.
func (*InstructionBuilder) Build ¶
func (b *InstructionBuilder) Build(opcode OpCode) Instruction
Build builds the instruction with the given opcode. It copies the words to a new slice so the builder can be safely reused. If the builder has an arena, words are allocated from the arena (amortized O(1)).
func (*InstructionBuilder) Reset ¶
func (b *InstructionBuilder) Reset()
Reset clears the builder for reuse without allocating.
type LoopContext ¶
type LoopContext struct {
ContinuingID uint32 // 0 = not in a continuing block
BreakID uint32 // 0 = not in a loop/switch
}
LoopContext provides break/continue targets for loop bodies. Passed by VALUE to ensure nested loops get isolated contexts, matching Rust's Copy semantics for the equivalent struct.
type LoopControl ¶
type LoopControl uint32
LoopControl flags for OpLoopMerge
const ( LoopControlNone LoopControl = 0x0 LoopControlUnroll LoopControl = 0x1 LoopControlDontUnroll LoopControl = 0x2 LoopControlDependencyInfinite LoopControl = 0x4 LoopControlDependencyLength LoopControl = 0x8 LoopControlMinIterations LoopControl = 0x10 LoopControlMaxIterations LoopControl = 0x20 LoopControlIterationMultiple LoopControl = 0x40 LoopControlPeelCount LoopControl = 0x80 LoopControlPartialCount LoopControl = 0x100 )
type MemoryModel ¶
type MemoryModel uint32
MemoryModel represents a SPIR-V memory model.
const ( MemoryModelSimple MemoryModel = 0 MemoryModelGLSL450 MemoryModel = 1 MemoryModelOpenCL MemoryModel = 2 MemoryModelVulkan MemoryModel = 3 )
Common memory models
type ModuleBuilder ¶
type ModuleBuilder struct {
// contains filtered or unexported fields
}
ModuleBuilder builds complete SPIR-V modules.
func NewModuleBuilder ¶
func NewModuleBuilder(version Version) *ModuleBuilder
NewModuleBuilder creates a new SPIR-V module builder.
func (*ModuleBuilder) AddAccessChain ¶
func (b *ModuleBuilder) AddAccessChain(resultType uint32, base uint32, indices ...uint32) uint32
AddAccessChain adds OpAccessChain.
func (*ModuleBuilder) AddBinaryOp ¶
func (b *ModuleBuilder) AddBinaryOp(opcode OpCode, resultType uint32, left uint32, right uint32) uint32
AddBinaryOp adds a binary operation instruction.
func (*ModuleBuilder) AddBranchConditional ¶
func (b *ModuleBuilder) AddBranchConditional(condition uint32, trueLabel uint32, falseLabel uint32)
AddBranchConditional adds OpBranchConditional.
func (*ModuleBuilder) AddCapability ¶
func (b *ModuleBuilder) AddCapability(capability Capability)
AddCapability adds a capability.
func (*ModuleBuilder) AddCompositeConstruct ¶
func (b *ModuleBuilder) AddCompositeConstruct(resultType uint32, constituents ...uint32) uint32
AddCompositeConstruct adds OpCompositeConstruct.
func (*ModuleBuilder) AddCompositeExtract ¶
func (b *ModuleBuilder) AddCompositeExtract(resultType uint32, composite uint32, indexes ...uint32) uint32
AddCompositeExtract adds OpCompositeExtract to extract a member from a composite value. Unlike OpAccessChain, this operates on values (not pointers) and indexes are literals.
func (*ModuleBuilder) AddConstant ¶
func (b *ModuleBuilder) AddConstant(typeID uint32, values ...uint32) uint32
AddConstant adds OpConstant.
func (*ModuleBuilder) AddConstantComposite ¶
func (b *ModuleBuilder) AddConstantComposite(typeID uint32, constituents ...uint32) uint32
AddConstantComposite adds OpConstantComposite.
func (*ModuleBuilder) AddConstantFloat32 ¶
func (b *ModuleBuilder) AddConstantFloat32(typeID uint32, value float32) uint32
AddConstantFloat32 adds a 32-bit float constant.
func (*ModuleBuilder) AddConstantFloat64 ¶
func (b *ModuleBuilder) AddConstantFloat64(typeID uint32, value float64) uint32
AddConstantFloat64 adds a 64-bit float constant.
func (*ModuleBuilder) AddConstantNull ¶
func (b *ModuleBuilder) AddConstantNull(typeID uint32) uint32
AddConstantNull adds OpConstantNull for a given type (all zeros/false/null).
func (*ModuleBuilder) AddCopyLogical ¶
func (b *ModuleBuilder) AddCopyLogical(resultType uint32, operand uint32) uint32
AddCopyLogical adds OpCopyLogical (opcode 400, SPIR-V 1.4+). Copies a composite value to a logically equivalent type with different decorations.
func (*ModuleBuilder) AddDecorate ¶
func (b *ModuleBuilder) AddDecorate(id uint32, decoration Decoration, params ...uint32)
AddDecorate adds a decoration.
func (*ModuleBuilder) AddEntryPoint ¶
func (b *ModuleBuilder) AddEntryPoint(execModel ExecutionModel, funcID uint32, name string, interfaces []uint32)
AddEntryPoint adds an entry point.
func (*ModuleBuilder) AddExecutionMode ¶
func (b *ModuleBuilder) AddExecutionMode(entryPoint uint32, mode ExecutionMode, params ...uint32)
AddExecutionMode adds an execution mode.
func (*ModuleBuilder) AddExtInst ¶
func (b *ModuleBuilder) AddExtInst(resultType uint32, extSet uint32, instruction uint32, operands ...uint32) uint32
AddExtInst adds OpExtInst (extended instruction).
func (*ModuleBuilder) AddExtInstImport ¶
func (b *ModuleBuilder) AddExtInstImport(name string) uint32
AddExtInstImport imports an extended instruction set.
func (*ModuleBuilder) AddExtension ¶
func (b *ModuleBuilder) AddExtension(name string)
AddExtension adds an extension.
func (*ModuleBuilder) AddFunction ¶
func (b *ModuleBuilder) AddFunction(funcType uint32, returnType uint32, control FunctionControl) uint32
AddFunction adds a function definition.
func (*ModuleBuilder) AddFunctionEnd ¶
func (b *ModuleBuilder) AddFunctionEnd()
AddFunctionEnd adds OpFunctionEnd.
func (*ModuleBuilder) AddFunctionParameter ¶
func (b *ModuleBuilder) AddFunctionParameter(typeID uint32) uint32
AddFunctionParameter adds a function parameter.
func (*ModuleBuilder) AddKill ¶
func (b *ModuleBuilder) AddKill()
AddKill adds OpKill (fragment shader discard).
func (*ModuleBuilder) AddLabelWithID ¶
func (b *ModuleBuilder) AddLabelWithID(id uint32)
AddLabelWithID adds a label with a pre-allocated ID.
func (*ModuleBuilder) AddLoad ¶
func (b *ModuleBuilder) AddLoad(resultType uint32, pointer uint32) uint32
AddLoad adds OpLoad.
func (*ModuleBuilder) AddLoopMerge ¶
func (b *ModuleBuilder) AddLoopMerge(mergeLabel uint32, continueLabel uint32, control LoopControl)
AddLoopMerge adds OpLoopMerge.
func (*ModuleBuilder) AddMemberDecorate ¶
func (b *ModuleBuilder) AddMemberDecorate(structID, member uint32, decoration Decoration, params ...uint32)
AddMemberDecorate adds a member decoration.
func (*ModuleBuilder) AddMemberName ¶
func (b *ModuleBuilder) AddMemberName(structID, member uint32, name string)
AddMemberName adds a debug member name.
func (*ModuleBuilder) AddName ¶
func (b *ModuleBuilder) AddName(id uint32, name string)
AddName adds a debug name.
func (*ModuleBuilder) AddReturnValue ¶
func (b *ModuleBuilder) AddReturnValue(valueID uint32)
AddReturnValue adds OpReturnValue.
func (*ModuleBuilder) AddSelect ¶
func (b *ModuleBuilder) AddSelect(resultType uint32, condition uint32, accept uint32, reject uint32) uint32
AddSelect adds OpSelect.
func (*ModuleBuilder) AddSelectionMerge ¶
func (b *ModuleBuilder) AddSelectionMerge(mergeLabel uint32, control SelectionControl)
AddSelectionMerge adds OpSelectionMerge.
func (*ModuleBuilder) AddStore ¶
func (b *ModuleBuilder) AddStore(pointer uint32, value uint32)
AddStore adds OpStore.
func (*ModuleBuilder) AddString ¶
func (b *ModuleBuilder) AddString(text string) uint32
AddString adds a debug string.
func (*ModuleBuilder) AddTypeArray ¶
func (b *ModuleBuilder) AddTypeArray(elementType uint32, length uint32) uint32
AddTypeArray adds OpTypeArray.
func (*ModuleBuilder) AddTypeBool ¶
func (b *ModuleBuilder) AddTypeBool() uint32
AddTypeBool adds OpTypeBool.
func (*ModuleBuilder) AddTypeFloat ¶
func (b *ModuleBuilder) AddTypeFloat(width uint32) uint32
AddTypeFloat adds OpTypeFloat.
func (*ModuleBuilder) AddTypeFunction ¶
func (b *ModuleBuilder) AddTypeFunction(returnType uint32, paramTypes ...uint32) uint32
AddTypeFunction adds OpTypeFunction.
func (*ModuleBuilder) AddTypeInt ¶
func (b *ModuleBuilder) AddTypeInt(width uint32, signed bool) uint32
AddTypeInt adds OpTypeInt.
func (*ModuleBuilder) AddTypeMatrix ¶
func (b *ModuleBuilder) AddTypeMatrix(columnType uint32, columnCount uint32) uint32
AddTypeMatrix adds OpTypeMatrix.
func (*ModuleBuilder) AddTypePointer ¶
func (b *ModuleBuilder) AddTypePointer(storageClass StorageClass, baseType uint32) uint32
AddTypePointer adds OpTypePointer.
func (*ModuleBuilder) AddTypeRuntimeArray ¶
func (b *ModuleBuilder) AddTypeRuntimeArray(elementType uint32) uint32
AddTypeRuntimeArray adds OpTypeRuntimeArray for storage buffer runtime-sized arrays.
func (*ModuleBuilder) AddTypeSampler ¶
func (b *ModuleBuilder) AddTypeSampler() uint32
AddTypeSampler adds OpTypeSampler.
func (*ModuleBuilder) AddTypeStruct ¶
func (b *ModuleBuilder) AddTypeStruct(memberTypes ...uint32) uint32
AddTypeStruct adds OpTypeStruct.
func (*ModuleBuilder) AddTypeVector ¶
func (b *ModuleBuilder) AddTypeVector(componentType uint32, count uint32) uint32
AddTypeVector adds OpTypeVector.
func (*ModuleBuilder) AddTypeVoid ¶
func (b *ModuleBuilder) AddTypeVoid() uint32
AddTypeVoid adds OpTypeVoid.
func (*ModuleBuilder) AddUnaryOp ¶
func (b *ModuleBuilder) AddUnaryOp(opcode OpCode, resultType uint32, operand uint32) uint32
AddUnaryOp adds a unary operation instruction.
func (*ModuleBuilder) AddUnreachable ¶
func (b *ModuleBuilder) AddUnreachable()
AddUnreachable adds OpUnreachable (terminator for unreachable basic blocks).
func (*ModuleBuilder) AddVariable ¶
func (b *ModuleBuilder) AddVariable(pointerType uint32, storageClass StorageClass) uint32
AddVariable adds OpVariable.
func (*ModuleBuilder) AddVariableWithInit ¶
func (b *ModuleBuilder) AddVariableWithInit(pointerType uint32, storageClass StorageClass, initID uint32) uint32
AddVariableWithInit adds OpVariable with initializer.
func (*ModuleBuilder) AddVectorExtractDynamic ¶
func (b *ModuleBuilder) AddVectorExtractDynamic(resultType uint32, vector uint32, index uint32) uint32
AddVectorExtractDynamic adds OpVectorExtractDynamic to extract an element from a vector using a dynamic (runtime) index. Unlike OpCompositeExtract, the index is an ID not a literal.
func (*ModuleBuilder) AddVectorShuffle ¶
func (b *ModuleBuilder) AddVectorShuffle(resultType uint32, vec1 uint32, vec2 uint32, components []uint32) uint32
AddVectorShuffle adds OpVectorShuffle for vector swizzle operations.
func (*ModuleBuilder) AllocID ¶
func (b *ModuleBuilder) AllocID() uint32
AllocID allocates a new SPIR-V ID.
func (*ModuleBuilder) Build ¶
func (b *ModuleBuilder) Build() []byte
Build generates the final SPIR-V binary.
func (*ModuleBuilder) RequireVersion ¶
func (b *ModuleBuilder) RequireVersion(minVersion Version)
RequireVersion bumps the module's SPIR-V version to at least minVersion. If the current version is already >= minVersion, this is a no-op.
func (*ModuleBuilder) Reset ¶
func (b *ModuleBuilder) Reset(version Version)
Reset clears all state in the ModuleBuilder without deallocating. This allows reuse of the builder across compilations, avoiding repeated allocation of instruction slices and the word arena.
func (*ModuleBuilder) SetMemoryModel ¶
func (b *ModuleBuilder) SetMemoryModel(addressing AddressingModel, memory MemoryModel)
SetMemoryModel sets the memory model.
type OpCode ¶
type OpCode uint16
OpCode represents a SPIR-V opcode.
const ( OpSampledImage OpCode = 86 OpImageSampleImplicitLod OpCode = 87 OpImageSampleExplicitLod OpCode = 88 OpImageSampleDrefImplicitLod OpCode = 89 OpImageSampleDrefExplicitLod OpCode = 90 OpImageSampleProjImplicitLod OpCode = 91 OpImageSampleProjExplicitLod OpCode = 92 OpImageSampleProjDrefImplicit OpCode = 93 OpImageSampleProjDrefExplicit OpCode = 94 OpImageFetch OpCode = 95 OpImageGather OpCode = 96 OpImageDrefGather OpCode = 97 OpImageRead OpCode = 98 OpImageWrite OpCode = 99 OpImageTexelPointer OpCode = 60 OpImageQuerySizeLod OpCode = 103 OpImageQuerySize OpCode = 104 OpImageQueryLod OpCode = 105 OpImageQueryLevels OpCode = 106 OpImageQuerySamples OpCode = 107 )
Image instruction opcodes
const ( OpNop OpCode = 0 OpSource OpCode = 3 OpString OpCode = 7 OpName OpCode = 5 OpMemberName OpCode = 6 OpExtInstImport OpCode = 11 OpMemoryModel OpCode = 14 OpEntryPoint OpCode = 15 OpExecutionMode OpCode = 16 OpCapability OpCode = 17 OpTypeVoid OpCode = 19 OpTypeBool OpCode = 20 OpTypeInt OpCode = 21 OpTypeFloat OpCode = 22 OpTypeVector OpCode = 23 OpTypeMatrix OpCode = 24 OpTypeArray OpCode = 28 OpTypeRuntimeArray OpCode = 29 OpTypeStruct OpCode = 30 OpTypePointer OpCode = 32 OpTypeFunction OpCode = 33 OpConstant OpCode = 43 OpConstantComposite OpCode = 44 OpConstantNull OpCode = 46 OpFunction OpCode = 54 OpFunctionParameter OpCode = 55 OpFunctionEnd OpCode = 56 OpFunctionCall OpCode = 57 OpVariable OpCode = 59 OpLoad OpCode = 61 OpStore OpCode = 62 OpAccessChain OpCode = 65 OpDecorate OpCode = 71 OpMemberDecorate OpCode = 72 OpLabel OpCode = 248 OpBranch OpCode = 249 OpPhi OpCode = 245 OpReturn OpCode = 253 OpReturnValue OpCode = 254 OpUnreachable OpCode = 255 )
Common opcodes
const ( OpFNegate OpCode = 127 // Float negation OpSNegate OpCode = 126 // Signed integer negation OpFAdd OpCode = 129 // Float addition OpFSub OpCode = 131 // Float subtraction OpFMul OpCode = 133 // Float multiplication OpUDiv OpCode = 134 // Unsigned integer division OpSDiv OpCode = 135 // Signed integer division OpFDiv OpCode = 136 // Float division OpUMod OpCode = 137 // Unsigned integer modulo OpSRem OpCode = 138 // Signed integer remainder OpSMod OpCode = 139 // Signed integer modulo OpFRem OpCode = 140 // Float remainder OpFMod OpCode = 141 // Float modulo OpVectorTimesScalar OpCode = 142 // Vector-scalar float multiplication OpMatrixTimesScalar OpCode = 143 // Matrix-scalar float multiplication OpVectorTimesMatrix OpCode = 144 // Vector-matrix multiplication OpMatrixTimesVector OpCode = 145 // Matrix-vector multiplication OpMatrixTimesMatrix OpCode = 146 // Matrix-matrix multiplication OpIAdd OpCode = 128 // Integer addition OpISub OpCode = 130 // Integer subtraction OpIMul OpCode = 132 // Integer multiplication )
Arithmetic opcodes
const ( OpFOrdEqual OpCode = 180 // Float ordered equal OpFOrdNotEqual OpCode = 182 // Float ordered not equal OpFOrdLessThan OpCode = 184 // Float ordered less than OpFOrdGreaterThan OpCode = 186 // Float ordered greater than OpFOrdLessThanEqual OpCode = 188 // Float ordered less than or equal OpFOrdGreaterThanEqual OpCode = 190 // Float ordered greater than or equal OpIEqual OpCode = 170 // Integer equal OpINotEqual OpCode = 171 // Integer not equal OpSLessThan OpCode = 177 // Signed integer less than OpSLessThanEqual OpCode = 179 // Signed integer less than or equal OpSGreaterThan OpCode = 173 // Signed integer greater than OpSGreaterThanEqual OpCode = 175 // Signed integer greater than or equal OpULessThan OpCode = 176 // Unsigned integer less than OpULessThanEqual OpCode = 178 // Unsigned integer less than or equal OpUGreaterThan OpCode = 172 // Unsigned integer greater than OpUGreaterThanEqual OpCode = 174 // Unsigned integer greater than or equal )
Comparison opcodes
const ( OpLogicalEqual OpCode = 164 // Logical equal OpLogicalNotEqual OpCode = 165 // Logical not equal OpLogicalOr OpCode = 166 // Logical or OpLogicalAnd OpCode = 167 // Logical and OpLogicalNot OpCode = 168 // Logical not OpSelect OpCode = 169 // Select between values OpNot OpCode = 200 // Bitwise not OpAny OpCode = 154 // True if any component of boolean vector is true OpAll OpCode = 155 // True if all components of boolean vector are true OpIsNan OpCode = 156 // True if value is NaN OpIsInf OpCode = 157 // True if value is Inf )
Logical opcodes
const ( OpVectorExtractDynamic OpCode = 77 // Extract from vector with dynamic index OpVectorShuffle OpCode = 79 // Shuffle vector components OpCompositeConstruct OpCode = 80 // Construct composite OpCompositeExtract OpCode = 81 // Extract from composite )
Composite opcodes
const ( OpShiftRightLogical OpCode = 194 // Shift right logical OpShiftRightArithmetic OpCode = 195 // Shift right arithmetic OpShiftLeftLogical OpCode = 196 // Shift left logical OpBitwiseOr OpCode = 197 // Bitwise OR OpBitwiseXor OpCode = 198 // Bitwise XOR OpBitwiseAnd OpCode = 199 // Bitwise AND OpBitFieldInsert OpCode = 201 // Insert bit field OpBitFieldSExtract OpCode = 202 // Extract signed bit field OpBitFieldUExtract OpCode = 203 // Extract unsigned bit field OpBitReverse OpCode = 204 // Reverse bits OpBitCount OpCode = 205 // Count set bits )
Bitwise opcodes
const ( OpSelectionMerge OpCode = 247 // Selection merge point OpLoopMerge OpCode = 246 // Loop merge point OpBranchConditional OpCode = 250 // Conditional branch OpSwitch OpCode = 251 // Switch statement OpKill OpCode = 252 // Fragment discard )
Control flow opcodes
const ( OpDPdx OpCode = 207 // Derivative in X OpDPdy OpCode = 208 // Derivative in Y OpFwidth OpCode = 209 // Sum of absolute derivatives OpDPdxFine OpCode = 210 // Fine derivative in X OpDPdyFine OpCode = 211 // Fine derivative in Y OpFwidthFine OpCode = 212 // Fine fwidth OpDPdxCoarse OpCode = 213 // Coarse derivative in X OpDPdyCoarse OpCode = 214 // Coarse derivative in Y OpFwidthCoarse OpCode = 215 // Coarse fwidth )
Derivative opcodes
const ( OpConvertFToU OpCode = 109 // Float to unsigned int OpConvertFToS OpCode = 110 // Float to signed int OpConvertSToF OpCode = 111 // Signed int to float OpConvertUToF OpCode = 112 // Unsigned int to float OpUConvert OpCode = 113 // Unsigned int width conversion OpSConvert OpCode = 114 // Signed int width conversion OpFConvert OpCode = 115 // Float width conversion OpQuantizeToF16 OpCode = 116 // Quantize float to f16 precision OpBitcast OpCode = 124 // Bitcast between types of same width )
Conversion opcodes
const ( OpAtomicLoad OpCode = 227 // Atomic load OpAtomicStore OpCode = 228 // Atomic store OpAtomicExchange OpCode = 229 // Atomic exchange OpAtomicCompareExch OpCode = 230 // Atomic compare-exchange OpAtomicIIncrement OpCode = 232 // Atomic integer increment OpAtomicIDecrement OpCode = 233 // Atomic integer decrement OpAtomicIAdd OpCode = 234 // Atomic integer add OpAtomicFAddEXT OpCode = 6035 // Atomic float add (SPV_EXT_shader_atomic_float_add) OpAtomicISub OpCode = 235 // Atomic integer subtract OpAtomicSMin OpCode = 236 // Atomic signed min OpAtomicUMin OpCode = 237 // Atomic unsigned min OpAtomicSMax OpCode = 238 // Atomic signed max OpAtomicUMax OpCode = 239 // Atomic unsigned max OpAtomicAnd OpCode = 240 // Atomic bitwise and OpAtomicOr OpCode = 241 // Atomic bitwise or OpAtomicXor OpCode = 242 // Atomic bitwise xor )
Atomic operation opcodes
const ( OpControlBarrier OpCode = 224 // Control barrier (execution + memory) OpMemoryBarrier OpCode = 225 // Memory barrier only )
Barrier opcodes
const ( OpGroupNonUniformElect OpCode = 333 OpGroupNonUniformAll OpCode = 334 OpGroupNonUniformAny OpCode = 335 OpGroupNonUniformAllEqual OpCode = 336 OpGroupNonUniformBroadcast OpCode = 337 OpGroupNonUniformBroadcastFirst OpCode = 338 OpGroupNonUniformBallot OpCode = 339 OpGroupNonUniformInverseBallot OpCode = 340 OpGroupNonUniformBallotBitExtract OpCode = 341 OpGroupNonUniformBallotBitCount OpCode = 342 OpGroupNonUniformBallotFindLSB OpCode = 343 OpGroupNonUniformBallotFindMSB OpCode = 344 OpGroupNonUniformShuffle OpCode = 345 OpGroupNonUniformShuffleXor OpCode = 346 OpGroupNonUniformShuffleUp OpCode = 347 OpGroupNonUniformShuffleDown OpCode = 348 OpGroupNonUniformIAdd OpCode = 349 OpGroupNonUniformFAdd OpCode = 350 OpGroupNonUniformIMul OpCode = 351 OpGroupNonUniformFMul OpCode = 352 OpGroupNonUniformSMin OpCode = 353 OpGroupNonUniformUMin OpCode = 354 OpGroupNonUniformFMin OpCode = 355 OpGroupNonUniformSMax OpCode = 356 OpGroupNonUniformUMax OpCode = 357 OpGroupNonUniformFMax OpCode = 358 OpGroupNonUniformBitwiseAnd OpCode = 359 OpGroupNonUniformBitwiseOr OpCode = 360 OpGroupNonUniformBitwiseXor OpCode = 361 OpGroupNonUniformLogicalAnd OpCode = 362 OpGroupNonUniformLogicalOr OpCode = 363 OpGroupNonUniformLogicalXor OpCode = 364 OpGroupNonUniformQuadBroadcast OpCode = 365 OpGroupNonUniformQuadSwap OpCode = 366 )
Subgroup opcodes (SPV_KHR_subgroup_vote, SPV_KHR_subgroup_ballot, etc.)
const OpArrayLength OpCode = 68
OpArrayLength gets the length of a runtime-sized array in a storage buffer struct. Result type must be u32. Operands: struct pointer, member index.
const OpConstantFalse OpCode = 42
OpConstantFalse represents OpConstantFalse opcode.
const OpConstantTrue OpCode = 41
OpConstantTrue represents OpConstantTrue opcode.
const OpCopyLogical OpCode = 400
OpCopyLogical performs a logical copy between composite types with different decorations (e.g., layout-free Workgroup type → decorated Storage type). Requires SPIR-V 1.4+. Both types must be logically equivalent (same structure).
const OpDot OpCode = 148
OpDot represents OpDot opcode (dot product).
const (
OpExtInst OpCode = 12 // Extended instruction
)
Extended instruction set opcodes
const OpExtension OpCode = 10
OpExtension represents OpExtension opcode.
const OpTranspose OpCode = 84
OpTranspose represents OpTranspose opcode (matrix transpose).
const OpTypeAccelerationStructureKHR OpCode = 5341
OpTypeAccelerationStructureKHR represents OpTypeAccelerationStructureKHR.
const OpTypeImage OpCode = 25
OpTypeImage represents OpTypeImage opcode.
const OpTypeRayQueryKHR OpCode = 4472
OpTypeRayQueryKHR represents OpTypeRayQueryKHR.
const OpTypeSampledImage OpCode = 27
OpTypeSampledImage represents OpTypeSampledImage opcode.
const OpTypeSampler OpCode = 26
OpTypeSampler represents OpTypeSampler 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
// types used in entry point inputs/outputs. When true, f16 I/O uses native
// 16-bit types; when false, a polyfill converts to/from f32.
UseStorageInputOutput16 bool
// ForcePointSize adds a BuiltIn PointSize output variable with value 1.0
// to every vertex shader entry point. Required by some Vulkan drivers.
ForcePointSize bool
// AdjustCoordinateSpace flips the Y coordinate of Position built-in outputs
// in vertex shaders to match Vulkan's coordinate system (Y pointing down).
AdjustCoordinateSpace bool
// ForceLoopBounding inserts a decrementing counter at every loop header
// that breaks when the counter reaches zero. This prevents infinite loops
// from hanging the GPU. Matches Rust naga's force_loop_bounding option
// (default true). The counter uses a vec2<u32> to simulate 64-bit range.
ForceLoopBounding bool
// BoundsCheckPolicies controls how out-of-bounds image accesses are handled.
BoundsCheckPolicies BoundsCheckPolicies
// CapabilitiesAvailable limits which capabilities may be used. When nil,
// all capabilities are available (the default). When non-nil, only
// capabilities present in the set may be used; others trigger polyfills.
// This matches Rust naga's Options::capabilities field.
CapabilitiesAvailable map[Capability]struct{}
// RayQueryInitTracking enables initialization tracking for ray queries.
// When true (default), ray query helper functions include validation checks
// that track whether the query was properly initialized before proceed/get.
// When false, validation checks are skipped and helper functions branch
// unconditionally. Matches Rust naga's ray_query_initialization_tracking.
RayQueryInitTracking bool
}
Options configures SPIR-V generation.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns sensible default options.
type SelectionControl ¶
type SelectionControl uint32
SelectionControl flags for OpSelectionMerge
const ( SelectionControlNone SelectionControl = 0x0 SelectionControlFlatten SelectionControl = 0x1 SelectionControlDontFlatten SelectionControl = 0x2 )
type StorageClass ¶
type StorageClass uint32
StorageClass represents a SPIR-V storage class.
const ( StorageClassUniformConstant StorageClass = 0 StorageClassInput StorageClass = 1 StorageClassUniform StorageClass = 2 StorageClassOutput StorageClass = 3 StorageClassWorkgroup StorageClass = 4 StorageClassCrossWorkgroup StorageClass = 5 StorageClassPrivate StorageClass = 6 StorageClassFunction StorageClass = 7 StorageClassGeneric StorageClass = 8 StorageClassPushConstant StorageClass = 9 StorageClassAtomicCounter StorageClass = 10 StorageClassImage StorageClass = 11 StorageClassStorageBuffer StorageClass = 12 StorageClassTaskPayloadWorkgroupEXT StorageClass = 5328 )
Common storage classes
type TerminatedBlock ¶
type TerminatedBlock struct {
LabelID uint32
Body []Instruction // includes terminator as last element
}
TerminatedBlock is a finalized basic block whose Body includes the terminator as its last instruction.