Module librashader::reflect
source · Available on crate feature
reflect
only.Expand description
Shader reflection and cross-compilation.
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)]
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::semantics::ShaderSemantics;
use librashader_reflect::front::{ShaderInputCompiler, SpirvCompilation};
use librashader_reflect::reflect::cross::SpirvCross;
type Artifact = impl CompileReflectShader<SPIRV, SpirvCompilation, SpirvCross>;
type ShaderPassMeta = ShaderPassArtifact<Artifact>;
// Compile single shader
pub fn compile_spirv(
source: &ShaderSource,
) -> Result<Artifact, Box<dyn Error>>
{
let compilation = SpirvCompilation::compile(&source)?;
let spirv = SPIRV::from_compilation(compilation)?;
Ok(spirv)
}
// 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.shaders, &preset.textures)?;
Ok((passes, semantics))
}
§What’s with all the traits?
librashader-reflect is designed to be compiler-agnostic. In the future, we will allow usage of naga, a pure-Rust shader compiler, when it has matured enough to support the features librashader needs.
In the meanwhile, the only supported input compiler is SpirvCompilation, which does compilation of GLSL to SPIR-V via glslang.
Modules§
- cross
reflect-cross
Reflection via SPIRV-Cross. - dxilWindows and
reflect-dxil
DXIL reflection via spirv-to-dxil. - naga
reflect-naga
Reflection via Naga - Shader semantics and reflection information.
- Supported shader compiler targets.
Structs§
- Reflection metadata about the various bindings for this shader.
- A wrapper for a compiler backend.
- The output of the shader compiler.
- Reflection information about a shader.
- A reflectable shader compilation via glslang.
Enums§
- The error kind encountered when reflecting shader semantics.
- Error type for shader compilation.
- Error type for shader reflection.
Traits§
- Trait for target shading languages that can compile output with shader preset metdata.
- Marker trait for combinations of targets and compilations that can be reflected and compiled successfully.
- A trait for objects that can be compiled into a shader.
- A trait for reflectable compilations that can be transformed into an object ready for reflection or compilation.
- Marker trait for shader compiler targets.
- A trait for compilation outputs that can provide reflection information.
- Trait for types that can compile shader sources into a compilation unit.
- The output of a shader compiler that is reflectable.
Type Aliases§
- Artifacts of a reflected and compiled shader pass.