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

shaderc

package module
v0.0.0-...-741f8c4 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2026 License: MIT Imports: 6 Imported by: 0

README

shaderc-go

Pure Go bindings for Google's libshaderc shader compiler. Compiles GLSL and HLSL to SPIR-V without cgo, using purego for dynamic library loading.

Requirements

  • Go 1.24+
  • libshaderc_shared installed on your system

Install libshaderc via your package manager:

# Arch Linux
pacman -S shaderc

# Ubuntu / Debian
apt install libshaderc-dev

# macOS
brew install shaderc

# Windows — place shaderc_shared.dll in your PATH or use SetLibraryPath

Install

go get github.com/thegrumpylion/shaderc-go

Usage

Compile GLSL to SPIR-V
package main

import (
 "log"
 "os"

 shaderc "github.com/thegrumpylion/shaderc-go"
)

func main() {
 compiler, err := shaderc.NewCompiler()
 if err != nil {
  log.Fatal(err)
 }

 source := `#version 450
layout(location = 0) in vec3 position;
layout(location = 1) in vec3 color;
layout(location = 0) out vec3 fragColor;

layout(set = 0, binding = 0) uniform UBO {
    mat4 mvp;
} ubo;

void main() {
    gl_Position = ubo.mvp * vec4(position, 1.0);
    fragColor = color;
}`

 result, err := compiler.CompileIntoSpv(
  source,
  shaderc.VertexShader,
  "shader.vert",
  "main",
  nil, // default options
 )
 if err != nil {
  log.Fatalf("compilation failed: %v", err)
 }

 spirv := result.Bytes()
 os.WriteFile("shader.spv", spirv, 0644)
}
Compile with options
opts, _ := shaderc.NewCompileOptions()
opts.SetOptimizationLevel(shaderc.OptimizationLevelPerformance)
opts.SetTargetEnv(shaderc.TargetEnvVulkan, shaderc.EnvVersionVulkan1_3)
opts.SetTargetSpirV(shaderc.SpirVVersion1_6)
opts.SetWarningsAsErrors()

result, err := compiler.CompileIntoSpv(source, shaderc.VertexShader, "shader.vert", "main", opts)
Compile HLSL
opts, _ := shaderc.NewCompileOptions()
opts.SetSourceLanguage(shaderc.SourceLanguageHLSL)

hlsl := `float4 main(float3 pos : POSITION) : SV_Position {
    return float4(pos, 1.0);
}`

result, err := compiler.CompileIntoSpv(hlsl, shaderc.VertexShader, "shader.hlsl", "main", opts)
Include resolution

Implement the IncludeResolver interface to handle #include directives:

type FileIncluder struct {
 basePath string
}

func (f *FileIncluder) Resolve(
 requestedSource string,
 includeType shaderc.IncludeType,
 requestingSource string,
 includeDepth int,
) *shaderc.IncludeResult {
 path := filepath.Join(f.basePath, requestedSource)
 data, err := os.ReadFile(path)
 if err != nil {
  return &shaderc.IncludeResult{Content: err.Error()}
 }
 return &shaderc.IncludeResult{
  SourceName: path,
  Content:    string(data),
 }
}

// Use it:
opts, _ := shaderc.NewCompileOptions()
opts.SetIncludeCallbacks(&FileIncluder{basePath: "shaders/"})

result, err := compiler.CompileIntoSpv(source, shaderc.FragmentShader, "main.frag", "main", opts)
Preprocessor and SPIR-V assembly
// Get preprocessed source text
ppResult, _ := compiler.CompileIntoPreprocessedText(source, shaderc.VertexShader, "shader.vert", "main", opts)
fmt.Println(string(ppResult.Bytes()))

// Get SPIR-V assembly text
asmResult, _ := compiler.CompileIntoSpvAssembly(source, shaderc.VertexShader, "shader.vert", "main", opts)
fmt.Println(string(asmResult.Bytes()))

// Assemble SPIR-V text back to binary
binResult, _ := compiler.AssembleIntoSpv(string(asmResult.Bytes()), nil)
spirv := binResult.Bytes()
Macro definitions
opts, _ := shaderc.NewCompileOptions()
opts.AddMacroDefinition("MAX_LIGHTS", "8")
opts.AddMacroDefinition("ENABLE_SHADOWS", "") // valueless define
Error handling
result, err := compiler.CompileIntoSpv(source, shaderc.FragmentShader, "shader.frag", "main", nil)
if err != nil {
 // result is still available for inspection on failure
 fmt.Printf("status:   %s\n", result.Status())
 fmt.Printf("errors:   %d\n", result.NumErrors())
 fmt.Printf("warnings: %d\n", result.NumWarnings())
 fmt.Printf("message:\n%s\n", result.ErrorMessage())
}
Custom library path
// Must be called before any other shaderc function.
shaderc.SetLibraryPath("/opt/vulkan/lib/libshaderc_shared.so")

Resource Management

