librashader_reflect/
lib.rs

1//! Shader reflection and cross-compilation for librashader.
2//!
3//! ## Usage
4//!
5//! librashader-reflect requires the `type_alias_impl_trait` nightly feature. You should choose your
6//! target shading language, and a compilation type.
7//!
8//! ```rust
9//! #![feature(type_alias_impl_trait)]
10//!
11//! use std::error::Error;
12//! use librashader_preprocess::ShaderSource;
13//! use librashader_presets::ShaderPreset;
14//! use librashader_reflect::back::{CompileReflectShader, FromCompilation};
15//! use librashader_reflect::back::targets::SPIRV;
16//! use librashader_reflect::front::{Glslang, ShaderInputCompiler, SpirvCompilation};
17//! use librashader_reflect::reflect::cross::SpirvCross;
18//! use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
19//! use librashader_reflect::reflect::semantics::ShaderSemantics;
20//! type Artifact = impl CompileReflectShader<SPIRV, SpirvCompilation, SpirvCross>;
21//! type ShaderPassMeta = ShaderPassArtifact<Artifact>;
22//!
23//! // Compile single shader
24//! pub fn compile_spirv(
25//!         source: &ShaderSource,
26//!     ) -> Result<Artifact, Box<dyn Error>>
27//! {
28//!     let compilation = SpirvCompilation::try_from(&source);
29//!     let spirv = SPIRV::from_compilation(compilation)?;
30//!     Ok(spirv)
31//! }
32//!
33//! // Compile preset
34//! pub fn compile_preset(preset: ShaderPreset) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), Box<dyn Error>>
35//! {
36//!     let (passes, semantics) = SPIRV::compile_preset_passes::<SpirvCompilation, SpirvCross, Box<dyn Error>>(
37//!     preset.passes, &preset.textures)?;
38//!     Ok((passes, semantics))
39//! }
40//! ```
41//!
42//! ## What's with all the traits?
43//! librashader-reflect is designed to be compiler-agnostic. [naga](https://docs.rs/naga/latest/naga/index.html),
44//! a pure-Rust shader compiler, as well as SPIRV-Cross via [SpirvCompilation](crate::front::SpirvCompilation)
45//! is supported.
46#![cfg_attr(not(feature = "stable"), feature(impl_trait_in_assoc_type))]
47/// Shader codegen backends.
48pub mod back;
49/// Error types.
50pub mod error;
51/// Shader frontend parsers.
52pub mod front;
53/// Shader reflection.
54pub mod reflect;