diff --git a/Cargo.toml b/Cargo.toml index e7da7e5cd1951..f3bab82571fdd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -102,7 +102,6 @@ ron = "0.7.0" serde = { version = "1", features = ["derive"] } # Needed to poll Task examples futures-lite = "1.11.3" -crevice = { path = "crates/crevice", version = "0.8.0", features = ["glam"] } [[example]] name = "hello_world" diff --git a/crates/crevice/Cargo.toml b/crates/bevy_crevice/Cargo.toml similarity index 80% rename from crates/crevice/Cargo.toml rename to crates/bevy_crevice/Cargo.toml index 76d473d0c501c..a886f495aaeca 100644 --- a/crates/crevice/Cargo.toml +++ b/crates/bevy_crevice/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "crevice" -description = "Create GLSL-compatible versions of structs with explicitly-initialized padding" -version = "0.8.0" +name = "bevy_crevice" +description = "Create GLSL-compatible versions of structs with explicitly-initialized padding (Bevy version)" +version = "0.5.0" edition = "2021" authors = ["Lucien Greathouse "] documentation = "https://docs.rs/crevice" homepage = "https://github.com/LPGhatguy/crevice" -repository = "https://github.com/LPGhatguy/crevice" +repository = "https://github.com/bevyengine/bevy" readme = "README.md" keywords = ["glsl", "std140", "std430"] license = "MIT OR Apache-2.0" @@ -23,7 +23,7 @@ std = [] # default-members = ["crevice-derive", "crevice-tests"] [dependencies] -crevice-derive = { version = "0.8.0", path = "crevice-derive" } +bevy-crevice-derive = { version = "0.5.0", path = "bevy-crevice-derive" } bytemuck = "1.4.1" mint = "0.5.8" diff --git a/crates/crevice/LICENSE-APACHE b/crates/bevy_crevice/LICENSE-APACHE similarity index 100% rename from crates/crevice/LICENSE-APACHE rename to crates/bevy_crevice/LICENSE-APACHE diff --git a/crates/crevice/LICENSE-MIT b/crates/bevy_crevice/LICENSE-MIT similarity index 100% rename from crates/crevice/LICENSE-MIT rename to crates/bevy_crevice/LICENSE-MIT diff --git a/crates/crevice/README.md b/crates/bevy_crevice/README.md similarity index 87% rename from crates/crevice/README.md rename to crates/bevy_crevice/README.md index 7e7070178e454..a5c16f69c75a0 100644 --- a/crates/crevice/README.md +++ b/crates/bevy_crevice/README.md @@ -1,8 +1,19 @@ -# Crevice +# Bevy Crevice -[![GitHub CI Status](https://github.com/LPGhatguy/crevice/workflows/CI/badge.svg)](https://github.com/LPGhatguy/crevice/actions) -[![crevice on crates.io](https://img.shields.io/crates/v/crevice.svg)](https://crates.io/crates/crevice) -[![crevice docs](https://img.shields.io/badge/docs-docs.rs-orange.svg)](https://docs.rs/crevice) +This is a fork of [Crevice](https://crates.io/crates/crevice) for +[Bevy](https://bevyengine.org). + +For use outside of Bevy, you should consider +using [Crevice](https://crates.io/crates/crevice) directly. + +It was forked to allow better integration in Bevy: + +* Easier derive macro usage, without needing to depend on `Crevice` directly. +* Use of unmerged features (as of the fork), like +[Array Support](https://github.com/LPGhatguy/crevice/pull/27/). +* Renaming of traits and macros to better match Bevy API. + +## Crevice Crevice creates GLSL-compatible versions of types through the power of derive macros. Generated structures provide an [`as_bytes`][std140::Std140::as_bytes] @@ -21,7 +32,7 @@ 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 +* glam 0.20, using the `glam` feature PRs are welcome to add or update math libraries to Crevice. @@ -50,7 +61,7 @@ uniform MAIN { ``` ```rust -use crevice::std140::{AsStd140, Std140}; +use bevy_crevice::std140::{AsStd140, Std140}; #[derive(AsStd140)] struct MainUniform { @@ -93,7 +104,7 @@ buffer POINT_LIGHTS { ``` ```rust -use crevice::std140::{self, AsStd140}; +use bevy_crevice::std140::{self, AsStd140}; #[derive(AsStd140)] struct PointLight { diff --git a/crates/crevice/README.tpl b/crates/bevy_crevice/README.tpl similarity index 100% rename from crates/crevice/README.tpl rename to crates/bevy_crevice/README.tpl diff --git a/crates/crevice/crevice-derive/Cargo.toml b/crates/bevy_crevice/bevy-crevice-derive/Cargo.toml similarity index 68% rename from crates/crevice/crevice-derive/Cargo.toml rename to crates/bevy_crevice/bevy-crevice-derive/Cargo.toml index 1d64fbb6738fc..4d7809ece780e 100644 --- a/crates/crevice/crevice-derive/Cargo.toml +++ b/crates/bevy_crevice/bevy-crevice-derive/Cargo.toml @@ -1,12 +1,12 @@ [package] -name = "crevice-derive" -description = "Derive crate for the 'crevice' crate" -version = "0.8.0" +name = "bevy-crevice-derive" +description = "Derive crate for the 'crevice' crate (Bevy version)" +version = "0.5.0" edition = "2018" authors = ["Lucien Greathouse "] documentation = "https://docs.rs/crevice-derive" homepage = "https://github.com/LPGhatguy/crevice" -repository = "https://github.com/LPGhatguy/crevice" +repository = "https://github.com/bevyengine/bevy" license = "MIT OR Apache-2.0" [features] @@ -24,3 +24,4 @@ proc-macro = true syn = "1.0.40" quote = "1.0.7" proc-macro2 = "1.0.21" +bevy_macro_utils = { path = "../../bevy_macro_utils", version = "0.5.0" } diff --git a/crates/crevice/crevice-derive/src/glsl.rs b/crates/bevy_crevice/bevy-crevice-derive/src/glsl.rs similarity index 78% rename from crates/crevice/crevice-derive/src/glsl.rs rename to crates/bevy_crevice/bevy-crevice-derive/src/glsl.rs index fd74f0cd91a91..e81442bf4554c 100644 --- a/crates/crevice/crevice-derive/src/glsl.rs +++ b/crates/bevy_crevice/bevy-crevice-derive/src/glsl.rs @@ -3,6 +3,8 @@ use quote::quote; use syn::{parse_quote, Data, DeriveInput, Fields, Path}; pub fn emit(input: DeriveInput) -> TokenStream { + let bevy_crevice_path = crate::bevy_crevice_path(); + let fields = match &input.data { Data::Struct(data) => match &data.fields { Fields::Named(fields) => fields, @@ -12,8 +14,8 @@ pub fn emit(input: DeriveInput) -> TokenStream { 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 base_trait_path: Path = parse_quote!(#bevy_crevice_path::glsl::Glsl); + let struct_trait_path: Path = parse_quote!(#bevy_crevice_path::glsl::GlslStruct); let name = input.ident; let name_str = Literal::string(&name.to_string()); @@ -23,14 +25,14 @@ pub fn emit(input: DeriveInput) -> TokenStream { 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>}; + let field_as = quote! {<#field_ty as #bevy_crevice_path::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); + <#field_as::ArraySize as #bevy_crevice_path::glsl::DimensionList>::push_to_string(s); s.push_str(";\n"); } }); diff --git a/crates/crevice/crevice-derive/src/layout.rs b/crates/bevy_crevice/bevy-crevice-derive/src/layout.rs similarity index 91% rename from crates/crevice/crevice-derive/src/layout.rs rename to crates/bevy_crevice/bevy-crevice-derive/src/layout.rs index 0819a01cf2bfc..74c04ad1100d1 100644 --- a/crates/crevice/crevice-derive/src/layout.rs +++ b/crates/bevy_crevice/bevy-crevice-derive/src/layout.rs @@ -8,10 +8,12 @@ pub fn emit( mod_name: &'static str, min_struct_alignment: usize, ) -> TokenStream { + let bevy_crevice_path = crate::bevy_crevice_path(); + let mod_name = Ident::new(mod_name, Span::call_site()); let trait_name = Ident::new(trait_name, Span::call_site()); - let mod_path: Path = parse_quote!(::crevice::#mod_name); + let mod_path: Path = parse_quote!(#bevy_crevice_path::#mod_name); let trait_path: Path = parse_quote!(#mod_path::#trait_name); let as_trait_name = format_ident!("As{}", trait_name); @@ -63,7 +65,7 @@ pub fn emit( let field_alignments = fields.iter().map(|field| layout_alignment_of_ty(&field.ty)); let struct_alignment = quote! { - ::crevice::internal::max_arr([ + #bevy_crevice_path::internal::max_arr([ #min_struct_alignment, #(#field_alignments,)* ]) @@ -139,13 +141,13 @@ pub fn emit( // We set our target alignment to the larger of the // alignment due to the previous field and the alignment // requirement of the next field. - let alignment = ::crevice::internal::max( + let alignment = #bevy_crevice_path::internal::max( #next_field_or_self_alignment, min_alignment, ); // Using everything we've got, compute our padding amount. - ::crevice::internal::align_offset(starting_offset, alignment) + #bevy_crevice_path::internal::align_offset(starting_offset, alignment) } } }) @@ -222,7 +224,7 @@ pub fn emit( let size = ::core::mem::size_of::(); let align = ::ALIGNMENT; - let zeroed: Self = ::crevice::internal::bytemuck::Zeroable::zeroed(); + let zeroed: Self = #bevy_crevice_path::internal::bytemuck::Zeroable::zeroed(); #[derive(Debug)] struct Field { @@ -253,13 +255,13 @@ pub fn emit( #pad_fn_impls #struct_definition - unsafe impl #impl_generics ::crevice::internal::bytemuck::Zeroable for #generated_name #ty_generics #where_clause {} - unsafe impl #impl_generics ::crevice::internal::bytemuck::Pod for #generated_name #ty_generics #where_clause {} + unsafe impl #impl_generics #bevy_crevice_path::internal::bytemuck::Zeroable for #generated_name #ty_generics #where_clause {} + unsafe impl #impl_generics #bevy_crevice_path::internal::bytemuck::Pod for #generated_name #ty_generics #where_clause {} unsafe impl #impl_generics #mod_path::#trait_name for #generated_name #ty_generics #where_clause { const ALIGNMENT: usize = #struct_alignment; const PAD_AT_END: bool = true; - type Padded = #padded_path(), #struct_alignment )}>; @@ -272,7 +274,7 @@ pub fn emit( Self::Output { #generated_struct_field_init - ..::crevice::internal::bytemuck::Zeroable::zeroed() + ..#bevy_crevice_path::internal::bytemuck::Zeroable::zeroed() } } diff --git a/crates/bevy_crevice/bevy-crevice-derive/src/lib.rs b/crates/bevy_crevice/bevy-crevice-derive/src/lib.rs new file mode 100644 index 0000000000000..e0cc77a8ee4a2 --- /dev/null +++ b/crates/bevy_crevice/bevy-crevice-derive/src/lib.rs @@ -0,0 +1,60 @@ +mod glsl; +mod layout; + +use bevy_macro_utils::BevyManifest; +use proc_macro::TokenStream as CompilerTokenStream; + +use syn::{parse_macro_input, DeriveInput, Path}; + +#[proc_macro_derive(AsStd140)] +pub fn derive_as_std140(input: CompilerTokenStream) -> CompilerTokenStream { + let input = parse_macro_input!(input as DeriveInput); + let expanded = layout::emit(input, "Std140", "std140", 16); + + CompilerTokenStream::from(expanded) +} + +#[proc_macro_derive(AsStd430)] +pub fn derive_as_std430(input: CompilerTokenStream) -> CompilerTokenStream { + let input = parse_macro_input!(input as DeriveInput); + let expanded = layout::emit(input, "Std430", "std430", 0); + + CompilerTokenStream::from(expanded) +} + +#[proc_macro_derive(GlslStruct)] +pub fn derive_glsl_struct(input: CompilerTokenStream) -> CompilerTokenStream { + let input = parse_macro_input!(input as DeriveInput); + let expanded = glsl::emit(input); + + CompilerTokenStream::from(expanded) +} + +const BEVY: &str = "bevy"; +const BEVY_CREVICE: &str = "bevy_crevice"; +const BEVY_RENDER: &str = "bevy_render"; + +fn bevy_crevice_path() -> Path { + let bevy_manifest = BevyManifest::default(); + bevy_manifest + .maybe_get_path(crate::BEVY) + .map(|bevy_path| { + let mut segments = bevy_path.segments; + segments.push(BevyManifest::parse_str("render")); + segments.push(BevyManifest::parse_str("render_resource")); + Path { + leading_colon: None, + segments, + } + }) + .or_else(|| bevy_manifest.maybe_get_path(crate::BEVY_RENDER)) + .map(|bevy_render_path| { + let mut segments = bevy_render_path.segments; + segments.push(BevyManifest::parse_str("render_resource")); + Path { + leading_colon: None, + segments, + } + }) + .unwrap_or_else(|| bevy_manifest.get_path(crate::BEVY_CREVICE)) +} diff --git a/crates/crevice/crevice-tests/Cargo.toml b/crates/bevy_crevice/crevice-tests/Cargo.toml similarity index 77% rename from crates/crevice/crevice-tests/Cargo.toml rename to crates/bevy_crevice/crevice-tests/Cargo.toml index 103614eb393a2..7d7a6bbec14a5 100644 --- a/crates/crevice/crevice-tests/Cargo.toml +++ b/crates/bevy_crevice/crevice-tests/Cargo.toml @@ -7,8 +7,8 @@ edition = "2018" wgpu-validation = ["wgpu", "naga", "futures"] [dependencies] -crevice = { path = ".." } -crevice-derive = { path = "../crevice-derive", features = ["debug-methods"] } +bevy_crevice = { path = ".." } +bevy-crevice-derive = { path = "../bevy-crevice-derive", features = ["debug-methods"] } anyhow = "1.0.44" bytemuck = "1.7.2" diff --git a/crates/crevice/crevice-tests/src/gpu.rs b/crates/bevy_crevice/crevice-tests/src/gpu.rs similarity index 98% rename from crates/crevice/crevice-tests/src/gpu.rs rename to crates/bevy_crevice/crevice-tests/src/gpu.rs index 517e8d7a46f98..a91703e4ffef5 100644 --- a/crates/crevice/crevice-tests/src/gpu.rs +++ b/crates/bevy_crevice/crevice-tests/src/gpu.rs @@ -2,9 +2,9 @@ use std::borrow::Cow; use std::fmt::Debug; use std::marker::PhantomData; -use crevice::glsl::{Glsl, GlslStruct}; -use crevice::std140::{AsStd140, Std140}; -use crevice::std430::{AsStd430, Std430}; +use bevy_crevice::glsl::{Glsl, GlslStruct}; +use bevy_crevice::std140::{AsStd140, Std140}; +use bevy_crevice::std430::{AsStd430, Std430}; use futures::executor::block_on; use wgpu::util::DeviceExt; diff --git a/crates/crevice/crevice-tests/src/lib.rs b/crates/bevy_crevice/crevice-tests/src/lib.rs similarity index 98% rename from crates/crevice/crevice-tests/src/lib.rs rename to crates/bevy_crevice/crevice-tests/src/lib.rs index da61b47fb47cf..2f0516e4abd53 100644 --- a/crates/crevice/crevice-tests/src/lib.rs +++ b/crates/bevy_crevice/crevice-tests/src/lib.rs @@ -15,9 +15,9 @@ fn test_round_trip_primitive(_value: T) {} #[macro_use] mod util; -use crevice::glsl::GlslStruct; -use crevice::std140::AsStd140; -use crevice::std430::AsStd430; +use bevy_crevice::glsl::GlslStruct; +use bevy_crevice::std140::AsStd140; +use bevy_crevice::std430::AsStd430; use mint::{ColumnMatrix2, ColumnMatrix3, ColumnMatrix4, Vector2, Vector3, Vector4}; #[test] diff --git a/crates/crevice/crevice-tests/src/util.rs b/crates/bevy_crevice/crevice-tests/src/util.rs similarity index 100% rename from crates/crevice/crevice-tests/src/util.rs rename to crates/bevy_crevice/crevice-tests/src/util.rs diff --git a/crates/crevice/src/glsl.rs b/crates/bevy_crevice/src/glsl.rs similarity index 98% rename from crates/crevice/src/glsl.rs rename to crates/bevy_crevice/src/glsl.rs index 3f879b6ab1798..d6b1c48b63607 100644 --- a/crates/crevice/src/glsl.rs +++ b/crates/bevy_crevice/src/glsl.rs @@ -1,6 +1,6 @@ //! Defines traits and types for generating GLSL code from Rust definitions. -pub use crevice_derive::GlslStruct; +pub use bevy_crevice_derive::GlslStruct; use std::marker::PhantomData; /// Type-level linked list of array dimensions diff --git a/crates/crevice/src/imp.rs b/crates/bevy_crevice/src/imp.rs similarity index 100% rename from crates/crevice/src/imp.rs rename to crates/bevy_crevice/src/imp.rs diff --git a/crates/crevice/src/imp/imp_cgmath.rs b/crates/bevy_crevice/src/imp/imp_cgmath.rs similarity index 100% rename from crates/crevice/src/imp/imp_cgmath.rs rename to crates/bevy_crevice/src/imp/imp_cgmath.rs diff --git a/crates/crevice/src/imp/imp_glam.rs b/crates/bevy_crevice/src/imp/imp_glam.rs similarity index 100% rename from crates/crevice/src/imp/imp_glam.rs rename to crates/bevy_crevice/src/imp/imp_glam.rs diff --git a/crates/crevice/src/imp/imp_mint.rs b/crates/bevy_crevice/src/imp/imp_mint.rs similarity index 100% rename from crates/crevice/src/imp/imp_mint.rs rename to crates/bevy_crevice/src/imp/imp_mint.rs diff --git a/crates/crevice/src/imp/imp_nalgebra.rs b/crates/bevy_crevice/src/imp/imp_nalgebra.rs similarity index 100% rename from crates/crevice/src/imp/imp_nalgebra.rs rename to crates/bevy_crevice/src/imp/imp_nalgebra.rs diff --git a/crates/crevice/src/internal.rs b/crates/bevy_crevice/src/internal.rs similarity index 100% rename from crates/crevice/src/internal.rs rename to crates/bevy_crevice/src/internal.rs diff --git a/crates/crevice/src/lib.rs b/crates/bevy_crevice/src/lib.rs similarity index 98% rename from crates/crevice/src/lib.rs rename to crates/bevy_crevice/src/lib.rs index 46b96d1b307bd..782e85cf4d938 100644 --- a/crates/crevice/src/lib.rs +++ b/crates/bevy_crevice/src/lib.rs @@ -56,7 +56,7 @@ uniform MAIN { ``` ```rust -use crevice::std140::{AsStd140, Std140}; +use bevy_crevice::std140::{AsStd140, Std140}; #[derive(AsStd140)] struct MainUniform { @@ -100,7 +100,7 @@ buffer POINT_LIGHTS { ``` ```rust -use crevice::std140::{self, AsStd140}; +use bevy_crevice::std140::{self, AsStd140}; #[derive(AsStd140)] struct PointLight { diff --git a/crates/crevice/src/std140.rs b/crates/bevy_crevice/src/std140.rs similarity index 90% rename from crates/crevice/src/std140.rs rename to crates/bevy_crevice/src/std140.rs index 184b99a92d4be..dd7cde1cabf40 100644 --- a/crates/crevice/src/std140.rs +++ b/crates/bevy_crevice/src/std140.rs @@ -15,4 +15,4 @@ pub use self::traits::*; #[cfg(feature = "std")] pub use self::writer::*; -pub use crevice_derive::AsStd140; +pub use bevy_crevice_derive::AsStd140; diff --git a/crates/crevice/src/std140/dynamic_uniform.rs b/crates/bevy_crevice/src/std140/dynamic_uniform.rs similarity index 100% rename from crates/crevice/src/std140/dynamic_uniform.rs rename to crates/bevy_crevice/src/std140/dynamic_uniform.rs diff --git a/crates/crevice/src/std140/primitives.rs b/crates/bevy_crevice/src/std140/primitives.rs similarity index 100% rename from crates/crevice/src/std140/primitives.rs rename to crates/bevy_crevice/src/std140/primitives.rs diff --git a/crates/crevice/src/std140/sizer.rs b/crates/bevy_crevice/src/std140/sizer.rs similarity index 97% rename from crates/crevice/src/std140/sizer.rs rename to crates/bevy_crevice/src/std140/sizer.rs index ee5c134595daf..87c27cb63b3d9 100644 --- a/crates/crevice/src/std140/sizer.rs +++ b/crates/bevy_crevice/src/std140/sizer.rs @@ -25,7 +25,7 @@ buffer FROBS { ``` ``` -use crevice::std140::{self, AsStd140}; +use bevy_crevice::std140::{self, AsStd140}; #[derive(AsStd140)] struct Frob { diff --git a/crates/crevice/src/std140/traits.rs b/crates/bevy_crevice/src/std140/traits.rs similarity index 99% rename from crates/crevice/src/std140/traits.rs rename to crates/bevy_crevice/src/std140/traits.rs index caa8fce6fdaa6..392251c3f80ec 100644 --- a/crates/crevice/src/std140/traits.rs +++ b/crates/bevy_crevice/src/std140/traits.rs @@ -89,7 +89,7 @@ uniform CAMERA { ``` ```no_run -use crevice::std140::{AsStd140, Std140}; +use bevy_crevice::std140::{AsStd140, Std140}; #[derive(AsStd140)] struct CameraUniform { diff --git a/crates/crevice/src/std140/writer.rs b/crates/bevy_crevice/src/std140/writer.rs similarity index 98% rename from crates/crevice/src/std140/writer.rs rename to crates/bevy_crevice/src/std140/writer.rs index 2a4dbc550f518..aeed06ff78e9b 100644 --- a/crates/crevice/src/std140/writer.rs +++ b/crates/bevy_crevice/src/std140/writer.rs @@ -32,7 +32,7 @@ buffer POINT_LIGHTS { ``` ``` -use crevice::std140::{self, AsStd140}; +use bevy_crevice::std140::{self, AsStd140}; #[derive(AsStd140)] struct PointLight { diff --git a/crates/crevice/src/std430.rs b/crates/bevy_crevice/src/std430.rs similarity index 88% rename from crates/crevice/src/std430.rs rename to crates/bevy_crevice/src/std430.rs index 7e1af050ceee1..676c999556c11 100644 --- a/crates/crevice/src/std430.rs +++ b/crates/bevy_crevice/src/std430.rs @@ -13,4 +13,4 @@ pub use self::traits::*; #[cfg(feature = "std")] pub use self::writer::*; -pub use crevice_derive::AsStd430; +pub use bevy_crevice_derive::AsStd430; diff --git a/crates/crevice/src/std430/primitives.rs b/crates/bevy_crevice/src/std430/primitives.rs similarity index 100% rename from crates/crevice/src/std430/primitives.rs rename to crates/bevy_crevice/src/std430/primitives.rs diff --git a/crates/crevice/src/std430/sizer.rs b/crates/bevy_crevice/src/std430/sizer.rs similarity index 97% rename from crates/crevice/src/std430/sizer.rs rename to crates/bevy_crevice/src/std430/sizer.rs index 20b7b29e0bc5a..05203d5577d9c 100644 --- a/crates/crevice/src/std430/sizer.rs +++ b/crates/bevy_crevice/src/std430/sizer.rs @@ -25,7 +25,7 @@ buffer FROBS { ``` ``` -use crevice::std430::{self, AsStd430}; +use bevy_crevice::std430::{self, AsStd430}; #[derive(AsStd430)] struct Frob { diff --git a/crates/crevice/src/std430/traits.rs b/crates/bevy_crevice/src/std430/traits.rs similarity index 99% rename from crates/crevice/src/std430/traits.rs rename to crates/bevy_crevice/src/std430/traits.rs index 6206ec7ac641f..dfd5ad7d84b8c 100644 --- a/crates/crevice/src/std430/traits.rs +++ b/crates/bevy_crevice/src/std430/traits.rs @@ -89,7 +89,7 @@ uniform CAMERA { ``` ```no_run -use crevice::std430::{AsStd430, Std430}; +use bevy_crevice::std430::{AsStd430, Std430}; #[derive(AsStd430)] struct CameraUniform { diff --git a/crates/crevice/src/std430/writer.rs b/crates/bevy_crevice/src/std430/writer.rs similarity index 98% rename from crates/crevice/src/std430/writer.rs rename to crates/bevy_crevice/src/std430/writer.rs index 518455543561b..199ab3ab50abc 100644 --- a/crates/crevice/src/std430/writer.rs +++ b/crates/bevy_crevice/src/std430/writer.rs @@ -32,7 +32,7 @@ buffer POINT_LIGHTS { ``` ``` -use crevice::std430::{self, AsStd430}; +use bevy_crevice::std430::{self, AsStd430}; #[derive(AsStd430)] struct PointLight { diff --git a/crates/crevice/src/util.rs b/crates/bevy_crevice/src/util.rs similarity index 100% rename from crates/crevice/src/util.rs rename to crates/bevy_crevice/src/util.rs diff --git a/crates/crevice/tests/snapshots/test__generate_struct_array_glsl.snap b/crates/bevy_crevice/tests/snapshots/test__generate_struct_array_glsl.snap similarity index 100% rename from crates/crevice/tests/snapshots/test__generate_struct_array_glsl.snap rename to crates/bevy_crevice/tests/snapshots/test__generate_struct_array_glsl.snap diff --git a/crates/crevice/tests/snapshots/test__generate_struct_glsl.snap b/crates/bevy_crevice/tests/snapshots/test__generate_struct_glsl.snap similarity index 100% rename from crates/crevice/tests/snapshots/test__generate_struct_glsl.snap rename to crates/bevy_crevice/tests/snapshots/test__generate_struct_glsl.snap diff --git a/crates/crevice/tests/test.rs b/crates/bevy_crevice/tests/test.rs similarity index 94% rename from crates/crevice/tests/test.rs rename to crates/bevy_crevice/tests/test.rs index f07786c827c63..693ce080c7f12 100644 --- a/crates/crevice/tests/test.rs +++ b/crates/bevy_crevice/tests/test.rs @@ -1,5 +1,5 @@ -use crevice::glsl::GlslStruct; -use crevice::std140::AsStd140; +use bevy_crevice::glsl::GlslStruct; +use bevy_crevice::std140::AsStd140; #[test] fn there_and_back_again() { diff --git a/crates/bevy_macro_utils/src/lib.rs b/crates/bevy_macro_utils/src/lib.rs index 15ce683f962ac..b7e0eaa2fd398 100644 --- a/crates/bevy_macro_utils/src/lib.rs +++ b/crates/bevy_macro_utils/src/lib.rs @@ -30,13 +30,13 @@ impl Default for BevyManifest { } impl BevyManifest { - pub fn get_path(&self, name: &str) -> syn::Path { + pub fn maybe_get_path(&self, name: &str) -> Option { const BEVY: &str = "bevy"; const BEVY_INTERNAL: &str = "bevy_internal"; let find_in_deps = |deps: &DepsSet| -> Option { let package = if let Some(dep) = deps.get(name) { - return Some(get_path(dep.package().unwrap_or(name))); + return Some(Self::parse_str(dep.package().unwrap_or(name))); } else if let Some(dep) = deps.get(BEVY) { dep.package().unwrap_or(BEVY) } else if let Some(dep) = deps.get(BEVY_INTERNAL) { @@ -45,9 +45,9 @@ impl BevyManifest { return None; }; - let mut path = get_path(package); + let mut path = Self::parse_str::(package); if let Some(module) = name.strip_prefix("bevy_") { - path.segments.push(parse_str(module)); + path.segments.push(Self::parse_str(module)); } Some(path) }; @@ -57,16 +57,15 @@ impl BevyManifest { deps.and_then(find_in_deps) .or_else(|| deps_dev.and_then(find_in_deps)) - .unwrap_or_else(|| get_path(name)) } -} - -fn get_path(path: &str) -> syn::Path { - parse_str(path) -} + pub fn get_path(&self, name: &str) -> syn::Path { + self.maybe_get_path(name) + .unwrap_or_else(|| Self::parse_str(name)) + } -fn parse_str(path: &str) -> T { - syn::parse(path.parse::().unwrap()).unwrap() + pub fn parse_str(path: &str) -> T { + syn::parse(path.parse::().unwrap()).unwrap() + } } /// Derive a label trait diff --git a/crates/bevy_pbr/Cargo.toml b/crates/bevy_pbr/Cargo.toml index cee9a7db2426f..94d8d8950c2db 100644 --- a/crates/bevy_pbr/Cargo.toml +++ b/crates/bevy_pbr/Cargo.toml @@ -29,5 +29,4 @@ bevy_window = { path = "../bevy_window", version = "0.5.0" } bitflags = "1.2" # direct dependency required for derive macro bytemuck = { version = "1", features = ["derive"] } -crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] } wgpu = { version = "0.12.0", features = ["spirv"] } diff --git a/crates/bevy_pbr/src/material.rs b/crates/bevy_pbr/src/material.rs index e2a4a23f7c36f..25d07a4be9b83 100644 --- a/crates/bevy_pbr/src/material.rs +++ b/crates/bevy_pbr/src/material.rs @@ -7,11 +7,13 @@ use bevy_reflect::TypeUuid; use bevy_render::{ color::Color, render_asset::{PrepareAssetError, RenderAsset, RenderAssetPlugin, RenderAssets}, - render_resource::{BindGroup, Buffer, BufferInitDescriptor, BufferUsages}, + render_resource::{ + std140::{AsStd140, Std140}, + BindGroup, Buffer, BufferInitDescriptor, BufferUsages, + }, renderer::RenderDevice, texture::Image, }; -use crevice::std140::{AsStd140, Std140}; use wgpu::{BindGroupDescriptor, BindGroupEntry, BindingResource}; pub const DEFAULT_STANDARD_MATERIAL_HANDLE: HandleUntyped = diff --git a/crates/bevy_pbr/src/render/light.rs b/crates/bevy_pbr/src/render/light.rs index d6545a43cd95f..0b7cbe8a12197 100644 --- a/crates/bevy_pbr/src/render/light.rs +++ b/crates/bevy_pbr/src/render/light.rs @@ -22,14 +22,13 @@ use bevy_render::{ EntityRenderCommand, PhaseItem, RenderCommandResult, RenderPhase, SetItemPipeline, TrackedRenderPass, }, - render_resource::*, + render_resource::{std140::AsStd140, *}, renderer::{RenderContext, RenderDevice, RenderQueue}, texture::*, view::{ExtractedView, ViewUniform, ViewUniformOffset, ViewUniforms, VisibleEntities}, }; use bevy_transform::components::GlobalTransform; use bevy_utils::{tracing::warn, HashMap}; -use crevice::std140::AsStd140; use std::num::NonZeroU32; #[derive(Debug, Hash, PartialEq, Eq, Clone, SystemLabel)] diff --git a/crates/bevy_pbr/src/render/mesh.rs b/crates/bevy_pbr/src/render/mesh.rs index acc2d893df5c8..d18cccd12073e 100644 --- a/crates/bevy_pbr/src/render/mesh.rs +++ b/crates/bevy_pbr/src/render/mesh.rs @@ -15,14 +15,13 @@ use bevy_render::{ render_asset::RenderAssets, render_component::{ComponentUniforms, DynamicUniformIndex, UniformComponentPlugin}, render_phase::{EntityRenderCommand, RenderCommandResult, TrackedRenderPass}, - render_resource::*, + render_resource::{std140::AsStd140, *}, renderer::{RenderDevice, RenderQueue}, texture::{BevyDefault, GpuImage, Image, TextureFormatPixelInfo}, view::{ComputedVisibility, ViewUniform, ViewUniformOffset, ViewUniforms}, RenderApp, RenderStage, }; use bevy_transform::components::GlobalTransform; -use crevice::std140::AsStd140; use wgpu::{ Extent3d, ImageCopyTexture, ImageDataLayout, Origin3d, SamplerBindingType, TextureDimension, TextureFormat, TextureViewDescriptor, diff --git a/crates/bevy_pbr/src/render/mod.rs b/crates/bevy_pbr/src/render/mod.rs index 88a8476c1750f..5b8b379183d1d 100644 --- a/crates/bevy_pbr/src/render/mod.rs +++ b/crates/bevy_pbr/src/render/mod.rs @@ -19,11 +19,10 @@ use bevy_render::{ DrawFunctions, EntityRenderCommand, RenderCommandResult, RenderPhase, SetItemPipeline, TrackedRenderPass, }, - render_resource::*, + render_resource::{std140::AsStd140, *}, renderer::RenderDevice, view::{ExtractedView, Msaa, VisibleEntities}, }; -use crevice::std140::AsStd140; // NOTE: These must match the bit flags in bevy_pbr2/src/render/pbr.wgsl! bitflags::bitflags! { diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index 6f48e9a89261e..a17665d7ec05c 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -25,6 +25,7 @@ webgl = ["wgpu/webgl"] bevy_app = { path = "../bevy_app", version = "0.5.0" } bevy_asset = { path = "../bevy_asset", version = "0.5.0" } bevy_core = { path = "../bevy_core", version = "0.5.0" } +bevy_crevice = { path = "../bevy_crevice", version = "0.5.0", features = ["glam"] } bevy_derive = { path = "../bevy_derive", version = "0.5.0" } bevy_ecs = { path = "../bevy_ecs", version = "0.5.0" } bevy_math = { path = "../bevy_math", version = "0.5.0" } @@ -52,4 +53,3 @@ hex = "0.4.2" hexasphere = "6.0.0" parking_lot = "0.11.0" regex = "1.5" -crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] } diff --git a/crates/bevy_render/src/render_component.rs b/crates/bevy_render/src/render_component.rs index 437ae2b973795..721e1b2918250 100644 --- a/crates/bevy_render/src/render_component.rs +++ b/crates/bevy_render/src/render_component.rs @@ -1,5 +1,5 @@ use crate::{ - render_resource::DynamicUniformVec, + render_resource::{std140::AsStd140, DynamicUniformVec}, renderer::{RenderDevice, RenderQueue}, RenderApp, RenderStage, }; @@ -14,7 +14,6 @@ use bevy_ecs::{ RunSystem, SystemParamItem, }, }; -use crevice::std140::AsStd140; use std::{marker::PhantomData, ops::Deref}; /// Stores the index of a uniform inside of [`ComponentUniforms`]. diff --git a/crates/bevy_render/src/render_resource/mod.rs b/crates/bevy_render/src/render_resource/mod.rs index 5069a896f9e01..000f2ec2d981b 100644 --- a/crates/bevy_render/src/render_resource/mod.rs +++ b/crates/bevy_render/src/render_resource/mod.rs @@ -40,3 +40,5 @@ pub use wgpu::{ TextureViewDimension, VertexAttribute, VertexBufferLayout as RawVertexBufferLayout, VertexFormat, VertexState as RawVertexState, VertexStepMode, }; + +pub use bevy_crevice::*; diff --git a/crates/bevy_render/src/render_resource/uniform_vec.rs b/crates/bevy_render/src/render_resource/uniform_vec.rs index 8cbc1f09c910f..f31e7e258d6a2 100644 --- a/crates/bevy_render/src/render_resource/uniform_vec.rs +++ b/crates/bevy_render/src/render_resource/uniform_vec.rs @@ -1,8 +1,8 @@ use crate::{ + render_resource::std140::{self, AsStd140, DynamicUniform, Std140}, render_resource::Buffer, renderer::{RenderDevice, RenderQueue}, }; -use crevice::std140::{self, AsStd140, DynamicUniform, Std140}; use std::num::NonZeroU64; use wgpu::{BindingResource, BufferBinding, BufferDescriptor, BufferUsages}; diff --git a/crates/bevy_render/src/view/mod.rs b/crates/bevy_render/src/view/mod.rs index 2bb395b368fa0..710df62774f8a 100644 --- a/crates/bevy_render/src/view/mod.rs +++ b/crates/bevy_render/src/view/mod.rs @@ -10,7 +10,7 @@ pub use window::*; use crate::{ camera::{ExtractedCamera, ExtractedCameraNames}, - render_resource::{DynamicUniformVec, Texture, TextureView}, + render_resource::{std140::AsStd140, DynamicUniformVec, Texture, TextureView}, renderer::{RenderDevice, RenderQueue}, texture::{BevyDefault, TextureCache}, RenderApp, RenderStage, @@ -19,7 +19,6 @@ use bevy_app::{App, Plugin}; use bevy_ecs::prelude::*; use bevy_math::{Mat4, Vec3}; use bevy_transform::components::GlobalTransform; -use crevice::std140::AsStd140; pub struct ViewPlugin; diff --git a/crates/bevy_sprite/Cargo.toml b/crates/bevy_sprite/Cargo.toml index 64163006280a0..53b70abeb8d9f 100644 --- a/crates/bevy_sprite/Cargo.toml +++ b/crates/bevy_sprite/Cargo.toml @@ -26,7 +26,6 @@ bevy_utils = { path = "../bevy_utils", version = "0.5.0" } # other bytemuck = { version = "1.5", features = ["derive"] } -crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] } guillotiere = "0.6.0" thiserror = "1.0" rectangle-pack = "0.4" diff --git a/crates/bevy_sprite/src/render/mod.rs b/crates/bevy_sprite/src/render/mod.rs index e9bb91fca6885..f66101f44f8f9 100644 --- a/crates/bevy_sprite/src/render/mod.rs +++ b/crates/bevy_sprite/src/render/mod.rs @@ -16,7 +16,7 @@ use bevy_render::{ color::Color, render_asset::RenderAssets, render_phase::{Draw, DrawFunctions, RenderPhase, TrackedRenderPass}, - render_resource::*, + render_resource::{std140::AsStd140, *}, renderer::{RenderDevice, RenderQueue}, texture::{BevyDefault, Image}, view::{ComputedVisibility, ViewUniform, ViewUniformOffset, ViewUniforms}, @@ -25,7 +25,6 @@ use bevy_render::{ use bevy_transform::components::GlobalTransform; use bevy_utils::HashMap; use bytemuck::{Pod, Zeroable}; -use crevice::std140::AsStd140; pub struct SpritePipeline { view_layout: BindGroupLayout, diff --git a/crates/bevy_ui/Cargo.toml b/crates/bevy_ui/Cargo.toml index 7b2acbff686d5..eaa5b66170c31 100644 --- a/crates/bevy_ui/Cargo.toml +++ b/crates/bevy_ui/Cargo.toml @@ -32,4 +32,3 @@ stretch = "0.3.2" serde = { version = "1", features = ["derive"] } smallvec = { version = "1.6", features = ["union", "const_generics"] } bytemuck = { version = "1.5", features = ["derive"] } -crevice = { path = "../crevice", version = "0.8.0", features = ["glam"] } diff --git a/crates/bevy_ui/src/render/pipeline.rs b/crates/bevy_ui/src/render/pipeline.rs index 8e6d36fe96c8d..4538dc922b131 100644 --- a/crates/bevy_ui/src/render/pipeline.rs +++ b/crates/bevy_ui/src/render/pipeline.rs @@ -1,10 +1,11 @@ use bevy_ecs::prelude::*; use bevy_render::{ - render_resource::*, renderer::RenderDevice, texture::BevyDefault, view::ViewUniform, + render_resource::{std140::AsStd140, *}, + renderer::RenderDevice, + texture::BevyDefault, + view::ViewUniform, }; -use crevice::std140::AsStd140; - pub struct UiPipeline { pub view_layout: BindGroupLayout, pub image_layout: BindGroupLayout, diff --git a/crates/crevice/crevice-derive/src/lib.rs b/crates/crevice/crevice-derive/src/lib.rs deleted file mode 100644 index ab1012a9092f9..0000000000000 --- a/crates/crevice/crevice-derive/src/lib.rs +++ /dev/null @@ -1,30 +0,0 @@ -mod glsl; -mod layout; - -use proc_macro::TokenStream as CompilerTokenStream; - -use syn::{parse_macro_input, DeriveInput}; - -#[proc_macro_derive(AsStd140)] -pub fn derive_as_std140(input: CompilerTokenStream) -> CompilerTokenStream { - let input = parse_macro_input!(input as DeriveInput); - let expanded = layout::emit(input, "Std140", "std140", 16); - - CompilerTokenStream::from(expanded) -} - -#[proc_macro_derive(AsStd430)] -pub fn derive_as_std430(input: CompilerTokenStream) -> CompilerTokenStream { - let input = parse_macro_input!(input as DeriveInput); - let expanded = layout::emit(input, "Std430", "std430", 0); - - CompilerTokenStream::from(expanded) -} - -#[proc_macro_derive(GlslStruct)] -pub fn derive_glsl_struct(input: CompilerTokenStream) -> CompilerTokenStream { - let input = parse_macro_input!(input as DeriveInput); - let expanded = glsl::emit(input); - - CompilerTokenStream::from(expanded) -} diff --git a/examples/shader/shader_material.rs b/examples/shader/shader_material.rs index e7c4737023a71..ad2f934f514af 100644 --- a/examples/shader/shader_material.rs +++ b/examples/shader/shader_material.rs @@ -15,13 +15,15 @@ use bevy::{ AddRenderCommand, DrawFunctions, EntityRenderCommand, RenderCommandResult, RenderPhase, SetItemPipeline, TrackedRenderPass, }, - render_resource::*, + render_resource::{ + std140::{AsStd140, Std140}, + *, + }, renderer::RenderDevice, view::{ExtractedView, Msaa}, RenderApp, RenderStage, }, }; -use crevice::std140::{AsStd140, Std140}; fn main() { App::new() diff --git a/tools/publish.sh b/tools/publish.sh index f76ad1ba37d28..a0cdd0a59dd0c 100644 --- a/tools/publish.sh +++ b/tools/publish.sh @@ -18,6 +18,8 @@ crates=( bevy_diagnostic bevy_transform bevy_window + bevy_crevice/bevy-crevice-derive + bevy_crevice bevy_render bevy_core_pipeline bevy_input