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] - Update vendored Crevice to 0.8.0 + PR for arrays #3059

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
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"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Specifying a version here will make cargo use the non-vendored version when publishing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 3 dependencies on crevice in Bevy crates, it was the only one not specifying a version so I added it for consistency.

Before Bevy release, Cart will also have to rename it to "bevy_crevice" or something

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That depends whether we even need to vendor it anymore. I think we should at least try it from crates.io after the recent rewrite and see if it fits our needs or not.

Copy link
Member Author

@mockersf mockersf Nov 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried, it's missing the array PR. once that's merged and released we wouldn't need to vendor it

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! :)


[[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 = "5.0.1"
parking_lot = "0.11.0"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
89 changes: 89 additions & 0 deletions crates/crevice/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Crevice Changelog

## Unreleased Changes

## [0.8.0] - 2021-10-26
* Added support for many math libraries directly: ([#37])
* cgmath 0.18, behind the `cgmath` feature
* nalgebra 0.29, behind the `nalgebra` feature
* glam 0.19, behind the `glam` feature
* Added support for generating GLSL source from structs. ([#33])
* Fixed many, many subtle alignment bugs. ([#28], [#35])
* Disabled bool-based types temporarily ([#36])
* Renamed `AsStdN::StdNType` to `Output`.
* Increased MSRV to 1.52.1.

[#28]: https://github.com/LPGhatguy/crevice/issues/28
[#33]: https://github.com/LPGhatguy/crevice/pull/33
[#35]: https://github.com/LPGhatguy/crevice/pull/35
[#36]: https://github.com/LPGhatguy/crevice/issues/36
[#37]: https://github.com/LPGhatguy/crevice/pull/37
[0.8.0]: https://github.com/LPGhatguy/crevice/releases/tag/v0.8.0

## [0.7.1] - 2021-07-24
* Fixed broken crates.io release by publishing crevice-derive too.

[0.7.1]: https://github.com/LPGhatguy/crevice/releases/tag/v0.7.1

## [0.7.0] - 2021-07-20 (Yanked)
**This release was yanked due to an issue reported in [#32].**

* Added `ivec`, `uvec`, and `bvec` structs ([#18])
* Improved padding behavior for structs and matrices ([#20])
* Implemented Crevice traits for more types ([#23])
* Added conversions from Std* types to AsStd* types ([#24])
* Added no_std support ([#25])

[#18]: https://github.com/LPGhatguy/crevice/pull/18
[#20]: https://github.com/LPGhatguy/crevice/pull/20
[#23]: https://github.com/LPGhatguy/crevice/pull/23
[#24]: https://github.com/LPGhatguy/crevice/pull/24
[#25]: https://github.com/LPGhatguy/crevice/pull/25
[#32]: https://github.com/LPGhatguy/crevice/issues/32
[0.7.0]: https://github.com/LPGhatguy/crevice/releases/tag/v0.7.0

## [0.6.0] - 2021-02-24
* Added `std430` support. Most APIs between `std140` and `std430` are the same!
* Added the `WriteStd140` trait. This trait is more general than `AsStd140` and is automatically implemented for all existing `AsStd140` implementers.
* Added `Writer::write_std140` to write a type that implements `Std140`.
* Added `AsStd140::std140_size_static`. This is similar to the old size method, `std140_size`, but no longer requires a value to be passed. For size measurements that depend on a value, use `WriteStd140::std140_size` instead.
* Deprecated `Writer::write_slice`, as `Writer::write` now accepts slices.
* Changed bounds of some functions, like `Writer::write` to use `WriteStd140` instead of `AsStd140`. This should affect no existing consumers.
* Moved `std140_size` from `AsStd140` to `WriteStd140`. Some existing consumers may need to import the other trait to access this m ethod.

[0.6.0]: https://github.com/LPGhatguy/crevice/releases/tag/v0.6.0

## [0.5.0] - 2020-10-18
* Added f64-based std140 types: `DVec2`, `DVec3`, `DVec4`, `DMat2`, `DMat3`, and `DMat4`.
* Added support for std140 structs with alignment greater than 16.
* Fixed padding for std140 matrices; they were previously missing trailing padding.

[0.5.0]: https://github.com/LPGhatguy/crevice/releases/tag/v0.5.0

## [0.4.0] - 2020-10-01
* Added `AsStd140::std140_size` for easily pre-sizing buffers.
* `Writer::write` and `Sizer::add` now return the offset the value is or would be written to.
* Added `std140::DynamicUniform` for aligning dynamic uniform members.
* Added `Writer::write_slice` for writing multiple values in a row.

[0.4.0]: https://github.com/LPGhatguy/crevice/releases/tag/v0.4.0

## [0.3.0] - 2020-09-22
* Added `Std140::as_bytes`, reducing the need to work with bytemuck directly.
* Removed public re-export of bytemuck.

[0.3.0]: https://github.com/LPGhatguy/crevice/releases/tag/v0.3.0

## [0.2.0] - 2020-09-22
* Added documentation for everything in the crate.
* Removed `type_layout` being exposed except for internal tests.
* Fixed alignment offset not taking into account previously added alignment.
* Added `std140::Writer`, for writing dynamically laid out types to buffers.
* Added `std140::Sizer`, for pre-calculating buffer sizes.

[0.2.0]: https://github.com/LPGhatguy/crevice/releases/tag/v0.2.0

## [0.1.0] - 2020-09-18
* Initial MVP release

[0.1.0]: https://github.com/LPGhatguy/crevice/releases/tag/v0.1.0
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 <[email protected]>"]
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"
73 changes: 52 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:

## Examples
* 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

### Single Value
PRs are welcome to add or update math libraries to Crevice.

Uploading many types can be done by deriving `AsStd140` and using
[`as_std140`][std140::AsStd140::as_std140] and
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`][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 @@ -59,7 +76,8 @@ upload_data_to_gpu(value_std140.as_bytes());

#### 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,37 @@ unmap_gpu_buffer();

```

### 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.

### Minimum Supported Rust Version (MSRV)

Crevice supports Rust 1.46.0 and newer due to use of new `const fn` features.
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](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT](LICENSE-MIT) or 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.
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 <[email protected]>"]
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