Skip to content

Commit 290b7dd

Browse files
committed
Update vendored Crevice to 0.8.0 + PR for arrays (#3059)
# 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
1 parent e375add commit 290b7dd

39 files changed

+1846
-668
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ ron = "0.6.2"
108108
serde = { version = "1", features = ["derive"] }
109109
# Needed to poll Task examples
110110
futures-lite = "1.11.3"
111-
crevice = {path = "crates/crevice"}
111+
crevice = { path = "crates/crevice", version = "0.8.0", features = ["glam"] }
112112

113113
[[example]]
114114
name = "hello_world"

crates/bevy_math/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ license = "MIT OR Apache-2.0"
1313
keywords = ["bevy"]
1414

1515
[dependencies]
16-
glam = { version = "0.15.1", features = ["serde", "bytemuck"] }
16+
glam = { version = "0.20.0", features = ["serde", "bytemuck"] }
1717
bevy_reflect = { path = "../bevy_reflect", version = "0.5.0", features = ["bevy"] }

crates/bevy_reflect/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ parking_lot = "0.11.0"
2828
thiserror = "1.0"
2929
serde = "1"
3030
smallvec = { version = "1.6", features = ["serde", "union", "const_generics"], optional = true }
31-
glam = { version = "0.15.1", features = ["serde"], optional = true }
31+
glam = { version = "0.20.0", features = ["serde"], optional = true }
3232

3333
[dev-dependencies]
3434
ron = "0.6.2"

crates/bevy_render/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ downcast-rs = "1.2.0"
3232
thiserror = "1.0"
3333
anyhow = "1.0.4"
3434
hex = "0.4.2"
35-
hexasphere = "4.0.0"
35+
hexasphere = "6.0.0"
3636
parking_lot = "0.11.0"
3737

3838
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]

crates/crevice/Cargo.toml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
11
[package]
22
name = "crevice"
33
description = "Create GLSL-compatible versions of structs with explicitly-initialized padding"
4-
version = "0.6.0"
5-
edition = "2018"
4+
version = "0.8.0"
5+
edition = "2021"
66
authors = ["Lucien Greathouse <[email protected]>"]
77
documentation = "https://docs.rs/crevice"
88
homepage = "https://github.com/LPGhatguy/crevice"
99
repository = "https://github.com/LPGhatguy/crevice"
1010
readme = "README.md"
1111
keywords = ["glsl", "std140", "std430"]
1212
license = "MIT OR Apache-2.0"
13+
# resolver = "2"
1314

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

1617
[features]
1718
default = ["std"]
1819
std = []
1920

21+
# [workspace]
22+
# members = ["crevice-derive", "crevice-tests"]
23+
# default-members = ["crevice-derive", "crevice-tests"]
24+
2025
[dependencies]
21-
crevice-derive = { version = "0.6.0", path = "crevice-derive" }
26+
crevice-derive = { version = "0.8.0", path = "crevice-derive" }
2227

2328
bytemuck = "1.4.1"
24-
mint = "0.5.5"
25-
glam = "0.15.1"
29+
mint = "0.5.8"
30+
31+
cgmath = { version = "0.18.0", optional = true }
32+
glam = { version = "0.20.0", features = ["mint"], optional = true }
33+
nalgebra = { version = "0.29.0", features = ["mint"], optional = true }
2634

2735
[dev-dependencies]
28-
crevice-derive = { version = "0.6.0", path = "crevice-derive" }
36+
insta = "0.16.1"

crates/crevice/README.md

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,34 @@ method to allow safely packing data into buffers for uploading.
1111
Generated structs also implement [`bytemuck::Zeroable`] and
1212
[`bytemuck::Pod`] for use with other libraries.
1313

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

17-
Examples in this crate use cgmath, but any math crate that works with the mint
18-
crate will also work. Some other crates include nalgebra, ultraviolet, glam, and
19-
vek.
18+
Crevice has support for many Rust math libraries via feature flags, and most
19+
other math libraries by use of the mint crate. Crevice currently supports:
20+
21+
* mint 0.5, enabled by default
22+
* cgmath 0.18, using the `cgmath` feature
23+
* nalgebra 0.29, using the `nalgebra` feature
24+
* glam 0.19, using the `glam` feature
25+
26+
PRs are welcome to add or update math libraries to Crevice.
27+
28+
If your math library is not supported, it's possible to define structs using the
29+
types from mint and convert your math library's types into mint types. This is
30+
supported by most Rust math libraries.
31+
32+
Your math library may require you to turn on a feature flag to get mint support.
33+
For example, cgmath requires the "mint" feature to be enabled to allow
34+
conversions to and from mint types.
2035

