do not depend on spirv on wasm target (#689)

do not use spirv for wasm target
This commit is contained in:
Mariusz Kryński 2020-10-16 20:12:55 +02:00 committed by GitHub
parent 9db8ae7a16
commit fccfa12d3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 69 additions and 20 deletions

View File

@ -3,7 +3,7 @@
## Unreleased
### Added
- [Do not depend on spirv on wasm32 target][689]
- [Another fast compile flag for macOS][552]
### Changed
@ -15,7 +15,7 @@
- Individual color-components must now be accessed through setters and getters: `.r`, `.g`, `.b`, `.a`, `.set_r`, `.set_g`, `.set_b`, `.set_a`, and the corresponding methods with the `*_linear` suffix.
- Despawning an entity multiple times causes a debug-level log message to be emitted instead of a panic [649] [651]
[689]: https://github.com/bevyengine/bevy/pull/689
[552]: https://github.com/bevyengine/bevy/pull/552
[616]: https://github.com/bevyengine/bevy/pull/616
[649]: https://github.com/bevyengine/bevy/pull/649

View File

@ -27,7 +27,6 @@ bevy_window = { path = "../bevy_window", version = "0.2.1" }
bevy_utils = { path = "../bevy_utils", version = "0.2.1" }
# rendering
spirv-reflect = "0.2.3"
image = { version = "0.23", default-features = false }
# misc
@ -45,7 +44,10 @@ hex = "0.4.2"
hexasphere = "1.0.0"
parking_lot = "0.11.0"
[target.'cfg(not(target_os = "ios"))'.dependencies]
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
spirv-reflect = "0.2.3"
[target.'cfg(all(not(target_os = "ios"), not(target_arch = "wasm32")))'.dependencies]
bevy-glsl-to-spirv = "0.1.7"
[target.'cfg(target_os = "ios")'.dependencies]

View File

@ -1,8 +1,26 @@
#[allow(clippy::module_inception)]
mod shader;
mod shader_defs;
#[cfg(not(target_arch = "wasm32"))]
mod shader_reflect;
#[cfg(target_arch = "wasm32")]
#[path = "shader_reflect_wasm.rs"]
mod shader_reflect;
pub use shader::*;
pub use shader_defs::*;
pub use shader_reflect::*;
use crate::pipeline::{BindGroupDescriptor, VertexBufferDescriptor};
/// Defines the memory layout of a shader
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ShaderLayout {
pub bind_groups: Vec<BindGroupDescriptor>,
pub vertex_buffer_descriptors: Vec<VertexBufferDescriptor>,
pub entry_point: String,
}
pub const GL_VERTEX_INDEX: &str = "gl_VertexIndex";

View File

@ -10,7 +10,7 @@ pub enum ShaderStage {
Compute,
}
#[cfg(not(target_os = "ios"))]
#[cfg(all(not(target_os = "ios"), not(target_arch = "wasm32")))]
impl Into<bevy_glsl_to_spirv::ShaderType> for ShaderStage {
fn into(self) -> bevy_glsl_to_spirv::ShaderType {
match self {
@ -21,7 +21,7 @@ impl Into<bevy_glsl_to_spirv::ShaderType> for ShaderStage {
}
}
#[cfg(not(target_os = "ios"))]
#[cfg(all(not(target_os = "ios"), not(target_arch = "wasm32")))]
fn glsl_to_spirv(
glsl_source: &str,
stage: ShaderStage,
@ -116,6 +116,7 @@ impl Shader {
}
}
#[cfg(not(target_arch = "wasm32"))]
pub fn get_spirv(&self, macros: Option<&[String]>) -> Vec<u32> {
match self.source {
ShaderSource::Spirv(ref bytes) => bytes.clone(),
@ -123,9 +124,13 @@ impl Shader {
}
}
#[allow(unused_variables)]
pub fn get_spirv_shader(&self, macros: Option<&[String]>) -> Shader {
Shader {
#[cfg(not(target_arch = "wasm32"))]
source: ShaderSource::Spirv(self.get_spirv(macros)),
#[cfg(target_arch = "wasm32")]
source: self.source.clone(),
stage: self.stage,
}
}
@ -143,12 +148,31 @@ impl Shader {
}
/// All stages in a shader program
#[derive(Clone, Debug)]
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
pub struct ShaderStages {
pub vertex: Handle<Shader>,
pub fragment: Option<Handle<Shader>>,
}
pub struct ShaderStagesIterator<'a> {
shader_stages: &'a ShaderStages,
state: u32,
}
impl<'a> Iterator for ShaderStagesIterator<'a> {
type Item = Handle<Shader>;
fn next(&mut self) -> Option<Self::Item> {
let ret = match self.state {
0 => Some(self.shader_stages.vertex),
1 => self.shader_stages.fragment,
_ => None,
};
self.state += 1;
ret
}
}
impl ShaderStages {
pub fn new(vertex_shader: Handle<Shader>) -> Self {
ShaderStages {
@ -156,4 +180,11 @@ impl ShaderStages {
fragment: None,
}
}
pub fn iter(&self) -> ShaderStagesIterator {
ShaderStagesIterator {
shader_stages: &self,
state: 0,
}
}
}

View File

@ -3,6 +3,7 @@ use crate::{
BindGroupDescriptor, BindType, BindingDescriptor, BindingShaderStage, InputStepMode,
UniformProperty, VertexAttributeDescriptor, VertexBufferDescriptor, VertexFormat,
},
shader::{ShaderLayout, GL_VERTEX_INDEX},
texture::{TextureComponentType, TextureViewDimension},
};
use bevy_core::AsBytes;
@ -16,16 +17,6 @@ use spirv_reflect::{
ShaderModule,
};
/// Defines the memory layout of a shader
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ShaderLayout {
pub bind_groups: Vec<BindGroupDescriptor>,
pub vertex_buffer_descriptors: Vec<VertexBufferDescriptor>,
pub entry_point: String,
}
pub const GL_VERTEX_INDEX: &str = "gl_VertexIndex";
impl ShaderLayout {
pub fn from_spirv(spirv_data: &[u32], bevy_conventions: bool) -> ShaderLayout {
match ShaderModule::load_u8_data(spirv_data.as_bytes()) {

View File

@ -0,0 +1,7 @@
use crate::shader::ShaderLayout;
impl ShaderLayout {
pub fn from_spirv(_spirv_data: &[u32], _bevy_conventions: bool) -> ShaderLayout {
panic!("reflecting shader layout from spirv data is not available");
}
}