Skip to content

Commit

Permalink
Update vendored Crevice to 0.8.0 + PR for arrays (#3059)
Browse files Browse the repository at this point in the history
# Objective

- Update vendor crevice to have the latest update from crevice 0.8.0
- Using https://github.com/ElectronicRU/crevice/tree/arrays which has the changes to make arrays work

## Solution

- Also updated glam and hexasphere to only have one version of glam
- From the original PR, using crevice to write GLSL code containing arrays would probably not work but it's not something used by Bevy
  • Loading branch information
mockersf committed Nov 12, 2021
1 parent e375add commit 290b7dd
Show file tree
Hide file tree
Showing 39 changed files with 1,846 additions and 668 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ ron = "0.6.2"
serde = { version = "1", features = ["derive"] }
# Needed to poll Task examples
futures-lite = "1.11.3"
crevice = {path = "crates/crevice"}
crevice = { path = "crates/crevice", version = "0.8.0", features = ["glam"] }

[[example]]
name = "hello_world"
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_math/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[dependencies]
glam = { version = "0.15.1", features = ["serde", "bytemuck"] }
glam = { version = "0.20.0", features = ["serde", "bytemuck"] }
bevy_reflect = { path = "../bevy_reflect", version = "0.5.0", features = ["bevy"] }
2 changes: 1 addition & 1 deletion crates/bevy_reflect/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ parking_lot = "0.11.0"
thiserror = "1.0"
serde = "1"
smallvec = { version = "1.6", features = ["serde", "union", "const_generics"], optional = true }
glam = { version = "0.15.1", features = ["serde"], optional = true }
glam = { version = "0.20.0", features = ["serde"], optional = true }

[dev-dependencies]
ron = "0.6.2"
2 changes: 1 addition & 1 deletion crates/bevy_render/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ downcast-rs = "1.2.0"
thiserror = "1.0"
anyhow = "1.0.4"
hex = "0.4.2"
hexasphere = "4.0.0"
hexasphere = "6.0.0"
parking_lot = "0.11.0"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
20 changes: 14 additions & 6 deletions crates/crevice/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
[package]
name = "crevice"
description = "Create GLSL-compatible versions of structs with explicitly-initialized padding"
version = "0.6.0"
edition = "2018"
version = "0.8.0"
edition = "2021"
authors = ["Lucien Greathouse <me@lpghatguy.com>"]
documentation = "https://docs.rs/crevice"
homepage = "https://github.com/LPGhatguy/crevice"
repository = "https://github.com/LPGhatguy/crevice"
readme = "README.md"
keywords = ["glsl", "std140", "std430"]
license = "MIT OR Apache-2.0"
# resolver = "2"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = ["std"]
std = []

# [workspace]
# members = ["crevice-derive", "crevice-tests"]
# default-members = ["crevice-derive", "crevice-tests"]

[dependencies]
crevice-derive = { version = "0.6.0", path = "crevice-derive" }
crevice-derive = { version = "0.8.0", path = "crevice-derive" }

bytemuck = "1.4.1"
mint = "0.5.5"
glam = "0.15.1"
mint = "0.5.8"

cgmath = { version = "0.18.0", optional = true }
glam = { version = "0.20.0", features = ["mint"], optional = true }
nalgebra = { version = "0.29.0", features = ["mint"], optional = true }

[dev-dependencies]
crevice-derive = { version = "0.6.0", path = "crevice-derive" }
insta = "0.16.1"
76 changes: 55 additions & 21 deletions crates/crevice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,34 @@ method to allow safely packing data into buffers for uploading.
Generated structs also implement [`bytemuck::Zeroable`] and
[`bytemuck::Pod`] for use with other libraries.

Crevice is similar to [`glsl-layout`][glsl-layout], but supports `mint` types
and explicitly initializes padding to remove one source of undefined behavior.
Crevice is similar to [`glsl-layout`][glsl-layout], but supports types from many
math crates, can generate GLSL source from structs, and explicitly initializes
padding to remove one source of undefined behavior.

Examples in this crate use cgmath, but any math crate that works with the mint
crate will also work. Some other crates include nalgebra, ultraviolet, glam, and
vek.
Crevice has support for many Rust math libraries via feature flags, and most
other math libraries by use of the mint crate. Crevice currently supports:

* mint 0.5, enabled by default
* cgmath 0.18, using the `cgmath` feature
* nalgebra 0.29, using the `nalgebra` feature
* glam 0.19, using the `glam` feature

PRs are welcome to add or update math libraries to Crevice.

If your math library is not supported, it's possible to define structs using the
types from mint and convert your math library's types into mint types. This is
supported by most Rust math libraries.

Your math library may require you to turn on a feature flag to get mint support.
For example, cgmath requires the "mint" feature to be enabled to allow
conversions to and from mint types.

## Examples

### Single Value

Uploading many types can be done by deriving `AsStd140` and using
[`as_std140`][std140::AsStd140::as_std140] and
Uploading many types can be done by deriving [`AsStd140`][std140::AsStd140] and
using [`as_std140`][std140::AsStd140::as_std140] and
[`as_bytes`][std140::Std140::as_bytes] to turn the result into bytes.

```glsl
Expand All @@ -36,8 +51,6 @@ uniform MAIN {

```rust
use crevice::std140::{AsStd140, Std140};
use cgmath::prelude::*;
use cgmath::{Matrix3, Vector3};

#[derive(AsStd140)]
struct MainUniform {
Expand All @@ -47,8 +60,12 @@ struct MainUniform {
}

let value = MainUniform {
orientation: Matrix3::identity().into(),
position: Vector3::new(1.0, 2.0, 3.0).into(),
orientation: [
[1.0, 0.0, 0.0],
[0.0, 1.0, 0.0],
[0.0, 0.0, 1.0],
].into(),
position: [1.0, 2.0, 3.0].into(),
scale: 4.0,
};

Expand All @@ -57,9 +74,10 @@ let value_std140 = value.as_std140();
upload_data_to_gpu(value_std140.as_bytes());
```

#### Sequential Types
### Sequential Types

More complicated data can be uploaded using the std140 `Writer` type.
More complicated data can be uploaded using the std140
[`Writer`][std140::Writer] type.

```glsl
struct PointLight {
Expand Down Expand Up @@ -113,24 +131,40 @@ unmap_gpu_buffer();

```

### Minimum Supported Rust Version (MSRV)
## Features

* `std` (default): Enables [`std::io::Write`]-based structs.
* `cgmath`: Enables support for types from cgmath.
* `nalgebra`: Enables support for types from nalgebra.
* `glam`: Enables support for types from glam.

Crevice supports Rust 1.46.0 and newer due to use of new `const fn` features.
## Minimum Supported Rust Version (MSRV)

Crevice supports Rust 1.52.1 and newer due to use of new `const fn` features.

[glsl-layout]: https://github.com/rustgd/glsl-layout
[Zeroable]: https://docs.rs/bytemuck/latest/bytemuck/trait.Zeroable.html
[Pod]: https://docs.rs/bytemuck/latest/bytemuck/trait.Pod.html
[TypeLayout]: https://docs.rs/type-layout/latest/type_layout/trait.TypeLayout.html

[std140::AsStd140]: https://docs.rs/crevice/latest/crevice/std140/trait.AsStd140.html
[std140::AsStd140::as_std140]: https://docs.rs/crevice/latest/crevice/std140/trait.AsStd140.html#method.as_std140
[std140::Std140::as_bytes]: https://docs.rs/crevice/latest/crevice/std140/trait.Std140.html#method.as_bytes
[std140::Writer]: https://docs.rs/crevice/latest/crevice/std140/struct.Writer.html

[`std::io::Write`]: https://doc.rust-lang.org/stable/std/io/trait.Write.html

[`bytemuck::Pod`]: https://docs.rs/bytemuck/latest/bytemuck/trait.Pod.html
[`bytemuck::Zeroable`]: https://docs.rs/bytemuck/latest/bytemuck/trait.Zeroable.html

## License

Licensed under either of

* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0))
* MIT license ([LICENSE-MIT](LICENSE-MIT) or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT))
* Apache License, Version 2.0, ([LICENSE-APACHE](http://www.apache.org/licenses/LICENSE-2.0))
* MIT license ([LICENSE-MIT](http://opensource.org/licenses/MIT))

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall
be dual licensed as above, without any additional terms or conditions.
10 changes: 10 additions & 0 deletions crates/crevice/README.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

{{readme}}

[std140::AsStd140]: https://docs.rs/crevice/latest/crevice/std140/trait.AsStd140.html
[std140::AsStd140::as_std140]: https://docs.rs/crevice/latest/crevice/std140/trait.AsStd140.html#method.as_std140
[std140::Std140::as_bytes]: https://docs.rs/crevice/latest/crevice/std140/trait.Std140.html#method.as_bytes
[std140::Writer]: https://docs.rs/crevice/latest/crevice/std140/struct.Writer.html

[`std::io::Write`]: https://doc.rust-lang.org/stable/std/io/trait.Write.html

[`bytemuck::Pod`]: https://docs.rs/bytemuck/latest/bytemuck/trait.Pod.html
[`bytemuck::Zeroable`]: https://docs.rs/bytemuck/latest/bytemuck/trait.Zeroable.html

## License

Licensed under either of
Expand Down
8 changes: 7 additions & 1 deletion crates/crevice/crevice-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
[package]
name = "crevice-derive"
description = "Derive crate for the 'crevice' crate"
version = "0.6.0"
version = "0.8.0"
edition = "2018"
authors = ["Lucien Greathouse <me@lpghatguy.com>"]
documentation = "https://docs.rs/crevice-derive"
homepage = "https://github.com/LPGhatguy/crevice"
repository = "https://github.com/LPGhatguy/crevice"
license = "MIT OR Apache-2.0"

[features]
default = []

# Enable methods that let you introspect into the generated structs.
debug-methods = []

[lib]
proc-macro = true

Expand Down
49 changes: 49 additions & 0 deletions crates/crevice/crevice-derive/src/glsl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use proc_macro2::{Literal, TokenStream};
use quote::quote;
use syn::{parse_quote, Data, DeriveInput, Fields, Path};

pub fn emit(input: DeriveInput) -> TokenStream {
let fields = match &input.data {
Data::Struct(data) => match &data.fields {
Fields::Named(fields) => fields,
Fields::Unnamed(_) => panic!("Tuple structs are not supported"),
Fields::Unit => panic!("Unit structs are not supported"),
},
Data::Enum(_) | Data::Union(_) => panic!("Only structs are supported"),
};

let base_trait_path: Path = parse_quote!(::crevice::glsl::Glsl);
let struct_trait_path: Path = parse_quote!(::crevice::glsl::GlslStruct);

let name = input.ident;
let name_str = Literal::string(&name.to_string());

let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();

let glsl_fields = fields.named.iter().map(|field| {
let field_ty = &field.ty;
let field_name_str = Literal::string(&field.ident.as_ref().unwrap().to_string());
let field_as = quote! {<#field_ty as ::crevice::glsl::GlslArray>};

quote! {
s.push_str("\t");
s.push_str(#field_as::NAME);
s.push_str(" ");
s.push_str(#field_name_str);
<#field_as::ArraySize as ::crevice::glsl::DimensionList>::push_to_string(s);
s.push_str(";\n");
}
});

quote! {
unsafe impl #impl_generics #base_trait_path for #name #ty_generics #where_clause {
const NAME: &'static str = #name_str;
}

unsafe impl #impl_generics #struct_trait_path for #name #ty_generics #where_clause {
fn enumerate_fields(s: &mut String) {
#( #glsl_fields )*
}
}
}
}
Loading

0 comments on commit 290b7dd

Please sign in to comment.