Help us shape the future of Go! Take the 2026 Go Developer Survey

codegen

package
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Desktop OpenGL versions
	Version330 = Version{Major: 3, Minor: 30, ES: false} // OpenGL 3.3 Core
	Version400 = Version{Major: 4, Minor: 0, ES: false}  // OpenGL 4.0
	Version410 = Version{Major: 4, Minor: 10, ES: false} // OpenGL 4.1
	Version420 = Version{Major: 4, Minor: 20, ES: false} // OpenGL 4.2
	Version430 = Version{Major: 4, Minor: 30, ES: false} // OpenGL 4.3 (compute shaders)
	Version450 = Version{Major: 4, Minor: 50, ES: false} // OpenGL 4.5
	Version460 = Version{Major: 4, Minor: 60, ES: false} // OpenGL 4.6

	// OpenGL ES / WebGL versions
	VersionES300 = Version{Major: 3, Minor: 0, ES: true}  // ES 3.0 / WebGL 2.0
	VersionES310 = Version{Major: 3, Minor: 10, ES: true} // ES 3.1 (compute shaders)
	VersionES320 = Version{Major: 3, Minor: 20, ES: true} // ES 3.2
)

Common GLSL versions.

Functions

This section is empty.

Types

type BindingMapKey

type BindingMapKey struct {
	Group   uint32
	Binding uint32
}

BindingMapKey identifies a resource binding for the BindingMap.

type Features

type Features uint32

Features represents required GLSL features as bitflags. Matches Rust naga's back::glsl::Features.

const (
	FeatureBufferStorage         Features = 1 << 0
	FeatureArrayOfArrays         Features = 1 << 1
	FeatureDoubleType            Features = 1 << 2
	FeatureFullImageFormats      Features = 1 << 3
	FeatureMultisampledTextures  Features = 1 << 4
	FeatureMultisampledTexArrays Features = 1 << 5
	FeatureCubeTexturesArray     Features = 1 << 6
	FeatureComputeShader         Features = 1 << 7
	FeatureImageLoadStore        Features = 1 << 8
	FeatureConservativeDepth     Features = 1 << 9
	FeatureNoPerspective         Features = 1 << 11
	FeatureSampleQualifier       Features = 1 << 12
	FeatureClipDistance          Features = 1 << 13
	FeatureCullDistance          Features = 1 << 14
	FeatureSampleVariables       Features = 1 << 15
	FeatureDynamicArraySize      Features = 1 << 16
	FeatureMultiView             Features = 1 << 17
	FeatureTextureSamples        Features = 1 << 18
	FeatureTextureLevels         Features = 1 << 19
	FeatureImageSize             Features = 1 << 20
	FeatureDualSourceBlending    Features = 1 << 21
	FeatureInstanceIndex         Features = 1 << 22
	FeatureTextureShadowLod      Features = 1 << 23
	FeatureSubgroupOperations    Features = 1 << 24
	FeatureTextureAtomics        Features = 1 << 25
	FeatureShaderBarycentrics    Features = 1 << 26
	// FeatureDrawIndex is gl_DrawID, core in GLSL 4.60 and on older desktop
	// versions gl_DrawIDARB of GL_ARB_shader_draw_parameters. Rust naga has
	// no such feature: it writes gl_DrawID at every version, which no GLSL
	// below 4.60 declares.
	FeatureDrawIndex Features = 1 << 27
)

func (Features) Names added in v0.21.0

func (f Features) Names() []string

Names returns Rust naga's names of the features, in bit order.

func (Features) String added in v0.21.0

func (f Features) String() string

String returns the names of the features joined by " | ", as Rust naga's Display for Features.

type ImmediateItem added in v0.20.5

type ImmediateItem struct {
	AccessPath string
	Type       ir.TypeInner
	Offset     uint32
	SizeBytes  uint32
}

ImmediateItem is one GL uniform that carries part of the immediate data. See glsl.ImmediateItem.

type MissingFeaturesError added in v0.21.0

type MissingFeaturesError struct {
	Version            Version
	Features           Features
	ForImageLoadChecks bool
}

MissingFeaturesError is Rust naga's Error::MissingFeatures: the entry point needs Features that Version lacks. ForImageLoadChecks reports that the ImageLoad bounds checks asked for some of them, so ImageLoad set to Unchecked avoids the error. glsl.Compile returns it as glsl.MissingFeaturesError.

func (*MissingFeaturesError) Error added in v0.21.0

func (e *MissingFeaturesError) Error() string

type Options

