pub struct Compiler { /* private fields */ }
Expand description
An opaque object managing all compiler states.
Creating an Compiler
object has substantial resource costs; so it is
recommended to keep one object around for all tasks.
Implementations§
Source§impl Compiler
impl Compiler
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Returns a Compiler
object that can be used to compile SPIR-V modules.
A return of Err
indicates that there was an error initializing
the underlying compiler (i.e., shaderc_compiler_initialize()
returned null).
Sourcepub fn compile_into_spirv(
&self,
source_text: &str,
shader_kind: ShaderKind,
input_file_name: &str,
entry_point_name: &str,
additional_options: Option<&CompileOptions<'_>>,
) -> Result<CompilationArtifact>
pub fn compile_into_spirv( &self, source_text: &str, shader_kind: ShaderKind, input_file_name: &str, entry_point_name: &str, additional_options: Option<&CompileOptions<'_>>, ) -> Result<CompilationArtifact>
Compiles the given source string source_text
to a SPIR-V binary
module according to the given additional_options
.
The source string will be compiled into a SPIR-V binary module
contained in a CompilationArtifact
object if no error happens.
The source string is treated as the given shader kind shader_kind
.
If InferFromSource
is given, the compiler will try to deduce the
shader kind from the source string via #pragma
directives and a
failure in deducing will generate an error. 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 the source string.
input_file_name
is a string used as a tag to identify the source
string in cases like emitting error messages. It doesn’t have to be
a canonical “file name”.
entry_point_name
is a string defines the name of the entry point
to associate with the source string.
Sourcepub fn compile_into_spirv_assembly(
&self,
source_text: &str,
shader_kind: ShaderKind,
input_file_name: &str,
entry_point_name: &str,
additional_options: Option<&CompileOptions<'_>>,
) -> Result<CompilationArtifact>
pub fn compile_into_spirv_assembly( &self, source_text: &str, shader_kind: ShaderKind, input_file_name: &str, entry_point_name: &str, additional_options: Option<&CompileOptions<'_>>, ) -> Result<CompilationArtifact>
Like compile_into_spirv
but the result contains SPIR-V assembly text
instead of a SPIR-V binary module.
The output SPIR-V assembly string will be of the format defined in the SPIRV-Tools project.
Sourcepub fn preprocess(
&self,
source_text: &str,
input_file_name: &str,
entry_point_name: &str,
additional_options: Option<&CompileOptions<'_>>,
) -> Result<CompilationArtifact>
pub fn preprocess( &self, source_text: &str, input_file_name: &str, entry_point_name: &str, additional_options: Option<&CompileOptions<'_>>, ) -> Result<CompilationArtifact>
Like compile_into_spirv
but the result contains preprocessed source
code instead of a SPIR-V binary module.
Sourcepub fn assemble(
&self,
source_assembly: &str,
additional_options: Option<&CompileOptions<'_>>,
) -> Result<CompilationArtifact>
pub fn assemble( &self, source_assembly: &str, additional_options: Option<&CompileOptions<'_>>, ) -> Result<CompilationArtifact>
Assembles the given SPIR-V assembly string source_assembly
into a
SPIR-V binary module according to the given additional_options
.
The input SPIR-V assembly string should be of the format defined in the SPIRV-Tools project.
For options specified in additional_options
, the assembling will
only pick those ones suitable for assembling.