Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use shaderc for aarch64-apple-darwin. #1027

Merged
merged 1 commit into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()?;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines were not compiling prior to my pull request. Both of these lines return Option, whereas the function signature returns Result.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing it ❤️

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