reflect: abstract away input compiler from compilation

This commit is contained in:
chyyran 2024-02-10 17:47:05 -05:00 committed by Ronny Chan
parent 11d12730eb
commit a7ca391ef6
19 changed files with 145 additions and 122 deletions

View file

@ -6,21 +6,25 @@ use librashader_reflect::back::targets::{GLSL, HLSL, SPIRV};
use librashader_reflect::back::{CompilerBackend, FromCompilation};
use librashader_reflect::error::{ShaderCompileError, ShaderReflectError};
use librashader_reflect::front::{GlslangCompilation, ShaderCompilation};
use librashader_reflect::front::{Glslang, ShaderInputCompiler, ShaderReflectObject, SpirvCompilation};
pub struct CachedCompilation<T> {
compilation: T,
}
impl<T: ShaderCompilation + for<'de> serde::Deserialize<'de> + serde::Serialize + Clone>
ShaderCompilation for CachedCompilation<T>
impl <T: ShaderReflectObject> ShaderReflectObject for CachedCompilation<T> {
}
impl<T: ShaderReflectObject + for<'de> serde::Deserialize<'de> + serde::Serialize + Clone>
ShaderInputCompiler<CachedCompilation<T>> for Glslang where Glslang: ShaderInputCompiler<T>
{
fn compile(source: &ShaderSource) -> Result<Self, ShaderCompileError> {
fn compile(source: &ShaderSource) -> Result<CachedCompilation<T>, ShaderCompileError> {
let cache = crate::cache::internal::get_cache();
let Ok(cache) = cache else {
return Ok(CachedCompilation {
compilation: T::compile(source)?,
compilation: Glslang::compile(source)?,
});
};
@ -45,7 +49,7 @@ impl<T: ShaderCompilation + for<'de> serde::Deserialize<'de> + serde::Serialize
}
CachedCompilation {
compilation: T::compile(source)?,
compilation: Glslang::compile(source)?,
}
};
@ -60,53 +64,53 @@ impl<T: ShaderCompilation + for<'de> serde::Deserialize<'de> + serde::Serialize
}
#[cfg(all(target_os = "windows", feature = "d3d"))]
impl FromCompilation<CachedCompilation<GlslangCompilation>> for DXIL {
type Target = <DXIL as FromCompilation<GlslangCompilation>>::Target;
type Options = <DXIL as FromCompilation<GlslangCompilation>>::Options;
type Context = <DXIL as FromCompilation<GlslangCompilation>>::Context;
type Output = <DXIL as FromCompilation<GlslangCompilation>>::Output;
impl FromCompilation<CachedCompilation<SpirvCompilation>> for DXIL {
type Target = <DXIL as FromCompilation<SpirvCompilation>>::Target;
type Options = <DXIL as FromCompilation<SpirvCompilation>>::Options;
type Context = <DXIL as FromCompilation<SpirvCompilation>>::Context;
type Output = <DXIL as FromCompilation<SpirvCompilation>>::Output;
fn from_compilation(
compile: CachedCompilation<GlslangCompilation>,
compile: CachedCompilation<SpirvCompilation>,
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
DXIL::from_compilation(compile.compilation)
}
}
impl FromCompilation<CachedCompilation<GlslangCompilation>> for HLSL {
type Target = <HLSL as FromCompilation<GlslangCompilation>>::Target;
type Options = <HLSL as FromCompilation<GlslangCompilation>>::Options;
type Context = <HLSL as FromCompilation<GlslangCompilation>>::Context;
type Output = <HLSL as FromCompilation<GlslangCompilation>>::Output;
impl FromCompilation<CachedCompilation<SpirvCompilation>> for HLSL {
type Target = <HLSL as FromCompilation<SpirvCompilation>>::Target;
type Options = <HLSL as FromCompilation<SpirvCompilation>>::Options;
type Context = <HLSL as FromCompilation<SpirvCompilation>>::Context;
type Output = <HLSL as FromCompilation<SpirvCompilation>>::Output;
fn from_compilation(
compile: CachedCompilation<GlslangCompilation>,
compile: CachedCompilation<SpirvCompilation>,
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
HLSL::from_compilation(compile.compilation)
}
}
impl FromCompilation<CachedCompilation<GlslangCompilation>> for GLSL {
type Target = <GLSL as FromCompilation<GlslangCompilation>>::Target;
type Options = <GLSL as FromCompilation<GlslangCompilation>>::Options;
type Context = <GLSL as FromCompilation<GlslangCompilation>>::Context;
type Output = <GLSL as FromCompilation<GlslangCompilation>>::Output;
impl FromCompilation<CachedCompilation<SpirvCompilation>> for GLSL {
type Target = <GLSL as FromCompilation<SpirvCompilation>>::Target;
type Options = <GLSL as FromCompilation<SpirvCompilation>>::Options;
type Context = <GLSL as FromCompilation<SpirvCompilation>>::Context;
type Output = <GLSL as FromCompilation<SpirvCompilation>>::Output;
fn from_compilation(
compile: CachedCompilation<GlslangCompilation>,
compile: CachedCompilation<SpirvCompilation>,
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
GLSL::from_compilation(compile.compilation)
}
}
impl FromCompilation<CachedCompilation<GlslangCompilation>> for SPIRV {
type Target = <SPIRV as FromCompilation<GlslangCompilation>>::Target;
type Options = <SPIRV as FromCompilation<GlslangCompilation>>::Options;
type Context = <SPIRV as FromCompilation<GlslangCompilation>>::Context;
type Output = <SPIRV as FromCompilation<GlslangCompilation>>::Output;
impl FromCompilation<CachedCompilation<SpirvCompilation>> for SPIRV {
type Target = <SPIRV as FromCompilation<SpirvCompilation>>::Target;
type Options = <SPIRV as FromCompilation<SpirvCompilation>>::Options;
type Context = <SPIRV as FromCompilation<SpirvCompilation>>::Context;
type Output = <SPIRV as FromCompilation<SpirvCompilation>>::Output;
fn from_compilation(
compile: CachedCompilation<GlslangCompilation>,
compile: CachedCompilation<SpirvCompilation>,
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
SPIRV::from_compilation(compile.compilation)
}

View file

@ -1,7 +1,7 @@
use crate::back::targets::{GLSL, HLSL};
use crate::back::{CompileShader, CompilerBackend, FromCompilation};
use crate::error::ShaderReflectError;
use crate::front::GlslangCompilation;
use crate::front::SpirvCompilation;
use crate::reflect::cross::{CompiledProgram, GlslReflect, HlslReflect};
use crate::reflect::ReflectShader;
@ -19,7 +19,7 @@ pub struct CrossGlslContext {
pub artifact: CompiledProgram<spirv_cross::glsl::Target>,
}
impl FromCompilation<GlslangCompilation> for GLSL {
impl FromCompilation<SpirvCompilation> for GLSL {
type Target = GLSL;
type Options = GlslVersion;
type Context = CrossGlslContext;
@ -27,7 +27,7 @@ impl FromCompilation<GlslangCompilation> for GLSL {
+ ReflectShader;
fn from_compilation(
compile: GlslangCompilation,
compile: SpirvCompilation,
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
Ok(CompilerBackend {
backend: GlslReflect::try_from(&compile)?,
@ -41,7 +41,7 @@ pub struct CrossHlslContext {
pub artifact: CompiledProgram<spirv_cross::hlsl::Target>,
}
impl FromCompilation<GlslangCompilation> for HLSL {
impl FromCompilation<SpirvCompilation> for HLSL {
type Target = HLSL;
type Options = Option<HlslShaderModel>;
type Context = CrossHlslContext;
@ -49,7 +49,7 @@ impl FromCompilation<GlslangCompilation> for HLSL {
+ ReflectShader;
fn from_compilation(
compile: GlslangCompilation,
compile: SpirvCompilation,
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
Ok(CompilerBackend {
backend: HlslReflect::try_from(&compile)?,

View file

@ -8,7 +8,7 @@ use spirv_to_dxil::{
use crate::back::targets::{OutputTarget, DXIL};
use crate::error::{ShaderCompileError, ShaderReflectError};
use crate::front::GlslangCompilation;
use crate::front::SpirvCompilation;
use crate::reflect::cross::GlslReflect;
use crate::reflect::ReflectShader;
@ -16,7 +16,7 @@ impl OutputTarget for DXIL {
type Output = DxilObject;
}
impl FromCompilation<GlslangCompilation> for DXIL {
impl FromCompilation<SpirvCompilation> for DXIL {
type Target = DXIL;
type Options = Option<ShaderModel>;
type Context = ();
@ -24,7 +24,7 @@ impl FromCompilation<GlslangCompilation> for DXIL {
+ ReflectShader;
fn from_compilation(
compile: GlslangCompilation,
compile: SpirvCompilation,
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
let reflect = GlslReflect::try_from(&compile)?;
let vertex = compile.vertex;

View file

@ -4,12 +4,14 @@ pub mod dxil;
mod spirv;
pub mod targets;
pub mod wgsl;
mod msl;
use crate::back::targets::OutputTarget;
use crate::error::{ShaderCompileError, ShaderReflectError};
use crate::reflect::semantics::ShaderSemantics;
use crate::reflect::{ReflectShader, ShaderReflection};
use std::fmt::Debug;
use crate::front::ShaderReflectObject;
/// The output of the shader compiler.
#[derive(Debug)]
@ -118,11 +120,11 @@ where
#[cfg(test)]
mod test {
use crate::front::GlslangCompilation;
use crate::front::{Glslang, ShaderInputCompiler, SpirvCompilation};
use librashader_preprocess::ShaderSource;
pub fn test() {
let result = ShaderSource::load("../test/basic.slang").unwrap();
let _cross = GlslangCompilation::compile(&result).unwrap();
let _cross = Glslang::compile(&result).unwrap();
}
}

View file

View file

@ -1,7 +1,7 @@
use crate::back::targets::SPIRV;
use crate::back::{CompileShader, CompilerBackend, FromCompilation, ShaderCompilerOutput};
use crate::error::{ShaderCompileError, ShaderReflectError};
use crate::front::GlslangCompilation;
use crate::front::SpirvCompilation;
use crate::reflect::cross::GlslReflect;
use crate::reflect::semantics::ShaderSemantics;
use crate::reflect::{ReflectShader, ShaderReflection};
@ -13,7 +13,7 @@ pub(crate) struct WriteSpirV {
pub(crate) fragment: Vec<u32>,
}
impl FromCompilation<GlslangCompilation> for SPIRV {
impl FromCompilation<SpirvCompilation> for SPIRV {
type Target = SPIRV;
type Options = Option<()>;
type Context = ();
@ -21,7 +21,7 @@ impl FromCompilation<GlslangCompilation> for SPIRV {
+ ReflectShader;
fn from_compilation(
compile: GlslangCompilation,
compile: SpirvCompilation,
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
let reflect = GlslReflect::try_from(&compile)?;
let vertex = compile.vertex;

View file

@ -34,6 +34,9 @@ impl OutputTarget for HLSL {
impl OutputTarget for WGSL {
type Output = String;
}
impl OutputTarget for MSL {
type Output = String;
}
impl OutputTarget for SPIRV {
type Output = Vec<u32>;
}
@ -42,9 +45,9 @@ impl OutputTarget for SPIRV {
mod test {
use crate::back::targets::GLSL;
use crate::back::FromCompilation;
use crate::front::GlslangCompilation;
use crate::front::SpirvCompilation;
#[allow(dead_code)]
pub fn test_compile(value: GlslangCompilation) {
pub fn test_compile(value: SpirvCompilation) {
let _x = GLSL::from_compilation(value).unwrap();
}
}

View file

@ -4,7 +4,7 @@ use crate::back::targets::WGSL;
use crate::back::wgsl::lower_samplers::LowerCombinedImageSamplerPass;
use crate::back::{CompileShader, CompilerBackend, FromCompilation, ShaderCompilerOutput};
use crate::error::{ShaderCompileError, ShaderReflectError};
use crate::front::GlslangCompilation;
use crate::front::SpirvCompilation;
use crate::reflect::naga::NagaReflect;
use crate::reflect::ReflectShader;
use naga::back::wgsl::WriterFlags;
@ -26,7 +26,7 @@ pub struct WgslCompileOptions {
pub sampler_bind_group: u32,
}
impl FromCompilation<GlslangCompilation> for WGSL {
impl FromCompilation<SpirvCompilation> for WGSL {
type Target = WGSL;
type Options = WgslCompileOptions;
type Context = NagaWgslContext;
@ -34,7 +34,7 @@ impl FromCompilation<GlslangCompilation> for WGSL {
+ ReflectShader;
fn from_compilation(
compile: GlslangCompilation,
compile: SpirvCompilation,
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
fn lower_fragment_shader(words: &[u32]) -> Vec<u32> {
let mut loader = rspirv::dr::Loader::new();
@ -189,7 +189,7 @@ mod test {
);
}
let compilation = crate::front::GlslangCompilation::try_from(&result).unwrap();
let compilation = crate::front::SpirvCompilation::try_from(&result).unwrap();
let mut wgsl = WGSL::from_compilation(compilation).unwrap();

View file

@ -4,34 +4,20 @@ use librashader_preprocess::ShaderSource;
#[cfg(feature = "serialize")]
use serde::{Deserialize, Serialize};
use crate::front::{ShaderInputCompiler, SpirvCompilation};
/// A reflectable shader compilation via glslang.
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub struct GlslangCompilation {
pub(crate) vertex: Vec<u32>,
pub(crate) fragment: Vec<u32>,
}
/// glslang compiler
pub struct Glslang;
impl GlslangCompilation {
/// Tries to compile SPIR-V from the provided shader source.
pub fn compile(source: &ShaderSource) -> Result<Self, ShaderCompileError> {
impl ShaderInputCompiler<SpirvCompilation> for Glslang {
fn compile(source: &ShaderSource) -> Result<SpirvCompilation, ShaderCompileError> {
compile_spirv(source)
}
}
impl TryFrom<&ShaderSource> for GlslangCompilation {
type Error = ShaderCompileError;
/// Tries to compile SPIR-V from the provided shader source.
fn try_from(source: &ShaderSource) -> Result<Self, Self::Error> {
GlslangCompilation::compile(source)
}
}
pub(crate) fn compile_spirv(
source: &ShaderSource,
) -> Result<GlslangCompilation, ShaderCompileError> {
) -> Result<SpirvCompilation, ShaderCompileError> {
let compiler = glslang::Compiler::acquire().ok_or(ShaderCompileError::CompilerInitError)?;
let options = CompilerOptions {
source_language: glslang::SourceLanguage::GLSL,
@ -53,7 +39,7 @@ pub(crate) fn compile_spirv(
let vertex = Vec::from(vertex.compile()?);
let fragment = Vec::from(fragment.compile()?);
Ok(GlslangCompilation { vertex, fragment })
Ok(SpirvCompilation { vertex, fragment })
}
#[cfg(test)]

View file

@ -1,18 +1,44 @@
use crate::error::ShaderCompileError;
use librashader_preprocess::ShaderSource;
use serde::{Deserialize, Serialize};
mod glslang;
pub use crate::front::glslang::GlslangCompilation;
pub trait ShaderReflectObject : Sized {
}
pub use glslang::Glslang;
/// Trait for types that can compile shader sources into a compilation unit.
pub trait ShaderCompilation: Sized {
pub trait ShaderInputCompiler<O: ShaderReflectObject>: Sized {
/// Compile the input shader source file into a compilation unit.
fn compile(source: &ShaderSource) -> Result<Self, ShaderCompileError>;
fn compile(source: &ShaderSource) -> Result<O, ShaderCompileError>;
}
impl<T: for<'a> TryFrom<&'a ShaderSource, Error = ShaderCompileError>> ShaderCompilation for T {
fn compile(source: &ShaderSource) -> Result<Self, ShaderCompileError> {
source.try_into()
impl ShaderReflectObject for SpirvCompilation { }
/// A reflectable shader compilation via glslang.
#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
#[derive(Debug, Clone)]
pub struct SpirvCompilation {
pub(crate) vertex: Vec<u32>,
pub(crate) fragment: Vec<u32>,
}
impl SpirvCompilation {
/// Tries to compile SPIR-V from the provided shader source.
pub fn compile(source: &ShaderSource) -> Result<Self, ShaderCompileError> {
glslang::compile_spirv(source)
}
}
impl TryFrom<&ShaderSource> for SpirvCompilation {
type Error = ShaderCompileError;
/// Tries to compile SPIR-V from the provided shader source.
fn try_from(source: &ShaderSource) -> Result<Self, Self::Error> {
Glslang::compile(source)
}
}

View file

@ -13,10 +13,10 @@
//! use librashader_presets::ShaderPreset;
//! use librashader_reflect::back::{CompileReflectShader, FromCompilation};
//! use librashader_reflect::back::targets::SPIRV;
//! use librashader_reflect::front::GlslangCompilation;
//! use librashader_reflect::front::{Glslang, ShaderInputCompiler, SpirvCompilation};
//! use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
//! use librashader_reflect::reflect::semantics::ShaderSemantics;
//! type Artifact = impl CompileReflectShader<SPIRV, GlslangCompilation>;
//! type Artifact = impl CompileReflectShader<SPIRV, SpirvCompilation>;
//! type ShaderPassMeta = ShaderPassArtifact<Artifact>;
//!
//! // Compile single shader
@ -24,7 +24,7 @@
//! source: &ShaderSource,
//! ) -> Result<Artifact, Box<dyn Error>>
//! {
//! let compilation = GlslangCompilation::compile(&source)?;
//! let artifact = Glslang::compile(&source)?;
//! let spirv = SPIRV::from_compilation(artifact)?;
//! Ok(spirv)
//! }
@ -32,7 +32,7 @@
//! // Compile preset
//! pub fn compile_preset(preset: ShaderPreset) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), Box<dyn Error>>
//! {
//! let (passes, semantics) = SPIRV::compile_preset_passes::<GlslangCompilation, Box<dyn Error>>(
//! let (passes, semantics) = SPIRV::compile_preset_passes::<Glslang, SpirvCompilation, Box<dyn Error>>(
//! preset.shaders, &preset.textures)?;
//! Ok((passes, semantics))
//! }
@ -43,7 +43,7 @@
//! [naga](https://docs.rs/naga/latest/naga/index.html), a pure-Rust shader compiler, when it has
//! matured enough to support [the features librashader needs](https://github.com/gfx-rs/naga/issues/1012).
//!
//! In the meanwhile, the only supported compilation type is [GlslangCompilation](crate::front::GlslangCompilation),
//! In the meanwhile, the only supported compilation type is [GlslangCompilation](crate::front::SpirvCompilation),
//! which does transpilation via [glslang](https://github.com/KhronosGroup/glslang) and [SPIRV-Cross](https://github.com/KhronosGroup/SPIRV-Cross).
#![feature(type_alias_impl_trait)]
#![feature(impl_trait_in_assoc_type)]

View file

@ -1,5 +1,5 @@
use crate::error::{SemanticsErrorKind, ShaderCompileError, ShaderReflectError};
use crate::front::GlslangCompilation;
use crate::front::SpirvCompilation;
use crate::reflect::semantics::{
BindingMeta, BindingStage, BufferReflection, MemberOffset, ShaderReflection, ShaderSemantics,
TextureBinding, TextureSemanticMap, TextureSemantics, TextureSizeMeta, TypeInfo,
@ -134,7 +134,7 @@ impl ValidateTypeSemantics<Type> for TextureSemantics {
}
}
impl<T> TryFrom<&GlslangCompilation> for CrossReflect<T>
impl<T> TryFrom<&SpirvCompilation> for CrossReflect<T>
where
T: spirv_cross::spirv::Target,
Ast<T>: spirv_cross::spirv::Compile<T>,
@ -142,7 +142,7 @@ where
{
type Error = ShaderReflectError;
fn try_from(value: &GlslangCompilation) -> Result<Self, Self::Error> {
fn try_from(value: &SpirvCompilation) -> Result<Self, Self::Error> {
let vertex_module = Module::from_words(&value.vertex);
let fragment_module = Module::from_words(&value.fragment);
@ -890,7 +890,7 @@ mod test {
use rustc_hash::FxHashMap;
use crate::back::CompileShader;
use crate::front::GlslangCompilation;
use crate::front::{Glslang, ShaderInputCompiler, SpirvCompilation};
use crate::reflect::semantics::{Semantic, ShaderSemantics, UniformSemantic, UniqueSemantics};
use librashader_preprocess::ShaderSource;
use spirv_cross::glsl;
@ -910,7 +910,7 @@ mod test {
}),
);
}
let spirv = GlslangCompilation::compile(&result).unwrap();
let spirv = Glslang::compile(&result).unwrap();
let mut reflect = CrossReflect::<glsl::Target>::try_from(&spirv).unwrap();
let _shader_reflection = reflect
.reflect(

View file

@ -1,7 +1,7 @@
use crate::back::targets::OutputTarget;
use crate::back::{CompilerBackend, FromCompilation};
use crate::error::{ShaderCompileError, ShaderReflectError};
use crate::front::ShaderCompilation;
use crate::front::{ShaderInputCompiler, ShaderReflectObject, SpirvCompilation};
use crate::reflect::semantics::{
Semantic, ShaderSemantics, TextureSemantics, UniformSemantic, UniqueSemantics,
};
@ -19,10 +19,10 @@ use rustc_hash::FxHashMap;
/// #![feature(type_alias_impl_trait)]
/// use librashader_reflect::back::CompileReflectShader;
/// use librashader_reflect::back::targets::SPIRV;
/// use librashader_reflect::front::GlslangCompilation;
/// use librashader_reflect::front::SpirvCompilation;
/// use librashader_reflect::reflect::presets::ShaderPassArtifact;
///
/// type VulkanPassMeta = ShaderPassArtifact<impl CompileReflectShader<SPIRV, GlslangCompilation>>;
/// type VulkanPassMeta = ShaderPassArtifact<impl CompileReflectShader<SPIRV, SpirvCompilation>>;
/// ```
///
/// This allows a runtime to not name the backing type of the compiled artifact if not necessary.
@ -35,44 +35,46 @@ impl<T: OutputTarget> CompilePresetTarget for T {}
pub trait CompilePresetTarget: OutputTarget {
/// Compile passes of a shader preset given the applicable
/// shader output target, compilation type, and resulting error.
fn compile_preset_passes<C, E>(
fn compile_preset_passes<C, I, E>(
passes: Vec<ShaderPassConfig>,
textures: &[TextureConfig],
) -> Result<
(
Vec<ShaderPassArtifact<<Self as FromCompilation<C>>::Output>>,
Vec<ShaderPassArtifact<<Self as FromCompilation<I>>::Output>>,
ShaderSemantics,
),
E,
>
where
I: ShaderReflectObject,
Self: Sized,
Self: FromCompilation<C>,
C: ShaderCompilation,
Self: FromCompilation<I>,
C: ShaderInputCompiler<I>,
E: From<PreprocessError>,
E: From<ShaderReflectError>,
E: From<ShaderCompileError>,
{
compile_preset_passes::<Self, C, E>(passes, textures)
compile_preset_passes::<Self, C, I, E>(passes, textures)
}
}
/// Compile passes of a shader preset given the applicable
/// shader output target, compilation type, and resulting error.
fn compile_preset_passes<T, C, E>(
fn compile_preset_passes<T, C, I, E>(
passes: Vec<ShaderPassConfig>,
textures: &[TextureConfig],
) -> Result<
(
Vec<ShaderPassArtifact<<T as FromCompilation<C>>::Output>>,
Vec<ShaderPassArtifact<<T as FromCompilation<I>>::Output>>,
ShaderSemantics,
),
E,
>
where
I: ShaderReflectObject,
T: OutputTarget,
T: FromCompilation<C>,
C: ShaderCompilation,
T: FromCompilation<I>,
C: ShaderInputCompiler<I>,
E: From<PreprocessError>,
E: From<ShaderReflectError>,
E: From<ShaderCompileError>,

View file

@ -4,7 +4,7 @@ use librashader_common::{ImageFormat, Size, Viewport};
use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
use librashader_reflect::back::targets::HLSL;
use librashader_reflect::back::{CompileReflectShader, CompileShader};
use librashader_reflect::front::GlslangCompilation;
use librashader_reflect::front::{Glslang, SpirvCompilation};
use librashader_reflect::reflect::semantics::ShaderSemantics;
use librashader_reflect::reflect::ReflectShader;
use librashader_runtime::image::{Image, ImageError, UVDirection};
@ -74,18 +74,18 @@ pub(crate) struct FilterCommon {
}
type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation> + Send>;
ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation> + Send>;
fn compile_passes(
shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig],
disable_cache: bool,
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache {
HLSL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
HLSL::compile_preset_passes::<Glslang, CachedCompilation<SpirvCompilation>, FilterChainError>(
shaders, &textures,
)?
} else {
HLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(shaders, &textures)?
HLSL::compile_preset_passes::<Glslang, SpirvCompilation, FilterChainError>(shaders, &textures)?
};
Ok((passes, semantics))

View file

@ -18,7 +18,7 @@ use librashader_common::{ImageFormat, Size, Viewport};
use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
use librashader_reflect::back::targets::{DXIL, HLSL};
use librashader_reflect::back::{CompileReflectShader, CompileShader};
use librashader_reflect::front::GlslangCompilation;
use librashader_reflect::front::{Glslang, SpirvCompilation};
use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
use librashader_reflect::reflect::semantics::{ShaderSemantics, MAX_BINDINGS_COUNT};
use librashader_reflect::reflect::ReflectShader;
@ -145,35 +145,35 @@ impl Drop for FrameResiduals {
}
type DxilShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<DXIL, GlslangCompilation> + Send>;
ShaderPassArtifact<impl CompileReflectShader<DXIL, SpirvCompilation> + Send>;
fn compile_passes_dxil(
shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig],
disable_cache: bool,
) -> Result<(Vec<DxilShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache {
DXIL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
DXIL::compile_preset_passes::<Glslang, CachedCompilation<SpirvCompilation>, FilterChainError>(
shaders, &textures,
)?
} else {
DXIL::compile_preset_passes::<GlslangCompilation, FilterChainError>(shaders, &textures)?
DXIL::compile_preset_passes::<Glslang, SpirvCompilation, FilterChainError>(shaders, &textures)?
};
Ok((passes, semantics))
}
type HlslShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<HLSL, GlslangCompilation> + Send>;
ShaderPassArtifact<impl CompileReflectShader<HLSL, SpirvCompilation> + Send>;
fn compile_passes_hlsl(
shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig],
disable_cache: bool,
) -> Result<(Vec<HlslShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache {
HLSL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
HLSL::compile_preset_passes::<Glslang, CachedCompilation<SpirvCompilation>, FilterChainError>(
shaders, &textures,
)?
} else {
HLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(shaders, &textures)?
HLSL::compile_preset_passes::<Glslang, SpirvCompilation, FilterChainError>(shaders, &textures)?
};
Ok((passes, semantics))

View file

@ -16,7 +16,7 @@ use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
use librashader_reflect::back::cross::GlslVersion;
use librashader_reflect::back::targets::GLSL;
use librashader_reflect::back::{CompileReflectShader, CompileShader};
use librashader_reflect::front::GlslangCompilation;
use librashader_reflect::front::{Glslang, SpirvCompilation};
use librashader_reflect::reflect::semantics::{ShaderSemantics, UniformMeta};
use librashader_cache::CachedCompilation;
@ -97,18 +97,18 @@ impl<T: GLInterface> FilterChainImpl<T> {
}
}
type ShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<GLSL, GlslangCompilation>>;
type ShaderPassMeta = ShaderPassArtifact<impl CompileReflectShader<GLSL, SpirvCompilation>>;
fn compile_passes(
shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig],
disable_cache: bool,
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache {
GLSL::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
GLSL::compile_preset_passes::<Glslang, CachedCompilation<SpirvCompilation>, FilterChainError>(
shaders, &textures,
)?
} else {
GLSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(shaders, &textures)?
GLSL::compile_preset_passes::<Glslang, SpirvCompilation, FilterChainError>(shaders, &textures)?
};
Ok((passes, semantics))

View file

@ -17,7 +17,7 @@ use gpu_allocator::vulkan::Allocator;
use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
use librashader_reflect::back::targets::SPIRV;
use librashader_reflect::back::{CompileReflectShader, CompileShader};
use librashader_reflect::front::GlslangCompilation;
use librashader_reflect::front::{Glslang, SpirvCompilation};
use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
use librashader_reflect::reflect::semantics::ShaderSemantics;
use librashader_reflect::reflect::ReflectShader;
@ -208,18 +208,18 @@ impl Drop for FrameResiduals {
}
type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<SPIRV, GlslangCompilation> + Send>;
ShaderPassArtifact<impl CompileReflectShader<SPIRV, SpirvCompilation> + Send>;
fn compile_passes(
shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig],
disable_cache: bool,
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) = if !disable_cache {
SPIRV::compile_preset_passes::<CachedCompilation<GlslangCompilation>, FilterChainError>(
SPIRV::compile_preset_passes::<Glslang, CachedCompilation<SpirvCompilation>, FilterChainError>(
shaders, &textures,
)?
} else {
SPIRV::compile_preset_passes::<GlslangCompilation, FilterChainError>(shaders, &textures)?
SPIRV::compile_preset_passes::<Glslang, SpirvCompilation, FilterChainError>(shaders, &textures)?
};
Ok((passes, semantics))

View file

@ -1,7 +1,7 @@
use librashader_presets::{ShaderPassConfig, ShaderPreset, TextureConfig};
use librashader_reflect::back::targets::WGSL;
use librashader_reflect::back::{CompileReflectShader, CompileShader};
use librashader_reflect::front::GlslangCompilation;
use librashader_reflect::front::{Glslang, SpirvCompilation};
use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
use librashader_reflect::reflect::semantics::ShaderSemantics;
use librashader_reflect::reflect::ReflectShader;
@ -38,13 +38,13 @@ use crate::samplers::SamplerSet;
use crate::texture::{InputImage, OwnedImage};
type ShaderPassMeta =
ShaderPassArtifact<impl CompileReflectShader<WGSL, GlslangCompilation> + Send>;
ShaderPassArtifact<impl CompileReflectShader<WGSL, SpirvCompilation> + Send>;
fn compile_passes(
shaders: Vec<ShaderPassConfig>,
textures: &[TextureConfig],
) -> Result<(Vec<ShaderPassMeta>, ShaderSemantics), FilterChainError> {
let (passes, semantics) =
WGSL::compile_preset_passes::<GlslangCompilation, FilterChainError>(shaders, &textures)?;
WGSL::compile_preset_passes::<Glslang, SpirvCompilation, FilterChainError>(shaders, &textures)?;
Ok((passes, semantics))
}

View file

@ -150,7 +150,7 @@ pub mod reflect {
FromCompilation, ShaderCompilerOutput,
};
pub use librashader_reflect::front::GlslangCompilation;
pub use librashader_reflect::front::SpirvCompilation;
/// Reflection via SPIRV-Cross.
#[cfg(feature = "reflect-cross")]
@ -196,7 +196,7 @@ pub mod reflect {
pub use librashader_reflect::reflect::presets::{CompilePresetTarget, ShaderPassArtifact};
pub use librashader_reflect::front::ShaderCompilation;
pub use librashader_reflect::front::ShaderInputCompiler;
#[doc(hidden)]
#[cfg(feature = "internal")]
/// Helper methods for runtimes.