Documentation
¶
Index ¶
- Constants
- Variables
- func DefaultBoundsCheckPolicies() backend.BoundsCheckPolicies
- type AttributeMapping
- type BindExternalTextureTarget
- type BindSamplerTarget
- type BindTarget
- type EntryPointResources
- type InlineSampler
- type Options
- type PipelineOptions
- type SamplerAddress
- type SamplerBorderColor
- type SamplerCompareFunc
- type SamplerCoord
- type SamplerFilter
- type StorageAccess
- type TranslationInfo
- type Version
- type VertexBufferMapping
- type VertexBufferStepMode
- type VertexFormat
- type Writer
Constants ¶
const Namespace = "metal::"
Namespace is the MSL metal namespace prefix.
Variables ¶
var ( Version1_0 = Version{Major: 1, Minor: 0} Version1_2 = Version{Major: 1, Minor: 2} Version2_0 = Version{Major: 2, Minor: 0} Version2_1 = Version{Major: 2, Minor: 1} Version2_2 = Version{Major: 2, Minor: 2} Version2_3 = Version{Major: 2, Minor: 3} Version2_4 = Version{Major: 2, Minor: 4} Version3_0 = Version{Major: 3, Minor: 0} Version3_1 = Version{Major: 3, Minor: 1} Version4_0 = Version{Major: 4, Minor: 0} )
Common MSL versions.
Functions ¶
func DefaultBoundsCheckPolicies ¶
func DefaultBoundsCheckPolicies() backend.BoundsCheckPolicies
DefaultBoundsCheckPolicies returns ReadZeroSkipWrite on every field, the policies of DefaultOptions.
Types ¶
type AttributeMapping ¶
type AttributeMapping struct {
ShaderLocation uint32
Offset uint32
Format VertexFormat
}
AttributeMapping maps a vertex attribute to a shader location.
type BindExternalTextureTarget ¶
BindExternalTextureTarget specifies the Metal binding slots for an external texture global variable. External textures are lowered to 3 texture planes and a constant buffer of NagaExternalTextureParams.
type BindSamplerTarget ¶
type BindSamplerTarget struct {
// IsInline indicates the sampler is an inline (constexpr) sampler.
IsInline bool
// Slot is the binding slot (for resource samplers) or index into
// Options.InlineSamplers (for inline samplers).
Slot uint8
}
BindSamplerTarget specifies how a sampler is bound.
type BindTarget ¶
type BindTarget struct {
// Buffer is the buffer binding slot. Nil if not bound as buffer.
Buffer *uint8
// Texture is the texture binding slot. Nil if not bound as texture.
Texture *uint8
// Sampler is the sampler binding slot. Nil if not bound as sampler.
Sampler *BindSamplerTarget
// ExternalTexture is the binding for external texture planes + params.
ExternalTexture *BindExternalTextureTarget
// Mutable indicates if this is a read-write resource.
Mutable bool
}
BindTarget specifies the Metal binding slots for a resource.
type EntryPointResources ¶
type EntryPointResources struct {
// Resources maps (group, binding) pairs to Metal bind targets.
Resources map[ir.ResourceBinding]BindTarget
// SizesBuffer is the buffer slot for runtime array sizes.
// Required when using runtime-sized arrays.
SizesBuffer *uint8
// ImmediatesBuffer is the buffer slot for immediate data.
// Nil if immediate data is not used.
ImmediatesBuffer *uint8
}
EntryPointResources maps WGSL resource bindings to Metal binding slots.
type InlineSampler ¶
type InlineSampler struct {
Coord SamplerCoord
Address [3]SamplerAddress
BorderColor SamplerBorderColor
MagFilter SamplerFilter
MinFilter SamplerFilter
MipFilter *SamplerFilter // nil if not set
CompareFunc SamplerCompareFunc
}
InlineSampler defines an inline (constexpr) sampler in Metal.
type Options ¶
type Options struct {
// LangVersion is the target MSL version.
// Defaults to Version2_1 if zero.
LangVersion Version
// PerEntryPointMap maps entry point names to their resource bindings.
// If nil, bindings are auto-generated.
PerEntryPointMap map[string]EntryPointResources
// InlineSamplers defines constexpr samplers to be inlined into the code.
// Referenced by BindSamplerTarget.Slot when IsInline is true.
InlineSamplers []InlineSampler
// BoundsCheckPolicies controls bounds checking behavior.
BoundsCheckPolicies backend.BoundsCheckPolicies
// ZeroInitializeWorkgroupMemory is how compute entry points zero the
// threadgroup variables they use: Polyfill (zero) or None; Native is an
// error.
ZeroInitializeWorkgroupMemory backend.ZeroInitializeWorkgroupMemoryMode
// ForceLoopBounding adds loop iteration limits to prevent infinite loops.
// Recommended for untrusted shaders.
ForceLoopBounding bool
// FakeMissingBindings generates placeholder bindings for resources
// that are referenced but not in the PerEntryPointMap.
FakeMissingBindings bool
// AllowAndForcePointSize forces point size output for vertex shaders.
// When true, vertex output structs get an extra _point_size [[point_size]]
// member, and the entry point return initializer includes 1.0.
// Required for point primitive topologies.
AllowAndForcePointSize bool
// VertexPullingTransform enables vertex pulling transformation.
// When true, vertex shaders receive raw buffer data instead of assembled
// vertex attributes. The shader reads bytes from vertex buffers and
// unpacks attribute data manually with bounds checking.
VertexPullingTransform bool
// VertexBufferMappings describes the vertex buffer layout for vertex pulling.
// Each entry describes one vertex buffer with its stride, step mode, and attributes.
VertexBufferMappings []VertexBufferMapping
// ClampFragDepth clamps the depth a fragment entry point writes to the
// range at byte ClampFragDepth.Offset of its immediates buffer (see the
// msl package).
ClampFragDepth *backend.ClampFragDepth
// FixedSampleMask is the render pipeline's sample mask, which fragment
// entry points apply themselves (see the msl package).
FixedSampleMask *uint32
}
Options configures MSL code generation.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns sensible default options for MSL generation.
type PipelineOptions ¶
type PipelineOptions struct {
// EntryPoint specifies which entry point to compile.
// If nil, all entry points are compiled.
EntryPoint *backend.EntryPointSelector
// AllowAndForcePointSize forces point size output for vertex shaders.
// Required for point primitive topology.
AllowAndForcePointSize bool
}
PipelineOptions configures options specific to a single pipeline/entry point.
type SamplerAddress ¶
type SamplerAddress int
SamplerAddress specifies the addressing mode for an inline sampler.
const ( SamplerAddressRepeat SamplerAddress = iota SamplerAddressMirroredRepeat SamplerAddressClampToEdge SamplerAddressClampToZero SamplerAddressClampToBorder )
type SamplerBorderColor ¶
type SamplerBorderColor int
SamplerBorderColor specifies the border color for an inline sampler.
const ( SamplerBorderColorTransparentBlack SamplerBorderColor = iota SamplerBorderColorOpaqueBlack SamplerBorderColorOpaqueWhite )
type SamplerCompareFunc ¶
type SamplerCompareFunc int
SamplerCompareFunc specifies the comparison function for an inline sampler.
const ( SamplerCompareFuncNever SamplerCompareFunc = iota SamplerCompareFuncLess SamplerCompareFuncLessEqual SamplerCompareFuncGreater SamplerCompareFuncGreaterEqual SamplerCompareFuncEqual SamplerCompareFuncNotEqual SamplerCompareFuncAlways )
type SamplerCoord ¶
type SamplerCoord int
SamplerCoord specifies the coordinate system for an inline sampler.
const ( SamplerCoordNormalized SamplerCoord = iota SamplerCoordPixel )
type SamplerFilter ¶
type SamplerFilter int
SamplerFilter specifies the filtering mode for an inline sampler.
const ( SamplerFilterNearest SamplerFilter = iota SamplerFilterLinear )
type StorageAccess ¶
type StorageAccess uint8
StorageAccess represents storage access flags for images.
type TranslationInfo ¶
type TranslationInfo struct {
// EntryPointNames maps original entry point names to generated MSL names.
EntryPointNames map[string]string
// RequiresSizesBuffer indicates if a sizes buffer is needed for
// runtime-sized arrays.
RequiresSizesBuffer bool
}
TranslationInfo contains information about the compiled MSL output.
func Compile ¶
Compile generates MSL source code from an IR module. Returns the MSL source as a string and translation info, or an error.
func CompileWithPipeline ¶
func CompileWithPipeline(module *ir.Module, options Options, pipeline PipelineOptions) (string, TranslationInfo, error)
CompileWithPipeline generates MSL source code with pipeline-specific options.
type Version ¶
Version represents an MSL language version.
type VertexBufferMapping ¶
type VertexBufferMapping struct {
ID uint32
Stride uint32
StepMode VertexBufferStepMode
Attributes []AttributeMapping
}
VertexBufferMapping describes a vertex buffer and its attributes.
type VertexBufferStepMode ¶
type VertexBufferStepMode int
VertexBufferStepMode defines how to advance the data in vertex buffers.
const ( VertexStepModeConstant VertexBufferStepMode = 0 VertexStepModeByVertex VertexBufferStepMode = 1 VertexStepModeByInstance VertexBufferStepMode = 2 )
type VertexFormat ¶
type VertexFormat int
VertexFormat describes the format of a vertex attribute. Matches Rust naga's back::msl::VertexFormat enum.
const ( VertexFormatUint8 VertexFormat = 0 VertexFormatUint8x2 VertexFormat = 1 VertexFormatUint8x4 VertexFormat = 2 VertexFormatSint8 VertexFormat = 3 VertexFormatSint8x2 VertexFormat = 4 VertexFormatSint8x4 VertexFormat = 5 VertexFormatUnorm8 VertexFormat = 6 VertexFormatUnorm8x2 VertexFormat = 7 VertexFormatUnorm8x4 VertexFormat = 8 VertexFormatSnorm8 VertexFormat = 9 VertexFormatSnorm8x2 VertexFormat = 10 VertexFormatSnorm8x4 VertexFormat = 11 VertexFormatUint16 VertexFormat = 12 VertexFormatUint16x2 VertexFormat = 13 VertexFormatUint16x4 VertexFormat = 14 VertexFormatSint16 VertexFormat = 15 VertexFormatSint16x2 VertexFormat = 16 VertexFormatSint16x4 VertexFormat = 17 VertexFormatUnorm16 VertexFormat = 18 VertexFormatUnorm16x2 VertexFormat = 19 VertexFormatUnorm16x4 VertexFormat = 20 VertexFormatSnorm16 VertexFormat = 21 VertexFormatSnorm16x2 VertexFormat = 22 VertexFormatSnorm16x4 VertexFormat = 23 VertexFormatFloat16 VertexFormat = 24 VertexFormatFloat16x2 VertexFormat = 25 VertexFormatFloat16x4 VertexFormat = 26 VertexFormatFloat32 VertexFormat = 27 VertexFormatFloat32x2 VertexFormat = 28 VertexFormatFloat32x3 VertexFormat = 29 VertexFormatFloat32x4 VertexFormat = 30 VertexFormatUint32 VertexFormat = 31 VertexFormatUint32x2 VertexFormat = 32 VertexFormatUint32x3 VertexFormat = 33 VertexFormatUint32x4 VertexFormat = 34 VertexFormatSint32 VertexFormat = 35 VertexFormatSint32x2 VertexFormat = 36 VertexFormatSint32x3 VertexFormat = 37 VertexFormatSint32x4 VertexFormat = 38 VertexFormatUnorm10_10_10_2 VertexFormat = 43 VertexFormatUnorm8x4Bgra VertexFormat = 44 VertexFormatSnorm10_10_10_2 VertexFormat = 45 )
type Writer ¶
type Writer struct {
textutil.IndentWriter // provides Out, Indent, WriteLine, WriteIndent, PushIndent, PopIndent
// contains filtered or unexported fields
}
Writer generates MSL source code from IR.