All resources (Compiler, CompileOptions, CompilationResult) are automatically released by the garbage collector via runtime.AddCleanup. There are no manual Release() methods.

Bytes() copies the output into Go-managed memory, so the returned slice is always safe to use regardless of the result's lifetime.

API Coverage

Every public symbol from the libshaderc C API is bound:

  • 11 enum types with all constant values
  • 4 compilation functions (SPIR-V binary, assembly, preprocessed text, assemble)
  • 27 compile option setters
  • Full include callback support
  • Utility functions (GetSpvVersion, ParseVersionProfile)

See docs/api-mapping.md for the complete C-to-Go binding reference.

License

MIT

Documentation

Overview

Package shaderc provides Go bindings for Google's libshaderc shader compiler using purego for dynamic library loading without cgo.

The library compiles GLSL/HLSL source code into SPIR-V binary or assembly, and can also assemble SPIR-V assembly text into binary.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSpvVersion

func GetSpvVersion() (version, revision uint32, err error)

GetSpvVersion returns the SPIR-V version and revision that will be produced by the compiler. Returns an error if the library cannot be loaded.

func SetLibraryPath

func SetLibraryPath(path string) error

SetLibraryPath sets a custom path for the libshaderc shared library. Must be called before any other shaderc function. Calling after the library has been loaded will return an error.

Types

type CompilationResult

type CompilationResult struct {
	// contains filtered or unexported fields
}

CompilationResult holds the results of a compilation or assembly operation.

Resources are automatically released by the garbage collector. The byte slice returned by Bytes is a copy that remains valid independently.

func (*CompilationResult) Bytes

func (r *CompilationResult) Bytes() []byte

Bytes returns a copy of the compilation output data. For SPIR-V binary output, the returned byte slice contains the SPIR-V module. For assembly or preprocessed text output, it contains the text.

The returned slice is a Go-owned copy that is always safe to use.

func (*CompilationResult) ErrorMessage

func (r *CompilationResult) ErrorMessage() string

ErrorMessage returns any error or warning messages generated during compilation as a string.

func (*CompilationResult) Len

func (r *CompilationResult) Len() int

Len returns the number of bytes of the compilation output data.

func (*CompilationResult) NumErrors

func (r *CompilationResult) NumErrors() int

NumErrors returns the number of errors generated during compilation.

func (*CompilationResult) NumWarnings

func (r *CompilationResult) NumWarnings() int

NumWarnings returns the number of warnings generated during compilation.

func (*CompilationResult) Status

Status returns the compilation status, indicating whether compilation succeeded or failed.

type CompilationStatus

type CompilationStatus int32

CompilationStatus indicates the status of a compilation.

const (
	// CompilationStatusSuccess indicates successful compilation.
	CompilationStatusSuccess CompilationStatus = 0
	// CompilationStatusInvalidStage indicates an error in stage deduction.
	CompilationStatusInvalidStage CompilationStatus = 1
	// CompilationStatusCompilationError indicates a compilation error.
	CompilationStatusCompilationError CompilationStatus = 2
	// CompilationStatusInternalError indicates an unexpected failure.
	CompilationStatusInternalError CompilationStatus = 3
	// CompilationStatusNullResultObject indicates a null result object.
	CompilationStatusNullResultObject CompilationStatus = 4
	// CompilationStatusInvalidAssembly indicates invalid SPIR-V assembly.
	CompilationStatusInvalidAssembly CompilationStatus = 5
	// CompilationStatusValidationError indicates a SPIR-V validation error.
	CompilationStatusValidationError CompilationStatus = 6
	// CompilationStatusTransformationError indicates a transformation error.
	CompilationStatusTransformationError CompilationStatus = 7
	// CompilationStatusConfigurationError indicates a configuration error.
	CompilationStatusConfigurationError CompilationStatus = 8
)

func (CompilationStatus) String

func (s CompilationStatus) String() string

String returns a human-readable string for the CompilationStatus.

type CompileOptions

type CompileOptions struct {
	// contains filtered or unexported fields
}

CompileOptions manages options for a single compilation. Options can be reused across multiple compilations.

Resources are automatically released by the garbage collector. There is no need to manually release the options.

func NewCompileOptions

func NewCompileOptions() (*CompileOptions, error)

NewCompileOptions creates a new default-initialized set of compile options.

func (*CompileOptions) AddMacroDefinition

func (o *CompileOptions) AddMacroDefinition(name, value string)

AddMacroDefinition adds a predefined macro to the compilation options. This has the same effect as passing -Dname=value to the command-line compiler. If value is empty, the macro is defined without a value (equivalent to -Dname).

func (*CompileOptions) Clone

func (o *CompileOptions) Clone() (*CompileOptions, error)

Clone returns a deep copy of the compile options. The cloned options share the include callback state with the original via reference counting, so either can be garbage collected independently.

func (*CompileOptions) SetAutoBindUniforms

