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
staticparseVersionProfile(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
new()
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
assemble(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 | 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. |
compile(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 |
---|---|
kind | The shader kind. If the shader kind is not set to a specified kind, but |
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. |
compileIntoAssembly(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 |
---|---|
kind | The shader kind. If the shader kind is not set to a specified kind, but |
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. |
preprocess(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 |
---|---|
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. |
release():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. |
---|