2022-11-11 17:44:41 +11:00
|
|
|
pub mod cross;
|
2022-11-07 16:25:11 +11:00
|
|
|
pub mod targets;
|
|
|
|
|
|
|
|
use std::fmt::Debug;
|
2022-11-22 08:53:36 +11:00
|
|
|
use crate::back::targets::OutputTarget;
|
|
|
|
use crate::error::{ShaderCompileError, ShaderReflectError};
|
|
|
|
use crate::reflect::{ReflectShader, ShaderReflection};
|
|
|
|
use crate::reflect::semantics::ReflectSemantics;
|
2022-11-07 16:25:11 +11:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
2022-11-11 17:53:02 +11:00
|
|
|
pub struct ShaderCompilerOutput<T, Context = ()> {
|
|
|
|
pub vertex: T,
|
|
|
|
pub fragment: T,
|
2022-11-09 17:11:25 +11:00
|
|
|
pub context: Context,
|
2022-11-07 16:25:11 +11:00
|
|
|
}
|
2022-11-22 08:53:36 +11:00
|
|
|
|
|
|
|
pub trait CompileShader<T: OutputTarget> {
|
|
|
|
type Options;
|
|
|
|
type Context;
|
|
|
|
|
|
|
|
fn compile(
|
|
|
|
self,
|
|
|
|
options: Self::Options,
|
|
|
|
) -> Result<ShaderCompilerOutput<T::Output, Self::Context>, ShaderCompileError>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T, E> CompileShader<E> for CompilerBackend<T>
|
|
|
|
where
|
|
|
|
T: CompileShader<E>,
|
|
|
|
E: OutputTarget,
|
|
|
|
{
|
|
|
|
type Options = T::Options;
|
|
|
|
type Context = T::Context;
|
|
|
|
|
|
|
|
fn compile(
|
|
|
|
self,
|
|
|
|
options: Self::Options,
|
|
|
|
) -> Result<ShaderCompilerOutput<E::Output, Self::Context>, ShaderCompileError> {
|
|
|
|
self.backend.compile(options)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait FromCompilation<T> {
|
|
|
|
type Target: OutputTarget;
|
|
|
|
type Options;
|
|
|
|
type Context;
|
|
|
|
|
|
|
|
fn from_compilation(
|
|
|
|
compile: T,
|
|
|
|
) -> Result<
|
|
|
|
CompilerBackend<impl CompileShader<Self::Target, Context = Self::Context> + ReflectShader>,
|
|
|
|
ShaderReflectError,
|
|
|
|
>;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CompilerBackend<T> {
|
|
|
|
pub(crate) backend: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> ReflectShader for CompilerBackend<T>
|
|
|
|
where
|
|
|
|
T: ReflectShader,
|
|
|
|
{
|
|
|
|
fn reflect(
|
|
|
|
&mut self,
|
|
|
|
pass_number: usize,
|
|
|
|
semantics: &ReflectSemantics,
|
|
|
|
) -> Result<ShaderReflection, ShaderReflectError> {
|
|
|
|
self.backend.reflect(pass_number, semantics)
|
|
|
|
}
|
|
|
|
}
|