func (o *CompileOptions) SetAutoBindUniforms(autoBind bool)

SetAutoBindUniforms sets whether the compiler should automatically assign bindings to uniforms that aren't already explicitly bound in the shader source.

func (*CompileOptions) SetAutoCombinedImageSampler

func (o *CompileOptions) SetAutoCombinedImageSampler(upgrade bool)

SetAutoCombinedImageSampler sets whether the compiler should automatically remove sampler variables and convert image variables to combined image-sampler variables.

func (*CompileOptions) SetAutoMapLocations

func (o *CompileOptions) SetAutoMapLocations(autoMap bool)

SetAutoMapLocations sets whether the compiler should automatically assign locations to uniform variables that don't have explicit locations in the shader source.

func (*CompileOptions) SetBindingBase

func (o *CompileOptions) SetBindingBase(kind UniformKind, base uint32)

SetBindingBase sets the base binding number used for a uniform resource type when automatically assigning bindings. For GLSL compilation, sets the lowest automatically assigned number. For HLSL compilation, the register number assigned to the resource is added to this base.

func (*CompileOptions) SetBindingBaseForStage

func (o *CompileOptions) SetBindingBaseForStage(shaderKind ShaderKind, kind UniformKind, base uint32)

SetBindingBaseForStage is like SetBindingBase, but only takes effect when compiling a given shader stage.

func (*CompileOptions) SetForcedVersionProfile

func (o *CompileOptions) SetForcedVersionProfile(version int, profile Profile)

SetForcedVersionProfile forces the GLSL language version and profile to the given pair. The version number is the same as would appear in the #version annotation in the source. This overrides the #version annotation in the source. Use ProfileNone for GLSL versions that do not define profiles (e.g. versions below 150).

func (*CompileOptions) SetGenerateDebugInfo

func (o *CompileOptions) SetGenerateDebugInfo()

SetGenerateDebugInfo sets the compiler mode to generate debug information in the output.

func (*CompileOptions) SetHLSL16BitTypes

func (o *CompileOptions) SetHLSL16BitTypes(enable bool)

SetHLSL16BitTypes sets whether 16-bit types are supported in HLSL.

func (*CompileOptions) SetHLSLFunctionality1

func (o *CompileOptions) SetHLSLFunctionality1(enable bool)

SetHLSLFunctionality1 sets whether the compiler should enable the SPV_GOOGLE_hlsl_functionality1 extension.

func (*CompileOptions) SetHLSLIOMapping

func (o *CompileOptions) SetHLSLIOMapping(hlslIOMap bool)

SetHLSLIOMapping sets whether the compiler should use HLSL IO mapping rules for bindings. Defaults to false.

func (*CompileOptions) SetHLSLOffsets

func (o *CompileOptions) SetHLSLOffsets(hlslOffsets bool)

SetHLSLOffsets sets whether the compiler should determine block member offsets using HLSL packing rules instead of standard GLSL rules. Defaults to false. Only affects GLSL compilation. HLSL rules are always used when compiling HLSL.

func (*CompileOptions) SetHLSLRegisterSetAndBinding

func (o *CompileOptions) SetHLSLRegisterSetAndBinding(reg, set, binding string)

SetHLSLRegisterSetAndBinding sets a descriptor set and binding for an HLSL register, affecting all shader stages. The library copies the string data.

func (*CompileOptions) SetHLSLRegisterSetAndBindingForStage

func (o *CompileOptions) SetHLSLRegisterSetAndBindingForStage(shaderKind ShaderKind, reg, set, binding string)

SetHLSLRegisterSetAndBindingForStage sets a descriptor set and binding for an HLSL register in the given stage. The library copies the string data.

func (*CompileOptions) SetIncludeCallbacks

func (o *CompileOptions) SetIncludeCallbacks(resolver IncludeResolver)

SetIncludeCallbacks sets the include resolver for handling #include directives during compilation. See the IncludeResolver interface for details.

func (*CompileOptions) SetInvertY

func (o *CompileOptions) SetInvertY(enable bool)

SetInvertY sets whether the compiler should invert position.Y output in vertex shaders.

func (*CompileOptions) SetLimit

func (o *CompileOptions) SetLimit(limit Limit, value int)

SetLimit sets a resource limit for compilation.

func (*CompileOptions) SetMaxIDBound

func (o *CompileOptions) SetMaxIDBound(maxIDBound uint32)

SetMaxIDBound sets the maximum ID bound for the SPIR-V module.

func (*CompileOptions) SetNaNClamp

func (o *CompileOptions) SetNaNClamp(enable bool)

SetNaNClamp sets whether the compiler generates code for max and min builtins which, if given a NaN operand, will return the other operand. Similarly, the clamp builtin will favour the non-NaN operands.

func (*CompileOptions) SetOptimizationLevel

func (o *CompileOptions) SetOptimizationLevel(level OptimizationLevel)

SetOptimizationLevel sets the compiler optimization level. Only the last call takes effect if multiple calls are made.

