2023-01-17 15:09:07 +11:00
|
|
|
//! Shader reflection and cross-compilation for librashader.
|
2023-01-20 10:59:39 +11:00
|
|
|
//!
|
|
|
|
//! ## Usage
|
|
|
|
//!
|
|
|
|
//! librashader-reflect requires the `type_alias_impl_trait` nightly feature. You should choose your
|
|
|
|
//! target shading language, and a compilation type.
|
|
|
|
//!
|
|
|
|
//! ```rust
|
|
|
|
//! #![feature(type_alias_impl_trait)]
|
|
|
|
//!
|
|
|
|
//! use std::error::Error;
|
|
|
|
//! use librashader_preprocess::ShaderSource;
|
|
|
|
//! use librashader_presets::ShaderPreset;
|
|
|
|
//! use librashader_reflect::back::{CompileReflectShader, FromCompilation};
|
|
|
|
//! use librashader_reflect::back::targets::SPIRV;
|
2024-02-11 09:47:05 +11:00
|
|
|
//! use librashader_reflect::front::{Glslang, ShaderInputCompiler, SpirvCompilation};
|
2024-02-11 13:17:58 +11:00
|
|
|
//! use librashader_reflect::reflect::cross::SpirvCross;
|
2023-01-20 10:59:39 +11:00
|
|
|
//! use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
|
|
|
|
//! use librashader_reflect::reflect::semantics::ShaderSemantics;
|
2024-02-11 13:17:58 +11:00
|
|
|
//! type Artifact = impl CompileReflectShader<SPIRV, SpirvCompilation, SpirvCross>;
|
2023-01-20 10:59:39 +11:00
|
|
|
//! type ShaderPassMeta = ShaderPassArtifact<Artifact>;
|
|
|
|
//!
|
|
|
|
//! // Compile single shader
|
|
|
|
//! pub fn compile_spirv(
|
|
|
|
//! source: &ShaderSource,
|
|
|
|
//! ) -> Result<Artifact, Box<dyn Error>>
|
|
|
|
//! {
|
2024-02-14 09:37:48 +11:00
|
|
|
//! let compilation = SpirvCompilation::try_from(&source);
|
|
|
|
//! let spirv = SPIRV::from_compilation(compilation)?;
|
2023-01-20 10:59:39 +11:00
|
|
|
//! Ok(spirv)
|
|
|
|
//! }
|
|
|
|
//!
|
|
|
|
//! // Compile preset
|
|
|
|
//! pub fn compile_preset(preset: ShaderPreset) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), Box<dyn Error>>
|
|
|
|
//! {
|
2024-02-14 09:37:48 +11:00
|
|
|
//! let (passes, semantics) = SPIRV::compile_preset_passes::<SpirvCompilation, SpirvCross, Box<dyn Error>>(
|
2023-01-20 10:59:39 +11:00
|
|
|
//! preset.shaders, &preset.textures)?;
|
|
|
|
//! Ok((passes, semantics))
|
|
|
|
//! }
|
|
|
|
//! ```
|
|
|
|
//!
|
|
|
|
//! ## What's with all the traits?
|
2024-08-09 14:29:04 +10:00
|
|
|
//! librashader-reflect is designed to be compiler-agnostic. [naga](https://docs.rs/naga/latest/naga/index.html),
|
|
|
|
//! a pure-Rust shader compiler, as well as SPIRV-Cross via [SpirvCompilation](crate::front::SpirvCompilation)
|
|
|
|
//! is supported.
|
2024-09-15 15:36:14 +10:00
|
|
|
#![cfg_attr(not(feature="stable"), feature(impl_trait_in_assoc_type))]
|
2024-09-07 13:42:18 +10:00
|
|
|
#![allow(stable_features)]
|
2024-09-15 15:36:14 +10:00
|
|
|
#![cfg_attr(not(feature="stable"), feature(c_str_literals))]
|
2022-12-01 14:50:57 +11:00
|
|
|
/// Shader codegen backends.
|
2022-11-11 17:44:41 +11:00
|
|
|
pub mod back;
|
2022-12-01 14:50:57 +11:00
|
|
|
/// Error types.
|
2022-11-07 16:25:11 +11:00
|
|
|
pub mod error;
|
2022-12-01 14:50:57 +11:00
|
|
|
/// Shader frontend parsers.
|
2022-11-07 16:25:11 +11:00
|
|
|
pub mod front;
|
2022-12-01 14:50:57 +11:00
|
|
|
/// Shader reflection.
|
2022-11-07 16:25:11 +11:00
|
|
|
pub mod reflect;
|