Skip to content

Commit 66f972c

Browse files
authored
Use shaderc for aarch64-apple-darwin. (#1027)
1 parent f53ee54 commit 66f972c

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

crates/bevy_render/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ parking_lot = "0.11.0"
4444
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
4545
spirv-reflect = "0.2.3"
4646

47-
[target.'cfg(all(not(target_os = "ios"), not(target_arch = "wasm32")))'.dependencies]
47+
[target.'cfg(all(not(target_os = "ios"), not(target_arch = "wasm32"), not(all(target_arch = "aarch64", target_os = "macos"))))'.dependencies]
4848
bevy-glsl-to-spirv = "0.2.0"
4949

50-
[target.'cfg(target_os = "ios")'.dependencies]
50+
[target.'cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))'.dependencies]
5151
shaderc = "0.7.0"
5252

5353
[features]

crates/bevy_render/src/shader/shader.rs

+26-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,26 @@ pub enum ShaderError {
2626
/// Shader compilation error.
2727
#[error("Shader compilation error: {0}")]
2828
Compilation(String),
29-
#[cfg(target_os = "ios")]
29+
30+
#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
3031
/// shaderc error.
3132
#[error("shaderc error")]
3233
ShaderC(#[from] shaderc::Error),
34+
35+
#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
36+
#[error("Error initializing shaderc Compiler")]
37+
ErrorInitializingShadercCompiler,
38+
39+
#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
40+
#[error("Error initializing shaderc CompileOptions")]
41+
ErrorInitializingShadercCompileOptions,
3342
}
3443

35-
#[cfg(all(not(target_os = "ios"), not(target_arch = "wasm32")))]
44+
#[cfg(all(
45+
not(target_os = "ios"),
46+
not(target_arch = "wasm32"),
47+
not(all(target_arch = "aarch64", target_os = "macos"))
48+
))]
3649
impl Into<bevy_glsl_to_spirv::ShaderType> for ShaderStage {
3750
fn into(self) -> bevy_glsl_to_spirv::ShaderType {
3851
match self {
@@ -43,7 +56,11 @@ impl Into<bevy_glsl_to_spirv::ShaderType> for ShaderStage {
4356
}
4457
}
4558

46-
#[cfg(all(not(target_os = "ios"), not(target_arch = "wasm32")))]
59+
#[cfg(all(
60+
not(target_os = "ios"),
61+
not(target_arch = "wasm32"),
62+
not(all(target_arch = "aarch64", target_os = "macos"))
63+
))]
4764
pub fn glsl_to_spirv(
4865
glsl_source: &str,
4966
stage: ShaderStage,
@@ -53,7 +70,7 @@ pub fn glsl_to_spirv(
5370
.map_err(ShaderError::Compilation)
5471
}
5572

56-
#[cfg(target_os = "ios")]
73+
#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
5774
impl Into<shaderc::ShaderKind> for ShaderStage {
5875
fn into(self) -> shaderc::ShaderKind {
5976
match self {
@@ -64,14 +81,16 @@ impl Into<shaderc::ShaderKind> for ShaderStage {
6481
}
6582
}
6683

67-
#[cfg(target_os = "ios")]
84+
#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
6885
pub fn glsl_to_spirv(
6986
glsl_source: &str,
7087
stage: ShaderStage,
7188
shader_defs: Option<&[String]>,
7289
) -> Result<Vec<u32>, ShaderError> {
73-
let mut compiler = shaderc::Compiler::new()?;
74-
let mut options = shaderc::CompileOptions::new()?;
90+
let mut compiler =
91+
shaderc::Compiler::new().ok_or(ShaderError::ErrorInitializingShadercCompiler)?;
92+
let mut options = shaderc::CompileOptions::new()
93+
.ok_or(ShaderError::ErrorInitializingShadercCompileOptions)?;
7594
if let Some(shader_defs) = shader_defs {
7695
for def in shader_defs.iter() {
7796
options.add_macro_definition(def, None);

0 commit comments

Comments
 (0)