From f1ddd7a2adbf06f59b1b8cab3066fb8467a90f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois?= Date: Mon, 19 Apr 2021 21:28:30 +0000 Subject: [PATCH] change how to select bevy-glsl-to-spirv or shaderc (#1819) `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 --- crates/bevy_render/Cargo.toml | 4 +- crates/bevy_render/src/shader/shader.rs | 65 ++++++++++++++++++++----- 2 files changed, 54 insertions(+), 15 deletions(-) diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index d79870b38b..4345723745 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"), 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] diff --git a/crates/bevy_render/src/shader/shader.rs b/crates/bevy_render/src/shader/shader.rs index 5f33c31e23..6ce291f670 100644 --- a/crates/bevy_render/src/shader/shader.rs +++ b/crates/bevy_render/src/shader/shader.rs @@ -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 for bevy_glsl_to_spirv::ShaderType { fn from(s: ShaderStage) -> bevy_glsl_to_spirv::ShaderType { @@ -56,10 +79,12 @@ impl From 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, @@ -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 for ShaderStage { fn into(self) -> shaderc::ShaderKind { match self { @@ -81,7 +113,14 @@ impl Into 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,