func (*CompileOptions) SetPreserveBindings

func (o *CompileOptions) SetPreserveBindings(preserve bool)

SetPreserveBindings sets whether the compiler should preserve all bindings, even when those bindings are not used.

func (*CompileOptions) SetSourceLanguage

func (o *CompileOptions) SetSourceLanguage(lang SourceLanguage)

SetSourceLanguage sets the source language. The default is GLSL.

func (*CompileOptions) SetSuppressWarnings

func (o *CompileOptions) SetSuppressWarnings()

SetSuppressWarnings sets the compiler mode to suppress warnings. This overrides the warnings-as-errors mode.

func (*CompileOptions) SetTargetEnv

func (o *CompileOptions) SetTargetEnv(target TargetEnv, version EnvVersion)

SetTargetEnv sets the target shader environment, affecting which warnings or errors will be issued. The version should be either 0 or a value from EnvVersion. A version of 0 maps to Vulkan 1.0 if target is Vulkan, and OpenGL 4.5 if target is OpenGL.

func (*CompileOptions) SetTargetSpirV

func (o *CompileOptions) SetTargetSpirV(version SpirVVersion)

SetTargetSpirV sets the target SPIR-V version. The generated module will use this version of SPIR-V. Defaults to the highest version of SPIR-V 1.0 which is required to be supported by the target environment.

func (*CompileOptions) SetVulkanRulesRelaxed

func (o *CompileOptions) SetVulkanRulesRelaxed(enable bool)

SetVulkanRulesRelaxed enables or disables relaxed Vulkan rules. This allows most OpenGL shaders to compile under Vulkan semantics.

func (*CompileOptions) SetWarningsAsErrors

func (o *CompileOptions) SetWarningsAsErrors()

SetWarningsAsErrors sets the compiler mode to treat all warnings as errors. Note that SetSuppressWarnings overrides this option.

type Compiler

type Compiler struct {
	// contains filtered or unexported fields
}

Compiler manages all compiler state. It can be used to compile multiple shaders concurrently. A single Compiler instance can be reused across many compilations.

Resources are automatically released by the garbage collector. There is no need to manually release the compiler.

func NewCompiler

func NewCompiler() (*Compiler, error)

NewCompiler creates a new shader compiler instance. Returns an error if the library cannot be loaded or the compiler cannot be initialized.

func (*Compiler) AssembleIntoSpv

func (c *Compiler) AssembleIntoSpv(sourceAssembly string, options *CompileOptions) (*CompilationResult, error)

AssembleIntoSpv assembles the given SPIR-V assembly text into a SPIR-V binary module.

The sourceAssembly is SPIR-V assembly text in the format defined by the SPIRV-Tools project. If options is nil, default options are used.

func (*Compiler) CompileIntoPreprocessedText

func (c *Compiler) CompileIntoPreprocessedText(source string, kind ShaderKind, inputFileName, entryPoint string, options *CompileOptions) (*CompilationResult, error)

CompileIntoPreprocessedText compiles the given source code and returns the preprocessed source text instead of a SPIR-V binary module.

See CompileIntoSpv for parameter documentation.

func (*Compiler) CompileIntoSpv

func (c *Compiler) CompileIntoSpv(source string, kind ShaderKind, inputFileName, entryPoint string, options *CompileOptions) (*CompilationResult, error)

CompileIntoSpv compiles the given source code into SPIR-V binary.

The source is the shader source code. The kind specifies the shader kind. The inputFileName is a null-terminated string used as a tag in error messages; it does not have to be an actual file name. The entryPoint is the name of the entry point function.

If options is nil, default options are used.

func (*Compiler) CompileIntoSpvAssembly

func (c *Compiler) CompileIntoSpvAssembly(source string, kind ShaderKind, inputFileName, entryPoint string, options *CompileOptions) (*CompilationResult, error)

CompileIntoSpvAssembly compiles the given source code into SPIR-V assembly text instead of a SPIR-V binary module. The SPIR-V assembly syntax is as defined by the SPIRV-Tools project.

See CompileIntoSpv for parameter documentation.

type EnvVersion

type EnvVersion uint32

EnvVersion represents the version of the target environment.

const (
	// EnvVersionVulkan1_0 targets Vulkan 1.0.
	EnvVersionVulkan1_0 EnvVersion = (1 << 22)
	// EnvVersionVulkan1_1 targets Vulkan 1.1.
	EnvVersionVulkan1_1 EnvVersion = (1 << 22) | (1 << 12)
	// EnvVersionVulkan1_2 targets Vulkan 1.2.
	EnvVersionVulkan1_2 EnvVersion = (1 << 22) | (2 << 12)
	// EnvVersionVulkan1_3 targets Vulkan 1.3.
	EnvVersionVulkan1_3 EnvVersion = (1 << 22) | (3 << 12)
	// EnvVersionVulkan1_4 targets Vulkan 1.4.
	EnvVersionVulkan1_4 EnvVersion = (1 << 22) | (4 << 12)
	// EnvVersionOpenGL4_5 targets OpenGL 4.5.
	EnvVersionOpenGL4_5 EnvVersion = 450
	// EnvVersionWebGPU is deprecated. WebGPU env never defined versions.
	EnvVersionWebGPU EnvVersion = 451
)

