Skip to content

Commit f8a0f19

Browse files
committed
reflect(wgsl): fix build flags when naga-in is disabled
1 parent fdf94ca commit f8a0f19

9 files changed

Lines changed: 157 additions & 153 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 21 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

librashader-reflect/src/back/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ pub mod hlsl;
88
pub mod msl;
99
pub mod spirv;
1010
pub mod targets;
11+
12+
#[cfg(feature = "wgsl")]
1113
pub mod wgsl;
1214

1315
use crate::back::targets::OutputTarget;

librashader-reflect/src/back/spirv.rs

Lines changed: 136 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -4,153 +4,163 @@ use crate::back::{
44
};
55
use crate::error::{ShaderCompileError, ShaderReflectError};
66
use crate::front::SpirvCompilation;
7-
#[cfg(feature = "cross")]
8-
use crate::reflect::cross::glsl::GlslReflect;
9-
#[cfg(feature = "cross")]
10-
use crate::reflect::cross::SpirvCross;
11-
use crate::reflect::naga::{Naga, NagaLoweringOptions, NagaReflect};
12-
#[cfg(feature = "cross")]
137
use crate::reflect::semantics::ShaderSemantics;
14-
#[cfg(feature = "cross")]
158
use crate::reflect::{ReflectShader, ShaderReflection};
16-
use naga::Module;
179

