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§
- cross
reflect-cross - Reflection via SPIRV-Cross.
- dxil
Windows and reflect-dxil - DXIL reflection via spirv-to-dxil.
- naga
reflect-naga - Reflection via Naga
- semantics
- Shader semantics and reflection information.
- targets
- Supported shader compiler targets.
Structs§
- Binding
Meta - Reflection metadata about the various bindings for this shader.
- Compiler
Backend - A wrapper for a compiler backend.
- Shader
Compiler Output - The output of the shader compiler.
- Shader
Reflection - Reflection information about a shader.
- Spirv
Compilation - A reflectable shader compilation via glslang.
Enums§
- Semantics
Error Kind - The error kind encountered when reflecting shader semantics.
- Shader
Compile Error - Error type for shader compilation.
- Shader
Reflect Error - Error type for shader reflection.
Traits§
- Compile
Preset Target - Trait for target shading languages that can compile output with shader preset metdata.
- Compile
Reflect Shader - Marker trait for combinations of targets and compilations that can be reflected and compiled successfully.
- Compile
Shader - A trait for objects that can be compiled into a shader.
- From
Compilation - A trait for reflectable compilations that can be transformed into an object ready for reflection or compilation.
- Output
Target - Marker trait for shader compiler targets.
- Reflect
Shader - A trait for compilation outputs that can provide reflection information.
- Shader
Input Compiler - Trait for types that can compile shader sources into a compilation unit.
- Shader
Reflect Object - The output of a shader compiler that is reflectable.
Type Aliases§
- Shader
Pass Artifact - Artifacts of a reflected and compiled shader pass.