type IncludeResolver

type IncludeResolver interface {
	// Resolve is called when the compiler encounters an #include directive.
	//
	// requestedSource is the name specified in the #include directive.
	// includeType indicates whether the include is relative (#include "...")
	// or standard (#include <...>).
	// requestingSource is the name of the source that contains the #include.
	// includeDepth is the current include nesting depth.
	//
	// Return an IncludeResult with the resolved source name and content.
	// To signal an error, return an IncludeResult with an empty SourceName
	// and the error message in Content.
	Resolve(requestedSource string, includeType IncludeType, requestingSource string, includeDepth int) *IncludeResult
}

IncludeResolver handles #include directive resolution during shader compilation.

type IncludeResult

type IncludeResult struct {
	// SourceName is the fully resolved name of the included source. For
	// example, if the includer maps source names to filesystem paths, this
	// should be the absolute path. For a failed inclusion, set this to an
	// empty string.
	SourceName string

	// Content is the text content of the included source. For a failed
	// inclusion, set this to the error message.
	Content string
}

IncludeResult represents the result of resolving an #include directive.

type IncludeType

type IncludeType int32

IncludeType represents the kind of #include request.

const (
	// IncludeTypeRelative represents a relative include: #include "source"
	IncludeTypeRelative IncludeType = 0
	// IncludeTypeStandard represents a standard include: #include <source>
	IncludeTypeStandard IncludeType = 1
)

func (IncludeType) String

func (t IncludeType) String() string

String returns a human-readable string for the IncludeType.

type Limit

type Limit int32

Limit represents a resource limit that can be set for compilation.

