Skip to main content

Crate shaderc_dyn

Crate shaderc_dyn 

Source
Expand description

Rust binding for the Shaderc library (dynamic loading fork).

This crate contains the higher-level Rust-friendly interface for the Shaderc library. For the lower-level C interface, please see the shaderc-sys-dyn crate.

The Shaderc library provides an API for compiling GLSL/HLSL source code to SPIRV modules. It has been shipping in the Android NDK since version r12b.

This fork loads the shaderc shared library (libshaderc_shared) at runtime using libloading. No build-time compilation is performed. The shared library must be installed and available on the system library search path, or its location can be specified via the SHADERC_LIB_PATH environment variable.

§Examples

Compile a shader into SPIR-V binary module and assembly text:

use shaderc_dyn;

let source = "#version 310 es\n void EP() {}";

let compiler = shaderc_dyn::Compiler::new().unwrap();
let mut options = shaderc_dyn::CompileOptions::new().unwrap();
options.add_macro_definition("EP", Some("main"));
let binary_result = compiler.compile_into_spirv(
    source, shaderc_dyn::ShaderKind::Vertex,
    "shader.glsl", "main", Some(&options)).unwrap();

assert_eq!(Some(&0x07230203), binary_result.as_binary().first());

let text_result = compiler.compile_into_spirv_assembly(
    source, shaderc_dyn::ShaderKind::Vertex,
    "shader.glsl", "main", Some(&options)).unwrap();

assert!(text_result.as_text().starts_with("; SPIR-V\n"));

Structs§

CompilationArtifact
An opaque object containing the results of compilation.
CompileOptions
An opaque object managing options to compilation.
Compiler
An opaque object managing all compiler states.
ResolvedInclude
A representation of a successfully resolved include directive, containing the name of the include and its contents.

Enums§

EnvVersion
Target environment version.
Error
Error.
GlslProfile
GLSL profile.
IncludeType
Identifies the type of include directive. Relative is for include directives of the form #include "...", and Standard is for include directives of the form #include <...>.
Limit
Resource limit.
OptimizationLevel
Optimization level.
ResourceKind
Resource kinds.
ShaderKind
Shader kind.
SourceLanguage
Source language.
SpirvVersion
The known versions of SPIR-V.
TargetEnv
Target environment.

Functions§

get_spirv_version
Returns the version and revision of the SPIR-V generated by this library.
parse_version_profile
Parses the version and profile from the given string, returning a Result.

Type Aliases§

IncludeCallbackResult
Include callback status.
Result
Compilation status.