reflect: move GlslangCompilation up a level and remove intermediate modules in reflect::front
This commit is contained in:
parent
b3dd378b5b
commit
261710d639
|
@ -1,7 +1,7 @@
|
||||||
use crate::back::targets::{GLSL, HLSL};
|
use crate::back::targets::{GLSL, HLSL};
|
||||||
use crate::back::{CompileShader, CompilerBackend, FromCompilation};
|
use crate::back::{CompileShader, CompilerBackend, FromCompilation};
|
||||||
use crate::error::ShaderReflectError;
|
use crate::error::ShaderReflectError;
|
||||||
use crate::front::shaderc::GlslangCompilation;
|
use crate::front::GlslangCompilation;
|
||||||
use crate::reflect::cross::{CompiledProgram, GlslReflect, HlslReflect};
|
use crate::reflect::cross::{CompiledProgram, GlslReflect, HlslReflect};
|
||||||
use crate::reflect::ReflectShader;
|
use crate::reflect::ReflectShader;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::back::targets::SPIRV;
|
use crate::back::targets::SPIRV;
|
||||||
use crate::back::{CompileShader, CompilerBackend, FromCompilation, ShaderCompilerOutput};
|
use crate::back::{CompileShader, CompilerBackend, FromCompilation, ShaderCompilerOutput};
|
||||||
use crate::error::{ShaderCompileError, ShaderReflectError};
|
use crate::error::{ShaderCompileError, ShaderReflectError};
|
||||||
use crate::front::shaderc::GlslangCompilation;
|
use crate::front::GlslangCompilation;
|
||||||
use crate::reflect::cross::GlslReflect;
|
use crate::reflect::cross::GlslReflect;
|
||||||
use crate::reflect::semantics::ShaderSemantics;
|
use crate::reflect::semantics::ShaderSemantics;
|
||||||
use crate::reflect::{ReflectShader, ShaderReflection};
|
use crate::reflect::{ReflectShader, ShaderReflection};
|
||||||
|
|
|
@ -26,7 +26,7 @@ impl OutputTarget for SPIRV {
|
||||||
mod test {
|
mod test {
|
||||||
use crate::back::targets::GLSL;
|
use crate::back::targets::GLSL;
|
||||||
use crate::back::FromCompilation;
|
use crate::back::FromCompilation;
|
||||||
use crate::front::shaderc::GlslangCompilation;
|
use crate::front::GlslangCompilation;
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn test_compile(value: GlslangCompilation) {
|
pub fn test_compile(value: GlslangCompilation) {
|
||||||
let _x = GLSL::from_compilation(value).unwrap();
|
let _x = GLSL::from_compilation(value).unwrap();
|
||||||
|
|
|
@ -2,11 +2,23 @@ use crate::error::ShaderCompileError;
|
||||||
use librashader_preprocess::ShaderSource;
|
use librashader_preprocess::ShaderSource;
|
||||||
|
|
||||||
#[cfg(feature = "unstable-naga")]
|
#[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 {
|
pub trait ShaderCompilation: Sized {
|
||||||
/// Compile the input shader source file into a compilation unit.
|
/// Compile the input shader source file into a compilation unit.
|
||||||
fn compile(source: &ShaderSource) -> Result<Self, ShaderCompileError>;
|
fn compile(source: &ShaderSource) -> Result<Self, ShaderCompileError>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: for<'a> TryFrom<&'a ShaderSource, Error = ShaderCompileError>> ShaderCompilation for T {
|
||||||
|
fn compile(source: &ShaderSource) -> Result<Self, ShaderCompileError> {
|
||||||
|
source.try_into()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -10,7 +10,16 @@ pub struct NagaCompilation {
|
||||||
pub(crate) fragment: Module,
|
pub(crate) fragment: Module,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn compile_spirv(source: &ShaderSource) -> Result<NagaCompilation, ShaderCompileError> {
|
impl TryFrom<&ShaderSource> for NagaCompilation {
|
||||||
|
type Error = ShaderCompileError;
|
||||||
|
|
||||||
|
/// Tries to compile SPIR-V from the provided shader source.
|
||||||
|
fn try_from(source: &ShaderSource) -> Result<Self, Self::Error> {
|
||||||
|
compile_spirv(source)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn compile_spirv(source: &ShaderSource) -> Result<NagaCompilation, ShaderCompileError> {
|
||||||
let mut parser = Parser::default();
|
let mut parser = Parser::default();
|
||||||
let vertex = parser.parse(&Options::from(ShaderStage::Vertex), &source.vertex)?;
|
let vertex = parser.parse(&Options::from(ShaderStage::Vertex), &source.vertex)?;
|
||||||
let fragment = parser.parse(&Options::from(ShaderStage::Fragment), &source.fragment)?;
|
let fragment = parser.parse(&Options::from(ShaderStage::Fragment), &source.fragment)?;
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::error::ShaderCompileError;
|
use crate::error::ShaderCompileError;
|
||||||
use crate::front::ShaderCompilation;
|
|
||||||
use librashader_preprocess::ShaderSource;
|
use librashader_preprocess::ShaderSource;
|
||||||
use shaderc::{CompilationArtifact, CompileOptions, Limit, ShaderKind};
|
use shaderc::{CompilationArtifact, CompileOptions, Limit, ShaderKind};
|
||||||
|
|
||||||
|
@ -16,12 +15,6 @@ impl GlslangCompilation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ShaderCompilation for GlslangCompilation {
|
|
||||||
fn compile(source: &ShaderSource) -> Result<Self, ShaderCompileError> {
|
|
||||||
GlslangCompilation::compile(source)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TryFrom<&ShaderSource> for GlslangCompilation {
|
impl TryFrom<&ShaderSource> for GlslangCompilation {
|
||||||
type Error = ShaderCompileError;
|
type Error = ShaderCompileError;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::error::{SemanticsErrorKind, ShaderCompileError, ShaderReflectError};
|
use crate::error::{SemanticsErrorKind, ShaderCompileError, ShaderReflectError};
|
||||||
use crate::front::shaderc::GlslangCompilation;
|
use crate::front::GlslangCompilation;
|
||||||
use crate::reflect::semantics::{
|
use crate::reflect::semantics::{
|
||||||
BindingMeta, BindingStage, MemberOffset, PushReflection, ShaderReflection, ShaderSemantics,
|
BindingMeta, BindingStage, MemberOffset, PushReflection, ShaderReflection, ShaderSemantics,
|
||||||
TextureBinding, TextureSemanticMap, TextureSemantics, TextureSizeMeta, TypeInfo, UboReflection,
|
TextureBinding, TextureSemanticMap, TextureSemantics, TextureSizeMeta, TypeInfo, UboReflection,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use crate::back::targets::OutputTarget;
|
use crate::back::targets::OutputTarget;
|
||||||
use crate::back::{CompileShader, CompilerBackend, FromCompilation};
|
use crate::back::{CompilerBackend, FromCompilation};
|
||||||
use crate::error::{ShaderCompileError, ShaderReflectError};
|
use crate::error::{ShaderCompileError, ShaderReflectError};
|
||||||
use crate::front::ShaderCompilation;
|
use crate::front::ShaderCompilation;
|
||||||
use crate::reflect::semantics::{
|
use crate::reflect::semantics::{
|
||||||
|
|
|
@ -4,7 +4,7 @@ use librashader_common::{ImageFormat, Size, Viewport};
|
||||||
use librashader_presets::{ShaderPreset, TextureConfig};
|
use librashader_presets::{ShaderPreset, TextureConfig};
|
||||||
use librashader_reflect::back::targets::HLSL;
|
use librashader_reflect::back::targets::HLSL;
|
||||||
use librashader_reflect::back::CompileShader;
|
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::semantics::{ShaderSemantics, TextureSemantics, UniformBinding};
|
||||||
use librashader_reflect::reflect::ReflectShader;
|
use librashader_reflect::reflect::ReflectShader;
|
||||||
use librashader_runtime::image::{Image, UVDirection};
|
use librashader_runtime::image::{Image, UVDirection};
|
||||||
|
|
|
@ -15,7 +15,7 @@ use librashader_presets::ShaderPreset;
|
||||||
use librashader_reflect::back::cross::GlslVersion;
|
use librashader_reflect::back::cross::GlslVersion;
|
||||||
use librashader_reflect::back::targets::GLSL;
|
use librashader_reflect::back::targets::GLSL;
|
||||||
use librashader_reflect::back::CompileShader;
|
use librashader_reflect::back::CompileShader;
|
||||||
use librashader_reflect::front::shaderc::GlslangCompilation;
|
use librashader_reflect::front::GlslangCompilation;
|
||||||
use librashader_reflect::reflect::semantics::{
|
use librashader_reflect::reflect::semantics::{
|
||||||
MemberOffset, ShaderSemantics, TextureSemantics, UniformBinding, UniformMeta,
|
MemberOffset, ShaderSemantics, TextureSemantics, UniformBinding, UniformMeta,
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,7 +18,7 @@ use librashader_common::{ImageFormat, Size, Viewport};
|
||||||
use librashader_presets::{ShaderPreset, TextureConfig};
|
use librashader_presets::{ShaderPreset, TextureConfig};
|
||||||
use librashader_reflect::back::targets::SPIRV;
|
use librashader_reflect::back::targets::SPIRV;
|
||||||
use librashader_reflect::back::CompileShader;
|
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::presets::CompilePreset;
|
||||||
use librashader_reflect::reflect::semantics::{ShaderSemantics, TextureSemantics, UniformBinding};
|
use librashader_reflect::reflect::semantics::{ShaderSemantics, TextureSemantics, UniformBinding};
|
||||||
use librashader_reflect::reflect::ReflectShader;
|
use librashader_reflect::reflect::ReflectShader;
|
||||||
|
|
|
@ -95,7 +95,7 @@ pub mod reflect {
|
||||||
|
|
||||||
/// Reflection via SPIRV-Cross.
|
/// Reflection via SPIRV-Cross.
|
||||||
pub mod cross {
|
pub mod cross {
|
||||||
pub use librashader_reflect::front::shaderc::GlslangCompilation;
|
pub use librashader_reflect::front::GlslangCompilation;
|
||||||
|
|
||||||
#[cfg(feature = "gl")]
|
#[cfg(feature = "gl")]
|
||||||
/// The version of GLSL to compile to.
|
/// The version of GLSL to compile to.
|
||||||
|
@ -115,6 +115,7 @@ pub mod reflect {
|
||||||
|
|
||||||
pub use librashader_reflect::reflect::presets;
|
pub use librashader_reflect::reflect::presets;
|
||||||
|
|
||||||
|
pub use librashader_reflect::front::ShaderCompilation;
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
#[cfg(feature = "internal")]
|
#[cfg(feature = "internal")]
|
||||||
/// Helper methods for runtimes.
|
/// Helper methods for runtimes.
|
||||||
|
|
Loading…
Reference in a new issue