const (
	LimitMaxLights                                 Limit = 0
	LimitMaxClipPlanes                             Limit = 1
	LimitMaxTextureUnits                           Limit = 2
	LimitMaxTextureCoords                          Limit = 3
	LimitMaxVertexAttribs                          Limit = 4
	LimitMaxVertexUniformComponents                Limit = 5
	LimitMaxVaryingFloats                          Limit = 6
	LimitMaxVertexTextureImageUnits                Limit = 7
	LimitMaxCombinedTextureImageUnits              Limit = 8
	LimitMaxTextureImageUnits                      Limit = 9
	LimitMaxFragmentUniformComponents              Limit = 10
	LimitMaxDrawBuffers                            Limit = 11
	LimitMaxVertexUniformVectors                   Limit = 12
	LimitMaxVaryingVectors                         Limit = 13
	LimitMaxFragmentUniformVectors                 Limit = 14
	LimitMaxVertexOutputVectors                    Limit = 15
	LimitMaxFragmentInputVectors                   Limit = 16
	LimitMinProgramTexelOffset                     Limit = 17
	LimitMaxProgramTexelOffset                     Limit = 18
	LimitMaxClipDistances                          Limit = 19
	LimitMaxComputeWorkGroupCountX                 Limit = 20
	LimitMaxComputeWorkGroupCountY                 Limit = 21
	LimitMaxComputeWorkGroupCountZ                 Limit = 22
	LimitMaxComputeWorkGroupSizeX                  Limit = 23
	LimitMaxComputeWorkGroupSizeY                  Limit = 24
	LimitMaxComputeWorkGroupSizeZ                  Limit = 25
	LimitMaxComputeUniformComponents               Limit = 26
	LimitMaxComputeTextureImageUnits               Limit = 27
	LimitMaxComputeImageUniforms                   Limit = 28
	LimitMaxComputeAtomicCounters                  Limit = 29
	LimitMaxComputeAtomicCounterBuffers            Limit = 30
	LimitMaxVaryingComponents                      Limit = 31
	LimitMaxVertexOutputComponents                 Limit = 32
	LimitMaxGeometryInputComponents                Limit = 33
	LimitMaxGeometryOutputComponents               Limit = 34
	LimitMaxFragmentInputComponents                Limit = 35
	LimitMaxImageUnits                             Limit = 36
	LimitMaxCombinedImageUnitsAndFragmentOutputs   Limit = 37
	LimitMaxCombinedShaderOutputResources          Limit = 38
	LimitMaxImageSamples                           Limit = 39
	LimitMaxVertexImageUniforms                    Limit = 40
	LimitMaxTessControlImageUniforms               Limit = 41
	LimitMaxTessEvaluationImageUniforms            Limit = 42
	LimitMaxGeometryImageUniforms                  Limit = 43
	LimitMaxFragmentImageUniforms                  Limit = 44
	LimitMaxCombinedImageUniforms                  Limit = 45
	LimitMaxGeometryTextureImageUnits              Limit = 46
	LimitMaxGeometryOutputVertices                 Limit = 47
	LimitMaxGeometryTotalOutputComponents          Limit = 48
	LimitMaxGeometryUniformComponents              Limit = 49
	LimitMaxGeometryVaryingComponents              Limit = 50
	LimitMaxTessControlInputComponents             Limit = 51
	LimitMaxTessControlOutputComponents            Limit = 52
	LimitMaxTessControlTextureImageUnits           Limit = 53
	LimitMaxTessControlUniformComponents           Limit = 54
	LimitMaxTessControlTotalOutputComponents       Limit = 55
	LimitMaxTessEvaluationInputComponents          Limit = 56
	LimitMaxTessEvaluationOutputComponents         Limit = 57
	LimitMaxTessEvaluationTextureImageUnits        Limit = 58
	LimitMaxTessEvaluationUniformComponents        Limit = 59
	LimitMaxTessPatchComponents                    Limit = 60
	LimitMaxPatchVertices                          Limit = 61
	LimitMaxTessGenLevel                           Limit = 62
	LimitMaxViewports                              Limit = 63
	LimitMaxVertexAtomicCounters                   Limit = 64
	LimitMaxTessControlAtomicCounters              Limit = 65
	LimitMaxTessEvaluationAtomicCounters           Limit = 66
	LimitMaxGeometryAtomicCounters                 Limit = 67
	LimitMaxFragmentAtomicCounters                 Limit = 68
	LimitMaxCombinedAtomicCounters                 Limit = 69
	LimitMaxAtomicCounterBindings                  Limit = 70
	LimitMaxVertexAtomicCounterBuffers             Limit = 71
	LimitMaxTessControlAtomicCounterBuffers        Limit = 72
	LimitMaxTessEvaluationAtomicCounterBuffers     Limit = 73
	LimitMaxGeometryAtomicCounterBuffers           Limit = 74
	LimitMaxFragmentAtomicCounterBuffers           Limit = 75
	LimitMaxCombinedAtomicCounterBuffers           Limit = 76
	LimitMaxAtomicCounterBufferSize                Limit = 77
	LimitMaxTransformFeedbackBuffers               Limit = 78
	LimitMaxTransformFeedbackInterleavedComponents Limit = 79
	LimitMaxCullDistances                          Limit = 80
	LimitMaxCombinedClipAndCullDistances           Limit = 81
	LimitMaxSamples                                Limit = 82
	LimitMaxMeshOutputVerticesNV                   Limit = 83
	LimitMaxMeshOutputPrimitivesNV                 Limit = 84
	LimitMaxMeshWorkGroupSizeXNV                   Limit = 85
	LimitMaxMeshWorkGroupSizeYNV                   Limit = 86
	LimitMaxMeshWorkGroupSizeZNV                   Limit = 87
	LimitMaxTaskWorkGroupSizeXNV                   Limit = 88
	LimitMaxTaskWorkGroupSizeYNV                   Limit = 89
	LimitMaxTaskWorkGroupSizeZNV                   Limit = 90
	LimitMaxMeshViewCountNV                        Limit = 91
	LimitMaxMeshOutputVerticesEXT                  Limit = 92
	LimitMaxMeshOutputPrimitivesEXT                Limit = 93
	LimitMaxMeshWorkGroupSizeXEXT                  Limit = 94
	LimitMaxMeshWorkGroupSizeYEXT                  Limit = 95
	LimitMaxMeshWorkGroupSizeZEXT                  Limit = 96
	LimitMaxTaskWorkGroupSizeXEXT                  Limit = 97
	LimitMaxTaskWorkGroupSizeYEXT                  Limit = 98
	LimitMaxTaskWorkGroupSizeZEXT                  Limit = 99
	LimitMaxMeshViewCountEXT                       Limit = 100
	LimitMaxDualSourceDrawBuffersEXT               Limit = 101
)

type OptimizationLevel

type OptimizationLevel int32

OptimizationLevel represents the optimization level for compilation.

const (
	// OptimizationLevelZero applies no optimization.
	OptimizationLevelZero OptimizationLevel = 0
	// OptimizationLevelSize optimizes towards reducing code size.
	OptimizationLevelSize OptimizationLevel = 1
	// OptimizationLevelPerformance optimizes towards performance.
	OptimizationLevelPerformance OptimizationLevel = 2
)

func (OptimizationLevel) String

func (l OptimizationLevel) String() string

String returns a human-readable string for the OptimizationLevel.

type Profile

type Profile int32

Profile represents a GLSL profile.

const (
	// ProfileNone is used when the GLSL version does not specify a profile
	// (e.g. versions below 150).
	ProfileNone Profile = 0
	// ProfileCore specifies the core profile.
	ProfileCore Profile = 1
	// ProfileCompatibility specifies the compatibility profile. Disabled;
	// this generates an error.
	ProfileCompatibility Profile = 2
	// ProfileES specifies the ES profile.
	ProfileES Profile = 3
)

