Skip to content

Commit

Permalink
change how to select bevy-glsl-to-spirv or shaderc (#1819)
Browse files Browse the repository at this point in the history
`cfg` for `bevy-glsl-to-spirv` use now mimics https://github.com/cart/glsl-to-spirv/blob/master/Cargo.toml

fixes #898 
fixes #1348 
fixes #1942 
fixes #1078
  • Loading branch information
mockersf committed Apr 19, 2021
1 parent 3eb828f commit f1ddd7a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 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"), not(all(target_arch = "aarch64", target_os = "macos"))))'.dependencies]
[target.'cfg(any(all(target_arch="x86_64", target_os="linux", target_env="gnu"), all(target_arch="x86_64", target_os="macos"), all(target_arch="aarch64", target_os="android"), all(target_arch="armv7", target_os="androidabi"), all(target_arch="x86_64", target_os="windows", target_env="msvc")))'.dependencies]
bevy-glsl-to-spirv = "0.2.0"

[target.'cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))'.dependencies]
[target.'cfg(not(any(target_arch = "wasm32", all(target_arch="x86_64", target_os="linux", target_env="gnu"), all(target_arch="x86_64", target_os="macos"), all(target_arch="aarch64", target_os="android"), all(target_arch="armv7", target_os="androidabi"), all(target_arch="x86_64", target_os="windows", target_env="msvc"))))'.dependencies]
shaderc = "0.7.0"

[features]
Expand Down
65 changes: 52 additions & 13 deletions crates/bevy_render/src/shader/shader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,47 @@ pub enum ShaderError {
#[error("Shader compilation error:\n{0}")]
Compilation(String),

#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
#[cfg(not(any(
target_arch = "wasm32",
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
all(target_arch = "x86_64", target_os = "macos"),
all(target_arch = "aarch64", target_os = "android"),
all(target_arch = "armv7", target_os = "androidabi"),
all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"),
)))]
/// shaderc error.
#[error("shaderc error: {0}")]
ShaderC(#[from] shaderc::Error),

#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
#[cfg(not(any(
target_arch = "wasm32",
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
all(target_arch = "x86_64", target_os = "macos"),
all(target_arch = "aarch64", target_os = "android"),
all(target_arch = "armv7", target_os = "androidabi"),
all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"),
)))]
#[error("Error initializing shaderc Compiler")]
ErrorInitializingShadercCompiler,

#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
#[cfg(not(any(
target_arch = "wasm32",
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
all(target_arch = "x86_64", target_os = "macos"),
all(target_arch = "aarch64", target_os = "android"),
all(target_arch = "armv7", target_os = "androidabi"),
all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"),
)))]
#[error("Error initializing shaderc CompileOptions")]
ErrorInitializingShadercCompileOptions,
}

#[cfg(all(
not(target_os = "ios"),
not(target_arch = "wasm32"),
not(all(target_arch = "aarch64", target_os = "macos"))
#[cfg(any(
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
all(target_arch = "x86_64", target_os = "macos"),
all(target_arch = "aarch64", target_os = "android"),
all(target_arch = "armv7", target_os = "androidabi"),
all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"),
))]
impl From<ShaderStage> for bevy_glsl_to_spirv::ShaderType {
fn from(s: ShaderStage) -> bevy_glsl_to_spirv::ShaderType {
Expand All @@ -56,10 +79,12 @@ impl From<ShaderStage> for bevy_glsl_to_spirv::ShaderType {
}
}

#[cfg(all(
not(target_os = "ios"),
not(target_arch = "wasm32"),
not(all(target_arch = "aarch64", target_os = "macos"))
#[cfg(any(
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
all(target_arch = "x86_64", target_os = "macos"),
all(target_arch = "aarch64", target_os = "android"),
all(target_arch = "armv7", target_os = "androidabi"),
all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"),
))]
pub fn glsl_to_spirv(
glsl_source: &str,
Expand All @@ -70,7 +95,14 @@ pub fn glsl_to_spirv(
.map_err(ShaderError::Compilation)
}

#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
#[cfg(not(any(
target_arch = "wasm32",
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
all(target_arch = "x86_64", target_os = "macos"),
all(target_arch = "aarch64", target_os = "android"),
all(target_arch = "armv7", target_os = "androidabi"),
all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"),
)))]
impl Into<shaderc::ShaderKind> for ShaderStage {
fn into(self) -> shaderc::ShaderKind {
match self {
Expand All @@ -81,7 +113,14 @@ impl Into<shaderc::ShaderKind> for ShaderStage {
}
}

#[cfg(any(target_os = "ios", all(target_arch = "aarch64", target_os = "macos")))]
#[cfg(not(any(
target_arch = "wasm32",
all(target_arch = "x86_64", target_os = "linux", target_env = "gnu"),
all(target_arch = "x86_64", target_os = "macos"),
all(target_arch = "aarch64", target_os = "android"),
all(target_arch = "armv7", target_os = "androidabi"),
all(target_arch = "x86_64", target_os = "windows", target_env = "msvc"),
)))]
pub fn glsl_to_spirv(
glsl_source: &str,
stage: ShaderStage,
Expand Down

0 comments on commit f1ddd7a

Please sign in to comment.