1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
pub mod cross;
#[cfg(feature = "dxil")]
pub mod dxil;
mod spirv;
pub mod targets;
use crate::back::targets::OutputTarget;
use crate::error::{ShaderCompileError, ShaderReflectError};
use crate::reflect::semantics::ShaderSemantics;
use crate::reflect::{ReflectShader, ShaderReflection};
use std::fmt::Debug;
#[derive(Debug)]
pub struct ShaderCompilerOutput<T, Context = ()> {
pub vertex: T,
pub fragment: T,
pub context: Context,
}
pub trait CompileShader<T: OutputTarget> {
type Options;
type Context;
fn compile(
self,
options: Self::Options,
) -> Result<ShaderCompilerOutput<T::Output, Self::Context>, ShaderCompileError>;
}
pub trait CompileReflectShader<T: OutputTarget, C>:
CompileShader<
T,
Options = <T as FromCompilation<C>>::Options,
Context = <T as FromCompilation<C>>::Context,
> + ReflectShader
where
T: FromCompilation<C>,
{
}
impl<T, C, O> CompileReflectShader<T, C> for O
where
T: OutputTarget,
T: FromCompilation<C>,
O: ReflectShader,
O: CompileShader<
T,
Options = <T as FromCompilation<C>>::Options,
Context = <T as FromCompilation<C>>::Context,
>,
{
}
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;
type Output: CompileShader<Self::Target, Context = Self::Context, Options = Self::Options>
+ ReflectShader;
fn from_compilation(compile: T) -> Result<CompilerBackend<Self::Output>, 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: &ShaderSemantics,
) -> Result<ShaderReflection, ShaderReflectError> {
self.backend.reflect(pass_number, semantics)
}
}