Skip to content

Commit

Permalink
Use shaderc for aarch64-apple-darwin. (#1027)
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv authored Dec 9, 2020
1 parent f53ee54 commit 66f972c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
4 changes: 2 additions & 2 deletions crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
33 changes: 26 additions & 7 deletions crates/bevy_render/src/shader/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bevy_glsl_to_spirv::ShaderType> for ShaderStage {
fn into(self) -> bevy_glsl_to_spirv::ShaderType {
match self {
Expand All @@ -43,7 +56,11 @@ impl Into<bevy_glsl_to_spirv::ShaderType> 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,
Expand All @@ -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<shaderc::ShaderKind> for ShaderStage {
fn into(self) -> shaderc::ShaderKind {
match self {
Expand All @@ -64,14 +81,16 @@ impl Into<shaderc::ShaderKind> 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<Vec<u32>, 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);
Expand Down

0 comments on commit 66f972c

Please sign in to comment.