diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index ecd88c787293c..8528587e037ca 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -44,10 +44,10 @@ parking_lot = "0.11.0" [target.'cfg(not(target_arch = "wasm32"))'.dependencies] spirv-reflect = "0.2.3" -[target.'cfg(all(not(target_os = "ios"), not(target_arch = "wasm32")))'.dependencies] +[target.'cfg(all(not(target_os = "ios"), not(target_arch = "wasm32"), not(all(target_arch = "aarch64", target_os = "macos"))))'.dependencies] bevy-glsl-to-spirv = "0.2.0" -[target.'cfg(target_os = "ios")'.dependencies] +[target.'cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))'.dependencies] shaderc = "0.7.0" [features] diff --git a/crates/bevy_render/src/shader/shader.rs b/crates/bevy_render/src/shader/shader.rs index 6fffa1e0ca7e8..19a89af632f0f 100644 --- a/crates/bevy_render/src/shader/shader.rs +++ b/crates/bevy_render/src/shader/shader.rs @@ -26,13 +26,26 @@ pub enum ShaderError { /// Shader compilation error. #[error("Shader compilation error: {0}")] Compilation(String), - #[cfg(target_os = "ios")] + + #[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))] /// shaderc error. #[error("shaderc error")] ShaderC(#[from] shaderc::Error), + + #[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))] + #[error("Error initializing shaderc Compiler")] + ErrorInitializingShadercCompiler, + + #[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))] + #[error("Error initializing shaderc CompileOptions")] + ErrorInitializingShadercCompileOptions, } -#[cfg(all(not(target_os = "ios"), not(target_arch = "wasm32")))] +#[cfg(all( + not(target_os = "ios"), + not(target_arch = "wasm32"), + not(all(target_arch = "aarch64", target_os = "macos")) +))] impl Into for ShaderStage { fn into(self) -> bevy_glsl_to_spirv::ShaderType { match self { @@ -43,7 +56,11 @@ impl Into for ShaderStage { } } -#[cfg(all(not(target_os = "ios"), not(target_arch = "wasm32")))] +#[cfg(all( + not(target_os = "ios"), + not(target_arch = "wasm32"), + not(all(target_arch = "aarch64", target_os = "macos")) +))] pub fn glsl_to_spirv( glsl_source: &str, stage: ShaderStage, @@ -53,7 +70,7 @@ pub fn glsl_to_spirv( .map_err(ShaderError::Compilation) } -#[cfg(target_os = "ios")] +#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))] impl Into for ShaderStage { fn into(self) -> shaderc::ShaderKind { match self { @@ -64,14 +81,16 @@ impl Into for ShaderStage { } } -#[cfg(target_os = "ios")] +#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))] pub fn glsl_to_spirv( glsl_source: &str, stage: ShaderStage, shader_defs: Option<&[String]>, ) -> Result, ShaderError> { - let mut compiler = shaderc::Compiler::new()?; - let mut options = shaderc::CompileOptions::new()?; + let mut compiler = + shaderc::Compiler::new().ok_or(ShaderError::ErrorInitializingShadercCompiler)?; + let mut options = shaderc::CompileOptions::new() + .ok_or(ShaderError::ErrorInitializingShadercCompileOptions)?; if let Some(shader_defs) = shader_defs { for def in shader_defs.iter() { options.add_macro_definition(def, None);