diff --git a/librashader-reflect/src/back/cross.rs b/librashader-reflect/src/back/cross.rs index 6ef9a87..434b433 100644 --- a/librashader-reflect/src/back/cross.rs +++ b/librashader-reflect/src/back/cross.rs @@ -1,7 +1,7 @@ use crate::back::targets::{GLSL, HLSL}; use crate::back::{CompileShader, CompilerBackend, FromCompilation}; use crate::error::ShaderReflectError; -use crate::front::shaderc::GlslangCompilation; +use crate::front::GlslangCompilation; use crate::reflect::cross::{CompiledProgram, GlslReflect, HlslReflect}; use crate::reflect::ReflectShader; diff --git a/librashader-reflect/src/back/spirv.rs b/librashader-reflect/src/back/spirv.rs index c94fee3..3aa583d 100644 --- a/librashader-reflect/src/back/spirv.rs +++ b/librashader-reflect/src/back/spirv.rs @@ -1,7 +1,7 @@ use crate::back::targets::SPIRV; use crate::back::{CompileShader, CompilerBackend, FromCompilation, ShaderCompilerOutput}; use crate::error::{ShaderCompileError, ShaderReflectError}; -use crate::front::shaderc::GlslangCompilation; +use crate::front::GlslangCompilation; use crate::reflect::cross::GlslReflect; use crate::reflect::semantics::ShaderSemantics; use crate::reflect::{ReflectShader, ShaderReflection}; diff --git a/librashader-reflect/src/back/targets.rs b/librashader-reflect/src/back/targets.rs index d1e5955..6c69ec4 100644 --- a/librashader-reflect/src/back/targets.rs +++ b/librashader-reflect/src/back/targets.rs @@ -26,7 +26,7 @@ impl OutputTarget for SPIRV { mod test { use crate::back::targets::GLSL; use crate::back::FromCompilation; - use crate::front::shaderc::GlslangCompilation; + use crate::front::GlslangCompilation; #[allow(dead_code)] pub fn test_compile(value: GlslangCompilation) { let _x = GLSL::from_compilation(value).unwrap(); diff --git a/librashader-reflect/src/front/mod.rs b/librashader-reflect/src/front/mod.rs index 8e3fd15..0b7d7dc 100644 --- a/librashader-reflect/src/front/mod.rs +++ b/librashader-reflect/src/front/mod.rs @@ -2,11 +2,23 @@ use crate::error::ShaderCompileError; use librashader_preprocess::ShaderSource; #[cfg(feature = "unstable-naga")] -pub mod naga; +mod naga; -pub mod shaderc; +mod shaderc; +pub use crate::front::shaderc::GlslangCompilation; + +#[cfg(feature = "unstable-naga")] +pub use crate::front::naga::NagaCompilation; + +/// Trait for types that can compile shader sources into a compilation unit. pub trait ShaderCompilation: Sized { /// Compile the input shader source file into a compilation unit. fn compile(source: &ShaderSource) -> Result; } + +impl TryFrom<&'a ShaderSource, Error = ShaderCompileError>> ShaderCompilation for T { + fn compile(source: &ShaderSource) -> Result { + source.try_into() + } +} diff --git a/librashader-reflect/src/front/naga.rs b/librashader-reflect/src/front/naga.rs index ede6472..32ede44 100644 --- a/librashader-reflect/src/front/naga.rs +++ b/librashader-reflect/src/front/naga.rs @@ -10,7 +10,16 @@ pub struct NagaCompilation { pub(crate) fragment: Module, } -pub fn compile_spirv(source: &ShaderSource) -> Result { +impl TryFrom<&ShaderSource> for NagaCompilation { + type Error = ShaderCompileError; + + /// Tries to compile SPIR-V from the provided shader source. + fn try_from(source: &ShaderSource) -> Result { + compile_spirv(source) + } +} + +fn compile_spirv(source: &ShaderSource) -> Result { let mut parser = Parser::default(); let vertex = parser.parse(&Options::from(ShaderStage::Vertex), &source.vertex)?; let fragment = parser.parse(&Options::from(ShaderStage::Fragment), &source.fragment)?; diff --git a/librashader-reflect/src/front/shaderc.rs b/librashader-reflect/src/front/shaderc.rs index 142e005..01693c8 100644 --- a/librashader-reflect/src/front/shaderc.rs +++ b/librashader-reflect/src/front/shaderc.rs @@ -1,5 +1,4 @@ use crate::error::ShaderCompileError; -use crate::front::ShaderCompilation; use librashader_preprocess::ShaderSource; use shaderc::{CompilationArtifact, CompileOptions, Limit, ShaderKind}; @@ -16,12 +15,6 @@ impl GlslangCompilation { } } -impl ShaderCompilation for GlslangCompilation { - fn compile(source: &ShaderSource) -> Result { - GlslangCompilation::compile(source) - } -} - impl TryFrom<&ShaderSource> for GlslangCompilation { type Error = ShaderCompileError; diff --git a/librashader-reflect/src/reflect/cross.rs b/librashader-reflect/src/reflect/cross.rs index eb4256a..c291d70 100644 --- a/librashader-reflect/src/reflect/cross.rs +++ b/librashader-reflect/src/reflect/cross.rs @@ -1,5 +1,5 @@ use crate::error::{SemanticsErrorKind, ShaderCompileError, ShaderReflectError}; -use crate::front::shaderc::GlslangCompilation; +use crate::front::GlslangCompilation; use crate::reflect::semantics::{ BindingMeta, BindingStage, MemberOffset, PushReflection, ShaderReflection, ShaderSemantics, TextureBinding, TextureSemanticMap, TextureSemantics, TextureSizeMeta, TypeInfo, UboReflection, diff --git a/librashader-reflect/src/reflect/presets.rs b/librashader-reflect/src/reflect/presets.rs index 1f3a7dd..bdd33c1 100644 --- a/librashader-reflect/src/reflect/presets.rs +++ b/librashader-reflect/src/reflect/presets.rs @@ -1,5 +1,5 @@ use crate::back::targets::OutputTarget; -use crate::back::{CompileShader, CompilerBackend, FromCompilation}; +use crate::back::{CompilerBackend, FromCompilation}; use crate::error::{ShaderCompileError, ShaderReflectError}; use crate::front::ShaderCompilation; use crate::reflect::semantics::{ diff --git a/librashader-runtime-d3d11/src/filter_chain.rs b/librashader-runtime-d3d11/src/filter_chain.rs index f3069c3..ef378cb 100644 --- a/librashader-runtime-d3d11/src/filter_chain.rs +++ b/librashader-runtime-d3d11/src/filter_chain.rs @@ -4,7 +4,7 @@ use librashader_common::{ImageFormat, Size, Viewport}; use librashader_presets::{ShaderPreset, TextureConfig}; use librashader_reflect::back::targets::HLSL; use librashader_reflect::back::CompileShader; -use librashader_reflect::front::shaderc::GlslangCompilation; +use librashader_reflect::front::GlslangCompilation; use librashader_reflect::reflect::semantics::{ShaderSemantics, TextureSemantics, UniformBinding}; use librashader_reflect::reflect::ReflectShader; use librashader_runtime::image::{Image, UVDirection}; diff --git a/librashader-runtime-gl/src/filter_chain/filter_impl.rs b/librashader-runtime-gl/src/filter_chain/filter_impl.rs index a0c310a..f30723d 100644 --- a/librashader-runtime-gl/src/filter_chain/filter_impl.rs +++ b/librashader-runtime-gl/src/filter_chain/filter_impl.rs @@ -15,7 +15,7 @@ use librashader_presets::ShaderPreset; use librashader_reflect::back::cross::GlslVersion; use librashader_reflect::back::targets::GLSL; use librashader_reflect::back::CompileShader; -use librashader_reflect::front::shaderc::GlslangCompilation; +use librashader_reflect::front::GlslangCompilation; use librashader_reflect::reflect::semantics::{ MemberOffset, ShaderSemantics, TextureSemantics, UniformBinding, UniformMeta, }; diff --git a/librashader-runtime-vk/src/filter_chain.rs b/librashader-runtime-vk/src/filter_chain.rs index a808c0d..680e2c3 100644 --- a/librashader-runtime-vk/src/filter_chain.rs +++ b/librashader-runtime-vk/src/filter_chain.rs @@ -18,7 +18,7 @@ use librashader_common::{ImageFormat, Size, Viewport}; use librashader_presets::{ShaderPreset, TextureConfig}; use librashader_reflect::back::targets::SPIRV; use librashader_reflect::back::CompileShader; -use librashader_reflect::front::shaderc::GlslangCompilation; +use librashader_reflect::front::GlslangCompilation; use librashader_reflect::reflect::presets::CompilePreset; use librashader_reflect::reflect::semantics::{ShaderSemantics, TextureSemantics, UniformBinding}; use librashader_reflect::reflect::ReflectShader; diff --git a/librashader/src/lib.rs b/librashader/src/lib.rs index 68f3395..5eae6ad 100644 --- a/librashader/src/lib.rs +++ b/librashader/src/lib.rs @@ -95,7 +95,7 @@ pub mod reflect { /// Reflection via SPIRV-Cross. pub mod cross { - pub use librashader_reflect::front::shaderc::GlslangCompilation; + pub use librashader_reflect::front::GlslangCompilation; #[cfg(feature = "gl")] /// The version of GLSL to compile to. @@ -115,6 +115,7 @@ pub mod reflect { pub use librashader_reflect::reflect::presets; + pub use librashader_reflect::front::ShaderCompilation; #[doc(hidden)] #[cfg(feature = "internal")] /// Helper methods for runtimes.