2136
## Examples
2237

2338
### Single Value
2439

25-
Uploading many types can be done by deriving `AsStd140` and using
26-
[`as_std140`][std140::AsStd140::as_std140] and
40+
Uploading many types can be done by deriving [`AsStd140`][std140::AsStd140] and
41+
using [`as_std140`][std140::AsStd140::as_std140] and
2742
[`as_bytes`][std140::Std140::as_bytes] to turn the result into bytes.
2843

2944
```glsl
@@ -36,8 +51,6 @@ uniform MAIN {
3651

3752
```rust
3853
use crevice::std140::{AsStd140, Std140};
39-
use cgmath::prelude::*;
40-
use cgmath::{Matrix3, Vector3};
4154

4255
#[derive(AsStd140)]
4356
struct MainUniform {
@@ -47,8 +60,12 @@ struct MainUniform {
4760
}
4861

4962
let value = MainUniform {
50-
orientation: Matrix3::identity().into(),
51-
position: Vector3::new(1.0, 2.0, 3.0).into(),
63+
orientation: [
64+
[1.0, 0.0, 0.0],
65+
[0.0, 1.0, 0.0],
66+
[0.0, 0.0, 1.0],
67+
].into(),
68+
position: [1.0, 2.0, 3.0].into(),
5269
scale: 4.0,
5370
};
5471

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

60-
#### Sequential Types
77+
### Sequential Types
6178

62-
More complicated data can be uploaded using the std140 `Writer` type.
79+
More complicated data can be uploaded using the std140
80+
[`Writer`][std140::Writer] type.
6381

6482
```glsl
6583
struct PointLight {
@@ -113,24 +131,40 @@ unmap_gpu_buffer();
113131

114132
```
115133

116-
### Minimum Supported Rust Version (MSRV)
134+
## Features
135+
136+
* `std` (default): Enables [`std::io::Write`]-based structs.
137+
* `cgmath`: Enables support for types from cgmath.
138+
* `nalgebra`: Enables support for types from nalgebra.
139+
* `glam`: Enables support for types from glam.
117140

118-
Crevice supports Rust 1.46.0 and newer due to use of new `const fn` features.
141+
## Minimum Supported Rust Version (MSRV)
142+
143+
Crevice supports Rust 1.52.1 and newer due to use of new `const fn` features.
119144

120145
[glsl-layout]: https://github.com/rustgd/glsl-layout
121-
[Zeroable]: https://docs.rs/bytemuck/latest/bytemuck/trait.Zeroable.html
122-
[Pod]: https://docs.rs/bytemuck/latest/bytemuck/trait.Pod.html
123-
[TypeLayout]: https://docs.rs/type-layout/latest/type_layout/trait.TypeLayout.html
146+
147+
[std140::AsStd140]: https://docs.rs/crevice/latest/crevice/std140/trait.AsStd140.html
148+
[std140::AsStd140::as_std140]: https://docs.rs/crevice/latest/crevice/std140/trait.AsStd140.html#method.as_std140
149+
[std140::Std140::as_bytes]: https://docs.rs/crevice/latest/crevice/std140/trait.Std140.html#method.as_bytes
150+
[std140::Writer]: https://docs.rs/crevice/latest/crevice/std140/struct.Writer.html
151+
152+
[`std::io::Write`]: https://doc.rust-lang.org/stable/std/io/trait.Write.html
153+
154+
[`bytemuck::Pod`]: https://docs.rs/bytemuck/latest/bytemuck/trait.Pod.html
155+
[`bytemuck::Zeroable`]: https://docs.rs/bytemuck/latest/bytemuck/trait.Zeroable.html
124156

125157
## License
126158

127159
Licensed under either of
128160

129-
* 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))
130-
* MIT license ([LICENSE-MIT](LICENSE-MIT) or [http://opensource.org/licenses/MIT](http://opensource.org/licenses/MIT))
161+
* Apache License, Version 2.0, ([LICENSE-APACHE](http://www.apache.org/licenses/LICENSE-2.0))
162+
* MIT license ([LICENSE-MIT](http://opensource.org/licenses/MIT))
131163

132164
at your option.
133165

134166
### Contribution
135167

136-
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.
168+
Unless you explicitly state otherwise, any contribution intentionally submitted
169+
for inclusion in the work by you, as defined in the Apache-2.0 license, shall
170+
be dual licensed as above, without any additional terms or conditions.

crates/crevice/README.tpl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
{{readme}}
44

5+
[std140::AsStd140]: https://docs.rs/crevice/latest/crevice/std140/trait.AsStd140.html
6+
[std140::AsStd140::as_std140]: https://docs.rs/crevice/latest/crevice/std140/trait.AsStd140.html#method.as_std140
7+
[std140::Std140::as_bytes]: https://docs.rs/crevice/latest/crevice/std140/trait.Std140.html#method.as_bytes
8+
[std140::Writer]: https://docs.rs/crevice/latest/crevice/std140/struct.Writer.html
9+
10+
[`std::io::Write`]: https://doc.rust-lang.org/stable/std/io/trait.Write.html
11+
12+
[`bytemuck::Pod`]: https://docs.rs/bytemuck/latest/bytemuck/trait.Pod.html
13+
[`bytemuck::Zeroable`]: https://docs.rs/bytemuck/latest/bytemuck/trait.Zeroable.html
14+
515
## License
616

717
Licensed under either of

crates/crevice/crevice-derive/Cargo.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
[package]
22
name = "crevice-derive"
33
description = "Derive crate for the 'crevice' crate"
4-
version = "0.6.0"
4+
version = "0.8.0"
55
edition = "2018"
66
authors = ["Lucien Greathouse <[email protected]>"]
77
documentation = "https://docs.rs/crevice-derive"
88
homepage = "https://github.com/LPGhatguy/crevice"
99
repository = "https://github.com/LPGhatguy/crevice"
1010
license = "MIT OR Apache-2.0"
1111

12+
[features]
13+
default = []
14+
15+
# Enable methods that let you introspect into the generated structs.
16+
debug-methods = []
17+
1218
[lib]
1319
proc-macro = true
1420

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
use proc_macro2::{Literal, TokenStream};
2+
use quote::quote;
3+
use syn::{parse_quote, Data, DeriveInput, Fields, Path};
4+
5+
pub fn emit(input: DeriveInput) -> TokenStream {
6+
let fields = match &input.data {
7+
Data::Struct(data) => match &data.fields {
8+
Fields::Named(fields) => fields,
9+
Fields::Unnamed(_) => panic!("Tuple structs are not supported"),
10+
Fields::Unit => panic!("Unit structs are not supported"),
11+
},
12+
Data::Enum(_) | Data::Union(_) => panic!("Only structs are supported"),
13+
};
14+
15+
let base_trait_path: Path = parse_quote!(::crevice::glsl::Glsl);
16+
let struct_trait_path: Path = parse_quote!(::crevice::glsl::GlslStruct);
17+
18+
let name = input.ident;
19+
let name_str = Literal::string(&name.to_string());
20+
21+
let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl();
22+
23+
let glsl_fields = fields.named.iter().map(|field| {
24+
let field_ty = &field.ty;
25+
let field_name_str = Literal::string(&field.ident.as_ref().unwrap().to_string());
26+
let field_as = quote! {<#field_ty as ::crevice::glsl::GlslArray>};
27+
28+
quote! {
29+
s.push_str("\t");
30+
s.push_str(#field_as::NAME);
31+
s.push_str(" ");
32+
s.push_str(#field_name_str);
33+
<#field_as::ArraySize as ::crevice::glsl::DimensionList>::push_to_string(s);
34+
s.push_str(";\n");
35+
}
36+
});
37+
38+
quote! {
39+
unsafe impl #impl_generics #base_trait_path for #name #ty_generics #where_clause {
40+
const NAME: &'static str = #name_str;
41+
}
42+
43+
unsafe impl #impl_generics #struct_trait_path for #name #ty_generics #where_clause {
44+
fn enumerate_fields(s: &mut String) {
45+
#( #glsl_fields )*
46+
}
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)