1810
#[cfg(feature = "cross")]
19-
pub(crate) struct WriteSpirV {
20-
// rely on GLSL to provide out reflection but we don't actually need the AST.
21-
pub(crate) reflect: GlslReflect,
22-
pub(crate) vertex: Vec<u32>,
23-
pub(crate) fragment: Vec<u32>,
24-
}
11+
mod cross {
12+
use super::*;
13+
use crate::reflect::cross::glsl::GlslReflect;
14+
15+
use crate::reflect::cross::SpirvCross;
2516

26-
#[cfg(all(feature = "cross", feature = "nightly"))]
27-
impl FromCompilation<SpirvCompilation, SpirvCross> for SPIRV {
28-
type Target = SPIRV;
29-
type Options = Option<()>;
30-
type Context = ();
31-
type Output = impl CompileReflectShader<Self::Target, SpirvCompilation, SpirvCross>;
32-
33-
fn from_compilation(
34-
compile: SpirvCompilation,
35-
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
36-
let reflect = GlslReflect::try_from(&compile)?;
37-
let vertex = compile.vertex;
38-
let fragment = compile.fragment;
39-
Ok(CompilerBackend {
40-
backend: WriteSpirV {
41-
reflect,
42-
vertex,
43-
fragment,
44-
},
45-
})
17+
pub(crate) struct WriteSpirV {
18+
// rely on GLSL to provide out reflection but we don't actually need the AST.
19+
pub(crate) reflect: GlslReflect,
20+
pub(crate) vertex: Vec<u32>,
21+
pub(crate) fragment: Vec<u32>,
4622
}
47-
}
4823

49-
#[cfg(all(feature = "cross", not(feature = "nightly")))]
50-
impl FromCompilation<SpirvCompilation, SpirvCross> for SPIRV {
51-
type Target = SPIRV;
52-
type Options = Option<()>;
53-
type Context = ();
54-
type Output = Box<dyn CompileReflectShader<Self::Target, SpirvCompilation, SpirvCross> + Send>;
55-
56-
fn from_compilation(
57-
compile: SpirvCompilation,
58-
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
59-
let reflect = GlslReflect::try_from(&compile)?;
60-
let vertex = compile.vertex;
61-
let fragment = compile.fragment;
62-
Ok(CompilerBackend {
63-
backend: Box::new(WriteSpirV {
64-
reflect,
65-
vertex,
66-
fragment,
67-
}),
68-
})
24+
#[cfg(feature = "nightly")]
25+
impl FromCompilation<SpirvCompilation, SpirvCross> for SPIRV {
26+
type Target = SPIRV;
27+
type Options = Option<()>;
28+
type Context = ();
29+
type Output = impl CompileReflectShader<Self::Target, SpirvCompilation, SpirvCross>;
30+
31+
fn from_compilation(
32+
compile: SpirvCompilation,
33+
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
34+
let reflect = GlslReflect::try_from(&compile)?;
35+
let vertex = compile.vertex;
36+
let fragment = compile.fragment;
37+
Ok(CompilerBackend {
38+
backend: WriteSpirV {
39+
reflect,
40+
vertex,
41+
fragment,
42+
},
43+
})
44+
}
6945
}
70-
}
7146

72-
#[cfg(feature = "cross")]
73-
impl ReflectShader for WriteSpirV {
74-
fn reflect(
75-
&mut self,
76-
pass_number: usize,
77-
semantics: &ShaderSemantics,
78-
) -> Result<ShaderReflection, ShaderReflectError> {
79-
self.reflect.reflect(pass_number, semantics)
47+
#[cfg(not(feature = "nightly"))]
48+
impl FromCompilation<SpirvCompilation, SpirvCross> for SPIRV {
49+
type Target = SPIRV;
50+
type Options = Option<()>;
51+
type Context = ();
52+
type Output = Box<dyn CompileReflectShader<Self::Target, SpirvCompilation, SpirvCross> + Send>;
53+
54+
fn from_compilation(
55+
compile: SpirvCompilation,
56+
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
57+
let reflect = GlslReflect::try_from(&compile)?;
58+
let vertex = compile.vertex;
59+
let fragment = compile.fragment;
60+
Ok(CompilerBackend {
61+
backend: Box::new(WriteSpirV {
62+
reflect,
63+
vertex,
64+
fragment,
65+
}),
66+
})
67+
}
68+
}
69+
70+
impl ReflectShader for WriteSpirV {
71+
fn reflect(
72+
&mut self,
73+
pass_number: usize,
74+
semantics: &ShaderSemantics,
75+
) -> Result<ShaderReflection, ShaderReflectError> {
76+
self.reflect.reflect(pass_number, semantics)
77+
}
78+
79+
fn validate(&mut self) -> Result<(), ShaderReflectError> {
80+
self.reflect.validate()
81+
}
8082
}
8183

82-
fn validate(&mut self) -> Result<(), ShaderReflectError> {
83-
self.reflect.validate()
84+
impl CompileShader<SPIRV> for WriteSpirV {
85+
type Options = Option<()>;
86+
type Context = ();
87+
88+
fn compile(
89+
self,
90+
_options: Self::Options,
91+
) -> Result<ShaderCompilerOutput<Vec<u32>, Self::Context>, ShaderCompileError> {
92+
Ok(ShaderCompilerOutput {
93+
vertex: self.vertex,
94+
fragment: self.fragment,
95+
context: (),
96+
})
97+
}
98+
99+
fn compile_boxed(
100+
self: Box<Self>,
101+
_options: Self::Options,
102+
) -> Result<ShaderCompilerOutput<Vec<u32>, Self::Context>, ShaderCompileError> {
103+
Ok(ShaderCompilerOutput {
104+
vertex: self.vertex,
105+
fragment: self.fragment,
106+
context: (),
107+
})
108+
}
84109
}
85110
}
86111

87112
#[cfg(feature = "cross")]
88-
impl CompileShader<SPIRV> for WriteSpirV {
89-
type Options = Option<()>;
90-
type Context = ();
91-
92-
fn compile(
93-
self,
94-
_options: Self::Options,
95-
) -> Result<ShaderCompilerOutput<Vec<u32>, Self::Context>, ShaderCompileError> {
96-
Ok(ShaderCompilerOutput {
97-
vertex: self.vertex,
98-
fragment: self.fragment,
99-
context: (),
100-
})
113+
pub(crate) use cross::*;
114+
115+
#[cfg(feature = "naga")]
116+
mod naga {
117+
use super::*;
118+
use ::naga::Module;
119+
use crate::reflect::naga::{Naga, NagaLoweringOptions, NagaReflect};
120+
121+
/// The context for a SPIRV compilation via Naga
122+
pub struct NagaSpirvContext {
123+
pub fragment: Module,
124+
pub vertex: Module,
101125
}
102126

103-
fn compile_boxed(
104-
self: Box<Self>,
105-
_options: Self::Options,
106-
) -> Result<ShaderCompilerOutput<Vec<u32>, Self::Context>, ShaderCompileError> {
107-
Ok(ShaderCompilerOutput {
108-
vertex: self.vertex,
109-
fragment: self.fragment,
110-
context: (),
111-
})
127+
#[cfg(all(feature = "nightly", feature = "naga"))]
128+
impl FromCompilation<SpirvCompilation, Naga> for SPIRV {
129+
type Target = SPIRV;
130+
type Options = NagaSpirvOptions;
131+
type Context = NagaSpirvContext;
132+
type Output = impl CompileReflectShader<Self::Target, SpirvCompilation, Naga>;
133+
134+
fn from_compilation(
135+
compile: SpirvCompilation,
136+
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
137+
Ok(CompilerBackend {
138+
backend: NagaReflect::try_from(&compile)?,
139+
})
140+
}
112141
}
113-
}
114142

115-
/// The context for a SPIRV compilation via Naga
116-
pub struct NagaSpirvContext {
117-
pub fragment: Module,
118-
pub vertex: Module,
119-
}
120-
121-
#[cfg(feature = "nightly")]
122-
impl FromCompilation<SpirvCompilation, Naga> for SPIRV {
123-
type Target = SPIRV;
124-
type Options = NagaSpirvOptions;
125-
type Context = NagaSpirvContext;
126-
type Output = impl CompileReflectShader<Self::Target, SpirvCompilation, Naga>;
127-
128-
fn from_compilation(
129-
compile: SpirvCompilation,
130-
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
131-
Ok(CompilerBackend {
132-
backend: NagaReflect::try_from(&compile)?,
133-
})
143+
#[cfg(not(feature = "nightly"))]
144+
impl FromCompilation<SpirvCompilation, Naga> for SPIRV {
145+
type Target = SPIRV;
146+
type Options = NagaSpirvOptions;
147+
type Context = NagaSpirvContext;
148+
type Output = Box<dyn CompileReflectShader<Self::Target, SpirvCompilation, Naga> + Send>;
149+
150+
fn from_compilation(
151+
compile: SpirvCompilation,
152+
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
153+
Ok(CompilerBackend {
154+
backend: Box::new(NagaReflect::try_from(&compile)?),
155+
})
156+
}
134157
}
135-
}
136158

137-
#[cfg(not(feature = "nightly"))]
138-
impl FromCompilation<SpirvCompilation, Naga> for SPIRV {
139-
type Target = SPIRV;
140-
type Options = NagaSpirvOptions;
141-
type Context = NagaSpirvContext;
142-
type Output = Box<dyn CompileReflectShader<Self::Target, SpirvCompilation, Naga> + Send>;
143-
144-
fn from_compilation(
145-
compile: SpirvCompilation,
146-
) -> Result<CompilerBackend<Self::Output>, ShaderReflectError> {
147-
Ok(CompilerBackend {
148-
backend: Box::new(NagaReflect::try_from(&compile)?),
149-
})
159+
pub struct NagaSpirvOptions {
160+
pub lowering: NagaLoweringOptions,
161+
pub version: (u8, u8),
150162
}
151163
}
152164

153-
pub struct NagaSpirvOptions {
154-
pub lowering: NagaLoweringOptions,
155-
pub version: (u8, u8),
156-
}
165+
#[cfg(feature = "naga")]
166+
pub use naga::*;

librashader-reflect/src/back/wgsl.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::back::targets::WGSL;
22
use crate::back::{CompileReflectShader, CompilerBackend, FromCompilation};
33
use crate::error::ShaderReflectError;
4-
use crate::front::{SpirvCompilation, WgslCompilation};
4+
use crate::front::SpirvCompilation;
55
use crate::reflect::naga::{Naga, NagaLoweringOptions, NagaReflect};
66
use naga::Module;
77

@@ -43,6 +43,9 @@ impl FromCompilation<SpirvCompilation, Naga> for WGSL {
4343
}
4444
}
4545

46+
#[cfg(feature = "naga-in")]
47+
use crate::front::WgslCompilation;
48+
4649
#[cfg(all(feature = "nightly", feature = "naga-in"))]
4750
impl FromCompilation<WgslCompilation, Naga> for WGSL {
4851
type Target = WGSL;

librashader-reflect/src/front/glslang.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::front::spirv_passes::{link_input_outputs, load_module};
88
use crate::front::{ShaderInputCompiler, ShaderReflectObject, SpirvCompilation};
99

1010
/// glslang compiler
11+
///
12+
/// The most common path, to compile GLSL to SPIR-V.
1113
pub struct Glslang;
1214

1315
impl ShaderReflectObject for SpirvCompilation {

0 commit comments

Comments
 (0)