type Options struct {
	// LangVersion is the target GLSL version.
	// Defaults to Version330 if zero.
	LangVersion Version

	// EntryPoint selects the entry point to compile; nil selects the first.
	EntryPoint *backend.EntryPointSelector

	// SkipAdjustCoordinateSpace leaves gl_Position as written; by default a
	// vertex entry point ends with
	// gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);
	// (Rust naga's WriterFlags::ADJUST_COORDINATE_SPACE).
	SkipAdjustCoordinateSpace bool

	// ForcePointSize writes gl_PointSize = 1.0 in vertex entry points
	// (FORCE_POINT_SIZE).
	ForcePointSize bool

	// TextureShadowLod enables GL_EXT_texture_shadow_lod (TEXTURE_SHADOW_LOD).
	TextureShadowLod bool

	// DrawParameters uses GL_ARB_shader_draw_parameters (DRAW_PARAMETERS).
	DrawParameters bool

	// BoundsCheckPolicies controls bounds checking for resource accesses.
	// Matches Rust naga's proc::BoundsCheckPolicies.
	BoundsCheckPolicies backend.BoundsCheckPolicies

	// BindingMap maps resource bindings to flat GL binding indices.
	// Matches Rust naga's back::glsl::BindingMap.
	// When set, layout(binding = N) qualifiers are emitted.
	BindingMap map[BindingMapKey]uint8

	// FakeMissingBindings writes a resource a non-nil BindingMap leaves out
	// without a binding qualifier instead of failing.
	FakeMissingBindings bool

	// ZeroInitializeWorkgroupMemory is how compute entry points zero the
	// shared variables they use: Polyfill (zero) or None; Native is an
	// error.
	ZeroInitializeWorkgroupMemory backend.ZeroInitializeWorkgroupMemoryMode

	// ClampFragDepth clamps the depth a fragment entry point writes to the
	// range at byte ClampFragDepth.Offset of its immediate data (see the
	// glsl package).
	ClampFragDepth *backend.ClampFragDepth
}

Options configures GLSL code generation.

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns sensible default options for GLSL generation.

type TextureMapping

type TextureMapping struct {
	// TextureBinding is the (group, binding) of the texture global variable.
	TextureBinding ir.ResourceBinding

	// SamplerBinding is the (group, binding) of the associated sampler, if any.
	// Nil for storage images which have no sampler.
	SamplerBinding *ir.ResourceBinding
}

TextureMapping describes a combined texture-sampler pair generated by the GLSL backend. Matches Rust naga's TextureMapping (glsl/mod.rs:401-406).

In GLSL, separate texture2D + sampler become a single sampler2D uniform. The combined uniform uses the texture's binding. The GLES HAL needs to know which sampler is associated with which texture to bind the GL sampler object to the correct texture unit (not the sampler's own WGSL binding).

type TranslationInfo

type TranslationInfo struct {
	// EntryPointNames maps original entry point names to generated GLSL names.
	EntryPointNames map[string]string

	// UsedExtensions lists GLSL extensions required by the shader.
	UsedExtensions []string

	// RequiredVersion is the minimum GLSL version needed for this shader.
	// May be higher than the requested version if features require it.
	RequiredVersion Version

	// TextureSamplerPairs lists the combined texture-sampler pairs generated.
	// Each entry is "textureName_samplerName".
	TextureSamplerPairs []string

	// TextureMappings maps combined sampler2D uniform names to their texture
	// and sampler source bindings. Used by GLES HAL to build SamplerBindMap
	// (bind GL sampler to texture's unit, not sampler's own binding).
	// Matches Rust naga ReflectionInfo.texture_mapping.
	TextureMappings map[string]TextureMapping

	// Uniforms maps global variable block names to their binding info.
	// Used by GLES HAL for runtime binding fallback on GL < 4.2 where
	// layout(binding=N) is unavailable. After glLinkProgram, the HAL
	// queries block indices by name and assigns bindings via GL calls.
	// Matches Rust naga ReflectionInfo.uniforms.
	Uniforms []UniformInfo

	// ImmediateItems lists the GL uniforms of the immediate data.
	// Matches Rust naga ReflectionInfo.immediates_items.
	ImmediateItems []ImmediateItem
}

TranslationInfo contains metadata about the translation.

func Compile

func Compile(module *ir.Module, options Options) (string, TranslationInfo, error)

Compile generates GLSL source code from an IR module. Returns the GLSL source as a string, translation info, or an error.

type UniformInfo added in v0.17.14

type UniformInfo struct {
	// BlockName is the GLSL block name (e.g., "Uniforms_block_0Vertex").
	// Used with glGetUniformBlockIndex (uniform buffers) or
	// glGetShaderStorageBlockIndex (storage buffers).
	BlockName string

	// Binding is the source (group, binding) from the IR.
	Binding ir.ResourceBinding

	// IsStorage is true for storage buffers (SSBO), false for uniform buffers (UBO).
	IsStorage bool
}

UniformInfo describes a GLSL uniform or storage buffer block for reflection. Used by the HAL runtime binding fallback on GL < 4.2 where layout(binding=N) is unavailable and bindings must be assigned after linking via GL calls. Matches Rust naga ReflectionInfo.uniforms.

type Version

type Version struct {
	Major uint8
	Minor uint8
	ES    bool // true for GLSL ES (OpenGL ES / WebGL)
}

Version represents a GLSL version.

func (Version) String

func (v Version) String() string

String returns the version as a GLSL version directive value.

func (Version) SupportsCompute

func (v Version) SupportsCompute() bool

SupportsCompute returns true if this version supports compute shaders.

func (Version) SupportsStorageBuffers

func (v Version) SupportsStorageBuffers() bool

SupportsStorageBuffers returns true if this version supports storage buffers.

func (Version) VersionNumber

func (v Version) VersionNumber() string

VersionNumber returns just the numeric version (e.g., "330", "300").

type Writer

type Writer struct {
	textutil.IndentWriter // provides Out, Indent, WriteLine, WriteIndent, PushIndent, PopIndent
	// contains filtered or unexported fields
}

Writer generates GLSL source code from IR.

func (*Writer) String

func (w *Writer) String() string

String returns the generated GLSL source code.

Jump to

Keyboard shortcuts

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