A shader compiler.

Creating a compiler has substantial resource costs, so it is recommended to keep one object around for all tasks.

Static variables

staticread onlyspirvVersion:{revision:Int, minor:Int, major:Int}

The version of the SPIR-V which will be produced.

Static methods

@:has_untypedstaticparseVersionProfile(text:String):Null<{version:Int, profile:Profile}>

Parses the version and profile from a given string containing both version and profile, like: '450core'.

Parameters:

text

The text to parse.

Returns:

The version and profile, or null if the string cannot be parsed.

Constructor

@:has_untypednew()

Create a compiler that can be used to compile modules.

This has substantial resource costs, so it is recommended to keep one object around for all tasks.

Concurrent use on different objects needs no synchronization, concurrent invocation of these functions on the same object requires synchronization.

You need to release the object with ShaderCompiler.release when you are done using it. Using the object after that will throw a UseAfterReleaseException exception.

Throws:

InitializationErrorException

If there was an error initializing the compiler.

Methods

@:has_untypedassemble(source:String, ?options:Options):Result<ReadOnlyArray<Int>>

Compile a SPIR-V assembly text into a SPIR-V binary.

May be safely called from multiple threads without explicit synchronization.

Parameters:

source

The source of the shader, if Options.sourceLanguage isn't set it will be treated as GLSL..

options

Optional, if set then the compilation is modified by any options present that affects assembly.

Throws:

CompilationFailureException

If the compilation failed.

UseAfterReleaseException

If the object was released.

@:has_untypedcompile(source:String, kind:Kind, filename:String, entryPoint:String, ?options:Options):Result<ReadOnlyArray<Int>>

Compile a shader into a SPIR-V binary.

May be safely called from multiple threads without explicit synchronization.

Parameters:

source

The source of the shader, if Options.sourceLanguage isn't set it will be treated as GLSL.

kind

The shader kind. If the shader kind is not set to a specified kind, but Kind.InferFromSource, the compiler will try to deduce the shader kind from the source string and a failure in deducing will generate an error. Currently only #pragma annotation is supported. If the shader kind is set to one of the default shader kinds, the compiler will fall back to the default shader kind in case it failed to deduce the shader kind from source string.

filename

Used as a tag to identify the source string in cases like emitting error messages. It doesn't have to be a 'file name'.

entryPoint

Defines the name of the entry point.

options

Optional, if set then the compilation is modified by any options present.

Throws:

CompilationFailureException

If the compilation failed.

UseAfterReleaseException

If the object was released.

@:has_untypedcompileIntoAssembly(source:String, kind:Kind, filename:String, entryPoint:String, ?options:Options):Result<String>

Compiles a shader into SPIR-V assembly text.

The SPIR-V assembly syntax is as defined by the SPIRV-Tools open source project.

May be safely called from multiple threads without explicit synchronization.

Parameters:

source

The source of the shader, if Options.sourceLanguage isn't set it will be treated as GLSL.

kind

The shader kind. If the shader kind is not set to a specified kind, but Kind.InferFromSource, the compiler will try to deduce the shader kind from the source string and a failure in deducing will generate an error. Currently only #pragma annotation is supported. If the shader kind is set to one of the default shader kinds, the compiler will fall back to the default shader kind in case it failed to deduce the shader kind from source string.

filename

Used as a tag to identify the source string in cases like emitting error messages. It doesn't have to be a 'file name'.

entryPoint

Defines the name of the entry point.

options

Optional, if set then the compilation is modified by any options present.

Throws:

CompilationFailureException

If the compilation failed.

UseAfterReleaseException

If the object was released.

@:has_untypedpreprocess(source:String, filename:String, entryPoint:String, ?options:Options):Result<String>

Compiles a shader into preprocessed source code.

May be safely called from multiple threads without explicit synchronization.

Parameters:

source

The source of the shader, if Options.sourceLanguage isn't set it will be treated as GLSL.

filename

Used as a tag to identify the source string in cases like emitting error messages. It doesn't have to be a 'file name'.

entryPoint

Defines the name of the entry point.

options

Optional, if set then the compilation is modified by any options present.

Throws:

CompilationFailureException

If the compilation failed.

UseAfterReleaseException

If the object was released.

@:has_untypedrelease():Void

Releases the resources held by the compiler.

Using the object after that will throw a UseAfterReleaseException exception.

Throws:

UseAfterReleaseException

If the object was released.