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

[Merged by Bors] - change how to select bevy-glsl-to-spirv or shaderc #1819

Closed
wants to merge 4 commits into from
Closed
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"), 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