func ParseVersionProfile

func ParseVersionProfile(str string) (version int, profile Profile, ok bool)

ParseVersionProfile parses a version and profile from a string like "450core". Returns the version number, profile, and whether parsing succeeded.

func (Profile) String

func (p Profile) String() string

String returns a human-readable string for the Profile.

type ShaderKind

type ShaderKind int32

ShaderKind represents the kind of shader to compile.

const (

	// VertexShader forces compilation as a vertex shader.
	VertexShader ShaderKind = 0
	// FragmentShader forces compilation as a fragment shader.
	FragmentShader ShaderKind = 1
	// ComputeShader forces compilation as a compute shader.
	ComputeShader ShaderKind = 2
	// GeometryShader forces compilation as a geometry shader.
	GeometryShader ShaderKind = 3
	// TessControlShader forces compilation as a tessellation control shader.
	TessControlShader ShaderKind = 4
	// TessEvaluationShader forces compilation as a tessellation evaluation shader.
	TessEvaluationShader ShaderKind = 5

	// GLSLVertexShader is an alias for VertexShader.
	GLSLVertexShader ShaderKind = VertexShader
	// GLSLFragmentShader is an alias for FragmentShader.
	GLSLFragmentShader ShaderKind = FragmentShader
	// GLSLComputeShader is an alias for ComputeShader.
	GLSLComputeShader ShaderKind = ComputeShader
	// GLSLGeometryShader is an alias for GeometryShader.
	GLSLGeometryShader ShaderKind = GeometryShader
	// GLSLTessControlShader is an alias for TessControlShader.
	GLSLTessControlShader ShaderKind = TessControlShader
	// GLSLTessEvaluationShader is an alias for TessEvaluationShader.
	GLSLTessEvaluationShader ShaderKind = TessEvaluationShader

	// GLSLInferFromSource deduces the shader kind from #pragma annotation in the
	// source code. The compiler will emit an error if #pragma annotation is not found.
	GLSLInferFromSource ShaderKind = 6

	// GLSLDefaultVertexShader falls back to vertex shader if #pragma is not found.
	GLSLDefaultVertexShader ShaderKind = 7
	// GLSLDefaultFragmentShader falls back to fragment shader if #pragma is not found.
	GLSLDefaultFragmentShader ShaderKind = 8
	// GLSLDefaultComputeShader falls back to compute shader if #pragma is not found.
	GLSLDefaultComputeShader ShaderKind = 9
	// GLSLDefaultGeometryShader falls back to geometry shader if #pragma is not found.
	GLSLDefaultGeometryShader ShaderKind = 10
	// GLSLDefaultTessControlShader falls back to tessellation control shader if #pragma is not found.
	GLSLDefaultTessControlShader ShaderKind = 11
	// GLSLDefaultTessEvaluationShader falls back to tessellation evaluation shader if #pragma is not found.
	GLSLDefaultTessEvaluationShader ShaderKind = 12

	// SpirvAssembly indicates the input is SPIR-V assembly text.
	SpirvAssembly ShaderKind = 13

	// RaygenShader forces compilation as a ray generation shader.
	RaygenShader ShaderKind = 14
	// AnyhitShader forces compilation as an any-hit shader.
	AnyhitShader ShaderKind = 15
	// ClosesthitShader forces compilation as a closest-hit shader.
	ClosesthitShader ShaderKind = 16
	// MissShader forces compilation as a miss shader.
	MissShader ShaderKind = 17
	// IntersectionShader forces compilation as an intersection shader.
	IntersectionShader ShaderKind = 18
	// CallableShader forces compilation as a callable shader.
	CallableShader ShaderKind = 19

	// GLSLRaygenShader is an alias for RaygenShader.
	GLSLRaygenShader ShaderKind = RaygenShader
	// GLSLAnyhitShader is an alias for AnyhitShader.
	GLSLAnyhitShader ShaderKind = AnyhitShader
	// GLSLClosesthitShader is an alias for ClosesthitShader.
	GLSLClosesthitShader ShaderKind = ClosesthitShader
	// GLSLMissShader is an alias for MissShader.
	GLSLMissShader ShaderKind = MissShader
	// GLSLIntersectionShader is an alias for IntersectionShader.
	GLSLIntersectionShader ShaderKind = IntersectionShader
	// GLSLCallableShader is an alias for CallableShader.
	GLSLCallableShader ShaderKind = CallableShader

	// GLSLDefaultRaygenShader falls back to ray generation shader if #pragma is not found.
	GLSLDefaultRaygenShader ShaderKind = 20
	// GLSLDefaultAnyhitShader falls back to any-hit shader if #pragma is not found.
	GLSLDefaultAnyhitShader ShaderKind = 21
	// GLSLDefaultClosesthitShader falls back to closest-hit shader if #pragma is not found.
	GLSLDefaultClosesthitShader ShaderKind = 22
	// GLSLDefaultMissShader falls back to miss shader if #pragma is not found.
	GLSLDefaultMissShader ShaderKind = 23
	// GLSLDefaultIntersectionShader falls back to intersection shader if #pragma is not found.
	GLSLDefaultIntersectionShader ShaderKind = 24
	// GLSLDefaultCallableShader falls back to callable shader if #pragma is not found.
	GLSLDefaultCallableShader ShaderKind = 25

	// TaskShader forces compilation as a task shader.
	TaskShader ShaderKind = 26
	// MeshShader forces compilation as a mesh shader.
	MeshShader ShaderKind = 27

	// GLSLTaskShader is an alias for TaskShader.
	GLSLTaskShader ShaderKind = TaskShader
	// GLSLMeshShader is an alias for MeshShader.
	GLSLMeshShader ShaderKind = MeshShader

	// GLSLDefaultTaskShader falls back to task shader if #pragma is not found.
	GLSLDefaultTaskShader ShaderKind = 28
	// GLSLDefaultMeshShader falls back to mesh shader if #pragma is not found.
	GLSLDefaultMeshShader ShaderKind = 29
)

