Skip to main content

Module reflect

Module reflect 

Source
Available on crate feature reflect only.
Expand description

Shader reflection and cross-compilation.

Without the stable crate feature, the type_alias_impl_trait nightly feature is required.

You should choose your target shading language, and a compilation type.

#![feature(type_alias_impl_trait)]
mod compile {
    use std::error::Error;
    use librashader::preprocess::ShaderSource;
    use librashader::presets::ShaderPreset;
    use librashader::reflect::{CompileReflectShader, FromCompilation, CompilePresetTarget, ShaderPassArtifact};
    use librashader::reflect::targets::SPIRV;
    use librashader::reflect::SpirvCompilation;
    use librashader::reflect::cross::SpirvCross;
    use librashader::reflect::semantics::ShaderSemantics;

    type Artifact = impl CompileReflectShader<SPIRV, SpirvCompilation, SpirvCross>;
    type ShaderPassMeta = ShaderPassArtifact<Artifact>;

     // Compile preset
    pub fn compile_preset(preset: ShaderPreset) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), Box<dyn Error>>
    {
        let (passes, semantics) = SPIRV::compile_preset_passes::<SpirvCompilation, SpirvCross, Box<dyn Error>>(
        preset.passes, &preset.textures)?;
        Ok((passes, semantics))
    }
}

With the stable crate feature, a trait object can be used instead. Note the Send bound on Artifact is required.

use librashader::reflect::CompileReflectShader;
use librashader::reflect::targets::SPIRV;
use librashader::reflect::SpirvCompilation;
use librashader::reflect::cross::SpirvCross;
use librashader::reflect::ShaderPassArtifact;

type Artifact = Box<dyn CompileReflectShader<SPIRV, SpirvCompilation, SpirvCross> + Send>;
type ShaderPassMeta = ShaderPassArtifact<Artifact>;

§What’s with all the traits?

librashader-reflect is designed to be compiler-agnostic. naga, a pure-Rust shader compiler, as well as SPIRV-Cross via SpirvCompilation is supported.

Modules§

crossreflect-cross
Reflection via SPIRV-Cross.
dxilWindows and reflect-dxil
DXIL reflection via spirv-to-dxil.
nagareflect-naga
Reflection via Naga
semantics
Shader semantics and reflection information.
targets
Supported shader compiler targets.

Structs§

BindingMeta
Reflection metadata about the various bindings for this shader.
CompilerBackend
A wrapper for a compiler backend.
ShaderCompilerOutput
The output of the shader compiler.
ShaderReflection
Reflection information about a shader.
SpirvCompilation
A reflectable shader compilation via glslang.

Enums§

SemanticsErrorKind
The error kind encountered when reflecting shader semantics.
ShaderCompileError
Error type for shader compilation.
ShaderReflectError
Error type for shader reflection.

Traits§

CompilePresetTarget
Trait for target shading languages that can compile output with shader preset metdata.
CompileReflectShader
Marker trait for combinations of targets and compilations that can be reflected and compiled successfully.
CompileShader
A trait for objects that can be compiled into a shader.
FromCompilation
A trait for reflectable compilations that can be transformed into an object ready for reflection or compilation.
OutputTarget
Marker trait for shader compiler targets.
ReflectShader
A trait for compilation outputs that can provide reflection information.
ShaderInputCompiler
Trait for types that can compile shader sources into a compilation unit.
ShaderReflectObject
The output of a shader compiler that is reflectable.

Type Aliases§

ShaderPassArtifact
Artifacts of a reflected and compiled shader pass.