func (ShaderKind) String

func (k ShaderKind) String() string

String returns a human-readable string for the ShaderKind.

type SourceLanguage

type SourceLanguage int32

SourceLanguage represents the source language of the shader.

const (
	// SourceLanguageGLSL indicates GLSL source.
	SourceLanguageGLSL SourceLanguage = 0
	// SourceLanguageHLSL indicates HLSL source.
	SourceLanguageHLSL SourceLanguage = 1
)

func (SourceLanguage) String

func (l SourceLanguage) String() string

String returns a human-readable string for the SourceLanguage.

type SpirVVersion

type SpirVVersion int32

SpirVVersion represents a version of SPIR-V.

const (
	// SpirVVersion1_0 targets SPIR-V 1.0.
	SpirVVersion1_0 SpirVVersion = 0x010000
	// SpirVVersion1_1 targets SPIR-V 1.1.
	SpirVVersion1_1 SpirVVersion = 0x010100
	// SpirVVersion1_2 targets SPIR-V 1.2.
	SpirVVersion1_2 SpirVVersion = 0x010200
	// SpirVVersion1_3 targets SPIR-V 1.3.
	SpirVVersion1_3 SpirVVersion = 0x010300
	// SpirVVersion1_4 targets SPIR-V 1.4.
	SpirVVersion1_4 SpirVVersion = 0x010400
	// SpirVVersion1_5 targets SPIR-V 1.5.
	SpirVVersion1_5 SpirVVersion = 0x010500
	// SpirVVersion1_6 targets SPIR-V 1.6.
	SpirVVersion1_6 SpirVVersion = 0x010600
)

type TargetEnv

type TargetEnv int32

TargetEnv represents the target shader environment.

const (
	// TargetEnvVulkan targets SPIR-V under Vulkan semantics.
	TargetEnvVulkan TargetEnv = 0
	// TargetEnvOpenGL targets SPIR-V under OpenGL semantics.
	TargetEnvOpenGL TargetEnv = 1
	// TargetEnvOpenGLCompat targets SPIR-V under OpenGL semantics, including
	// compatibility profile functions. Note: SPIR-V code generation is not
	// supported for shaders under OpenGL compatibility profile.
	TargetEnvOpenGLCompat TargetEnv = 2
	// TargetEnvWebGPU is deprecated. It targets SPIR-V under WebGPU semantics.
	TargetEnvWebGPU TargetEnv = 3
	// TargetEnvDefault is an alias for TargetEnvVulkan.
	TargetEnvDefault TargetEnv = TargetEnvVulkan
)

func (TargetEnv) String

func (e TargetEnv) String() string

String returns a human-readable string for the TargetEnv.

type UniformKind

type UniformKind int32

UniformKind represents the kind of uniform resource.

const (
	// UniformKindImage represents an image and image buffer.
	UniformKindImage UniformKind = 0
	// UniformKindSampler represents a pure sampler.
	UniformKindSampler UniformKind = 1
	// UniformKindTexture represents a sampled texture in GLSL, or Shader
	// Resource View in HLSL.
	UniformKindTexture UniformKind = 2
	// UniformKindBuffer represents a Uniform Buffer Object (UBO) in GLSL,
	// or Cbuffer in HLSL.
	UniformKindBuffer UniformKind = 3
	// UniformKindStorageBuffer represents a Shader Storage Buffer Object
	// (SSBO) in GLSL.
	UniformKindStorageBuffer UniformKind = 4
	// UniformKindUnorderedAccessView represents an Unordered Access View in
	// HLSL (writable storage image or storage buffer).
	UniformKindUnorderedAccessView UniformKind = 5
)

func (UniformKind) String

func (k UniformKind) String() string

String returns a human-readable string for the UniformKind.

Jump to

Keyboard shortcuts

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